Skip to content

Commit 0fc784b

Browse files
d0iasmChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Update the spec comment to add 'script type' check in the register algorithm
This CL updates the spec comment since the spec issue was resolved. w3c/ServiceWorker#1359 Also, 1) updates a TODO comment from using a specific person's name to the crbug link. 2) Rename the method from "ContinueWithRegistrationForSameScriptUrl" to "ContinueWithRegistrationWithSameRegistrationOptions" because it requires the equality of the script type and the update-via-cache option too. No behavior change. Bug: 824647 Change-Id: I44e146554010e77b9833abc1d2df55e0b1bb78a4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2732746 Commit-Queue: Asami Doi <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/master@{#860113}
1 parent a778230 commit 0fc784b

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

content/browser/service_worker/service_worker_register_job.cc

+25-28
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ void ServiceWorkerRegisterJob::SetPhase(Phase phase) {
225225
phase_ = phase;
226226
}
227227

228-
// This function corresponds to the steps in [[Register]] following
229-
// "Let registration be the result of running the [[GetRegistration]] algorithm.
230-
// Throughout this file, comments in quotes are excerpts from the spec.
228+
// This function corresponds to the steps in the [[Register]] algorithm.
229+
// https://w3c.github.io/ServiceWorker/#register-algorithm
230+
// "4. Let registration be the result of running the Get Registration algorithm
231+
// passing job’s scope url as the argument."
231232
void ServiceWorkerRegisterJob::ContinueWithRegistration(
232233
blink::ServiceWorkerStatusCode status,
233234
scoped_refptr<ServiceWorkerRegistration> existing_registration) {
@@ -244,20 +245,19 @@ void ServiceWorkerRegisterJob::ContinueWithRegistration(
244245
}
245246

246247
DCHECK(existing_registration->GetNewestVersion());
247-
// We also compare |script_type| here to proceed with registration when the
248-
// script type is changed.
249-
// TODO(asamidoi): Update the spec comment once
250-
// https://github.com/w3c/ServiceWorker/issues/1359 is resolved.
251-
// "If scriptURL is equal to registration.[[ScriptURL]] and "update_via_cache
252-
// is equal to registration.[[update_via_cache]], then:"
248+
// "5.2. If newestWorker is not null, job’s script url equals newestWorker’s
249+
// script url, job’s worker type equals newestWorker’s type, and job’s update
250+
// via cache mode's value equals registration’s update via cache mode, then:"
253251
if (existing_registration->GetNewestVersion()->script_url() == script_url_ &&
254-
existing_registration->update_via_cache() == update_via_cache_ &&
255252
existing_registration->GetNewestVersion()->script_type() ==
256-
worker_script_type_) {
257-
// "Set registration.[[Uninstalling]] to false."
258-
existing_registration->AbortPendingClear(base::BindOnce(
259-
&ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl,
260-
weak_factory_.GetWeakPtr(), existing_registration));
253+
worker_script_type_ &&
254+
existing_registration->update_via_cache() == update_via_cache_) {
255+
// Subsequent spec steps (5.2.1-5.2.2) are implemented in
256+
// ContinueWithRegistrationWithSameRegistrationOptions().
257+
existing_registration->AbortPendingClear(
258+
base::BindOnce(&ServiceWorkerRegisterJob::
259+
ContinueWithRegistrationWithSameRegistrationOptions,
260+
weak_factory_.GetWeakPtr(), existing_registration));
261261
return;
262262
}
263263

@@ -268,12 +268,11 @@ void ServiceWorkerRegisterJob::ContinueWithRegistration(
268268
return;
269269
}
270270

271-
// "Invoke Set Registration algorithm with job’s scope url and
272-
// job’s update via cache mode."
271+
// "6.1. Invoke Set Registration algorithm with job’s scope url and job’s
272+
// update via cache mode."
273273
existing_registration->SetUpdateViaCache(update_via_cache_);
274274
set_registration(existing_registration);
275-
// "Return the result of running the [[Update]] algorithm, or its equivalent,
276-
// passing registration as the argument."
275+
// "7. Invoke Update algorithm passing job as the argument."
277276
UpdateAndContinue();
278277
}
279278

@@ -401,32 +400,30 @@ void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration(
401400
UpdateAndContinue();
402401
}
403402

404-
void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl(
405-
scoped_refptr<ServiceWorkerRegistration> existing_registration,
406-
blink::ServiceWorkerStatusCode status) {
403+
void ServiceWorkerRegisterJob::
404+
ContinueWithRegistrationWithSameRegistrationOptions(
405+
scoped_refptr<ServiceWorkerRegistration> existing_registration,
406+
blink::ServiceWorkerStatusCode status) {
407407
if (status != blink::ServiceWorkerStatusCode::kOk) {
408408
Complete(status);
409409
return;
410410
}
411411
set_registration(existing_registration);
412412

413-
// "If newestWorker is not null, scriptURL is equal to newestWorker.scriptURL,
414-
// and job’s update via cache mode's value equals registration’s
415-
// update via cache mode then:
416-
// Return a promise resolved with registration."
417413
// We resolve only if there's an active version. If there's not,
418414
// then there is either no version or only a waiting version from
419415
// the last browser session; it makes sense to proceed with registration in
420416
// either case.
421417
DCHECK(!existing_registration->installing_version());
422418
if (existing_registration->active_version()) {
419+
// "5.2.1. Invoke Resolve Job Promise with job and registration."
423420
ResolvePromise(status, std::string(), existing_registration.get());
421+
// "5.2.2. Invoke Finish Job with job and abort these steps."
424422
Complete(blink::ServiceWorkerStatusCode::kOk);
425423
return;
426424
}
427425

428-
// "Return the result of running the [[Update]] algorithm, or its equivalent,
429-
// passing registration as the argument."
426+
// "7. Invoke Update algorithm passing job as the argument."
430427
UpdateAndContinue();
431428
}
432429

content/browser/service_worker/service_worker_register_job.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ServiceWorkerRegisterJob : public ServiceWorkerRegisterJobBase {
131131
void ContinueWithUninstallingRegistration(
132132
scoped_refptr<ServiceWorkerRegistration> existing_registration,
133133
blink::ServiceWorkerStatusCode status);
134-
void ContinueWithRegistrationForSameScriptUrl(
134+
void ContinueWithRegistrationWithSameRegistrationOptions(
135135
scoped_refptr<ServiceWorkerRegistration> existing_registration,
136136
blink::ServiceWorkerStatusCode status);
137137
void UpdateAndContinue();

third_party/blink/renderer/modules/service_worker/service_worker_container.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ ScriptPromise ServiceWorkerContainer::registerServiceWorker(
219219
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
220220
ScriptPromise promise = resolver->Promise();
221221

222-
// TODO(asamidoi): Remove this check after module loading for
223-
// ServiceWorker is enabled by default (https://crbug.com/824647).
222+
// TODO(crbug.com/824647): Remove this check after module loading for
223+
// ServiceWorker is enabled by default.
224224
if (options->type() == "module" &&
225225
!RuntimeEnabledFeatures::ModuleServiceWorkerEnabled()) {
226226
resolver->Reject(MakeGarbageCollected<DOMException>(

0 commit comments

Comments
 (0)