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

import("//build/buildflag_header.gni")
import("//build/util/process_version.gni")
import("//chrome/common/features.gni")
import("//chrome/process_version_rc_template.gni")  # For branding_file_path.
import("//extensions/features/features.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//tools/grit/grit_rule.gni")

grit("resources") {
  source = "common_resources.grd"
  use_qualified_include = true
  defines = chrome_grit_defines
  output_dir = "$root_gen_dir/chrome"
  output_name = "common_resources"
  outputs = [
    "grit/common_resources.h",
    "common_resources.pak",
  ]
}

buildflag_header("features") {
  header = "features.h"
  flags = [
    "ANDROID_JAVA_UI=$android_java_ui",
    "ENABLE_APP_LIST=$enable_app_list",
    "ENABLE_BACKGROUND=$enable_background",
    "ENABLE_BASIC_PRINT_DIALOG=$enable_basic_print_dialog",
    "ENABLE_CAPTIVE_PORTAL_DETECTION=$enable_captive_portal_detection",
    "ENABLE_GOOGLE_NOW=$enable_google_now",
    "ENABLE_HANGOUT_SERVICES_EXTENSION=$enable_hangout_services_extension",
    "ENABLE_ONE_CLICK_SIGNIN=$enable_one_click_signin",
    "ENABLE_PACKAGE_MASH_SERVICES=$enable_package_mash_services",
    "ENABLE_PLUGIN_INSTALLATION=$enable_plugin_installation",
    "ENABLE_SERVICE_DISCOVERY=$enable_service_discovery",
    "ENABLE_SESSION_SERVICE=$enable_session_service",
    "ENABLE_SUPERVISED_USERS=$enable_supervised_users",
    "ENABLE_XPC_NOTIFICATIONS=$enable_xpc_notifications",
    "PGO_BUILD=$pgo_build",
    "USE_VULCANIZE=$use_vulcanize",
  ]
}

