chromium/third_party/blink/public/mojom/worker/dedicated_worker_host_factory.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 "services/network/public/mojom/cross_origin_embedder_policy.mojom";
import "services/network/public/mojom/fetch_api.mojom";
import "services/network/public/mojom/storage_access_api.mojom";
import "third_party/blink/public/mojom/blob/blob_url_store.mojom";
import "third_party/blink/public/mojom/browser_interface_broker.mojom";
import "third_party/blink/public/mojom/loader/fetch_client_settings_object.mojom";
import "third_party/blink/public/mojom/worker/subresource_loader_updater.mojom";
import "third_party/blink/public/mojom/loader/url_loader_factory_bundle.mojom";
import "third_party/blink/public/mojom/worker/dedicated_worker_host.mojom";
import "third_party/blink/public/mojom/worker/worker_main_script_load_params.mojom";
import "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_container.mojom";
import "third_party/blink/public/mojom/tokens/tokens.mojom";
import "third_party/blink/public/mojom/frame/back_forward_cache_controller.mojom";
import "url/mojom/url.mojom";
import "url/mojom/origin.mojom";

// The name of the InterfaceProviderSpec in service manifests used by the
// frame tree to expose dedicated-worker-specific interfaces between renderer
// and browser.
const string kNavigation_DedicatedWorkerSpec = "navigation:dedicated_worker";

// PlzDedicatedWorker:
// An interface implemented by clients (e.g., the renderer where "new Worker()"
// was invoked) to observe events on the DedicatedWorkerHostFactory.
interface DedicatedWorkerHostFactoryClient {
  // Called when the worker host is created.
  // `origin` is the origin that will be used by the worker on the renderer
  // side. It might differ from the origin that is used on the browser side
  // when `script_url` is a data: URL, due to the linked bug.
  // TODO(crbug.com/40051700): Remove the mismatch cases.
  OnWorkerHostCreated(
      // Used for accessing services from the worker.
      pending_remote<blink.mojom.BrowserInterfaceBroker>
          browser_interface_broker,
      // Used for updating its state from the worker.
      pending_remote<DedicatedWorkerHost> host,
      url.mojom.Origin origin);

  // Called when the worker host started loading the main worker script. This
  // is called after OnWorkerHostCreated(). This is never called when
  // OnScriptLoadStartFailed() is called.
  OnScriptLoadStarted(
      // The info about the service worker container host in the browser process
      // that provides support for this worker to be a service worker client.
      //
      // This is null if the dedicated worker cannot be a service
      // worker client, because for example, the worker's URL is
      // not http(s) or another service worker supported scheme.
      ServiceWorkerContainerInfoForClient? service_worker_container_info,

      // Used for passing the main script pre-requested by the browser process
      // and its redirect information.
      WorkerMainScriptLoadParams main_script_load_params,

      // Used for loading subresources. This also supports non-network URLs like
      // chrome-extension:// URLs.
      URLLoaderFactoryBundle subresource_loader_factories,

      // Used for updating subresource loaders after NetworkService crash.
      pending_receiver<SubresourceLoaderUpdater> subresource_loader_updater,

      // Used to make fetches from the worker go through the controller service
      // worker. This is null when there're no controller service worker.
      ControllerServiceWorkerInfo? controller_info,

      // Used to notify feature usages that might affect back-forward cache
      // usages.
      pending_remote<BackForwardCacheControllerHost>
      back_forward_cache_controller_host);

  // Called when the worker host fails to start loading the main worker script.
  // This is called after OnWorkerHostCreated(). This is never called when
  // OnScriptLoadStarted() is called.
  OnScriptLoadStartFailed();
};

// An interface used to instantiate a dedicated worker host. The implementation
// of this interface lives in the browser process.
interface DedicatedWorkerHostFactory {
  // TODO(crbug.com/906991): Remove this after PlzDedicatedWorker ships.
  // Non-PlzDedicatedWorker:
  // The factory client should call this instead of
  // CreateWorkerHostAndStartScriptLoad() when PlzDedicatedWorker is disabled.
  //
  // Creates a new DedicatedWorkerHost, and requests `browser_interface_broker`
  // to provide the worker access to mojo interfaces.
  // `script_url` is used only for UMA purposes.
  // `origin` is the origin that will be used by the worker on the renderer
  // side. It might differ from the origin that is used on the browser side
  // when `script_url` is a data: URL, due to the linked bug. We are passing the
  // origin to the browser side so that it can use it in cases like blob URL
  // origin resolving, which is based on the renderer side's origin.
  // TODO(crbug.com/40051700): Remove the mismatch cases.
  CreateWorkerHost(
      blink.mojom.DedicatedWorkerToken token,
      url.mojom.Url script_url,
      url.mojom.Origin origin,
      pending_receiver<blink.mojom.BrowserInterfaceBroker>
          browser_interface_broker,
      pending_receiver<DedicatedWorkerHost> host) =>
    (network.mojom.CrossOriginEmbedderPolicy parent_coep,
     // Used to notify feature usages that might affect back-forward cache
     // usages.
     pending_remote<BackForwardCacheControllerHost>?
         back_forward_cache_controller_host);

  // PlzDedicatedWorker:
  // The factory client should call this instead of CreateWorkerHost() when
  // PlzDedicatedWorker is enabled.
  //
  // Creates a new DedicatedWorkerHost, and requests to start top-level worker
  // script loading for `script_url` using `credentials_mode` and
  // `outside_fetch_client_settings_object`.
  // `blob_url_token` should be non-null when `script_url` is a blob URL.
  // `client` is used for notifying the renderer process of results of worker
  // host creation and script loading.
  // `storage_access_api_status` notifies the browser process if unpartitioned cookie
  // access should be granted to the worker. The browser process verifies this
  // by checking if it has a record of the STORAGE_ACCESS permission grant.
  CreateWorkerHostAndStartScriptLoad(
      blink.mojom.DedicatedWorkerToken token,
      url.mojom.Url script_url,
      network.mojom.CredentialsMode credentials_mode,
      blink.mojom.FetchClientSettingsObject
          outside_fetch_client_settings_object,
      pending_remote<blink.mojom.BlobURLToken>? blob_url_token,
      pending_remote<DedicatedWorkerHostFactoryClient> client,
      network.mojom.StorageAccessApiStatus storage_access_api_status);
};