Skip to content

Commit

Permalink
[Service Worker] SW shouldn't start control the page when activating (y…
Browse files Browse the repository at this point in the history
…outube#712)

b/283332879
  • Loading branch information
sherryzy authored Jun 27, 2023
1 parent 7b88f37 commit 5c40b4f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ self.oninstall = function (e) {

self.onactivate = function (e) {
console.log('onactivate event received', e);
self.clients.claim();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ service-worker/import-scripts-resource-map.https.html, PASS
service-worker/import-scripts-updated-flag.https.html, PASS
service-worker/multiple-update.https.html, PASS
service-worker/register-default-scope.https.html, PASS
service-worker/register-wait-forever-in-install-worker.https.html, PASS
service-worker/registration-basic.https.html, PASS
service-worker/registration-security-error.https.html, PASS
service-worker/registration-service-worker-attributes.https.html, PASS
Expand Down Expand Up @@ -38,7 +39,6 @@ service-worker/import-scripts-mime-types.https.html, DISABLE

# b/234788479 Implement waiting for update worker state tasks in Install algorithm.
service-worker/import-scripts-redirect.https.html, DISABLE
service-worker/register-wait-forever-in-install-worker.https.html, DISABLE

# "Module" type of dedicated worker is supported in Cobalt
service-worker/dedicated-worker-service-worker-interception.https.html, DISABLE
Expand Down
14 changes: 3 additions & 11 deletions cobalt/worker/service_worker_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,23 +557,15 @@ void ServiceWorkerContext::Activate(
// Cobalt doesn't implement 'application cache':
// https://www.w3.org/TR/2011/WD-html5-20110525/offline.html#applicationcache
// 9. For each service worker client client who is using registration:
// Note: The spec defines "control" and "use" of a service worker from the
// value of the active service worker property of the client environment, but
// that property is set here, so here we should not use that exact definition
// to determine if the client is using this registration. Instead, we use the
// Match Service Worker Registration algorithm to find the registration for a
// client and compare it with the registration being activated.
// https://www.w3.org/TR/2022/CRD-service-workers-20220712/#dfn-use
for (const auto& client : web_context_registrations_) {
scoped_refptr<ServiceWorkerRegistrationObject> client_registration =
scope_to_registration_map_->MatchServiceWorkerRegistration(
client->environment_settings()->ObtainStorageKey(),
client->environment_settings()->creation_url());
// When a service worker client is controlled by a service worker, it is
// said that the service worker client is using the service worker’s
// containing service worker registration.
// https://www.w3.org/TR/2022/CRD-service-workers-20220712/#dfn-control
if (client_registration.get() == registration) {
if (client->active_service_worker() &&
client->active_service_worker()
->containing_service_worker_registration() == registration) {
// 9.1. Set client’s active worker to registration’s active worker.
client->set_active_service_worker(registration->active_worker());
// 9.2. Invoke Notify Controller Change algorithm with client as the
Expand Down

0 comments on commit 5c40b4f

Please sign in to comment.