summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 17:14:39 +0000
committerdgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 17:14:39 +0000
commit657e9e5d7bea9145db790e14ec9be4ed8de47aeb (patch)
tree461f340d9ade0181464c7483feb7e169d1fa2a4e
parent8b56bd0b75e103c157ed25d96a4c15832f875bc7 (diff)
downloadchromium_src-657e9e5d7bea9145db790e14ec9be4ed8de47aeb.zip
chromium_src-657e9e5d7bea9145db790e14ec9be4ed8de47aeb.tar.gz
chromium_src-657e9e5d7bea9145db790e14ec9be4ed8de47aeb.tar.bz2
[DevTools] Move DevToolsClientHost functionality out of DevToolsFrontendHost.
DevToolsFrontendHost is just a transport now. Next step is to remove HandleMessageFromDevToolsFrontendToBackend, make it one of the embedder messages, and allow embedder to talk to backend in itself. BUG=398046 Review URL: https://codereview.chromium.org/427143003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287027 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/devtools/devtools_ui_bindings.cc54
-rw-r--r--chrome/browser/devtools/devtools_ui_bindings.h25
-rw-r--r--chrome/browser/devtools/devtools_window.cc18
-rw-r--r--chrome/browser/ui/webui/inspect_ui.cc2
-rw-r--r--content/browser/devtools/devtools_frontend_host.cc96
-rw-r--r--content/browser/devtools/devtools_frontend_host.h51
-rw-r--r--content/browser/devtools/devtools_frontend_host_impl.cc66
-rw-r--r--content/browser/devtools/devtools_frontend_host_impl.h36
-rw-r--r--content/content_browser.gypi6
-rw-r--r--content/public/browser/devtools_client_host.h9
-rw-r--r--content/public/browser/devtools_frontend_host.h53
-rw-r--r--content/public/browser/devtools_frontend_host_delegate.h29
-rw-r--r--content/shell/browser/shell_devtools_frontend.cc26
-rw-r--r--content/shell/browser/shell_devtools_frontend.h17
14 files changed, 255 insertions, 233 deletions
diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc
index dcef0cb..620f432 100644
--- a/chrome/browser/devtools/devtools_ui_bindings.cc
+++ b/chrome/browser/devtools/devtools_ui_bindings.cc
@@ -259,6 +259,16 @@ void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() {
void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone(
base::TerminationStatus status) {
+ switch (status) {
+ case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
+ case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
+ case base::TERMINATION_STATUS_PROCESS_CRASHED:
+ content::DevToolsManager::GetInstance()->ClientHostClosing(
+ devtools_bindings_);
+ break;
+ default:
+ break;
+ }
devtools_bindings_->delegate_->RenderProcessGone();
}
@@ -266,10 +276,13 @@ void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView(
content::RenderViewHost* render_view_host) {
content::NavigationEntry* entry =
web_contents()->GetController().GetActiveEntry();
- if (devtools_bindings_->url_ == entry->GetURL())
- content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host);
- else
+ if (devtools_bindings_->url_ == entry->GetURL()) {
+ devtools_bindings_->frontend_host_.reset(
+ content::DevToolsFrontendHost::Create(
+ render_view_host, devtools_bindings_));
+ } else {
delete devtools_bindings_;
+ }
}
void DevToolsUIBindings::FrontendWebContentsObserver::
@@ -314,8 +327,6 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents,
frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false;
- frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(
- web_contents_, this));
file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_));
file_system_indexer_ = new DevToolsFileSystemIndexer();
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
@@ -342,8 +353,7 @@ DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents,
}
DevToolsUIBindings::~DevToolsUIBindings() {
- content::DevToolsManager::GetInstance()->ClientHostClosing(
- frontend_host_.get());
+ content::DevToolsManager::GetInstance()->ClientHostClosing(this);
for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin());
jobs_it != indexing_jobs_.end(); ++jobs_it) {
@@ -354,10 +364,7 @@ DevToolsUIBindings::~DevToolsUIBindings() {
SetDevicesUpdatesEnabled(false);
}
-void DevToolsUIBindings::InspectedContentsClosing() {
- delegate_->InspectedContentsClosing();
-}
-
+// content::NotificationObserver overrides ------------------------------------
void DevToolsUIBindings::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -365,7 +372,9 @@ void DevToolsUIBindings::Observe(int type,
UpdateTheme();
}
-void DevToolsUIBindings::DispatchOnEmbedder(const std::string& message) {
+// content::DevToolsFrontendHost::Delegate implementation ---------------------
+void DevToolsUIBindings::HandleMessageFromDevToolsFrontend(
+ const std::string& message) {
std::string method;
base::ListValue empty_params;
base::ListValue* params = &empty_params;
@@ -394,6 +403,27 @@ void DevToolsUIBindings::DispatchOnEmbedder(const std::string& message) {
}
}
+void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend(
+ const std::string& message) {
+ content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend(
+ this, message);
+}
+
+// content::DevToolsClientHost implementation ---------------------------------
+void DevToolsUIBindings::DispatchOnInspectorFrontend(
+ const std::string& message) {
+ if (frontend_host_)
+ frontend_host_->DispatchOnDevToolsFrontend(message);
+}
+
+void DevToolsUIBindings::InspectedContentsClosing() {
+ delegate_->InspectedContentsClosing();
+}
+
+void DevToolsUIBindings::ReplacedWithAnotherClient() {
+}
+
+// DevToolsEmbedderMessageDispatcher::Delegate implementation -----------------
void DevToolsUIBindings::ActivateWindow() {
delegate_->ActivateWindow();
}
diff --git a/chrome/browser/devtools/devtools_ui_bindings.h b/chrome/browser/devtools/devtools_ui_bindings.h
index 8ebd805..2ec6de5 100644
--- a/chrome/browser/devtools/devtools_ui_bindings.h
+++ b/chrome/browser/devtools/devtools_ui_bindings.h
@@ -18,7 +18,7 @@
#include "chrome/browser/devtools/devtools_file_system_indexer.h"
#include "chrome/browser/devtools/devtools_targets_ui.h"
#include "content/public/browser/devtools_client_host.h"
-#include "content/public/browser/devtools_frontend_host_delegate.h"
+#include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/size.h"
@@ -34,9 +34,10 @@ class WebContents;
// Base implementation of DevTools bindings around front-end.
class DevToolsUIBindings : public content::NotificationObserver,
- public content::DevToolsFrontendHostDelegate,
+ public content::DevToolsFrontendHost::Delegate,
public DevToolsEmbedderMessageDispatcher::Delegate,
- public DevToolsAndroidBridge::DeviceCountListener {
+ public DevToolsAndroidBridge::DeviceCountListener,
+ public content::DevToolsClientHost {
public:
static GURL ApplyThemeToURL(Profile* profile, const GURL& base_url);
@@ -65,7 +66,6 @@ class DevToolsUIBindings : public content::NotificationObserver,
content::WebContents* web_contents() { return web_contents_; }
Profile* profile() { return profile_; }
- content::DevToolsClientHost* frontend_host() { return frontend_host_.get(); }
// Takes ownership over the |delegate|.
void SetDelegate(Delegate* delegate);
@@ -74,16 +74,23 @@ class DevToolsUIBindings : public content::NotificationObserver,
const base::Value* arg2,
const base::Value* arg3);
private:
- // content::NotificationObserver:
+ // content::NotificationObserver overrides.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // content::DevToolsFrontendHostDelegate override:
+ // content::DevToolsFrontendHost::Delegate implementation.
+ virtual void HandleMessageFromDevToolsFrontend(
+ const std::string& message) OVERRIDE;
+ virtual void HandleMessageFromDevToolsFrontendToBackend(
+ const std::string& message) OVERRIDE;
+
+ // content::DevToolsClientHost implementation.
+ virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
virtual void InspectedContentsClosing() OVERRIDE;
- virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE;
+ virtual void ReplacedWithAnotherClient() OVERRIDE;
- // DevToolsEmbedderMessageDispatcher::Delegate overrides:
+ // DevToolsEmbedderMessageDispatcher::Delegate implementation.
virtual void ActivateWindow() OVERRIDE;
virtual void CloseWindow() OVERRIDE;
virtual void SetInspectedPageBounds(const gfx::Rect& rect) OVERRIDE;
@@ -163,7 +170,7 @@ class DevToolsUIBindings : public content::NotificationObserver,
content::WebContents* web_contents_;
scoped_ptr<Delegate> delegate_;
content::NotificationRegistrar registrar_;
- scoped_ptr<content::DevToolsClientHost> frontend_host_;
+ scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
scoped_ptr<DevToolsFileHelper> file_helper_;
scoped_refptr<DevToolsFileSystemIndexer> file_system_indexer_;
typedef std::map<
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index 1a6962f..0dd6dbb 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -427,7 +427,7 @@ DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker(
window = DevToolsWindow::CreateDevToolsWindowForWorker(profile);
// Will disconnect the current client host if there is one.
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
- worker_agent, window->bindings_->frontend_host());
+ worker_agent, window->bindings_);
}
window->ScheduleShow(DevToolsToggleAction::Show());
return window;
@@ -479,7 +479,7 @@ void DevToolsWindow::OpenExternalFrontend(
window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL,
false, true, false, "");
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
- agent_host, window->bindings_->frontend_host());
+ agent_host, window->bindings_);
}
window->ScheduleShow(DevToolsToggleAction::Show());
}
@@ -502,8 +502,7 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
base::UserMetricsAction("DevTools_InspectRenderer"));
window = Create(
profile, GURL(), inspected_rvh, false, false, true, settings);
- manager->RegisterDevToolsClientHostFor(agent.get(),
- window->bindings_->frontend_host());
+ manager->RegisterDevToolsClientHostFor(agent.get(), window->bindings_);
do_open = true;
}
@@ -799,8 +798,7 @@ DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
++it) {
- if (manager->GetDevToolsAgentHostFor((*it)->bindings_->frontend_host()) ==
- agent_host)
+ if (manager->GetDevToolsAgentHostFor((*it)->bindings_) == agent_host)
return *it;
}
return NULL;
@@ -832,12 +830,12 @@ WebContents* DevToolsWindow::OpenURLFromTab(
content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
scoped_refptr<DevToolsAgentHost> agent_host(
- manager->GetDevToolsAgentHostFor(bindings_->frontend_host()));
+ manager->GetDevToolsAgentHostFor(bindings_));
if (!agent_host.get())
return NULL;
- manager->ClientHostClosing(bindings_->frontend_host());
+ manager->ClientHostClosing(bindings_);
manager->RegisterDevToolsClientHostFor(agent_host.get(),
- bindings_->frontend_host());
+ bindings_);
content::NavigationController::LoadURLParams load_url_params(params.url);
main_web_contents_->GetController().LoadURLWithParams(load_url_params);
@@ -916,7 +914,7 @@ void DevToolsWindow::BeforeUnloadFired(WebContents* tab,
// Docked devtools window closed directly.
if (proceed) {
content::DevToolsManager::GetInstance()->ClientHostClosing(
- bindings_->frontend_host());
+ bindings_);
}
*proceed_to_fire_unload = proceed;
} else {
diff --git a/chrome/browser/ui/webui/inspect_ui.cc b/chrome/browser/ui/webui/inspect_ui.cc
index 70401b1..dc203b6 100644
--- a/chrome/browser/ui/webui/inspect_ui.cc
+++ b/chrome/browser/ui/webui/inspect_ui.cc
@@ -295,7 +295,7 @@ void InspectUI::InspectBrowserWithCustomFrontend(
// Engage remote debugging between front-end and agent host.
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
- agent_host, bindings->frontend_host());
+ agent_host, bindings);
}
void InspectUI::InspectDevices(Browser* browser) {
diff --git a/content/browser/devtools/devtools_frontend_host.cc b/content/browser/devtools/devtools_frontend_host.cc
deleted file mode 100644
index bfa623a..0000000
--- a/content/browser/devtools/devtools_frontend_host.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/browser/devtools/devtools_frontend_host.h"
-
-#include "content/browser/devtools/devtools_manager_impl.h"
-#include "content/browser/renderer_host/render_view_host_impl.h"
-#include "content/browser/web_contents/web_contents_impl.h"
-#include "content/common/devtools_messages.h"
-#include "content/public/browser/devtools_client_host.h"
-#include "content/public/browser/devtools_frontend_host_delegate.h"
-
-namespace content {
-
-// static
-DevToolsClientHost* DevToolsClientHost::CreateDevToolsFrontendHost(
- WebContents* client_web_contents,
- DevToolsFrontendHostDelegate* delegate) {
- return new DevToolsFrontendHost(
- static_cast<WebContentsImpl*>(client_web_contents), delegate);
-}
-
-// static
-void DevToolsClientHost::SetupDevToolsFrontendClient(
- RenderViewHost* frontend_rvh) {
- frontend_rvh->Send(new DevToolsMsg_SetupDevToolsClient(
- frontend_rvh->GetRoutingID()));
-}
-
-DevToolsFrontendHost::DevToolsFrontendHost(
- WebContentsImpl* web_contents,
- DevToolsFrontendHostDelegate* delegate)
- : WebContentsObserver(web_contents),
- delegate_(delegate) {
-}
-
-DevToolsFrontendHost::~DevToolsFrontendHost() {
- DevToolsManager::GetInstance()->ClientHostClosing(this);
-}
-
-void DevToolsFrontendHost::DispatchOnInspectorFrontend(
- const std::string& message) {
- if (!web_contents())
- return;
- RenderViewHostImpl* target_host =
- static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost());
- target_host->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(
- target_host->GetRoutingID(),
- message));
-}
-
-void DevToolsFrontendHost::InspectedContentsClosing() {
- delegate_->InspectedContentsClosing();
-}
-
-void DevToolsFrontendHost::ReplacedWithAnotherClient() {
-}
-
-bool DevToolsFrontendHost::OnMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHost, message)
- IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
- OnDispatchOnInspectorBackend)
- IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder,
- OnDispatchOnEmbedder)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void DevToolsFrontendHost::RenderProcessGone(
- base::TerminationStatus status) {
- switch(status) {
- case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
- case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
- case base::TERMINATION_STATUS_PROCESS_CRASHED:
- DevToolsManager::GetInstance()->ClientHostClosing(this);
- break;
- default:
- break;
- }
-}
-
-void DevToolsFrontendHost::OnDispatchOnInspectorBackend(
- const std::string& message) {
- DevToolsManagerImpl::GetInstance()->DispatchOnInspectorBackend(this, message);
-}
-
-void DevToolsFrontendHost::OnDispatchOnEmbedder(
- const std::string& message) {
- delegate_->DispatchOnEmbedder(message);
-}
-
-} // namespace content
diff --git a/content/browser/devtools/devtools_frontend_host.h b/content/browser/devtools/devtools_frontend_host.h
deleted file mode 100644
index 469d162..0000000
--- a/content/browser/devtools/devtools_frontend_host.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_HOST_H_
-#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_HOST_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "content/public/browser/devtools_client_host.h"
-#include "content/public/browser/web_contents_observer.h"
-
-namespace content {
-
-class DevToolsFrontendHostDelegate;
-class WebContentsImpl;
-
-// This class handles messages from DevToolsClient and calls corresponding
-// methods on DevToolsFrontendHostDelegate which is implemented by the
-// embedder. This allows us to avoid exposing DevTools client messages through
-// the content public API.
-class DevToolsFrontendHost : public DevToolsClientHost,
- public WebContentsObserver {
- public:
- DevToolsFrontendHost(WebContentsImpl* web_contents,
- DevToolsFrontendHostDelegate* delegate);
-
- private:
- virtual ~DevToolsFrontendHost();
-
- // DevToolsClientHost implementation.
- virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
- virtual void InspectedContentsClosing() OVERRIDE;
- virtual void ReplacedWithAnotherClient() OVERRIDE;
-
- // WebContentsObserver overrides.
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
- virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
-
- void OnDispatchOnInspectorBackend(const std::string& message);
- void OnDispatchOnEmbedder(const std::string& message);
-
- DevToolsFrontendHostDelegate* delegate_;
- DISALLOW_COPY_AND_ASSIGN(DevToolsFrontendHost);
-};
-
-} // namespace content
-
-#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_HOST_H_
diff --git a/content/browser/devtools/devtools_frontend_host_impl.cc b/content/browser/devtools/devtools_frontend_host_impl.cc
new file mode 100644
index 0000000..9a81dfd
--- /dev/null
+++ b/content/browser/devtools/devtools_frontend_host_impl.cc
@@ -0,0 +1,66 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/devtools/devtools_frontend_host_impl.h"
+
+#include "content/common/devtools_messages.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+
+namespace content {
+
+// static
+DevToolsFrontendHost* DevToolsFrontendHost::Create(
+ RenderViewHost* frontend_rvh,
+ DevToolsFrontendHost::Delegate* delegate) {
+ return new DevToolsFrontendHostImpl(frontend_rvh, delegate);
+}
+
+DevToolsFrontendHostImpl::DevToolsFrontendHostImpl(
+ RenderViewHost* frontend_rvh,
+ DevToolsFrontendHost::Delegate* delegate)
+ : WebContentsObserver(WebContents::FromRenderViewHost(frontend_rvh)),
+ delegate_(delegate) {
+ frontend_rvh->Send(new DevToolsMsg_SetupDevToolsClient(
+ frontend_rvh->GetRoutingID()));
+}
+
+DevToolsFrontendHostImpl::~DevToolsFrontendHostImpl() {
+}
+
+void DevToolsFrontendHostImpl::DispatchOnDevToolsFrontend(
+ const std::string& message) {
+ if (!web_contents())
+ return;
+ RenderViewHost* target_host = web_contents()->GetRenderViewHost();
+ target_host->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(
+ target_host->GetRoutingID(),
+ message));
+}
+
+bool DevToolsFrontendHostImpl::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHostImpl, message)
+ IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
+ OnDispatchOnInspectorBackend)
+ IPC_MESSAGE_HANDLER(DevToolsHostMsg_DispatchOnEmbedder,
+ OnDispatchOnEmbedder)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void DevToolsFrontendHostImpl::OnDispatchOnInspectorBackend(
+ const std::string& message) {
+ delegate_->HandleMessageFromDevToolsFrontendToBackend(message);
+}
+
+void DevToolsFrontendHostImpl::OnDispatchOnEmbedder(
+ const std::string& message) {
+ delegate_->HandleMessageFromDevToolsFrontend(message);
+}
+
+} // namespace content
diff --git a/content/browser/devtools/devtools_frontend_host_impl.h b/content/browser/devtools/devtools_frontend_host_impl.h
new file mode 100644
index 0000000..b6bb79b
--- /dev/null
+++ b/content/browser/devtools/devtools_frontend_host_impl.h
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_HOST_IMPL_H_
+#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_HOST_IMPL_H_
+
+#include "content/public/browser/devtools_frontend_host.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace content {
+
+class DevToolsFrontendHostImpl : public DevToolsFrontendHost,
+ public WebContentsObserver {
+ public:
+ DevToolsFrontendHostImpl(RenderViewHost* frontend_rvh,
+ DevToolsFrontendHost::Delegate* delegate);
+ virtual ~DevToolsFrontendHostImpl();
+
+ // DevToolsFrontendHost implementation.
+ virtual void DispatchOnDevToolsFrontend(const std::string& message) OVERRIDE;
+
+ private:
+ // WebContentsObserver overrides.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ void OnDispatchOnInspectorBackend(const std::string& message);
+ void OnDispatchOnEmbedder(const std::string& message);
+
+ DevToolsFrontendHost::Delegate* delegate_;
+ DISALLOW_COPY_AND_ASSIGN(DevToolsFrontendHostImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_FRONTEND_HOST_IMPL_H_
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index b1477e4..452985e 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -100,7 +100,7 @@
'public/browser/devtools_external_agent_proxy.h',
'public/browser/devtools_external_agent_proxy_delegate.h',
'public/browser/download_danger_type.h',
- 'public/browser/devtools_frontend_host_delegate.h',
+ 'public/browser/devtools_frontend_host.h',
'public/browser/devtools_http_handler.h',
'public/browser/devtools_http_handler_delegate.h',
'public/browser/devtools_manager.h',
@@ -422,8 +422,8 @@
'browser/devtools/devtools_agent_host_impl.h',
'browser/devtools/devtools_browser_target.cc',
'browser/devtools/devtools_browser_target.h',
- 'browser/devtools/devtools_frontend_host.cc',
- 'browser/devtools/devtools_frontend_host.h',
+ 'browser/devtools/devtools_frontend_host_impl.cc',
+ 'browser/devtools/devtools_frontend_host_impl.h',
'browser/devtools/devtools_http_handler_impl.cc',
'browser/devtools/devtools_http_handler_impl.h',
'browser/devtools/devtools_manager_impl.cc',
diff --git a/content/public/browser/devtools_client_host.h b/content/public/browser/devtools_client_host.h
index fe76d3c..67b7003 100644
--- a/content/public/browser/devtools_client_host.h
+++ b/content/public/browser/devtools_client_host.h
@@ -38,15 +38,6 @@ class CONTENT_EXPORT DevToolsClientHost {
// Called to notify client that it has been kicked out by some other client
// with greater priority.
virtual void ReplacedWithAnotherClient() = 0;
-
- // Creates a DevToolsClientHost for a WebContents containing the default
- // DevTools frontend implementation.
- static DevToolsClientHost* CreateDevToolsFrontendHost(
- WebContents* client_web_contents,
- DevToolsFrontendHostDelegate* delegate);
-
- // Sets up DevToolsClient on the corresponding RenderView.
- static void SetupDevToolsFrontendClient(RenderViewHost* frontend_rvh);
};
} // namespace content
diff --git a/content/public/browser/devtools_frontend_host.h b/content/public/browser/devtools_frontend_host.h
new file mode 100644
index 0000000..ac79df2
--- /dev/null
+++ b/content/public/browser/devtools_frontend_host.h
@@ -0,0 +1,53 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_H_
+#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_H_
+
+#include <string>
+
+#include "content/common/content_export.h"
+
+namespace content {
+
+class RenderViewHost;
+
+// This class dispatches messages between DevTools frontend and Delegate
+// which is implemented by the embedder.
+// This allows us to avoid exposing DevTools frontend messages through
+// the content public API.
+class DevToolsFrontendHost {
+ public:
+ // Delegate actually handles messages from frontend.
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // Message is coming from frontend to the embedder.
+ virtual void HandleMessageFromDevToolsFrontend(
+ const std::string& message) = 0;
+
+ // Message is coming from frontend to the backend.
+ // TODO(dgozman): remove this by making one of the possible messages
+ // passed via the method above.
+ virtual void HandleMessageFromDevToolsFrontendToBackend(
+ const std::string& message) = 0;
+ };
+
+ // Creates a new DevToolsFrontendHost for RenderViewHost where DevTools
+ // frontend is loaded.
+ CONTENT_EXPORT static DevToolsFrontendHost* Create(
+ RenderViewHost* frontend_rvh, Delegate* delegate);
+
+ CONTENT_EXPORT virtual ~DevToolsFrontendHost() {}
+
+ // Dispatches message from embedder/backend to frontend.
+ // TODO(dgozman): remove and make embedder to take care of this.
+ CONTENT_EXPORT virtual void DispatchOnDevToolsFrontend(
+ const std::string& message) = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_H_
diff --git a/content/public/browser/devtools_frontend_host_delegate.h b/content/public/browser/devtools_frontend_host_delegate.h
deleted file mode 100644
index 1d41bef..0000000
--- a/content/public/browser/devtools_frontend_host_delegate.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_DELEGATE_H_
-#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_DELEGATE_H_
-
-#include <string>
-
-namespace content {
-
-// Clients that want to use default DevTools front-end implementation should
-// implement this interface to provide access to the embedding browser from
-// the front-end.
-class DevToolsFrontendHostDelegate {
- public:
- virtual ~DevToolsFrontendHostDelegate() {}
-
- // Dispatch the message from the frontend to the frontend host.
- virtual void DispatchOnEmbedder(const std::string& message) = 0;
-
- // This method is called when the contents inspected by this devtools frontend
- // is closing.
- virtual void InspectedContentsClosing() = 0;
-};
-
-} // namespace content
-
-#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_DELEGATE_H_
diff --git a/content/shell/browser/shell_devtools_frontend.cc b/content/shell/browser/shell_devtools_frontend.cc
index e64685d..fe30edd 100644
--- a/content/shell/browser/shell_devtools_frontend.cc
+++ b/content/shell/browser/shell_devtools_frontend.cc
@@ -106,8 +106,6 @@ ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell,
: WebContentsObserver(frontend_shell->web_contents()),
frontend_shell_(frontend_shell),
agent_host_(agent_host) {
- frontend_host_.reset(
- DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this));
}
ShellDevToolsFrontend::~ShellDevToolsFrontend() {
@@ -115,11 +113,11 @@ ShellDevToolsFrontend::~ShellDevToolsFrontend() {
void ShellDevToolsFrontend::RenderViewCreated(
RenderViewHost* render_view_host) {
- DevToolsClientHost::SetupDevToolsFrontendClient(
- web_contents()->GetRenderViewHost());
- DevToolsManager* manager = DevToolsManager::GetInstance();
- manager->RegisterDevToolsClientHostFor(agent_host_.get(),
- frontend_host_.get());
+ if (!frontend_host_) {
+ frontend_host_.reset(DevToolsFrontendHost::Create(render_view_host, this));
+ DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
+ agent_host_.get(), this);
+ }
}
void ShellDevToolsFrontend::DocumentOnLoadCompletedInMainFrame() {
@@ -128,7 +126,7 @@ void ShellDevToolsFrontend::DocumentOnLoadCompletedInMainFrame() {
}
void ShellDevToolsFrontend::WebContentsDestroyed() {
- DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get());
+ DevToolsManager::GetInstance()->ClientHostClosing(this);
delete this;
}
@@ -137,6 +135,18 @@ void ShellDevToolsFrontend::RenderProcessGone(base::TerminationStatus status) {
WebKitTestController::Get()->DevToolsProcessCrashed();
}
+void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(
+ const std::string& message) {
+ DevToolsManager::GetInstance()->DispatchOnInspectorBackend(
+ this, message);
+}
+
+void ShellDevToolsFrontend::DispatchOnInspectorFrontend(
+ const std::string& message) {
+ if (frontend_host_)
+ frontend_host_->DispatchOnDevToolsFrontend(message);
+}
+
void ShellDevToolsFrontend::InspectedContentsClosing() {
frontend_shell_->Close();
}
diff --git a/content/shell/browser/shell_devtools_frontend.h b/content/shell/browser/shell_devtools_frontend.h
index f08aa24..381ff22 100644
--- a/content/shell/browser/shell_devtools_frontend.h
+++ b/content/shell/browser/shell_devtools_frontend.h
@@ -11,7 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_client_host.h"
-#include "content/public/browser/devtools_frontend_host_delegate.h"
+#include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/web_contents_observer.h"
namespace content {
@@ -24,7 +24,8 @@ class Shell;
class WebContents;
class ShellDevToolsFrontend : public WebContentsObserver,
- public DevToolsFrontendHostDelegate {
+ public DevToolsFrontendHost::Delegate,
+ public DevToolsClientHost {
public:
static ShellDevToolsFrontend* Show(WebContents* inspected_contents);
static ShellDevToolsFrontend* Show(WebContents* inspected_contents,
@@ -47,14 +48,20 @@ class ShellDevToolsFrontend : public WebContentsObserver,
virtual void WebContentsDestroyed() OVERRIDE;
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
- // DevToolsFrontendHostDelegate implementation
- virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE {}
+ // content::DevToolsFrontendHost::Delegate implementation.
+ virtual void HandleMessageFromDevToolsFrontend(
+ const std::string& message) OVERRIDE {}
+ virtual void HandleMessageFromDevToolsFrontendToBackend(
+ const std::string& message) OVERRIDE;
+ // content::DevToolsClientHost implementation.
+ virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
virtual void InspectedContentsClosing() OVERRIDE;
+ virtual void ReplacedWithAnotherClient() OVERRIDE {}
Shell* frontend_shell_;
scoped_refptr<DevToolsAgentHost> agent_host_;
- scoped_ptr<DevToolsClientHost> frontend_host_;
+ scoped_ptr<DevToolsFrontendHost> frontend_host_;
DISALLOW_COPY_AND_ASSIGN(ShellDevToolsFrontend);
};