blob: ba8140973871cae083bd94ba90eb657675de0f50 [file] [log] [blame]
// Copyright 2016 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 "content/common/service_worker/service_worker_fetch_response_callback.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
import "services/network/public/mojom/cookie_manager.mojom";
import "third_party/blink/public/platform/modules/fetch/fetch_api_request.mojom";
import "third_party/blink/public/platform/modules/notifications/notification.mojom";
import "third_party/blink/public/platform/modules/payments/payment_app.mojom";
import "third_party/blink/public/mojom/message_port/message_port.mojom";
import "third_party/blink/public/mojom/service_worker/dispatch_fetch_event_params.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_client.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_event_status.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 "url/mojom/origin.mojom";
import "url/mojom/url.mojom";
[Native]
struct PushEventPayload;
[Native]
struct ServiceWorkerResponse;
// TODO(peter): Move this to Blink when ServiceWorkerResponse has a Mojo
// counterpart.
struct BackgroundFetchSettledFetch {
blink.mojom.FetchAPIRequest request;
ServiceWorkerResponse response;
};
enum BackgroundFetchState {
PENDING,
SUCCEEDED,
FAILED
};
struct ExtendableMessageEvent {
blink.mojom.TransferableMessage message;
url.mojom.Origin source_origin;
// Exactly one of |source_info_for_client| and
// |source_info_for_service_worker| should be non-null.
blink.mojom.ServiceWorkerClientInfo? source_info_for_client;
blink.mojom.ServiceWorkerObjectInfo? source_info_for_service_worker;
};
// The number of seconds for which a 'push' event should be allowed to run.
// This is not in the spec but for a Chrome-specific timeout. Each
// event dispatched to service workers has a 5 minute timeout in the Chrome
// implementation, but this makes the timeout for push events shorter.
const int32 kPushEventTimeoutSeconds = 90;
// An interface for talking to a running service worker thread. The browser
// process uses this interface to request the renderer to do things like
// dispatch events to the service worker. This interface is bound on the
// service worker thread and is implemented by ServiceWorkerContextClient.
//
// This is the master interface for the Mojo message pipe between the browser
// process and the service worker thread in the renderer process. Other service
// worker-related interfaces bound on the service worker thread are associated
// with this interface. These include:
// - ServiceWorkerHost for this service worker.
// - ServiceWorkerRegistrationObject(Host) for this service worker's
// self.registration property.
// - ServiceWorkerObjects(Host) for that registration's properties.
//
// A similar (but non-associated) interface is ControllerServiceWorker. That
// interface is used by service worker clients (inside renderer processes) to
// talk directly to their controller service worker, without going through the
// browser.
//
// USAGE TIP: Those DispatchEvent* messages expecting a
// (blink.mojom.ServiceWorkerEventStatus, mojo_base.mojom.Time) callback are
// considered 'simple events'. ServiceWorkerVersion::CreateSimpleEventCallback
// can be used to create the callback for these.
interface ServiceWorker {
// The first message sent on this interface. It is used to associate service
// worker-related interfaces together on the service worker thread, as
// ServiceWorker is the first interface available on the
// service worker thread. It establishes the |service_worker_host| connection
// and passes information used to populate
// ServiceWorkerGlobalScope#registration object. JavaScript execution of the
// service worker does not start until this message is received.
InitializeGlobalScope(
associated blink.mojom.ServiceWorkerHost service_worker_host,
blink.mojom.ServiceWorkerRegistrationObjectInfo registration_info);
DispatchInstallEvent()
=> (blink.mojom.ServiceWorkerEventStatus status,
bool has_fetch_handler,
mojo_base.mojom.Time dispatch_event_time);
DispatchActivateEvent()
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
// These methods dispatch to the ServiceWorkerGlobalScope the events listed on
// https://wicg.github.io/background-fetch/#service-worker-global-events.
// The callbacks are called once the event handler has run and waitUntil()
// promise has settled. |developer_id| and |unique_id| are documented in
// content::BackgroundFetchRegistrationId.
DispatchBackgroundFetchAbortEvent(string developer_id,
string unique_id,
array<BackgroundFetchSettledFetch> fetches)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchBackgroundFetchClickEvent(string developer_id,
BackgroundFetchState state)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchBackgroundFetchFailEvent(string developer_id,
string unique_id,
array<BackgroundFetchSettledFetch> fetches)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchBackgroundFetchedEvent(string developer_id,
string unique_id,
array<BackgroundFetchSettledFetch> fetches)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
// Dispatches the cookie change events in the Async Cookie API specification.
// https://github.com/WICG/cookie-store/
// The callback is called once the event handler has run and the waitUntil()
// promise has settled.
DispatchCookieChangeEvent(
network.mojom.CanonicalCookie cookie,
network.mojom.CookieChangeCause cause)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
// The Dispatch*FetchEvent() callback is called once the event finishes,
// which means the event handler ran and all outstanding respondWith() and
// waitUntil() promises have settled. |response_callback| is called once the
// promise to respondWith() settles, or when the event handler ran without
// calling respondWith().
DispatchFetchEvent(blink.mojom.DispatchFetchEventParams params,
ServiceWorkerFetchResponseCallback response_callback)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchNotificationClickEvent(
string notification_id,
blink.mojom.NotificationData notification_data,
int32 action_index,
mojo_base.mojom.String16? reply)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchNotificationCloseEvent(
string notification_id,
blink.mojom.NotificationData notification_data)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchPushEvent(PushEventPayload payload)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
// Arguments are passed to the event handler as parameters of SyncEvent.
// Ref: https://wicg.github.io/BackgroundSync/spec/#sync-event
// S13nServiceWorker: |timeout| is the amount of time to allow this event to
// finish.
// Non-S13nServiceWorker: |timeout| is just ignored.
DispatchSyncEvent(string id,
bool last_chance,
mojo_base.mojom.TimeDelta timeout)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchAbortPaymentEvent(
payments.mojom.PaymentHandlerResponseCallback result_of_abort_payment)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchCanMakePaymentEvent(
payments.mojom.CanMakePaymentEventData event_data,
payments.mojom.PaymentHandlerResponseCallback result_of_can_make_payment)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchPaymentRequestEvent(
payments.mojom.PaymentRequestEventData request_data,
payments.mojom.PaymentHandlerResponseCallback response_callback)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchExtendableMessageEvent(ExtendableMessageEvent event)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
// Pings the service worker to check if it is responsive. If the callback is
// not called within a certain period of time, the browser will terminate the
// worker.
Ping() => ();
// S13nServiceWorker:
// Lets the idle timer request termination immediately after all inflight
// events are handled without delay.
SetIdleTimerDelayToZero();
};