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 /content/worker | |
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
Diffstat (limited to 'content/worker')
-rw-r--r-- | content/worker/webworker_stub.cc | 10 | ||||
-rw-r--r-- | content/worker/webworker_stub.h | 6 | ||||
-rw-r--r-- | content/worker/webworkerclient_proxy.cc | 9 | ||||
-rw-r--r-- | content/worker/webworkerclient_proxy.h | 7 | ||||
-rw-r--r-- | content/worker/worker_devtools_agent.cc | 57 | ||||
-rw-r--r-- | content/worker/worker_devtools_agent.h | 44 |
6 files changed, 130 insertions, 3 deletions
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_ |