From: Cheng Zhao Date: Fri, 4 Apr 2014 14:28:18 +0000 (+0800) Subject: Enable getting a window according to its attached devtools. X-Git-Tag: v0.11.6~7^2~6 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=f5fc26d8fca0b61b8b56127662ef17b7d4207fb6;p=electron.git Enable getting a window according to its attached devtools. --- diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index e8a845ff..c12effeb 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -503,6 +503,19 @@ void Window::IsCrashed(const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(self->window_->GetWebContents()->IsCrashed()); } +// static +void Window::GetDevTools(const v8::FunctionCallbackInfo& args) { + UNWRAP_WINDOW_AND_CHECK; + + content::WebContents* web_contents = self->window_->GetDevToolsWebContents(); + v8::Local devtools = v8::Object::New(); + devtools->Set(ToV8Value("processId"), + ToV8Value(web_contents->GetRenderProcessHost()->GetID())); + devtools->Set(ToV8Value("routingId"), + ToV8Value(web_contents->GetRoutingID())); + args.GetReturnValue().Set(devtools); +} + // static void Window::LoadURL(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; @@ -686,6 +699,8 @@ void Window::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "getProcessId", GetProcessID); NODE_SET_PROTOTYPE_METHOD(t, "isCrashed", IsCrashed); + NODE_SET_PROTOTYPE_METHOD(t, "getDevTools", GetDevTools); + NODE_SET_PROTOTYPE_METHOD(t, "loadUrl", LoadURL); NODE_SET_PROTOTYPE_METHOD(t, "getUrl", GetURL); NODE_SET_PROTOTYPE_METHOD(t, "canGoBack", CanGoBack); diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index bca32f2b..b16bb70a 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -103,6 +103,9 @@ class Window : public EventEmitter, static void GetProcessID(const v8::FunctionCallbackInfo& args); static void IsCrashed(const v8::FunctionCallbackInfo& args); + // APIs for devtools. + static void GetDevTools(const v8::FunctionCallbackInfo& args); + // APIs for NavigationController. static void LoadURL(const v8::FunctionCallbackInfo& args); static void GetURL(const v8::FunctionCallbackInfo& args); diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index 38946c55..a359b282 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -55,4 +55,11 @@ BrowserWindow.fromProcessIdAndRoutingId = (processId, routingId) -> return window for window in windows when window.getProcessId() == processId and window.getRoutingId() == routingId +BrowserWindow.fromDevTools = (processId, routingId) -> + windows = BrowserWindow.getAllWindows() + for window in windows + devtools = window.getDevTools() + return window if devtools.processId == processId and + devtools.routingId == routingId + module.exports = BrowserWindow