diff options
author | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 08:26:06 +0000 |
---|---|---|
committer | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 08:26:06 +0000 |
commit | bf7cc538f3e6f04f043fb5c56457597e2702fda7 (patch) | |
tree | 31745bc501a32190b9eedde0b9783a5395405bbb | |
parent | 69b5cc1cd49d108cdb7ced431f8caf56e8d3bd43 (diff) | |
download | chromium_src-bf7cc538f3e6f04f043fb5c56457597e2702fda7.zip chromium_src-bf7cc538f3e6f04f043fb5c56457597e2702fda7.tar.gz chromium_src-bf7cc538f3e6f04f043fb5c56457597e2702fda7.tar.bz2 |
This change provides initial support for sending DevTools messages between Worker and Page processes.
On the Page side devtools messages are handled by WorkerDevtoolsAgentProxy. It implements WebWorkerBase::DevToolsDelegate interface which isolates worker stuff under content/ from DevTools specifics.
In the worker process it's WorkerDevtoolsAgent that is responsible for sending/receiving devtools messages. It implements WebWorkerStub::DevToolsDelegate and WebWorkerClientProxy::DevToolsDelegate which insulate worker stuff under content/ from the devtools implementation details.
WorkerDevtoolsAgentProxy and WorkerDevtoolsAgent are counterparts of WebWorkerProxy and WebWorkerStub. Since devtools is not a part of HTML5 the new classes live under chrome/
ContentWorkerClient is introduced for notifying embedder about certain events when worker clients can be installed.
BUG=13684
TEST=None
Review URL: http://codereview.chromium.org/6990059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86991 0039d316-1c4b-4281-b951-d872f2087c98
36 files changed, 334 insertions, 29 deletions
diff --git a/chrome/browser/debugger/debugger_remote_service.cc b/chrome/browser/debugger/debugger_remote_service.cc index 5847191..8f814a8 100644 --- a/chrome/browser/debugger/debugger_remote_service.cc +++ b/chrome/browser/debugger/debugger_remote_service.cc @@ -17,10 +17,10 @@ #include "chrome/browser/debugger/devtools_protocol_handler.h" #include "chrome/browser/debugger/devtools_remote_message.h" #include "chrome/browser/debugger/inspectable_tab_proxy.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/render_messages.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" namespace { diff --git a/chrome/browser/debugger/devtools_handler.cc b/chrome/browser/debugger/devtools_handler.cc index 9e60a11..3627954 100644 --- a/chrome/browser/debugger/devtools_handler.cc +++ b/chrome/browser/debugger/devtools_handler.cc @@ -6,9 +6,9 @@ #include "chrome/browser/debugger/devtools_file_util.h" #include "chrome/browser/debugger/devtools_manager.h" -#include "chrome/common/devtools_messages.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" DevToolsHandler::DevToolsHandler(RenderViewHost* render_view_host) : RenderViewHostObserver(render_view_host) { diff --git a/chrome/browser/debugger/devtools_http_protocol_handler.cc b/chrome/browser/debugger/devtools_http_protocol_handler.cc index 9b2abacf..b0763b0 100644 --- a/chrome/browser/debugger/devtools_http_protocol_handler.cc +++ b/chrome/browser/debugger/devtools_http_protocol_handler.cc @@ -20,9 +20,9 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/devtools_ui.h" -#include "chrome/common/devtools_messages.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" #include "grit/devtools_frontend_resources.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc index 34e935d..0f4180b 100644 --- a/chrome/browser/debugger/devtools_manager.cc +++ b/chrome/browser/debugger/devtools_manager.cc @@ -16,12 +16,12 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/pref_names.h" #include "content/browser/browsing_instance.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/site_instance.h" +#include "content/common/devtools_messages.h" #include "content/common/notification_service.h" #include "googleurl/src/gurl.h" diff --git a/chrome/browser/debugger/devtools_remote_service.cc b/chrome/browser/debugger/devtools_remote_service.cc index 0d3e776..048a6bf 100644 --- a/chrome/browser/debugger/devtools_remote_service.cc +++ b/chrome/browser/debugger/devtools_remote_service.cc @@ -14,9 +14,9 @@ #include "chrome/browser/debugger/devtools_protocol_handler.h" #include "chrome/browser/debugger/devtools_remote_message.h" #include "chrome/browser/debugger/inspectable_tab_proxy.h" -#include "chrome/common/devtools_messages.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/navigation_entry.h" +#include "content/common/devtools_messages.h" const char DevToolsRemoteServiceCommand::kPing[] = "ping"; const char DevToolsRemoteServiceCommand::kVersion[] = "version"; diff --git a/chrome/browser/debugger/extension_ports_remote_service.cc b/chrome/browser/debugger/extension_ports_remote_service.cc index 9db706c..1cf8155 100644 --- a/chrome/browser/debugger/extension_ports_remote_service.cc +++ b/chrome/browser/debugger/extension_ports_remote_service.cc @@ -20,9 +20,9 @@ #include "chrome/browser/debugger/devtools_remote_message.h" #include "chrome/browser/debugger/inspectable_tab_proxy.h" #include "chrome/browser/profiles/profile_manager.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/extensions/extension_messages.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" namespace { diff --git a/chrome/browser/debugger/inspectable_tab_proxy.cc b/chrome/browser/debugger/inspectable_tab_proxy.cc index 3998143..6f73bd8 100644 --- a/chrome/browser/debugger/inspectable_tab_proxy.cc +++ b/chrome/browser/debugger/inspectable_tab_proxy.cc @@ -12,8 +12,8 @@ #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/devtools_messages.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" DevToolsClientHostImpl::DevToolsClientHostImpl( int32 id, diff --git a/chrome/browser/extensions/extension_debugger_api.cc b/chrome/browser/extensions/extension_debugger_api.cc index c65687a..8a47316 100644 --- a/chrome/browser/extensions/extension_debugger_api.cc +++ b/chrome/browser/extensions/extension_debugger_api.cc @@ -21,10 +21,10 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_error_utils.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" #include "content/common/notification_service.h" namespace keys = extension_debugger_api_constants; diff --git a/chrome/browser/extensions/extension_devtools_bridge.cc b/chrome/browser/extensions/extension_devtools_bridge.cc index 9077bf5..b928025 100644 --- a/chrome/browser/extensions/extension_devtools_bridge.cc +++ b/chrome/browser/extensions/extension_devtools_bridge.cc @@ -16,8 +16,8 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/devtools_messages.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/devtools_messages.h" ExtensionDevToolsBridge::ExtensionDevToolsBridge(int tab_id, Profile* profile) diff --git a/chrome/browser/extensions/extension_devtools_browsertests.cc b/chrome/browser/extensions/extension_devtools_browsertests.cc index e0ccc0f..7ead773 100644 --- a/chrome/browser/extensions/extension_devtools_browsertests.cc +++ b/chrome/browser/extensions/extension_devtools_browsertests.cc @@ -16,12 +16,12 @@ #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/url_constants.h" #include "chrome/test/ui_test_utils.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 "net/base/net_util.h" // Looks for an ExtensionHost whose URL has the given path component (including diff --git a/chrome/browser/ui/views/about_ipc_dialog.cc b/chrome/browser/ui/views/about_ipc_dialog.cc index fd446f3..fbb6e29 100644 --- a/chrome/browser/ui/views/about_ipc_dialog.cc +++ b/chrome/browser/ui/views/about_ipc_dialog.cc @@ -24,8 +24,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/render_messages.h" +#include "content/common/devtools_messages.h" #include "content/common/plugin_messages.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_job.h" diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc index 4782c53..6008f46 100644 --- a/chrome/browser/ui/webui/devtools_ui.cc +++ b/chrome/browser/ui/webui/devtools_ui.cc @@ -8,11 +8,11 @@ #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_thread.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 "grit/devtools_resources_map.h" #include "ui/base/resource/resource_bundle.h" diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 63ff6e78..0037a88 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -44,7 +44,6 @@ 'common/content_settings_helper.cc', 'common/content_settings_helper.h', 'common/content_settings_types.h', - 'common/devtools_messages.h', 'common/external_ipc_fuzzer.h', 'common/external_ipc_fuzzer.cc', 'common/guid.cc', diff --git a/chrome/common/common_message_generator.h b/chrome/common/common_message_generator.h index 5597abd..52b8ec2 100644 --- a/chrome/common/common_message_generator.h +++ b/chrome/common/common_message_generator.h @@ -5,7 +5,6 @@ // Multiply-included file, hence no include guard. #include "chrome/common/autofill_messages.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/extensions/extension_messages.h" #include "chrome/common/icon_messages.h" #include "chrome/common/print_messages.h" diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc index 7f5c6a6..2c27809 100644 --- a/chrome/common/logging_chrome.cc +++ b/chrome/common/logging_chrome.cc @@ -16,8 +16,8 @@ // IPC_MESSAGE_MACROS_LOG_ENABLED doesn't get undefined. #if defined(OS_POSIX) && defined(IPC_MESSAGE_LOG_ENABLED) #define IPC_MESSAGE_MACROS_LOG_ENABLED -#include "chrome/common/devtools_messages.h" #include "chrome/common/render_messages.h" +#include "content/common/devtools_messages.h" #include "content/common/plugin_messages.h" #include "content/common/worker_messages.h" #endif diff --git a/chrome/renderer/devtools_agent.cc b/chrome/renderer/devtools_agent.cc index ba27dba..21e411a 100644 --- a/chrome/renderer/devtools_agent.cc +++ b/chrome/renderer/devtools_agent.cc @@ -9,9 +9,9 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/devtools_messages.h" #include "chrome/renderer/devtools_agent_filter.h" #include "chrome/renderer/devtools_client.h" +#include "content/common/devtools_messages.h" #include "content/common/view_messages.h" #include "content/renderer/render_view.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" diff --git a/chrome/renderer/devtools_agent_filter.cc b/chrome/renderer/devtools_agent_filter.cc index 4300461..330fca3 100644 --- a/chrome/renderer/devtools_agent_filter.cc +++ b/chrome/renderer/devtools_agent_filter.cc @@ -5,9 +5,9 @@ #include "chrome/renderer/devtools_agent_filter.h" #include "base/message_loop.h" -#include "chrome/common/devtools_messages.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/devtools_agent.h" +#include "content/common/devtools_messages.h" #include "content/renderer/plugin_channel_host.h" #include "content/renderer/render_view.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" diff --git a/chrome/renderer/devtools_client.cc b/chrome/renderer/devtools_client.cc index ac6c090..02882b5 100644 --- a/chrome/renderer/devtools_client.cc +++ b/chrome/renderer/devtools_client.cc @@ -8,7 +8,7 @@ #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/devtools_messages.h" +#include "content/common/devtools_messages.h" #include "content/renderer/render_thread.h" #include "content/renderer/render_view.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontend.h" diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h index 21c3e76..10659b8 100644 --- a/content/common/content_message_generator.h +++ b/content/common/content_message_generator.h @@ -15,6 +15,7 @@ #include "content/common/database_messages.h" #include "content/common/desktop_notification_messages.h" #include "content/common/device_orientation_messages.h" +#include "content/common/devtools_messages.h" #include "content/common/dom_storage_messages.h" #include "content/common/drag_messages.h" #include "content/common/file_system_messages.h" diff --git a/chrome/common/devtools_messages.h b/content/common/devtools_messages.h index e3275766..d0178bc 100644 --- a/chrome/common/devtools_messages.h +++ b/content/common/devtools_messages.h @@ -45,12 +45,12 @@ #include "ipc/ipc_message_macros.h" // Singly-included section. -#ifndef CHROME_COMMON_DEVTOOLS_MESSAGES_H_ -#define CHROME_COMMON_DEVTOOLS_MESSAGES_H_ +#ifndef CONTENT_COMMON_DEVTOOLS_MESSAGES_H_ +#define CONTENT_COMMON_DEVTOOLS_MESSAGES_H_ typedef std::map<std::string, std::string> DevToolsRuntimeProperties; -#endif // CHROME_COMMON_DEVTOOLS_MESSAGES_H_ +#endif // CONTENT_COMMON_DEVTOOLS_MESSAGES_H_ #define IPC_MESSAGE_START DevToolsMsgStart @@ -82,6 +82,11 @@ IPC_MESSAGE_CONTROL0(DevToolsAgentMsg_FrontendLoaded) IPC_MESSAGE_CONTROL1(DevToolsAgentMsg_DispatchOnInspectorBackend, std::string /* message */) +// WebKit-level transport for messages from WorkerInspectorController to +// InspectorController. +IPC_MESSAGE_ROUTED1(DevToolsAgentMsg_DispatchMessageFromWorker, + std::string /* message */) + // Send debugger command to the debugger agent. Debugger commands should // be handled on IO thread(while all other devtools messages are handled in // the render thread) to allow executing the commands when v8 is on a @@ -140,3 +145,13 @@ IPC_MESSAGE_ROUTED2(DevToolsHostMsg_SaveAs, IPC_MESSAGE_ROUTED2(DevToolsHostMsg_RuntimePropertyChanged, std::string /* name */, std::string /* value */) + + +//----------------------------------------------------------------------------- +// These are messages sent from the inspected page renderer to the worker +// renderer. + +IPC_MESSAGE_ROUTED0(WorkerDevToolsAgentMsg_Attach) +IPC_MESSAGE_ROUTED0(WorkerDevToolsAgentMsg_Detach) +IPC_MESSAGE_ROUTED1(WorkerDevToolsAgentMsg_DispatchOnInspectorBackend, + std::string /* message */) diff --git a/content/content_common.gypi b/content/content_common.gypi index ea57081..7913d47 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -79,6 +79,7 @@ 'common/debug_flags.h', 'common/desktop_notification_messages.h', 'common/device_orientation_messages.h', + 'common/devtools_messages.h', 'common/dom_storage_common.h', 'common/dom_storage_messages.h', 'common/drag_messages.h', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index b1d25d7..ebc1f99 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -156,6 +156,8 @@ 'renderer/webworker_proxy.h', 'renderer/web_ui_bindings.cc', 'renderer/web_ui_bindings.h', + 'renderer/worker_devtools_agent_proxy.cc', + 'renderer/worker_devtools_agent_proxy.h', ], 'conditions': [ ['p2p_apis==1', { diff --git a/content/content_worker.gypi b/content/content_worker.gypi index 498315f..0e04832 100644 --- a/content/content_worker.gypi +++ b/content/content_worker.gypi @@ -23,6 +23,8 @@ 'worker/webworker_stub.h', 'worker/webworkerclient_proxy.cc', 'worker/webworkerclient_proxy.h', + 'worker/worker_devtools_agent.cc', + 'worker/worker_devtools_agent.h', 'worker/worker_main.cc', 'worker/worker_thread.cc', 'worker/worker_thread.h', diff --git a/content/renderer/websharedworker_proxy.cc b/content/renderer/websharedworker_proxy.cc index 203ec6b..9bd48b4 100644 --- a/content/renderer/websharedworker_proxy.cc +++ b/content/renderer/websharedworker_proxy.cc @@ -18,7 +18,8 @@ WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread, document_id, exists ? route_id : MSG_ROUTING_NONE, render_view_route_id, - 0), + 0, + NULL), pending_route_id_(route_id), connect_listener_(NULL) { } diff --git a/content/renderer/webworker_base.cc b/content/renderer/webworker_base.cc index c8e1304..c35ad64 100644 --- a/content/renderer/webworker_base.cc +++ b/content/renderer/webworker_base.cc @@ -8,6 +8,7 @@ #include "content/common/view_messages.h" #include "content/common/webmessageportchannel_impl.h" #include "content/common/worker_messages.h" +#include "content/renderer/worker_devtools_agent_proxy.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" @@ -22,10 +23,12 @@ WebWorkerBase::WebWorkerBase( unsigned long long document_id, int route_id, int render_view_route_id, - int parent_appcache_host_id) + int parent_appcache_host_id, + WorkerDevToolsAgentProxy* devtools_proxy) : route_id_(route_id), render_view_route_id_(render_view_route_id), child_thread_(child_thread), + devtools_proxy_(devtools_proxy), document_id_(document_id), parent_appcache_host_id_(parent_appcache_host_id) { if (route_id_ != MSG_ROUTING_NONE) @@ -50,6 +53,9 @@ void WebWorkerBase::Disconnect() { child_thread_->RemoveRoute(route_id_); route_id_ = MSG_ROUTING_NONE; + + if (devtools_proxy_.get()) + devtools_proxy_->SetRouteId(MSG_ROUTING_NONE); } void WebWorkerBase::CreateWorkerContext(const GURL& script_url, @@ -77,6 +83,9 @@ void WebWorkerBase::CreateWorkerContext(const GURL& script_url, child_thread_->AddRoute(route_id_, this); + if (devtools_proxy_.get()) + devtools_proxy_->SetRouteId(route_id_); + // We make sure that the start message is the first, since postMessage or // connect might have already been called. queued_messages_.insert(queued_messages_.begin(), diff --git a/content/renderer/webworker_base.h b/content/renderer/webworker_base.h index 7ea07b3..76f5868 100644 --- a/content/renderer/webworker_base.h +++ b/content/renderer/webworker_base.h @@ -6,13 +6,16 @@ #define CONTENT_RENDERER_WEBWORKER_BASE_H_ #pragma once +#include <string> #include <vector> #include "base/basictypes.h" +#include "base/scoped_ptr.h" #include "ipc/ipc_channel.h" class ChildThread; class GURL; +class WorkerDevToolsAgentProxy; // WebWorkerBase is the common base class used by both WebWorkerProxy and // WebSharedWorker. It contains logic to support starting up both dedicated @@ -63,7 +66,8 @@ class WebWorkerBase : public IPC::Channel::Listener { unsigned long long document_id, int route_id, int render_view_route_id, - int parent_appcache_host_id); + int parent_appcache_host_id, + WorkerDevToolsAgentProxy*); // Routing id associated with this worker - used to receive messages from the // worker, and also to route messages to the worker (WorkerService contains @@ -76,6 +80,8 @@ class WebWorkerBase : public IPC::Channel::Listener { ChildThread* child_thread_; + scoped_ptr<WorkerDevToolsAgentProxy> devtools_proxy_; + private: void CreateWorkerContext(const GURL& script_url, bool is_shared, diff --git a/content/renderer/webworker_proxy.cc b/content/renderer/webworker_proxy.cc index 9817f0f..1457be7 100644 --- a/content/renderer/webworker_proxy.cc +++ b/content/renderer/webworker_proxy.cc @@ -5,9 +5,11 @@ #include "content/renderer/webworker_proxy.h" #include "content/common/child_thread.h" +#include "content/common/content_client.h" #include "content/common/view_messages.h" #include "content/common/webmessageportchannel_impl.h" #include "content/common/worker_messages.h" +#include "content/renderer/worker_devtools_agent_proxy.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" @@ -23,8 +25,13 @@ WebWorkerProxy::WebWorkerProxy( ChildThread* child_thread, int render_view_route_id, int parent_appcache_host_id) - : WebWorkerBase(child_thread, 0, MSG_ROUTING_NONE, render_view_route_id, - parent_appcache_host_id), + : WebWorkerBase( + child_thread, + 0, + MSG_ROUTING_NONE, + render_view_route_id, + parent_appcache_host_id, + new WorkerDevToolsAgentProxy(this, MSG_ROUTING_NONE, client)), client_(client) { // TODO(atwilson): Change to pass in a real document_id when we support nested // workers. @@ -84,10 +91,25 @@ void WebWorkerProxy::workerObjectDestroyed() { void WebWorkerProxy::clientDestroyed() { } +void WebWorkerProxy::attachDevTools() { + devtools_proxy_->AttachDevTools(); +} + +void WebWorkerProxy::detachDevTools() { + devtools_proxy_->DetachDevTools(); +} + +void WebWorkerProxy::dispatchDevToolsMessage(const WebString& message) { + devtools_proxy_->SendDevToolsMessage(message.utf8()); +} + bool WebWorkerProxy::OnMessageReceived(const IPC::Message& message) { if (!client_) return false; + if (devtools_proxy_->OnMessageReceived(message)) + return true; + bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebWorkerProxy, message) IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) diff --git a/content/renderer/webworker_proxy.h b/content/renderer/webworker_proxy.h index 80014ac..fea3811 100644 --- a/content/renderer/webworker_proxy.h +++ b/content/renderer/webworker_proxy.h @@ -42,6 +42,10 @@ class WebWorkerProxy : public WebKit::WebWorker, private WebWorkerBase { virtual void workerObjectDestroyed(); virtual void clientDestroyed(); + virtual void attachDevTools(); + virtual void detachDevTools(); + virtual void dispatchDevToolsMessage(const WebKit::WebString&); + // IPC::Channel::Listener implementation. virtual bool OnMessageReceived(const IPC::Message& message); diff --git a/content/renderer/worker_devtools_agent_proxy.cc b/content/renderer/worker_devtools_agent_proxy.cc new file mode 100644 index 0000000..ba7fe2a --- /dev/null +++ b/content/renderer/worker_devtools_agent_proxy.cc @@ -0,0 +1,67 @@ +// 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/renderer/worker_devtools_agent_proxy.h" + +#include "content/common/devtools_messages.h" +#include "content/renderer/webworker_base.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" + +using WebKit::WebString; +using WebKit::WebWorkerClient; + +WorkerDevToolsAgentProxy::WorkerDevToolsAgentProxy(WebWorkerBase* webworker, + int route_id, + WebWorkerClient* client) + : route_id_(route_id), + webworker_(webworker), + webworker_client_(client) { +} + +WorkerDevToolsAgentProxy::~WorkerDevToolsAgentProxy() { +} + +void WorkerDevToolsAgentProxy::WorkerProxyDestroyed() { + delete this; +} + +void WorkerDevToolsAgentProxy::SetRouteId(int route_id) { + route_id_ = route_id; +} + +// Called on the Renderer thread. +bool WorkerDevToolsAgentProxy::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentProxy, message) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchMessageFromWorker, + OnDispatchMessageFromWorker) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void WorkerDevToolsAgentProxy::AttachDevTools() { + Send(new WorkerDevToolsAgentMsg_Attach(route_id_)); +} + +void WorkerDevToolsAgentProxy::DetachDevTools() { + Send(new WorkerDevToolsAgentMsg_Detach(route_id_)); +} + +void WorkerDevToolsAgentProxy::SendDevToolsMessage( + const std::string& message) { + Send(new WorkerDevToolsAgentMsg_DispatchOnInspectorBackend(route_id_, + message)); +} + +void WorkerDevToolsAgentProxy::OnDispatchMessageFromWorker( + const std::string& message) { + webworker_client_->dispatchDevToolsMessage(WebString::fromUTF8(message)); +} + +void WorkerDevToolsAgentProxy::Send(IPC::Message* message) { + webworker_->Send(message); +} diff --git a/content/renderer/worker_devtools_agent_proxy.h b/content/renderer/worker_devtools_agent_proxy.h new file mode 100644 index 0000000..99ae1f2b --- /dev/null +++ b/content/renderer/worker_devtools_agent_proxy.h @@ -0,0 +1,50 @@ +// 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_RENDERER_WORKER_DEVTOOLS_AGENT_PROXY_H_ +#define CONTENT_RENDERER_WORKER_DEVTOOLS_AGENT_PROXY_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" + +namespace IPC { +class Message; +} + +namespace WebKit { +class WebWorkerClient; +} + +class WebWorkerBase; + +class WorkerDevToolsAgentProxy { + public: + WorkerDevToolsAgentProxy(WebWorkerBase*, + int route_id, + WebKit::WebWorkerClient*); + ~WorkerDevToolsAgentProxy(); + + void WorkerProxyDestroyed(); + void SetRouteId(int route_id); + bool OnMessageReceived(const IPC::Message& message); + + void AttachDevTools(); + void DetachDevTools(); + void SendDevToolsMessage(const std::string&); + + private: + void OnDispatchMessageFromWorker(const std::string& message); + + void Send(IPC::Message* message); + + int route_id_; + WebWorkerBase* webworker_; + WebKit::WebWorkerClient* webworker_client_; + + DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsAgentProxy); +}; + +#endif // CONTENT_RENDERER_WORKER_DEVTOOLS_AGENT_PROXY_H_ diff --git a/content/worker/webworker_stub.cc b/content/worker/webworker_stub.cc index 1cf7fdb..b7ecd13 100644 --- a/content/worker/webworker_stub.cc +++ b/content/worker/webworker_stub.cc @@ -6,9 +6,11 @@ #include "base/command_line.h" #include "content/common/child_thread.h" +#include "content/common/content_client.h" #include "content/common/file_system/file_system_dispatcher.h" #include "content/common/webmessageportchannel_impl.h" #include "content/common/worker_messages.h" +#include "content/worker/worker_devtools_agent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" @@ -19,7 +21,10 @@ WebWorkerStub::WebWorkerStub(const GURL& url, int route_id, const WorkerAppCacheInitInfo& appcache_init_info) : WebWorkerStubBase(route_id, appcache_init_info), ALLOW_THIS_IN_INITIALIZER_LIST(impl_(WebWorker::create(client()))), - url_(url) { + url_(url), + ALLOW_THIS_IN_INITIALIZER_LIST(worker_devtools_agent_( + new WorkerDevToolsAgent(route_id, impl_))) { + client()->set_devtools_agent(worker_devtools_agent_.get()); } WebWorkerStub::~WebWorkerStub() { @@ -38,6 +43,9 @@ bool WebWorkerStub::OnMessageReceived(const IPC::Message& message) { if (!impl_) return false; + if (worker_devtools_agent_->OnMessageReceived(message)) + return true; + bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebWorkerStub, message) IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, impl_, diff --git a/content/worker/webworker_stub.h b/content/worker/webworker_stub.h index ff93cdd..06b4b10 100644 --- a/content/worker/webworker_stub.h +++ b/content/worker/webworker_stub.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -6,6 +6,7 @@ #define CONTENT_WORKER_WEBWORKER_STUB_H_ #pragma once +#include "base/scoped_ptr.h" #include "content/worker/webworker_stub_base.h" #include "content/worker/webworkerclient_proxy.h" #include "googleurl/src/gurl.h" @@ -14,6 +15,8 @@ namespace WebKit { class WebWorker; } +class WorkerDevToolsAgent; + // This class creates a WebWorker, and translates incoming IPCs to the // appropriate WebWorker APIs. class WebWorkerStub : public WebWorkerStubBase { @@ -37,6 +40,7 @@ class WebWorkerStub : public WebWorkerStubBase { WebKit::WebWorker* impl_; GURL url_; + scoped_ptr<WorkerDevToolsAgent> worker_devtools_agent_; DISALLOW_COPY_AND_ASSIGN(WebWorkerStub); }; diff --git a/content/worker/webworkerclient_proxy.cc b/content/worker/webworkerclient_proxy.cc index f665de5..dde6be2 100644 --- a/content/worker/webworkerclient_proxy.cc +++ b/content/worker/webworkerclient_proxy.cc @@ -16,6 +16,7 @@ // don't support nested workers anyways. //#include "content/renderer/webworker_proxy.h" #include "content/worker/webworker_stub_base.h" +#include "content/worker/worker_devtools_agent.h" #include "content/worker/worker_thread.h" #include "content/worker/worker_webapplicationcachehost_impl.h" #include "ipc/ipc_logging.h" @@ -43,7 +44,8 @@ WebWorkerClientProxy::WebWorkerClientProxy(int route_id, : route_id_(route_id), appcache_host_id_(0), stub_(stub), - ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)), + devtools_agent_(NULL) { } WebWorkerClientProxy::~WebWorkerClientProxy() { @@ -173,6 +175,11 @@ void WebWorkerClientProxy::openFileSystem( size, create, new WebFileSystemCallbackDispatcher(callbacks)); } +void WebWorkerClientProxy::dispatchDevToolsMessage(const WebString& message) { + if (devtools_agent_) + devtools_agent_->SendDevToolsMessage(message); +} + bool WebWorkerClientProxy::Send(IPC::Message* message) { return WorkerThread::current()->Send(message); } diff --git a/content/worker/webworkerclient_proxy.h b/content/worker/webworkerclient_proxy.h index 66268a2..31c0340 100644 --- a/content/worker/webworkerclient_proxy.h +++ b/content/worker/webworkerclient_proxy.h @@ -20,6 +20,7 @@ class WebWorker; } class WebWorkerStubBase; +class WorkerDevToolsAgent; // This class receives IPCs from the renderer and calls the WebCore::Worker // implementation (after the data types have been converted by glue code). It @@ -78,9 +79,14 @@ class WebWorkerClientProxy : public WebKit::WebWorkerClient { long long size, bool create, WebKit::WebFileSystemCallbacks* callbacks); + virtual void dispatchDevToolsMessage(const WebKit::WebString&); void EnsureWorkerContextTerminates(); + void set_devtools_agent(WorkerDevToolsAgent* devtools_agent) { + devtools_agent_ = devtools_agent; + } + private: bool Send(IPC::Message* message); @@ -88,6 +94,7 @@ class WebWorkerClientProxy : public WebKit::WebWorkerClient { int appcache_host_id_; WebWorkerStubBase* stub_; ScopedRunnableMethodFactory<WebWorkerClientProxy> kill_process_factory_; + WorkerDevToolsAgent* devtools_agent_; DISALLOW_COPY_AND_ASSIGN(WebWorkerClientProxy); }; diff --git a/content/worker/worker_devtools_agent.cc b/content/worker/worker_devtools_agent.cc new file mode 100644 index 0000000..af00871 --- /dev/null +++ b/content/worker/worker_devtools_agent.cc @@ -0,0 +1,57 @@ +// 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/worker/worker_devtools_agent.h" + +#include "content/common/devtools_messages.h" +#include "content/worker/worker_thread.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" + +using WebKit::WebString; +using WebKit::WebWorker; + +WorkerDevToolsAgent::WorkerDevToolsAgent(int route_id, WebWorker* webworker) + : route_id_(route_id), + webworker_(webworker) { +} + +WorkerDevToolsAgent::~WorkerDevToolsAgent() { +} + +// Called on the Worker thread. +bool WorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgent, message) + IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Attach, OnAttach) + IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Detach, OnDetach) + IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_DispatchOnInspectorBackend, + OnDispatchOnInspectorBackend) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void WorkerDevToolsAgent::OnAttach() { + webworker_->attachDevTools(); +} + +void WorkerDevToolsAgent::OnDetach() { + webworker_->detachDevTools(); +} + +void WorkerDevToolsAgent::OnDispatchOnInspectorBackend( + const std::string& message) { + webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message)); +} + +bool WorkerDevToolsAgent::Send(IPC::Message* message) { + return WorkerThread::current()->Send(message); +} + +void WorkerDevToolsAgent::SendDevToolsMessage(const WebString& message) { + Send(new DevToolsAgentMsg_DispatchMessageFromWorker(route_id_, + message.utf8())); +} diff --git a/content/worker/worker_devtools_agent.h b/content/worker/worker_devtools_agent.h new file mode 100644 index 0000000..64dc3c8 --- /dev/null +++ b/content/worker/worker_devtools_agent.h @@ -0,0 +1,44 @@ +// 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_WORKER_WORKER_DEVTOOLS_AGENT_H_ +#define CONTENT_WORKER_WORKER_DEVTOOLS_AGENT_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" + +namespace IPC { +class Message; +} + +namespace WebKit { +class WebString; +class WebWorker; +} + +class WorkerDevToolsAgent { + public: + WorkerDevToolsAgent(int route_id, WebKit::WebWorker*); + ~WorkerDevToolsAgent(); + + bool OnMessageReceived(const IPC::Message& message); + + void SendDevToolsMessage(const WebKit::WebString&); + + private: + void OnAttach(); + void OnDetach(); + void OnDispatchOnInspectorBackend(const std::string& message); + + bool Send(IPC::Message* message); + + int route_id_; + WebKit::WebWorker* webworker_; + + DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsAgent); +}; + +#endif // CONTENT_WORKER_WORKER_DEVTOOLS_AGENT_H_ |