]> khamidou — GitHub mirrors - electron.git/commitdiff
Disable the undocked devtools.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 06:25:15 +0000 (14:25 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 06:25:15 +0000 (14:25 +0800)
browser/native_window.cc
browser/native_window.h
vendor/brightray

index 3ef5bc7d1b68bd47f14461495db4d45d1c753655..7bd45ee0b63d718dfd6a74bb5de43f1a99f6754e 100644 (file)
@@ -7,6 +7,7 @@
 #include <string>
 
 #include "base/file_util.h"
+#include "base/prefs/pref_service.h"
 #include "base/message_loop/message_loop.h"
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "ui/gfx/point.h"
 #include "ui/gfx/rect.h"
 #include "ui/gfx/size.h"
-#include "vendor/brightray/browser/inspectable_web_contents_impl.h"
 #include "webkit/common/user_agent/user_agent_util.h"
 
 using content::NavigationEntry;
 
 namespace atom {
 
+namespace {
+
+const char kDockSidePref[] = "brightray.devtools.dockside";
+
+}  // namespace
+
 NativeWindow::NativeWindow(content::WebContents* web_contents,
                            base::DictionaryValue* options)
     : content::WebContentsObserver(web_contents),
@@ -166,7 +172,19 @@ bool NativeWindow::HasModalDialog() {
 }
 
 void NativeWindow::OpenDevTools() {
+  // Check if the devtools is docked.
+  AtomBrowserContext* browser_context = AtomBrowserContext::Get();
+  std::string dock_side = browser_context->prefs()->GetString(kDockSidePref);
+  if (dock_side == "undocked")
+    browser_context->prefs()->SetString(kDockSidePref, "bottom");
+
   inspectable_web_contents()->ShowDevTools();
+
+  // Intercept the requestSetDockSide message of devtools.
+  inspectable_web_contents()->embedder_message_dispatcher()->
+      RegisterHandler("requestSetDockSide",
+                      base::Bind(&NativeWindow::OnRequestSetDockSide,
+                                 base::Unretained(this)));
 }
 
 void NativeWindow::CloseDevTools() {
@@ -283,10 +301,7 @@ content::WebContents* NativeWindow::GetWebContents() const {
 }
 
 content::WebContents* NativeWindow::GetDevToolsWebContents() const {
-  brightray::InspectableWebContentsImpl* inspectable_web_contents_impl =
-      static_cast<brightray::InspectableWebContentsImpl*>(
-          inspectable_web_contents());
-  return inspectable_web_contents_impl->devtools_web_contents();
+  return inspectable_web_contents()->devtools_web_contents();
 }
 
 void NativeWindow::NotifyWindowClosed() {
@@ -476,6 +491,22 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
   callback.Run(data);
 }
 
+bool NativeWindow::OnRequestSetDockSide(const base::ListValue& args) {
+  brightray::DevToolsEmbedderMessageDispatcher::Delegate* delegate =
+      static_cast<brightray::DevToolsEmbedderMessageDispatcher::Delegate*>(
+          inspectable_web_contents());
+
+  // Do not allow the "undocked" state.
+  std::string dock_side;
+  if (args.GetString(0, &dock_side) && dock_side == "undocked") {
+    delegate->CloseWindow();
+    return true;
+  }
+
+  delegate->SetDockSide(dock_side);
+  return true;
+}
+
 void NativeWindow::OnRendererMessage(const string16& channel,
                                      const base::ListValue& args) {
   AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage(
index b1eb6e695b46186b2ce50b8c23527ef41513be90..6d97c3aabbe8e8d184729eeb2baeb683543ea5de 100644 (file)
 #include "browser/native_window_observer.h"
 #include "content/public/browser/notification_registrar.h"
 #include "content/public/browser/notification_observer.h"
-#include "content/public/browser/web_contents_observer.h"
 #include "ui/gfx/image/image.h"
 #include "vendor/brightray/browser/default_web_contents_delegate.h"
+#include "vendor/brightray/browser/inspectable_web_contents_impl.h"
 
 namespace base {
 class DictionaryValue;
 class ListValue;
 }
 
-namespace brightray {
-class InspectableWebContents;
-}
-
 namespace content {
 class BrowserContext;
 class WebContents;
@@ -174,8 +170,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   explicit NativeWindow(content::WebContents* web_contents,
                         base::DictionaryValue* options);
 
-  brightray::InspectableWebContents* inspectable_web_contents() const {
-    return inspectable_web_contents_.get();
+  brightray::InspectableWebContentsImpl* inspectable_web_contents() const {
+    return static_cast<brightray::InspectableWebContentsImpl*>(
+        inspectable_web_contents_.get());
   }
 
   void NotifyWindowClosed();
@@ -232,6 +229,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
                          bool succeed,
                          const SkBitmap& bitmap);
 
+  // Handler for the requestSetDockSide message from devtools.
+  bool OnRequestSetDockSide(const base::ListValue&);
+
   void OnRendererMessage(const string16& channel,
                          const base::ListValue& args);
 
index 569ea3f1e14b9214528be09dfc2117e387c0a03f..90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 569ea3f1e14b9214528be09dfc2117e387c0a03f
+Subproject commit 90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2