Merge remote-tracking branch 'upstream/master' into speedup-gpu

This commit is contained in:
gellert
2016-08-02 14:59:03 +02:00
79 changed files with 674 additions and 436 deletions

View File

@@ -531,9 +531,10 @@ mate::Handle<App> App::Create(v8::Isolate* isolate) {
// static
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());
mate::ObjectTemplateBuilder(isolate, prototype)
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
.SetMethod("exit", base::Bind(&Browser::Exit, 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();
mate::Dictionary dict(isolate, exports);
dict.Set("App", atom::api::App::GetConstructor(isolate)->GetFunction());
dict.Set("app", atom::api::App::Create(isolate));
dict.SetMethod("appendSwitch", &AppendSwitch);
dict.SetMethod("appendArgument",
@@ -656,6 +658,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
base::Bind(&Browser::DockGetBadgeText, browser));
dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser));
dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser));
dict.SetMethod("dockIsVisible", base::Bind(&Browser::DockIsVisible, browser));
dict.SetMethod("dockSetMenu", &DockSetMenu);
dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser));
#endif

View File

@@ -40,7 +40,7 @@ class App : public AtomBrowserClient::Delegate,
static mate::Handle<App> Create(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.
void OnCreateWindow(const GURL& target_url,

View File

@@ -106,8 +106,9 @@ mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
// static
void AutoUpdater::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
.SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL)
.SetMethod("setFeedURL", &AutoUpdater::SetFeedURL)
@@ -121,11 +122,14 @@ void AutoUpdater::BuildPrototype(
namespace {
using atom::api::AutoUpdater;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
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

View File

@@ -24,7 +24,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
static mate::Handle<AutoUpdater> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit AutoUpdater(v8::Isolate* isolate);

View File

@@ -248,8 +248,9 @@ mate::Handle<Cookies> Cookies::Create(
// static
void Cookies::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Cookies"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("get", &Cookies::Get)
.SetMethod("remove", &Cookies::Remove)
.SetMethod("set", &Cookies::Set);

View File

@@ -41,7 +41,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
// mate::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);

View File

@@ -23,14 +23,6 @@ namespace atom {
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)
: web_contents_(web_contents),
previous_request_id_(0) {
@@ -151,37 +143,33 @@ void Debugger::SendCommand(mate::Arguments* args) {
mate::Handle<Debugger> Debugger::Create(
v8::Isolate* isolate,
content::WebContents* web_contents) {
auto handle = mate::CreateHandle(
isolate, new Debugger(isolate, web_contents));
g_wrap_debugger.Run(handle.ToV8());
return handle;
return mate::CreateHandle(isolate, new Debugger(isolate, web_contents));
}
// static
void Debugger::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Debugger"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("attach", &Debugger::Attach)
.SetMethod("isAttached", &Debugger::IsAttached)
.SetMethod("detach", &Debugger::Detach)
.SetMethod("sendCommand", &Debugger::SendCommand);
}
void SetWrapDebugger(const WrapDebuggerCallback& callback) {
g_wrap_debugger = callback;
}
} // namespace api
} // namespace atom
namespace {
using atom::api::Debugger;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("_setWrapDebugger", &atom::api::SetWrapDebugger);
mate::Dictionary(isolate, exports)
.Set("Debugger", Debugger::GetConstructor(isolate)->GetFunction());
}
} // namespace

View File

@@ -39,7 +39,7 @@ class Debugger: public mate::TrackableObject<Debugger>,
// mate::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
Debugger(v8::Isolate* isolate, content::WebContents* web_contents);

View File

@@ -99,8 +99,9 @@ mate::Handle<DesktopCapturer> DesktopCapturer::Create(v8::Isolate* isolate) {
// static
void DesktopCapturer::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "DesktopCapturer"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("startHandling", &DesktopCapturer::StartHandling);
}

View File

@@ -20,7 +20,7 @@ class DesktopCapturer: public mate::EventEmitter<DesktopCapturer>,
static mate::Handle<DesktopCapturer> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
void StartHandling(bool capture_window,
bool capture_screen,

View File

@@ -11,7 +11,6 @@
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/node_includes.h"
#include "base/memory/linked_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/dictionary.h"
@@ -52,11 +51,7 @@ namespace api {
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, linked_ptr<v8::Global<v8::Value>>> g_download_item_objects;
std::map<uint32_t, v8::Global<v8::Object>> g_download_item_objects;
} // namespace
@@ -76,9 +71,7 @@ DownloadItem::~DownloadItem() {
}
// Remove from the global map.
auto iter = g_download_item_objects.find(weak_map_id());
if (iter != g_download_item_objects.end())
g_download_item_objects.erase(iter);
g_download_item_objects.erase(weak_map_id());
}
void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) {
@@ -170,8 +163,9 @@ base::FilePath DownloadItem::GetSavePath() const {
// static
void DownloadItem::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "DownloadItem"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("pause", &DownloadItem::Pause)
.SetMethod("isPaused", &DownloadItem::IsPaused)
@@ -199,18 +193,13 @@ mate::Handle<DownloadItem> DownloadItem::Create(
return mate::CreateHandle(isolate, static_cast<DownloadItem*>(existing));
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.
g_download_item_objects[handle->weak_map_id()] = make_linked_ptr(
new v8::Global<v8::Value>(isolate, handle.ToV8()));
g_download_item_objects[handle->weak_map_id()] =
v8::Global<v8::Object>(isolate, handle.ToV8());
return handle;
}
void SetWrapDownloadItem(const WrapDownloadItemCallback& callback) {
g_wrap_download_item = callback;
}
} // namespace api
} // namespace atom
@@ -220,8 +209,9 @@ namespace {
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("_setWrapDownloadItem", &atom::api::SetWrapDownloadItem);
mate::Dictionary(isolate, exports)
.Set("DownloadItem",
atom::api::DownloadItem::GetConstructor(isolate)->GetFunction());
}
} // namespace

