]> khamidou — GitHub mirrors - electron.git/commitdiff
Separate devtools code out.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 24 Feb 2014 03:53:13 +0000 (11:53 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 24 Feb 2014 03:53:13 +0000 (11:53 +0800)
atom.gyp
browser/devtools_delegate.cc [new file with mode: 0644]
browser/devtools_delegate.h [new file with mode: 0644]
browser/native_window.cc
browser/native_window.h

index 1b470d337cd79ee7cf02677fbb67d4b84569158e..a419ae94278a6473390e7776725c559c36c8bbaa 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -90,6 +90,8 @@
       'browser/browser_mac.mm',
       'browser/browser_win.cc',
       'browser/browser_observer.h',
+      'browser/devtools_delegate.cc',
+      'browser/devtools_delegate.h',
       'browser/native_window.cc',
       'browser/native_window.h',
       'browser/native_window_gtk.cc',
diff --git a/browser/devtools_delegate.cc b/browser/devtools_delegate.cc
new file mode 100644 (file)
index 0000000..77b8923
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (c) 2014 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/devtools_delegate.h"
+
+#include "base/values.h"
+#include "browser/native_window.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/web_contents.h"
+
+namespace atom {
+
+DevToolsDelegate::DevToolsDelegate(NativeWindow* window,
+                                   content::WebContents* target_web_contents)
+    : content::WebContentsObserver(window->GetWebContents()),
+      owner_window_(window) {
+  content::WebContents* web_contents = window->GetWebContents();
+
+  // Setup devtools.
+  devtools_agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(
+      target_web_contents->GetRenderViewHost());
+  devtools_client_host_.reset(
+      content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents,
+                                                              this));
+  content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
+      devtools_agent_host_.get(), devtools_client_host_.get());
+
+  // Go!
+  base::DictionaryValue options;
+  options.SetString("title", "DevTools Debugger");
+  window->InitFromOptions(&options);
+  web_contents->GetController().LoadURL(
+      GURL("chrome-devtools://devtools/devtools.html"),
+      content::Referrer(),
+      content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+      std::string());
+}
+
+DevToolsDelegate::~DevToolsDelegate() {
+}
+
+void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) {
+}
+
+void DevToolsDelegate::InspectedContentsClosing() {
+  owner_window_->CloseImmediately();
+}
+
+void DevToolsDelegate::AboutToNavigateRenderView(
+      content::RenderViewHost* render_view_host) {
+  content::DevToolsClientHost::SetupDevToolsFrontendClient(
+      owner_window_->GetWebContents()->GetRenderViewHost());
+}
+
+}  // namespace atom
diff --git a/browser/devtools_delegate.h b/browser/devtools_delegate.h
new file mode 100644 (file)
index 0000000..d281e3b
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (c) 2014 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_DEVTOOLS_DELEGATE_H_
+#define ATOM_BROWSER_DEVTOOLS_DELEGATE_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/devtools_frontend_host_delegate.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace content {
+class DevToolsAgentHost;
+class DevToolsClientHost;
+}
+
+namespace atom {
+
+class NativeWindow;
+
+class DevToolsDelegate : public content::DevToolsFrontendHostDelegate,
+                         public content::WebContentsObserver {
+ public:
+  DevToolsDelegate(NativeWindow* window,
+                   content::WebContents* target_web_contents);
+  virtual ~DevToolsDelegate();
+
+ protected:
+  // Implementations of content::DevToolsFrontendHostDelegate.
+  virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
+  virtual void InspectedContentsClosing() OVERRIDE;
+
+  // Implementations of content::WebContentsObserver.
+  virtual void AboutToNavigateRenderView(
+      content::RenderViewHost* render_view_host) OVERRIDE;
+
+ private:
+  NativeWindow* owner_window_;
+
+  scoped_refptr<content::DevToolsAgentHost> devtools_agent_host_;
+  scoped_ptr<content::DevToolsClientHost> devtools_client_host_;
+
+  DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate);
+};
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_DEVTOOLS_DELEGATE_H_
index a9d887c13212c98da8e563ce059edf3b48133ae9..603c9db1dd037686681a7a383c9e22be9339143d 100644 (file)
 #include "browser/atom_browser_main_parts.h"
 #include "browser/atom_javascript_dialog_manager.h"
 #include "browser/browser.h"