# Use a static library here because many test binaries depend on this but don't
# require many files from it. This makes linking more efficient.
static_library("common") {
  sources = [
    "all_messages.h",
    "attrition_experiments.h",
    "auto_start_linux.cc",
    "auto_start_linux.h",
    "channel_info.cc",
    "channel_info.h",
    "channel_info_android.cc",
    "channel_info_chromeos.cc",
    "channel_info_mac.mm",
    "channel_info_posix.cc",
    "channel_info_win.cc",
    "child_process_logging.h",
    "child_process_logging_win.cc",
    "chrome_content_client.cc",
    "chrome_content_client.h",
    "chrome_content_client_constants.cc",
    "chrome_content_client_ios.mm",
    "chrome_media_client_android.cc",
    "chrome_media_client_android.h",
    "chrome_result_codes.h",
    "chrome_utility_messages.h",
    "common_message_generator.cc",
    "common_message_generator.h",
    "common_param_traits.cc",
    "common_param_traits.h",
    "common_param_traits_macros.h",
    "component_flash_hint_file_linux.cc",
    "component_flash_hint_file_linux.h",
    "content_restriction.h",
    "content_settings_pattern_serializer.cc",
    "content_settings_pattern_serializer.h",
    "crash_keys.cc",
    "crash_keys.h",
    "custom_handlers/protocol_handler.cc",
    "custom_handlers/protocol_handler.h",
    "descriptors_android.h",
    "ini_parser.cc",
    "ini_parser.h",
    "logging_chrome.cc",
    "logging_chrome.h",
    "mac/app_shim_launch.h",
    "mac/app_shim_messages.h",
    "mac/cfbundle_blocker.h",
    "mac/cfbundle_blocker.mm",
    "mac/launchd.h",
    "mac/launchd.mm",
    "media/media_resource_provider.cc",
    "media/media_resource_provider.h",
    "media/webrtc_logging_message_data.cc",
    "media/webrtc_logging_message_data.h",
    "media/webrtc_logging_messages.h",
    "media_galleries/metadata_types.h",
    "multi_process_lock.h",
    "multi_process_lock_linux.cc",
    "multi_process_lock_mac.cc",
    "multi_process_lock_win.cc",
    "origin_trials/chrome_origin_trial_policy.cc",
    "origin_trials/chrome_origin_trial_policy.h",
    "page_load_metrics/page_load_metrics_messages.h",
    "page_load_metrics/page_load_timing.cc",
    "page_load_metrics/page_load_timing.h",
    "page_load_metrics/page_track_decider.cc",
    "page_load_metrics/page_track_decider.h",
    "partial_circular_buffer.cc",
    "partial_circular_buffer.h",
    "pref_names_util.cc",
    "pref_names_util.h",
    "prerender_types.h",
    "profiling.cc",
    "profiling.h",
    "ref_counted_util.h",
    "render_messages.cc",
    "render_messages.h",
    "resource_usage_reporter_type_converters.cc",
    "resource_usage_reporter_type_converters.h",
    "safe_browsing/safebrowsing_messages.h",
    "search/instant_types.cc",
    "search/instant_types.h",
    "search/ntp_logging_events.h",
    "search/search_types.h",
    "search/search_urls.cc",
    "search/search_urls.h",
    "secure_origin_whitelist.cc",
    "secure_origin_whitelist.h",
    "ssl_insecure_content.cc",
    "ssl_insecure_content.h",
    "stack_sampling_configuration.cc",
    "stack_sampling_configuration.h",
    "switch_utils.cc",
    "switch_utils.h",
    "trace_event_args_whitelist.cc",
    "trace_event_args_whitelist.h",
    "tts_messages.h",
    "tts_utterance_request.cc",
    "tts_utterance_request.h",
    "url_constants.cc",
    "url_constants.h",
    "v8_breakpad_support_win.cc",
    "v8_breakpad_support_win.h",
    "variations/child_process_field_trial_syncer.cc",
    "variations/child_process_field_trial_syncer.h",
    "web_application_info.cc",
    "web_application_info.h",
    "widevine_cdm_constants.cc",
    "widevine_cdm_constants.h",
  ]
  defines = []

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

  public_deps = [
    ":features",
    ":mojo_bindings",
    "//base:base",
    "//base:base_static",
    "//base:i18n",
    "//chrome:resources",
    "//chrome:strings",
    "//chrome/app/theme:theme_resources",
    "//chrome/common:constants",
    "//chrome/common/net",
    "//chrome/common/safe_browsing:proto",
    "//chrome/installer/util:with_no_strings",
    "//components/autofill/content/common:ipc_traits",
    "//components/autofill/core/common",
    "//components/cast_certificate",
    "//components/cdm/common",
    "//components/cloud_devices/common",
    "//components/component_updater",
    "//components/content_settings/core/common",
    "//components/crash/core/common",
    "//components/dom_distiller/core",
    "//components/error_page/common",
    "//components/favicon_base",
    "//components/flags_ui:switches",
    "//components/gcm_driver/common",
    "//components/json_schema",
    "//components/metrics",
    "//components/metrics:net",
    "//components/nacl/common:process_type",
    "//components/nacl/common:switches",
    "//components/offline_pages:switches",
    "//components/omnibox/common",
    "//components/password_manager/content/common:mojo_interfaces",
    "//components/password_manager/core/common",
    "//components/policy:generated",
    "//components/policy/core/common",
    "//components/prefs",
    "//components/signin/core/common",
    "//components/strings",
    "//components/translate/content/common",
    "//components/translate/core/common",
    "//components/url_formatter",
    "//components/variations",
    "//components/version_info",
    "//components/visitedlink/common",
    "//content/public/common",
    "//crypto",
    "//extensions/common:common_constants",
    "//extensions/features",
    "//gin",
    "//google_apis",
    "//gpu/command_buffer/service",
    "//gpu/config",
    "//ipc",
    "//media",
    "//mojo/edk/system",
    "//mojo/public/cpp/bindings",
    "//net",
    "//ppapi/features",
    "//printing/features",
    "//skia",
    "//third_party/icu",
    "//third_party/kasko:kasko_features",
    "//third_party/re2",
    "//third_party/widevine/cdm:headers",
    "//third_party/zlib:zip",
    "//ui/accessibility",
    "//ui/base",
    "//ui/gfx/ipc",
    "//ui/gfx/ipc/geometry",
    "//ui/gfx/ipc/skia",
    "//ui/gl",
    "//ui/message_center",
    "//ui/resources:resources",
    "//url",
  ]

  if (enable_plugins) {
    public_deps += [ "//ppapi/shared_impl" ]
  }

  if (enable_extensions) {
    sources += [
      "cast_messages.cc",
      "cast_messages.h",
      "extensions/api/commands/commands_handler.cc",
      "extensions/api/commands/commands_handler.h",
      "extensions/api/extension_action/action_info.cc",
      "extensions/api/extension_action/action_info.h",
      "extensions/api/notifications/notification_style.cc",
      "extensions/api/notifications/notification_style.h",
      "extensions/api/omnibox/omnibox_handler.cc",
      "extensions/api/omnibox/omnibox_handler.h",
      "extensions/api/plugins/plugins_handler.cc",
      "extensions/api/plugins/plugins_handler.h",
      "extensions/api/speech/tts_engine_manifest_handler.cc",
      "extensions/api/speech/tts_engine_manifest_handler.h",
      "extensions/api/spellcheck/spellcheck_handler.cc",
      "extensions/api/spellcheck/spellcheck_handler.h",
      "extensions/api/storage/storage_schema_manifest_handler.cc",
      "extensions/api/storage/storage_schema_manifest_handler.h",
      "extensions/api/system_indicator/system_indicator_handler.cc",
      "extensions/api/system_indicator/system_indicator_handler.h",
      "extensions/api/url_handlers/url_handlers_parser.cc",
      "extensions/api/url_handlers/url_handlers_parser.h",
      "extensions/api/webstore/webstore_api_constants.cc",
      "extensions/api/webstore/webstore_api_constants.h",
      "extensions/chrome_aliases.cc",
      "extensions/chrome_aliases.h",
      "extensions/chrome_extension_messages.h",
      "extensions/chrome_extensions_client.cc",
      "extensions/chrome_extensions_client.h",
      "extensions/chrome_manifest_handlers.cc",
      "extensions/chrome_manifest_handlers.h",
      "extensions/chrome_manifest_url_handlers.cc",
      "extensions/chrome_manifest_url_handlers.h",
      "extensions/chrome_utility_extensions_messages.h",
      "extensions/command.cc",
      "extensions/command.h",
      "extensions/extension_constants.cc",
      "extensions/extension_constants.h",
      "extensions/extension_metrics.cc",
      "extensions/extension_metrics.h",
      "extensions/extension_process_policy.cc",
      "extensions/extension_process_policy.h",
      "extensions/image_writer/image_writer_util_mac.cc",
      "extensions/image_writer/image_writer_util_mac.h",
      "extensions/manifest_handlers/app_icon_color_info.cc",
      "extensions/manifest_handlers/app_icon_color_info.h",
      "extensions/manifest_handlers/app_launch_info.cc",
      "extensions/manifest_handlers/app_launch_info.h",
      "extensions/manifest_handlers/automation.cc",
      "extensions/manifest_handlers/automation.h",
      "extensions/manifest_handlers/content_scripts_handler.cc",
      "extensions/manifest_handlers/content_scripts_handler.h",
      "extensions/manifest_handlers/extension_action_handler.cc",
      "extensions/manifest_handlers/extension_action_handler.h",
      "extensions/manifest_handlers/linked_app_icons.cc",
      "extensions/manifest_handlers/linked_app_icons.h",
      "extensions/manifest_handlers/minimum_chrome_version_checker.cc",
      "extensions/manifest_handlers/minimum_chrome_version_checker.h",
      "extensions/manifest_handlers/settings_overrides_handler.cc",
      "extensions/manifest_handlers/settings_overrides_handler.h",
      "extensions/manifest_handlers/theme_handler.cc",
      "extensions/manifest_handlers/theme_handler.h",
      "extensions/manifest_handlers/ui_overrides_handler.cc",
      "extensions/manifest_handlers/ui_overrides_handler.h",
      "extensions/permissions/chrome_api_permissions.cc",
      "extensions/permissions/chrome_api_permissions.h",
      "extensions/permissions/chrome_permission_message_provider.cc",
      "extensions/permissions/chrome_permission_message_provider.h",
      "extensions/permissions/chrome_permission_message_rules.cc",
      "extensions/permissions/chrome_permission_message_rules.h",
      "extensions/sync_helper.cc",
      "extensions/sync_helper.h",
      "extensions/webstore_install_result.cc",
      "extensions/webstore_install_result.h",
    ]
    public_deps += [
      "//chrome/common/extensions/api",
      "//chrome/common/extensions/api:extensions_features",
      "//device/usb",
      "//extensions:extensions_resources",
      "//extensions/common",
      "//extensions/common/api",
      "//extensions/strings",
      "//media/cast:net",
    ]
    if (is_chromeos) {
      sources += [
        "extensions/api/file_browser_handlers/file_browser_handler.cc",
        "extensions/api/file_browser_handlers/file_browser_handler.h",
        "extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.cc",
        "extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h",
        "extensions/api/input_ime/input_components_handler.cc",
        "extensions/api/input_ime/input_components_handler.h",
      ]
    }
    if (use_aura) {
      # This dependency is for a header used only by extensions code.
      public_deps += [ "//ui/keyboard:keyboard_with_content" ]
    }
  }

  if (is_win || is_mac) {
    sources += [
      "media_galleries/itunes_library.cc",
      "media_galleries/itunes_library.h",
      "media_galleries/picasa_types.cc",
      "media_galleries/picasa_types.h",
      "media_galleries/pmp_constants.h",
    ]
  }
  if (is_mac) {
    public_deps += [ ":app_mode_app_support" ]
  }
  if (is_chromeos) {
    public_deps += [ "//chromeos" ]
  }

  if (enable_nacl) {
    public_deps += [ "//components/nacl/common" ]
  }

  # Printing.
  if (enable_basic_printing || enable_print_preview) {
    sources += [
      "chrome_utility_printing_messages.h",
      "cloud_print/cloud_print_cdd_conversion.cc",
      "cloud_print/cloud_print_cdd_conversion.h",
      "cloud_print/cloud_print_class_mac.h",
      "cloud_print/cloud_print_class_mac.mm",
      "cloud_print/cloud_print_constants.cc",
      "cloud_print/cloud_print_constants.h",
      "cloud_print/cloud_print_helpers.cc",
      "cloud_print/cloud_print_helpers.h",
      "cloud_print/cloud_print_proxy_info.cc",
      "cloud_print/cloud_print_proxy_info.h",
    ]

    public_deps += [
      "//components/printing/common",
      "//printing",
    ]
    if (enable_print_preview) {
      # Full printing support.
      sources += [
        "service_messages.h",
        "service_process_util.cc",
        "service_process_util.h",
        "service_process_util_linux.cc",
        "service_process_util_mac.mm",
        "service_process_util_posix.cc",
        "service_process_util_posix.h",
        "service_process_util_win.cc",
      ]
    }
  }

  if (is_android) {
    sources -= [
      "channel_info_posix.cc",
      "media_galleries/metadata_types.h",
    ]
  } else {
    # Non-Android.
    sources += [
      "importer/edge_importer_utils_win.cc",
      "importer/edge_importer_utils_win.h",
      "importer/firefox_importer_utils.cc",
      "importer/firefox_importer_utils.h",
      "importer/firefox_importer_utils_linux.cc",
      "importer/firefox_importer_utils_mac.mm",
      "importer/firefox_importer_utils_win.cc",
      "importer/ie_importer_utils_win.cc",
      "importer/ie_importer_utils_win.h",
      "importer/imported_bookmark_entry.cc",
      "importer/imported_bookmark_entry.h",
      "importer/importer_autofill_form_data_entry.cc",
      "importer/importer_autofill_form_data_entry.h",
      "importer/importer_bridge.cc",
      "importer/importer_bridge.h",
      "importer/importer_data_types.cc",
      "importer/importer_data_types.h",
      "importer/importer_test_registry_overrider_win.cc",
      "importer/importer_test_registry_overrider_win.h",
      "importer/importer_type.h",
      "importer/importer_url_row.cc",
      "importer/importer_url_row.h",
      "importer/profile_import_process_messages.cc",
      "importer/profile_import_process_messages.h",
      "importer/profile_import_process_param_traits_macros.h",
      "importer/safari_importer_utils.h",
      "importer/safari_importer_utils.mm",
    ]
  }

  if (is_chromeos) {
    sources -= [ "channel_info_posix.cc" ]
  }

  if (is_win) {
    public_deps += [
      "//components/dom_distiller/core",  # Needed by chrome_content_client.cc.
      "//third_party/wtl",
    ]

    libs = [ "wintrust.lib" ]
  }

  if (is_mac) {
    sources -= [ "channel_info_posix.cc" ]
    public_deps += [
      "//third_party/google_toolbox_for_mac",
      "//third_party/mach_override",
    ]
  }

  if (enable_plugins) {
    sources += [
      "pepper_flash.cc",
      "pepper_flash.h",
      "plugin_utils.cc",
      "plugin_utils.h",
      "ppapi_utils.cc",
      "ppapi_utils.h",
    ]
    public_deps += [ "//third_party/adobe/flash:flapper_version_h" ]
  }
  if (enable_plugins && enable_extensions) {
    sources += [
      "pepper_permission_util.cc",
      "pepper_permission_util.h",
    ]
  }
  if (!enable_webrtc) {
    sources -= [ "media/webrtc_logging_messages.h" ]
  }

  if (safe_browsing_mode != 0) {
    sources += [
      "safe_browsing/file_type_policies.cc",
      "safe_browsing/file_type_policies.h",
    ]

    if (safe_browsing_mode == 1) {
      sources += [
        "safe_browsing/binary_feature_extractor.cc",
        "safe_browsing/binary_feature_extractor.h",
        "safe_browsing/binary_feature_extractor_mac.cc",
        "safe_browsing/binary_feature_extractor_posix.cc",
        "safe_browsing/binary_feature_extractor_win.cc",
        "safe_browsing/download_protection_util.cc",
        "safe_browsing/download_protection_util.h",
        "safe_browsing/ipc_protobuf_message_macros.h",
        "safe_browsing/ipc_protobuf_message_null_macros.h",
        "safe_browsing/mach_o_image_reader_mac.cc",
        "safe_browsing/mach_o_image_reader_mac.h",
        "safe_browsing/pe_image_reader_win.cc",
        "safe_browsing/pe_image_reader_win.h",
        "safe_browsing/protobuf_message_log_macros.h",
        "safe_browsing/protobuf_message_param_traits.h",
        "safe_browsing/protobuf_message_read_macros.h",
        "safe_browsing/protobuf_message_size_macros.h",
        "safe_browsing/protobuf_message_write_macros.h",
        "safe_browsing/zip_analyzer.cc",
        "safe_browsing/zip_analyzer.h",
        "safe_browsing/zip_analyzer_results.cc",
        "safe_browsing/zip_analyzer_results.h",
      ]
    }
  }

  if (enable_vr_shell) {
    defines += [ "ENABLE_VR_SHELL" ]
  }

  if (is_linux) {
    deps = [
      "//sandbox/linux:sandbox_services",
    ]
  }
}

