diff options
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/render_view.cc | 18 | ||||
-rw-r--r-- | chrome/renderer/websharedworker_proxy.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/websharedworker_proxy.h | 5 | ||||
-rw-r--r-- | chrome/renderer/websharedworkerrepository_impl.cc | 21 | ||||
-rw-r--r-- | chrome/renderer/websharedworkerrepository_impl.h | 10 | ||||
-rw-r--r-- | chrome/renderer/webworker_base.h | 2 | ||||
-rw-r--r-- | chrome/renderer/webworker_proxy.cc | 11 | ||||
-rw-r--r-- | chrome/renderer/webworker_proxy.h | 4 |
8 files changed, 52 insertions, 29 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 006ae43..aa8d86d 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -1805,13 +1805,19 @@ WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { WebSharedWorker* RenderView::createSharedWorker( WebFrame* frame, const WebURL& url, const WebString& name, - unsigned long long documentId) { + unsigned long long document_id) { - // TODO(atwilson): Call to the browser process to check if there's an existing - // worker (passing MSG_ROUTING_NONE for now, to indicate no existing worker). - int worker_route_id = MSG_ROUTING_NONE; - return new WebSharedWorkerProxy( - RenderThread::current(), worker_route_id, routing_id_); + int route_id = MSG_ROUTING_NONE; + bool url_mismatch = false; + Send(new ViewHostMsg_LookupSharedWorker( + url, name, document_id, &route_id, &url_mismatch)); + if (url_mismatch) { + return NULL; + } else { + return new WebSharedWorkerProxy(RenderThread::current(), + route_id, + routing_id_); + } } WebMediaPlayer* RenderView::createMediaPlayer( diff --git a/chrome/renderer/websharedworker_proxy.cc b/chrome/renderer/websharedworker_proxy.cc index 7ad1f61..1d5425f 100644 --- a/chrome/renderer/websharedworker_proxy.cc +++ b/chrome/renderer/websharedworker_proxy.cc @@ -13,7 +13,7 @@ WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread, int route_id, int render_view_route_id) : WebWorkerBase(child_thread, route_id, render_view_route_id), - m_connectListener(NULL) { + connect_listener_(NULL) { } bool WebSharedWorkerProxy::isStarted() { @@ -25,6 +25,7 @@ void WebSharedWorkerProxy::startWorkerContext( const WebKit::WebString& name, const WebKit::WebString& user_agent, const WebKit::WebString& source_code) { + DCHECK(!isStarted()); CreateWorkerContext(script_url, true, name, user_agent, source_code); } @@ -49,7 +50,7 @@ void WebSharedWorkerProxy::connect(WebKit::WebMessagePortChannel* channel, Send(new WorkerMsg_Connect(route_id_, message_port_id, MSG_ROUTING_NONE)); if (HasQueuedMessages()) { - m_connectListener = listener; + connect_listener_ = listener; } else { listener->connected(); // The listener may free this object, so do not access the object after @@ -70,8 +71,7 @@ void WebSharedWorkerProxy::OnWorkerCreated() { // Inform any listener that the pending connect event has been sent // (this can result in this object being freed). - if (m_connectListener) { - m_connectListener->connected(); + if (connect_listener_) { + connect_listener_->connected(); } } - diff --git a/chrome/renderer/websharedworker_proxy.h b/chrome/renderer/websharedworker_proxy.h index 68dab47..c3143db 100644 --- a/chrome/renderer/websharedworker_proxy.h +++ b/chrome/renderer/websharedworker_proxy.h @@ -20,6 +20,7 @@ class ChildThread; class WebSharedWorkerProxy : public WebKit::WebSharedWorker, private WebWorkerBase { public: + // If the worker not loaded yet, route_id == MSG_ROUTING_NONE WebSharedWorkerProxy(ChildThread* child_thread, int route_id, int render_view_route_id); @@ -35,13 +36,13 @@ class WebSharedWorkerProxy : public WebKit::WebSharedWorker, virtual void terminateWorkerContext(); virtual void clientDestroyed(); - // IPC::Channel::Listener proxyementation. + // IPC::Channel::Listener implementation. void OnMessageReceived(const IPC::Message& message); private: void OnWorkerCreated(); - ConnectListener* m_connectListener; + ConnectListener* connect_listener_; DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); }; diff --git a/chrome/renderer/websharedworkerrepository_impl.cc b/chrome/renderer/websharedworkerrepository_impl.cc index 24664b7..99f2a3b 100644 --- a/chrome/renderer/websharedworkerrepository_impl.cc +++ b/chrome/renderer/websharedworkerrepository_impl.cc @@ -4,21 +4,24 @@ #include "chrome/renderer/websharedworkerrepository_impl.h" +#include "chrome/common/render_messages.h" +#include "chrome/renderer/render_thread.h" #include "chrome/renderer/websharedworker_proxy.h" void WebSharedWorkerRepositoryImpl::addSharedWorker( WebKit::WebSharedWorker* worker, DocumentID document) { - // TODO(atwilson): Track shared worker creation here. + shared_worker_parents_.insert(document); } -void WebSharedWorkerRepositoryImpl::documentDetached( - DocumentID document) { - // TODO(atwilson): Update this to call to WorkerService to shutdown any - // associated SharedWorkers. +void WebSharedWorkerRepositoryImpl::documentDetached(DocumentID document) { + DocumentSet::iterator iter = shared_worker_parents_.find(document); + if (iter != shared_worker_parents_.end()) { + // Notify the browser process that the document has shut down. + ChildThread::current()->Send(new ViewHostMsg_DocumentDetached(document)); + shared_worker_parents_.erase(iter); + } } -bool WebSharedWorkerRepositoryImpl::hasSharedWorkers( - DocumentID document) { - // TODO(atwilson): Update this when we track shared worker creation. - return false; +bool WebSharedWorkerRepositoryImpl::hasSharedWorkers(DocumentID document) { + return shared_worker_parents_.find(document) != shared_worker_parents_.end(); } diff --git a/chrome/renderer/websharedworkerrepository_impl.h b/chrome/renderer/websharedworkerrepository_impl.h index d8cec99..5806485 100644 --- a/chrome/renderer/websharedworkerrepository_impl.h +++ b/chrome/renderer/websharedworkerrepository_impl.h @@ -7,14 +7,24 @@ #include "third_party/WebKit/WebKit/chromium/public/WebSharedWorkerRepository.h" +#include "base/hash_tables.h" + namespace WebKit { class WebSharedWorker; } class WebSharedWorkerRepositoryImpl : public WebKit::WebSharedWorkerRepository { + public: virtual void addSharedWorker(WebKit::WebSharedWorker*, DocumentID document); virtual void documentDetached(DocumentID document); + + // Returns true if the document has created a SharedWorker (used by the + // WebKit code to determine if the document can be suspended). virtual bool hasSharedWorkers(DocumentID document); + private: + // The set of documents that have created a SharedWorker. + typedef base::hash_set<DocumentID> DocumentSet; + DocumentSet shared_worker_parents_; }; #endif // CHROME_RENDERER_WEB_SHARED_WORKER_REPOSITORY_IMPL_H_ diff --git a/chrome/renderer/webworker_base.h b/chrome/renderer/webworker_base.h index 0693863..fe5becc 100644 --- a/chrome/renderer/webworker_base.h +++ b/chrome/renderer/webworker_base.h @@ -36,7 +36,7 @@ class WebWorkerBase : public IPC::Channel::Listener { bool IsStarted(); // Disconnects the worker (stops listening for incoming messages). - virtual void Disconnect(); + void Disconnect(); // Sends a message to the worker thread (forwarded via the RenderViewHost). // If WorkerStarted() has not yet been called, message is queued. diff --git a/chrome/renderer/webworker_proxy.cc b/chrome/renderer/webworker_proxy.cc index a263565..fdcc9f1 100644 --- a/chrome/renderer/webworker_proxy.cc +++ b/chrome/renderer/webworker_proxy.cc @@ -26,16 +26,18 @@ WebWorkerProxy::WebWorkerProxy( client_(client) { } -void WebWorkerProxy::Disconnect() { +WebWorkerProxy::~WebWorkerProxy() { + // If we're midway through starting a worker, cancel it. + CancelCreation(); +} + +void WebWorkerProxy::CancelCreation() { if (route_id_ == MSG_ROUTING_NONE) return; // Tell the browser to not start our queued worker. if (!IsStarted()) child_thread_->Send(new ViewHostMsg_CancelCreateDedicatedWorker(route_id_)); - - // Call our superclass to shutdown the routing - WebWorkerBase::Disconnect(); } void WebWorkerProxy::startWorkerContext( @@ -48,6 +50,7 @@ void WebWorkerProxy::startWorkerContext( void WebWorkerProxy::terminateWorkerContext() { if (route_id_ != MSG_ROUTING_NONE) { Send(new WorkerMsg_TerminateWorkerContext(route_id_)); + CancelCreation(); Disconnect(); } } diff --git a/chrome/renderer/webworker_proxy.h b/chrome/renderer/webworker_proxy.h index fb2db3ed..112b561 100644 --- a/chrome/renderer/webworker_proxy.h +++ b/chrome/renderer/webworker_proxy.h @@ -27,6 +27,7 @@ class WebWorkerProxy : public WebKit::WebWorker, private WebWorkerBase { WebWorkerProxy(WebKit::WebWorkerClient* client, ChildThread* child_thread, int render_view_route_id); + ~WebWorkerProxy(); // WebWorker implementation. virtual void startWorkerContext(const WebKit::WebURL& script_url, @@ -43,8 +44,7 @@ class WebWorkerProxy : public WebKit::WebWorker, private WebWorkerBase { void OnMessageReceived(const IPC::Message& message); private: - virtual void Disconnect(); - + void CancelCreation(); void OnWorkerCreated(); void OnWorkerContextDestroyed(); void OnPostMessage(const string16& message, |