Separate devtools code out.
This commit is contained in:
parent
99c0de6a1a
commit
8b9d35d84e
5 changed files with 123 additions and 57 deletions
2
atom.gyp
2
atom.gyp
|
@ -90,6 +90,8 @@
|
||||||
'browser/browser_mac.mm',
|
'browser/browser_mac.mm',
|
||||||
'browser/browser_win.cc',
|
'browser/browser_win.cc',
|
||||||
'browser/browser_observer.h',
|
'browser/browser_observer.h',
|
||||||
|
'browser/devtools_delegate.cc',
|
||||||
|
'browser/devtools_delegate.h',
|
||||||
'browser/native_window.cc',
|
'browser/native_window.cc',
|
||||||
'browser/native_window.h',
|
'browser/native_window.h',
|
||||||
'browser/native_window_gtk.cc',
|
'browser/native_window_gtk.cc',
|
||||||
|
|
59
browser/devtools_delegate.cc
Normal file
59
browser/devtools_delegate.cc
Normal file
|
@ -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
|
48
browser/devtools_delegate.h
Normal file
48
browser/devtools_delegate.h
Normal file
|
@ -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_
|
|
@ -18,11 +18,9 @@
|
||||||
#include "browser/atom_browser_main_parts.h"
|
#include "browser/atom_browser_main_parts.h"
|
||||||
#include "browser/atom_javascript_dialog_manager.h"
|
#include "browser/atom_javascript_dialog_manager.h"
|
||||||
#include "browser/browser.h"
|
#include "browser/browser.h"
|
||||||
|
#include "browser/devtools_delegate.h"
|
||||||
#include "browser/window_list.h"
|
#include "browser/window_list.h"
|
||||||
#include "content/public/browser/devtools_agent_host.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/invalidate_type.h"
|
||||||
#include "content/public/browser/navigation_entry.h"
|
#include "content/public/browser/navigation_entry.h"
|
||||||
#include "content/public/browser/notification_details.h"
|
#include "content/public/browser/notification_details.h"
|
||||||
|
@ -195,30 +193,8 @@ void NativeWindow::DebugDevTools() {
|
||||||
|
|
||||||
base::DictionaryValue options;
|
base::DictionaryValue options;
|
||||||
NativeWindow* window = NativeWindow::Create(&options);
|
NativeWindow* window = NativeWindow::Create(&options);
|
||||||
|
window->devtools_delegate_.reset(new DevToolsDelegate(
|
||||||
// Receive devtool's web contents.
|
window, GetDevToolsWebContents()));
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::FocusOnWebView() {
|
void NativeWindow::FocusOnWebView() {
|
||||||
|
@ -307,6 +283,13 @@ content::WebContents* NativeWindow::GetWebContents() const {
|
||||||
return inspectable_web_contents_->GetWebContents();
|
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() {
|
void NativeWindow::NotifyWindowClosed() {
|
||||||
if (is_closed_)
|
if (is_closed_)
|
||||||
return;
|
return;
|
||||||
|
@ -436,14 +419,6 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
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) {
|
void NativeWindow::RenderViewDeleted(content::RenderViewHost* rvh) {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||||
OnRenderViewDeleted(rvh->GetProcess()->GetID(),
|
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,
|
void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
|
||||||
bool succeed,
|
bool succeed,
|
||||||
const SkBitmap& bitmap) {
|
const SkBitmap& bitmap) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "base/observer_list.h"
|
#include "base/observer_list.h"
|
||||||
#include "browser/native_window_observer.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_registrar.h"
|
||||||
#include "content/public/browser/notification_observer.h"
|
#include "content/public/browser/notification_observer.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
|
@ -30,8 +29,6 @@ class InspectableWebContents;
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class BrowserContext;
|
class BrowserContext;
|
||||||
class DevToolsAgentHost;
|
|
||||||
class DevToolsClientHost;
|
|
||||||
class WebContents;
|
class WebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +45,12 @@ class Message;
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class AtomJavaScriptDialogManager;
|
class AtomJavaScriptDialogManager;
|
||||||
|
class DevToolsDelegate;
|
||||||
struct DraggableRegion;
|
struct DraggableRegion;
|
||||||
|
|
||||||
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
public content::WebContentsObserver,
|
public content::WebContentsObserver,
|
||||||
public content::NotificationObserver,
|
public content::NotificationObserver {
|
||||||
public content::DevToolsFrontendHostDelegate {
|
|
||||||
public:
|
public:
|
||||||
typedef base::Callback<void(const std::vector<unsigned char>& buffer)>
|
typedef base::Callback<void(const std::vector<unsigned char>& buffer)>
|
||||||
CapturePageCallback;
|
CapturePageCallback;
|
||||||
|
@ -154,6 +151,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
virtual void CloseWebContents();
|
virtual void CloseWebContents();
|
||||||
|
|
||||||
content::WebContents* GetWebContents() const;
|
content::WebContents* GetWebContents() const;
|
||||||
|
content::WebContents* GetDevToolsWebContents() const;
|
||||||
|
|
||||||
void AddObserver(NativeWindowObserver* obs) {
|
void AddObserver(NativeWindowObserver* obs) {
|
||||||
observers_.AddObserver(obs);
|
observers_.AddObserver(obs);
|
||||||
|
@ -210,8 +208,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
|
virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
|
||||||
|
|
||||||
// Implementations of content::WebContentsObserver.
|
// Implementations of content::WebContentsObserver.
|
||||||
virtual void AboutToNavigateRenderView(
|
|
||||||
content::RenderViewHost* render_view_host) OVERRIDE;
|
|
||||||
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
|
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
|
||||||
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
|
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
|
||||||
virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) 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::NotificationSource& source,
|
||||||
const content::NotificationDetails& details) OVERRIDE;
|
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.
|
// Whether window has standard frame.
|
||||||
bool has_frame_;
|
bool has_frame_;
|
||||||
|
|
||||||
|
@ -266,12 +258,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
|
|
||||||
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||||
|
|
||||||
|
scoped_ptr<DevToolsDelegate> devtools_delegate_;
|
||||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||||
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
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);
|
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue