Move "id" and "fromId" to C++

This commit is contained in:
Cheng Zhao 2015-06-24 16:37:48 +08:00
parent c2f14e6053
commit 5e62b5975b
4 changed files with 15 additions and 13 deletions

View file

@ -435,6 +435,10 @@ bool Window::IsVisibleOnAllWorkspaces() {
return window_->IsVisibleOnAllWorkspaces();
}
int32_t Window::ID() const {
return weak_map_id();
}
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
if (web_contents_.IsEmpty()) {
auto handle =
@ -518,6 +522,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("showDefinitionForSelection",
&Window::ShowDefinitionForSelection)
#endif
.SetProperty("id", &Window::ID)
.SetProperty("webContents", &Window::WebContents)
.SetProperty("devToolsWebContents", &Window::DevToolsWebContents);
}
@ -529,14 +534,18 @@ void Window::BuildPrototype(v8::Isolate* isolate,
namespace {
using atom::api::Window;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
using atom::api::Window;
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);
browser_window.SetMethod("fromId", &mate::TrackableObject::FromWeakMapID);
mate::Dictionary dict(isolate, exports);
dict.Set("BrowserWindow", static_cast<v8::Local<v8::Value>>(constructor));
dict.Set("BrowserWindow", browser_window);
}
} // namespace

View file

@ -10,8 +10,8 @@
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/image/image.h"
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/native_window_observer.h"
#include "atom/browser/api/event_emitter.h"
#include "native_mate/handle.h"
class GURL;
@ -37,7 +37,7 @@ namespace api {
class WebContents;
class Window : public mate::EventEmitter,
class Window : public mate::TrackableObject,
public NativeWindowObserver {
public:
static mate::Wrappable* New(v8::Isolate* isolate,
@ -147,6 +147,7 @@ class Window : public mate::EventEmitter,
void SetVisibleOnAllWorkspaces(bool visible);
bool IsVisibleOnAllWorkspaces();
int32_t ID() const;
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);

View file

@ -15,11 +15,6 @@ BrowserWindow::_init = ->
menu = app.getApplicationMenu()
@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"
@on '-new-window', (event, url, frameName) =>
event.sender = @webContents
@ -63,9 +58,6 @@ BrowserWindow.fromDevToolsWebContents = (webContents) ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.devToolsWebContents?.equal webContents
BrowserWindow.fromId = (id) ->
BrowserWindow.windows.get id if BrowserWindow.windows.has id
# Helpers.
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit cad1fa50a95ca4185c435846e4868d5bd6cc94df
Subproject commit cc4e2fcd94b5a22e6720f0fba1c586a89640f1f6