Set prototype of constructor directly
This commit is contained in:
parent
8c3232dc56
commit
844f32aa36
19 changed files with 84 additions and 158 deletions
|
@ -639,6 +639,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||||
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
|
dict.Set("App", atom::api::App::GetConstructor(isolate)->GetFunction());
|
||||||
dict.Set("app", atom::api::App::Create(isolate));
|
dict.Set("app", atom::api::App::Create(isolate));
|
||||||
dict.SetMethod("appendSwitch", &AppendSwitch);
|
dict.SetMethod("appendSwitch", &AppendSwitch);
|
||||||
dict.SetMethod("appendArgument",
|
dict.SetMethod("appendArgument",
|
||||||
|
|
|
@ -122,11 +122,14 @@ void AutoUpdater::BuildPrototype(
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::AutoUpdater;
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("autoUpdater", atom::api::AutoUpdater::Create(isolate));
|
dict.Set("autoUpdater", AutoUpdater::Create(isolate));
|
||||||
|
dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -23,14 +23,6 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// The wrapDebugger funtion which is implemented in JavaScript.
|
|
||||||
using WrapDebuggerCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
|
||||||
WrapDebuggerCallback g_wrap_debugger;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Debugger::Debugger(v8::Isolate* isolate, content::WebContents* web_contents)
|
Debugger::Debugger(v8::Isolate* isolate, content::WebContents* web_contents)
|
||||||
: web_contents_(web_contents),
|
: web_contents_(web_contents),
|
||||||
previous_request_id_(0) {
|
previous_request_id_(0) {
|
||||||
|
@ -151,10 +143,7 @@ void Debugger::SendCommand(mate::Arguments* args) {
|
||||||
mate::Handle<Debugger> Debugger::Create(
|
mate::Handle<Debugger> Debugger::Create(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
content::WebContents* web_contents) {
|
content::WebContents* web_contents) {
|
||||||
auto handle = mate::CreateHandle(
|
return mate::CreateHandle(isolate, new Debugger(isolate, web_contents));
|
||||||
isolate, new Debugger(isolate, web_contents));
|
|
||||||
g_wrap_debugger.Run(handle.ToV8());
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -168,21 +157,19 @@ void Debugger::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("sendCommand", &Debugger::SendCommand);
|
.SetMethod("sendCommand", &Debugger::SendCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWrapDebugger(const WrapDebuggerCallback& callback) {
|
|
||||||
g_wrap_debugger = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::Debugger;
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary(isolate, exports)
|
||||||
dict.SetMethod("_setWrapDebugger", &atom::api::SetWrapDebugger);
|
.Set("Debugger", Debugger::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -51,10 +51,6 @@ namespace api {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// The wrapDownloadItem funtion which is implemented in JavaScript
|
|
||||||
using WrapDownloadItemCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
|
||||||
WrapDownloadItemCallback g_wrap_download_item;
|
|
||||||
|
|
||||||
std::map<uint32_t, v8::Global<v8::Object>> g_download_item_objects;
|
std::map<uint32_t, v8::Global<v8::Object>> g_download_item_objects;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -197,7 +193,6 @@ mate::Handle<DownloadItem> DownloadItem::Create(
|
||||||
return mate::CreateHandle(isolate, static_cast<DownloadItem*>(existing));
|
return mate::CreateHandle(isolate, static_cast<DownloadItem*>(existing));
|
||||||
|
|
||||||
auto handle = mate::CreateHandle(isolate, new DownloadItem(isolate, item));
|
auto handle = mate::CreateHandle(isolate, new DownloadItem(isolate, item));
|
||||||
g_wrap_download_item.Run(handle.ToV8());
|
|
||||||
|
|
||||||
// Reference this object in case it got garbage collected.
|
// Reference this object in case it got garbage collected.
|
||||||
g_download_item_objects[handle->weak_map_id()] =
|
g_download_item_objects[handle->weak_map_id()] =
|
||||||
|
@ -205,10 +200,6 @@ mate::Handle<DownloadItem> DownloadItem::Create(
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWrapDownloadItem(const WrapDownloadItemCallback& callback) {
|
|
||||||
g_wrap_download_item = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
@ -218,8 +209,9 @@ namespace {
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary(isolate, exports)
|
||||||
dict.SetMethod("_setWrapDownloadItem", &atom::api::SetWrapDownloadItem);
|
.Set("DownloadItem",
|
||||||
|
atom::api::DownloadItem::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -63,16 +63,19 @@ void PowerMonitor::BuildPrototype(
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::PowerMonitor;
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
|
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using atom::api::PowerMonitor;
|
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("powerMonitor", PowerMonitor::Create(isolate));
|
dict.Set("powerMonitor", PowerMonitor::Create(isolate));
|
||||||
|
dict.Set("PowerMonitor",
|
||||||
|
PowerMonitor::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -129,10 +129,14 @@ void Screen::BuildPrototype(
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::Screen;
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
dict.Set("screen", atom::api::Screen::Create(context->GetIsolate()));
|
mate::Dictionary dict(isolate, exports);
|
||||||
|
dict.Set("screen", Screen::Create(isolate));
|
||||||
|
dict.Set("Screen", Screen::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -170,10 +170,6 @@ namespace {
|
||||||
|
|
||||||
const char kPersistPrefix[] = "persist:";
|
const char kPersistPrefix[] = "persist:";
|
||||||
|
|
||||||
// The wrapSession funtion which is implemented in JavaScript
|
|
||||||
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
|
||||||
WrapSessionCallback g_wrap_session;
|
|
||||||
|
|
||||||
// Referenced session objects.
|
// Referenced session objects.
|
||||||
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
|
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
|
||||||
|
|
||||||
|
@ -541,7 +537,6 @@ mate::Handle<Session> Session::CreateFrom(
|
||||||
|
|
||||||
auto handle = mate::CreateHandle(
|
auto handle = mate::CreateHandle(
|
||||||
isolate, new Session(isolate, browser_context));
|
isolate, new Session(isolate, browser_context));
|
||||||
g_wrap_session.Run(handle.ToV8());
|
|
||||||
|
|
||||||
// The Sessions should never be garbage collected, since the common pattern is
|
// The Sessions should never be garbage collected, since the common pattern is
|
||||||
// to use partition strings, instead of using the Session object directly.
|
// to use partition strings, instead of using the Session object directly.
|
||||||
|
@ -596,16 +591,14 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetProperty("webRequest", &Session::WebRequest);
|
.SetProperty("webRequest", &Session::WebRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWrapSession(const WrapSessionCallback& callback) {
|
|
||||||
g_wrap_session = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::Session;
|
||||||
|
|
||||||
v8::Local<v8::Value> FromPartition(
|
v8::Local<v8::Value> FromPartition(
|
||||||
const std::string& partition, mate::Arguments* args) {
|
const std::string& partition, mate::Arguments* args) {
|
||||||
if (!atom::Browser::Get()->is_ready()) {
|
if (!atom::Browser::Get()->is_ready()) {
|
||||||
|
@ -614,16 +607,15 @@ v8::Local<v8::Value> FromPartition(
|
||||||
}
|
}
|
||||||
base::DictionaryValue options;
|
base::DictionaryValue options;
|
||||||
args->GetNext(&options);
|
args->GetNext(&options);
|
||||||
return atom::api::Session::FromPartition(
|
return Session::FromPartition(args->isolate(), partition, options).ToV8();
|
||||||
args->isolate(), partition, options).ToV8();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
|
dict.Set("Session", Session::GetConstructor(isolate)->GetFunction());
|
||||||
dict.SetMethod("fromPartition", &FromPartition);
|
dict.SetMethod("fromPartition", &FromPartition);
|
||||||
dict.SetMethod("_setWrapSession", &atom::api::SetWrapSession);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -69,11 +69,15 @@ void SystemPreferences::BuildPrototype(
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::SystemPreferences;
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("systemPreferences", atom::api::SystemPreferences::Create(isolate));
|
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
|
||||||
|
dict.Set("SystemPreferences",
|
||||||
|
SystemPreferences::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -221,10 +221,6 @@ namespace api {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// The wrapWebContents function which is implemented in JavaScript
|
|
||||||
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
|
||||||
WrapWebContentsCallback g_wrap_web_contents;
|
|
||||||
|
|
||||||
content::ServiceWorkerContext* GetServiceWorkerContext(
|
content::ServiceWorkerContext* GetServiceWorkerContext(
|
||||||
const content::WebContents* web_contents) {
|
const content::WebContents* web_contents) {
|
||||||
auto context = web_contents->GetBrowserContext();
|
auto context = web_contents->GetBrowserContext();
|
||||||
|
@ -1470,41 +1466,32 @@ mate::Handle<WebContents> WebContents::CreateFrom(
|
||||||
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
|
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
|
||||||
|
|
||||||
// Otherwise create a new WebContents wrapper object.
|
// Otherwise create a new WebContents wrapper object.
|
||||||
auto handle = mate::CreateHandle(
|
return mate::CreateHandle(isolate, new WebContents(isolate, web_contents));
|
||||||
isolate, new WebContents(isolate, web_contents));
|
|
||||||
g_wrap_web_contents.Run(handle.ToV8());
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<WebContents> WebContents::Create(
|
mate::Handle<WebContents> WebContents::Create(
|
||||||
v8::Isolate* isolate, const mate::Dictionary& options) {
|
v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||||
auto handle = mate::CreateHandle(isolate, new WebContents(isolate, options));
|
return mate::CreateHandle(isolate, new WebContents(isolate, options));
|
||||||
g_wrap_web_contents.Run(handle.ToV8());
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetWrapWebContents(const WrapWebContentsCallback& callback) {
|
|
||||||
g_wrap_web_contents = callback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::WebContents;
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.SetMethod("create", &atom::api::WebContents::Create);
|
dict.Set("WebContents", WebContents::GetConstructor(isolate)->GetFunction());
|
||||||
dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
|
dict.SetMethod("create", &WebContents::Create);
|
||||||
dict.SetMethod("fromId",
|
dict.SetMethod("fromId", &mate::TrackableObject<WebContents>::FromWeakMapID);
|
||||||
&mate::TrackableObject<atom::api::WebContents>::FromWeakMapID);
|
|
||||||
dict.SetMethod("getAllWebContents",
|
dict.SetMethod("getAllWebContents",
|
||||||
&mate::TrackableObject<atom::api::WebContents>::GetAll);
|
&mate::TrackableObject<WebContents>::GetAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -16,9 +16,6 @@ namespace mate {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// The prototype of Node's EventEmitter.
|
|
||||||
v8::Persistent<v8::Object> g_event_emitter_prototype;
|
|
||||||
|
|
||||||
v8::Persistent<v8::ObjectTemplate> event_template;
|
v8::Persistent<v8::ObjectTemplate> event_template;
|
||||||
|
|
||||||
void PreventDefault(mate::Arguments* args) {
|
void PreventDefault(mate::Arguments* args) {
|
||||||
|
@ -80,29 +77,6 @@ v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags) {
|
||||||
return obj.GetHandle();
|
return obj.GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InheritFromEventEmitter(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::FunctionTemplate> constructor) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetEventEmitterPrototype(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::Object> prototype) {
|
|
||||||
g_event_emitter_prototype.Reset(isolate, prototype);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
|
||||||
mate::Dictionary(context->GetIsolate(), exports)
|
|
||||||
.SetMethod("setEventEmitterPrototype",
|
|
||||||
&mate::internal::SetEventEmitterPrototype);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_event_emitter, Initialize)
|
|
||||||
|
|
|
@ -32,9 +32,6 @@ v8::Local<v8::Object> CreateCustomEvent(
|
||||||
v8::Local<v8::Object> event);
|
v8::Local<v8::Object> event);
|
||||||
v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags);
|
v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags);
|
||||||
|
|
||||||
void InheritFromEventEmitter(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::FunctionTemplate> constructor);
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
// Provide helperers to emit event in JavaScript.
|
// Provide helperers to emit event in JavaScript.
|
||||||
|
@ -90,11 +87,6 @@ class EventEmitter : public Wrappable<T> {
|
||||||
protected:
|
protected:
|
||||||
EventEmitter() {}
|
EventEmitter() {}
|
||||||
|
|
||||||
static void InheritFromEventEmitter(
|
|
||||||
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> constructor) {
|
|
||||||
internal::InheritFromEventEmitter(isolate, constructor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// this.emit(name, event, args...);
|
// this.emit(name, event, args...);
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const bindings = process.atomBinding('app')
|
const bindings = process.atomBinding('app')
|
||||||
const {app} = bindings
|
const {app, App} = bindings
|
||||||
|
|
||||||
// Only one app object permitted.
|
// Only one app object permitted.
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
@ -10,7 +10,7 @@ const electron = require('electron')
|
||||||
const {deprecate, Menu} = electron
|
const {deprecate, Menu} = electron
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
|
|
||||||
Object.setPrototypeOf(app.__proto__, EventEmitter.prototype)
|
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
let appPath = null
|
let appPath = null
|
||||||
|
|
||||||
|
@ -76,7 +76,5 @@ for (let name of events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrappers for native classes.
|
// Wrappers for native classes.
|
||||||
process.atomBinding('download_item')._setWrapDownloadItem((downloadItem) => {
|
const {DownloadItem} = process.atomBinding('download_item')
|
||||||
// downloadItem is an EventEmitter.
|
Object.setPrototypeOf(DownloadItem.prototype, EventEmitter.prototype)
|
||||||
Object.setPrototypeOf(downloadItem.__proto__, EventEmitter.prototype)
|
|
||||||
})
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const EventEmitter = require('events').EventEmitter
|
const EventEmitter = require('events').EventEmitter
|
||||||
const autoUpdater = process.atomBinding('auto_updater').autoUpdater
|
const {autoUpdater, AutoUpdater} = process.atomBinding('auto_updater')
|
||||||
|
|
||||||
Object.setPrototypeOf(autoUpdater.__proto__, EventEmitter.prototype)
|
Object.setPrototypeOf(AutoUpdater.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
module.exports = autoUpdater
|
module.exports = autoUpdater
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {powerMonitor} = process.atomBinding('power_monitor')
|
const {powerMonitor, PowerMonitor} = process.atomBinding('power_monitor')
|
||||||
|
|
||||||
Object.setPrototypeOf(powerMonitor.__proto__, EventEmitter.prototype)
|
Object.setPrototypeOf(PowerMonitor.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
module.exports = powerMonitor
|
module.exports = powerMonitor
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {screen} = process.atomBinding('screen')
|
const {screen, Screen} = process.atomBinding('screen')
|
||||||
|
|
||||||
Object.setPrototypeOf(screen.__proto__, EventEmitter.prototype)
|
Object.setPrototypeOf(Screen.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
module.exports = screen
|
module.exports = screen
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {app} = require('electron')
|
const {app} = require('electron')
|
||||||
const {fromPartition, _setWrapSession} = process.atomBinding('session')
|
const {fromPartition, Session} = process.atomBinding('session')
|
||||||
|
|
||||||
// Public API.
|
// Public API.
|
||||||
Object.defineProperties(exports, {
|
Object.defineProperties(exports, {
|
||||||
|
@ -14,9 +14,8 @@ Object.defineProperties(exports, {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Wraps native Session class.
|
Object.setPrototypeOf(Session.prototype, EventEmitter.prototype)
|
||||||
_setWrapSession(function (session) {
|
|
||||||
// Session is an EventEmitter.
|
Session.prototype._init = function () {
|
||||||
Object.setPrototypeOf(session.__proto__, EventEmitter.prototype)
|
app.emit('session-created', this)
|
||||||
app.emit('session-created', session)
|
}
|
||||||
})
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {systemPreferences} = process.atomBinding('system_preferences')
|
const {systemPreferences, SystemPreferences} = process.atomBinding('system_preferences')
|
||||||
|
|
||||||
Object.setPrototypeOf(systemPreferences.__proto__, EventEmitter.prototype)
|
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
module.exports = systemPreferences
|
module.exports = systemPreferences
|
||||||
|
|
|
@ -7,9 +7,6 @@ const {app, ipcMain, session, Menu, NavigationController} = require('electron')
|
||||||
// before the webContents module.
|
// before the webContents module.
|
||||||
session
|
session
|
||||||
|
|
||||||
const binding = process.atomBinding('web_contents')
|
|
||||||
const debuggerBinding = process.atomBinding('debugger')
|
|
||||||
|
|
||||||
let nextId = 0
|
let nextId = 0
|
||||||
const getNextId = function () {
|
const getNextId = function () {
|
||||||
return ++nextId
|
return ++nextId
|
||||||
|
@ -81,6 +78,11 @@ const defaultPrintingSetting = {
|
||||||
shouldPrintSelectionOnly: false
|
shouldPrintSelectionOnly: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const binding = process.atomBinding('web_contents')
|
||||||
|
const {WebContents} = binding
|
||||||
|
|
||||||
|
Object.setPrototypeOf(WebContents.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
// Following methods are mapped to webFrame.
|
// Following methods are mapped to webFrame.
|
||||||
const webFrameMethods = [
|
const webFrameMethods = [
|
||||||
'insertText',
|
'insertText',
|
||||||
|
@ -95,13 +97,10 @@ const webFrameMethodsWithResult = [
|
||||||
]
|
]
|
||||||
|
|
||||||
// Add JavaScript wrappers for WebContents class.
|
// Add JavaScript wrappers for WebContents class.
|
||||||
const wrapWebContents = function (webContents) {
|
WebContents.prototype._init = function () {
|
||||||
// webContents is an EventEmitter.
|
|
||||||
Object.setPrototypeOf(webContents.__proto__, EventEmitter.prototype)
|
|
||||||
|
|
||||||
// Every remote callback from renderer process would add a listenter to the
|
// Every remote callback from renderer process would add a listenter to the
|
||||||
// render-view-deleted event, so ignore the listenters warning.
|
// render-view-deleted event, so ignore the listenters warning.
|
||||||
webContents.setMaxListeners(0)
|
this.setMaxListeners(0)
|
||||||
|
|
||||||
// WebContents::send(channel, args..)
|
// WebContents::send(channel, args..)
|
||||||
// WebContents::sendToAll(channel, args..)
|
// WebContents::sendToAll(channel, args..)
|
||||||
|
@ -109,17 +108,17 @@ const wrapWebContents = function (webContents) {
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
throw new Error('Missing required channel argument')
|
throw new Error('Missing required channel argument')
|
||||||
}
|
}
|
||||||
return webContents._send(allFrames, channel, args)
|
return this._send(allFrames, channel, args)
|
||||||
}
|
}
|
||||||
webContents.send = sendWrapper.bind(null, false)
|
this.send = sendWrapper.bind(null, false)
|
||||||
webContents.sendToAll = sendWrapper.bind(null, true)
|
this.sendToAll = sendWrapper.bind(null, true)
|
||||||
|
|
||||||
// The navigation controller.
|
// The navigation controller.
|
||||||
const controller = new NavigationController(webContents)
|
const controller = new NavigationController(this)
|
||||||
for (const name in NavigationController.prototype) {
|
for (const name in NavigationController.prototype) {
|
||||||
const method = NavigationController.prototype[name]
|
const method = NavigationController.prototype[name]
|
||||||
if (method instanceof Function) {
|
if (method instanceof Function) {
|
||||||
webContents[name] = function () {
|
this[name] = function () {
|
||||||
return method.apply(controller, arguments)
|
return method.apply(controller, arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,13 +140,13 @@ const wrapWebContents = function (webContents) {
|
||||||
|
|
||||||
// Mapping webFrame methods.
|
// Mapping webFrame methods.
|
||||||
for (const method of webFrameMethods) {
|
for (const method of webFrameMethods) {
|
||||||
webContents[method] = function (...args) {
|
this[method] = function (...args) {
|
||||||
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args)
|
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const method of webFrameMethodsWithResult) {
|
for (const method of webFrameMethodsWithResult) {
|
||||||
webContents[method] = function (...args) {
|
this[method] = function (...args) {
|
||||||
const callback = args[args.length - 1]
|
const callback = args[args.length - 1]
|
||||||
const actualArgs = args.slice(0, args.length - 2)
|
const actualArgs = args.slice(0, args.length - 2)
|
||||||
syncWebFrameMethods.call(this, getNextId(), method, callback, ...actualArgs)
|
syncWebFrameMethods.call(this, getNextId(), method, callback, ...actualArgs)
|
||||||
|
@ -156,7 +155,7 @@ const wrapWebContents = function (webContents) {
|
||||||
|
|
||||||
// Make sure webContents.executeJavaScript would run the code only when the
|
// Make sure webContents.executeJavaScript would run the code only when the
|
||||||
// webContents has been loaded.
|
// webContents has been loaded.
|
||||||
webContents.executeJavaScript = function (code, hasUserGesture, callback) {
|
this.executeJavaScript = function (code, hasUserGesture, callback) {
|
||||||
const requestId = getNextId()
|
const requestId = getNextId()
|
||||||
if (typeof hasUserGesture === 'function') {
|
if (typeof hasUserGesture === 'function') {
|
||||||
callback = hasUserGesture
|
callback = hasUserGesture
|
||||||
|
@ -172,10 +171,10 @@ const wrapWebContents = function (webContents) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch IPC messages to the ipc module.
|
// Dispatch IPC messages to the ipc module.
|
||||||
webContents.on('ipc-message', function (event, [channel, ...args]) {
|
this.on('ipc-message', function (event, [channel, ...args]) {
|
||||||
ipcMain.emit(channel, event, ...args)
|
ipcMain.emit(channel, event, ...args)
|
||||||
})
|
})
|
||||||
webContents.on('ipc-message-sync', function (event, [channel, ...args]) {
|
this.on('ipc-message-sync', function (event, [channel, ...args]) {
|
||||||
Object.defineProperty(event, 'returnValue', {
|
Object.defineProperty(event, 'returnValue', {
|
||||||
set: function (value) {
|
set: function (value) {
|
||||||
return event.sendReply(JSON.stringify(value))
|
return event.sendReply(JSON.stringify(value))
|
||||||
|
@ -186,24 +185,24 @@ const wrapWebContents = function (webContents) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle context menu action request from pepper plugin.
|
// Handle context menu action request from pepper plugin.
|
||||||
webContents.on('pepper-context-menu', function (event, params) {
|
this.on('pepper-context-menu', function (event, params) {
|
||||||
const menu = Menu.buildFromTemplate(params.menu)
|
const menu = Menu.buildFromTemplate(params.menu)
|
||||||
menu.popup(params.x, params.y)
|
menu.popup(params.x, params.y)
|
||||||
})
|
})
|
||||||
|
|
||||||
// The devtools requests the webContents to reload.
|
// The devtools requests the webContents to reload.
|
||||||
webContents.on('devtools-reload-page', function () {
|
this.on('devtools-reload-page', function () {
|
||||||
webContents.reload()
|
this.reload()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Delays the page-title-updated event to next tick.
|
// Delays the page-title-updated event to next tick.
|
||||||
webContents.on('-page-title-updated', function (...args) {
|
this.on('-page-title-updated', function (...args) {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
this.emit.apply(this, ['page-title-updated'].concat(args))
|
this.emit.apply(this, ['page-title-updated'].concat(args))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
webContents.printToPDF = function (options, callback) {
|
this.printToPDF = function (options, callback) {
|
||||||
const printingSetting = Object.assign({}, defaultPrintingSetting)
|
const printingSetting = Object.assign({}, defaultPrintingSetting)
|
||||||
if (options.landscape) {
|
if (options.landscape) {
|
||||||
printingSetting.landscape = options.landscape
|
printingSetting.landscape = options.landscape
|
||||||
|
@ -244,19 +243,14 @@ const wrapWebContents = function (webContents) {
|
||||||
this._printToPDF(printingSetting, callback)
|
this._printToPDF(printingSetting, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.emit('web-contents-created', {}, webContents)
|
app.emit('web-contents-created', {}, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding._setWrapWebContents(wrapWebContents)
|
const {Debugger} = process.atomBinding('debugger')
|
||||||
|
|
||||||
// Add JavaScript wrappers for Debugger class.
|
Object.setPrototypeOf(Debugger.prototype, EventEmitter.prototype)
|
||||||
const wrapDebugger = function (webContentsDebugger) {
|
|
||||||
// debugger is an EventEmitter.
|
|
||||||
Object.setPrototypeOf(webContentsDebugger.__proto__, EventEmitter.prototype)
|
|
||||||
}
|
|
||||||
|
|
||||||
debuggerBinding._setWrapDebugger(wrapDebugger)
|
|
||||||
|
|
||||||
|
// Public APIs.
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create (options = {}) {
|
create (options = {}) {
|
||||||
return binding.create(options)
|
return binding.create(options)
|
||||||
|
|
|
@ -6,10 +6,6 @@ const util = require('util')
|
||||||
const Module = require('module')
|
const Module = require('module')
|
||||||
const v8 = require('v8')
|
const v8 = require('v8')
|
||||||
|
|
||||||
// Save the prototype of EventEmitter, must be called before using native API.
|
|
||||||
const {setEventEmitterPrototype} = process.binding('atom_browser_event_emitter')
|
|
||||||
setEventEmitterPrototype(require('events').EventEmitter)
|
|
||||||
|
|
||||||
// We modified the original process.argv to let node.js load the atom.js,
|
// We modified the original process.argv to let node.js load the atom.js,
|
||||||
// we need to restore it here.
|
// we need to restore it here.
|
||||||
process.argv.splice(1, 1)
|
process.argv.splice(1, 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue