Move "id" and "fromId" to C++
This commit is contained in:
parent
c2f14e6053
commit
5e62b5975b
4 changed files with 15 additions and 13 deletions
|
@ -435,6 +435,10 @@ bool Window::IsVisibleOnAllWorkspaces() {
|
||||||
return window_->IsVisibleOnAllWorkspaces();
|
return window_->IsVisibleOnAllWorkspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t Window::ID() const {
|
||||||
|
return weak_map_id();
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
|
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
|
||||||
if (web_contents_.IsEmpty()) {
|
if (web_contents_.IsEmpty()) {
|
||||||
auto handle =
|
auto handle =
|
||||||
|
@ -518,6 +522,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("showDefinitionForSelection",
|
.SetMethod("showDefinitionForSelection",
|
||||||
&Window::ShowDefinitionForSelection)
|
&Window::ShowDefinitionForSelection)
|
||||||
#endif
|
#endif
|
||||||
|
.SetProperty("id", &Window::ID)
|
||||||
.SetProperty("webContents", &Window::WebContents)
|
.SetProperty("webContents", &Window::WebContents)
|
||||||
.SetProperty("devToolsWebContents", &Window::DevToolsWebContents);
|
.SetProperty("devToolsWebContents", &Window::DevToolsWebContents);
|
||||||
}
|
}
|
||||||
|
@ -529,14 +534,18 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
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) {
|
||||||
using atom::api::Window;
|
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
|
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
|
||||||
isolate, "BrowserWindow", base::Bind(&Window::New));
|
isolate, "BrowserWindow", base::Bind(&Window::New));
|
||||||
|
mate::Dictionary browser_window(isolate, constructor);
|
||||||
|
browser_window.SetMethod("fromId", &mate::TrackableObject::FromWeakMapID);
|
||||||
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("BrowserWindow", static_cast<v8::Local<v8::Value>>(constructor));
|
dict.Set("BrowserWindow", browser_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
#include "atom/browser/api/trackable_object.h"
|
||||||
#include "atom/browser/native_window_observer.h"
|
#include "atom/browser/native_window_observer.h"
|
||||||
#include "atom/browser/api/event_emitter.h"
|
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
|
||||||
class GURL;
|
class GURL;
|
||||||
|
@ -37,7 +37,7 @@ namespace api {
|
||||||
|
|
||||||
class WebContents;
|
class WebContents;
|
||||||
|
|
||||||
class Window : public mate::EventEmitter,
|
class Window : public mate::TrackableObject,
|
||||||
public NativeWindowObserver {
|
public NativeWindowObserver {
|
||||||
public:
|
public:
|
||||||
static mate::Wrappable* New(v8::Isolate* isolate,
|
static mate::Wrappable* New(v8::Isolate* isolate,
|
||||||
|
@ -147,6 +147,7 @@ class Window : public mate::EventEmitter,
|
||||||
void SetVisibleOnAllWorkspaces(bool visible);
|
void SetVisibleOnAllWorkspaces(bool visible);
|
||||||
bool IsVisibleOnAllWorkspaces();
|
bool IsVisibleOnAllWorkspaces();
|
||||||
|
|
||||||
|
int32_t ID() const;
|
||||||
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);
|
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,6 @@ BrowserWindow::_init = ->
|
||||||
menu = app.getApplicationMenu()
|
menu = app.getApplicationMenu()
|
||||||
@setMenu menu if menu?
|
@setMenu menu if menu?
|
||||||
|
|
||||||
# Remember the window ID.
|
|
||||||
Object.defineProperty this, 'id',
|
|
||||||
value: BrowserWindow.windows.add(this)
|
|
||||||
enumerable: true
|
|
||||||
|
|
||||||
# Make new windows requested by links behave like "window.open"
|
# Make new windows requested by links behave like "window.open"
|
||||||
@on '-new-window', (event, url, frameName) =>
|
@on '-new-window', (event, url, frameName) =>
|
||||||
event.sender = @webContents
|
event.sender = @webContents
|
||||||
|
@ -63,9 +58,6 @@ BrowserWindow.fromDevToolsWebContents = (webContents) ->
|
||||||
windows = BrowserWindow.getAllWindows()
|
windows = BrowserWindow.getAllWindows()
|
||||||
return window for window in windows when window.devToolsWebContents?.equal webContents
|
return window for window in windows when window.devToolsWebContents?.equal webContents
|
||||||
|
|
||||||
BrowserWindow.fromId = (id) ->
|
|
||||||
BrowserWindow.windows.get id if BrowserWindow.windows.has id
|
|
||||||
|
|
||||||
# Helpers.
|
# Helpers.
|
||||||
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
||||||
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit cad1fa50a95ca4185c435846e4868d5bd6cc94df
|
Subproject commit cc4e2fcd94b5a22e6720f0fba1c586a89640f1f6
|
Loading…
Reference in a new issue