2016-05-26 23:51:02 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_render_process_preferences.h"
|
|
|
|
|
2016-06-14 00:01:13 +00:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2016-05-27 00:20:46 +00:00
|
|
|
#include "atom/browser/atom_browser_client.h"
|
2016-05-26 23:51:02 +00:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2019-03-12 00:13:43 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2016-05-27 00:20:46 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2016-05-26 23:51:02 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "native_mate/object_template_builder.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-06-14 00:01:13 +00:00
|
|
|
bool IsWebContents(v8::Isolate* isolate, content::RenderProcessHost* process) {
|
2016-05-27 00:20:46 +00:00
|
|
|
content::WebContents* web_contents =
|
2018-04-18 01:55:30 +00:00
|
|
|
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
|
|
|
|
->GetWebContentsFromProcessID(process->GetID());
|
2016-05-27 00:20:46 +00:00
|
|
|
if (!web_contents)
|
|
|
|
return false;
|
|
|
|
|
2018-10-19 08:52:07 +00:00
|
|
|
auto api_web_contents = WebContents::FromOrCreate(isolate, web_contents);
|
2016-06-14 16:37:55 +00:00
|
|
|
auto type = api_web_contents->GetType();
|
|
|
|
return type == WebContents::Type::BROWSER_WINDOW ||
|
|
|
|
type == WebContents::Type::WEB_VIEW;
|
2016-05-26 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
RenderProcessPreferences::RenderProcessPreferences(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const atom::RenderProcessPreferences::Predicate& predicate)
|
|
|
|
: preferences_(predicate) {
|
|
|
|
Init(isolate);
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
RenderProcessPreferences::~RenderProcessPreferences() {}
|
2016-05-26 23:51:02 +00:00
|
|
|
|
|
|
|
int RenderProcessPreferences::AddEntry(const base::DictionaryValue& entry) {
|
|
|
|
return preferences_.AddEntry(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderProcessPreferences::RemoveEntry(int id) {
|
|
|
|
preferences_.RemoveEntry(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void RenderProcessPreferences::BuildPrototype(
|
2018-04-18 01:55:30 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(
|
|
|
|
mate::StringToV8(isolate, "RenderProcessPreferences"));
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2016-05-26 23:51:02 +00:00
|
|
|
.SetMethod("addEntry", &RenderProcessPreferences::AddEntry)
|
|
|
|
.SetMethod("removeEntry", &RenderProcessPreferences::RemoveEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
mate::Handle<RenderProcessPreferences>
|
2016-06-14 00:01:13 +00:00
|
|
|
RenderProcessPreferences::ForAllWebContents(v8::Isolate* isolate) {
|
2018-04-18 01:55:30 +00:00
|
|
|
return mate::CreateHandle(isolate,
|
|
|
|
new RenderProcessPreferences(
|
|
|
|
isolate, base::Bind(&IsWebContents, isolate)));
|
2016-05-26 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2016-05-26 23:51:02 +00:00
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
2016-06-14 00:01:13 +00:00
|
|
|
dict.SetMethod("forAllWebContents",
|
|
|
|
&atom::api::RenderProcessPreferences::ForAllWebContents);
|
2016-05-26 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-08 18:29:52 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_render_process_preferences,
|
|
|
|
Initialize)
|