View File

@@ -24,7 +24,7 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
content::DownloadItem* item);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
void Pause();
bool IsPaused() const;

View File

@@ -74,8 +74,9 @@ mate::Handle<GlobalShortcut> GlobalShortcut::Create(v8::Isolate* isolate) {
// static
void GlobalShortcut::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("register", &GlobalShortcut::Register)
.SetMethod("isRegistered", &GlobalShortcut::IsRegistered)
.SetMethod("unregister", &GlobalShortcut::Unregister)

View File

@@ -24,7 +24,7 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
static mate::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit GlobalShortcut(v8::Isolate* isolate);

View File

@@ -19,9 +19,10 @@ namespace atom {
namespace api {
Menu::Menu(v8::Isolate* isolate)
Menu::Menu(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
: model_(new AtomMenuModel(this)),
parent_(nullptr) {
InitWith(isolate, wrapper);
}
Menu::~Menu() {
@@ -154,8 +155,9 @@ bool Menu::IsVisibleAt(int index) const {
// static
void Menu::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Menu"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("insertItem", &Menu::InsertItemAt)
.SetMethod("insertCheckItem", &Menu::InsertCheckItemAt)
@@ -184,14 +186,15 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
namespace {
using atom::api::Menu;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
using atom::api::Menu;
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::Function> constructor = mate::CreateConstructor<Menu>(
isolate, "Menu", base::Bind(&Menu::Create));
Menu::SetConstructor(isolate, base::Bind(&Menu::New));
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)
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
dict.SetMethod("sendActionToFirstResponder",

View File

@@ -20,10 +20,10 @@ namespace api {
class Menu : public mate::TrackableObject<Menu>,
public AtomMenuModel::Delegate {
public:
static mate::WrappableBase* Create(v8::Isolate* isolate);
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
#if defined(OS_MACOSX)
// Set the global menubar.
@@ -36,7 +36,7 @@ class Menu : public mate::TrackableObject<Menu>,
AtomMenuModel* model() const { return model_.get(); }
protected:
explicit Menu(v8::Isolate* isolate);
Menu(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
~Menu() override;
// mate::Wrappable:

View File

@@ -17,7 +17,7 @@ namespace api {
class MenuMac : public Menu {
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;

View File

@@ -18,7 +18,8 @@ namespace atom {
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) {
@@ -94,8 +95,8 @@ void Menu::SendActionToFirstResponder(const std::string& action) {
}
// static
mate::WrappableBase* Menu::Create(v8::Isolate* isolate) {
return new MenuMac(isolate);
mate::WrappableBase* Menu::New(mate::Arguments* args) {
return new MenuMac(args->isolate(), args->GetThis());
}
} // namespace api

View File

@@ -14,7 +14,8 @@ namespace atom {
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) {
@@ -53,8 +54,8 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
}
// static
mate::WrappableBase* Menu::Create(v8::Isolate* isolate) {
return new MenuViews(isolate);
mate::WrappableBase* Menu::New(mate::Arguments* args) {
return new MenuViews(args->isolate(), args->GetThis());
}
} // namespace api

View File

@@ -14,7 +14,7 @@ namespace api {
class MenuViews : public Menu {
public:
explicit MenuViews(v8::Isolate* isolate);
MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
protected:
void PopupAt(Window* window, int x, int y, int positioning_item) override;

View File

@@ -52,8 +52,8 @@ v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
// static
void PowerMonitor::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype);
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "PowerMonitor"));
}
} // namespace api
@@ -63,16 +63,19 @@ void PowerMonitor::BuildPrototype(
namespace {
using atom::api::PowerMonitor;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
#if defined(OS_MACOSX)
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
#endif
using atom::api::PowerMonitor;
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("powerMonitor", PowerMonitor::Create(isolate));
dict.Set("PowerMonitor",
PowerMonitor::GetConstructor(isolate)->GetFunction());
}
} // namespace

View File

@@ -20,7 +20,7 @@ class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit PowerMonitor(v8::Isolate* isolate);

View File

@@ -105,8 +105,9 @@ mate::Handle<PowerSaveBlocker> PowerSaveBlocker::Create(v8::Isolate* isolate) {
// static
void PowerSaveBlocker::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "PowerSaveBlocker"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("start", &PowerSaveBlocker::Start)
.SetMethod("stop", &PowerSaveBlocker::Stop)
.SetMethod("isStarted", &PowerSaveBlocker::IsStarted);

View File

@@ -25,7 +25,7 @@ class PowerSaveBlocker : public mate::TrackableObject<PowerSaveBlocker> {
static mate::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit PowerSaveBlocker(v8::Isolate* isolate);

View File

@@ -160,8 +160,9 @@ mate::Handle<Protocol> Protocol::Create(
// static
void Protocol::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Protocol"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("registerServiceWorkerSchemes",
&Protocol::RegisterServiceWorkerSchemes)
.SetMethod("registerStringProtocol",

View File

@@ -39,7 +39,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
v8::Isolate* isolate, AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);

View File

@@ -53,8 +53,10 @@ void RenderProcessPreferences::RemoveEntry(int id) {
// static
void RenderProcessPreferences::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(
mate::StringToV8(isolate, "RenderProcessPreferences"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("addEntry", &RenderProcessPreferences::AddEntry)
.SetMethod("removeEntry", &RenderProcessPreferences::RemoveEntry);
}

View File

@@ -20,7 +20,7 @@ class RenderProcessPreferences
ForAllWebContents(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);
void RemoveEntry(int id);

View File

@@ -113,8 +113,9 @@ v8::Local<v8::Value> Screen::Create(v8::Isolate* isolate) {
// static
void Screen::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Screen"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("getCursorScreenPoint", &Screen::GetCursorScreenPoint)
.SetMethod("getPrimaryDisplay", &Screen::GetPrimaryDisplay)
.SetMethod("getAllDisplays", &Screen::GetAllDisplays)
@@ -128,10 +129,14 @@ void Screen::BuildPrototype(
namespace {
using atom::api::Screen;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.Set("screen", atom::api::Screen::Create(context->GetIsolate()));
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("screen", Screen::Create(isolate));
dict.Set("Screen", Screen::GetConstructor(isolate)->GetFunction());
}
} // namespace

View File

@@ -28,7 +28,7 @@ class Screen : public mate::EventEmitter<Screen>,
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
Screen(v8::Isolate* isolate, display::Screen* screen);

View File

@@ -4,6 +4,7 @@
#include "atom/browser/api/atom_api_session.h"
#include <map>
#include <string>
#include <vector>
@@ -169,9 +170,8 @@ namespace {
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.
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
class ResolveProxyHelper {
public:
@@ -346,6 +346,7 @@ Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
Session::~Session() {
content::BrowserContext::GetDownloadManager(browser_context())->
RemoveObserver(this);
g_sessions.erase(weak_map_id());
}
void Session::OnDownloadCreated(content::DownloadManager* manager,
@@ -536,7 +537,12 @@ mate::Handle<Session> Session::CreateFrom(
auto handle = mate::CreateHandle(
isolate, new Session(isolate, browser_context));
g_wrap_session.Run(handle.ToV8());
// The Sessions should never be garbage collected, since the common pattern is
// to use partition strings, instead of using the Session object directly.
g_sessions[handle->weak_map_id()] =
v8::Global<v8::Object>(isolate, handle.ToV8());
return handle;
}
@@ -559,8 +565,9 @@ mate::Handle<Session> Session::FromPartition(
// static
void Session::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Session"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("resolveProxy", &Session::ResolveProxy)
.SetMethod("getCacheSize", &Session::DoCacheAction<CacheAction::STATS>)
@@ -584,16 +591,14 @@ void Session::BuildPrototype(v8::Isolate* isolate,
.SetProperty("webRequest", &Session::WebRequest);
}
void SetWrapSession(const WrapSessionCallback& callback) {
g_wrap_session = callback;
}
} // namespace api
} // namespace atom
namespace {
using atom::api::Session;
v8::Local<v8::Value> FromPartition(
const std::string& partition, mate::Arguments* args) {
if (!atom::Browser::Get()->is_ready()) {
@@ -602,16 +607,15 @@ v8::Local<v8::Value> FromPartition(
}
base::DictionaryValue options;
args->GetNext(&options);
return atom::api::Session::FromPartition(
args->isolate(), partition, options).ToV8();
return Session::FromPartition(args->isolate(), partition, options).ToV8();
}
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("Session", Session::GetConstructor(isolate)->GetFunction());
dict.SetMethod("fromPartition", &FromPartition);
dict.SetMethod("_setWrapSession", &atom::api::SetWrapSession);
}
} // namespace

View File

@@ -57,7 +57,7 @@ class Session: public mate::TrackableObject<Session>,
// mate::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
// Methods.
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);

View File

@@ -44,8 +44,9 @@ mate::Handle<SystemPreferences> SystemPreferences::Create(
// static
void SystemPreferences::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "SystemPreferences"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
#if defined(OS_WIN)
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
#elif defined(OS_MACOSX)
@@ -68,11 +69,15 @@ void SystemPreferences::BuildPrototype(
namespace {
using atom::api::SystemPreferences;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
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

View File

@@ -24,7 +24,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
#if defined(OS_WIN)
bool IsAeroGlassEnabled();

View File

@@ -60,10 +60,13 @@ namespace atom {
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()) {
SetImage(isolate, image);
tray_icon_->AddObserver(this);
InitWith(isolate, wrapper);
}
Tray::~Tray() {
@@ -72,14 +75,13 @@ Tray::~Tray() {
}
// static
mate::WrappableBase* Tray::New(v8::Isolate* isolate,
mate::Handle<NativeImage> image) {
mate::WrappableBase* Tray::New(mate::Handle<NativeImage> image,
mate::Arguments* args) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate, "Cannot create Tray before app is ready")));
args->ThrowError("Cannot create Tray before app is ready");
return nullptr;
}
return new Tray(isolate, image);
return new Tray(args->isolate(), args->GetThis(), image);
}
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
@@ -199,8 +201,9 @@ gfx::Rect Tray::GetBounds() {
// static
void Tray::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Tray"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("setImage", &Tray::SetImage)
.SetMethod("setPressedImage", &Tray::SetPressedImage)
@@ -220,14 +223,15 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
namespace {
using atom::api::Tray;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
using atom::api::Tray;
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::Function> constructor = mate::CreateConstructor<Tray>(
isolate, "Tray", base::Bind(&Tray::New));
Tray::SetConstructor(isolate, base::Bind(&Tray::New));
mate::Dictionary dict(isolate, exports);
dict.Set("Tray", static_cast<v8::Local<v8::Value>>(constructor));
dict.Set("Tray", Tray::GetConstructor(isolate)->GetFunction());
}
} // namespace

View File

@@ -35,14 +35,15 @@ class NativeImage;
class Tray : public mate::TrackableObject<Tray>,
public TrayIconObserver {
public:
static mate::WrappableBase* New(
v8::Isolate* isolate, mate::Handle<NativeImage> image);
static mate::WrappableBase* New(mate::Handle<NativeImage> image,
mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
Tray(v8::Isolate* isolate, mate::Handle<NativeImage> image);
Tray(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
mate::Handle<NativeImage> image);
~Tray() override;
// TrayIconObserver:

View File

@@ -228,10 +228,6 @@ namespace api {
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(
const content::WebContents* web_contents) {
auto context = web_contents->GetBrowserContext();
@@ -1458,8 +1454,9 @@ int WebContents::GetFrameRate() const {
// static
void WebContents::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "WebContents"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("getId", &WebContents::GetID)
.SetMethod("equal", &WebContents::Equal)
@@ -1569,41 +1566,32 @@ mate::Handle<WebContents> WebContents::CreateFrom(
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
// Otherwise create a new WebContents wrapper object.
auto handle = mate::CreateHandle(
isolate, new WebContents(isolate, web_contents));
g_wrap_web_contents.Run(handle.ToV8());
return handle;
return mate::CreateHandle(isolate, new WebContents(isolate, web_contents));
}
// static
mate::Handle<WebContents> WebContents::Create(
v8::Isolate* isolate, const mate::Dictionary& options) {
auto handle = 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;
return mate::CreateHandle(isolate, new WebContents(isolate, options));
}
} // namespace api
} // namespace atom
namespace {
using atom::api::WebContents;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("create", &atom::api::WebContents::Create);
dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
dict.SetMethod("fromId",
&mate::TrackableObject<atom::api::WebContents>::FromWeakMapID);
dict.Set("WebContents", WebContents::GetConstructor(isolate)->GetFunction());
dict.SetMethod("create", &WebContents::Create);
dict.SetMethod("fromId", &mate::TrackableObject<WebContents>::FromWeakMapID);
dict.SetMethod("getAllWebContents",
&mate::TrackableObject<atom::api::WebContents>::GetAll);
&mate::TrackableObject<WebContents>::GetAll);
}
} // namespace

View File

@@ -66,7 +66,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Isolate* isolate, const mate::Dictionary& options);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
int GetID() const;
Type GetType() const;

View File

@@ -88,8 +88,9 @@ mate::Handle<WebRequest> WebRequest::Create(
// static
void WebRequest::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "WebRequest"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("onBeforeRequest",
&WebRequest::SetResponseListener<
AtomNetworkDelegate::kOnBeforeRequest>)

View File

@@ -22,7 +22,7 @@ class WebRequest : public mate::TrackableObject<WebRequest> {
AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
protected:
WebRequest(v8::Isolate* isolate, AtomBrowserContext* browser_context);

View File

@@ -69,7 +69,8 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
} // 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.
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
@@ -113,7 +114,14 @@ Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
window_->InitFromOptions(options);
window_->AddObserver(this);
InitWith(isolate, wrapper);
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() {
@@ -125,17 +133,6 @@ Window::~Window() {
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) {
*prevent_default = Emit("close");
}
@@ -268,10 +265,9 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
#endif
// static
mate::WrappableBase* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
mate::WrappableBase* Window::New(mate::Arguments* args) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate, "Cannot create BrowserWindow before app is ready")));
args->ThrowError("Cannot create BrowserWindow before app is ready");
return nullptr;
}
@@ -282,10 +278,10 @@ mate::WrappableBase* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
mate::Dictionary 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() {
@@ -756,8 +752,9 @@ void Window::RemoveFromParentChildWindows() {
// static
void Window::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
.SetMethod("close", &Window::Close)
.SetMethod("focus", &Window::Focus)
@@ -879,9 +876,10 @@ using atom::api::Window;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
isolate, "BrowserWindow", base::Bind(&Window::New));
mate::Dictionary browser_window(isolate, constructor);
Window::SetConstructor(isolate, base::Bind(&Window::New));
mate::Dictionary browser_window(
isolate, Window::GetConstructor(isolate)->GetFunction());
browser_window.SetMethod("fromId",
&mate::TrackableObject<Window>::FromWeakMapID);
browser_window.SetMethod("getAllWindows",

View File

@@ -40,10 +40,10 @@ class WebContents;
class Window : public mate::TrackableObject<Window>,
public NativeWindowObserver {
public:
static mate::WrappableBase* New(v8::Isolate* isolate, mate::Arguments* args);
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
// Returns the BrowserWindow object from |native_window|.
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(); }
protected:
Window(v8::Isolate* isolate, const mate::Dictionary& options);
Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
const mate::Dictionary& options);
~Window() override;
// TrackableObject:
void AfterInit(v8::Isolate* isolate) override;
// NativeWindowObserver:
void WillCloseWindow(bool* prevent_default) override;
void WillDestoryNativeObject() override;

View File

@@ -58,8 +58,9 @@ Handle<Event> Event::Create(v8::Isolate* isolate) {
// static
void Event::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Event"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("preventDefault", &Event::PreventDefault)
.SetMethod("sendReply", &Event::SendReply);
}

View File

@@ -21,7 +21,7 @@ class Event : public Wrappable<Event>,
static Handle<Event> Create(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.
void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);

View File

@@ -10,6 +10,8 @@
#include "native_mate/object_template_builder.h"
#include "ui/events/event_constants.h"
#include "atom/common/node_includes.h"
namespace mate {
namespace {

View File

@@ -29,7 +29,7 @@ class IDUserData : public base::SupportsUserData::Data {
} // namespace
TrackableObjectBase::TrackableObjectBase()
: weak_map_id_(0), wrapped_(nullptr), weak_factory_(this) {
: weak_map_id_(0), weak_factory_(this) {
cleanup_ = RegisterDestructionCallback(GetDestroyClosure());
}
@@ -46,14 +46,7 @@ void TrackableObjectBase::Destroy() {
}
void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
if (weak_map_id_ != 0) {
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;
}
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
}
// static

View File

@@ -44,7 +44,6 @@ class TrackableObjectBase {
static base::Closure RegisterDestructionCallback(const base::Closure& c);
int32_t weak_map_id_;
base::SupportsUserData* wrapped_;
private:
void Destroy();
@@ -110,14 +109,13 @@ class TrackableObject : public TrackableObjectBase,
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_) {
weak_map_ = new atom::KeyWeakMap<int32_t>;
}
weak_map_id_ = ++next_id_;
weak_map_->Set(isolate, weak_map_id_, Wrappable<T>::GetWrapper());
if (wrapped_)
AttachAsUserData(wrapped_);
weak_map_->Set(isolate, weak_map_id_, wrapper);
}
private:

View File

@@ -136,6 +136,7 @@ class Browser : public WindowListObserver {
// Hide/Show dock.
void DockHide();
void DockShow();
bool DockIsVisible();
// Set docks' menu.
void DockSetMenu(AtomMenuModel* model);

View File

@@ -208,6 +208,12 @@ void Browser::DockHide() {
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}
bool Browser::DockIsVisible() {
// Because DockShow has a slight delay this may not be true immediately
// after that call.
return ([[NSRunningApplication currentApplication] activationPolicy] == NSApplicationActivationPolicyRegular);
}
void Browser::DockShow() {
BOOL active = [[NSRunningApplication currentApplication] isActive];
ProcessSerialNumber psn = { 0, kCurrentProcess };

View File

@@ -29,8 +29,9 @@ class Archive : public mate::Wrappable<Archive> {
}
static void BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Archive"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetProperty("path", &Archive::GetPath)
.SetMethod("getFileInfo", &Archive::GetFileInfo)
.SetMethod("stat", &Archive::Stat)

View File

@@ -8,6 +8,7 @@
#include "atom/common/key_weak_map.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
namespace atom {
@@ -21,8 +22,9 @@ class KeyWeakMap : public mate::Wrappable<KeyWeakMap<K>> {
}
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "KeyWeakMap"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("set", &KeyWeakMap<K>::Set)
.SetMethod("get", &KeyWeakMap<K>::Get)
.SetMethod("has", &KeyWeakMap<K>::Has)

View File

@@ -355,8 +355,9 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
// static
void NativeImage::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "NativeImage"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("toPNG", &NativeImage::ToPNG)
.SetMethod("toJPEG", &NativeImage::ToJPEG)
.SetMethod("toBitmap", &NativeImage::ToBitmap)

View File

@@ -52,7 +52,7 @@ class NativeImage : public mate::Wrappable<NativeImage> {
v8::Isolate* isolate, const GURL& url);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
#if defined(OS_WIN)
HICON GetHICON(int size);

View File

@@ -9,7 +9,7 @@
#include <utility>
#include <vector>
#include "base/memory/linked_ptr.h"
#include "base/macros.h"
#include "v8/include/v8.h"
namespace atom {
@@ -26,16 +26,16 @@ class KeyWeakMap {
KeyWeakMap() {}
virtual ~KeyWeakMap() {
for (const auto& p : map_)
p.second.second->ClearWeak();
for (auto& p : map_)
p.second.second.ClearWeak();
}
// Sets the object to WeakMap with the given |key|.
void Set(v8::Isolate* isolate, const K& key, v8::Local<v8::Object> object) {
auto value = make_linked_ptr(new v8::Global<v8::Object>(isolate, object));
KeyObject key_object = {key, this};
auto& p = map_[key] = std::make_pair(key_object, value);
value->SetWeak(&(p.first), OnObjectGC, v8::WeakCallbackType::kParameter);
auto& p = map_[key] =
std::make_pair(key_object, v8::Global<v8::Object>(isolate, object));
p.second.SetWeak(&(p.first), OnObjectGC, v8::WeakCallbackType::kParameter);
}
// Gets the object from WeakMap by its |key|.
@@ -44,7 +44,7 @@ class KeyWeakMap {
if (iter == map_.end())
return v8::MaybeLocal<v8::Object>();
else
return v8::Local<v8::Object>::New(isolate, *(iter->second.second));
return v8::Local<v8::Object>::New(isolate, iter->second.second);
}
// Whethere there is an object with |key| in this WeakMap.
@@ -56,10 +56,8 @@ class KeyWeakMap {
std::vector<v8::Local<v8::Object>> Values(v8::Isolate* isolate) const {
std::vector<v8::Local<v8::Object>> keys;
keys.reserve(map_.size());
for (const auto& iter : map_) {
const auto& value = *(iter.second.second);
keys.emplace_back(v8::Local<v8::Object>::New(isolate, value));
}
for (const auto& it : map_)
keys.emplace_back(v8::Local<v8::Object>::New(isolate, it.second.second));
return keys;
}
@@ -69,7 +67,7 @@ class KeyWeakMap {
if (iter == map_.end())
return;
iter->second.second->ClearWeak();
iter->second.second.ClearWeak();
map_.erase(iter);
}
@@ -82,7 +80,7 @@ class KeyWeakMap {
// Map of stored objects.
std::unordered_map<
K, std::pair<KeyObject, linked_ptr<v8::Global<v8::Object>>>> map_;
K, std::pair<KeyObject, v8::Global<v8::Object>>> map_;
DISALLOW_COPY_AND_ASSIGN(KeyWeakMap);
};

View File

@@ -187,8 +187,9 @@ void WebFrame::ClearCache(v8::Isolate* isolate) {
// static
void WebFrame::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "WebFrame"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setName", &WebFrame::SetName)
.SetMethod("setZoomLevel", &WebFrame::SetZoomLevel)
.SetMethod("getZoomLevel", &WebFrame::GetZoomLevel)
@@ -219,11 +220,14 @@ void WebFrame::BuildPrototype(
namespace {
using atom::api::WebFrame;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
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

View File

@@ -32,7 +32,7 @@ class WebFrame : public mate::Wrappable<WebFrame> {
static mate::Handle<WebFrame> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype);
v8::Local<v8::FunctionTemplate> prototype);
private:
explicit WebFrame(v8::Isolate* isolate);