chromium/ui/base/clipboard/BUILD.gn

# Copyright 2019 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/ozone.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//testing/libfuzzer/fuzzer_test.gni")

component("clipboard_types") {
  output_name = "ui_base_clipboard_types"
  sources = [
    "clipboard_buffer.h",
    "clipboard_constants.cc",
    "clipboard_constants.h",
  ]

  if (use_blink) {
    sources += [ "clipboard_format_type.h" ]

    if (is_ios) {
      sources += [ "clipboard_format_type_ios.mm" ]
    }
  }

  if (is_android) {
    sources += [ "clipboard_format_type_android.cc" ]
  }

  if (is_mac) {
    sources += [ "clipboard_format_type_mac.mm" ]
  }

  if (is_apple) {
    sources += [ "clipboard_constants_mac.mm" ]
  }

  if (is_win) {
    sources += [ "clipboard_format_type_win.cc" ]
  }

  if (use_aura && !is_win) {
    sources += [ "clipboard_format_type_aura.cc" ]
  }

  defines = [ "IS_UI_BASE_CLIPBOARD_TYPES_IMPL" ]

  deps = [ "//base" ]

  frameworks = []
  if (is_apple) {
    frameworks += [ "Foundation.framework" ]
  }
  if (is_mac) {
    frameworks += [
      "AppKit.framework",
      "UniformTypeIdentifiers.framework",
    ]
  }
}

component("file_info") {
  output_name = "ui_base_file_info"

  sources = [
    "file_info.cc",
    "file_info.h",
  ]

  defines = [ "IS_UI_BASE_FILE_INFO_IMPL" ]

  deps = [ "//base" ]
}

# This is a source set because it needs to be included only on the Mac for the
# final executable, but needs to be included on any platform for the fuzzer.
source_set("url_file_parser") {
  sources = [
    "url_file_parser.cc",
    "url_file_parser.h",
  ]

  deps = [ "//base" ]
}

component("clipboard") {
  output_name = "ui_base_clipboard"

  sources = [
    "clipboard.cc",
    "clipboard.h",
    "clipboard_metrics.cc",
    "clipboard_metrics.h",
    "clipboard_monitor.cc",
    "clipboard_monitor.h",
    "clipboard_observer.cc",
    "clipboard_observer.h",
    "clipboard_sequence_number_token.h",
    "clipboard_util.cc",
    "clipboard_util.h",
    "custom_data_helper.cc",
    "custom_data_helper.h",
    "scoped_clipboard_writer.cc",
    "scoped_clipboard_writer.h",
  ]

  if (is_android) {
    sources += [
      "clipboard_android.cc",
      "clipboard_android.h",
    ]
  } else {
    sources += [
      "clipboard_data.cc",
      "clipboard_data.h",
      "clipboard_non_backed.cc",
      "clipboard_non_backed.h",
    ]
  }

  if (is_mac) {
    sources += [
      "clipboard_mac.h",
      "clipboard_mac.mm",
      "clipboard_util_mac.h",
      "clipboard_util_mac.mm",
    ]
  }

  if (is_ios) {
    sources += [
      "clipboard_ios.h",
      "clipboard_ios.mm",
    ]
  }

  if (is_win) {
    sources += [
      "clipboard_util_win.cc",
      "clipboard_util_win.h",
      "clipboard_win.cc",
      "clipboard_win.h",
    ]
  }

  defines = [ "IS_UI_BASE_CLIPBOARD_IMPL" ]

  deps = [
    "//base",
    "//build:chromeos_buildflags",
    "//mojo/public/cpp/base",
    "//net",
    "//ui/base:features",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]

  public_deps = [
    ":clipboard_types",
    ":file_info",
    "//skia",
    "//ui/base/data_transfer_policy",
  ]

  if (use_aura) {
    if (use_ozone) {
      sources += [
        "clipboard_factory_ozone.cc",
        "clipboard_ozone.cc",
        "clipboard_ozone.h",
      ]
      deps += [
        "//ui/base",
        "//ui/ozone",
      ]
    }
  }

  if (is_android) {
    deps += [ "//ui/base:clipboard_jni_headers" ]
  }

  if (is_mac) {
    deps += [ ":url_file_parser" ]
    frameworks = [
      "AppKit.framework",
      "CoreFoundation.framework",
      "UniformTypeIdentifiers.framework",
    ]
  }
}

source_set("clipboard_test_support") {
  testonly = true

  if (use_blink) {
    sources = [
      "test/clipboard_test_util.cc",
      "test/clipboard_test_util.h",
      "test/test_clipboard.cc",
      "test/test_clipboard.h",
    ]
  }

  if (is_android) {
    sources += [ "clipboard_android_test_support.cc" ]
  }

  public_deps = [
    ":clipboard",
    "//base",
    "//skia",
  ]

  deps = [
    "//base/test:test_support",
    "//build:chromecast_buildflags",
    "//build:chromeos_buildflags",
    "//ui/base:features",
    "//ui/gfx",
  ]

  if (is_android) {
    deps += [ "//ui/android:ui_javatest_jni_headers" ]
  }
}

source_set("clipboard_test") {
  testonly = true

  sources = []
  output_name = "ui_base_clipboard_test"

  if (is_ios) {
    if (use_blink) {
      # On other OSs, clipboard platform unit tests are run as part of
      # interactive_ui_tests. However, since interactive_ui_tests is not yet
      # ready for Blink iOS, we run them here for now.
      sources += [
        "clipboard_test_template.h",
        "clipboard_unittest.cc",
      ]
    }
  } else {
    sources += [
      "custom_data_helper_unittest.cc",
      "test/test_clipboard_unittest.cc",
    ]
  }

  if (is_mac) {
    sources += [
      "clipboard_mac_unittest.mm",
      "clipboard_util_mac_unittest.mm",
      "url_file_parser_unittest.cc",
    ]
    frameworks = [ "PDFKit.framework" ]
  }

  if (is_win) {
    sources += [ "clipboard_util_win_unittest.cc" ]
  }

  deps = [
    ":clipboard_test_support",
    "//base/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/base:features",
    "//ui/events/platform",
    "//ui/gfx:test_support",
    "//url:url",
  ]

  if (is_mac) {
    deps += [ ":url_file_parser" ]
  }

  if ((use_aura && !is_chromeos_lacros) || is_mac) {
    sources += [
      "clipboard_data_unittest.cc",
      "clipboard_non_backed_unittest.cc",
    ]

    if (use_ozone) {
      deps += [
        "//ui/ozone:ozone_switches",
        "//ui/ozone:platform",
      ]
    }
  }
}

fuzzer_test("url_file_parser_fuzzer") {
  sources = [ "url_file_parser_fuzzer.cc" ]
  deps = [
    ":url_file_parser",
    "//base",
  ]
  seed_corpus = "test/url_file_parser_fuzzer_testcases"
}