process_version("version_header") {
  # TODO(brettw) this should have more reduced visibility, but chrome/browser
  # currently depends on this.
  #visibility = [ ":*" ]

  sources = [
    "//build/util/LASTCHANGE",
    "//chrome/VERSION",
    branding_file_path,
  ]
  template_file = "chrome_version.h.in"

  output = "$target_gen_dir/chrome_version.h"
}

static_library("constants") {
  sources = [
    "chrome_constants.cc",
    "chrome_constants.h",
    "chrome_features.cc",
    "chrome_features.h",
    "chrome_icon_resources_win.cc",
    "chrome_icon_resources_win.h",
    "chrome_paths.cc",
    "chrome_paths.h",
    "chrome_paths_android.cc",
    "chrome_paths_internal.h",
    "chrome_paths_linux.cc",
    "chrome_paths_mac.mm",
    "chrome_paths_win.cc",
    "chrome_result_codes.h",
    "chrome_switches.cc",
    "chrome_switches.h",
    "env_vars.cc",
    "env_vars.h",
    "pref_font_script_names-inl.h",
    "pref_font_webkit_names.h",
    "pref_names.cc",
    "pref_names.h",
  ]

  public_deps = [
    ":features",
    "//content/public/common:result_codes",
    "//extensions/features",
    "//printing/features",
  ]
  deps = [
    ":version_header",
    "//base",
    "//base/third_party/dynamic_annotations",
    "//components/bookmarks/common",
    "//components/nacl/common:switches",
    "//media:cdm_paths",  # Needed by chrome_paths.cc.
    "//ppapi/features",
    "//third_party/widevine/cdm:headers",
  ]

  if (is_android) {
    # This dependency must only be added for Android.
    #
    # On Windows, //chrome/installer/util depends on this target to get
    # constants. That target is in turn used in a number of installer helper
    # targets independent of Chrome that we want to keep small. So we don't
    # want something large like //ui/base.
    #
    # Android doesn't have this structure and corresponding size limitation
    # on this target. On that platform one of the Chrome paths forwards to one
    # implemented in //ui/base, so we need that dependency.
    deps += [ "//ui/base" ]
  }
}

if (is_win) {
  source_set("metrics_constants_util_win") {
    sources = [
      "metrics_constants_util_win.cc",
      "metrics_constants_util_win.h",
    ]

    deps = [
      "//base",
      "//chrome/installer/util:with_no_strings",
    ]
  }
}

# Use a static library here because many test binaries depend on this but don't
# require many files from it. This makes linking more efficient.
static_library("test_support") {
  testonly = true
  visibility = [ "//chrome/test:test_support" ]

  sources = []

  deps = [
    ":common",
    "//base",
    "//testing/gtest",
  ]

  if (is_win || is_mac) {
    sources += [
      "media_galleries/picasa_test_util.cc",
      "media_galleries/picasa_test_util.h",
      "media_galleries/pmp_test_util.cc",
      "media_galleries/pmp_test_util.h",
    ]
  }

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

  if (enable_extensions) {
    sources += [
      "extensions/extension_test_util.cc",
      "extensions/extension_test_util.h",
    ]
    deps += [ "//chrome/common/extensions:test_features" ]
  }
}

source_set("app_mode_app_support") {
  sources = [
    "mac/app_mode_chrome_locator.h",
    "mac/app_mode_chrome_locator.mm",
    "mac/app_mode_common.h",
    "mac/app_mode_common.mm",
  ]

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

  deps = [
    ":constants",
    "//base",
  ]
}

mojom("mojo_bindings") {
  sources = [
    "network_diagnostics.mojom",
    "resource_usage_reporter.mojom",
    "shell_handler_win.mojom",
  ]

  public_deps = [
    "//url/mojo:url_mojom_gurl",
  ]
}
