chromium/fuchsia_web/shell/web_engine_shell.cml

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
{
  include: [
    // CML shards intended for tests are used here because this component is
    // launched as a test. While it doesn't fit the typical use-case for a test
    // component, it's a useful way to be able to launch the component from a
    // host tool and have it run somewhere it can get the capabilities it needs
    // to function correctly.
    // TODO(crbug.com/42050572): Run as a non-test component.
    "//build/config/fuchsia/test/chromium_system_test_facet.shard.test-cml",
    "//build/config/fuchsia/test/elf_test_runner.shard.test-cml",
    "sys/component/realm_builder_absolute.shard.cml",

    "syslog/client.shard.cml",
  ],
  program: {
    binary: "web_engine_shell_exec",
  },


  use: [
    // Required in `--use-context-provider` mode.

    {
      protocol: [
        // Required to display the View in Scene Manager unless running in
        // `--headless` mode.
        "fuchsia.element.GraphicalPresenter",
      ],
      availability: "optional",
    },

    {
      protocol: [
        // The system ContextProvider is required to create the Context.
        "fuchsia.web.ContextProvider",
      ],
      availability: "optional",
    },

    // The remaining are provided from this Component to the `web_instance.cm`
    // via `CreateContextParams.service_directory`.

    {
      // Used to hold the cdm_data directory passed to the WebInstance.
      storage: "data",
      path: "/data",

      // The `--use-context-provider` mode  does not support
      // `--enable-web-instance-tmp` so there is no need to `use` "tmp" like
      // the `offer` when not in `--use-context-provider` mode.
    },
    {
      protocol: [
        // Required capabilities for all WebInstance configurations.
        "fuchsia.buildinfo.Provider",
        "fuchsia.device.NameProvider",
        "fuchsia.fonts.Provider",
        "fuchsia.hwinfo.Product",
        "fuchsia.intl.PropertyProvider",
        // "fuchsia.logger/LogSink", is included by the shard above.
        "fuchsia.memorypressure.Provider",
        "fuchsia.process.Launcher",
        "fuchsia.sysmem.Allocator",
        "fuchsia.sysmem2.Allocator",
      ],
      // TODO(crbug.com/42050582): Make required when `--use-context-provider`.
      availability: "optional",
    },
    {
      protocol: [
        // Allows CPU scheduling profiles to be applied to threads to
        // tune their performance, especially for media rendering.
        // TODO(crbug.com/42050308): Migrate to `fuchsia.scheduler`.
        "fuchsia.media.ProfileProvider",

        // Optionally used by the tracing service.
        // TODO(crbug.com/42050521): Offer only when enabled.
        "fuchsia.tracing.perfetto.ProducerConnector",
      ],
      availability: "optional",
    },
    {
      protocol: [
        // Required by `fuchsia.web/ContextFeatureFlags.NETWORK`.
        "fuchsia.net.interfaces.State",
        "fuchsia.net.name.Lookup",
        "fuchsia.posix.socket.Provider",

        // Required by `fuchsia.web/ContextFeatureFlags.AUDIO`.
        "fuchsia.media.Audio",
        "fuchsia.media.AudioDeviceEnumerator",
        "fuchsia.media.SessionAudioConsumerFactory",

        // Required by `fuchsia.web/ContextFeatureFlags.VULKAN`.
        // "fuchsia.tracing.provider.Registry" is optionally used by the
        // tracing service.
        "fuchsia.tracing.provider.Registry",
        "fuchsia.vulkan.loader.Loader",

        // Required by `fuchsia.web/ContextFeatureFlags.HARDWARE_VIDEO_DECODER`.
        "fuchsia.mediacodec.CodecFactory",
      ],
      // TODO(crbug.com/42050582): Make required when `--use-context-provider`.
      availability: "optional",
    },
    {
      // Required by `fuchsia.web/ContextFeatureFlags.WIDEVINE_CDM` if the value
      // of the GN arg `enable_widevine` at is true.
      // TODO(crbug.com/40875562): Use a shard to conditionally `use` based on
      // the build-time config.
      protocol: "fuchsia.media.drm.Widevine",
      availability: "optional",
    },
    {
      protocol: [
        // Required by the absence of `fuchsia.web/ContextFeatureFlags.HEADLESS`
        // unless running in `--headless` mode.
        "fuchsia.accessibility.semantics.SemanticsManager",
        "fuchsia.ui.composition.Allocator",
        "fuchsia.ui.composition.Flatland",
      ],
      availability: "optional",
    },
    {
      protocol: [
        // Required by `fuchsia.web/ContextFeatureFlags.KEYBOARD`.
        "fuchsia.ui.input3.Keyboard",

        // Required by `fuchsia.web/ContextFeatureFlags.VIRTUAL_KEYBOARD`.
        "fuchsia.input.virtualkeyboard.ControllerCreator",

        // Required by the absence of
        // `fuchsia.web/ContextFeatureFlags.DISABLE_DYNAMIC_CODE_GENERATION`.
        "fuchsia.kernel.VmexResource",
      ],
    },
  ],
  offer: [
    {
      // Required capabilities for WebInstanceHost in a child Component.
      protocol: [
        "fuchsia.feedback.ComponentDataRegister",
        "fuchsia.feedback.CrashReportingProductRegister",
      ],
      from: "parent",
      to: "#realm_builder",
    },

    // Offered for use by the relaunched
    // `fuchsia_web/shell/web_engine_shell_for_web_instance_host.cml`
    // TODO(crbug.com/42050572): Remove when running as a non-test component and
    // thus the relaunch is no longer needed.
    {
      protocol: [
        // Required to display the View in Scene Manager unless running in
        // `--headless` mode.
        "fuchsia.element.GraphicalPresenter",
      ],
      from: "parent",
      to: "#realm_builder",
      availability: "optional",
    },

    // The remaining are offered from the parent to `web_instance.cm` via
    // `RealmBuilder` when not in `--use-context-provider` mode.

    {
      // Used to hold the cdm_data directory passed to web_instance.
      storage: "data",
      from: "parent",
      to: "#realm_builder",
    },
    {
      // Used when launched with --enable-web-instance-tmp.
      storage: [ "tmp" ],
      from: "parent",
      to: "#realm_builder",
      availability: "optional",
    },
    {
      // The chromium test realm offers the system-wide config-data dir to test
      // components. Route the web_engine sub-directory of this as required by
      // WebInstanceHost.
      directory: "config-data",
      from: "parent",
      as: "config-data-for-web-instance",
      to: "#realm_builder",
      subdir: "web_engine",
      availability: "optional",
    },
    {
      // Holds ICU time zone data files.
      // See:
      // https://fuchsia.dev/fuchsia-src/concepts/process/namespaces?typical_directory_structure
      directory: "tzdata-icu",
      from: "parent",
      to: "#realm_builder",
    },
    {
      // Required by `fuchsia.web/ContextFeatureFlags.NETWORK`.
      directory: "root-ssl-certificates",
      from: "parent",
      to: "#realm_builder",
    },
    {
      // Required capabilities for all WebInstance configurations.
      protocol: [
        "fuchsia.buildinfo.Provider",
        "fuchsia.device.NameProvider",
        "fuchsia.fonts.Provider",
        "fuchsia.hwinfo.Product",
        "fuchsia.intl.PropertyProvider",
        // "fuchsia.logger/LogSink", is included by the shard above.
        "fuchsia.memorypressure.Provider",
        "fuchsia.process.Launcher",
        "fuchsia.sysmem.Allocator",
        "fuchsia.sysmem2.Allocator",
      ],
      from: "parent",
      to: "#realm_builder",
    },
    {
      protocol: [
        // Allows CPU scheduling profiles to be applied to threads to
        // tune their performance, especially for media rendering.
        // TODO(crbug.com/42050308): Migrate to `fuchsia.scheduler`.
        "fuchsia.media.ProfileProvider",

        // Optionally used by the tracing service.
        // TODO(crbug.com/42050521): Offer only when enabled.
        "fuchsia.tracing.perfetto.ProducerConnector",
      ],
      from: "parent",
      to: "#realm_builder",
      availability: "optional",
    },
    {
      protocol: [
        // Required by `fuchsia.web/ContextFeatureFlags.NETWORK`.
        "fuchsia.net.interfaces.State",
        "fuchsia.net.name.Lookup",
        "fuchsia.posix.socket.Provider",

        // Required by `fuchsia.web/ContextFeatureFlags.AUDIO`.
        "fuchsia.media.Audio",
        "fuchsia.media.AudioDeviceEnumerator",
        "fuchsia.media.SessionAudioConsumerFactory",

        // Required by `fuchsia.web/ContextFeatureFlags.VULKAN`.
        // "fuchsia.tracing.provider.Registry" is optionally used by the
        // tracing service.
        "fuchsia.tracing.provider.Registry",
        "fuchsia.vulkan.loader.Loader",

        // Required by `fuchsia.web/ContextFeatureFlags.HARDWARE_VIDEO_DECODER`.
        "fuchsia.mediacodec.CodecFactory",
      ],
      from: "parent",
      to: "#realm_builder",
    },
    {
      // Required by `fuchsia.web/ContextFeatureFlags.WIDEVINE_CDM` if the value
      // of the GN arg `enable_widevine` at is true.
      // TODO(crbug.com/40875562): Use a shard to conditionally `offer` based on
      // the build-time config.
      protocol: "fuchsia.media.drm.Widevine",
      from: "parent",
      to: "#realm_builder",
      availability: "optional",
    },
    {
      protocol: [
        // Required by the absence of `fuchsia.web/ContextFeatureFlags.HEADLESS`
        // unless running in `--headless` mode.
        "fuchsia.accessibility.semantics.SemanticsManager",
        "fuchsia.ui.composition.Allocator",
        "fuchsia.ui.composition.Flatland",
      ],
      from: "parent",
      to: "#realm_builder",
      availability: "optional",
    },
    {
      protocol: [
        // Required by `fuchsia.web/ContextFeatureFlags.KEYBOARD`.
        "fuchsia.ui.input3.Keyboard",

        // Required by `fuchsia.web/ContextFeatureFlags.VIRTUAL_KEYBOARD`.
        "fuchsia.input.virtualkeyboard.ControllerCreator",

        // Required by the absence of
        // `fuchsia.web/ContextFeatureFlags.DISABLE_DYNAMIC_CODE_GENERATION`.
        "fuchsia.kernel.VmexResource",
      ],
      from: "parent",
      to: "#realm_builder",
    },
  ],
  facets: {
    // TODO(crbug.com/42050572): Remove when converting to a non-test component.
    "fuchsia.test": {
      "deprecated-allowed-packages": [
        "web_engine",
        "web_engine_with_webui",
      ],
    },
  },
}