diff options
author | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 16:21:44 +0000 |
---|---|---|
committer | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 16:21:44 +0000 |
commit | 0e12d7d59d4778e1a8ef692d244bf66aea1a80b8 (patch) | |
tree | 11fd0f2f8d0ab431f59084541922d6c971876f99 | |
parent | 5581458c8b7ac9e7117d96606d74e574c41df8d6 (diff) | |
download | chromium_src-0e12d7d59d4778e1a8ef692d244bf66aea1a80b8.zip chromium_src-0e12d7d59d4778e1a8ef692d244bf66aea1a80b8.tar.gz chromium_src-0e12d7d59d4778e1a8ef692d244bf66aea1a80b8.tar.bz2 |
Define DevTools content API
The API consists of the following parts:
* DevToolsManager routes messages between devtools agents and clients
* DevToolsAgentHost provides an abstract interface to the debuggee, currently it is either RenderViewHost or Shared Worker. Client can obtain DevToolsAgentHost from DevToolsAgentHostRegistry.
* DevToolsClientHost is an API that should be implemented by DevTools front-end. There is a default Chromium implementation living in chrome/ and a remote debugging server which also implements this interface. Clients can extend it in order to provide custom front-end. There is a default DevTools front-end implementation and content/ provides a way for creating corresponding DevToolsClientHost by means of DevToolsClientHost::CreateDevToolsFrontendHost. The embedder just needs to provide a concrete delegate.
* This patch also removes DevToolsHost_ForwardToAgent and DevToolsHost_ForwardToClient IPC messages which were used to forward only one message. DevTools IPC messages are now hidden behind the devtools content API.
BUG=104625
TEST=Existing tests
Review URL: http://codereview.chromium.org/8549022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112473 0039d316-1c4b-4281-b951-d872f2087c98
48 files changed, 828 insertions, 644 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 72cdae8..2d92a3a 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -36,8 +36,6 @@ include_rules = [ "+content/common/chrome_application_mac.h", "+content/common/mac/scoped_sending_event.h", "+content/common/view_messages.h", - # TODO(pfeldman) - "+content/common/devtools_messages.h", # TODO(gbilock) "+content/common/intents_messages.h", diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index a48ad44..e6ee1d1 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -79,7 +79,6 @@ #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/download/download_item.h" #include "content/browser/download/save_package.h" #include "content/browser/renderer_host/render_view_host.h" diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc index 9d8ceb6..cc659e6 100644 --- a/chrome/browser/debugger/devtools_sanity_unittest.cc +++ b/chrome/browser/debugger/devtools_sanity_unittest.cc @@ -21,20 +21,23 @@ #include "chrome/common/chrome_paths.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/browser/debugger/devtools_client_host.h" -#include "content/browser/debugger/devtools_manager.h" -#include "content/browser/debugger/worker_devtools_manager.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/browser/worker_host/worker_service.h" #include "content/browser/worker_host/worker_service_observer.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_manager.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" #include "net/test/test_server.h" using content::BrowserThread; +using content::DevToolsManager; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; namespace { @@ -145,7 +148,9 @@ class DevToolsSanityTest : public InProcessBrowserTest { // UnregisterDevToolsClientHostFor may destroy window_ so store the browser // first. Browser* browser = window_->browser(); - devtools_manager->UnregisterDevToolsClientHostFor(inspected_rvh_); + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + inspected_rvh_); + devtools_manager->UnregisterDevToolsClientHostFor(agent); // Wait only when DevToolsWindow has a browser. For docked DevTools, this // is NULL and we skip the wait. @@ -386,12 +391,12 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest { window_ = DevToolsWindow::CreateDevToolsWindowForWorker(profile); window_->Show(DEVTOOLS_TOGGLE_ACTION_NONE); DevToolsAgentHost* agent_host = - WorkerDevToolsManager::GetDevToolsAgentHostForWorker( + DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( worker_data->worker_process_id, worker_data->worker_route_id); DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( agent_host, - window_); + window_->devtools_client_host()); RenderViewHost* client_rvh = window_->GetRenderViewHost(); TabContents* client_contents = client_rvh->delegate()->GetAsTabContents(); if (client_contents->IsLoading()) { diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index a741085..020a242 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -31,7 +31,6 @@ #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/browsing_instance.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" #include "content/browser/load_notification_details.h" #include "content/browser/renderer_host/render_view_host.h" @@ -39,9 +38,9 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" -#include "content/common/devtools_messages.h" #include "content/public/browser/content_browser_client.h" -#include "content/public/browser/devtools_frontend_window.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_manager.h" #include "content/public/browser/notification_source.h" #include "content/public/common/bindings_policy.h" #include "grit/generated_resources.h" @@ -53,6 +52,11 @@ base::LazyInstance<DevToolsWindowList, g_instances = LAZY_INSTANCE_INITIALIZER; } // namespace +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsClientHost; +using content::DevToolsManager; + const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; // static @@ -68,9 +72,13 @@ TabContentsWrapper* DevToolsWindow::GetDevToolsContents( if (!inspected_tab) return NULL; + if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost( + inspected_tab->render_view_host())) + return NULL; + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + inspected_tab->render_view_host()); DevToolsManager* manager = DevToolsManager::GetInstance(); - DevToolsClientHost* client_host = manager-> - GetDevToolsClientHostFor(inspected_tab->render_view_host()); + DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent); DevToolsWindow* window = AsDevToolsWindow(client_host); if (!window || !window->is_docked()) return NULL; @@ -95,16 +103,17 @@ DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( Profile* profile, DevToolsAgentHost* worker_agent) { DevToolsWindow* window; - DevToolsClientHost* client = - DevToolsManager::GetInstance()->GetDevToolsClientHostFor(worker_agent); + DevToolsClientHost* client = content::DevToolsManager::GetInstance()-> + GetDevToolsClientHostFor(worker_agent); if (client) { window = AsDevToolsWindow(client); if (!window) return NULL; } else { window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); - DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(worker_agent, - window); + DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( + worker_agent, + window->frontend_host_); } window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); return window; @@ -133,10 +142,9 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, int x, int y) { - inspected_rvh->Send(new DevToolsAgentMsg_InspectElement( - inspected_rvh->routing_id(), - x, - y)); + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + inspected_rvh); + DevToolsManager::GetInstance()->InspectElement(agent, x, y); // TODO(loislo): we should initiate DevTools window opening from within // renderer. Otherwise, we still can hit a race condition here. OpenDevToolsWindow(inspected_rvh); @@ -171,18 +179,17 @@ DevToolsWindow::DevToolsWindow(TabContentsWrapper* tab_contents, browser_(NULL), docked_(docked), is_loaded_(false), - action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { + action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE), + frontend_host_(NULL) { + frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost( + tab_contents->tab_contents(), + this); g_instances.Get().push_back(this); // Wipe out page icon so that the default application icon is used. NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); entry->favicon().set_bitmap(SkBitmap()); entry->favicon().set_is_valid(true); - // Install DevTools front-end message handler. - content::SetupDevToolsFrontendDelegate( - tab_contents->tab_contents(), - this); - // Register on-load actions. registrar_.Add( this, @@ -214,13 +221,6 @@ DevToolsWindow::~DevToolsWindow() { instances.erase(it); } -void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { - RenderViewHost* target_host = tab_contents_->render_view_host(); - IPC::Message* m = new IPC::Message(message); - m->set_routing_id(target_host->routing_id()); - target_host->Send(m); -} - void DevToolsWindow::InspectedTabClosing() { if (docked_) { // Update dev tools to reflect removed dev tools window. @@ -477,7 +477,7 @@ void DevToolsWindow::Observe(int type, // of window.Close event. // Notify manager that this DevToolsClientHost no longer exists and // initiate self-destuct here. - NotifyCloseListener(); + DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_); delete this; } } else if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { @@ -598,13 +598,14 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( RenderViewHost* inspected_rvh, bool force_open, DevToolsToggleAction action) { + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + inspected_rvh); DevToolsManager* manager = DevToolsManager::GetInstance(); - - DevToolsClientHost* host = manager->GetDevToolsClientHostFor(inspected_rvh); + DevToolsClientHost* host = manager->GetDevToolsClientHostFor(agent); DevToolsWindow* window = AsDevToolsWindow(host); if (host != NULL && window == NULL) { // Break remote debugging / extension debugging session. - manager->UnregisterDevToolsClientHostFor(inspected_rvh); + manager->UnregisterDevToolsClientHostFor(agent); } bool do_open = force_open; @@ -613,7 +614,7 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( inspected_rvh->process()->GetBrowserContext()); bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked); window = Create(profile, inspected_rvh, docked, false); - manager->RegisterDevToolsClientHostFor(inspected_rvh, window); + manager->RegisterDevToolsClientHostFor(agent, window->frontend_host_); do_open = true; } @@ -622,7 +623,7 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( if (!window->is_docked() || do_open) window->Show(action); else - manager->UnregisterDevToolsClientHostFor(inspected_rvh); + manager->UnregisterDevToolsClientHostFor(agent); return window; } @@ -635,17 +636,12 @@ DevToolsWindow* DevToolsWindow::AsDevToolsWindow( DevToolsWindowList& instances = g_instances.Get(); for (DevToolsWindowList::iterator it = instances.begin(); it != instances.end(); ++it) { - DevToolsClientHost* client = *it; - if (client == client_host) + if ((*it)->frontend_host_ == client_host) return *it; } return NULL; } -void DevToolsWindow::ForwardToDevToolsAgent(const IPC::Message& message) { - DevToolsManager::GetInstance()->ForwardToDevToolsAgent(this, message); -} - void DevToolsWindow::ActivateWindow() { if (!docked_) { if (!browser_->window()->IsActive()) { @@ -660,7 +656,7 @@ void DevToolsWindow::ActivateWindow() { void DevToolsWindow::CloseWindow() { DCHECK(docked_); - NotifyCloseListener(); + DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_); InspectedTabClosing(); } diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h index a9616e3..49c2c17 100644 --- a/chrome/browser/debugger/devtools_window.h +++ b/chrome/browser/debugger/devtools_window.h @@ -11,9 +11,9 @@ #include "base/basictypes.h" #include "chrome/browser/debugger/devtools_toggle_action.h" -#include "content/browser/debugger/devtools_client_host.h" #include "content/browser/tab_contents/tab_contents_delegate.h" -#include "content/public/browser/devtools_frontend_window_delegate.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -23,7 +23,6 @@ class Message; class Browser; class BrowserWindow; -class DevToolsAgentHost; class PrefService; class Profile; class RenderViewHost; @@ -33,10 +32,14 @@ namespace base { class Value; } -class DevToolsWindow : public DevToolsClientHost, - private content::NotificationObserver, +namespace content { +class DevToolsAgentHost; +class DevToolsClientHost; +} + +class DevToolsWindow : private content::NotificationObserver, private TabContentsDelegate, - private content::DevToolsFrontendWindowDelegate { + private content::DevToolsFrontendHostDelegate { public: static const char kDevToolsApp[]; static void RegisterUserPrefs(PrefService* prefs); @@ -45,7 +48,7 @@ class DevToolsWindow : public DevToolsClientHost, static DevToolsWindow* OpenDevToolsWindowForWorker( Profile* profile, - DevToolsAgentHost* worker_agent); + content::DevToolsAgentHost* worker_agent); static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); static DevToolsWindow* OpenDevToolsWindow(RenderViewHost* inspected_rvh); static DevToolsWindow* ToggleDevToolsWindow(RenderViewHost* inspected_rvh, @@ -55,7 +58,6 @@ class DevToolsWindow : public DevToolsClientHost, virtual ~DevToolsWindow(); // Overridden from DevToolsClientHost. - virtual void SendMessageToClient(const IPC::Message& message) OVERRIDE; virtual void InspectedTabClosing() OVERRIDE; virtual void TabReplaced(TabContents* new_tab) OVERRIDE; RenderViewHost* GetRenderViewHost(); @@ -65,6 +67,9 @@ class DevToolsWindow : public DevToolsClientHost, TabContentsWrapper* tab_contents() { return tab_contents_; } Browser* browser() { return browser_; } // For tests. bool is_docked() { return docked_; } + content::DevToolsClientHost* devtools_client_host() { + return frontend_host_; + } private: static DevToolsWindow* Create(Profile* profile, @@ -121,10 +126,9 @@ class DevToolsWindow : public DevToolsClientHost, static DevToolsWindow* ToggleDevToolsWindow(RenderViewHost* inspected_rvh, bool force_open, DevToolsToggleAction action); - static DevToolsWindow* AsDevToolsWindow(DevToolsClientHost*); + static DevToolsWindow* AsDevToolsWindow(content::DevToolsClientHost*); // content::DevToolsClientHandlerDelegate overrides. - virtual void ForwardToDevToolsAgent(const IPC::Message& message) OVERRIDE; virtual void ActivateWindow() OVERRIDE; virtual void CloseWindow() OVERRIDE; virtual void MoveWindow(int x, int y) OVERRIDE; @@ -132,6 +136,7 @@ class DevToolsWindow : public DevToolsClientHost, virtual void UndockWindow() OVERRIDE; virtual void SaveToFile(const std::string& suggested_file_name, const std::string& content) OVERRIDE; + void RequestSetDocked(bool docked); Profile* profile_; @@ -142,6 +147,7 @@ class DevToolsWindow : public DevToolsClientHost, bool is_loaded_; DevToolsToggleAction action_on_load_; content::NotificationRegistrar registrar_; + content::DevToolsClientHost* frontend_host_; DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); }; diff --git a/chrome/browser/extensions/extension_debugger_api.cc b/chrome/browser/extensions/extension_debugger_api.cc index 80d7970..c9bcb6c 100644 --- a/chrome/browser/extensions/extension_debugger_api.cc +++ b/chrome/browser/extensions/extension_debugger_api.cc @@ -22,13 +22,18 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_error_utils.h" -#include "content/browser/debugger/devtools_client_host.h" -#include "content/browser/debugger/devtools_manager.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_manager.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" #include "content/public/browser/notification_source.h" #include "webkit/glue/webkit_glue.h" +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsClientHost; +using content::DevToolsManager; + namespace keys = extension_debugger_api_constants; class ExtensionDevToolsClientHost : public DevToolsClientHost, @@ -49,7 +54,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, // DevToolsClientHost interface virtual void InspectedTabClosing(); - virtual void SendMessageToClient(const IPC::Message& msg); + virtual void DispatchOnInspectorFrontend(const std::string& message); virtual void TabReplaced(TabContents* tab_contents); virtual void FrameNavigating(const std::string& url) {} @@ -58,7 +63,6 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details); - void OnDispatchOnInspectorFrontend(const std::string& data); TabContents* tab_contents_; std::string extension_id_; @@ -98,8 +102,12 @@ class AttachedClientHosts { } ExtensionDevToolsClientHost* Lookup(RenderViewHost* rvh) { + if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)) + return NULL; + DevToolsAgentHost* agent = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh); DevToolsClientHost* client_host = - DevToolsManager::GetInstance()->GetDevToolsClientHostFor(rvh); + DevToolsManager::GetInstance()->GetDevToolsClientHostFor(agent); std::set<DevToolsClientHost*>::iterator it = client_hosts_.find(client_host); if (it == client_hosts_.end()) @@ -130,9 +138,9 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( content::Source<Profile>(profile)); // Attach to debugger and tell it we are ready. - DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( - tab_contents_->render_view_host(), - this); + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents_->render_view_host()); + DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); } ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { @@ -163,22 +171,13 @@ void ExtensionDevToolsClientHost::InspectedTabClosing() { delete this; } -void ExtensionDevToolsClientHost::SendMessageToClient( - const IPC::Message& msg) { - IPC_BEGIN_MESSAGE_MAP(ExtensionDevToolsClientHost, msg) - IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, - OnDispatchOnInspectorFrontend); - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() -} - void ExtensionDevToolsClientHost::TabReplaced( TabContents* tab_contents) { tab_contents_ = tab_contents; } void ExtensionDevToolsClientHost::Close() { - DevToolsClientHost::NotifyCloseListener(); + DevToolsManager::GetInstance()->ClientHostClosing(this); delete this; } @@ -196,10 +195,7 @@ void ExtensionDevToolsClientHost::SendMessageToBackend( std::string json_args; base::JSONWriter::Write(&protocol_request, false, &json_args); - DevToolsManager::GetInstance()->ForwardToDevToolsAgent( - this, - DevToolsAgentMsg_DispatchOnInspectorBackend(MSG_ROUTING_NONE, - json_args)); + DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); } void ExtensionDevToolsClientHost::Observe( @@ -210,14 +206,14 @@ void ExtensionDevToolsClientHost::Observe( Close(); } -void ExtensionDevToolsClientHost::OnDispatchOnInspectorFrontend( - const std::string& data) { +void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend( + const std::string& message) { Profile* profile = Profile::FromBrowserContext(tab_contents_->browser_context()); if (profile == NULL || !profile->GetExtensionEventRouter()) return; - scoped_ptr<Value> result(base::JSONReader::Read(data, false)); + scoped_ptr<Value> result(base::JSONReader::Read(message, false)); if (!result->IsType(Value::TYPE_DICTIONARY)) return; DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); @@ -314,8 +310,10 @@ bool AttachDebuggerFunction::RunImpl() { return false; } + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + contents_->render_view_host()); DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> - GetDevToolsClientHostFor(contents_->render_view_host()); + GetDevToolsClientHostFor(agent); if (client_host != NULL) { error_ = ExtensionErrorUtils::FormatErrorMessage( diff --git a/chrome/browser/extensions/extension_devtools_bridge.cc b/chrome/browser/extensions/extension_devtools_bridge.cc index 5372296..237e072 100644 --- a/chrome/browser/extensions/extension_devtools_bridge.cc +++ b/chrome/browser/extensions/extension_devtools_bridge.cc @@ -15,9 +15,13 @@ #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_manager.h" + +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsManager; ExtensionDevToolsBridge::ExtensionDevToolsBridge(int tab_id, Profile* profile) @@ -56,29 +60,25 @@ bool ExtensionDevToolsBridge::RegisterAsDevToolsClientHost() { &browser, &tab_strip, &contents, &tab_index)) { DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - if (devtools_manager->GetDevToolsClientHostFor(contents-> - render_view_host()) != NULL) + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + contents->render_view_host()); + if (devtools_manager->GetDevToolsClientHostFor(agent)) return false; - devtools_manager->RegisterDevToolsClientHostFor( - contents->render_view_host(), this); + devtools_manager->RegisterDevToolsClientHostFor(agent, this); // Following messages depend on inspector protocol that is not yet // finalized. // 1. Start timeline profiler. - devtools_manager->ForwardToDevToolsAgent( + devtools_manager->DispatchOnInspectorBackend( this, - DevToolsAgentMsg_DispatchOnInspectorBackend( - MSG_ROUTING_NONE, - FormatDevToolsMessage(2, "Timeline.start"))); + FormatDevToolsMessage(2, "Timeline.start")); // 2. Enable network resource tracking. - devtools_manager->ForwardToDevToolsAgent( + devtools_manager->DispatchOnInspectorBackend( this, - DevToolsAgentMsg_DispatchOnInspectorBackend( - MSG_ROUTING_NONE, - FormatDevToolsMessage(3, "Network.enable"))); + FormatDevToolsMessage(3, "Network.enable")); return true; } @@ -87,8 +87,7 @@ bool ExtensionDevToolsBridge::RegisterAsDevToolsClientHost() { void ExtensionDevToolsBridge::UnregisterAsDevToolsClientHost() { DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - - NotifyCloseListener(); + DevToolsManager::GetInstance()->ClientHostClosing(this); } // If the tab we are looking at is going away then we fire a closing event at @@ -106,20 +105,7 @@ void ExtensionDevToolsBridge::InspectedTabClosing() { extension_devtools_manager_->BridgeClosingForTab(tab_id_); } -void ExtensionDevToolsBridge::SendMessageToClient(const IPC::Message& msg) { - IPC_BEGIN_MESSAGE_MAP(ExtensionDevToolsBridge, msg) - IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, - OnDispatchOnInspectorFrontend); - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() -} - -void ExtensionDevToolsBridge::TabReplaced(TabContents* new_tab) { - // We don't update the tab id as it needs to remain the same so that we can - // properly unregister. -} - -void ExtensionDevToolsBridge::OnDispatchOnInspectorFrontend( +void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( const std::string& data) { DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); @@ -127,3 +113,8 @@ void ExtensionDevToolsBridge::OnDispatchOnInspectorFrontend( profile_->GetExtensionEventRouter()->DispatchEventToRenderers( on_page_event_name_, json, profile_, GURL()); } + +void ExtensionDevToolsBridge::TabReplaced(TabContents* new_tab) { + // We don't update the tab id as it needs to remain the same so that we can + // properly unregister. +} diff --git a/chrome/browser/extensions/extension_devtools_bridge.h b/chrome/browser/extensions/extension_devtools_bridge.h index dbcabd4..6c5c292 100644 --- a/chrome/browser/extensions/extension_devtools_bridge.h +++ b/chrome/browser/extensions/extension_devtools_bridge.h @@ -11,12 +11,12 @@ #include "base/memory/ref_counted.h" #include "chrome/browser/extensions/extension_devtools_manager.h" #include "chrome/browser/extensions/extension_message_service.h" -#include "content/browser/debugger/devtools_client_host.h" +#include "content/public/browser/devtools_client_host.h" class Profile; // This class is a DevToolsClientHost that fires extension events. -class ExtensionDevToolsBridge : public DevToolsClientHost { +class ExtensionDevToolsBridge : public content::DevToolsClientHost { public: ExtensionDevToolsBridge(int tab_id, Profile* profile); virtual ~ExtensionDevToolsBridge(); @@ -28,14 +28,12 @@ class ExtensionDevToolsBridge : public DevToolsClientHost { // closing. virtual void InspectedTabClosing() OVERRIDE; - // DevToolsClientHost, called to send a message to this host. - virtual void SendMessageToClient(const IPC::Message& msg) OVERRIDE; + // DevToolsClientHost, called to dispatch a message on this client. + virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; virtual void TabReplaced(TabContents* new_tab) OVERRIDE; private: - void OnDispatchOnInspectorFrontend(const std::string& data); - virtual void FrameNavigating(const std::string& url) OVERRIDE {} // ID of the tab we are monitoring. diff --git a/chrome/browser/extensions/extension_devtools_browsertests.cc b/chrome/browser/extensions/extension_devtools_browsertests.cc index 9f220b7..f41ebd3 100644 --- a/chrome/browser/extensions/extension_devtools_browsertests.cc +++ b/chrome/browser/extensions/extension_devtools_browsertests.cc @@ -16,14 +16,19 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/browser/debugger/devtools_client_host.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/site_instance.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_manager.h" #include "net/base/net_util.h" +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsClientHost; +using content::DevToolsManager; + // Looks for an ExtensionHost whose URL has the given path component (including // leading slash). Also verifies that the expected number of hosts are loaded. static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, @@ -73,18 +78,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, FLAKY_TimelineApi) { // Setting the events should have caused an ExtensionDevToolsBridge to be // registered for the tab's RenderViewHost. + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()); DevToolsClientHost* devtools_client_host = - devtools_manager->GetDevToolsClientHostFor( - tab_contents->render_view_host()); + devtools_manager->GetDevToolsClientHostFor(agent); ASSERT_TRUE(devtools_client_host); // Test onPageEvent event. result = false; - DevToolsClientMsg_DispatchOnInspectorFrontend pageEventMessage( - MSG_ROUTING_NONE, - ""); - devtools_client_host->SendMessageToClient(pageEventMessage); + devtools_client_host->DispatchOnInspectorFrontend(""); ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( host->render_view_host(), L"", L"testReceivePageEvent()", &result)); EXPECT_TRUE(result); @@ -92,7 +95,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, FLAKY_TimelineApi) { // Test onTabClose event. result = false; devtools_manager->UnregisterDevToolsClientHostFor( - tab_contents->render_view_host()); + DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host())); ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result)); EXPECT_TRUE(result); @@ -132,7 +136,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { // Setting the event listeners should have caused an ExtensionDevToolsBridge // to be registered for the tab's RenderViewHost. ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( - tab_contents->render_view_host())); + DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()))); // Register listeners from the second extension as well. std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)", @@ -148,7 +153,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { host_one->render_view_host(), L"", L"unregisterListeners()", &result)); EXPECT_TRUE(result); ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( - tab_contents->render_view_host())); + DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()))); // Removing the listeners from the second extension should tear the bridge // down. @@ -157,5 +163,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { host_two->render_view_host(), L"", L"unregisterListeners()", &result)); EXPECT_TRUE(result); ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( - tab_contents->render_view_host())); + DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()))); } diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 612ac2c..8fd7b59 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -86,11 +86,12 @@ #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/plugin_process_host.h" #include "content/browser/plugin_service.h" #include "content/browser/user_metrics.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" @@ -118,6 +119,8 @@ using base::Time; using content::BrowserThread; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; namespace errors = extension_manifest_errors; @@ -607,10 +610,14 @@ void ExtensionService::ReloadExtension(const std::string& extension_id) { // later. ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); - if (host) { + if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( + host->render_view_host())) { // Look for an open inspector for the background page. - int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost( - host->render_view_host()); + DevToolsAgentHost* agent = + DevToolsAgentHostRegistry::GetDevToolsAgentHost( + host->render_view_host()); + int devtools_cookie = + content::DevToolsManager::GetInstance()->DetachClientHost(agent); if (devtools_cookie >= 0) orphaned_dev_tools_[extension_id] = devtools_cookie; } @@ -2297,8 +2304,10 @@ void ExtensionService::DidCreateRenderViewForBackgroundPage( if (iter == orphaned_dev_tools_.end()) return; - DevToolsManager::GetInstance()->AttachClientHost( - iter->second, host->render_view_host()); + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + host->render_view_host()); + content::DevToolsManager::GetInstance()->AttachClientHost(iter->second, + agent); orphaned_dev_tools_.erase(iter); } diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc index 83043b5..035e84c 100644 --- a/chrome/browser/prerender/prerender_browsertest.cc +++ b/chrome/browser/prerender/prerender_browsertest.cc @@ -32,10 +32,11 @@ #include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/browser/debugger/devtools_client_host.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/common/url_constants.h" #include "grit/generated_resources.h" @@ -45,6 +46,10 @@ #include "ui/base/l10n/l10n_util.h" using content::BrowserThread; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsClientHost; +using content::DevToolsManager; // Prerender tests work as follows: // @@ -395,12 +400,10 @@ class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { class FakeDevToolsClientHost : public DevToolsClientHost { public: FakeDevToolsClientHost() {} - virtual ~FakeDevToolsClientHost() { - NotifyCloseListener(); - } + virtual ~FakeDevToolsClientHost() {} virtual void InspectedTabClosing() OVERRIDE {} virtual void FrameNavigating(const std::string& url) OVERRIDE {} - virtual void SendMessageToClient(const IPC::Message& msg) OVERRIDE {} + virtual void DispatchOnInspectorFrontend(const std::string& msg) OVERRIDE {} virtual void TabReplaced(TabContents* new_tab) OVERRIDE {} }; @@ -1836,13 +1839,15 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, NavigateToPrerenderedPageWhenDevToolsAttached) { DisableJavascriptCalls(); TabContents* tab_contents = browser()->GetSelectedTabContents(); - RenderViewHost* inspected_rvh = tab_contents->render_view_host(); + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()); DevToolsManager* manager = DevToolsManager::GetInstance(); FakeDevToolsClientHost client_host; - manager->RegisterDevToolsClientHostFor(inspected_rvh, &client_host); + manager->RegisterDevToolsClientHostFor(agent, &client_host); const char* url = "files/prerender/prerender_page.html"; PrerenderTestURL(url, FINAL_STATUS_DEVTOOLS_ATTACHED, 1); NavigateToURL(url); + manager->ClientHostClosing(&client_host); } // Validate that the sessionStorage namespace remains the same when swapping diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 8306bfb..323d202 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -35,7 +35,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" #include "content/browser/cancelable_request.h" -#include "content/browser/debugger/render_view_devtools_agent_host.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" @@ -43,6 +42,7 @@ #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_delegate.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" @@ -595,7 +595,7 @@ bool PrerenderManager::MaybeUsePrerenderedPage(TabContents* tab_contents, // Don't use prerendered pages if debugger is attached to the tab. // See http://crbug.com/98541 - if (RenderViewDevToolsAgentHost::IsDebuggerAttached(tab_contents)) { + if (content::DevToolsAgentHostRegistry::IsDebuggerAttached(tab_contents)) { prerender_contents.release()->Destroy(FINAL_STATUS_DEVTOOLS_ATTACHED); return false; } diff --git a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc index 4380ed8..734da89 100644 --- a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc +++ b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc @@ -12,11 +12,11 @@ #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/profiles/profile_manager.h" #include "content/browser/browser_child_process_host.h" -#include "content/browser/debugger/worker_devtools_manager.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/browser/worker_host/worker_service.h" #include "content/browser/worker_host/worker_service_observer.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/common/process_type.h" @@ -26,6 +26,8 @@ #include "ui/base/resource/resource_bundle.h" using content::BrowserThread; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; // Objects of this class are created on the IO thread and then passed to the UI // thread where they are passed to the task manager. All methods must be called @@ -127,7 +129,7 @@ void TaskManagerSharedWorkerResource::Inspect() const { if (!profile) return; DevToolsAgentHost* agent_host = - WorkerDevToolsManager::GetDevToolsAgentHostForWorker( + DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( process_info_.id(), routing_id_); DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index acffbcc..eb9a8dd 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -137,7 +137,6 @@ #include "chrome/common/web_apps.h" #include "content/browser/browser_url_handler.h" #include "content/browser/child_process_security_policy.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/download/download_item.h" #include "content/browser/download/download_manager.h" #include "content/browser/download/save_package.h" @@ -150,6 +149,7 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents_view.h" #include "content/browser/user_metrics.h" +#include "content/public/browser/devtools_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_details.h" #include "content/public/common/content_restriction.h" @@ -3342,10 +3342,8 @@ void Browser::TabReplacedAt(TabStripModel* tab_strip_model, new_contents, tab_handler_->GetTabStripModel()->IsTabPinned(index)); } - DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - if (devtools_manager) // NULL in unit tests. - devtools_manager->TabReplaced(old_contents->tab_contents(), - new_contents->tab_contents()); + content::DevToolsManager::GetInstance()->TabReplaced( + old_contents->tab_contents(), new_contents->tab_contents()); } void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { @@ -4160,7 +4158,7 @@ void Browser::Observe(int type, } else if (pref_name == prefs::kDevToolsDisabled) { UpdateCommandsForDevTools(); if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) - DevToolsManager::GetInstance()->CloseAllClientHosts(); + content::DevToolsManager::GetInstance()->CloseAllClientHosts(); } else if (pref_name == prefs::kEditBookmarksEnabled) { UpdateCommandsForBookmarkEditing(); } else if (pref_name == prefs::kShowBookmarkBar) { diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc index 5ea6be7..0d1ae7f 100644 --- a/chrome/browser/ui/webui/devtools_ui.cc +++ b/chrome/browser/ui/webui/devtools_ui.cc @@ -14,8 +14,8 @@ #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_client_host.h" #include "grit/devtools_resources_map.h" #include "ui/base/resource/resource_bundle.h" @@ -106,8 +106,6 @@ DevToolsUI::DevToolsUI(TabContents* contents) : ChromeWebUI(contents) { } void DevToolsUI::RenderViewCreated(RenderViewHost* render_view_host) { - render_view_host->Send(new DevToolsMsg_SetupDevToolsClient( - render_view_host->routing_id())); - + content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); ChromeWebUI::RenderViewCreated(render_view_host); } diff --git a/chrome/browser/ui/webui/workers_ui.cc b/chrome/browser/ui/webui/workers_ui.cc index d8ad254..521740f 100644 --- a/chrome/browser/ui/webui/workers_ui.cc +++ b/chrome/browser/ui/webui/workers_ui.cc @@ -16,7 +16,7 @@ #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" #include "chrome/common/url_constants.h" -#include "content/browser/debugger/worker_devtools_manager.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/browser/worker_host/worker_service.h" @@ -27,6 +27,8 @@ #include "ui/base/resource/resource_bundle.h" using content::BrowserThread; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; static const char kWorkersDataFile[] = "workers_data.json"; @@ -142,7 +144,7 @@ void WorkersDOMHandler::HandleOpenDevTools(const ListValue* args) { if (!profile) return; DevToolsAgentHost* agent_host = - WorkerDevToolsManager::GetDevToolsAgentHostForWorker( + DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( worker_process_host_id, worker_route_id); DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); diff --git a/content/browser/debugger/devtools_agent_host.cc b/content/browser/debugger/devtools_agent_host.cc index 0d206c9..ea9d37a 100644 --- a/content/browser/debugger/devtools_agent_host.cc +++ b/content/browser/debugger/devtools_agent_host.cc @@ -7,6 +7,8 @@ #include "base/basictypes.h" #include "content/common/devtools_messages.h" +namespace content { + DevToolsAgentHost::DevToolsAgentHost() : close_listener_(NULL) { } @@ -24,6 +26,16 @@ void DevToolsAgentHost::Detach() { SendMessageToAgent(new DevToolsAgentMsg_Detach(MSG_ROUTING_NONE)); } +void DevToolsAgentHost::DipatchOnInspectorBackend(const std::string& message) { + SendMessageToAgent(new DevToolsAgentMsg_DispatchOnInspectorBackend( + MSG_ROUTING_NONE, message)); +} + +void DevToolsAgentHost::InspectElement(int x, int y) { + SendMessageToAgent(new DevToolsAgentMsg_InspectElement(MSG_ROUTING_NONE, + x, y)); +} + void DevToolsAgentHost::NotifyCloseListener() { if (close_listener_) { close_listener_->AgentHostClosing(this); @@ -31,3 +43,4 @@ void DevToolsAgentHost::NotifyCloseListener() { } } +} // namespace content diff --git a/content/browser/debugger/devtools_agent_host.h b/content/browser/debugger/devtools_agent_host.h index fe430dd..b0621d4 100644 --- a/content/browser/debugger/devtools_agent_host.h +++ b/content/browser/debugger/devtools_agent_host.h @@ -14,6 +14,8 @@ namespace IPC { class Message; } +namespace content { + // Describes interface for managing devtools agents from the browser process. class CONTENT_EXPORT DevToolsAgentHost { public: @@ -25,10 +27,11 @@ class CONTENT_EXPORT DevToolsAgentHost { }; // Sends the message to the devtools agent hosted by this object. - virtual void SendMessageToAgent(IPC::Message* msg) = 0; - virtual void Attach(); - virtual void Reattach(const std::string& saved_agent_state); - virtual void Detach(); + void Attach(); + void Reattach(const std::string& saved_agent_state); + void Detach(); + void DipatchOnInspectorBackend(const std::string& message); + void InspectElement(int x, int y); // TODO(yurys): get rid of this method virtual void NotifyClientClosing() = 0; @@ -43,9 +46,12 @@ class CONTENT_EXPORT DevToolsAgentHost { DevToolsAgentHost(); virtual ~DevToolsAgentHost() {} + virtual void SendMessageToAgent(IPC::Message* msg) = 0; void NotifyCloseListener(); CloseListener* close_listener_; }; +} // namespace content + #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_AGENT_HOST_H_ diff --git a/content/browser/debugger/devtools_client_host.cc b/content/browser/debugger/devtools_client_host.cc deleted file mode 100644 index 68fa25f..0000000 --- a/content/browser/debugger/devtools_client_host.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2011 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/debugger/devtools_client_host.h" - -#include "content/browser/debugger/devtools_manager.h" - -DevToolsClientHost::~DevToolsClientHost() { -} - -DevToolsClientHost::DevToolsClientHost() : close_listener_(NULL) { -} - -void DevToolsClientHost::ForwardToDevToolsAgent(const IPC::Message& message) { - DevToolsManager::GetInstance()->ForwardToDevToolsAgent(this, message); -} - -void DevToolsClientHost::NotifyCloseListener() { - if (close_listener_) { - close_listener_->ClientHostClosing(this); - close_listener_ = NULL; - } -} diff --git a/content/browser/debugger/devtools_frontend_host.cc b/content/browser/debugger/devtools_frontend_host.cc new file mode 100644 index 0000000..724bd30 --- /dev/null +++ b/content/browser/debugger/devtools_frontend_host.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2011 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/debugger/devtools_frontend_host.h" + +#include "content/browser/debugger/devtools_manager_impl.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/tab_contents/tab_contents.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( + TabContents* client_tab_contents, + DevToolsFrontendHostDelegate* delegate) { + return new DevToolsFrontendHost(client_tab_contents, delegate); +} + +// static +void DevToolsClientHost::SetupDevToolsFrontendClient( + RenderViewHost* frontend_rvh) { + frontend_rvh->Send(new DevToolsMsg_SetupDevToolsClient( + frontend_rvh->routing_id())); +} + +DevToolsFrontendHost::DevToolsFrontendHost( + TabContents* tab_contents, + DevToolsFrontendHostDelegate* delegate) + : RenderViewHostObserver(tab_contents->render_view_host()), + tab_contents_(tab_contents), + delegate_(delegate) { +} + +DevToolsFrontendHost::~DevToolsFrontendHost() { +} + +void DevToolsFrontendHost::DispatchOnInspectorFrontend( + const std::string& message) { + RenderViewHost* target_host = tab_contents_->render_view_host(); + target_host->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( + target_host->routing_id(), + message)); +} + +void DevToolsFrontendHost::InspectedTabClosing() { + delegate_->InspectedTabClosing(); +} + +void DevToolsFrontendHost::FrameNavigating(const std::string& url) { + delegate_->FrameNavigating(url); +} + +void DevToolsFrontendHost::TabReplaced(TabContents* new_tab) { + delegate_->TabReplaced(new_tab); +} + +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_ActivateWindow, OnActivateWindow) + IPC_MESSAGE_HANDLER(DevToolsHostMsg_CloseWindow, OnCloseWindow) + IPC_MESSAGE_HANDLER(DevToolsHostMsg_MoveWindow, OnMoveWindow) + IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestDockWindow, OnRequestDockWindow) + IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestUndockWindow, + OnRequestUndockWindow) + IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAs, + OnSaveAs) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void DevToolsFrontendHost::OnDispatchOnInspectorBackend( + const std::string& message) { + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorBackend(this, message); +// delegate_->DispatchOnInspectorBackend(message); +} + +void DevToolsFrontendHost::OnActivateWindow() { + delegate_->ActivateWindow(); +} + +void DevToolsFrontendHost::OnCloseWindow() { + delegate_->CloseWindow(); +} + +void DevToolsFrontendHost::OnMoveWindow(int x, int y) { + delegate_->MoveWindow(x, y); +} + +void DevToolsFrontendHost::OnSaveAs( + const std::string& suggested_file_name, + const std::string& content) { + delegate_->SaveToFile(suggested_file_name, content); +} + +void DevToolsFrontendHost::OnRequestDockWindow() { + delegate_->DockWindow(); +} + +void DevToolsFrontendHost::OnRequestUndockWindow() { + delegate_->UndockWindow(); +} + +} // namespace content diff --git a/content/browser/debugger/devtools_frontend_host.h b/content/browser/debugger/devtools_frontend_host.h new file mode 100644 index 0000000..7dd3a91 --- /dev/null +++ b/content/browser/debugger/devtools_frontend_host.h @@ -0,0 +1,59 @@ +// Copyright (c) 2011 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_DEBUGGER_DEVTOOLS_FRONTEND_HOST_H_ +#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_FRONTEND_HOST_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/render_view_host_observer.h" + +class TabContents; + +namespace content { + +class DevToolsFrontendHostDelegate; + +// 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 RenderViewHostObserver { + public: + DevToolsFrontendHost(TabContents* tab_contents, + DevToolsFrontendHostDelegate* delegate); + + private: + virtual ~DevToolsFrontendHost(); + + // DevToolsFrontendHost implementation. + virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; + virtual void InspectedTabClosing() OVERRIDE; + virtual void FrameNavigating(const std::string& url) OVERRIDE; + virtual void TabReplaced(TabContents* new_tab) OVERRIDE; + + // content::RenderViewHostObserver overrides. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + void OnDispatchOnInspectorBackend(const std::string& message); + void OnActivateWindow(); + void OnCloseWindow(); + void OnMoveWindow(int x, int y); + void OnRequestDockWindow(); + void OnRequestUndockWindow(); + void OnSaveAs(const std::string& file_name, + const std::string& content); + + TabContents* tab_contents_; + DevToolsFrontendHostDelegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(DevToolsFrontendHost); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_FRONTEND_HOST_H_ diff --git a/content/browser/debugger/devtools_frontend_message_handler.cc b/content/browser/debugger/devtools_frontend_message_handler.cc deleted file mode 100644 index 13b0238..0000000 --- a/content/browser/debugger/devtools_frontend_message_handler.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2011 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/debugger/devtools_frontend_message_handler.h" - -#include "content/browser/tab_contents/tab_contents.h" -#include "content/common/devtools_messages.h" -#include "content/public/browser/devtools_frontend_window.h" -#include "content/public/browser/devtools_frontend_window_delegate.h" - -namespace content { - -void SetupDevToolsFrontendDelegate( - TabContents* client_tab_contents, - DevToolsFrontendWindowDelegate* delegate) { - new DevToolsFrontendMessageHandler(client_tab_contents, delegate); -} - -DevToolsFrontendMessageHandler::DevToolsFrontendMessageHandler( - TabContents* tab_contents, - DevToolsFrontendWindowDelegate* delegate) - : RenderViewHostObserver(tab_contents->render_view_host()), - tab_contents_(tab_contents), - delegate_(delegate) { -} - -DevToolsFrontendMessageHandler::~DevToolsFrontendMessageHandler() { -} - -bool DevToolsFrontendMessageHandler::OnMessageReceived( - const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendMessageHandler, message) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToAgent, ForwardToDevToolsAgent) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ActivateWindow, OnActivateWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_CloseWindow, OnCloseWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_MoveWindow, OnMoveWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestDockWindow, OnRequestDockWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestUndockWindow, - OnRequestUndockWindow) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAs, - OnSaveAs) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void DevToolsFrontendMessageHandler::ForwardToDevToolsAgent( - const IPC::Message& message) { - delegate_->ForwardToDevToolsAgent(message); -} - -void DevToolsFrontendMessageHandler::OnActivateWindow() { - delegate_->ActivateWindow(); -} - -void DevToolsFrontendMessageHandler::OnCloseWindow() { - delegate_->CloseWindow(); -} - -void DevToolsFrontendMessageHandler::OnMoveWindow(int x, int y) { - delegate_->MoveWindow(x, y); -} - -void DevToolsFrontendMessageHandler::OnSaveAs( - const std::string& suggested_file_name, - const std::string& content) { - delegate_->SaveToFile(suggested_file_name, content); -} - -void DevToolsFrontendMessageHandler::OnRequestDockWindow() { - delegate_->DockWindow(); -} - -void DevToolsFrontendMessageHandler::OnRequestUndockWindow() { - delegate_->UndockWindow(); -} - -} // namespace content diff --git a/content/browser/debugger/devtools_frontend_message_handler.h b/content/browser/debugger/devtools_frontend_message_handler.h deleted file mode 100644 index 603ee10..0000000 --- a/content/browser/debugger/devtools_frontend_message_handler.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 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_DEBUGGER_DEVTOOLS_FRONTEND_MESSAGE_HANDLER_H_ -#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_FRONTEND_MESSAGE_HANDLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "content/public/browser/render_view_host_observer.h" - -class TabContents; - -namespace content { - -class DevToolsFrontendWindowDelegate; - -// This class handles messages from DevToolsClient and calls corresponding -// methods on DevToolsFrontendWindowDelegate which is implemented by the -// embedder. This allows us to avoid exposing DevTools client messages through -// the content public API. -class DevToolsFrontendMessageHandler : public RenderViewHostObserver { - public: - DevToolsFrontendMessageHandler(TabContents* tab_contents, - DevToolsFrontendWindowDelegate* delegate); - - private: - virtual ~DevToolsFrontendMessageHandler(); - - // content::RenderViewHostObserver overrides. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - - void ForwardToDevToolsAgent(const IPC::Message& message); - void OnActivateWindow(); - void OnCloseWindow(); - void OnMoveWindow(int x, int y); - void OnRequestDockWindow(); - void OnRequestUndockWindow(); - void OnSaveAs(const std::string& file_name, - const std::string& content); - - TabContents* tab_contents_; - DevToolsFrontendWindowDelegate* delegate_; - DISALLOW_COPY_AND_ASSIGN(DevToolsFrontendMessageHandler); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_FRONTEND_MESSAGE_HANDLER_H_ diff --git a/content/browser/debugger/devtools_http_protocol_handler.cc b/content/browser/debugger/devtools_http_protocol_handler.cc index 8771675..df85974 100644 --- a/content/browser/debugger/devtools_http_protocol_handler.cc +++ b/content/browser/debugger/devtools_http_protocol_handler.cc @@ -17,12 +17,13 @@ #include "base/threading/thread.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "content/browser/debugger/devtools_client_host.h" -#include "content/browser/debugger/devtools_manager.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_observer.h" #include "content/common/devtools_messages.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_manager.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" #include "net/base/io_buffer.h" @@ -30,6 +31,10 @@ #include "net/url_request/url_request_context.h" using content::BrowserThread; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsClientHost; +using content::DevToolsManager; const int kBufferSize = 16 * 1024; @@ -55,23 +60,7 @@ class DevToolsClientHostImpl : public DevToolsClientHost { base::Bind(&net::HttpServer::Close, server_, connection_id_)); } - virtual void SendMessageToClient(const IPC::Message& msg) { - IPC_BEGIN_MESSAGE_MAP(DevToolsClientHostImpl, msg) - IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, - OnDispatchOnInspectorFrontend); - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() - } - - virtual void TabReplaced(TabContents* new_tab) { - } - - void NotifyCloseListener() { - DevToolsClientHost::NotifyCloseListener(); - } - private: - // Message handling routines - void OnDispatchOnInspectorFrontend(const std::string& data) { + virtual void DispatchOnInspectorFrontend(const std::string& data) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, @@ -81,6 +70,10 @@ class DevToolsClientHostImpl : public DevToolsClientHost { data)); } + virtual void TabReplaced(TabContents* new_tab) { + } + + private: virtual void FrameNavigating(const std::string& url) {} net::HttpServer* server_; int connection_id_; @@ -297,8 +290,10 @@ static PageList GeneratePageList( if (entry == NULL || !entry->url().is_valid()) continue; + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()); DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> - GetDevToolsClientHostFor(tab_contents->render_view_host()); + GetDevToolsClientHostFor(agent); PageInfo page_info; page_info.id = TabContentsIDHelper::GetID(tab_contents); page_info.attached = client_host != NULL; @@ -368,7 +363,9 @@ void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( } DevToolsManager* manager = DevToolsManager::GetInstance(); - if (manager->GetDevToolsClientHostFor(tab_contents->render_view_host())) { + DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( + tab_contents->render_view_host()); + if (manager->GetDevToolsClientHostFor(agent)) { Send500(connection_id, "Page with given id is being inspected: " + page_id); return; } @@ -377,9 +374,7 @@ void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( new DevToolsClientHostImpl(server_, connection_id); connection_to_client_host_ui_[connection_id] = client_host; - manager->RegisterDevToolsClientHostFor( - tab_contents->render_view_host(), - client_host); + manager->RegisterDevToolsClientHostFor(agent, client_host); AcceptWebSocket(connection_id, request); } @@ -393,9 +388,7 @@ void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( return; DevToolsManager* manager = DevToolsManager::GetInstance(); - manager->ForwardToDevToolsAgent( - it->second, - DevToolsAgentMsg_DispatchOnInspectorBackend(MSG_ROUTING_NONE, data)); + manager->DispatchOnInspectorBackend(it->second, data); } void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { @@ -404,7 +397,7 @@ void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { if (it != connection_to_client_host_ui_.end()) { DevToolsClientHostImpl* client_host = static_cast<DevToolsClientHostImpl*>(it->second); - client_host->NotifyCloseListener(); + DevToolsManager::GetInstance()->ClientHostClosing(client_host); delete client_host; connection_to_client_host_ui_.erase(connection_id); } diff --git a/content/browser/debugger/devtools_http_protocol_handler.h b/content/browser/debugger/devtools_http_protocol_handler.h index 866f925..c25b5cd 100644 --- a/content/browser/debugger/devtools_http_protocol_handler.h +++ b/content/browser/debugger/devtools_http_protocol_handler.h @@ -17,9 +17,12 @@ #include "net/server/http_server.h" #include "net/url_request/url_request.h" -class DevToolsClientHost; class TabContents; +namespace content { +class DevToolsClientHost; +} + namespace net { class URLRequestContext; } @@ -120,7 +123,7 @@ class DevToolsHttpProtocolHandler typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > BuffersMap; BuffersMap request_to_buffer_io_; - typedef std::map<int, DevToolsClientHost*> + typedef std::map<int, content::DevToolsClientHost*> ConnectionToClientHostMap; ConnectionToClientHostMap connection_to_client_host_ui_; scoped_ptr<Delegate> delegate_; diff --git a/content/browser/debugger/devtools_manager.cc b/content/browser/debugger/devtools_manager_impl.cc index 3929ce8..554f287 100644 --- a/content/browser/debugger/devtools_manager.cc +++ b/content/browser/debugger/devtools_manager_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/debugger/devtools_manager.h" +#include "content/browser/debugger/devtools_manager_impl.h" #include <vector> @@ -10,26 +10,32 @@ #include "base/message_loop.h" #include "content/browser/browsing_instance.h" #include "content/browser/child_process_security_policy.h" -#include "content/browser/debugger/devtools_client_host.h" #include "content/browser/debugger/devtools_netlog_observer.h" #include "content/browser/debugger/render_view_devtools_agent_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "googleurl/src/gurl.h" -using content::BrowserThread; +namespace content { // static DevToolsManager* DevToolsManager::GetInstance() { - return Singleton<DevToolsManager>::get(); + return DevToolsManagerImpl::GetInstance(); } -DevToolsManager::DevToolsManager() +// static +DevToolsManagerImpl* DevToolsManagerImpl::GetInstance() { + return Singleton<DevToolsManagerImpl>::get(); +} + +DevToolsManagerImpl::DevToolsManagerImpl() : last_orphan_cookie_(0) { } -DevToolsManager::~DevToolsManager() { +DevToolsManagerImpl::~DevToolsManagerImpl() { DCHECK(agent_to_client_host_.empty()); DCHECK(client_to_agent_host_.empty()); // By the time we destroy devtools manager, all orphan client hosts should @@ -37,14 +43,7 @@ DevToolsManager::~DevToolsManager() { DCHECK(orphan_client_hosts_.empty()); } -DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( - RenderViewHost* inspected_rvh) { - DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor( - inspected_rvh); - return GetDevToolsClientHostFor(agent_host); -} - -DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( +DevToolsClientHost* DevToolsManagerImpl::GetDevToolsClientHostFor( DevToolsAgentHost* agent_host) { AgentToClientHostMap::iterator it = agent_to_client_host_.find(agent_host); if (it != agent_to_client_host_.end()) @@ -52,50 +51,47 @@ DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( return NULL; } -void DevToolsManager::RegisterDevToolsClientHostFor( - RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host) { - DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); - DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor( - inspected_rvh); - RegisterDevToolsClientHostFor(agent_host, client_host); -} - -void DevToolsManager::RegisterDevToolsClientHostFor( +void DevToolsManagerImpl::RegisterDevToolsClientHostFor( DevToolsAgentHost* agent_host, DevToolsClientHost* client_host) { BindClientHost(agent_host, client_host); agent_host->Attach(); - client_host->set_close_listener(this); } -bool DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, - const IPC::Message& message) { +bool DevToolsManagerImpl::DispatchOnInspectorBackend( + DevToolsClientHost* from, + const std::string& message) { DevToolsAgentHost* agent_host = GetAgentHost(from); if (!agent_host) return false; - agent_host->SendMessageToAgent(new IPC::Message(message)); + agent_host->DipatchOnInspectorBackend(message); return true; } -void DevToolsManager::ForwardToDevToolsClient(DevToolsAgentHost* agent_host, - const IPC::Message& message) { +void DevToolsManagerImpl::DispatchOnInspectorFrontend( + DevToolsAgentHost* agent_host, + const std::string& message) { DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); if (!client_host) { // Client window was closed while there were messages // being sent to it. return; } - client_host->SendMessageToClient(message); + client_host->DispatchOnInspectorFrontend(message); } -void DevToolsManager::SaveAgentRuntimeState(DevToolsAgentHost* agent_host, - const std::string& state) { +void DevToolsManagerImpl::SaveAgentRuntimeState(DevToolsAgentHost* agent_host, + const std::string& state) { agent_runtime_states_[agent_host] = state; } -void DevToolsManager::ClientHostClosing(DevToolsClientHost* client_host) { +void DevToolsManagerImpl::InspectElement(DevToolsAgentHost* agent_host, + int x, int y) { + agent_host->InspectElement(x, y); +} + +void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) { DevToolsAgentHost* agent_host = GetAgentHost(client_host); if (!agent_host) { // It might be in the list of orphan client hosts, remove it from there. @@ -114,11 +110,11 @@ void DevToolsManager::ClientHostClosing(DevToolsClientHost* client_host) { UnbindClientHost(agent_host, client_host); } -void DevToolsManager::AgentHostClosing(DevToolsAgentHost* agent_host) { +void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHost* agent_host) { UnregisterDevToolsClientHostFor(agent_host); } -DevToolsAgentHost* DevToolsManager::GetAgentHost( +DevToolsAgentHost* DevToolsManagerImpl::GetAgentHost( DevToolsClientHost* client_host) { ClientHostToInspectedRvhMap::iterator it = client_to_agent_host_.find(client_host); @@ -127,14 +123,7 @@ DevToolsAgentHost* DevToolsManager::GetAgentHost( return NULL; } -void DevToolsManager::UnregisterDevToolsClientHostFor( - RenderViewHost* inspected_rvh) { - DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor( - inspected_rvh); - UnregisterDevToolsClientHostFor(agent_host); -} - -void DevToolsManager::UnregisterDevToolsClientHostFor( +void DevToolsManagerImpl::UnregisterDevToolsClientHostFor( DevToolsAgentHost* agent_host) { DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); if (!client_host) @@ -143,9 +132,9 @@ void DevToolsManager::UnregisterDevToolsClientHostFor( client_host->InspectedTabClosing(); } -void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, - RenderViewHost* dest_rvh, - const GURL& gurl) { +void DevToolsManagerImpl::OnNavigatingToPendingEntry(RenderViewHost* rvh, + RenderViewHost* dest_rvh, + const GURL& gurl) { if (rvh == dest_rvh && rvh->render_view_termination_status() == base::TERMINATION_STATUS_STILL_RUNNING) return; @@ -154,13 +143,16 @@ void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, // Navigating to URL in the inspected window. AttachClientHost(cookie, dest_rvh); - DevToolsClientHost* client_host = GetDevToolsClientHostFor(dest_rvh); + DevToolsAgentHost* dest_agent_host = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(dest_rvh); + DevToolsClientHost* client_host = GetDevToolsClientHostFor( + dest_agent_host); client_host->FrameNavigating(gurl.spec()); } } -void DevToolsManager::OnCancelPendingNavigation(RenderViewHost* pending, - RenderViewHost* current) { +void DevToolsManagerImpl::OnCancelPendingNavigation(RenderViewHost* pending, + RenderViewHost* current) { int cookie = DetachClientHost(pending); if (cookie != -1) { // Navigating to URL in the inspected window. @@ -168,10 +160,15 @@ void DevToolsManager::OnCancelPendingNavigation(RenderViewHost* pending, } } -void DevToolsManager::TabReplaced(TabContents* old_tab, - TabContents* new_tab) { +void DevToolsManagerImpl::TabReplaced(TabContents* old_tab, + TabContents* new_tab) { RenderViewHost* old_rvh = old_tab->render_view_host(); - DevToolsClientHost* client_host = GetDevToolsClientHostFor(old_rvh); + if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost(old_rvh)) + return; + + DevToolsAgentHost* old_agent_host = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(old_rvh); + DevToolsClientHost* client_host = GetDevToolsClientHostFor(old_agent_host); if (!client_host) return; // Didn't know about old_tab. int cookie = DetachClientHost(old_rvh); @@ -182,13 +179,13 @@ void DevToolsManager::TabReplaced(TabContents* old_tab, AttachClientHost(cookie, new_tab->render_view_host()); } -int DevToolsManager::DetachClientHost(RenderViewHost* from_rvh) { - DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor( - from_rvh); +int DevToolsManagerImpl::DetachClientHost(RenderViewHost* from_rvh) { + DevToolsAgentHost* agent_host = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(from_rvh); return DetachClientHost(agent_host); } -int DevToolsManager::DetachClientHost(DevToolsAgentHost* agent_host) { +int DevToolsManagerImpl::DetachClientHost(DevToolsAgentHost* agent_host) { DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); if (!client_host) return -1; @@ -202,15 +199,15 @@ int DevToolsManager::DetachClientHost(DevToolsAgentHost* agent_host) { return cookie; } -void DevToolsManager::AttachClientHost(int client_host_cookie, - RenderViewHost* to_rvh) { - DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor( - to_rvh); +void DevToolsManagerImpl::AttachClientHost(int client_host_cookie, + RenderViewHost* to_rvh) { + DevToolsAgentHost* agent_host = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(to_rvh); AttachClientHost(client_host_cookie, agent_host); } -void DevToolsManager::AttachClientHost(int client_host_cookie, - DevToolsAgentHost* agent_host) { +void DevToolsManagerImpl::AttachClientHost(int client_host_cookie, + DevToolsAgentHost* agent_host) { OrphanClientHosts::iterator it = orphan_client_hosts_.find( client_host_cookie); if (it == orphan_client_hosts_.end()) @@ -225,7 +222,7 @@ void DevToolsManager::AttachClientHost(int client_host_cookie, orphan_client_hosts_.erase(it); } -void DevToolsManager::BindClientHost( +void DevToolsManagerImpl::BindClientHost( DevToolsAgentHost* agent_host, DevToolsClientHost* client_host) { DCHECK(agent_to_client_host_.find(agent_host) == @@ -248,8 +245,8 @@ void DevToolsManager::BindClientHost( ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies(process_id); } -void DevToolsManager::UnbindClientHost(DevToolsAgentHost* agent_host, - DevToolsClientHost* client_host) { +void DevToolsManagerImpl::UnbindClientHost(DevToolsAgentHost* agent_host, + DevToolsClientHost* client_host) { DCHECK(agent_host); DCHECK(agent_to_client_host_.find(agent_host)->second == client_host); @@ -282,7 +279,7 @@ void DevToolsManager::UnbindClientHost(DevToolsAgentHost* agent_host, ChildProcessSecurityPolicy::GetInstance()->RevokeReadRawCookies(process_id); } -void DevToolsManager::CloseAllClientHosts() { +void DevToolsManagerImpl::CloseAllClientHosts() { std::vector<DevToolsAgentHost*> agents; for (AgentToClientHostMap::iterator it = agent_to_client_host_.begin(); @@ -294,3 +291,5 @@ void DevToolsManager::CloseAllClientHosts() { UnregisterDevToolsClientHostFor(*it); } } + +} // namespace content diff --git a/content/browser/debugger/devtools_manager.h b/content/browser/debugger/devtools_manager_impl.h index f589c85..62a5a9e 100644 --- a/content/browser/debugger/devtools_manager.h +++ b/content/browser/debugger/devtools_manager_impl.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ -#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ +#ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ +#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ #pragma once #include <map> @@ -12,10 +12,10 @@ #include "base/compiler_specific.h" #include "base/memory/singleton.h" #include "content/browser/debugger/devtools_agent_host.h" -#include "content/browser/debugger/devtools_client_host.h" #include "content/common/content_export.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_manager.h" -class DevToolsAgentHost; class GURL; class RenderViewHost; class TabContents; @@ -24,35 +24,31 @@ namespace IPC { class Message; } +namespace content { + +class DevToolsAgentHost; + // This class is a singleton that manages DevToolsClientHost instances and // routes messages between developer tools clients and agents. // // Methods below that accept inspected RenderViewHost as a parameter are // just convenience methods that call corresponding methods accepting // DevToolAgentHost. -class CONTENT_EXPORT DevToolsManager - : public DevToolsClientHost::CloseListener, - public DevToolsAgentHost::CloseListener { +class CONTENT_EXPORT DevToolsManagerImpl + : public DevToolsAgentHost::CloseListener, + public DevToolsManager { public: - static DevToolsManager* GetInstance(); + // Returns single instance of this class. The instance is destroyed on the + // browser main loop exit so this method MUST NOT be called after that point. + static DevToolsManagerImpl* GetInstance(); - DevToolsManager(); - virtual ~DevToolsManager(); + DevToolsManagerImpl(); + virtual ~DevToolsManagerImpl(); - // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if - // there is no alive DevToolsClientHost registered for |inspected_rvh|. - DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); - - // Registers new DevToolsClientHost for |inspected_rvh|. There must be no - // other DevToolsClientHosts registered for the RenderViewHost at the moment. - void RegisterDevToolsClientHostFor(RenderViewHost* inspected_rvh, - DevToolsClientHost* client_host); - void UnregisterDevToolsClientHostFor(RenderViewHost* inspected_rvh); - - bool ForwardToDevToolsAgent(DevToolsClientHost* from, - const IPC::Message& message); - void ForwardToDevToolsClient(DevToolsAgentHost* agent_host, - const IPC::Message& message); + virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from, + const std::string& message) OVERRIDE; + void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host, + const std::string& message); void SaveAgentRuntimeState(DevToolsAgentHost* agent_host, const std::string& state); @@ -67,36 +63,34 @@ class CONTENT_EXPORT DevToolsManager // Invoked when a tab is replaced by another tab. This is triggered by // TabStripModel::ReplaceTabContentsAt. - void TabReplaced(TabContents* old_tab, TabContents* new_tab); - - // Detaches client host and returns cookie that can be used in - // AttachClientHost. - int DetachClientHost(RenderViewHost* from_rvh); - - // Attaches orphan client host to new render view host. - void AttachClientHost(int client_host_cookie, - RenderViewHost* to_rvh); + virtual void TabReplaced(TabContents* old_tab, TabContents* new_tab) OVERRIDE; // Closes all open developer tools windows. - void CloseAllClientHosts(); - - void AttachClientHost(int client_host_cookie, - DevToolsAgentHost* to_agent); - DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host); - void RegisterDevToolsClientHostFor(DevToolsAgentHost* agent_host, - DevToolsClientHost* client_host); - void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host); - int DetachClientHost(DevToolsAgentHost* from_agent); - - private: - friend struct DefaultSingletonTraits<DevToolsManager>; + virtual void CloseAllClientHosts() OVERRIDE; + + virtual void AttachClientHost(int client_host_cookie, + DevToolsAgentHost* to_agent) OVERRIDE; + virtual DevToolsClientHost* GetDevToolsClientHostFor( + DevToolsAgentHost* agent_host) OVERRIDE; + virtual void RegisterDevToolsClientHostFor( + DevToolsAgentHost* agent_host, + DevToolsClientHost* client_host) OVERRIDE; + virtual void UnregisterDevToolsClientHostFor( + DevToolsAgentHost* agent_host) OVERRIDE; + virtual int DetachClientHost(DevToolsAgentHost* from_agent) OVERRIDE; - // DevToolsClientHost::CloseListener override. // This method will remove all references from the manager to the // DevToolsClientHost and unregister all listeners related to the // DevToolsClientHost. virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; + // Starts inspecting element at position (x, y) in the specified page. + virtual void InspectElement(DevToolsAgentHost* agent_host, + int x, int y) OVERRIDE; + + private: + friend struct DefaultSingletonTraits<DevToolsManagerImpl>; + // DevToolsAgentHost::CloseListener implementation. virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE; @@ -108,12 +102,20 @@ class CONTENT_EXPORT DevToolsManager void UnbindClientHost(DevToolsAgentHost* agent_host, DevToolsClientHost* client_host); + // Detaches client host and returns cookie that can be used in + // AttachClientHost. + int DetachClientHost(RenderViewHost* from_rvh); + + // Attaches orphan client host to new render view host. + void AttachClientHost(int client_host_cookie, + RenderViewHost* to_rvh); + // These two maps are for tracking dependencies between inspected tabs and // their DevToolsClientHosts. They are useful for routing devtools messages // and allow us to have at most one devtools client host per tab. // - // DevToolsManager start listening to DevToolsClientHosts when they are put - // into these maps and removes them when they are closing. + // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are + // put into these maps and removes them when they are closing. typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> AgentToClientHostMap; AgentToClientHostMap agent_to_client_host_; @@ -130,7 +132,9 @@ class CONTENT_EXPORT DevToolsManager OrphanClientHosts orphan_client_hosts_; int last_orphan_cookie_; - DISALLOW_COPY_AND_ASSIGN(DevToolsManager); + DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl); }; -#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ +} // namespace content + +#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ diff --git a/content/browser/debugger/devtools_manager_unittest.cc b/content/browser/debugger/devtools_manager_unittest.cc index f7daf85..ead247c 100644 --- a/content/browser/debugger/devtools_manager_unittest.cc +++ b/content/browser/debugger/devtools_manager_unittest.cc @@ -4,8 +4,7 @@ #include "base/basictypes.h" #include "base/time.h" -#include "content/browser/debugger/devtools_client_host.h" -#include "content/browser/debugger/devtools_manager.h" +#include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/debugger/render_view_devtools_agent_host.h" #include "content/browser/mock_content_browser_client.h" #include "content/browser/renderer_host/test_render_view_host.h" @@ -13,9 +12,16 @@ #include "content/browser/tab_contents/test_tab_contents.h" #include "content/common/view_messages.h" #include "content/public/browser/content_browser_client.h" +#include "content/public/browser/devtools_agent_host_registry.h" +#include "content/public/browser/devtools_client_host.h" #include "testing/gtest/include/gtest/gtest.h" using base::TimeDelta; +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsClientHost; +using content::DevToolsManager; +using content::DevToolsManagerImpl; namespace { @@ -30,20 +36,20 @@ class TestDevToolsClientHost : public DevToolsClientHost { EXPECT_TRUE(closed_); } - virtual void Close() { + virtual void Close(DevToolsManager* manager) { EXPECT_FALSE(closed_); close_counter++; - NotifyCloseListener(); + manager->ClientHostClosing(this); closed_ = true; } virtual void InspectedTabClosing() { - Close(); + FAIL(); } virtual void SetInspectedTabUrl(const std::string& url) { } - virtual void SendMessageToClient(const IPC::Message& message) { + virtual void DispatchOnInspectorFrontend(const std::string& message) { last_sent_message = &message; } @@ -56,7 +62,7 @@ class TestDevToolsClientHost : public DevToolsClientHost { static int close_counter; - const IPC::Message* last_sent_message; + const std::string* last_sent_message; private: bool closed_; @@ -129,42 +135,46 @@ class DevToolsManagerTest : public RenderViewHostTestHarness { }; TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { - DevToolsManager manager; + DevToolsManagerImpl manager; - DevToolsClientHost* host = manager.GetDevToolsClientHostFor(rvh()); + DevToolsAgentHost* agent = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh()); + DevToolsClientHost* host = manager.GetDevToolsClientHostFor(agent); EXPECT_TRUE(NULL == host); TestDevToolsClientHost client_host; - manager.RegisterDevToolsClientHostFor(rvh(), &client_host); + manager.RegisterDevToolsClientHostFor(agent, &client_host); // Test that just registered devtools host is returned. - host = manager.GetDevToolsClientHostFor(rvh()); + host = manager.GetDevToolsClientHostFor(agent); EXPECT_TRUE(&client_host == host); EXPECT_EQ(0, TestDevToolsClientHost::close_counter); // Test that the same devtools host is returned. - host = manager.GetDevToolsClientHostFor(rvh()); + host = manager.GetDevToolsClientHostFor(agent); EXPECT_TRUE(&client_host == host); EXPECT_EQ(0, TestDevToolsClientHost::close_counter); - client_host.Close(); + client_host.Close(&manager); EXPECT_EQ(1, TestDevToolsClientHost::close_counter); - host = manager.GetDevToolsClientHostFor(rvh()); + host = manager.GetDevToolsClientHostFor(agent); EXPECT_TRUE(NULL == host); } TEST_F(DevToolsManagerTest, ForwardMessageToClient) { - DevToolsManager manager; + DevToolsManagerImpl manager; TestDevToolsClientHost client_host; - manager.RegisterDevToolsClientHostFor(rvh(), &client_host); + DevToolsAgentHost* agent_host = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh()); + manager.RegisterDevToolsClientHostFor(agent_host, &client_host); EXPECT_EQ(0, TestDevToolsClientHost::close_counter); - IPC::Message m; - DevToolsAgentHost* agent_host = RenderViewDevToolsAgentHost::FindFor(rvh()); - manager.ForwardToDevToolsClient(agent_host, m); + std::string m = "test message"; + agent_host = DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh()); + manager.DispatchOnInspectorFrontend(agent_host, m); EXPECT_TRUE(&m == client_host.last_sent_message); - client_host.Close(); + client_host.Close(&manager); EXPECT_EQ(1, TestDevToolsClientHost::close_counter); } @@ -176,8 +186,10 @@ TEST_F(DevToolsManagerTest, NoUnresponsiveDialogInInspectedTab) { contents()->set_delegate(&delegate); TestDevToolsClientHost client_host; + DevToolsAgentHost* agent_host = + DevToolsAgentHostRegistry::GetDevToolsAgentHost(inspected_rvh); DevToolsManager::GetInstance()-> - RegisterDevToolsClientHostFor(inspected_rvh, &client_host); + RegisterDevToolsClientHostFor(agent_host, &client_host); // Start with a short timeout. inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); @@ -188,7 +200,7 @@ TEST_F(DevToolsManagerTest, NoUnresponsiveDialogInInspectedTab) { EXPECT_FALSE(delegate.renderer_unresponsive_received()); // Now close devtools and check that the notification is delivered. - client_host.Close(); + client_host.Close(DevToolsManager::GetInstance()); // Start with a short timeout. inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); // Wait long enough for first timeout and see if it fired. @@ -214,21 +226,24 @@ TEST_F(DevToolsManagerTest, ReattachOnCancelPendingNavigation) { TestDevToolsClientHost client_host; DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - devtools_manager->RegisterDevToolsClientHostFor(rvh(), &client_host); + devtools_manager->RegisterDevToolsClientHostFor( + DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh()), + &client_host); // Navigate to new site which should get a new RenderViewHost. const GURL url2("http://www.yahoo.com"); controller().LoadURL( url2, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); EXPECT_TRUE(contents()->cross_navigation_pending()); - EXPECT_EQ(&client_host, - devtools_manager->GetDevToolsClientHostFor(pending_rvh())); + EXPECT_EQ(&client_host, devtools_manager->GetDevToolsClientHostFor( + DevToolsAgentHostRegistry::GetDevToolsAgentHost(pending_rvh()))); // Interrupt pending navigation and navigate back to the original site. controller().LoadURL( url, GURL(), content::PAGE_TRANSITION_TYPED, std::string()); contents()->TestDidNavigate(orig_rvh, params1); EXPECT_FALSE(contents()->cross_navigation_pending()); - EXPECT_EQ(&client_host, devtools_manager->GetDevToolsClientHostFor(rvh())); - client_host.Close(); + EXPECT_EQ(&client_host, devtools_manager->GetDevToolsClientHostFor( + DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh()))); + client_host.Close(DevToolsManager::GetInstance()); } diff --git a/content/browser/debugger/render_view_devtools_agent_host.cc b/content/browser/debugger/render_view_devtools_agent_host.cc index a479b16..fd3574e 100644 --- a/content/browser/debugger/render_view_devtools_agent_host.cc +++ b/content/browser/debugger/render_view_devtools_agent_host.cc @@ -6,7 +6,7 @@ #include "base/basictypes.h" #include "base/lazy_instance.h" -#include "content/browser/debugger/devtools_manager.h" +#include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/debugger/render_view_devtools_agent_host.h" #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_view_host.h" @@ -14,9 +14,12 @@ #include "content/browser/tab_contents/tab_contents.h" #include "content/common/devtools_messages.h" #include "content/public/browser/content_browser_client.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" +namespace content { + typedef std::map<RenderViewHost*, RenderViewDevToolsAgentHost*> Instances; namespace { @@ -25,7 +28,9 @@ base::LazyInstance<Instances, g_instances = LAZY_INSTANCE_INITIALIZER; } // namespace -DevToolsAgentHost* RenderViewDevToolsAgentHost::FindFor( + +// static +DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHost( RenderViewHost* rvh) { Instances::iterator it = g_instances.Get().find(rvh); if (it != g_instances.Get().end()) @@ -33,8 +38,17 @@ DevToolsAgentHost* RenderViewDevToolsAgentHost::FindFor( return new RenderViewDevToolsAgentHost(rvh); } -bool RenderViewDevToolsAgentHost::IsDebuggerAttached( - TabContents* tab_contents) { +// static +bool DevToolsAgentHostRegistry::HasDevToolsAgentHost(RenderViewHost* rvh) { + if (g_instances == NULL) + return false; + Instances::iterator it = g_instances.Get().find(rvh); + return it != g_instances.Get().end(); +} + +bool DevToolsAgentHostRegistry::IsDebuggerAttached(TabContents* tab_contents) { + if (g_instances == NULL) + return false; DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); if (!devtools_manager) return false; @@ -86,7 +100,8 @@ bool RenderViewDevToolsAgentHost::OnMessageReceived( const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, message) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToClient, OnForwardToClient) + IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, + OnDispatchOnInspectorFrontend) IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, OnSaveAgentRuntimeState) IPC_MESSAGE_HANDLER(DevToolsHostMsg_ClearBrowserCache, OnClearBrowserCache) @@ -99,12 +114,12 @@ bool RenderViewDevToolsAgentHost::OnMessageReceived( void RenderViewDevToolsAgentHost::OnSaveAgentRuntimeState( const std::string& state) { - DevToolsManager::GetInstance()->SaveAgentRuntimeState(this, state); + DevToolsManagerImpl::GetInstance()->SaveAgentRuntimeState(this, state); } -void RenderViewDevToolsAgentHost::OnForwardToClient( - const IPC::Message& message) { - DevToolsManager::GetInstance()->ForwardToDevToolsClient( +void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend( + const std::string& message) { + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( this, message); } @@ -116,3 +131,5 @@ void RenderViewDevToolsAgentHost::OnClearBrowserCookies() { content::GetContentClient()->browser()->ClearCookies(render_view_host_); } +} // namespace content + diff --git a/content/browser/debugger/render_view_devtools_agent_host.h b/content/browser/debugger/render_view_devtools_agent_host.h index ff31de9..e0cab1f 100644 --- a/content/browser/debugger/render_view_devtools_agent_host.h +++ b/content/browser/debugger/render_view_devtools_agent_host.h @@ -16,15 +16,15 @@ class RenderViewHost; class TabContents; +namespace content { + class CONTENT_EXPORT RenderViewDevToolsAgentHost : public DevToolsAgentHost, private content::RenderViewHostObserver { public: - static DevToolsAgentHost* FindFor(RenderViewHost*); - static bool IsDebuggerAttached(TabContents*); + RenderViewDevToolsAgentHost(RenderViewHost*); private: - RenderViewDevToolsAgentHost(RenderViewHost*); virtual ~RenderViewDevToolsAgentHost(); // DevToolsAgentHost implementation. @@ -36,7 +36,7 @@ class CONTENT_EXPORT RenderViewDevToolsAgentHost virtual void RenderViewHostDestroyed(RenderViewHost* rvh) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - void OnForwardToClient(const IPC::Message& message); + void OnDispatchOnInspectorFrontend(const std::string& message); void OnSaveAgentRuntimeState(const std::string& state); void OnClearBrowserCache(); void OnClearBrowserCookies(); @@ -46,4 +46,6 @@ class CONTENT_EXPORT RenderViewDevToolsAgentHost DISALLOW_COPY_AND_ASSIGN(RenderViewDevToolsAgentHost); }; +} // namespace content + #endif // CONTENT_BROWSER_DEBUGGER_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_ diff --git a/content/browser/debugger/worker_devtools_manager.cc b/content/browser/debugger/worker_devtools_manager.cc index 6d6b366..6709d75 100644 --- a/content/browser/debugger/worker_devtools_manager.cc +++ b/content/browser/debugger/worker_devtools_manager.cc @@ -9,12 +9,13 @@ #include "base/bind.h" #include "content/browser/debugger/devtools_agent_host.h" -#include "content/browser/debugger/devtools_manager.h" +#include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/debugger/worker_devtools_message_filter.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/browser/worker_host/worker_service.h" #include "content/common/devtools_messages.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" @@ -26,6 +27,18 @@ using content::BrowserThread; +namespace content { + +// Called on the UI thread. +// static +DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( + int worker_process_id, + int worker_route_id) { + return WorkerDevToolsManager::GetDevToolsAgentHostForWorker( + worker_process_id, + worker_route_id); +} + class WorkerDevToolsManager::AgentHosts : private content::NotificationObserver { public: @@ -165,10 +178,10 @@ class WorkerDevToolsManager::DetachedClientHosts { RemovePendingWorkerData(id); return; } - DevToolsManager::GetInstance()->ForwardToDevToolsClient(agent, - DevToolsClientMsg_DispatchOnInspectorFrontend(MSG_ROUTING_NONE, - WebKit::WebDevToolsAgent::disconnectEventAsText().utf8())); - int cookie = DevToolsManager::GetInstance()->DetachClientHost(agent); + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( + agent, + WebKit::WebDevToolsAgent::disconnectEventAsText().utf8()); + int cookie = DevToolsManagerImpl::GetInstance()->DetachClientHost(agent); if (cookie == -1) { RemovePendingWorkerData(id); return; @@ -194,7 +207,7 @@ class WorkerDevToolsManager::DetachedClientHosts { WorkerDevToolsManager::GetDevToolsAgentHostForWorker( new_id.first, new_id.second); - DevToolsManager::GetInstance()->AttachClientHost( + DevToolsManagerImpl::GetInstance()->AttachClientHost( it->second, agent); worker_id_to_cookie_.erase(it); @@ -386,7 +399,7 @@ void WorkerDevToolsManager::RegisterDevToolsAgentHostForWorker( void WorkerDevToolsManager::ForwardToDevToolsClient( int worker_process_id, int worker_route_id, - const IPC::Message& message) { + const std::string& message) { if (FindInspectedWorker(worker_process_id, worker_route_id) == inspected_workers_.end()) { NOTREACHED(); @@ -431,13 +444,14 @@ void WorkerDevToolsManager::ForwardToWorkerDevToolsAgent( void WorkerDevToolsManager::ForwardToDevToolsClientOnUIThread( int worker_process_id, int worker_route_id, - const IPC::Message& message) { + const std::string& message) { WorkerDevToolsAgentHost* agent_host = AgentHosts::GetAgentHost(WorkerId( worker_process_id, worker_route_id)); if (!agent_host) return; - DevToolsManager::GetInstance()->ForwardToDevToolsClient(agent_host, message); + DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(agent_host, + message); } // static @@ -450,7 +464,7 @@ void WorkerDevToolsManager::SaveAgentRuntimeStateOnUIThread( worker_route_id)); if (!agent_host) return; - DevToolsManager::GetInstance()->SaveAgentRuntimeState(agent_host, state); + DevToolsManagerImpl::GetInstance()->SaveAgentRuntimeState(agent_host, state); } // static @@ -480,3 +494,5 @@ void WorkerDevToolsManager::SendResumeToWorker(const WorkerId& id) { if (WorkerProcessHost* process = FindWorkerProcess(id.first)) process->Send(new DevToolsAgentMsg_ResumeWorkerContext(id.second)); } + +} // namespace diff --git a/content/browser/debugger/worker_devtools_manager.h b/content/browser/debugger/worker_devtools_manager.h index 228653e..9cc55e5 100644 --- a/content/browser/debugger/worker_devtools_manager.h +++ b/content/browser/debugger/worker_devtools_manager.h @@ -15,12 +15,14 @@ #include "content/common/content_export.h" #include "content/browser/worker_host/worker_service_observer.h" -class DevToolsAgentHost; - namespace IPC { class Message; } +namespace content { + +class DevToolsAgentHost; + // All methods are supposed to be called on the IO thread. class WorkerDevToolsManager : private WorkerServiceObserver { public: @@ -28,13 +30,13 @@ class WorkerDevToolsManager : private WorkerServiceObserver { static WorkerDevToolsManager* GetInstance(); // Called on the UI thread. - CONTENT_EXPORT static DevToolsAgentHost* GetDevToolsAgentHostForWorker( + static DevToolsAgentHost* GetDevToolsAgentHostForWorker( int worker_process_id, int worker_route_id); void ForwardToDevToolsClient(int worker_process_id, int worker_route_id, - const IPC::Message& message); + const std::string& message); void SaveAgentRuntimeState(int worker_process_id, int worker_route_id, const std::string& state); @@ -72,7 +74,7 @@ class WorkerDevToolsManager : private WorkerServiceObserver { static void ForwardToDevToolsClientOnUIThread( int worker_process_id, int worker_route_id, - const IPC::Message& message); + const std::string& message); static void SaveAgentRuntimeStateOnUIThread( int worker_process_id, int worker_route_id, @@ -110,4 +112,6 @@ class WorkerDevToolsManager : private WorkerServiceObserver { DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsManager); }; +} // namespace content + #endif // CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MANAGER_H_ diff --git a/content/browser/debugger/worker_devtools_message_filter.cc b/content/browser/debugger/worker_devtools_message_filter.cc index 3d1795f..6cc0bc0 100644 --- a/content/browser/debugger/worker_devtools_message_filter.cc +++ b/content/browser/debugger/worker_devtools_message_filter.cc @@ -9,6 +9,8 @@ #include "content/common/devtools_messages.h" #include "content/common/worker_messages.h" +namespace content { + WorkerDevToolsMessageFilter::WorkerDevToolsMessageFilter( int worker_process_host_id) : worker_process_host_id_(worker_process_host_id), @@ -25,7 +27,8 @@ bool WorkerDevToolsMessageFilter::OnMessageReceived( current_routing_id_ = message.routing_id(); IPC_BEGIN_MESSAGE_MAP_EX(WorkerDevToolsMessageFilter, message, *message_was_ok) - IPC_MESSAGE_HANDLER(DevToolsHostMsg_ForwardToClient, OnForwardToClient) + IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, + OnDispatchOnInspectorFrontend) IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, OnSaveAgentRumtimeState) IPC_MESSAGE_UNHANDLED(handled = false) @@ -33,10 +36,10 @@ bool WorkerDevToolsMessageFilter::OnMessageReceived( return handled; } -void WorkerDevToolsMessageFilter::OnForwardToClient( - const IPC::Message& message) { +void WorkerDevToolsMessageFilter::OnDispatchOnInspectorFrontend( + const std::string& message) { WorkerDevToolsManager::GetInstance()->ForwardToDevToolsClient( - worker_process_host_id_, message.routing_id(), message); + worker_process_host_id_, current_routing_id_, message); } void WorkerDevToolsMessageFilter::OnSaveAgentRumtimeState( @@ -44,3 +47,5 @@ void WorkerDevToolsMessageFilter::OnSaveAgentRumtimeState( WorkerDevToolsManager::GetInstance()->SaveAgentRuntimeState( worker_process_host_id_, current_routing_id_, state); } + +} // namespace content diff --git a/content/browser/debugger/worker_devtools_message_filter.h b/content/browser/debugger/worker_devtools_message_filter.h index 23cd549..bfa96bd 100644 --- a/content/browser/debugger/worker_devtools_message_filter.h +++ b/content/browser/debugger/worker_devtools_message_filter.h @@ -9,6 +9,8 @@ #include "base/callback_forward.h" #include "content/browser/browser_message_filter.h" +namespace content { + class WorkerDevToolsMessageFilter : public BrowserMessageFilter { public: explicit WorkerDevToolsMessageFilter(int worker_process_host_id); @@ -20,7 +22,7 @@ class WorkerDevToolsMessageFilter : public BrowserMessageFilter { virtual bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok) OVERRIDE; // Message handlers. - void OnForwardToClient(const IPC::Message& message); + void OnDispatchOnInspectorFrontend(const std::string& message); void OnSaveAgentRumtimeState(const std::string& state); int worker_process_host_id_; @@ -29,4 +31,6 @@ class WorkerDevToolsMessageFilter : public BrowserMessageFilter { DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsMessageFilter); }; +} // namespace content + #endif // CONTENT_BROWSER_DEBUGGER_WORKER_DEVTOOLS_MESSAGE_FILTER_H_ diff --git a/content/browser/tab_contents/render_view_host_manager.cc b/content/browser/tab_contents/render_view_host_manager.cc index 2aacafc..f2d72a3 100644 --- a/content/browser/tab_contents/render_view_host_manager.cc +++ b/content/browser/tab_contents/render_view_host_manager.cc @@ -6,7 +6,7 @@ #include "base/command_line.h" #include "base/logging.h" -#include "content/browser/debugger/devtools_manager.h" +#include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/renderer_host/render_view_host_factory.h" @@ -753,11 +753,9 @@ void RenderViewHostManager::CancelPending() { RenderViewHost* pending_render_view_host = pending_render_view_host_; pending_render_view_host_ = NULL; - DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - if (devtools_manager) { // NULL in unit tests. - devtools_manager->OnCancelPendingNavigation(pending_render_view_host, - render_view_host_); - } + content::DevToolsManagerImpl::GetInstance()->OnCancelPendingNavigation( + pending_render_view_host, + render_view_host_); // We no longer need to prevent the process from exiting. pending_render_view_host->process()->RemovePendingView(); diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index f7fa51e..f3359a9 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -15,7 +15,7 @@ #include "base/utf_string_conversions.h" #include "content/browser/browser_context.h" #include "content/browser/child_process_security_policy.h" -#include "content/browser/debugger/devtools_manager.h" +#include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/download/download_manager.h" #include "content/browser/download/download_stats.h" #include "content/browser/host_zoom_map.h" @@ -41,7 +41,7 @@ #include "content/common/intents_messages.h" #include "content/common/view_messages.h" #include "content/public/browser/content_browser_client.h" -#include "content/public/browser/navigation_type.h" +#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/notification_service.h" #include "content/public/common/bindings_policy.h" #include "content/public/common/content_constants.h" @@ -106,6 +106,10 @@ // replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading // of the old RVH. +using content::DevToolsAgentHost; +using content::DevToolsAgentHostRegistry; +using content::DevToolsManagerImpl; + namespace { // Amount of time we wait between when a key event is received and the renderer @@ -614,12 +618,10 @@ bool TabContents::NavigateToEntry( is_allowed_in_web_ui_renderer); // Tell DevTools agent that it is attached prior to the navigation. - DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - if (devtools_manager) { // NULL in unit tests. - devtools_manager->OnNavigatingToPendingEntry(render_view_host(), - dest_render_view_host, - entry.url()); - } + DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry( + render_view_host(), + dest_render_view_host, + entry.url()); // Used for page load time metrics. current_load_start_ = base::TimeTicks::Now(); @@ -1892,9 +1894,10 @@ void TabContents::RendererUnresponsive(RenderViewHost* rvh, // Ignore renderer unresponsive event if debugger is attached to the tab // since the event may be a result of the renderer sitting on a breakpoint. // See http://crbug.com/65458 - DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); - if (devtools_manager && - devtools_manager->GetDevToolsClientHostFor(rvh) != NULL) + DevToolsAgentHost* agent = + content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh); + if (agent && + DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent)) return; if (is_during_unload) { diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index 79f0dc2..ba29447 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -259,7 +259,7 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { new SocketStreamDispatcherHost( new URLRequestContextSelector(request_context), resource_context_); AddFilter(socket_stream_dispatcher_host); - AddFilter(new WorkerDevToolsMessageFilter(id())); + AddFilter(new content::WorkerDevToolsMessageFilter(id())); } void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { diff --git a/content/common/devtools_messages.h b/content/common/devtools_messages.h index 36c88c0..6f29c0e 100644 --- a/content/common/devtools_messages.h +++ b/content/common/devtools_messages.h @@ -100,16 +100,6 @@ IPC_MESSAGE_ROUTED0(DevToolsMsg_SetupDevToolsClient) //----------------------------------------------------------------------------- // These are messages sent from the renderer to the browser. -// Wraps an IPC message that's destined to the DevToolsClient on -// DevToolsAgent->browser hop. -IPC_MESSAGE_ROUTED1(DevToolsHostMsg_ForwardToClient, - IPC::Message /* one of DevToolsClientMsg_XXX types */) - -// Wraps an IPC message that's destined to the DevToolsAgent on -// DevToolsClient->browser hop. -IPC_MESSAGE_ROUTED1(DevToolsHostMsg_ForwardToAgent, - IPC::Message /* one of DevToolsAgentMsg_XXX types */) - // Activates (brings to the front) corresponding dev tools window. IPC_MESSAGE_ROUTED0(DevToolsHostMsg_ActivateWindow) diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 754db1d..1256bfb 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -30,9 +30,11 @@ 'public/browser/browser_thread_delegate.h', 'public/browser/content_browser_client.h', 'public/browser/content_ipc_logging.h', - 'public/browser/download_manager_delegate.h', - 'public/browser/devtools_frontend_window.h', + 'public/browser/devtools_agent_host_registry.h', + 'public/browser/devtools_client_host.h', 'public/browser/devtools_frontend_window_delegate.h', + 'public/browser/devtools_manager.h', + 'public/browser/download_manager_delegate.h', 'public/browser/native_web_keyboard_event.h', 'public/browser/navigation_type.h', 'public/browser/notification_details.h', @@ -105,14 +107,12 @@ 'browser/cross_site_request_manager.h', 'browser/debugger/devtools_agent_host.cc', 'browser/debugger/devtools_agent_host.h', - 'browser/debugger/devtools_client_host.cc', - 'browser/debugger/devtools_client_host.h', - 'browser/debugger/devtools_frontend_message_handler.cc', - 'browser/debugger/devtools_frontend_message_handler.h', + 'browser/debugger/devtools_frontend_host.cc', + 'browser/debugger/devtools_frontend_host.h', 'browser/debugger/devtools_http_protocol_handler.cc', 'browser/debugger/devtools_http_protocol_handler.h', - 'browser/debugger/devtools_manager.cc', - 'browser/debugger/devtools_manager.h', + 'browser/debugger/devtools_manager_impl.cc', + 'browser/debugger/devtools_manager_impl.h', 'browser/debugger/devtools_netlog_observer.cc', 'browser/debugger/devtools_netlog_observer.h', 'browser/debugger/render_view_devtools_agent_host.cc', diff --git a/content/public/browser/devtools_agent_host_registry.h b/content/public/browser/devtools_agent_host_registry.h new file mode 100644 index 0000000..567d32e --- /dev/null +++ b/content/public/browser/devtools_agent_host_registry.h @@ -0,0 +1,39 @@ +// Copyright (c) 2011 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_AGENT_HOST_REGISTRY_H_ +#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_REGISTRY_H_ +#pragma once + +#include "content/common/content_export.h" + +class RenderViewHost; +class TabContents; + +namespace content { + +class DevToolsAgentHost; + +class CONTENT_EXPORT DevToolsAgentHostRegistry { + public: + // Returns DevToolsAgentHost that can be used for inspecting |rvh|. + // New DevToolsAgentHost will be created if it does not exist. + static DevToolsAgentHost* GetDevToolsAgentHost(RenderViewHost* rvh); + + // Returns true iff an instance of DevToolsAgentHost for the |rvh| + // does exist. + static bool HasDevToolsAgentHost(RenderViewHost* rvh); + + // Returns DevToolsAgentHost that can be used for inspecting shared worker + // with given worker process host id and routing id. + static DevToolsAgentHost* GetDevToolsAgentHostForWorker( + int worker_process_id, + int worker_route_id); + + static bool IsDebuggerAttached(TabContents* tab_contents); +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_REGISTRY_H_ diff --git a/content/browser/debugger/devtools_client_host.h b/content/public/browser/devtools_client_host.h index 0ae8c1b..8bd98e8 100644 --- a/content/browser/debugger/devtools_client_host.h +++ b/content/public/browser/devtools_client_host.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_CLIENT_HOST_H_ -#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_CLIENT_HOST_H_ +#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_CLIENT_HOST_H_ +#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_CLIENT_HOST_H_ #pragma once #include <string> @@ -15,23 +15,22 @@ namespace IPC { class Message; } +class RenderViewHost; class TabContents; +namespace content { + +class DevToolsFrontendHostDelegate; + // Describes interface for managing devtools clients from browser process. There // are currently two types of clients: devtools windows and TCP socket // debuggers. class CONTENT_EXPORT DevToolsClientHost { public: - class CONTENT_EXPORT CloseListener { - public: - CloseListener() {} - virtual ~CloseListener() {} - virtual void ClientHostClosing(DevToolsClientHost* host) = 0; - private: - DISALLOW_COPY_AND_ASSIGN(CloseListener); - }; + virtual ~DevToolsClientHost() {} - virtual ~DevToolsClientHost(); + // Dispatches given message on the front-end. + virtual void DispatchOnInspectorFrontend(const std::string& message) = 0; // This method is called when tab inspected by this devtools client is // closing. @@ -41,29 +40,20 @@ class CONTENT_EXPORT DevToolsClientHost { // navigating to |url|. virtual void FrameNavigating(const std::string& url) = 0; - // Sends the message to the devtools client hosted by this object. - virtual void SendMessageToClient(const IPC::Message& msg) = 0; - - void set_close_listener(CloseListener* listener) { - close_listener_ = listener; - } - // Invoked when a tab is replaced by another tab. This is triggered by // TabStripModel::ReplaceTabContentsAt. virtual void TabReplaced(TabContents* new_tab) = 0; - protected: - DevToolsClientHost(); + // Creates DevToolsClientHost for TabContents containing default DevTools + // frontend implementation. + static DevToolsClientHost* CreateDevToolsFrontendHost( + TabContents* client_tab_contents, + DevToolsFrontendHostDelegate* delegate); - void ForwardToDevToolsAgent(const IPC::Message& message); - - // Should be called when the devtools client is going to die and this - // DevToolsClientHost should not be used anymore. - void NotifyCloseListener(); - - private: - CloseListener* close_listener_; - DISALLOW_COPY_AND_ASSIGN(DevToolsClientHost); + // Sets up DevToolsClient on the corresponding RenderView. + static void SetupDevToolsFrontendClient(RenderViewHost* frontend_rvh); }; -#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_CLIENT_HOST_H_ +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_CLIENT_HOST_H_ diff --git a/content/public/browser/devtools_frontend_window_delegate.h b/content/public/browser/devtools_frontend_host_delegate.h index 06463ee..b645bf1 100644 --- a/content/public/browser/devtools_frontend_window_delegate.h +++ b/content/public/browser/devtools_frontend_host_delegate.h @@ -2,27 +2,20 @@ // 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_WINDOW_DELEGATE_H_ -#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_WINDOW_DELEGATE_H_ +#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_DELEGATE_H_ +#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_DELEGATE_H_ #pragma once #include <string> -namespace IPC { -class Message; -} - 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 DevToolsFrontendWindowDelegate { +class DevToolsFrontendHostDelegate { public: - virtual ~DevToolsFrontendWindowDelegate() {} - - // Routes message to the corresponding agent. - virtual void ForwardToDevToolsAgent(const IPC::Message& message) = 0; + virtual ~DevToolsFrontendHostDelegate() {} // Should bring DevTools window to front. virtual void ActivateWindow() = 0; @@ -43,8 +36,21 @@ class DevToolsFrontendWindowDelegate { // Shows "Save As..." dialog to save |content|. virtual void SaveToFile(const std::string& suggested_file_name, const std::string& content) = 0; + + + // This method is called when tab inspected by this devtools frontend is + // closing. + virtual void InspectedTabClosing() = 0; + + // This method is called when tab inspected by this devtools frontend is + // navigating to |url|. + virtual void FrameNavigating(const std::string& url) = 0; + + // Invoked when tab inspected by this devtools frontend is replaced by + // another tab. This is triggered by TabStripModel::ReplaceTabContentsAt. + virtual void TabReplaced(TabContents* new_tab) = 0; }; } // namespace content -#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_WINDOW_DELEGATE_H_ +#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_HOST_DELEGATE_H_ diff --git a/content/public/browser/devtools_frontend_window.h b/content/public/browser/devtools_frontend_window.h deleted file mode 100644 index 6b54ba4..0000000 --- a/content/public/browser/devtools_frontend_window.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2011 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_WINDOW_H_ -#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_WINDOW_H_ -#pragma once - -class TabContents; - -namespace content { - -class DevToolsFrontendWindowDelegate; - -// Installs delegate for DevTools front-end loaded into |client_tab_contents|. -CONTENT_EXPORT void SetupDevToolsFrontendDelegate( - TabContents* client_tab_contents, - DevToolsFrontendWindowDelegate* delegate); - -} - -#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_FRONTEND_WINDOW_H_ diff --git a/content/public/browser/devtools_manager.h b/content/public/browser/devtools_manager.h new file mode 100644 index 0000000..d2f1667 --- /dev/null +++ b/content/public/browser/devtools_manager.h @@ -0,0 +1,79 @@ +// Copyright (c) 2011 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_MANAGER_H_ +#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_H_ +#pragma once + +#include <string> + +#include "content/common/content_export.h" + +class TabContents; + +namespace IPC { +class Message; +} + +namespace content { + +class DevToolsAgentHost; +class DevToolsClientHost; + +// DevToolsManager connects a devtools client to inspected agent and routes +// devtools messages between the inspected instance represented by the agent +// and devtools front-end represented by the client. If inspected agent +// gets terminated DevToolsManager will notify corresponding client and +// remove it from the map. +class CONTENT_EXPORT DevToolsManager { + public: + static DevToolsManager* GetInstance(); + + // Routes devtools message from |from| client to corresponding + // DevToolsAgentHost. + virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from, + const std::string& message) = 0; + + // Invoked when a tab is replaced by another tab. This is triggered by + // TabStripModel::ReplaceTabContentsAt. + virtual void TabReplaced(TabContents* old_tab, TabContents* new_tab) = 0; + + // Closes all open developer tools windows. + virtual void CloseAllClientHosts() = 0; + + // Returns client attached to the |agent_host| if there is one. + virtual DevToolsClientHost* GetDevToolsClientHostFor( + DevToolsAgentHost* agent_host) = 0; + + // Registers new DevToolsClientHost for inspected |agent_host|. There must be + // no other DevToolsClientHosts registered for the |agent_host| at the moment. + virtual void RegisterDevToolsClientHostFor( + DevToolsAgentHost* agent_host, + DevToolsClientHost* client_host) = 0; + // Unregisters given |agent_host|. DevToolsManager will notify corresponding + // client if one is attached. + virtual void UnregisterDevToolsClientHostFor( + DevToolsAgentHost* agent_host) = 0; + + // Detaches client from |from_agent| and returns a cookie that allows to + // reattach that client to another agent later. Returns -1 if there is no + // client attached to |from_agent|. + virtual int DetachClientHost(DevToolsAgentHost* from_agent) = 0; + // Reattaches client host detached with DetachClientHost method above + // to |to_agent|. + virtual void AttachClientHost(int client_host_cookie, + DevToolsAgentHost* to_agent) = 0; + + // This method will remove all references from the manager to the + // DevToolsClientHost and unregister all listeners related to the + // DevToolsClientHost. Called by closing client. + virtual void ClientHostClosing(DevToolsClientHost* client_host) = 0; + + // Starts inspecting element at position (x, y) in the specified page. + virtual void InspectElement(DevToolsAgentHost* agent_host, int x, int y) = 0; +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_H_ diff --git a/content/renderer/devtools_agent.cc b/content/renderer/devtools_agent.cc index 093011c..7843fc6 100644 --- a/content/renderer/devtools_agent.cc +++ b/content/renderer/devtools_agent.cc @@ -92,10 +92,8 @@ bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { void DevToolsAgent::sendMessageToInspectorFrontend( const WebKit::WebString& message) { - Send(new DevToolsHostMsg_ForwardToClient( - routing_id(), - DevToolsClientMsg_DispatchOnInspectorFrontend(MSG_ROUTING_NONE, - message.utf8()))); + Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(routing_id(), + message.utf8())); } int DevToolsAgent::hostIdentifier() { diff --git a/content/renderer/devtools_client.cc b/content/renderer/devtools_client.cc index 961c149..73731fe 100644 --- a/content/renderer/devtools_client.cc +++ b/content/renderer/devtools_client.cc @@ -32,10 +32,6 @@ DevToolsClient::DevToolsClient(RenderViewImpl* render_view) DevToolsClient::~DevToolsClient() { } -void DevToolsClient::SendToAgent(const IPC::Message& tools_agent_message) { - Send(new DevToolsHostMsg_ForwardToAgent(routing_id(), tools_agent_message)); -} - bool DevToolsClient::OnMessageReceived(const IPC::Message& message) { DCHECK(RenderThreadImpl::current()); @@ -50,8 +46,8 @@ bool DevToolsClient::OnMessageReceived(const IPC::Message& message) { } void DevToolsClient::sendMessageToBackend(const WebString& message) { - SendToAgent(DevToolsAgentMsg_DispatchOnInspectorBackend(MSG_ROUTING_NONE, - message.utf8())); + Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(routing_id(), + message.utf8())); } void DevToolsClient::activateWindow() { diff --git a/content/renderer/devtools_client.h b/content/renderer/devtools_client.h index 8dedfd6..a85a7d9 100644 --- a/content/renderer/devtools_client.h +++ b/content/renderer/devtools_client.h @@ -49,9 +49,6 @@ class DevToolsClient : public content::RenderViewObserver, void OnDispatchOnInspectorFrontend(const std::string& message); - // Sends message to DevToolsAgent. - void SendToAgent(const IPC::Message& tools_agent_message); - scoped_ptr<WebKit::WebDevToolsFrontend> web_tools_frontend_; DISALLOW_COPY_AND_ASSIGN(DevToolsClient); diff --git a/content/worker/shared_worker_devtools_agent.cc b/content/worker/shared_worker_devtools_agent.cc index 702105d..9e897575 100644 --- a/content/worker/shared_worker_devtools_agent.cc +++ b/content/worker/shared_worker_devtools_agent.cc @@ -43,10 +43,9 @@ bool SharedWorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) { void SharedWorkerDevToolsAgent::SendDevToolsMessage( const WebKit::WebString& message) { - IPC::Message m = DevToolsClientMsg_DispatchOnInspectorFrontend( + Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( route_id_, - message.utf8()); - Send(new DevToolsHostMsg_ForwardToClient(route_id_, m)); + message.utf8())); } void SharedWorkerDevToolsAgent::SaveDevToolsAgentState( |