chromium/services/device/public/mojom/BUILD.gn

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

import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//services/device/public/cpp/compute_pressure/buildflags.gni")

mojom("mojom") {
  generate_java = true
  sources = [
    "battery_monitor.mojom",
    "battery_status.mojom",
    "fingerprint.mojom",
    "geolocation.mojom",
    "geolocation_client_id.mojom",
    "geolocation_config.mojom",
    "geolocation_context.mojom",
    "geolocation_control.mojom",
    "hid.mojom",
    "input_service.mojom",
    "nfc.mojom",
    "nfc_provider.mojom",
    "power_monitor.mojom",
    "pressure_manager.mojom",
    "pressure_update.mojom",
    "public_ip_address_geolocation_provider.mojom",
    "screen_orientation.mojom",
    "screen_orientation_lock_types.mojom",
    "serial.mojom",
    "smart_card.mojom",
    "time_zone_monitor.mojom",
    "vibration_manager.mojom",
    "wake_lock.mojom",
    "wake_lock_context.mojom",
    "wake_lock_provider.mojom",
  ]

  public_deps = [
    ":geoposition",
    "//device/bluetooth/public/mojom",
    "//mojo/public/mojom/base",
    "//services/network/public/mojom",
    "//services/network/public/mojom:mojom_proxy_config",
    "//services/network/public/mojom:url_loader_base",
    "//ui/gfx/geometry/mojom",
    "//url/mojom:url_mojom_gurl",
    "//url/mojom:url_mojom_origin",
  ]

  if (is_chromeos_ash) {
    sources += [
      "mtp_file_entry.mojom",
      "mtp_manager.mojom",
      "mtp_storage_info.mojom",
    ]
  }

  cpp_typemaps = [
    {
      types = [
        {
          mojom = "device.mojom.BluetoothAddress"
          cpp = "::std::array<::uint8_t, 6>"
        },
      ]
      traits_public_deps = [ "//base" ]
    },
  ]

  # The blink variant of the Device Service mojom are depended on by the
  # blink platform target. All blink variant mojoms use WTF types, which are
  # part of the blink platform component. In order to avoid a dependency cycle,
  # these targets must be part of that component.
  export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
  export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
  export_header_blink = "third_party/blink/public/platform/web_common.h"

  visibility_blink = [
    "//third_party/blink/renderer/platform:blink_platform_public_deps",
    "//third_party/blink/renderer/platform/media:*",
    "//third_party/blink/public/mojom:mojom_platform_blink",
  ]
}

mojom("device_service") {
  sources = [ "device_service.mojom" ]

  # We can't depend on the Blink variant of ":generic_sensors", but we need the
  # non-Blink variant as a dependency. Blink can never use the DeviceService
  # interface directly anyway, so don't generate bindings for it.
  disable_variants = true
  cpp_only = true

  # The interfaces defined here are privileged, and not vended to a renderer, so
  # they are not fuzzable by javascript-based fuzzers.
  enable_js_fuzzing = false

  enabled_features = []
  if ((is_linux || is_chromeos) && use_udev) {
    enabled_features += [ "enable_input_device_manager" ]
  }

  if (!is_android) {
    enabled_features += [ "enable_hid" ]
  }

  if (enable_compute_pressure) {
    enabled_features += [ "enable_compute_pressure" ]
  }

  public_deps = [
    ":generic_sensor",
    ":geolocation_internals",
    ":mojom",
    ":usb",
    ":usb_test",
  ]
}

mojom("generic_sensor") {
  generate_java = true
  sources = [
    "sensor.mojom",
    "sensor_provider.mojom",
  ]

  export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
  export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
  export_header_blink = "third_party/blink/public/platform/web_common.h"

  visibility_blink = [
    ":mojom_blink",
    "//third_party/blink/public/mojom:mojom_platform_blink",
    "//third_party/blink/renderer/platform:blink_platform_public_deps",
  ]

  # Generic Sensor Mojom interfaces are exposed publicly to layout tests which
  # use prepackaged redistributable JS bindings. It is therefore not desirable
  # to scramble these messages.
  scramble_message_ids = false

  cpp_typemaps = [
    {
      types = [
        {
          mojom = "device.mojom.SensorConfiguration"
          cpp = "::device::PlatformSensorConfiguration"
        },
        {
          mojom = "device.mojom.SensorReadingRaw"
          cpp = "::device::SensorReading"
        },
      ]
      traits_headers = [
        "//services/device/public/cpp/generic_sensor/sensor_mojom_traits.h",
      ]
      traits_sources = [
        "//services/device/public/cpp/generic_sensor/sensor_mojom_traits.cc",
      ]
      traits_public_deps = [
        "//services/device/public/cpp/generic_sensor:sensor_configuration",
        "//services/device/public/cpp/generic_sensor:sensor_reading",
      ]
    },
  ]

  public_deps = [ "//mojo/public/mojom/base" ]
}

mojom("usb") {
  generate_java = true
  sources = [
    "usb_device.mojom",
    "usb_enumeration_options.mojom",
    "usb_manager.mojom",
    "usb_manager_client.mojom",
  ]

  public_deps = [
    "//mojo/public/mojom/base",
    "//url/mojom:url_mojom_gurl",
  ]

  # USB Mojom interfaces are exposed publicly to layout tests which use
  # prepackaged redistributable JS bindings. It is therefore not desirable to
  # scramble these messages.
  scramble_message_ids = false

  # The blink variant of the usb mojom is depended on by the blink platform
  # target. All blink variant mojoms use WTF types, which are part of the
  # blink platform component. In order to avoid a dependency cycle, these
  # targets must be part of that component.
  export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
  export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
  export_header_blink = "third_party/blink/public/platform/web_common.h"

  visibility_blink = [
    ":*",
    "//ash/components/arc/mojom:mojom_blink",
    "//third_party/blink/public/mojom/usb:usb_blink",
    "//third_party/blink/renderer/modules/webusb",
    "//chrome/browser/ui/webui/usb_internals:mojo_bindings_blink",
  ]

  webui_module_path = "/"

  # Generate legacy JS bindings in addition to WebUI TS bindings for Blink Web
  # Tests.
  generate_legacy_js_bindings = true
}

mojom("usb_test") {
  generate_java = true
  sources = [ "usb_manager_test.mojom" ]
  public_deps = [ "//url/mojom:url_mojom_gurl" ]
  webui_module_path = "/"
}

mojom("geoposition") {
  generate_java = true
  sources = [ "geoposition.mojom" ]
  public_deps = [ "//mojo/public/mojom/base:base" ]

  # The blink variant of the geoposition mojom is depended on by the blink
  # platform target. All blink variant mojoms use WTF types, which are part of
  # the blink platform component. In order to avoid a dependency cycle, these
  # targets must be part of that component.
  export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
  export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
  export_header_blink = "third_party/blink/public/platform/web_common.h"

  webui_module_path = "/"
  generate_legacy_js_bindings = true
}

mojom("geolocation_internals") {
  sources = [ "geolocation_internals.mojom" ]
  webui_module_path = "/"
  public_deps = [
    ":geoposition",
    "//mojo/public/mojom/base",
  ]
}