]> khamidou — GitHub mirrors - electron.git/commitdiff
Enable getting a window according to its attached devtools.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 4 Apr 2014 14:28:18 +0000 (22:28 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 4 Apr 2014 14:28:18 +0000 (22:28 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/api/lib/browser-window.coffee

index e8a845ff6abf9aaa8c07099d2adb5be726ecd0cf..c12effeb35dd94b58b035ed106d5101f9083d7e9 100644 (file)
@@ -503,6 +503,19 @@ void Window::IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args) {
   args.GetReturnValue().Set(self->window_->GetWebContents()->IsCrashed());
 }
 
+// static
+void Window::GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
+  UNWRAP_WINDOW_AND_CHECK;
+
+  content::WebContents* web_contents = self->window_->GetDevToolsWebContents();
+  v8::Local<v8::Object> 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<v8::Value>& args) {
   UNWRAP_WINDOW_AND_CHECK;
@@ -686,6 +699,8 @@ void Window::Initialize(v8::Handle<v8::Object> 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);
index bca32f2b3cfbe51eda0249904daed22dc176457e..b16bb70a2e78a8b83774f45e410baa5e89971360 100644 (file)
@@ -103,6 +103,9 @@ class Window : public EventEmitter,
   static void GetProcessID(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args);
 
+  // APIs for devtools.
+  static void GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
+
   // APIs for NavigationController.
   static void LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void GetURL(const v8::FunctionCallbackInfo<v8::Value>& args);
index 38946c5500af511037bec6780c1d915208d4aa40..a359b28218ddd53803605d07639133346c78dcb6 100644 (file)
@@ -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