chromium/third_party/blink/public/mojom/service_worker/service_worker_object.mojom

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module blink.mojom;

import "third_party/blink/public/mojom/messaging/transferable_message.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_database.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_state.mojom";
import "url/mojom/url.mojom";

// Describes a ServiceWorker object:
// https://w3c.github.io/ServiceWorker/#serviceworker-interface
struct ServiceWorkerObjectInfo {
  // |version_id| identifies the service worker. It is internal state not
  // exposed to the web.
  int64 version_id = kInvalidServiceWorkerVersionId;

  // ServiceWorker#state
  ServiceWorkerState state = ServiceWorkerState.kParsed;

  // ServiceWorker#scriptURL
  url.mojom.Url url;

  // This object's host in the browser process.
  pending_associated_remote<ServiceWorkerObjectHost> host_remote;

  // This object in the renderer process.
  pending_associated_receiver<ServiceWorkerObject> receiver;
};

// The browser-side host of one ServiceWorker JavaScript object. The renderer
// uses this interface to ask the browser process to do operations needed to
// implement ServiceWorker methods.
interface ServiceWorkerObjectHost {
  // Corresponds to ServiceWorker#postMessage().
  PostMessageToServiceWorker(TransferableMessage message);

  // Tells the browser process to terminate the service worker. Used in layout
  // tests to verify behavior when a service worker isn't running. The callback
  // is called when the browser process actually observes the termination.
  TerminateForTesting() => ();
};

// The renderer-side endpoint for one ServiceWorker JavaScript object. The
// browser uses this interface to talk with the corresponding service worker
// object in the renderer process.
interface ServiceWorkerObject {
  // Corresponds to ServiceWorker#state.
  StateChanged(ServiceWorkerState state);
};