Merge pull request #6688 from electron/constructor-refactor
Use FunctionTemplate instead of ObjectTemplate for native classes
This commit is contained in:
commit
91169396f6
64 changed files with 358 additions and 387 deletions
|
@ -531,9 +531,10 @@ mate::Handle<App> App::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void App::BuildPrototype(
|
void App::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
|
prototype->SetClassName(mate::StringToV8(isolate, "App"));
|
||||||
auto browser = base::Unretained(Browser::Get());
|
auto browser = base::Unretained(Browser::Get());
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
||||||
.SetMethod("exit", base::Bind(&Browser::Exit, browser))
|
.SetMethod("exit", base::Bind(&Browser::Exit, browser))
|
||||||
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
||||||
|
@ -638,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",
|
||||||
|
|
|
@ -40,7 +40,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
static mate::Handle<App> Create(v8::Isolate* isolate);
|
static mate::Handle<App> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
// Called when window with disposition needs to be created.
|
// Called when window with disposition needs to be created.
|
||||||
void OnCreateWindow(const GURL& target_url,
|
void OnCreateWindow(const GURL& target_url,
|
||||||
|
|
|
@ -106,8 +106,9 @@ mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void AutoUpdater::BuildPrototype(
|
void AutoUpdater::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
|
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
|
||||||
.SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL)
|
.SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL)
|
||||||
.SetMethod("setFeedURL", &AutoUpdater::SetFeedURL)
|
.SetMethod("setFeedURL", &AutoUpdater::SetFeedURL)
|
||||||
|
@ -121,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
|
||||||
|
|
|
@ -24,7 +24,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
|
||||||
static mate::Handle<AutoUpdater> Create(v8::Isolate* isolate);
|
static mate::Handle<AutoUpdater> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit AutoUpdater(v8::Isolate* isolate);
|
explicit AutoUpdater(v8::Isolate* isolate);
|
||||||
|
|
|
@ -248,8 +248,9 @@ mate::Handle<Cookies> Cookies::Create(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Cookies::BuildPrototype(v8::Isolate* isolate,
|
void Cookies::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Cookies"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("get", &Cookies::Get)
|
.SetMethod("get", &Cookies::Get)
|
||||||
.SetMethod("remove", &Cookies::Remove)
|
.SetMethod("remove", &Cookies::Remove)
|
||||||
.SetMethod("set", &Cookies::Set);
|
.SetMethod("set", &Cookies::Set);
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
|
||||||
|
|
||||||
// mate::TrackableObject:
|
// mate::TrackableObject:
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
|
@ -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,37 +143,33 @@ 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
|
||||||
void Debugger::BuildPrototype(v8::Isolate* isolate,
|
void Debugger::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Debugger"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("attach", &Debugger::Attach)
|
.SetMethod("attach", &Debugger::Attach)
|
||||||
.SetMethod("isAttached", &Debugger::IsAttached)
|
.SetMethod("isAttached", &Debugger::IsAttached)
|
||||||
.SetMethod("detach", &Debugger::Detach)
|
.SetMethod("detach", &Debugger::Detach)
|
||||||
.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
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Debugger: public mate::TrackableObject<Debugger>,
|
||||||
|
|
||||||
// mate::TrackableObject:
|
// mate::TrackableObject:
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Debugger(v8::Isolate* isolate, content::WebContents* web_contents);
|
Debugger(v8::Isolate* isolate, content::WebContents* web_contents);
|
||||||
|
|
|
@ -99,8 +99,9 @@ mate::Handle<DesktopCapturer> DesktopCapturer::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void DesktopCapturer::BuildPrototype(
|
void DesktopCapturer::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "DesktopCapturer"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("startHandling", &DesktopCapturer::StartHandling);
|
.SetMethod("startHandling", &DesktopCapturer::StartHandling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class DesktopCapturer: public mate::EventEmitter<DesktopCapturer>,
|
||||||
static mate::Handle<DesktopCapturer> Create(v8::Isolate* isolate);
|
static mate::Handle<DesktopCapturer> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
void StartHandling(bool capture_window,
|
void StartHandling(bool capture_window,
|
||||||
bool capture_screen,
|
bool capture_screen,
|
||||||
|
|
|
@ -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
|
||||||
|
@ -167,8 +163,9 @@ base::FilePath DownloadItem::GetSavePath() const {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void DownloadItem::BuildPrototype(v8::Isolate* isolate,
|
void DownloadItem::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "DownloadItem"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("pause", &DownloadItem::Pause)
|
.SetMethod("pause", &DownloadItem::Pause)
|
||||||
.SetMethod("isPaused", &DownloadItem::IsPaused)
|
.SetMethod("isPaused", &DownloadItem::IsPaused)
|
||||||
|
@ -196,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()] =
|
||||||
|
@ -204,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
|
||||||
|
@ -217,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
|
||||||
|
|
|
@ -24,7 +24,7 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
|
||||||
content::DownloadItem* item);
|
content::DownloadItem* item);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
void Pause();
|
void Pause();
|
||||||
bool IsPaused() const;
|
bool IsPaused() const;
|
||||||
|
|
|
@ -74,8 +74,9 @@ mate::Handle<GlobalShortcut> GlobalShortcut::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void GlobalShortcut::BuildPrototype(
|
void GlobalShortcut::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("register", &GlobalShortcut::Register)
|
.SetMethod("register", &GlobalShortcut::Register)
|
||||||
.SetMethod("isRegistered", &GlobalShortcut::IsRegistered)
|
.SetMethod("isRegistered", &GlobalShortcut::IsRegistered)
|
||||||
.SetMethod("unregister", &GlobalShortcut::Unregister)
|
.SetMethod("unregister", &GlobalShortcut::Unregister)
|
||||||
|
|
|
@ -24,7 +24,7 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
|
||||||
static mate::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
|
static mate::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit GlobalShortcut(v8::Isolate* isolate);
|
explicit GlobalShortcut(v8::Isolate* isolate);
|
||||||
|
|
|
@ -19,9 +19,10 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
Menu::Menu(v8::Isolate* isolate)
|
Menu::Menu(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
|
||||||
: model_(new AtomMenuModel(this)),
|
: model_(new AtomMenuModel(this)),
|
||||||
parent_(nullptr) {
|
parent_(nullptr) {
|
||||||
|
InitWith(isolate, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::~Menu() {
|
Menu::~Menu() {
|
||||||
|
@ -154,8 +155,9 @@ bool Menu::IsVisibleAt(int index) const {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Menu::BuildPrototype(v8::Isolate* isolate,
|
void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Menu"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("insertItem", &Menu::InsertItemAt)
|
.SetMethod("insertItem", &Menu::InsertItemAt)
|
||||||
.SetMethod("insertCheckItem", &Menu::InsertCheckItemAt)
|
.SetMethod("insertCheckItem", &Menu::InsertCheckItemAt)
|
||||||
|
@ -184,14 +186,15 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::Menu;
|
||||||
|
|
||||||
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) {
|
||||||
using atom::api::Menu;
|
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Menu>(
|
Menu::SetConstructor(isolate, base::Bind(&Menu::New));
|
||||||
isolate, "Menu", base::Bind(&Menu::Create));
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("Menu", static_cast<v8::Local<v8::Value>>(constructor));
|
dict.Set("Menu", Menu::GetConstructor(isolate)->GetFunction());
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
||||||
dict.SetMethod("sendActionToFirstResponder",
|
dict.SetMethod("sendActionToFirstResponder",
|
||||||
|
|
|
@ -20,10 +20,10 @@ namespace api {
|
||||||
class Menu : public mate::TrackableObject<Menu>,
|
class Menu : public mate::TrackableObject<Menu>,
|
||||||
public AtomMenuModel::Delegate {
|
public AtomMenuModel::Delegate {
|
||||||
public:
|
public:
|
||||||
static mate::WrappableBase* Create(v8::Isolate* isolate);
|
static mate::WrappableBase* New(mate::Arguments* args);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
// Set the global menubar.
|
// Set the global menubar.
|
||||||
|
@ -36,7 +36,7 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||||
AtomMenuModel* model() const { return model_.get(); }
|
AtomMenuModel* model() const { return model_.get(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Menu(v8::Isolate* isolate);
|
Menu(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
|
||||||
~Menu() override;
|
~Menu() override;
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace api {
|
||||||
|
|
||||||
class MenuMac : public Menu {
|
class MenuMac : public Menu {
|
||||||
protected:
|
protected:
|
||||||
explicit MenuMac(v8::Isolate* isolate);
|
MenuMac(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
|
||||||
|
|
||||||
void PopupAt(Window* window, int x, int y, int positioning_item) override;
|
void PopupAt(Window* window, int x, int y, int positioning_item) override;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
MenuMac::MenuMac(v8::Isolate* isolate) : Menu(isolate) {
|
MenuMac::MenuMac(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
|
||||||
|
: Menu(isolate, wrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuMac::PopupAt(Window* window, int x, int y, int positioning_item) {
|
void MenuMac::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
|
@ -94,8 +95,8 @@ void Menu::SendActionToFirstResponder(const std::string& action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::WrappableBase* Menu::Create(v8::Isolate* isolate) {
|
mate::WrappableBase* Menu::New(mate::Arguments* args) {
|
||||||
return new MenuMac(isolate);
|
return new MenuMac(args->isolate(), args->GetThis());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -14,7 +14,8 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
MenuViews::MenuViews(v8::Isolate* isolate) : Menu(isolate) {
|
MenuViews::MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
|
||||||
|
: Menu(isolate, wrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
|
@ -53,8 +54,8 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::WrappableBase* Menu::Create(v8::Isolate* isolate) {
|
mate::WrappableBase* Menu::New(mate::Arguments* args) {
|
||||||
return new MenuViews(isolate);
|
return new MenuViews(args->isolate(), args->GetThis());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace api {
|
||||||
|
|
||||||
class MenuViews : public Menu {
|
class MenuViews : public Menu {
|
||||||
public:
|
public:
|
||||||
explicit MenuViews(v8::Isolate* isolate);
|
MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PopupAt(Window* window, int x, int y, int positioning_item) override;
|
void PopupAt(Window* window, int x, int y, int positioning_item) override;
|
||||||
|
|
|
@ -52,8 +52,8 @@ v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void PowerMonitor::BuildPrototype(
|
void PowerMonitor::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype);
|
prototype->SetClassName(mate::StringToV8(isolate, "PowerMonitor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
@ -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
|
||||||
|
|
|
@ -20,7 +20,7 @@ class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
|
||||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PowerMonitor(v8::Isolate* isolate);
|
explicit PowerMonitor(v8::Isolate* isolate);
|
||||||
|
|
|
@ -105,8 +105,9 @@ mate::Handle<PowerSaveBlocker> PowerSaveBlocker::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void PowerSaveBlocker::BuildPrototype(
|
void PowerSaveBlocker::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "PowerSaveBlocker"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("start", &PowerSaveBlocker::Start)
|
.SetMethod("start", &PowerSaveBlocker::Start)
|
||||||
.SetMethod("stop", &PowerSaveBlocker::Stop)
|
.SetMethod("stop", &PowerSaveBlocker::Stop)
|
||||||
.SetMethod("isStarted", &PowerSaveBlocker::IsStarted);
|
.SetMethod("isStarted", &PowerSaveBlocker::IsStarted);
|
||||||
|
|
|
@ -25,7 +25,7 @@ class PowerSaveBlocker : public mate::TrackableObject<PowerSaveBlocker> {
|
||||||
static mate::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
static mate::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PowerSaveBlocker(v8::Isolate* isolate);
|
explicit PowerSaveBlocker(v8::Isolate* isolate);
|
||||||
|
|
|
@ -160,8 +160,9 @@ mate::Handle<Protocol> Protocol::Create(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Protocol::BuildPrototype(
|
void Protocol::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Protocol"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("registerServiceWorkerSchemes",
|
.SetMethod("registerServiceWorkerSchemes",
|
||||||
&Protocol::RegisterServiceWorkerSchemes)
|
&Protocol::RegisterServiceWorkerSchemes)
|
||||||
.SetMethod("registerStringProtocol",
|
.SetMethod("registerStringProtocol",
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
|
@ -53,8 +53,10 @@ void RenderProcessPreferences::RemoveEntry(int id) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void RenderProcessPreferences::BuildPrototype(
|
void RenderProcessPreferences::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(
|
||||||
|
mate::StringToV8(isolate, "RenderProcessPreferences"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("addEntry", &RenderProcessPreferences::AddEntry)
|
.SetMethod("addEntry", &RenderProcessPreferences::AddEntry)
|
||||||
.SetMethod("removeEntry", &RenderProcessPreferences::RemoveEntry);
|
.SetMethod("removeEntry", &RenderProcessPreferences::RemoveEntry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class RenderProcessPreferences
|
||||||
ForAllWebContents(v8::Isolate* isolate);
|
ForAllWebContents(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
int AddEntry(const base::DictionaryValue& entry);
|
int AddEntry(const base::DictionaryValue& entry);
|
||||||
void RemoveEntry(int id);
|
void RemoveEntry(int id);
|
||||||
|
|
|
@ -113,8 +113,9 @@ v8::Local<v8::Value> Screen::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Screen::BuildPrototype(
|
void Screen::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Screen"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("getCursorScreenPoint", &Screen::GetCursorScreenPoint)
|
.SetMethod("getCursorScreenPoint", &Screen::GetCursorScreenPoint)
|
||||||
.SetMethod("getPrimaryDisplay", &Screen::GetPrimaryDisplay)
|
.SetMethod("getPrimaryDisplay", &Screen::GetPrimaryDisplay)
|
||||||
.SetMethod("getAllDisplays", &Screen::GetAllDisplays)
|
.SetMethod("getAllDisplays", &Screen::GetAllDisplays)
|
||||||
|
@ -128,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
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Screen : public mate::EventEmitter<Screen>,
|
||||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Screen(v8::Isolate* isolate, display::Screen* screen);
|
Screen(v8::Isolate* isolate, display::Screen* screen);
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -570,8 +565,9 @@ mate::Handle<Session> Session::FromPartition(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Session::BuildPrototype(v8::Isolate* isolate,
|
void Session::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Session"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("resolveProxy", &Session::ResolveProxy)
|
.SetMethod("resolveProxy", &Session::ResolveProxy)
|
||||||
.SetMethod("getCacheSize", &Session::DoCacheAction<CacheAction::STATS>)
|
.SetMethod("getCacheSize", &Session::DoCacheAction<CacheAction::STATS>)
|
||||||
|
@ -595,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()) {
|
||||||
|
@ -613,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
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
|
|
||||||
// mate::TrackableObject:
|
// mate::TrackableObject:
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
// Methods.
|
// Methods.
|
||||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||||
|
|
|
@ -44,8 +44,9 @@ mate::Handle<SystemPreferences> SystemPreferences::Create(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void SystemPreferences::BuildPrototype(
|
void SystemPreferences::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "SystemPreferences"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
|
@ -68,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
|
||||||
|
|
|
@ -24,7 +24,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
||||||
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
bool IsAeroGlassEnabled();
|
bool IsAeroGlassEnabled();
|
||||||
|
|
|
@ -60,10 +60,13 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
Tray::Tray(v8::Isolate* isolate, mate::Handle<NativeImage> image)
|
Tray::Tray(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
|
mate::Handle<NativeImage> image)
|
||||||
: tray_icon_(TrayIcon::Create()) {
|
: tray_icon_(TrayIcon::Create()) {
|
||||||
SetImage(isolate, image);
|
SetImage(isolate, image);
|
||||||
tray_icon_->AddObserver(this);
|
tray_icon_->AddObserver(this);
|
||||||
|
|
||||||
|
InitWith(isolate, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tray::~Tray() {
|
Tray::~Tray() {
|
||||||
|
@ -72,14 +75,13 @@ Tray::~Tray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::WrappableBase* Tray::New(v8::Isolate* isolate,
|
mate::WrappableBase* Tray::New(mate::Handle<NativeImage> image,
|
||||||
mate::Handle<NativeImage> image) {
|
mate::Arguments* args) {
|
||||||
if (!Browser::Get()->is_ready()) {
|
if (!Browser::Get()->is_ready()) {
|
||||||
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
args->ThrowError("Cannot create Tray before app is ready");
|
||||||
isolate, "Cannot create Tray before app is ready")));
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return new Tray(isolate, image);
|
return new Tray(args->isolate(), args->GetThis(), image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
|
@ -199,8 +201,9 @@ gfx::Rect Tray::GetBounds() {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Tray::BuildPrototype(v8::Isolate* isolate,
|
void Tray::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Tray"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("setImage", &Tray::SetImage)
|
.SetMethod("setImage", &Tray::SetImage)
|
||||||
.SetMethod("setPressedImage", &Tray::SetPressedImage)
|
.SetMethod("setPressedImage", &Tray::SetPressedImage)
|
||||||
|
@ -220,14 +223,15 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::Tray;
|
||||||
|
|
||||||
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) {
|
||||||
using atom::api::Tray;
|
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Tray>(
|
Tray::SetConstructor(isolate, base::Bind(&Tray::New));
|
||||||
isolate, "Tray", base::Bind(&Tray::New));
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("Tray", static_cast<v8::Local<v8::Value>>(constructor));
|
dict.Set("Tray", Tray::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -35,14 +35,15 @@ class NativeImage;
|
||||||
class Tray : public mate::TrackableObject<Tray>,
|
class Tray : public mate::TrackableObject<Tray>,
|
||||||
public TrayIconObserver {
|
public TrayIconObserver {
|
||||||
public:
|
public:
|
||||||
static mate::WrappableBase* New(
|
static mate::WrappableBase* New(mate::Handle<NativeImage> image,
|
||||||
v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
mate::Arguments* args);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Tray(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
Tray(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
|
mate::Handle<NativeImage> image);
|
||||||
~Tray() override;
|
~Tray() override;
|
||||||
|
|
||||||
// TrayIconObserver:
|
// TrayIconObserver:
|
||||||
|
|
|
@ -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();
|
||||||
|
@ -1364,8 +1360,9 @@ v8::Local<v8::Value> WebContents::Debugger(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void WebContents::BuildPrototype(v8::Isolate* isolate,
|
void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "WebContents"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("getId", &WebContents::GetID)
|
.SetMethod("getId", &WebContents::GetID)
|
||||||
.SetMethod("equal", &WebContents::Equal)
|
.SetMethod("equal", &WebContents::Equal)
|
||||||
|
@ -1469,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
|
||||||
|
|
|
@ -63,7 +63,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
v8::Isolate* isolate, const mate::Dictionary& options);
|
v8::Isolate* isolate, const mate::Dictionary& options);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
int GetID() const;
|
int GetID() const;
|
||||||
Type GetType() const;
|
Type GetType() const;
|
||||||
|
|
|
@ -88,8 +88,9 @@ mate::Handle<WebRequest> WebRequest::Create(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void WebRequest::BuildPrototype(v8::Isolate* isolate,
|
void WebRequest::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "WebRequest"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("onBeforeRequest",
|
.SetMethod("onBeforeRequest",
|
||||||
&WebRequest::SetResponseListener<
|
&WebRequest::SetResponseListener<
|
||||||
AtomNetworkDelegate::kOnBeforeRequest>)
|
AtomNetworkDelegate::kOnBeforeRequest>)
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WebRequest : public mate::TrackableObject<WebRequest> {
|
||||||
AtomBrowserContext* browser_context);
|
AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WebRequest(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
WebRequest(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
|
@ -67,7 +67,8 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
|
const mate::Dictionary& options) {
|
||||||
// Use options.webPreferences to create WebContents.
|
// Use options.webPreferences to create WebContents.
|
||||||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||||
options.Get(options::kWebPreferences, &web_preferences);
|
options.Get(options::kWebPreferences, &web_preferences);
|
||||||
|
@ -107,7 +108,14 @@ Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||||
|
|
||||||
window_->InitFromOptions(options);
|
window_->InitFromOptions(options);
|
||||||
window_->AddObserver(this);
|
window_->AddObserver(this);
|
||||||
|
|
||||||
|
InitWith(isolate, wrapper);
|
||||||
AttachAsUserData(window_.get());
|
AttachAsUserData(window_.get());
|
||||||
|
|
||||||
|
// We can only append this window to parent window's child windows after this
|
||||||
|
// window's JS wrapper gets initialized.
|
||||||
|
if (!parent.IsEmpty())
|
||||||
|
parent->child_windows_.Set(isolate, ID(), wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
|
@ -119,17 +127,6 @@ Window::~Window() {
|
||||||
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
|
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::AfterInit(v8::Isolate* isolate) {
|
|
||||||
mate::TrackableObject<Window>::AfterInit(isolate);
|
|
||||||
|
|
||||||
// We can only append this window to parent window's child windows after this
|
|
||||||
// window's JS wrapper gets initialized.
|
|
||||||
mate::Handle<Window> parent;
|
|
||||||
if (!parent_window_.IsEmpty() &&
|
|
||||||
mate::ConvertFromV8(isolate, GetParentWindow(), &parent))
|
|
||||||
parent->child_windows_.Set(isolate, ID(), GetWrapper());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::WillCloseWindow(bool* prevent_default) {
|
void Window::WillCloseWindow(bool* prevent_default) {
|
||||||
*prevent_default = Emit("close");
|
*prevent_default = Emit("close");
|
||||||
}
|
}
|
||||||
|
@ -262,10 +259,9 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::WrappableBase* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
|
mate::WrappableBase* Window::New(mate::Arguments* args) {
|
||||||
if (!Browser::Get()->is_ready()) {
|
if (!Browser::Get()->is_ready()) {
|
||||||
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
args->ThrowError("Cannot create BrowserWindow before app is ready");
|
||||||
isolate, "Cannot create BrowserWindow before app is ready")));
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,10 +272,10 @@ mate::WrappableBase* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
|
||||||
|
|
||||||
mate::Dictionary options;
|
mate::Dictionary options;
|
||||||
if (!(args->Length() == 1 && args->GetNext(&options))) {
|
if (!(args->Length() == 1 && args->GetNext(&options))) {
|
||||||
options = mate::Dictionary::CreateEmpty(isolate);
|
options = mate::Dictionary::CreateEmpty(args->isolate());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Window(isolate, options);
|
return new Window(args->isolate(), args->GetThis(), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::Close() {
|
void Window::Close() {
|
||||||
|
@ -750,8 +746,9 @@ void Window::RemoveFromParentChildWindows() {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Window::BuildPrototype(v8::Isolate* isolate,
|
void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("close", &Window::Close)
|
.SetMethod("close", &Window::Close)
|
||||||
.SetMethod("focus", &Window::Focus)
|
.SetMethod("focus", &Window::Focus)
|
||||||
|
@ -873,9 +870,10 @@ using atom::api::Window;
|
||||||
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();
|
||||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
|
Window::SetConstructor(isolate, base::Bind(&Window::New));
|
||||||
isolate, "BrowserWindow", base::Bind(&Window::New));
|
|
||||||
mate::Dictionary browser_window(isolate, constructor);
|
mate::Dictionary browser_window(
|
||||||
|
isolate, Window::GetConstructor(isolate)->GetFunction());
|
||||||
browser_window.SetMethod("fromId",
|
browser_window.SetMethod("fromId",
|
||||||
&mate::TrackableObject<Window>::FromWeakMapID);
|
&mate::TrackableObject<Window>::FromWeakMapID);
|
||||||
browser_window.SetMethod("getAllWindows",
|
browser_window.SetMethod("getAllWindows",
|
||||||
|
|
|
@ -40,10 +40,10 @@ class WebContents;
|
||||||
class Window : public mate::TrackableObject<Window>,
|
class Window : public mate::TrackableObject<Window>,
|
||||||
public NativeWindowObserver {
|
public NativeWindowObserver {
|
||||||
public:
|
public:
|
||||||
static mate::WrappableBase* New(v8::Isolate* isolate, mate::Arguments* args);
|
static mate::WrappableBase* New(mate::Arguments* args);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
// Returns the BrowserWindow object from |native_window|.
|
// Returns the BrowserWindow object from |native_window|.
|
||||||
static v8::Local<v8::Value> From(v8::Isolate* isolate,
|
static v8::Local<v8::Value> From(v8::Isolate* isolate,
|
||||||
|
@ -52,12 +52,10 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
NativeWindow* window() const { return window_.get(); }
|
NativeWindow* window() const { return window_.get(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Window(v8::Isolate* isolate, const mate::Dictionary& options);
|
Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
|
const mate::Dictionary& options);
|
||||||
~Window() override;
|
~Window() override;
|
||||||
|
|
||||||
// TrackableObject:
|
|
||||||
void AfterInit(v8::Isolate* isolate) override;
|
|
||||||
|
|
||||||
// NativeWindowObserver:
|
// NativeWindowObserver:
|
||||||
void WillCloseWindow(bool* prevent_default) override;
|
void WillCloseWindow(bool* prevent_default) override;
|
||||||
void WillDestoryNativeObject() override;
|
void WillDestoryNativeObject() override;
|
||||||
|
|
|
@ -58,8 +58,9 @@ Handle<Event> Event::Create(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Event::BuildPrototype(
|
void Event::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Event"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("preventDefault", &Event::PreventDefault)
|
.SetMethod("preventDefault", &Event::PreventDefault)
|
||||||
.SetMethod("sendReply", &Event::SendReply);
|
.SetMethod("sendReply", &Event::SendReply);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Event : public Wrappable<Event>,
|
||||||
static Handle<Event> Create(v8::Isolate* isolate);
|
static Handle<Event> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
// Pass the sender and message to be replied.
|
// Pass the sender and message to be replied.
|
||||||
void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);
|
void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "ui/events/event_constants.h"
|
#include "ui/events/event_constants.h"
|
||||||
|
|
||||||
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class IDUserData : public base::SupportsUserData::Data {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TrackableObjectBase::TrackableObjectBase()
|
TrackableObjectBase::TrackableObjectBase()
|
||||||
: weak_map_id_(0), wrapped_(nullptr), weak_factory_(this) {
|
: weak_map_id_(0), weak_factory_(this) {
|
||||||
cleanup_ = RegisterDestructionCallback(GetDestroyClosure());
|
cleanup_ = RegisterDestructionCallback(GetDestroyClosure());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,14 +46,7 @@ void TrackableObjectBase::Destroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
|
void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
|
||||||
if (weak_map_id_ != 0) {
|
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
|
||||||
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
|
|
||||||
wrapped_ = nullptr;
|
|
||||||
} else {
|
|
||||||
// If the TrackableObjectBase is not ready yet then delay SetUserData until
|
|
||||||
// AfterInit is called.
|
|
||||||
wrapped_ = wrapped;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -44,7 +44,6 @@ class TrackableObjectBase {
|
||||||
static base::Closure RegisterDestructionCallback(const base::Closure& c);
|
static base::Closure RegisterDestructionCallback(const base::Closure& c);
|
||||||
|
|
||||||
int32_t weak_map_id_;
|
int32_t weak_map_id_;
|
||||||
base::SupportsUserData* wrapped_;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
@ -110,14 +109,13 @@ class TrackableObject : public TrackableObjectBase,
|
||||||
RemoveFromWeakMap();
|
RemoveFromWeakMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AfterInit(v8::Isolate* isolate) override {
|
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override {
|
||||||
|
WrappableBase::InitWith(isolate, wrapper);
|
||||||
if (!weak_map_) {
|
if (!weak_map_) {
|
||||||
weak_map_ = new atom::KeyWeakMap<int32_t>;
|
weak_map_ = new atom::KeyWeakMap<int32_t>;
|
||||||
}
|
}
|
||||||
weak_map_id_ = ++next_id_;
|
weak_map_id_ = ++next_id_;
|
||||||
weak_map_->Set(isolate, weak_map_id_, Wrappable<T>::GetWrapper());
|
weak_map_->Set(isolate, weak_map_id_, wrapper);
|
||||||
if (wrapped_)
|
|
||||||
AttachAsUserData(wrapped_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -29,8 +29,9 @@ class Archive : public mate::Wrappable<Archive> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BuildPrototype(
|
static void BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "Archive"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetProperty("path", &Archive::GetPath)
|
.SetProperty("path", &Archive::GetPath)
|
||||||
.SetMethod("getFileInfo", &Archive::GetFileInfo)
|
.SetMethod("getFileInfo", &Archive::GetFileInfo)
|
||||||
.SetMethod("stat", &Archive::Stat)
|
.SetMethod("stat", &Archive::Stat)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "atom/common/key_weak_map.h"
|
#include "atom/common/key_weak_map.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
#include "native_mate/wrappable.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -21,8 +22,9 @@ class KeyWeakMap : public mate::Wrappable<KeyWeakMap<K>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "KeyWeakMap"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("set", &KeyWeakMap<K>::Set)
|
.SetMethod("set", &KeyWeakMap<K>::Set)
|
||||||
.SetMethod("get", &KeyWeakMap<K>::Get)
|
.SetMethod("get", &KeyWeakMap<K>::Get)
|
||||||
.SetMethod("has", &KeyWeakMap<K>::Has)
|
.SetMethod("has", &KeyWeakMap<K>::Has)
|
||||||
|
|
|
@ -355,8 +355,9 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void NativeImage::BuildPrototype(
|
void NativeImage::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "NativeImage"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("toPNG", &NativeImage::ToPNG)
|
.SetMethod("toPNG", &NativeImage::ToPNG)
|
||||||
.SetMethod("toJPEG", &NativeImage::ToJPEG)
|
.SetMethod("toJPEG", &NativeImage::ToJPEG)
|
||||||
.SetMethod("toBitmap", &NativeImage::ToBitmap)
|
.SetMethod("toBitmap", &NativeImage::ToBitmap)
|
||||||
|
|
|
@ -52,7 +52,7 @@ class NativeImage : public mate::Wrappable<NativeImage> {
|
||||||
v8::Isolate* isolate, const GURL& url);
|
v8::Isolate* isolate, const GURL& url);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
HICON GetHICON(int size);
|
HICON GetHICON(int size);
|
||||||
|
|
|
@ -187,8 +187,9 @@ void WebFrame::ClearCache(v8::Isolate* isolate) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void WebFrame::BuildPrototype(
|
void WebFrame::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
prototype->SetClassName(mate::StringToV8(isolate, "WebFrame"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("setName", &WebFrame::SetName)
|
.SetMethod("setName", &WebFrame::SetName)
|
||||||
.SetMethod("setZoomLevel", &WebFrame::SetZoomLevel)
|
.SetMethod("setZoomLevel", &WebFrame::SetZoomLevel)
|
||||||
.SetMethod("getZoomLevel", &WebFrame::GetZoomLevel)
|
.SetMethod("getZoomLevel", &WebFrame::GetZoomLevel)
|
||||||
|
@ -219,11 +220,14 @@ void WebFrame::BuildPrototype(
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::WebFrame;
|
||||||
|
|
||||||
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("webFrame", atom::api::WebFrame::Create(isolate));
|
dict.Set("webFrame", WebFrame::Create(isolate));
|
||||||
|
dict.Set("WebFrame", WebFrame::GetConstructor(isolate)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -32,7 +32,7 @@ class WebFrame : public mate::Wrappable<WebFrame> {
|
||||||
static mate::Handle<WebFrame> Create(v8::Isolate* isolate);
|
static mate::Handle<WebFrame> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit WebFrame(v8::Isolate* isolate);
|
explicit WebFrame(v8::Isolate* isolate);
|
||||||
|
|
|
@ -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, 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, 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, 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, EventEmitter.prototype)
|
Object.setPrototypeOf(PowerMonitor.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
module.exports = powerMonitor
|
module.exports = powerMonitor
|
||||||
|
|
|
@ -9,7 +9,7 @@ Object.setPrototypeOf(module.exports, new Proxy({}, {
|
||||||
if (!app.isReady()) return
|
if (!app.isReady()) return
|
||||||
|
|
||||||
const protocol = session.defaultSession.protocol
|
const protocol = session.defaultSession.protocol
|
||||||
if (!protocol.hasOwnProperty(property)) return
|
if (!Object.getPrototypeOf(protocol).hasOwnProperty(property)) return
|
||||||
|
|
||||||
// Returning a native function directly would throw error.
|
// Returning a native function directly would throw error.
|
||||||
return (...args) => protocol[property](...args)
|
return (...args) => protocol[property](...args)
|
||||||
|
@ -18,7 +18,7 @@ Object.setPrototypeOf(module.exports, new Proxy({}, {
|
||||||
ownKeys () {
|
ownKeys () {
|
||||||
if (!app.isReady()) return []
|
if (!app.isReady()) return []
|
||||||
|
|
||||||
return Object.getOwnPropertyNames(session.defaultSession.protocol)
|
return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.protocol))
|
||||||
},
|
},
|
||||||
|
|
||||||
getOwnPropertyDescriptor (target) {
|
getOwnPropertyDescriptor (target) {
|
||||||
|
|
|
@ -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, 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, 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, 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,24 @@ const defaultPrintingSetting = {
|
||||||
shouldPrintSelectionOnly: false
|
shouldPrintSelectionOnly: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JavaScript implementations of WebContents.
|
||||||
|
const binding = process.atomBinding('web_contents')
|
||||||
|
const {WebContents} = binding
|
||||||
|
|
||||||
|
Object.setPrototypeOf(NavigationController.prototype, EventEmitter.prototype)
|
||||||
|
Object.setPrototypeOf(WebContents.prototype, NavigationController.prototype)
|
||||||
|
|
||||||
|
// WebContents::send(channel, args..)
|
||||||
|
// WebContents::sendToAll(channel, args..)
|
||||||
|
WebContents.prototype.send = function (channel, ...args) {
|
||||||
|
if (channel == null) throw new Error('Missing required channel argument')
|
||||||
|
return this._send(false, channel, args)
|
||||||
|
}
|
||||||
|
WebContents.prototype.sendToAll = function (channel, ...args) {
|
||||||
|
if (channel == null) throw new Error('Missing required channel argument')
|
||||||
|
return this._send(true, channel, args)
|
||||||
|
}
|
||||||
|
|
||||||
// Following methods are mapped to webFrame.
|
// Following methods are mapped to webFrame.
|
||||||
const webFrameMethods = [
|
const webFrameMethods = [
|
||||||
'insertText',
|
'insertText',
|
||||||
|
@ -88,94 +103,112 @@ const webFrameMethods = [
|
||||||
'setZoomLevel',
|
'setZoomLevel',
|
||||||
'setZoomLevelLimits'
|
'setZoomLevelLimits'
|
||||||
]
|
]
|
||||||
|
|
||||||
const webFrameMethodsWithResult = [
|
const webFrameMethodsWithResult = [
|
||||||
'getZoomFactor',
|
'getZoomFactor',
|
||||||
'getZoomLevel'
|
'getZoomLevel'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||||
|
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||||
|
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||||
|
if (callback) callback(result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const syncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||||
|
this.send('ELECTRON_INTERNAL_RENDERER_SYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||||
|
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_SYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||||
|
if (callback) callback(result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const method of webFrameMethods) {
|
||||||
|
WebContents.prototype[method] = function (...args) {
|
||||||
|
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const method of webFrameMethodsWithResult) {
|
||||||
|
WebContents.prototype[method] = function (...args) {
|
||||||
|
const callback = args[args.length - 1]
|
||||||
|
const actualArgs = args.slice(0, args.length - 2)
|
||||||
|
syncWebFrameMethods.call(this, getNextId(), method, callback, ...actualArgs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure WebContents::executeJavaScript would run the code only when the
|
||||||
|
// WebContents has been loaded.
|
||||||
|
WebContents.prototype.executeJavaScript = function (code, hasUserGesture, callback) {
|
||||||
|
const requestId = getNextId()
|
||||||
|
if (typeof hasUserGesture === 'function') {
|
||||||
|
callback = hasUserGesture
|
||||||
|
hasUserGesture = false
|
||||||
|
}
|
||||||
|
if (this.getURL() && !this.isLoadingMainFrame()) {
|
||||||
|
asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
|
||||||
|
} else {
|
||||||
|
this.once('did-finish-load', () => {
|
||||||
|
asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translate the options of printToPDF.
|
||||||
|
WebContents.prototype.printToPDF = function (options, callback) {
|
||||||
|
const printingSetting = Object.assign({}, defaultPrintingSetting)
|
||||||
|
if (options.landscape) {
|
||||||
|
printingSetting.landscape = options.landscape
|
||||||
|
}
|
||||||
|
if (options.marginsType) {
|
||||||
|
printingSetting.marginsType = options.marginsType
|
||||||
|
}
|
||||||
|
if (options.printSelectionOnly) {
|
||||||
|
printingSetting.shouldPrintSelectionOnly = options.printSelectionOnly
|
||||||
|
}
|
||||||
|
if (options.printBackground) {
|
||||||
|
printingSetting.shouldPrintBackgrounds = options.printBackground
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.pageSize) {
|
||||||
|
const pageSize = options.pageSize
|
||||||
|
if (typeof pageSize === 'object') {
|
||||||
|
if (!pageSize.height || !pageSize.width) {
|
||||||
|
return callback(new Error('Must define height and width for pageSize'))
|
||||||
|
}
|
||||||
|
// Dimensions in Microns
|
||||||
|
// 1 meter = 10^6 microns
|
||||||
|
printingSetting.mediaSize = {
|
||||||
|
name: 'CUSTOM',
|
||||||
|
custom_display_name: 'Custom',
|
||||||
|
height_microns: pageSize.height,
|
||||||
|
width_microns: pageSize.width
|
||||||
|
}
|
||||||
|
} else if (PDFPageSizes[pageSize]) {
|
||||||
|
printingSetting.mediaSize = PDFPageSizes[pageSize]
|
||||||
|
} else {
|
||||||
|
return callback(new Error(`Does not support pageSize with ${pageSize}`))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printingSetting.mediaSize = PDFPageSizes['A4']
|
||||||
|
}
|
||||||
|
|
||||||
|
this._printToPDF(printingSetting, callback)
|
||||||
|
}
|
||||||
|
|
||||||
// Add JavaScript wrappers for WebContents class.
|
// Add JavaScript wrappers for WebContents class.
|
||||||
const wrapWebContents = function (webContents) {
|
WebContents.prototype._init = function () {
|
||||||
// webContents is an EventEmitter.
|
// The navigation controller.
|
||||||
Object.setPrototypeOf(webContents, EventEmitter.prototype)
|
NavigationController.call(this, this)
|
||||||
|
|
||||||
// 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::sendToAll(channel, args..)
|
|
||||||
const sendWrapper = (allFrames, channel, ...args) => {
|
|
||||||
if (channel == null) {
|
|
||||||
throw new Error('Missing required channel argument')
|
|
||||||
}
|
|
||||||
return webContents._send(allFrames, channel, args)
|
|
||||||
}
|
|
||||||
webContents.send = sendWrapper.bind(null, false)
|
|
||||||
webContents.sendToAll = sendWrapper.bind(null, true)
|
|
||||||
|
|
||||||
// The navigation controller.
|
|
||||||
const controller = new NavigationController(webContents)
|
|
||||||
for (const name in NavigationController.prototype) {
|
|
||||||
const method = NavigationController.prototype[name]
|
|
||||||
if (method instanceof Function) {
|
|
||||||
webContents[name] = function () {
|
|
||||||
return method.apply(controller, arguments)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
|
||||||
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
|
||||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
|
||||||
if (callback) callback(result)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const syncWebFrameMethods = function (requestId, method, callback, ...args) {
|
|
||||||
this.send('ELECTRON_INTERNAL_RENDERER_SYNC_WEB_FRAME_METHOD', requestId, method, args)
|
|
||||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_SYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
|
||||||
if (callback) callback(result)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mapping webFrame methods.
|
|
||||||
for (const method of webFrameMethods) {
|
|
||||||
webContents[method] = function (...args) {
|
|
||||||
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const method of webFrameMethodsWithResult) {
|
|
||||||
webContents[method] = function (...args) {
|
|
||||||
const callback = args[args.length - 1]
|
|
||||||
const actualArgs = args.slice(0, args.length - 2)
|
|
||||||
syncWebFrameMethods.call(this, getNextId(), method, callback, ...actualArgs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure webContents.executeJavaScript would run the code only when the
|
|
||||||
// webContents has been loaded.
|
|
||||||
webContents.executeJavaScript = function (code, hasUserGesture, callback) {
|
|
||||||
const requestId = getNextId()
|
|
||||||
if (typeof hasUserGesture === 'function') {
|
|
||||||
callback = hasUserGesture
|
|
||||||
hasUserGesture = false
|
|
||||||
}
|
|
||||||
if (this.getURL() && !this.isLoadingMainFrame()) {
|
|
||||||
asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
|
|
||||||
} else {
|
|
||||||
this.once('did-finish-load', () => {
|
|
||||||
asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,77 +219,32 @@ 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) {
|
app.emit('web-contents-created', {}, this)
|
||||||
const printingSetting = Object.assign({}, defaultPrintingSetting)
|
|
||||||
if (options.landscape) {
|
|
||||||
printingSetting.landscape = options.landscape
|
|
||||||
}
|
|
||||||
if (options.marginsType) {
|
|
||||||
printingSetting.marginsType = options.marginsType
|
|
||||||
}
|
|
||||||
if (options.printSelectionOnly) {
|
|
||||||
printingSetting.shouldPrintSelectionOnly = options.printSelectionOnly
|
|
||||||
}
|
|
||||||
if (options.printBackground) {
|
|
||||||
printingSetting.shouldPrintBackgrounds = options.printBackground
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.pageSize) {
|
|
||||||
const pageSize = options.pageSize
|
|
||||||
if (typeof pageSize === 'object') {
|
|
||||||
if (!pageSize.height || !pageSize.width) {
|
|
||||||
return callback(new Error('Must define height and width for pageSize'))
|
|
||||||
}
|
|
||||||
// Dimensions in Microns
|
|
||||||
// 1 meter = 10^6 microns
|
|
||||||
printingSetting.mediaSize = {
|
|
||||||
name: 'CUSTOM',
|
|
||||||
custom_display_name: 'Custom',
|
|
||||||
height_microns: pageSize.height,
|
|
||||||
width_microns: pageSize.width
|
|
||||||
}
|
|
||||||
} else if (PDFPageSizes[pageSize]) {
|
|
||||||
printingSetting.mediaSize = PDFPageSizes[pageSize]
|
|
||||||
} else {
|
|
||||||
return callback(new Error(`Does not support pageSize with ${pageSize}`))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printingSetting.mediaSize = PDFPageSizes['A4']
|
|
||||||
}
|
|
||||||
|
|
||||||
this._printToPDF(printingSetting, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.emit('web-contents-created', {}, webContents)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding._setWrapWebContents(wrapWebContents)
|
// JavaScript wrapper of Debugger.
|
||||||
|
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, EventEmitter.prototype)
|
|
||||||
}
|
|
||||||
|
|
||||||
debuggerBinding._setWrapDebugger(wrapDebugger)
|
|
||||||
|
|
||||||
|
// Public APIs.
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create (options = {}) {
|
create (options = {}) {
|
||||||
return binding.create(options)
|
return binding.create(options)
|
||||||
|
|
|
@ -65,7 +65,7 @@ process.on('uncaughtException', function (error) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Emit 'exit' event on quit.
|
// Emit 'exit' event on quit.
|
||||||
var app = require('electron').app
|
const {app} = require('electron')
|
||||||
|
|
||||||
app.on('quit', function (event, exitCode) {
|
app.on('quit', function (event, exitCode) {
|
||||||
process.emit('exit', exitCode)
|
process.emit('exit', exitCode)
|
||||||
|
@ -86,15 +86,12 @@ if (process.platform === 'win32') {
|
||||||
// form `com.squirrel.PACKAGE-NAME.OUREXE`. We need to call
|
// form `com.squirrel.PACKAGE-NAME.OUREXE`. We need to call
|
||||||
// app.setAppUserModelId with a matching identifier so that renderer processes
|
// app.setAppUserModelId with a matching identifier so that renderer processes
|
||||||
// will inherit this value.
|
// will inherit this value.
|
||||||
var updateDotExe = path.join(
|
const updateDotExe = path.join(path.dirname(process.execPath), '..', 'update.exe')
|
||||||
path.dirname(process.execPath),
|
|
||||||
'..',
|
|
||||||
'update.exe')
|
|
||||||
|
|
||||||
if (fs.statSyncNoException(updateDotExe)) {
|
if (fs.existsSync(updateDotExe)) {
|
||||||
var packageDir = path.dirname(path.resolve(updateDotExe))
|
const packageDir = path.dirname(path.resolve(updateDotExe))
|
||||||
var packageName = path.basename(packageDir).replace(/\s/g, '')
|
const packageName = path.basename(packageDir).replace(/\s/g, '')
|
||||||
var exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '')
|
const exeName = path.basename(process.execPath).replace(/\.exe$/i, '').replace(/\s/g, '')
|
||||||
|
|
||||||
app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`)
|
app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`)
|
||||||
}
|
}
|
||||||
|
@ -108,15 +105,13 @@ require('./rpc-server')
|
||||||
|
|
||||||
// Load the guest view manager.
|
// Load the guest view manager.
|
||||||
require('./guest-view-manager')
|
require('./guest-view-manager')
|
||||||
|
|
||||||
require('./guest-window-manager')
|
require('./guest-window-manager')
|
||||||
|
|
||||||
// Now we try to load app's package.json.
|
// Now we try to load app's package.json.
|
||||||
var packageJson = null
|
let packagePath = null
|
||||||
var searchPaths = ['app', 'app.asar', 'default_app.asar']
|
let packageJson = null
|
||||||
var i, len, packagePath
|
const searchPaths = ['app', 'app.asar', 'default_app.asar']
|
||||||
for (i = 0, len = searchPaths.length; i < len; i++) {
|
for (packagePath of searchPaths) {
|
||||||
packagePath = searchPaths[i]
|
|
||||||
try {
|
try {
|
||||||
packagePath = path.join(process.resourcesPath, packagePath)
|
packagePath = path.join(process.resourcesPath, packagePath)
|
||||||
packageJson = require(path.join(packagePath, 'package.json'))
|
packageJson = require(path.join(packagePath, 'package.json'))
|
||||||
|
@ -157,14 +152,9 @@ if (packageJson.v8Flags != null) {
|
||||||
v8.setFlagsFromString(packageJson.v8Flags)
|
v8.setFlagsFromString(packageJson.v8Flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chrome 42 disables NPAPI plugins by default, reenable them here
|
|
||||||
app.commandLine.appendSwitch('enable-npapi')
|
|
||||||
|
|
||||||
// Set the user path according to application's name.
|
// Set the user path according to application's name.
|
||||||
app.setPath('userData', path.join(app.getPath('appData'), app.getName()))
|
app.setPath('userData', path.join(app.getPath('appData'), app.getName()))
|
||||||
|
|
||||||
app.setPath('userCache', path.join(app.getPath('cache'), app.getName()))
|
app.setPath('userCache', path.join(app.getPath('cache'), app.getName()))
|
||||||
|
|
||||||
app.setAppPath(packagePath)
|
app.setAppPath(packagePath)
|
||||||
|
|
||||||
// Load the chrome extension support.
|
// Load the chrome extension support.
|
||||||
|
@ -177,7 +167,7 @@ require('./desktop-capturer')
|
||||||
require('./api/protocol')
|
require('./api/protocol')
|
||||||
|
|
||||||
// Set main startup script of the app.
|
// Set main startup script of the app.
|
||||||
var mainStartupScript = packageJson.main || 'index.js'
|
const mainStartupScript = packageJson.main || 'index.js'
|
||||||
|
|
||||||
// Finally load app's main.js and transfer control to C++.
|
// Finally load app's main.js and transfer control to C++.
|
||||||
Module._load(path.join(packagePath, mainStartupScript), Module, true)
|
Module._load(path.join(packagePath, mainStartupScript), Module, true)
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const EventEmitter = require('events').EventEmitter
|
const {EventEmitter} = require('events')
|
||||||
|
const {webFrame, WebFrame} = process.atomBinding('web_frame')
|
||||||
|
|
||||||
const webFrame = process.atomBinding('web_frame').webFrame
|
// WebFrame is an EventEmitter.
|
||||||
|
Object.setPrototypeOf(WebFrame.prototype, EventEmitter.prototype)
|
||||||
// webFrame is an EventEmitter.
|
|
||||||
Object.setPrototypeOf(webFrame, EventEmitter.prototype)
|
|
||||||
|
|
||||||
// Lots of webview would subscribe to webFrame's events.
|
// Lots of webview would subscribe to webFrame's events.
|
||||||
webFrame.setMaxListeners(0)
|
webFrame.setMaxListeners(0)
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit d9bfe6a49d8585916bd8dc77165154afeee4e5b6
|
Subproject commit fa483e1fe012f873ad9812a67a66e2b7dbb570c6
|
Loading…
Reference in a new issue