chromium/chrome/browser/extensions/api/BUILD.gn

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

import("//chrome/common/extensions/api/api_sources.gni")
import("//chrome/common/features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//pdf/features.gni")
import("//tools/json_schema_compiler/json_schema_api.gni")

assert(enable_extensions,
       "Cannot depend on extensions because enable_extensions=false.")

# This should be:
# The set of all targets needed to build out the extension API implementations
# and any necessary steps to register or instantiate them.
# Embedders should usually depend on this.
# Right now, there's currently a number of other targets that are (not ideally)
# sharded out. See https://crbug.com/883570.
group("api") {
  public_deps = [ "//chrome/browser/extensions/api:api_implementations" ]
}

# The collection of API implementations.
group("api_implementations") {
  # TODO(crbug.com/40245282): Add more API implementations here.
  public_deps = [
    "//chrome/browser/extensions/api/activity_log_private",
    "//chrome/browser/extensions/api/autofill_private",
    "//chrome/browser/extensions/api/command_line_private",
    "//chrome/browser/extensions/api/context_menus",
    "//chrome/browser/extensions/api/cookies",
    "//chrome/browser/extensions/api/desktop_capture",
    "//chrome/browser/extensions/api/downloads_internal",
    "//chrome/browser/extensions/api/font_settings",
    "//chrome/browser/extensions/api/mdns",
    "//chrome/browser/extensions/api/module",
    "//chrome/browser/extensions/api/omnibox",
    "//chrome/browser/extensions/api/page_capture",
    "//chrome/browser/extensions/api/permissions",
    "//chrome/browser/extensions/api/preference",
    "//chrome/browser/extensions/api/processes",
    "//chrome/browser/extensions/api/scripting",
    "//chrome/browser/extensions/api/webrtc_desktop_capture_private",
    "//chrome/browser/extensions/api/webrtc_logging_private",
  ]

  if (enable_pdf) {
    public_deps += [ "//chrome/browser/extensions/api/pdf_viewer_private" ]
  }

  if (enable_service_discovery) {
    public_deps += [ "//chrome/browser/extensions/api/mdns" ]
  }

  if (is_chromeos) {
    public_deps += [
      "//chrome/browser/chromeos/extensions/smart_card_provider_private",
      "//chrome/browser/extensions/api/document_scan",
    ]
  }

  if (is_chromeos_ash) {
    public_deps += [ "//chrome/browser/extensions/api/crash_report_private" ]
  }
}

# The step necessary to generate the code to register the corresponding
# ExtensionFunctions in order to map the function string name with their
# implementation.
function_registration("api_registration") {
  sources = chrome_extensions_api_schema_sources +
            chrome_extensions_api_uncompiled_sources
  impl_dir = "//chrome/browser/extensions/api"
  configs = [ "//build/config:precompiled_headers" ]
  bundle_name = "Chrome"
  root_namespace = chrome_extensions_api_root_namespace
  schema_include_rules = chrome_extensions_api_schema_include_rules

  deps = [
    # This is not directly included by the target, but specified here
    # to avoid cyclic dependency chain related to private_membership
    # protos.
    "//components/policy/proto",

    # Different APIs include headers from these targets.
    "//chrome/common",
    "//chrome/common:mojo_bindings",
    "//components/autofill/core/common/mojom:mojo_types",
    "//components/omnibox/browser",
    "//components/translate/core/browser",
    "//components/zoom",
    "//content/public/browser",
    "//extensions/browser",
    "//extensions/browser/api:api_implementations",
    "//extensions/common/api",

    # Different APIs include some headers from chrome/common that in turn
    # include generated headers from these targets.
    # TODO(brettw) this should be made unnecessary if possible.
    "//chrome/common/extensions/api",
    "//components/sync",
    "//skia",
    "//third_party/metrics_proto",
    "//ui/accessibility:ax_enums_mojo",
  ]
  if (is_chromeos) {
    deps += [
      "//chrome/browser/chromeos/extensions:constants",
      "//chrome/browser/chromeos/extensions/system_log",
    ]
  }

  if (is_chromeos_ash) {
    deps += [
      "//chrome/browser/ash/extensions/autotest_private",
      "//chrome/browser/ash/extensions/file_manager",
    ]
  }
}

# KeyedService factories initialization.
source_set("keyed_service_factories") {
  sources = [
    "api_browser_context_keyed_service_factories.cc",
    "api_browser_context_keyed_service_factories.h",
  ]

  deps = [
    ":api_implementations",
    "//chrome/browser/extensions",
  ]

  if (is_chromeos) {
    deps += [
      "//chrome/browser/chromeos/extensions/login_screen/login_state",
      "//chrome/browser/chromeos/extensions/wm",
    ]
  }
}

if (is_win) {
  # The files below are required to exercise the code that properly launches
  # Native Hosts with paths containing characters that are problematic for
  # cmd.exe. crbug.com/335558
  executable("native_messaging_test_echo_host") {
    testonly = true
    sources = [ "messaging/native_messaging_test_echo_host.cc" ]
    deps = [ "//base" ]
  }

  copy("native_messaging_test_echo_&_host") {
    testonly = true
    src_tool = ":native_messaging_test_echo_host"
    sources = [ get_label_info(src_tool, "root_out_dir") +
                "/native_messaging_test_echo_host.exe" ]
    outputs = [ "$root_build_dir/native_messaging_test_echo_&_host.exe" ]
    deps = [ src_tool ]
  }

  copy("native_messaging_test_echo_space_host") {
    testonly = true
    src_tool = ":native_messaging_test_echo_host"
    sources = [ get_label_info(src_tool, "root_out_dir") +
                "/native_messaging_test_echo_host.exe" ]
    outputs = [ "$root_build_dir/native_messaging_test_echo_ _host.exe" ]
    deps = [ src_tool ]
  }
}