diff options
author | horo@chromium.org <horo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-09 12:23:43 +0000 |
---|---|---|
committer | horo@chromium.org <horo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-09 12:23:43 +0000 |
commit | 93caf4510cc8402ab10f379d40d7f6999e76e6d9 (patch) | |
tree | 1e2aa23ecd802e6ced9e7119a02196b58ee67d4a /content/worker | |
parent | 11798005bc60ab5d1ad758bb7dcc671010243b2a (diff) | |
download | chromium_src-93caf4510cc8402ab10f379d40d7f6999e76e6d9.zip chromium_src-93caf4510cc8402ab10f379d40d7f6999e76e6d9.tar.gz chromium_src-93caf4510cc8402ab10f379d40d7f6999e76e6d9.tar.bz2 |
Move the worker script loading code to the worker process (phase:2/5)
- Add content_security_policy and security_policy_type to ViewHostMsg_CreateWorker_Params and WorkerProcessMsg_CreateWorker_Params.
It is needed because WorkerMsg_StartWorkerContext will be removed.
- Implement workerScriptLoaded, workerScriptLoadFailed and selectAppChacheID.
- Queue WebMessagePortChannel in WebSharedWorkerStub::OnConnect
When we will add the script loading code in WebSharedWorkerImpl, the worker process can't respond to the connection request which is sent soon after the SharedWorker is created.
So we have to create WebMessagePortChannelImpl in WebSharedWorkerStub::OnConnect.
This is step 2 of moving the worker script loading code from the renderer process to the worker process.
See: http://crbug.com/329786
BUG=329786
Review URL: https://codereview.chromium.org/115713004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243864 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/worker')
-rw-r--r-- | content/worker/websharedworker_stub.cc | 42 | ||||
-rw-r--r-- | content/worker/websharedworker_stub.h | 17 | ||||
-rw-r--r-- | content/worker/websharedworkerclient_proxy.cc | 30 | ||||
-rw-r--r-- | content/worker/websharedworkerclient_proxy.h | 5 | ||||
-rw-r--r-- | content/worker/worker_thread.cc | 8 |
5 files changed, 77 insertions, 25 deletions
diff --git a/content/worker/websharedworker_stub.cc b/content/worker/websharedworker_stub.cc index 4f6dd93..5f40bab 100644 --- a/content/worker/websharedworker_stub.cc +++ b/content/worker/websharedworker_stub.cc @@ -19,14 +19,18 @@ namespace content { WebSharedWorkerStub::WebSharedWorkerStub( + const GURL& url, const base::string16& name, + const base::string16& content_security_policy, + blink::WebContentSecurityPolicyType security_policy_type, int route_id, const WorkerAppCacheInitInfo& appcache_init_info) : route_id_(route_id), appcache_init_info_(appcache_init_info), client_(route_id, this), name_(name), - started_(false) { + started_(false), + worker_script_loaded_(false) { WorkerThread* worker_thread = WorkerThread::current(); DCHECK(worker_thread); @@ -94,30 +98,21 @@ void WebSharedWorkerStub::OnStartWorkerContext( content_security_policy, policy_type, 0); started_ = true; url_ = url; - - // Process any pending connections. - for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); - iter != pending_connects_.end(); - ++iter) { - OnConnect(iter->first, iter->second); - } - pending_connects_.clear(); } void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) { - if (started_) { - blink::WebMessagePortChannel* channel = - new WebMessagePortChannelImpl(routing_id, - sent_message_port_id, - base::MessageLoopProxy::current().get()); + blink::WebMessagePortChannel* channel = + new WebMessagePortChannelImpl(routing_id, + sent_message_port_id, + base::MessageLoopProxy::current().get()); + if (started_ && worker_script_loaded_) { impl_->connect(channel); } else { // If two documents try to load a SharedWorker at the same time, the // WorkerMsg_Connect for one of the documents can come in before the // worker is started. Just queue up the connect and deliver it once the // worker starts. - PendingConnectInfo pending_connect(sent_message_port_id, routing_id); - pending_connects_.push_back(pending_connect); + pending_channels_.push_back(channel); } } @@ -129,4 +124,19 @@ void WebSharedWorkerStub::OnTerminateWorkerContext() { started_ = false; } +void WebSharedWorkerStub::WorkerScriptLoaded() { + worker_script_loaded_ = true; + // Process any pending connections. + for (PendingChannelList::const_iterator iter = pending_channels_.begin(); + iter != pending_channels_.end(); + ++iter) { + impl_->connect(*iter); + } + pending_channels_.clear(); +} + +void WebSharedWorkerStub::WorkerScriptLoadFailed() { + // FIXME(horo): Implement this. +} + } // namespace content diff --git a/content/worker/websharedworker_stub.h b/content/worker/websharedworker_stub.h index 66d11ea..bde7cba 100644 --- a/content/worker/websharedworker_stub.h +++ b/content/worker/websharedworker_stub.h @@ -14,18 +14,24 @@ #include "url/gurl.h" namespace blink { +class WebMessagePortChannel; class WebSharedWorker; } namespace content { class SharedWorkerDevToolsAgent; +class WebMessagePortChannelImpl; // This class creates a WebSharedWorker, and translates incoming IPCs to the // appropriate WebSharedWorker APIs. class WebSharedWorkerStub : public IPC::Listener { public: - WebSharedWorkerStub(const base::string16& name, int route_id, + WebSharedWorkerStub(const GURL& url, + const base::string16& name, + const base::string16& content_security_policy, + blink::WebContentSecurityPolicyType security_policy_type, + int route_id, const WorkerAppCacheInitInfo& appcache_init_info); // IPC::Listener implementation. @@ -35,6 +41,9 @@ class WebSharedWorkerStub : public IPC::Listener { // Invoked when the WebSharedWorkerClientProxy is shutting down. void Shutdown(); + void WorkerScriptLoaded(); + void WorkerScriptLoadFailed(); + // Called after terminating the worker context to make sure that the worker // actually terminates (is not stuck in an infinite loop). void EnsureWorkerContextTerminates(); @@ -74,11 +83,11 @@ class WebSharedWorkerStub : public IPC::Listener { base::string16 name_; bool started_; GURL url_; + bool worker_script_loaded_; scoped_ptr<SharedWorkerDevToolsAgent> worker_devtools_agent_; - typedef std::pair<int, int> PendingConnectInfo; - typedef std::vector<PendingConnectInfo> PendingConnectInfoList; - PendingConnectInfoList pending_connects_; + typedef std::vector<blink::WebMessagePortChannel*> PendingChannelList; + PendingChannelList pending_channels_; DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerStub); }; diff --git a/content/worker/websharedworkerclient_proxy.cc b/content/worker/websharedworkerclient_proxy.cc index 8175b00..538657d 100644 --- a/content/worker/websharedworkerclient_proxy.cc +++ b/content/worker/websharedworkerclient_proxy.cc @@ -42,7 +42,8 @@ WebSharedWorkerClientProxy::WebSharedWorkerClientProxy( appcache_host_id_(0), stub_(stub), weak_factory_(this), - devtools_agent_(NULL) { + devtools_agent_(NULL), + app_cache_host_(NULL) { } WebSharedWorkerClientProxy::~WebSharedWorkerClientProxy() { @@ -59,6 +60,26 @@ void WebSharedWorkerClientProxy::workerContextDestroyed() { stub_->Shutdown(); } +void WebSharedWorkerClientProxy::workerScriptLoaded() { + if (stub_) + stub_->WorkerScriptLoaded(); +} + +void WebSharedWorkerClientProxy::workerScriptLoadFailed() { + if (stub_) + stub_->WorkerScriptLoadFailed(); +} + +void WebSharedWorkerClientProxy::selectAppCacheID(long long app_cache_id) { + if (app_cache_host_) { + // app_cache_host_ could become stale as it's owned by blink's + // DocumentLoader. This method is assumed to be called while it's valid. + app_cache_host_->backend()->SelectCacheForSharedWorker( + app_cache_host_->host_id(), + app_cache_id); + } +} + blink::WebNotificationPresenter* WebSharedWorkerClientProxy::notificationPresenter() { // TODO(johnnyg): Notifications are not yet hooked up to workers. @@ -69,13 +90,14 @@ WebSharedWorkerClientProxy::notificationPresenter() { WebApplicationCacheHost* WebSharedWorkerClientProxy::createApplicationCacheHost( blink::WebApplicationCacheHostClient* client) { - WorkerWebApplicationCacheHostImpl* host = + DCHECK(!app_cache_host_); + app_cache_host_ = new WorkerWebApplicationCacheHostImpl(stub_->appcache_init_info(), client); // Remember the id of the instance we create so we have access to that // value when creating nested dedicated workers in createWorker. - appcache_host_id_ = host->host_id(); - return host; + appcache_host_id_ = app_cache_host_->host_id(); + return app_cache_host_; } blink::WebWorkerPermissionClientProxy* diff --git a/content/worker/websharedworkerclient_proxy.h b/content/worker/websharedworkerclient_proxy.h index a573368..beb3086 100644 --- a/content/worker/websharedworkerclient_proxy.h +++ b/content/worker/websharedworkerclient_proxy.h @@ -21,6 +21,7 @@ namespace content { class SharedWorkerDevToolsAgent; class WebSharedWorkerStub; +class WorkerWebApplicationCacheHostImpl; // This class receives IPCs from the renderer and calls the WebCore::Worker // implementation (after the data types have been converted by glue code). It @@ -35,6 +36,9 @@ class WebSharedWorkerClientProxy : public blink::WebSharedWorkerClient { // WebSharedWorkerClient implementation. virtual void workerContextClosed(); virtual void workerContextDestroyed(); + virtual void workerScriptLoaded(); + virtual void workerScriptLoadFailed(); + virtual void selectAppCacheID(long long app_cache_id); virtual blink::WebNotificationPresenter* notificationPresenter(); @@ -61,6 +65,7 @@ class WebSharedWorkerClientProxy : public blink::WebSharedWorkerClient { WebSharedWorkerStub* stub_; base::WeakPtrFactory<WebSharedWorkerClientProxy> weak_factory_; SharedWorkerDevToolsAgent* devtools_agent_; + WorkerWebApplicationCacheHostImpl* app_cache_host_; DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerClientProxy); }; diff --git a/content/worker/worker_thread.cc b/content/worker/worker_thread.cc index 54764d0..456457c 100644 --- a/content/worker/worker_thread.cc +++ b/content/worker/worker_thread.cc @@ -121,7 +121,13 @@ void WorkerThread::OnCreateWorker( params.shared_worker_appcache_id); // WebSharedWorkerStub own themselves. - new WebSharedWorkerStub(params.name, params.route_id, appcache_init_info); + new WebSharedWorkerStub( + params.url, + params.name, + params.content_security_policy, + params.security_policy_type, + params.route_id, + appcache_init_info); } // The browser process is likely dead. Terminate all workers. |