+#include "browser/devtools_delegate.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"
@@ -195,30 +193,8 @@ void NativeWindow::DebugDevTools() {
 
   base::DictionaryValue options;
   NativeWindow* window = NativeWindow::Create(&options);
-
-  // Receive devtool's web contents.
-  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();
-
-  // Setup devtools.
-  window->devtools_agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(
-      devtools_web_contents->GetRenderViewHost());
-  window->devtools_client_host_.reset(
-      content::DevToolsClientHost::CreateDevToolsFrontendHost(
-          window->GetWebContents(), window));
-  content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
-      window->devtools_agent_host_.get(), window->devtools_client_host_.get());
-
-  // Done.
-  window->InitFromOptions(&options);
-  window->GetWebContents()->GetController().LoadURL(
-      GURL("chrome-devtools://devtools/devtools.html"),
-      content::Referrer(),
-      content::PAGE_TRANSITION_AUTO_TOPLEVEL,
-      std::string());
+  window->devtools_delegate_.reset(new DevToolsDelegate(
+      window, GetDevToolsWebContents()));
 }
 
 void NativeWindow::FocusOnWebView() {
@@ -307,6 +283,13 @@ content::WebContents* NativeWindow::GetWebContents() const {
   return inspectable_web_contents_->GetWebContents();
 }
 
+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();
+}
+
 void NativeWindow::NotifyWindowClosed() {
   if (is_closed_)
     return;
@@ -436,14 +419,6 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
   FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
 }
 
-void NativeWindow::AboutToNavigateRenderView(
-      content::RenderViewHost* render_view_host) {
-  // Setup devtools frontend if we are devtools window.
-  if (devtools_client_host_)
-    content::DevToolsClientHost::SetupDevToolsFrontendClient(
-        GetWebContents()->GetRenderViewHost());
-}
-
 void NativeWindow::RenderViewDeleted(content::RenderViewHost* rvh) {
   FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
                     OnRenderViewDeleted(rvh->GetProcess()->GetID(),
@@ -493,14 +468,6 @@ void NativeWindow::Observe(int type,
   }
 }
 
-void NativeWindow::DispatchOnEmbedder(const std::string& message) {
-}
-
-void NativeWindow::InspectedContentsClosing() {
-  // We are acting as devtools debugger, safe to close here.
-  CloseImmediately();
-}
-
 void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
                                      bool succeed,
                                      const SkBitmap& bitmap) {
index bf31049cd7f7a3a094707a18a514ebcfc8954c80..14268ccbd8d9d719b81fa075829d6b658192f82b 100644 (file)
@@ -12,7 +12,6 @@
 #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"
@@ -30,8 +29,6 @@ class InspectableWebContents;
 
 namespace content {
 class BrowserContext;
-class DevToolsAgentHost;
-class DevToolsClientHost;
 class WebContents;
 }
 
@@ -48,12 +45,12 @@ class Message;
 namespace atom {
 
 class AtomJavaScriptDialogManager;
+class DevToolsDelegate;
 struct DraggableRegion;
 
 class NativeWindow : public brightray::DefaultWebContentsDelegate,
                      public content::WebContentsObserver,
-                     public content::NotificationObserver,
-                     public content::DevToolsFrontendHostDelegate {
+                     public content::NotificationObserver {
  public:
   typedef base::Callback<void(const std::vector<unsigned char>& buffer)>
       CapturePageCallback;
@@ -154,6 +151,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void CloseWebContents();
 
   content::WebContents* GetWebContents() const;
+  content::WebContents* GetDevToolsWebContents() const;
 
   void AddObserver(NativeWindowObserver* obs) {
     observers_.AddObserver(obs);
@@ -210,8 +208,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
 
   // Implementations of content::WebContentsObserver.
-  virtual void AboutToNavigateRenderView(
-      content::RenderViewHost* render_view_host) OVERRIDE;
   virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
   virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE;
@@ -222,10 +218,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
                        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_;
 
@@ -266,12 +258,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
 
   base::WeakPtrFactory<NativeWindow> weak_factory_;
 
+  scoped_ptr<DevToolsDelegate> devtools_delegate_;
   scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
   scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
 
-  scoped_refptr<content::DevToolsAgentHost> devtools_agent_host_;
-  scoped_ptr<content::DevToolsClientHost> devtools_client_host_;
-
   DISALLOW_COPY_AND_ASSIGN(NativeWindow);
 };