blob: 2a78a6f2f739f1040565d89d9a92de5045477b8c [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module content.mojom;
import "mojo/public/mojom/base/string16.mojom";
import "third_party/blink/public/mojom/messaging/transferable_message.mojom";
import "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_error_type.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_object.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom";
import "third_party/blink/public/platform/web_feature.mojom";
import "url/mojom/url.mojom";
// Used for EnsureControllerServiceWorker() to indicate why a controllee needs
// a controller ServiceWorker.
enum ControllerServiceWorkerPurpose {
FETCH_SUB_RESOURCE
};
// ServiceWorkerContainerHost is an interface implemented by the browser
// process. The renderer process uses this interface to request the browser
// process to do operations involving service worker registrations.
//
// This interface is associated with its counterpart ServiceWorkerContainer.
// The message pipe it's used on depends on the container type.
// - For service workers:
// Associated with EmbeddedWorkerInstanceClient, which is on a dedicated
// message pipe.
// - For shared workers (S13nSW):
// Associated with SharedWorkerFactory, which is on a dedicated message
// pipe.
// - For shared workers (non-S13nSW):
// Associated with ServiceWorkerDispatcherHost, which is on the
// channel-associated interface to the renderer process.
// - For documents:
// Associated with ServiceWorkerDispatcherHost, which is on the
// channel-associated interface to the renderer process.
interface ServiceWorkerContainerHost {
// Corresponds to navigator.serviceWorker.register().
// Registers a service worker from |script_url| with |options|.
// On success, |error| is kNone with |registration| set.
// Otherwise, |error| and |error_msg| describe the failure.
Register(url.mojom.Url script_url,
blink.mojom.ServiceWorkerRegistrationOptions options)
=> (blink.mojom.ServiceWorkerErrorType error,
string? error_msg,
blink.mojom.ServiceWorkerRegistrationObjectInfo? registration);
// Corresponds to navigator.serviceWorker.getRegistration().
// Gets the service worker registration for the |client_url|.
// On success, |error| is kNone with |registration| set.
// In case there is no registration at |client_url|, or the registration is
// uninstalling, |error| is still kNone but with null |registration|.
// Otherwise, |error| and |error_msg| describe the failure.
GetRegistration(url.mojom.Url client_url)
=> (blink.mojom.ServiceWorkerErrorType error,
string? error_msg,
blink.mojom.ServiceWorkerRegistrationObjectInfo? registration);
// Corresponds to navigator.serviceWorker.getRegistrations().
// Gets all service worker registrations which have the same origin with
// the ServiceWorkerContainer that this interface hosts.
// On success, |error| is kNone with |infos| set. Otherwise, |error| and
// |error_msg| describe the failure.
GetRegistrations()
=> (blink.mojom.ServiceWorkerErrorType error,
string? error_msg,
array<blink.mojom.ServiceWorkerRegistrationObjectInfo>? infos);
// Corresponds to navigator.serviceWorker.ready.
// Returns the service worker registration for the ServiceWorkerContainer that
// this interface hosts, once such a registration exists and has an active
// service worker.
GetRegistrationForReady()
=> (blink.mojom.ServiceWorkerRegistrationObjectInfo? registration);
// S13nServiceWorker:
// Returns a Mojo end point to the controller ServiceWorker. This may start a
// service worker instance in a renderer process if the corresponding
// instance is not alive.
// This method must be called only by the controllees.
// If the browser fails to start the service worker it is propagated as a
// connection error of the returned pipe. The detailed error reasons are not
// reported to the controllees, but the browser process is responsible for
// properly handling the failure and recording the reasons.
// |purpose| is used for UMA.
EnsureControllerServiceWorker(blink.mojom.ControllerServiceWorker& controller,
ControllerServiceWorkerPurpose purpose);
// S13nServiceWorker:
// Makes a new endpoint to this ServiceWorkerContainerHost.
CloneContainerHost(ServiceWorkerContainerHost& container_host);
// Does nothing but calls the callback. Useful for pumping the message pipe
// for this interface and associated interfaces: when the callback is called,
// you know all incoming messages up to the Ping() call have been received.
Ping() => ();
// S13nServiceWorker:
// Gives a hint to the browser process to update the service worker after a
// controlled page load. This message is meant to be sent at a time when page
// load is no longer busy, so update doesn't adversely affect performance.
// The browser process can possibly coalesce hints for the same service
// worker into a single update.
HintToUpdateServiceWorker();
};
// ServiceWorkerContainer is an interface implemented by the renderer process.
// The browser process uses this interface to send messages to documents or the
// service worker.
//
// Roughly corresponds to the web-exposed ServiceWorkerContainer interface,
// i.e., navigator.serviceWorker. Actually, the plan is for this interface to be
// used for anything that could access a ServiceWorkerRegistration or
// ServiceWorker object. For example, ServiceWorkerGlobalScope needs to be
// connected to this, since it has self.registration, even though we don’t
// implement navigator.serviceWorker for Worker yet. But eventually anything
// that can touch these objects should be a ServiceWorkerContainer, so it’s OK
// to use this name.
//
// This interface is associated with its counterpart,
// ServiceWorkerContainerHost, as they are sent on the same master interface
// together. See ServiceWorkerContainerHost for documentation about the message
// pipe they live on.
interface ServiceWorkerContainer {
// Corresponds to setting ServiceWorkerContainer#controller.
// If |controller_info| is invalid (its |object_info| is null), then
// ServiceWorkerContainer#controller is cleared.
// If |controller_info| is valid, |used_features| is the set of
// features the controller has used, for UseCounter purposes.
// If |should_notify_controllerchange| is true, dispatch a 'controllerchange'
// event.
SetController(blink.mojom.ControllerServiceWorkerInfo controller_info,
array<blink.mojom.WebFeature> used_features,
bool should_notify_controllerchange);
// Corresponds to Client#postMessage().
// Sends |message| from the service worker |source| to this service worker
// client.
PostMessageToClient(blink.mojom.ServiceWorkerObjectInfo source,
blink.mojom.TransferableMessage message);
// Notifies this service worker client that its controller used a |feature|,
// for UseCounter purposes.
CountFeature(blink.mojom.WebFeature feature);
};