75 lines
2 KiB
C++
75 lines
2 KiB
C++
|
// 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"
|
||
|
|
||
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||
|
#include "atom/common/node_includes.h"
|
||
|
#include "native_mate/dictionary.h"
|
||
|
#include "native_mate/object_template_builder.h"
|
||
|
|
||
|
namespace atom {
|
||
|
|
||
|
namespace api {
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
bool IsBrowserWindow(content::RenderProcessHost* process) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
} // 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>
|
||
|
RenderProcessPreferences::ForAllBrowserWindow(v8::Isolate* isolate) {
|
||
|
return mate::CreateHandle(
|
||
|
isolate,
|
||
|
new RenderProcessPreferences(isolate, base::Bind(&IsBrowserWindow)));
|
||
|
}
|
||
|
|
||
|
} // 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);
|
||
|
dict.SetMethod("forAllBrowserWindow",
|
||
|
&atom::api::RenderProcessPreferences::ForAllBrowserWindow);
|
||
|
}
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_render_process_preferences,
|
||
|
Initialize)
|