]> khamidou — GitHub mirrors - electron.git/commitdiff
Use InspectableWebContentsDelegate.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 09:08:30 +0000 (17:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 4 Mar 2014 09:08:30 +0000 (17:08 +0800)
browser/native_window.cc
browser/native_window.h
vendor/brightray

index 72db7ef77a6c7f5ed4e6f0567572098dbd5b1d7e..e16c45f1ebab5f7915706bbbebc69c3a5ca6edad 100644 (file)
@@ -72,6 +72,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
   options->GetString(switches::kNodeIntegration, &node_integration_);
 
   web_contents->SetDelegate(this);
+  inspectable_web_contents()->SetDelegate(this);
 
   WindowList::AddWindow(this);
 
@@ -180,22 +181,8 @@ bool NativeWindow::HasModalDialog() {
 }
 
 void NativeWindow::OpenDevTools() {
-  // Check if the devtools is undocked.
-  AtomBrowserContext* browser_context = AtomBrowserContext::Get();
-  std::string dock_side = browser_context->prefs()->GetString(kDockSidePref);
-  if (dock_side == "undocked") {
-    Debug(GetWebContents());
-    return;
-  }
-
   // For docked devtools we give it to brightray.
   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() {
@@ -483,6 +470,24 @@ void NativeWindow::Observe(int type,
   }
 }
 
+bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side,
+                                       bool* succeed) {
+  if (dock_side != "undocked")
+    return false;
+
+  CloseDevTools();
+  Debug(GetWebContents());
+  return true;
+}
+
+bool NativeWindow::DevToolsShow(const std::string& dock_side) {
+  if (dock_side != "undocked")
+    return false;
+
+  Debug(GetWebContents());
+  return true;
+}
+
 void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
                                      bool succeed,
                                      const SkBitmap& bitmap) {
@@ -492,22 +497,6 @@ 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());
-
-  // Takeover when devtools is undocked.
-  std::string dock_side;
-  if (args.GetString(0, &dock_side) && dock_side == "undocked") {
-    delegate->CloseWindow();
-    Debug(GetWebContents());
-  } else {
-    delegate->SetDockSide(dock_side);
-  }
-  return true;
-}
-
 void NativeWindow::OnRendererMessage(const string16& channel,
                                      const base::ListValue& args) {
   AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage(
index 1e02dee817d74c5dca41c9c2e7973daa376f34ba..1b3b38df70932cebb15bde685042c4e0506e6482 100644 (file)
@@ -16,6 +16,7 @@
 #include "content/public/browser/notification_observer.h"
 #include "ui/gfx/image/image.h"
 #include "vendor/brightray/browser/default_web_contents_delegate.h"
+#include "vendor/brightray/browser/inspectable_web_contents_delegate.h"
 #include "vendor/brightray/browser/inspectable_web_contents_impl.h"
 
 namespace base {
@@ -45,6 +46,7 @@ class DevToolsDelegate;
 struct DraggableRegion;
 
 class NativeWindow : public brightray::DefaultWebContentsDelegate,
+                     public brightray::InspectableWebContentsDelegate,
                      public content::WebContentsObserver,
                      public content::NotificationObserver {
  public:
@@ -220,6 +222,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
                        const content::NotificationSource& source,
                        const content::NotificationDetails& details) OVERRIDE;
 
+  // Implementations of brightray::InspectableWebContentsDelegate.
+  virtual bool DevToolsSetDockSide(const std::string& dock_side,
+                                   bool* succeed) OVERRIDE;
+  virtual bool DevToolsShow(const std::string& side) OVERRIDE;
+
   // Whether window has standard frame.
   bool has_frame_;
 
@@ -232,9 +239,6 @@ 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 90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2..8111949e34a17bbeba9246494326bb891f55df34 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 90ea5b1d3b9147ae935e5077fbb40fa70a15b4f2
+Subproject commit 8111949e34a17bbeba9246494326bb891f55df34