chromium/components/safe_browsing/android/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/android/config.gni")
import("//build/config/android/rules.gni")
import("//components/safe_browsing/buildflags.gni")
import("//third_party/jni_zero/jni_zero.gni")
import("//third_party/libprotobuf-mutator/fuzzable_proto_library.gni")

android_library("safe_browsing_java") {
  deps = [
    "//base:base_java",
    "//build/android:build_java",
    "//third_party/androidx:androidx_annotation_annotation_java",
    "//third_party/jni_zero:jni_zero_java",
  ]

  srcjar_deps = [
    ":java_enums",
    ":jni_headers",
    ":sb_java_features_srcjar",
  ]

  sources = [
    "java/src/org/chromium/components/safe_browsing/SafeBrowsingApiBridge.java",
    "java/src/org/chromium/components/safe_browsing/SafeBrowsingApiHandler.java",
    "java/src/org/chromium/components/safe_browsing/SafetyNetApiHandler.java",
  ]
}

# Expose Safe Browsing feature flags to Java code
java_cpp_features("sb_java_features_srcjar") {
  visibility = [ ":*" ]
  sources = [ "//components/safe_browsing/core/common/features.cc" ]
  template = "java/src/org/chromium/components/safe_browsing/SafeBrowsingFeatures.java.tmpl"
}

fuzzable_proto_library("realtimeallowlist_proto") {
  proto_in_dir = "//"
  sources = [ "proto/realtimeallowlist.proto" ]
}

generate_jni("jni_headers") {
  sources = [
    "java/src/org/chromium/components/safe_browsing/SafeBrowsingApiBridge.java",
  ]
}

# This target is for the mobile version.
group("safe_browsing_mobile") {
  deps = [
    ":remote_database_manager",
    ":safe_browsing_api_handler",
    ":safe_browsing_api_handler_util",
    "//components/safe_browsing/core/browser/db:safe_browsing_db_shared",
  ]

  if (safe_browsing_mode == 2) {
    deps += [ ":real_time_url_checks_allowlist" ]
  }
}

if (safe_browsing_mode == 2) {
  static_library("real_time_url_checks_allowlist") {
    sources = [
      "real_time_url_checks_allowlist.cc",
      "real_time_url_checks_allowlist.h",
    ]

    configs += [ "//build/config/compiler:wexit_time_destructors" ]

    deps = [
      "//base",
      "//components/resources:components_resources",
      "//components/safe_browsing/android:realtimeallowlist_proto",
      "//components/safe_browsing/core/browser/db:v4_protocol_manager_util",
      "//components/safe_browsing/core/common",
      "//ui/base:base",
      "//url",
    ]
  }
}

static_library("remote_database_manager") {
  sources = [
    "remote_database_manager.cc",
    "remote_database_manager.h",
  ]

  configs += [ "//build/config/compiler:wexit_time_destructors" ]

  deps = [
    ":safe_browsing_api_handler",
    "//base:base",
    "//components/safe_browsing/core/browser/db:database_manager",
    "//components/safe_browsing/core/browser/db:v4_get_hash_protocol_manager",
    "//components/safe_browsing/core/browser/db:v4_protocol_manager_util",
    "//components/safe_browsing/core/common",
    "//components/variations",
    "//content/public/browser",
    "//net",
    "//services/network/public/mojom",
    "//url",
  ]

  if (safe_browsing_mode == 2) {
    deps += [ ":real_time_url_checks_allowlist" ]
  }
}

static_library("safe_browsing_api_handler_util") {
  sources = [
    "safe_browsing_api_handler_util.cc",
    "safe_browsing_api_handler_util.h",
  ]

  configs += [ "//build/config/compiler:wexit_time_destructors" ]

  deps = [
    "//base",
    "//components/safe_browsing/core/browser/db:util",
  ]
}

source_set("safe_browsing_api_handler") {
  sources = [
    "safe_browsing_api_handler_bridge.cc",
    "safe_browsing_api_handler_bridge.h",
  ]

  configs += [ "//build/config/compiler:wexit_time_destructors" ]

  deps = [
    ":jni_headers",
    ":safe_browsing_api_handler_util",
    "//base",
    "//components/safe_browsing:buildflags",
    "//components/safe_browsing/core/browser/db:util",
    "//components/safe_browsing/core/common",
    "//content/public/browser:browser",
    "//url",
  ]
}

android_library("native_java_unittests_java") {
  testonly = true
  deps = [
    ":safe_browsing_java",
    "//base:base_java",
    "//base:base_java_test_support",
    "//third_party/jni_zero:jni_zero_java",
    "//third_party/junit",
  ]

  srcjar_deps = [ ":native_j_unittests_jni_headers" ]
  sources = [ "native_java_unittests/src/org/chromium/components/safe_browsing/SafeBrowsingApiHandlerBridgeNativeUnitTestHelper.java" ]
}

generate_jni("native_j_unittests_jni_headers") {
  testonly = true
  sources = [ "native_java_unittests/src/org/chromium/components/safe_browsing/SafeBrowsingApiHandlerBridgeNativeUnitTestHelper.java" ]
}

source_set("unit_tests_mobile") {
  testonly = true
  sources = [
    "remote_database_manager_unittest.cc",
    "safe_browsing_api_handler_bridge_unittest.cc",
    "safe_browsing_api_handler_util_unittest.cc",
  ]
  deps = [
    ":native_j_unittests_jni_headers",
    ":native_java_unittests_java",
    ":remote_database_manager",
    ":safe_browsing_api_handler",
    ":safe_browsing_api_handler_util",
    "//base",
    "//components/resources:components_resources_grit",
    "//components/safe_browsing/android:realtimeallowlist_proto",
    "//components/safe_browsing/core/browser/db:database_manager",
    "//components/safe_browsing/core/browser/db:unit_tests_shared",
    "//components/safe_browsing/core/browser/db:util",
    "//components/safe_browsing/core/browser/db:v4_test_util",
    "//components/safe_browsing/core/common",
    "//components/variations",
    "//content/test:test_support",
    "//services/network:test_support",
    "//services/network/public/mojom",
    "//testing/gtest",
    "//url",
  ]

  if (safe_browsing_mode == 2) {
    sources += [
      "real_time_url_checks_allowlist_resource_file_unittest.cc",
      "real_time_url_checks_allowlist_unittest.cc",
    ]
    deps += [ ":real_time_url_checks_allowlist" ]
  }
}

source_set("referring_app_info") {
  sources = [ "referring_app_info.h" ]
  deps = [
    "//components/safe_browsing/core/common/proto:csd_proto",
    "//url",
  ]
}

java_cpp_enum("java_enums") {
  sources = [ "safe_browsing_api_handler_util.h" ]
}