'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',
--- /dev/null
+// 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
--- /dev/null
+// 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_
#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"
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() {
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;
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(),
}
}
-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) {
#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"
namespace content {
class BrowserContext;
-class DevToolsAgentHost;
-class DevToolsClientHost;
class WebContents;
}
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;
virtual void CloseWebContents();
content::WebContents* GetWebContents() const;
+ content::WebContents* GetDevToolsWebContents() const;
void AddObserver(NativeWindowObserver* obs) {
observers_.AddObserver(obs);
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;
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_;
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);
};