chromium/third_party/blink/common/BUILD.gn

# 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.

import("//build/config/features.gni")
import("//build/config/rust.gni")
import("//build/nocompile.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("//third_party/blink/renderer/build/scripts/scripts.gni")
import("//third_party/protobuf/proto_library.gni")

if (is_ios) {
  import("//build/config/ios/bundle_data_from_filelist.gni")
}

blink_python_runner("make_generated_permissions_policy_features") {
  script = "../renderer/build/scripts/make_permissions_policy_features.py"

  inputs = scripts_for_json5_files + [
             "../renderer/build/scripts/make_permissions_policy_features.py",
             "../renderer/core/permissions_policy/permissions_policy_features.json5",
             "../renderer/build/scripts/templates/permissions_policy_features_generated.cc.tmpl",
           ]
  outputs = [ "$root_gen_dir/third_party/blink/common/permissions_policy/permissions_policy_features_generated.cc" ]

  args = [
    rebase_path(
        "../renderer/core/permissions_policy/permissions_policy_features.json5",
        root_build_dir),
    "--output_dir",
    rebase_path("$root_gen_dir/third_party/blink/common/permissions_policy",
                root_build_dir),
  ]
}

blink_python_runner("make_generated_document_policy_features") {
  script = "../renderer/build/scripts/make_document_policy_features.py"

  inputs =
      scripts_for_json5_files + [
        "../renderer/build/scripts/make_document_policy_features.py",
        "../renderer/build/scripts/make_document_policy_features_util.py",
        "../renderer/core/permissions_policy/document_policy_features.json5",
        "../renderer/build/scripts/templates/document_policy_features.cc.tmpl",
      ]
  outputs = [ "$root_gen_dir/third_party/blink/common/permissions_policy/document_policy_features.cc" ]

  args = [
    rebase_path(
        "../renderer/core/permissions_policy/document_policy_features.json5",
        root_build_dir),
    "--output_dir",
    rebase_path("$root_gen_dir/third_party/blink/common/permissions_policy",
                root_build_dir),
  ]
}

blink_python_runner("make_generated_features") {
  script = "../renderer/build/scripts/make_common_features.py"

  inputs = scripts_for_json5_files + [
             "../renderer/build/scripts/make_common_features.py",
             "../renderer/platform/runtime_enabled_features.json5",
             "../renderer/build/scripts/templates/features_generated.cc.tmpl",
           ]
  outputs = [ "$root_gen_dir/third_party/blink/common/features_generated.cc" ]

  args = [
    rebase_path("../renderer/platform/runtime_enabled_features.json5",
                root_build_dir),
    "--output_dir",
    rebase_path("$root_gen_dir/third_party/blink/common", root_build_dir),
  ]

  visibility = [
    ":*",
    "//third_party/blink/public/common:java_features_srcjar",
  ]
}

blink_python_runner("make_generated_origin_trials") {
  script = "../renderer/build/scripts/make_origin_trials.py"

  inputs = scripts_for_json5_files + [
             "../renderer/build/scripts/make_origin_trials.py",
             "../renderer/platform/runtime_enabled_features.json5",
             "../renderer/build/scripts/templates/origin_trials.cc.tmpl",
           ]
  outputs = [
    "$root_gen_dir/third_party/blink/common/origin_trials/origin_trials.cc",
  ]

  args = [
    rebase_path("../renderer/platform/runtime_enabled_features.json5",
                root_build_dir),
    "--output_dir",
    rebase_path("$root_gen_dir/third_party/blink/common/origin_trials",
                root_build_dir),
  ]
}

blink_python_runner("make_runtime_feature_state_contexts_impl") {
  script =
      "../renderer/build/scripts/make_runtime_feature_state_contexts_impl.py"

  inputs = scripts_for_json5_files + [
             "../renderer/platform/runtime_enabled_features.json5",
             "../renderer/build/scripts/templates/runtime_feature_state_context.cc.tmpl",
           ]

  outputs = [ "$root_gen_dir/third_party/blink/common/runtime_feature_state/runtime_feature_state_context.cc" ]

  args = [
    rebase_path("../renderer/platform/runtime_enabled_features.json5",
                root_build_dir),
    "--output_dir",
    rebase_path("$root_gen_dir/third_party/blink/common/runtime_feature_state/",
                root_build_dir),
  ]
}

config("blink_common_implementation") {
  defines = [ "BLINK_COMMON_IMPLEMENTATION=1" ]
}

source_set("common") {
  # No target should directly depend on this target since this is just the
  # source set rather than the actual component that can be linked to.
  # Dependencies instead should be to //third_party/blink/public/common:common.
  visibility = [
    ":*",
    "//third_party/blink/public:all_blink",
    "//third_party/blink/public/common",
  ]

  configs += [ ":blink_common_implementation" ]

  sources = [
    # NOTE: Please do not add public headers that need to be referenced from
    # outside WebKit, add them in public/common instead.
    "associated_interfaces/associated_interface_provider.cc",
    "associated_interfaces/associated_interface_registry.cc",
    "blob/blob_utils.cc",
    "bluetooth/web_bluetooth_device_id.cc",
    "cache_storage/cache_storage_utils.cc",
    "chrome_debug_urls.cc",
    "client_hints/client_hints.cc",
    "client_hints/enabled_client_hints.cc",
    "context_menu_data/context_menu_mojom_traits.cc",
    "context_menu_data/context_menu_params_builder.cc",
    "context_menu_data/untrustworthy_context_menu_params.cc",
    "crash_helpers.cc",
    "crash_helpers.h",
    "custom_handlers/protocol_handler_utils.cc",
    "device_memory/approximated_device_memory.cc",
    "dom_storage/session_storage_namespace_id.cc",
    "features.cc",
    "fenced_frame/fenced_frame_utils.cc",
    "fenced_frame/redacted_fenced_frame_config.cc",
    "fenced_frame/redacted_fenced_frame_config_mojom_traits.cc",
    "fetch/fetch_api_request_body_mojom_traits.cc",
    "frame/delegated_capability_request_token.cc",
    "frame/frame_ad_evidence.cc",
    "frame/frame_ad_evidence_mojom_traits.cc",
    "frame/frame_owner_element_type_mojom_traits.cc",
    "frame/frame_policy.cc",
    "frame/frame_policy_mojom_traits.cc",
    "frame/frame_visual_properties.cc",
    "frame/frame_visual_properties_mojom_traits.cc",
    "frame/from_ad_state.cc",
    "frame/user_activation_state.cc",
    "frame/view_transition_state_mojom_traits.cc",
    "indexeddb/indexed_db_default_mojom_traits.cc",
    "indexeddb/indexeddb_key.cc",
    "indexeddb/indexeddb_key_path.cc",
    "indexeddb/indexeddb_key_range.cc",
    "indexeddb/indexeddb_metadata.cc",
    "input/synthetic_web_input_event_builders.cc",
    "input/web_coalesced_input_event.cc",
    "input/web_coalesced_input_event_mojom_traits.cc",
    "input/web_gesture_event.cc",
    "input/web_input_event.cc",
    "input/web_keyboard_event.cc",
    "input/web_mouse_event.cc",
    "input/web_mouse_wheel_event.cc",
    "input/web_pointer_event.cc",
    "input/web_touch_event.cc",
    "interest_group/ad_auction_constants.cc",
    "interest_group/ad_auction_currencies.cc",
    "interest_group/ad_display_size.cc",
    "interest_group/ad_display_size_mojom_traits.cc",
    "interest_group/ad_display_size_utils.cc",
    "interest_group/auction_config.cc",
    "interest_group/auction_config_mojom_traits.cc",
    "interest_group/devtools_serialization.cc",
    "interest_group/interest_group.cc",
    "interest_group/interest_group_mojom_traits.cc",
    "link_to_text/link_to_text_mojom_traits.cc",
    "loader/inter_process_time_ticks_converter.cc",
    "loader/lcp_critical_path_predictor_util.cc",
    "loader/loader_constants.cc",
    "loader/mime_sniffing_throttle.cc",
    "loader/mime_sniffing_url_loader.cc",
    "loader/network_utils.cc",
    "loader/record_load_histograms.cc",
    "loader/referrer_utils.cc",
    "loader/resource_type_util.cc",
    "loader/throttling_url_loader.cc",
    "loader/url_loader_factory_bundle.cc",
    "loader/url_loader_factory_bundle_mojom_traits.cc",
    "loader/url_loader_throttle.cc",
    "logging/logging_utils.cc",
    "manifest/manifest.cc",
    "manifest/manifest_icon_selector.cc",
    "manifest/manifest_util.cc",
    "media/watch_time_component.cc",
    "media/watch_time_reporter.cc",
    "mediastream/media_device_id.cc",
    "mediastream/media_devices.cc",
    "mediastream/media_devices_mojom_traits.cc",
    "mediastream/media_stream_controls.cc",
    "mediastream/media_stream_mojom_traits.cc",
    "mediastream/media_stream_request.cc",
    "messaging/accelerated_static_bitmap_image_mojom_traits.cc",
    "messaging/cloneable_message.cc",
    "messaging/cloneable_message_mojom_traits.cc",
    "messaging/message_port_channel.cc",
    "messaging/message_port_descriptor.cc",
    "messaging/message_port_descriptor_mojom_traits.cc",
    "messaging/string_message_codec.cc",
    "messaging/task_attribution_id_mojom_traits.cc",
    "messaging/transferable_message.cc",
    "messaging/transferable_message_mojom_traits.cc",
    "messaging/web_message_port.cc",
    "mime_util/mime_util.cc",
    "navigation/impression_mojom_traits.cc",
    "navigation/navigation_params.cc",
    "navigation/navigation_policy.cc",
    "navigation/navigation_policy_mojom_traits.cc",
    "navigation/prefetched_signed_exchange_info_mojom_traits.cc",
    "notifications/notification_mojom_traits.cc",
    "notifications/notification_resources.cc",
    "notifications/platform_notification_data.cc",
    "origin_trials/manual_completion_origin_trial_features.cc",
    "origin_trials/navigation_origin_trial_features.cc",
    "origin_trials/origin_trials_settings_provider.cc",
    "origin_trials/persistent_origin_trials.cc",
    "origin_trials/trial_token.cc",
    "origin_trials/trial_token_result.cc",
    "origin_trials/trial_token_validator.cc",
    "page/browsing_context_group_info.cc",
    "page/browsing_context_group_info_mojom_traits.cc",
    "page/color_provider_color_maps_mojom_traits.cc",
    "page/content_to_visible_time_reporter.cc",
    "page/drag_mojom_traits.cc",
    "page/drag_operation.cc",
    "page/page_zoom.cc",
    "page_state/page_state.cc",
    "page_state/page_state_serialization.cc",
    "peerconnection/webrtc_ip_handling_policy.cc",
    "permissions/permission_utils.cc",
    "permissions_policy/document_policy.cc",
    "permissions_policy/origin_with_possible_wildcards.cc",
    "permissions_policy/permissions_policy.cc",
    "permissions_policy/permissions_policy_declaration.cc",
    "permissions_policy/permissions_policy_features.cc",
    "permissions_policy/permissions_policy_features_generated.h",
    "permissions_policy/permissions_policy_features_internal.cc",
    "permissions_policy/permissions_policy_features_internal.h",
    "permissions_policy/permissions_policy_mojom_traits.cc",
    "permissions_policy/policy_value.cc",
    "renderer_preferences/renderer_preferences.cc",
    "renderer_preferences/renderer_preferences_mojom_traits.cc",
    "safe_url_pattern.cc",
    "safe_url_pattern_mojom_traits.cc",
    "scheduler/web_scheduler_tracked_feature.cc",
    "scheme_registry.cc",
    "security/address_space_feature.cc",
    "service_worker/service_worker_loader_helpers.cc",
    "service_worker/service_worker_router_rule.cc",
    "service_worker/service_worker_router_rule_mojom_traits.cc",
    "service_worker/service_worker_scope_match.cc",
    "service_worker/service_worker_status_code.cc",
    "service_worker/service_worker_type_converters.cc",
    "shared_storage/module_script_downloader.cc",
    "shared_storage/shared_storage_mojom_traits.cc",
    "shared_storage/shared_storage_utils.cc",
    "storage_key/storage_key.cc",
    "storage_key/storage_key_mojom_traits.cc",
    "switches.cc",
    "thread_safe_browser_interface_broker_proxy.cc",
    "unique_name/unique_name_helper.cc",
    "use_counter/use_counter_feature.cc",
    "use_counter/use_counter_feature_tracker.cc",
    "user_agent/user_agent_metadata.cc",
    "web_package/signed_exchange_consts.cc",
    "web_package/web_package_request_matcher.cc",
    "web_preferences/web_preferences.cc",
    "web_preferences/web_preferences_mojom_traits.cc",
    "widget/constants.cc",
    "widget/device_emulation_params_mojom_traits.cc",
    "widget/visual_properties.cc",
    "widget/visual_properties_mojom_traits.cc",
  ]

  sources += get_target_outputs(":make_generated_document_policy_features")
  sources += get_target_outputs(":make_generated_features")
  sources += get_target_outputs(":make_generated_origin_trials")
  sources += get_target_outputs(":make_generated_permissions_policy_features")
  sources += get_target_outputs(":make_runtime_feature_state_contexts_impl")

  public_deps = [
    ":make_generated_document_policy_features",
    ":make_generated_features",
    ":make_generated_origin_trials",
    ":make_generated_permissions_policy_features",
    ":make_runtime_feature_state_contexts_impl",
    "//components/viz/common:common",
    "//third_party/blink/common/privacy_budget:privacy_budget",
    "//third_party/blink/public/common:common_export",
    "//third_party/blink/public/common:headers",
  ]

  deps = [
    "//base",
    "//build:android_buildflags",
    "//build:chromecast_buildflags",
    "//build:chromeos_buildflags",
    "//media/capture:capture_base",
    "//media/capture/mojom:video_capture_mojom_support",
    "//mojo/public/cpp/system",
    "//net",
    "//services/metrics/public/cpp:metrics_cpp",
    "//services/metrics/public/cpp:ukm_builders",
    "//services/metrics/public/mojom:mojom",
    "//services/network/public/cpp:cpp",
    "//third_party/blink/public/common:buildflags",
    "//third_party/re2",
    "//ui/base:base",
    "//ui/base/dragdrop/mojom:mojom_shared",
    "//ui/base/mojom",
    "//ui/display",
    "//ui/display/mojom",
    "//ui/events:events_base",
    "//ui/events/mojom:event_latency_metadata_mojom",
    "//ui/latency/mojom:shared_mojom_traits",
  ]

  if (enable_rust_crash) {
    deps += [ "//third_party/blink/common/rust_crash" ]
  }

  # If use_blink is used then it needs to depend on //media
  if (use_blink) {
    deps += [ "//media" ]
  }

  if (is_android || is_win) {
    sources += [
      "font_unique_name_lookup/font_table_matcher.cc",
      "font_unique_name_lookup/font_table_persistence.cc",
      "font_unique_name_lookup/icu_fold_case_util.cc",
    ]

    deps += [ "//third_party/icu" ]
  }

  if (is_win) {
    deps += [ "//ui/gfx/" ]
  }

  if (is_chromeos || is_android || is_win || is_castos || is_fuchsia) {
    defines = [ "ENABLE_PROTECTED_MEDIA_IDENTIFIER_PERMISSION" ]
  }
}

test("blink_common_unittests") {
  visibility = [ "*" ]
  deps = [
    ":common_unittests_sources",
    "//services/metrics/public/cpp:metrics_cpp",
    "//services/metrics/public/cpp:ukm_builders",
    "//services/metrics/public/mojom:mojom",
    "//third_party/blink/common/privacy_budget:unit_tests",
    "//third_party/blink/public/common",
    "//ui/gfx:test_support",
  ]
  if (is_android) {
    deps += [ "//media/base/android:media_java" ]
  }
  if (is_ios) {
    bundle_deps = [ ":blink_common_unittests_pak_bundle_data" ]
  }
  if (is_fuchsia) {
    additional_manifest_fragments =
        [ "//build/config/fuchsia/test/mark_vmo_executable.shard.test-cml" ]
  }

  data_deps = [ ":common_unittests_data" ]
}

source_set("common_unittests_sources") {
  testonly = true

  sources = [
    "bluetooth/web_bluetooth_device_id_unittest.cc",
    "client_hints/client_hints_unittest.cc",
    "client_hints/enabled_client_hints_unittest.cc",
    "device_memory/approximated_device_memory_unittest.cc",
    "frame/delegated_capability_request_token_unittest.cc",
    "frame/user_activation_state_unittest.cc",
    "indexeddb/indexeddb_key_unittest.cc",
    "input/synthetic_web_input_event_builders_unittest.cc",
    "input/web_input_event_unittest.cc",
    "interest_group/ad_auction_currencies_unittest.cc",
    "interest_group/ad_display_size_mojom_traits_test.cc",
    "interest_group/ad_display_size_unittest.cc",
    "interest_group/ad_display_size_utils_unittest.cc",
    "interest_group/auction_config_mojom_traits_test.cc",
    "interest_group/auction_config_test_util.cc",
    "interest_group/auction_config_test_util.h",
    "interest_group/devtools_serialization_unittest.cc",
    "interest_group/interest_group_mojom_traits_test.cc",
    "interest_group/interest_group_unittest.cc",
    "interest_group/test/interest_group_test_utils_unittest.cc",
    "loader/inter_process_time_ticks_converter_unittest.cc",
    "loader/mime_sniffing_throttle_unittest.cc",
    "loader/referrer_utils_unittest.cc",
    "loader/throttling_url_loader_unittest.cc",
    "manifest/manifest_icon_selector_unittest.cc",
    "manifest/manifest_util_unittest.cc",
    "media/watch_time_component_unittest.cc",
    "mediastream/media_devices_mojom_traits_unittest.cc",
    "mediastream/media_devices_unittest.cc",
    "mediastream/media_stream_mojom_traits_unittest.cc",
    "messaging/message_port_descriptor_unittest.cc",
    "mime_util/mime_util_unittest.cc",
    "notifications/notification_mojom_traits_unittest.cc",
    "notifications/platform_notification_data_unittest.cc",
    "origin_trials/origin_trials_settings_provider_unittest.cc",
    "origin_trials/origin_trials_test.cc",
    "origin_trials/trial_token_unittest.cc",
    "origin_trials/trial_token_validator_unittest.cc",
    "page/browsing_context_group_info_mojom_traits_test.cc",
    "page/browsing_context_group_info_unittest.cc",
    "page/content_to_visible_time_reporter_unittest.cc",
    "page_state/page_state_serialization_unittest.cc",
    "permissions_policy/document_policy_unittest.cc",
    "permissions_policy/origin_with_possible_wildcards_unittest.cc",
    "permissions_policy/permissions_policy_declaration_unittest.cc",
    "permissions_policy/permissions_policy_features_internal.h",
    "permissions_policy/permissions_policy_unittest.cc",
    "permissions_policy/policy_value_unittest.cc",
    "scheduler/web_scheduler_tracked_feature_unittest.cc",
    "security/address_space_feature_unittest.cc",
    "service_worker/service_worker_router_rule_mojom_traits_unittest.cc",
    "service_worker/service_worker_scope_match_unittest.cc",
    "shared_storage/module_script_downloader_unittest.cc",
    "shared_storage/shared_storage_mojom_traits_unittest.cc",
    "storage_key/storage_key_mojom_traits_unittest.cc",
    "storage_key/storage_key_unittest.cc",
    "test/run_all_unittests.cc",
    "tokens/multi_token_unittest.cc",
    "tokens/tokens_mojom_traits_unittest.cc",
    "unique_name/unique_name_helper_unittest.cc",
    "user_agent/user_agent_metadata_unittest.cc",
    "web_package/web_package_request_matcher_unittest.cc",
  ]

  deps = [
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//components/ukm:test_support",
    "//components/viz/common",
    "//media/capture:capture_base",
    "//media/capture/mojom:video_capture_types",
    "//mojo/core/embedder",
    "//mojo/public/cpp/test_support:test_utils",
    "//net",
    "//net:test_support",
    "//services/device:test_support",
    "//services/network:test_support",
    "//skia/public/mojom",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/blink/public:test_headers",
    "//third_party/blink/public/common:buildflags",
    "//third_party/blink/public/common:headers",
    "//third_party/blink/public/mojom/tokens:tokens_traits_headers",
    "//third_party/boringssl",
    "//ui/gfx:test_support",
    "//url/mojom:url_mojom_gurl",
    "//v8",
    "//v8:v8_libplatform",
  ]

  if (enable_nocompile_tests) {
    deps += [ ":blink_common_nocompile_tests" ]
  }

  if (!is_android) {
    # TODO(crbug.com/845384): Enable these tests also on Android. Currently
    # they are excluded as they require V8 environment but V8 snapshot is
    # not available in the current minimum test setting.
    sources += [
      "messaging/string_message_codec_unittest.cc",
      "messaging/web_message_port_unittest.cc",
    ]
  }

  if (is_android || is_win) {
    sources += [
      "font_unique_name_lookup/font_table_matcher_unittest.cc",
      "font_unique_name_lookup/icu_fold_case_util_unittest.cc",
    ]
  }
}

group("common_unittests_data") {
  data = [ "page_state/test_data/" ]
}

if (is_ios) {
  bundle_data_from_filelist("blink_common_unittests_pak_bundle_data") {
    testonly = true
    filelist_name = "blink_common_unittests_bundle_data.filelist"
  }
}

static_library("test_support") {
  testonly = true

  sources = [
    "interest_group/test/interest_group_test_utils.cc",
    "interest_group/test_interest_group_builder.cc",
    "origin_trials/scoped_test_origin_trial_policy.cc",
  ]

  deps = [
    "//base",
    "//testing/gtest",
    "//third_party/blink/public:test_headers",
  ]

  visibility = [
    ":common_unittests_sources",
    "//third_party/blink/public:test_support",
  ]
}

if (use_fuzzing_engine_with_lpm) {
  fuzzer_test("storage_key_proto_fuzzer") {
    sources = [ "storage_key/storage_key_proto_fuzzer.cc" ]
    deps = [
      ":common",
      "//base/test:test_support",
      "//third_party/blink/public/common:storage_key_proto",
      "//third_party/blink/public/common:storage_key_proto_converter",
      "//third_party/libprotobuf-mutator",
    ]
  }

  fuzzer_test("storage_key_string_fuzzer") {
    sources = [ "storage_key/storage_key_string_fuzzer.cc" ]
    deps = [
      ":common",
      "//base/test:test_support",
      "//third_party/blink/public/common",
    ]
    seed_corpus = "//third_party/blink/common/storage_key/storage_key_corpus"
  }

  fuzzer_test("ad_display_size_parser_fuzzer") {
    sources = [ "interest_group/ad_display_size_parser_fuzzer.cc" ]
    deps = [
      ":common",
      "//content/public/common",
    ]
  }
}

if (enable_nocompile_tests) {
  nocompile_source_set("blink_common_nocompile_tests") {
    sources = [ "tokens/multi_token_nocompile.nc" ]

    deps = [
      "//base",
      "//third_party/blink/public/common",
    ]
  }
}