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"
|
|
|
|
#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 =
|
|
|
|
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->
|
|
|
|
GetWebContentsFromProcessID(process->GetID());
|
|
|
|
if (!web_contents)
|
|
|
|
return false;
|
|
|
|
|
2016-06-14 00:01:13 +00:00
|
|
|
auto api_web_contents = WebContents::CreateFrom(isolate, web_contents);
|
2016-06-14 16:09:54 +00:00
|
|
|
return api_web_contents->GetType() != WebContents::Type::REMOTE;
|
2016-05-26 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
RenderProcessPreferences::RenderProcessPreferences(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const atom::RenderProcessPreferences::Predicate& predicate)
|
|
|
|
: preferences_(predicate) {
|
|
|
|
Init(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderProcessPreferences::~RenderProcessPreferences() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int RenderProcessPreferences::AddEntry(const base::DictionaryValue& entry) {
|
|
|
|
return preferences_.AddEntry(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderProcessPreferences::RemoveEntry(int id) {
|
|
|
|
preferences_.RemoveEntry(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void RenderProcessPreferences::BuildPrototype(
|
|
|
|
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype)
|
|
|
|
.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) {
|
2016-05-26 23:51:02 +00:00
|
|
|
return mate::CreateHandle(
|
|
|
|
isolate,
|
2016-06-14 00:01:13 +00:00
|
|
|
new RenderProcessPreferences(isolate,
|
|
|
|
base::Bind(&IsWebContents, isolate)));
|
2016-05-26 23:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
|
|
|
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
|
|
|
|
|
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_render_process_preferences,
|
|
|
|
Initialize)
|