Chromium Code Reviews| Index: content/browser/debugger/devtools_manager.cc |
| diff --git a/content/browser/debugger/devtools_manager.cc b/content/browser/debugger/devtools_manager.cc |
| index 2db4480a13e9b3131fec94dfb4deb9824cbdbea7..128551262fce6243792308cd7c3d6e1886df3081 100644 |
| --- a/content/browser/debugger/devtools_manager.cc |
| +++ b/content/browser/debugger/devtools_manager.cc |
| @@ -12,6 +12,7 @@ |
| #include "chrome/browser/io_thread.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
|
Jói
2011/07/05 18:00:45
Please don't add a new dependency on ProfileManage
pfeldman
2011/07/06 08:29:39
Do you have an estimate on when migration is compl
jam
2011/07/06 13:47:40
if a method is added to ContentBrowserClient to re
yurys
2011/07/06 14:03:52
My understanding is that DevToolsWindow is a Chrom
|
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/browser/browsing_instance.h" |
| @@ -19,6 +20,7 @@ |
| #include "content/browser/debugger/devtools_client_host.h" |
| #include "content/browser/debugger/devtools_netlog_observer.h" |
| #include "content/browser/debugger/devtools_window.h" |
| +#include "content/browser/debugger/worker_devtools_manager.h" |
| #include "content/browser/renderer_host/render_view_host.h" |
| #include "content/browser/site_instance.h" |
| #include "content/common/devtools_messages.h" |
| @@ -55,6 +57,7 @@ DevToolsManager::~DevToolsManager() { |
| // By the time we destroy devtools manager, all orphan client hosts should |
| // have been delelted, no need to notify them upon tab closing. |
| DCHECK(orphan_client_hosts_.empty()); |
| + DCHECK(worker_id_to_client_host_.empty()); |
| } |
| DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( |
| @@ -81,8 +84,11 @@ void DevToolsManager::ForwardToDevToolsAgent( |
| RenderViewHost* client_rvh, |
| const IPC::Message& message) { |
| DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); |
| - if (client_host) |
| + if (client_host) { |
| ForwardToDevToolsAgent(client_host, message); |
| + return; |
| + } |
| + ForwardToWorkerDevToolsAgent(client_rvh, message); |
| } |
| void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, |
| @@ -110,6 +116,82 @@ void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, |
| client_host->SendMessageToClient(message); |
| } |
| +void DevToolsManager::OpenDevToolsForWorker(int worker_devtools_id) { |
| + Profile* profile = ProfileManager::GetDefaultProfile(); |
| + if (!profile) |
| + return; |
| + DevToolsWindow* window = new DevToolsWindow(profile, NULL, false); |
| + window->set_close_listener(this); |
| + window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); |
| + worker_id_to_client_host_[worker_devtools_id] = window; |
| +} |
| + |
| +void DevToolsManager::ForwardToWorkerDevToolsClient( |
| + int worker_devtools_id, |
| + const IPC::Message& message) { |
| + WorkerIdToClientHostMap::iterator it = |
| + worker_id_to_client_host_.find(worker_devtools_id); |
| + if (it == worker_id_to_client_host_.end()) |
| + return; |
| + it->second->SendMessageToClient(message); |
| +} |
| + |
| +static void ForwardToWorkerDevToolsAgentOnIOThread( |
| + int worker_devtools_id, |
| + const IPC::Message& message) { |
| + WorkerDevToolsManager::GetInstance()->ForwardToWorkerDevToolsAgent( |
| + worker_devtools_id, message); |
| +} |
| + |
| +void DevToolsManager::ForwardToWorkerDevToolsAgent( |
| + RenderViewHost* client_rvh, |
| + const IPC::Message& message) { |
| + int worker_devtools_id = FindWorkerDevToolsId(client_rvh); |
| + if (worker_devtools_id == -1) |
| + return; |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + NewRunnableFunction( |
| + ForwardToWorkerDevToolsAgentOnIOThread, |
| + worker_devtools_id, |
| + IPC::Message(message))); |
| +} |
| + |
| +int DevToolsManager::FindWorkerDevToolsId(RenderViewHost* client_rvh) { |
| + for (WorkerIdToClientHostMap::const_iterator it = |
| + worker_id_to_client_host_.begin(); |
| + it != worker_id_to_client_host_.end(); ++it) { |
| + DevToolsWindow* window = it->second->AsDevToolsWindow(); |
| + if (!window) |
| + continue; |
| + if (window->GetRenderViewHost() != client_rvh) |
| + continue; |
| + return it->first; |
| + } |
| + return -1; |
| +} |
| + |
| +static void NotifyWorkerDevToolsClientClosingOnIOThread( |
| + int worker_devtools_id) { |
| + WorkerDevToolsManager::GetInstance()->WorkerDevToolsClientClosing( |
| + worker_devtools_id); |
| +} |
| + |
| +void DevToolsManager::MaybeWorkerDevToolsClientHostClosing( |
| + DevToolsClientHost* host) { |
| + WorkerIdToClientHostMap::iterator it = worker_id_to_client_host_.begin(); |
| + for (; it != worker_id_to_client_host_.end(); ++it) { |
| + if (it->second == host) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + NewRunnableFunction(NotifyWorkerDevToolsClientClosingOnIOThread, |
| + it->first)); |
| + worker_id_to_client_host_.erase(it); |
| + return; |
| + } |
| + } |
| +} |
| + |
| void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { |
| DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); |
| if (!client_host) |
| @@ -186,6 +268,10 @@ void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { |
| return; |
| } |
| } |
| + |
| + // Worker DevTools clients don't have inspected RVHs. Check if one of them |
| + // is closing. |
| + MaybeWorkerDevToolsClientHostClosing(host); |
| return; |
| } |