]> khamidou — GitHub mirrors - electron.git/commitdiff
Add DebugDevTools API.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 24 Feb 2014 01:52:20 +0000 (09:52 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 24 Feb 2014 01:52:20 +0000 (09:52 +0800)
atom.gyp
browser/native_window.cc
browser/native_window.h

index a17155bb376092e2d33f438350997b513b0b3ed6..1b470d337cd79ee7cf02677fbb67d4b84569158e 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'include_dirs': [
         '.',
         'vendor',
+        'vendor/brightray',
         # Include directories for uv and node.
         'vendor/node/src',
         'vendor/node/deps/http_parser',
index 7c47c3122b188639508d577cc779f6e5ba7990a6..caa191b06c392e5c7919c6cec447c819a7fdd694 100644 (file)
@@ -20,6 +20,9 @@
 #include "browser/browser.h"
 #include "browser/window_list.h"
 #include "content/public/browser/devtools_agent_host.h"
+#include "content/public/browser/devtools_client_host.h"
+#include "content/public/browser/devtools_http_handler.h"
+#include "content/public/browser/devtools_manager.h"
 #include "content/public/browser/invalidate_type.h"
 #include "content/public/browser/navigation_entry.h"
 #include "content/public/browser/notification_details.h"
@@ -37,6 +40,7 @@
 #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;
@@ -165,6 +169,8 @@ bool NativeWindow::HasModalDialog() {
 
 void NativeWindow::OpenDevTools() {
   inspectable_web_contents()->ShowDevTools();
+
+  DebugDevTools();
 }
 
 void NativeWindow::CloseDevTools() {
@@ -183,6 +189,36 @@ 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);
+
+  brightray::InspectableWebContentsImpl* inspectable_web_contents_impl =
+      static_cast<brightray::InspectableWebContentsImpl*>(
+          inspectable_web_contents());
+  content::WebContents* devtools_web_contents =
+      inspectable_web_contents_impl->devtools_web_contents();
+
+  content::DevToolsAgentHost* agent_host =
+      content::DevToolsAgentHost::GetOrCreateFor(
+          devtools_web_contents->GetRenderViewHost());
+  content::DevToolsClientHost* frontend_host =
+      content::DevToolsClientHost::CreateDevToolsFrontendHost(
+          devtools_web_contents, window);
+  content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
+      agent_host, frontend_host);
+
+  window->InitFromOptions(&options);
+  window->GetWebContents()->GetController().LoadURL(
+        GURL("chrome-devtools://devtools/devtools.html"),
+        content::Referrer(),
+        content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+        std::string());
+}
+
 void NativeWindow::FocusOnWebView() {
   GetWebContents()->GetRenderViewHost()->Focus();
 }
@@ -447,6 +483,14 @@ void NativeWindow::Observe(int type,
   }
 }
 
+void NativeWindow::DispatchOnEmbedder(const std::string& message) {
+}
+
+void NativeWindow::InspectedContentsClosing() {
+  // We are acting as devtools debugger, safe to delete here.
+  delete this;
+}
+
 void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
                                      bool succeed,
                                      const SkBitmap& bitmap) {
index 0b82b969c72334cf0ec7f47c3429e492bdad9e07..2561285cf13c556e823a50b34f46ae7a73e1a2da 100644 (file)
@@ -12,6 +12,7 @@
 #include "base/memory/weak_ptr.h"
 #include "base/observer_list.h"
 #include "browser/native_window_observer.h"
+#include "content/public/browser/devtools_frontend_host_delegate.h"
 #include "content/public/browser/notification_registrar.h"
 #include "content/public/browser/notification_observer.h"
 #include "content/public/browser/web_contents_observer.h"
@@ -49,7 +50,8 @@ struct DraggableRegion;
 
 class NativeWindow : public brightray::DefaultWebContentsDelegate,
                      public content::WebContentsObserver,
-                     public content::NotificationObserver {
+                     public content::NotificationObserver,
+                     public content::DevToolsFrontendHostDelegate {
  public:
   typedef base::Callback<void(const std::vector<unsigned char>& buffer)>
       CapturePageCallback;
@@ -127,6 +129,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void CloseDevTools();
   virtual bool IsDevToolsOpened();
   virtual void InspectElement(int x, int y);
+  virtual void DebugDevTools();
 
   virtual void FocusOnWebView();
   virtual void BlurWebView();
@@ -210,11 +213,15 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE;
   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
 
-  // Implementations of content::NotificationObserver
+  // Implementations of content::NotificationObserver.
   virtual void Observe(int type,
                        const content::NotificationSource& source,
                        const content::NotificationDetails& details) OVERRIDE;
 
+  // Implementations of content::DevToolsFrontendHostDelegate.
+  virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
+  virtual void InspectedContentsClosing() OVERRIDE;
+
   // Whether window has standard frame.
   bool has_frame_;