Add the debugDevTools JS API.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 24 Feb 2014 04:08:33 +0000 (12:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 24 Feb 2014 04:08:33 +0000 (12:08 +0800)
browser/api/atom_api_window.cc
browser/api/atom_api_window.h
browser/native_window.cc
browser/native_window.h

index d5b6296831a7958b6b9216f8af8b3a1dc6a3a405..f502425749ede27316023f940d79624a9753b839 100644 (file)
@@ -414,6 +414,12 @@ void Window::InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args) {
   self->window_->InspectElement(x, y);
 }
 
+// static
+void Window::DebugDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
+  UNWRAP_WINDOW_AND_CHECK;
+  self->window_->DebugDevTools();
+}
+
 // static
 void Window::FocusOnWebView(const v8::FunctionCallbackInfo<v8::Value>& args) {
   UNWRAP_WINDOW_AND_CHECK;
@@ -663,6 +669,7 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
   NODE_SET_PROTOTYPE_METHOD(t, "closeDevTools", CloseDevTools);
   NODE_SET_PROTOTYPE_METHOD(t, "isDevToolsOpened", IsDevToolsOpened);
   NODE_SET_PROTOTYPE_METHOD(t, "inspectElement", InspectElement);
+  NODE_SET_PROTOTYPE_METHOD(t, "debugDevTools", DebugDevTools);
   NODE_SET_PROTOTYPE_METHOD(t, "focusOnWebView", FocusOnWebView);
   NODE_SET_PROTOTYPE_METHOD(t, "blurWebView", BlurWebView);
   NODE_SET_PROTOTYPE_METHOD(t, "isWebViewFocused", IsWebViewFocused);
index 1526e4802a09ec9cc29f9bae43f500a91b7f4f14..d53affaa7fcee412ca1926162047b64cca854a76 100644 (file)
@@ -86,6 +86,7 @@ class Window : public EventEmitter,
   static void CloseDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void IsDevToolsOpened(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args);
+  static void DebugDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void FocusOnWebView(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void BlurWebView(const v8::FunctionCallbackInfo<v8::Value>& args);
   static void IsWebViewFocused(const v8::FunctionCallbackInfo<v8::Value>& args);
index 603c9db1dd037686681a7a383c9e22be9339143d..3afdea54586c88073d07f94dc7f498dc72378ba9 100644 (file)
@@ -167,8 +167,6 @@ bool NativeWindow::HasModalDialog() {
 
 void NativeWindow::OpenDevTools() {
   inspectable_web_contents()->ShowDevTools();
-
-  DebugDevTools();
 }
 
 void NativeWindow::CloseDevTools() {
@@ -187,14 +185,16 @@ void NativeWindow::InspectElement(int x, int y) {
   agent->InspectElement(x, y);
 }
 
-void NativeWindow::DebugDevTools() {
-  if (!IsDevToolsOpened())
-    return;
+scoped_ptr<NativeWindow> NativeWindow::DebugDevTools() {
+  scoped_ptr<NativeWindow> window;
+  if (IsDevToolsOpened()) {
+    base::DictionaryValue options;
+    window.reset(NativeWindow::Create(&options));
+    window->devtools_delegate_.reset(new DevToolsDelegate(
+        window.get(), GetDevToolsWebContents()));
+  }
 
-  base::DictionaryValue options;
-  NativeWindow* window = NativeWindow::Create(&options);
-  window->devtools_delegate_.reset(new DevToolsDelegate(
-      window, GetDevToolsWebContents()));
+  return window.Pass();
 }
 
 void NativeWindow::FocusOnWebView() {
index 14268ccbd8d9d719b81fa075829d6b658192f82b..d17f41df846b672fc590362f59d7cbf764b03f11 100644 (file)
@@ -128,7 +128,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void CloseDevTools();
   virtual bool IsDevToolsOpened();
   virtual void InspectElement(int x, int y);
-  virtual void DebugDevTools();
+
+  // Creates a new window to debug the devtools.
+  virtual scoped_ptr<NativeWindow> DebugDevTools();
 
   virtual void FocusOnWebView();
   virtual void BlurWebView();