0

Cleanup: Update links on the ServiceWorker static routing API

Since the ServiceWorker static routing API gets included in the
specification (https://w3c.github.io/ServiceWorker/), let me update code
comments to point out it.  If it is not feasible to point out the
specification, let me point out the WICG page instead of my personal
github repository.

Also, this CL removed "Experimental" because the API became the
specification, and it is not experimental any more.

Bug: 40241479
Change-Id: I0c71d85d4025aeb5bc86e7ae072676c6657f7e97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5366431
Reviewed-by: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: Shunya Shishido <sisidovski@chromium.org>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org>
Commit-Queue: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1272604}
This commit is contained in:
Yoshisato Yanagisawa
2024-03-14 06:12:19 +00:00
committed by Chromium LUCI CQ
parent eaa9df2ad4
commit 30335d391e
12 changed files with 55 additions and 64 deletions

@ -121,7 +121,7 @@ class ServiceWorkerContainerHost::PendingUpdateVersion {
// and make the update notified to all the renderers via mojo IPC.
//
// See:
// https://github.com/WICG/service-worker-static-routing-api/blob/main/final-form.md#use-service-worker-iif-running
// https://w3c.github.io/ServiceWorker/#dom-routercondition-runningstatus
class ServiceWorkerContainerHost::ServiceWorkerRunningStatusObserver final
: public ServiceWorkerVersion::Observer {
public:

@ -325,8 +325,6 @@ void ServiceWorkerMainResourceLoader::StartRequest(
router_info->matched_source_type = source_type;
response_head_->service_worker_router_info = std::move(router_info);
// TODO(crbug.com/1371756): support other sources in the full form.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/final-form.md
switch (source_type) {
case network::mojom::ServiceWorkerRouterSourceType::kNetwork:
// Network fallback is requested.

@ -946,7 +946,7 @@ constexpr base::FeatureParam<int>
};
// Enables ServiceWorker static routing API.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://github.com/WICG/service-worker-static-routing-api
BASE_FEATURE(kServiceWorkerStaticRouter,
"ServiceWorkerStaticRouter",
base::FEATURE_ENABLED_BY_DEFAULT);

@ -374,8 +374,6 @@ void ServiceWorkerSubresourceLoader::DispatchFetchEvent() {
} race_network_request_mode = kDefault;
if (eval_result) { // matched the rule.
const auto& sources = eval_result->sources;
// TODO(crbug.com/1371756): support other sources in the full form.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/final-form.md
auto source_type = sources[0].type;
set_used_router_source_type(source_type);

@ -115,35 +115,20 @@ interface ServiceWorkerHost {
// Otherwise, |error| and |error_msg| describe the failure.
ClaimClients() => (ServiceWorkerErrorType error, string? error_msg);
// Experimental feature.
// Registers the service worker router rules, which are evaluated before
// the regular navigation path. i.e. evaluated before the service worker
// fetch handler is invoked.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
//
// Both RegisterRouter() and AddRoutes() methods initializes the router and
// register router rules in the host. Both methods behave exactly same except
// for one difference whether multiple API calls are allowed or not.
// RegisterRouter() is designed to be called once, the calling process will be
// killed with a bad message when the router already exists in the host. On
// the other hand, AddRoutes() can be called multiple times, it will append
// given router rules into existing router rules.
//
// RegisterRouter() is going to be deprecated when we send Intent to Ship,
// but for now we keep the method as it is since some webistes already use
// RegisterRouter() in Origin Trial. (crbug.com/1371756).
//
// When these methods are called multiple times. Belows are possible cases and
// expected behaviors.
//
// RegisterRouter() -> RegisterRouter(): Reports a bad message.
// AddRoutes() -> AddRoutes(): Register rules twice.
// Corresponds to InstallEvent#addRoutes(). Adds service worker router rules,
// which are evaluated before the regular navigation path. i.e. evaluated
// before the service worker fetch handler is invoked.
AddRoutes(ServiceWorkerRouterRules rules) => ();
// Deprecated.
// See:
// https://github.com/WICG/service-worker-static-routing-api/blob/main/README.md#how-chrome-implements-this
//
// RegisterRouter() and AddRoutes() should be implemented as mutual exclusive,
// the calling process will be killded with a bad message when these two
// method calls are mixed.
// TODO(crbug.com/329285464): remove this method.
RegisterRouter(ServiceWorkerRouterRules rules) => ();
AddRoutes(ServiceWorkerRouterRules rules) => ();
};
// Enum to indicate which router registration method is used. This is used to

@ -12,6 +12,8 @@ import "third_party/blink/public/mojom/safe_url_pattern.mojom";
// if the service worker is not ready to run the fetch handler right away.
// `kNotRunning` includes `EmbeddedWorkerStatus`'s `kStarting` and `kStopping`
// in addition to `kStopped`.
// See:
// https://w3c.github.io/ServiceWorker/#enumdef-runningstatus
enum ServiceWorkerRouterRunningStatusEnum {
// ServiceWorker can run the fetch handler without waiting for starting
// it up.
@ -22,21 +24,21 @@ enum ServiceWorkerRouterRunningStatusEnum {
// This represents a running status condition to match.
// See:
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/final-form.md
// https://w3c.github.io/ServiceWorker/#dom-routercondition-runningstatus
struct ServiceWorkerRouterRunningStatusCondition {
ServiceWorkerRouterRunningStatusEnum status;
};
// This represents a request condition to match.
// See:
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/final-form.md
struct ServiceWorkerRouterRequestCondition {
// The request method.
// See: https://fetch.spec.whatwg.org/#concept-request-method
// See:
// https://w3c.github.io/ServiceWorker/#dom-routercondition-requestmethod
string? method;
// RequestMode
// See: https://fetch.spec.whatwg.org/#concept-request-mode
// See:
// https://w3c.github.io/ServiceWorker/#dom-routercondition-requestmode
// If it is not set, ServiceWorkerRouterEvaluator won't use it as condition.
// TODO(http://crbug.com/657632): implement this with optional enum.
// Since the code is used on Android, we need Java variant, which currently
@ -45,7 +47,8 @@ struct ServiceWorkerRouterRequestCondition {
network.mojom.RequestMode mode;
// RequestDestination
// See: https://fetch.spec.whatwg.org/#concept-request-destination
// See:
// https://w3c.github.io/ServiceWorker/#dom-routercondition-requestdestination
// If it is not set, ServiceWorkerRouterEvaluator won't use it as condition.
// TODO(http://crbug.com/657632): implement this with optional enum.
// Since the code is used on Android, we need Java variant, which currently
@ -54,6 +57,9 @@ struct ServiceWorkerRouterRequestCondition {
network.mojom.RequestDestination destination;
};
// This represents a or condition to match.
// See:
// https://w3c.github.io/ServiceWorker/#dom-routercondition-or
struct ServiceWorkerRouterOrCondition {
array<ServiceWorkerRouterCondition> conditions;
};
@ -66,8 +72,9 @@ struct ServiceWorkerRouterNotCondition {
};
// This represents a condition of the router rule.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// See: https://w3c.github.io/ServiceWorker/#dictdef-routercondition
// TODO(crbug.com/1371756): implement other conditions in the full picture.
// https://github.com/WICG/service-worker-static-routing-api
struct ServiceWorkerRouterCondition {
// URLPattern to be used for matching.
SafeUrlPattern? url_pattern;
@ -78,28 +85,31 @@ struct ServiceWorkerRouterCondition {
};
// This is used for specifying the source is network.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dom-routersourceenum-network
// TODO(crbug.com/1371756): implement fields in the full picture.
// https://github.com/WICG/service-worker-static-routing-api
struct ServiceWorkerRouterNetworkSource {
};
// This source is used when the browser should allow a network source and
// the fetch handler to race, allowing the first one to respond to service
// the request.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dom-routersourceenum-race-network-and-fetch-handler
// TODO(crbug.com/1371756): implement fields in the full picture.
// https://github.com/WICG/service-worker-static-routing-api
struct ServiceWorkerRouterRaceSource {
};
// This is used for explicitly running the fetch event listeners.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dom-routersourceenum-fetch-event
// TODO(crbug.com/1371756): implement fields in the full picture.
// https://github.com/WICG/service-worker-static-routing-api
struct ServiceWorkerRouterFetchEventSource {
};
// This source is used when the response should be retrieved from the cache
// storage.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dom-routersourcedict-cachename
struct ServiceWorkerRouterCacheSource {
// The Cache object's name to be used. Unspecified means looking up from
// all Cache objects in the Cache Storage.
@ -107,8 +117,9 @@ struct ServiceWorkerRouterCacheSource {
};
// This represents a source of the router rule.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#typedefdef-routersource
// TODO(crbug.com/1371756): implement other sources in the full picture.
// https://github.com/WICG/service-worker-static-routing-api
union ServiceWorkerRouterSource {
ServiceWorkerRouterNetworkSource network_source;
ServiceWorkerRouterRaceSource race_source;
@ -117,7 +128,7 @@ union ServiceWorkerRouterSource {
};
// This represents a ServiceWorker static routing API's router rule.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dictdef-routerrule
// It represents each route.
// When an request matches `conditions`, a response is fetched from `sources`.
// `conditions` are evaluated sequentially to ensure all of them are fulfilled.
@ -133,7 +144,8 @@ struct ServiceWorkerRouterRule {
};
// This represents a list of ServiceWorker static routing API's router rules.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// It is usually used as the `addRoutes()` argument.
// https://w3c.github.io/ServiceWorker/#dom-installevent-addroutes-rules-rules
struct ServiceWorkerRouterRules {
array<ServiceWorkerRouterRule> rules;
};

@ -6,12 +6,11 @@ module blink.mojom;
import "third_party/blink/public/mojom/service_worker/service_worker_embedded_worker_status.mojom";
// Experimental.
// The callback interface to allow the browser process to notify the
// ServiceWorker running status to renderer processes executing subresource
// loaders for that ServiceWorker. This is used for realizing the running
// status condition defined in the ServiceWorker static routing API.
// See: https://github.com/WICG/service-worker-static-routing-api/blob/main/final-form.md#use-service-worker-iif-running
// See: https://w3c.github.io/ServiceWorker/#dom-routercondition-runningstatus
interface ServiceWorkerRunningStatusCallback {
// OnStatusChanged is called on the ServiceWorker running status change.
// `status` tell the latest running status.

@ -8,10 +8,12 @@
Exposed=ServiceWorker
] interface InstallEvent : ExtendableEvent {
constructor(DOMString type, optional ExtendableEventInit eventInitDict = {});
// Experimental
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// addRoutes() is going to be the final API surface. registerRouter() is
// eventually removed.
// https://w3c.github.io/ServiceWorker/#ref-for-dom-installevent-addroutes
[RuntimeEnabled=ServiceWorkerStaticRouter, CallWith=ScriptState, RaisesException, MeasureAs=ServiceWorkerStaticRouter_AddRoutes] Promise<undefined> addRoutes((RouterRule or sequence<RouterRule>) rules);
// Deprecated.
// See:
// https://github.com/WICG/service-worker-static-routing-api/blob/main/README.md#how-chrome-implements-this
// TODO(crbug.com/329285464): remove this method.
[RuntimeEnabled=ServiceWorkerStaticRouter, CallWith=ScriptState, RaisesException, MeasureAs=ServiceWorkerStaticRouter_RegisterRouter] Promise<undefined> registerRouter((RouterRule or sequence<RouterRule>) rules);
};

@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/final-form.md
// https://w3c.github.io/ServiceWorker/#enumdef-runningstatus
enum RunningStatusEnum { "running", "not-running" };
// Experimental.
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dictdef-routercondition
dictionary RouterCondition {
// For the URLPattern condition.
// https://wicg.github.io/urlpattern/#typedefdef-urlpatterncompatible

@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/WICG/service-worker-static-routing-api
// Some features come from final-form.md.
// https://w3c.github.io/ServiceWorker/#enumdef-routersourceenum
enum RouterSourceEnum { "network", "race-network-and-fetch-handler", "fetch-event", "cache" };
// https://w3c.github.io/ServiceWorker/#typedefdef-routersource
typedef (RouterSourceEnum or RouterSource) RouterSourceInput;
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api
// TODO(crbug.com/1371756): implement final form.
// https://w3c.github.io/ServiceWorker/#dictdef-routerrule
dictionary RouterRule {
RouterCondition condition;
RouterSourceInput source;

@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Experimental.
// https://github.com/WICG/service-worker-static-routing-api
// https://w3c.github.io/ServiceWorker/#dictdef-routersourcedict
dictionary RouterSource {
// For the cache storage source.
// A string that represents a specific cache to search within.

@ -324,12 +324,12 @@ std::optional<ServiceWorkerRouterRule> ConvertV8RouterRuleToBlink(
// Set up sources.
// TODO(crbug.com/1371756): support multiple sources.
// i.e. support full form shown in
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/final-form.md
// https://github.com/WICG/service-worker-static-routing-api/blob/main/final-form.md
//
// https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api/blob/main/README.md
// explains the first step. It does not cover cases sequence of sources
// are set. The current IDL has been implemented for this level, but
// the mojo IPC has been implemented to support the final form.
// The ServiceWorker specification (https://w3c.github.io/ServiceWorker/)
// does not cover cases sequence of sources are set. The current IDL has
// been implemented for this level, but the mojo IPC has been implemented
// to support the final form.
const std::optional<ServiceWorkerRouterSource> source =
RouterSourceInputToBlink(input->source(), fetch_handler_type,
exception_state);