]> khamidou — GitHub mirrors - electron.git/commitdiff
Make the DebugDevTools API more generic.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 06:35:35 +0000 (14:35 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 06:35:35 +0000 (14:35 +0800)
browser/api/atom_api_window.cc
browser/native_window.cc
browser/native_window.h

index f502425749ede27316023f940d79624a9753b839..7486f4f5b626157448e233b279146fa4876ab627 100644 (file)
@@ -417,7 +417,8 @@ void Window::InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args) {
 // static
 void Window::DebugDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
   UNWRAP_WINDOW_AND_CHECK;
-  self->window_->DebugDevTools();
+  if (self->window_->IsDevToolsOpened())
+    NativeWindow::Debug(self->window_->GetDevToolsWebContents());
 }
 
 // static
index 7bd45ee0b63d718dfd6a74bb5de43f1a99f6754e..3d3d38474c10ec8019db14648b0480537d4a6335 100644 (file)
@@ -101,6 +101,14 @@ NativeWindow* NativeWindow::Create(base::DictionaryValue* options) {
   return Create(content::WebContents::Create(create_params), options);
 }
 
+// static
+NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) {
+  base::DictionaryValue options;
+  NativeWindow* window = NativeWindow::Create(&options);
+  window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents));
+  return window;
+}
+
 // static
 NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
   // Stupid iterating.
@@ -203,16 +211,6 @@ void NativeWindow::InspectElement(int x, int y) {
   agent->InspectElement(x, y);
 }
 
-void NativeWindow::DebugDevTools() {
-  if (!IsDevToolsOpened())
-    return;
-
-  base::DictionaryValue options;
-  NativeWindow* window = NativeWindow::Create(&options);
-  window->devtools_delegate_.reset(new DevToolsDelegate(
-      window, GetDevToolsWebContents()));
-}
-
 void NativeWindow::FocusOnWebView() {
   GetWebContents()->GetRenderViewHost()->Focus();
 }
index 6d97c3aabbe8e8d184729eeb2baeb683543ea5de..1e02dee817d74c5dca41c9c2e7973daa376f34ba 100644 (file)
@@ -72,13 +72,19 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
 
   virtual ~NativeWindow();
 
-  // Create window with existing WebContents.
+  // Create window with existing WebContents, the caller is responsible for
+  // managing the window's live.
   static NativeWindow* Create(content::WebContents* web_contents,
                               base::DictionaryValue* options);
 
-  // Create window with new WebContents.
+  // Create window with new WebContents, the caller is responsible for
+  // managing the window's live.
   static NativeWindow* Create(base::DictionaryValue* options);
 
+  // Creates a devtools window to debug the WebContents, the returned window
+  // will manage its own life.
+  static NativeWindow* Debug(content::WebContents* web_contents);
+
   // Find a window from its process id and routing id.
   static NativeWindow* FromRenderView(int process_id, int routing_id);
 
@@ -125,9 +131,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual bool IsDevToolsOpened();
   virtual void InspectElement(int x, int y);
 
-  // Creates a new window to debug the devtools.
-  virtual void DebugDevTools();
-
   virtual void FocusOnWebView();
   virtual void BlurWebView();
   virtual bool IsWebViewFocused();