Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1713)

Unified Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 354643003: ServiceWorker: Support navigator.serviceWorker.active (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/service_worker/service_worker_dispatcher.cc
diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc
index bc0ef00891d0a4a6e202aa435e3d35bb4c775313..81f2c4ec0b7ab245ab8049716ebd4d8ea8fd964a 100644
--- a/content/child/service_worker/service_worker_dispatcher.cc
+++ b/content/child/service_worker/service_worker_dispatcher.cc
@@ -62,6 +62,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnSetInstallingServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker,
OnSetWaitingServiceWorker)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetActiveServiceWorker,
+ OnSetActiveServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
OnSetControllerServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
@@ -132,6 +134,7 @@ void ServiceWorkerDispatcher::RemoveProviderContext(
provider_contexts_.erase(provider_context->provider_id());
worker_to_provider_.erase(provider_context->installing_handle_id());
worker_to_provider_.erase(provider_context->waiting_handle_id());
+ worker_to_provider_.erase(provider_context->active_handle_id());
worker_to_provider_.erase(provider_context->controller_handle_id());
}
@@ -313,6 +316,33 @@ void ServiceWorkerDispatcher::OnSetWaitingServiceWorker(
}
}
+void ServiceWorkerDispatcher::OnSetActiveServiceWorker(
+ int thread_id,
+ int provider_id,
+ const ServiceWorkerObjectInfo& info) {
+ ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
+ if (provider != provider_contexts_.end()) {
+ int existing_active_id = provider->second->active_handle_id();
+ if (existing_active_id != info.handle_id &&
+ existing_active_id != kInvalidServiceWorkerHandleId) {
+ WorkerToProviderMap::iterator associated_provider =
+ worker_to_provider_.find(existing_active_id);
+ DCHECK(associated_provider != worker_to_provider_.end());
+ DCHECK(associated_provider->second->provider_id() == provider_id);
+ worker_to_provider_.erase(associated_provider);
+ }
+ provider->second->OnSetActiveServiceWorker(provider_id, info);
+ if (info.handle_id != kInvalidServiceWorkerHandleId)
+ worker_to_provider_[info.handle_id] = provider->second;
+ }
+
+ ScriptClientMap::iterator found = script_clients_.find(provider_id);
+ if (found != script_clients_.end()) {
+ // Populate the .active field with the new worker object.
+ found->second->setActive(GetServiceWorker(info, false));
+ }
+}
+
void ServiceWorkerDispatcher::OnSetControllerServiceWorker(
int thread_id,
int provider_id,

Powered by Google App Engine
This is Rietveld 408576698