From 213183fe6e8958d2ef43543c806dc3d34ce3509e Mon Sep 17 00:00:00 2001 From: iclelland Date: Thu, 23 Jul 2015 12:23:26 -0700 Subject: [Background Sync] Restrict sync registration to service workers with window clients. BUG=479658 Review URL: https://codereview.chromium.org/1234353004 Cr-Commit-Position: refs/heads/master@{#340141} --- .../background_sync/background_sync_manager.cc | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'content/browser/background_sync/background_sync_manager.cc') diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc index 2a79df5..6c33d51 100644 --- a/content/browser/background_sync/background_sync_manager.cc +++ b/content/browser/background_sync/background_sync_manager.cc @@ -320,6 +320,26 @@ void BackgroundSyncManager::RegisterImpl( return; } + ServiceWorkerRegistration* sw_registration = + service_worker_context_->GetLiveRegistration(sw_registration_id); + if (!sw_registration || !sw_registration->active_version()) { + BackgroundSyncMetrics::CountRegister( + options.periodicity, registration_could_fire, + BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, + ERROR_TYPE_NO_SERVICE_WORKER); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(callback, ERROR_TYPE_NO_SERVICE_WORKER, + BackgroundSyncRegistration())); + return; + } + + if (!sw_registration->active_version()->HasWindowClients()) { + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_ALLOWED, + BackgroundSyncRegistration())); + return; + } + BackgroundSyncRegistration* existing_registration = LookupRegistration(sw_registration_id, RegistrationKey(options)); if (existing_registration && @@ -351,19 +371,6 @@ void BackgroundSyncManager::RegisterImpl( &sw_to_registrations_map_[sw_registration_id]; new_registration.set_id(registrations->next_id++); - ServiceWorkerRegistration* sw_registration = - service_worker_context_->GetLiveRegistration(sw_registration_id); - if (!sw_registration || !sw_registration->active_version()) { - BackgroundSyncMetrics::CountRegister( - options.periodicity, registration_could_fire, - BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, - ERROR_TYPE_NO_SERVICE_WORKER); - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(callback, ERROR_TYPE_NO_SERVICE_WORKER, - BackgroundSyncRegistration())); - return; - } - AddRegistrationToMap(sw_registration_id, sw_registration->pattern().GetOrigin(), new_registration); -- cgit v1.1