# Copyright 2015 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("//android_webview/system_webview_apk_tmpl.gni")
import("//android_webview/webview_repack_locales.gni")
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/config/locales.gni")
import("//components/spellcheck/spellcheck_build_features.gni")
import("//tools/grit/repack.gni")
import("//tools/resources/generate_resource_whitelist.gni")

declare_args() {
  # Package name of the system_webview_apk target.
  system_webview_package_name = "com.android.webview"
}

if (enable_resource_whitelist_generation) {
  system_webview_pak_whitelist =
      "$target_gen_dir/system_webview_pak_whitelist.txt"
}

system_webview_android_manifest =
    "$target_gen_dir/system_webview_apk/AndroidManifest.xml"

group("android_webview") {
  if (public_android_sdk) {
    deps = [
      ":system_webview_apk",
    ]
  }
}

generate_jni("native_jni") {
  sources = [
    "java/src/org/chromium/android_webview/AndroidProtocolHandler.java",
    "java/src/org/chromium/android_webview/AwAutofillClient.java",
    "java/src/org/chromium/android_webview/AwBrowserProcess.java",
    "java/src/org/chromium/android_webview/AwContents.java",
    "java/src/org/chromium/android_webview/AwContentsBackgroundThreadClient.java",
    "java/src/org/chromium/android_webview/AwContentsClientBridge.java",
    "java/src/org/chromium/android_webview/AwContentsIoThreadClient.java",
    "java/src/org/chromium/android_webview/AwContentsLifecycleNotifier.java",
    "java/src/org/chromium/android_webview/AwContentsStatics.java",
    "java/src/org/chromium/android_webview/AwCookieManager.java",
    "java/src/org/chromium/android_webview/AwDebug.java",
    "java/src/org/chromium/android_webview/AwDevToolsServer.java",
    "java/src/org/chromium/android_webview/AwFormDatabase.java",
    "java/src/org/chromium/android_webview/AwGLFunctor.java",
    "java/src/org/chromium/android_webview/AwHttpAuthHandler.java",
    "java/src/org/chromium/android_webview/AwMetricsLogUploader.java",
    "java/src/org/chromium/android_webview/AwMetricsServiceClient.java",
    "java/src/org/chromium/android_webview/AwPdfExporter.java",
    "java/src/org/chromium/android_webview/AwPicture.java",
    "java/src/org/chromium/android_webview/AwQuotaManagerBridge.java",
    "java/src/org/chromium/android_webview/AwResource.java",
    "java/src/org/chromium/android_webview/AwSettings.java",
    "java/src/org/chromium/android_webview/AwTokenBindingManager.java",
    "java/src/org/chromium/android_webview/AwWebContentsDelegate.java",
    "java/src/org/chromium/android_webview/AwWebResourceResponse.java",
    "java/src/org/chromium/android_webview/InputStreamUtil.java",
    "java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java",
    "java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java",
    "java/src/org/chromium/android_webview/permission/AwPermissionRequest.java",
  ]
  jni_package = "android_webview"

  deps = [
    ":cancellation_signal_android_jar_jni_headers",
  ]
}

generate_jar_jni("cancellation_signal_android_jar_jni_headers") {
  classes = [ "android/os/CancellationSignal.class" ]
  jni_package = "android_webview"
}

java_cpp_enum("aw_permission_request_resource") {
  sources = [
    "browser/permission/aw_permission_request.h",
  ]
}

java_cpp_enum("android_webview_java_enums_srcjar") {
  sources = [
    "browser/aw_renderer_priority.h",
  ]
}

java_cpp_enum("aw_error_ui") {
  sources = [
    "browser/aw_safe_browsing_blocking_page.h",
  ]
}

java_cpp_enum("aw_safe_browsing_action") {
  sources = [
    "browser/aw_url_checker_delegate_impl.h",
  ]
}

jinja_template("system_webview_manifest") {
  input = "apk/java/AndroidManifest.xml"
  output = system_webview_android_manifest
  variables = [
    "package=$system_webview_package_name",
    "sandboxed_service_extra_flags=android:visibleToInstantApps=\"true\"",
  ]
}

webview_repack_locales("repack_locales") {
  input_locales = locales
  output_locales = locales

  if (enable_resource_whitelist_generation) {
    repack_whitelist = system_webview_pak_whitelist
    deps = [
      ":system_webview_pak_whitelist",
    ]
  }
}

android_assets("locale_pak_assets") {
  disable_compression = true
  renaming_sources = []
  renaming_destinations = []
  foreach(_locale, locales) {
    renaming_sources += [ "$root_out_dir/android_webview/locales/$_locale.pak" ]
    renaming_destinations += [ "stored-locales/$_locale.pak" ]
  }
  treat_as_locale_paks = true
  deps = [
    ":repack_locales",
  ]
}

repack("repack_pack") {
  sources = [
    "$root_gen_dir/blink/public/resources/blink_resources.pak",
    "$root_gen_dir/content/content_resources.pak",
    "$root_gen_dir/net/net_resources.pak",
    "$target_gen_dir/aw_resources.pak",
    "$target_gen_dir/components_resources.pak",
    "$target_gen_dir/webui_resources.pak",
  ]
  deps = [
    ":generate_aw_resources",
    ":generate_components_resources",
    ":generate_webui_resources",
    "//content:resources",
    "//net:net_resources",
    "//third_party/WebKit/public:resources",
  ]
  output = "$target_gen_dir/resources.pak"

  if (enable_resource_whitelist_generation) {
    repack_whitelist = system_webview_pak_whitelist
    deps += [ ":system_webview_pak_whitelist" ]
  }
}

repack("repack_100_percent") {
  sources = [
    "$root_gen_dir/blink/public/resources/blink_scaled_resources_100_percent.pak",
    "$root_gen_dir/content/app/resources/content_resources_100_percent.pak",
    "$root_gen_dir/ui/resources/ui_resources_100_percent.pak",
  ]
  deps = [
    "//content/app/resources",
    "//third_party/WebKit/public:scaled_resources_100_percent",
    "//ui/resources",
  ]
  output = "$target_gen_dir/chrome_100_percent.pak"

  if (enable_resource_whitelist_generation) {
    repack_whitelist = system_webview_pak_whitelist
    deps += [ ":system_webview_pak_whitelist" ]
  }
}

android_assets("pak_file_assets") {
  sources = [
    "$target_gen_dir/chrome_100_percent.pak",
    "$target_gen_dir/resources.pak",
  ]
  deps = [
    ":repack_100_percent",
    ":repack_pack",
  ]
  disable_compression = true
}

# These assets are needed by both monochrome and stand alone WebView, but not by
# Chrome.
android_assets("monochrome_webview_assets") {
  deps = [
    "//third_party/icu:icu_assets",
    "//v8:v8_external_startup_data_assets",
  ]
  if (android_64bit_target_cpu && build_apk_secondary_abi) {
    deps += [ ":v8_snapshot_secondary_abi_assets" ]
  }
}

java_group("assets") {
  deps = [
    ":license_assets",
    ":locale_pak_assets",
    ":monochrome_webview_assets",
    ":pak_file_assets",
  ]
}

java_group("stub_assets") {
  deps = [
    ":license_assets",
  ]
}

android_assets("license_assets") {
  renaming_sources = [ "$root_gen_dir/components/resources/about_credits.html" ]
  renaming_destinations = [ "webview_licenses.notice" ]
  deps = [
    "//components/resources:about_credits",
  ]
}

android_resources("system_webview_resources") {
  resource_dirs = [ "apk/java/res" ]
  custom_package = system_webview_package_name
}

android_resources("resources") {
  resource_dirs = [ "java/res" ]
  custom_package = "org.chromium.android_webview"
  deps = [
    ":strings_grd",
  ]
}

grit("generate_aw_resources") {
  source = "ui/aw_resources.grd"
  outputs = [
    "grit/aw_resources.h",
    "aw_resources.pak",
  ]
}

grit("generate_aw_strings") {
  source = "ui/aw_strings.grd"
  outputs = [
    "grit/aw_strings.h",
  ]
  foreach(_locale, locales) {
    outputs += [ "aw_strings_${_locale}.pak" ]
  }
}

grit("generate_webui_resources") {
  source = "../ui/webui/resources/webui_resources.grd"

  # The .grd contains references to generated files.
  source_is_generated = true

  # webui/resources has way too many resources. The whitelist is trim this down
  # to a reasonable size
  whitelist = rebase_path("ui/grit_resources_whitelist.txt")
  inputs = [
    whitelist,
  ]
  grit_flags = [
    "-w",
    whitelist,
  ]
  outputs = [
    "grit/webui_resources.h",
    "grit/webui_resources_map.cc",
    "grit/webui_resources_map.h",
    "webui_resources.pak",
  ]
}

grit("generate_components_resources") {
  source = "../components/resources/components_resources.grd"

  # The .grd contains references to generated files.
  source_is_generated = true

  # See :generate_webui_resources for an explanation of the whitelist
  whitelist = rebase_path("ui/grit_resources_whitelist.txt")
  inputs = [
    whitelist,
  ]
  grit_flags = [
    "-w",
    whitelist,
  ]
  outputs = [
    "grit/components_resources.h",
    "components_resources.pak",
  ]

  deps = [
    "//components/resources:components_resources",
  ]
}

grit("generate_components_strings") {
  source = "../components/components_strings.grd"

  # components_strings contains strings from all components. WebView
  # will never display most of them, so we try to limit the included
  # strings. This whitelist trims about 50% more than the compile-based
  # whitelist generated by :system_webview_pak_whitelist.
  whitelist = rebase_path("ui/grit_strings_whitelist.txt")
  inputs = [
    whitelist,
  ]
  grit_flags = [
    "-w",
    whitelist,
  ]
  outputs = [
    "grit/components_strings.h",
    "java/res/values-am/components_strings.xml",
    "java/res/values-ar/components_strings.xml",
    "java/res/values-bg/components_strings.xml",
    "java/res/values-ca/components_strings.xml",
    "java/res/values-cs/components_strings.xml",
    "java/res/values-da/components_strings.xml",
    "java/res/values-de/components_strings.xml",
    "java/res/values-el/components_strings.xml",
    "java/res/values-en-rGB/components_strings.xml",
    "java/res/values-es-rUS/components_strings.xml",
    "java/res/values-es/components_strings.xml",
    "java/res/values-fa/components_strings.xml",
    "java/res/values-fi/components_strings.xml",
    "java/res/values-fr/components_strings.xml",
    "java/res/values-hi/components_strings.xml",
    "java/res/values-hr/components_strings.xml",
    "java/res/values-hu/components_strings.xml",
    "java/res/values-in/components_strings.xml",
    "java/res/values-it/components_strings.xml",
    "java/res/values-iw/components_strings.xml",
    "java/res/values-ja/components_strings.xml",
    "java/res/values-ko/components_strings.xml",
    "java/res/values-lt/components_strings.xml",
    "java/res/values-lv/components_strings.xml",
    "java/res/values-nb/components_strings.xml",
    "java/res/values-nl/components_strings.xml",
    "java/res/values-pl/components_strings.xml",
    "java/res/values-pt-rBR/components_strings.xml",
    "java/res/values-pt-rPT/components_strings.xml",
    "java/res/values-ro/components_strings.xml",
    "java/res/values-ru/components_strings.xml",
    "java/res/values-sk/components_strings.xml",
    "java/res/values-sl/components_strings.xml",
    "java/res/values-sr/components_strings.xml",
    "java/res/values-sv/components_strings.xml",
    "java/res/values-sw/components_strings.xml",
    "java/res/values-th/components_strings.xml",
    "java/res/values-tl/components_strings.xml",
    "java/res/values-tr/components_strings.xml",
    "java/res/values-uk/components_strings.xml",
    "java/res/values-vi/components_strings.xml",
    "java/res/values-zh-rCN/components_strings.xml",
    "java/res/values-zh-rTW/components_strings.xml",
    "java/res/values/components_strings.xml",
  ]
  foreach(_locale, locales_with_fake_bidi) {
    outputs += [ "components_strings_${_locale}.pak" ]
  }
}

source_set("webview_entry_point") {
  deps = [
    ":common",
  ]
  sources = [
    "lib/webview_entry_point.cc",
  ]
}

shared_library("libwebviewchromium") {
  deps = [
    ":webview_entry_point",
  ]
  configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
  configs += [ "//build/config/android:hide_all_but_jni" ]
}

if (android_64bit_target_cpu) {
  android_assets("v8_snapshot_secondary_abi_assets") {
    _secondary_abi_out_dir =
        get_label_info("//v8($android_secondary_abi_toolchain)", "root_out_dir")
    assert(android_64bit_target_cpu,
           "32-bit targets shouldn't have secondary abi")
    arch_suffix = "32"
    renaming_sources = [ "$_secondary_abi_out_dir/snapshot_blob.bin" ]
    renaming_destinations = [ "snapshot_blob_$arch_suffix.bin" ]
    disable_compression = true
    deps = [
      "//v8($android_secondary_abi_toolchain)",
    ]
  }

  shared_library("monochrome") {
    deps = [
      ":webview_entry_point",
    ]
    configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
    configs += [ "//build/config/android:hide_all_but_jni" ]
    if (use_lld) {
      configs += [ "//build/config/android:lld_pack_relocations" ]
    }
  }
}

if (enable_resource_whitelist_generation) {
  generate_resource_whitelist("system_webview_pak_whitelist") {
    deps = [
      ":libwebviewchromium",
    ]
    input = "$root_out_dir/libwebviewchromium$shlib_extension.whitelist"
    output = system_webview_pak_whitelist
  }
}

source_set("common") {
  sources = [
    "browser/android_protocol_handler.cc",
    "browser/android_protocol_handler.h",
    "browser/aw_autofill_client.cc",
    "browser/aw_autofill_client.h",
    "browser/aw_browser_context.cc",
    "browser/aw_browser_context.h",
    "browser/aw_browser_main_parts.cc",
    "browser/aw_browser_main_parts.h",
    "browser/aw_browser_permission_request_delegate.h",
    "browser/aw_browser_policy_connector.cc",
    "browser/aw_browser_policy_connector.h",
    "browser/aw_browser_terminator.cc",
    "browser/aw_browser_terminator.h",
    "browser/aw_content_browser_client.cc",
    "browser/aw_content_browser_client.h",
    "browser/aw_contents.cc",
    "browser/aw_contents.h",
    "browser/aw_contents_client_bridge.cc",
    "browser/aw_contents_client_bridge.h",
    "browser/aw_contents_io_thread_client.cc",
    "browser/aw_contents_io_thread_client.h",
    "browser/aw_contents_lifecycle_notifier.cc",
    "browser/aw_contents_lifecycle_notifier.h",
    "browser/aw_contents_statics.cc",
    "browser/aw_cookie_access_policy.cc",
    "browser/aw_cookie_access_policy.h",
    "browser/aw_debug.cc",
    "browser/aw_devtools_manager_delegate.cc",
    "browser/aw_devtools_manager_delegate.h",
    "browser/aw_devtools_server.cc",
    "browser/aw_devtools_server.h",
    "browser/aw_download_manager_delegate.cc",
    "browser/aw_download_manager_delegate.h",
    "browser/aw_field_trial_creator.cc",
    "browser/aw_field_trial_creator.h",
    "browser/aw_form_database.cc",
    "browser/aw_form_database_service.cc",
    "browser/aw_form_database_service.h",
    "browser/aw_gl_functor.cc",
    "browser/aw_gl_functor.h",
    "browser/aw_gl_surface.cc",
    "browser/aw_gl_surface.h",
    "browser/aw_http_auth_handler.cc",
    "browser/aw_http_auth_handler.h",
    "browser/aw_javascript_dialog_manager.cc",
    "browser/aw_javascript_dialog_manager.h",
    "browser/aw_login_delegate.cc",
    "browser/aw_login_delegate.h",
    "browser/aw_media_url_interceptor.cc",
    "browser/aw_media_url_interceptor.h",
    "browser/aw_metrics_log_uploader.cc",
    "browser/aw_metrics_log_uploader.h",
    "browser/aw_metrics_service_client.cc",
    "browser/aw_metrics_service_client.h",
    "browser/aw_pdf_exporter.cc",
    "browser/aw_pdf_exporter.h",
    "browser/aw_permission_manager.cc",
    "browser/aw_permission_manager.h",
    "browser/aw_picture.cc",
    "browser/aw_picture.h",
    "browser/aw_print_manager.cc",
    "browser/aw_print_manager.h",
    "browser/aw_printing_message_filter.cc",
    "browser/aw_printing_message_filter.h",
    "browser/aw_quota_manager_bridge.cc",
    "browser/aw_quota_manager_bridge.h",
    "browser/aw_quota_permission_context.cc",
    "browser/aw_quota_permission_context.h",
    "browser/aw_render_process_gone_delegate.h",
    "browser/aw_render_thread_context_provider.cc",
    "browser/aw_render_thread_context_provider.h",
    "browser/aw_renderer_priority.h",
    "browser/aw_resource_context.cc",
    "browser/aw_resource_context.h",
    "browser/aw_result_codes.h",
    "browser/aw_safe_browsing_blocking_page.cc",
    "browser/aw_safe_browsing_blocking_page.h",
    "browser/aw_safe_browsing_config_helper.cc",
    "browser/aw_safe_browsing_config_helper.h",
    "browser/aw_safe_browsing_resource_throttle.cc",
    "browser/aw_safe_browsing_resource_throttle.h",
    "browser/aw_safe_browsing_ui_manager.cc",
    "browser/aw_safe_browsing_ui_manager.h",
    "browser/aw_safe_browsing_whitelist_manager.cc",
    "browser/aw_safe_browsing_whitelist_manager.h",
    "browser/aw_settings.cc",
    "browser/aw_settings.h",
    "browser/aw_ssl_host_state_delegate.cc",
    "browser/aw_ssl_host_state_delegate.h",
    "browser/aw_url_checker_delegate_impl.cc",
    "browser/aw_url_checker_delegate_impl.h",
    "browser/aw_variations_service_client.cc",
    "browser/aw_variations_service_client.h",
    "browser/aw_web_contents_delegate.cc",
    "browser/aw_web_contents_delegate.h",
    "browser/aw_web_contents_view_delegate.cc",
    "browser/aw_web_contents_view_delegate.h",
    "browser/aw_web_ui_controller_factory.cc",
    "browser/aw_web_ui_controller_factory.h",
    "browser/browser_view_renderer.cc",
    "browser/browser_view_renderer.h",
    "browser/browser_view_renderer_client.h",
    "browser/child_frame.cc",
    "browser/child_frame.h",
    "browser/command_line_helper.cc",
    "browser/command_line_helper.h",
    "browser/compositor_frame_consumer.h",
    "browser/compositor_frame_producer.h",
    "browser/compositor_id.cc",
    "browser/compositor_id.h",
    "browser/cookie_manager.cc",
    "browser/deferred_gpu_command_service.cc",
    "browser/deferred_gpu_command_service.h",
    "browser/find_helper.cc",
    "browser/find_helper.h",
    "browser/gl_view_renderer_manager.cc",
    "browser/gl_view_renderer_manager.h",
    "browser/hardware_renderer.cc",
    "browser/hardware_renderer.h",
    "browser/icon_helper.cc",
    "browser/icon_helper.h",
    "browser/input_stream.cc",
    "browser/input_stream.h",
    "browser/java_browser_view_renderer_helper.cc",
    "browser/java_browser_view_renderer_helper.h",
    "browser/net/android_stream_reader_url_request_job.cc",
    "browser/net/android_stream_reader_url_request_job.h",
    "browser/net/aw_cookie_store_wrapper.cc",
    "browser/net/aw_cookie_store_wrapper.h",
    "browser/net/aw_http_user_agent_settings.cc",
    "browser/net/aw_http_user_agent_settings.h",
    "browser/net/aw_network_change_notifier.cc",
    "browser/net/aw_network_change_notifier.h",
    "browser/net/aw_network_change_notifier_factory.cc",
    "browser/net/aw_network_change_notifier_factory.h",
    "browser/net/aw_network_delegate.cc",
    "browser/net/aw_network_delegate.h",
    "browser/net/aw_request_interceptor.cc",
    "browser/net/aw_request_interceptor.h",
    "browser/net/aw_url_request_context_getter.cc",
    "browser/net/aw_url_request_context_getter.h",
    "browser/net/aw_url_request_job_factory.cc",
    "browser/net/aw_url_request_job_factory.h",
    "browser/net/aw_web_resource_request.cc",
    "browser/net/aw_web_resource_request.h",
    "browser/net/aw_web_resource_response.cc",
    "browser/net/aw_web_resource_response.h",
    "browser/net/init_native_callback.cc",
    "browser/net/init_native_callback.h",
    "browser/net/input_stream_reader.cc",
    "browser/net/input_stream_reader.h",
    "browser/net/token_binding_manager.cc",
    "browser/net/token_binding_manager.h",
    "browser/parent_compositor_draw_constraints.cc",
    "browser/parent_compositor_draw_constraints.h",
    "browser/parent_output_surface.cc",
    "browser/parent_output_surface.h",
    "browser/permission/aw_permission_request.cc",
    "browser/permission/aw_permission_request.h",
    "browser/permission/aw_permission_request_delegate.cc",
    "browser/permission/aw_permission_request_delegate.h",
    "browser/permission/media_access_permission_request.cc",
    "browser/permission/media_access_permission_request.h",
    "browser/permission/permission_request_handler.cc",
    "browser/permission/permission_request_handler.h",
    "browser/permission/permission_request_handler_client.cc",
    "browser/permission/permission_request_handler_client.h",
    "browser/permission/simple_permission_request.cc",
    "browser/permission/simple_permission_request.h",
    "browser/popup_touch_handle_drawable.cc",
    "browser/popup_touch_handle_drawable.h",
    "browser/render_thread_manager.cc",
    "browser/render_thread_manager.h",
    "browser/render_thread_manager_client.h",
    "browser/renderer_host/auto_login_parser.cc",
    "browser/renderer_host/auto_login_parser.h",
    "browser/renderer_host/aw_render_view_host_ext.cc",
    "browser/renderer_host/aw_render_view_host_ext.h",
    "browser/renderer_host/aw_resource_dispatcher_host_delegate.cc",
    "browser/renderer_host/aw_resource_dispatcher_host_delegate.h",
    "browser/scoped_app_gl_state_restore.cc",
    "browser/scoped_app_gl_state_restore.h",
    "browser/state_serializer.cc",
    "browser/state_serializer.h",
    "browser/surfaces_instance.cc",
    "browser/surfaces_instance.h",
    "browser/token_binding_manager_bridge.cc",
    "browser/tracing/aw_tracing_delegate.cc",
    "browser/tracing/aw_tracing_delegate.h",
    "common/android_webview_message_generator.cc",
    "common/android_webview_message_generator.h",
    "common/aw_content_client.cc",
    "common/aw_content_client.h",
    "common/aw_descriptors.h",
    "common/aw_hit_test_data.cc",
    "common/aw_hit_test_data.h",
    "common/aw_media_drm_bridge_client.cc",
    "common/aw_media_drm_bridge_client.h",
    "common/aw_paths.cc",
    "common/aw_paths.h",
    "common/aw_resource.cc",
    "common/aw_resource.h",
    "common/aw_switches.cc",
    "common/aw_switches.h",
    "common/crash_reporter/aw_microdump_crash_reporter.cc",
    "common/crash_reporter/aw_microdump_crash_reporter.h",
    "common/crash_reporter/crash_keys.cc",
    "common/crash_reporter/crash_keys.h",
    "common/devtools_instrumentation.h",
    "common/render_view_messages.cc",
    "common/render_view_messages.h",
    "common/url_constants.cc",
    "common/url_constants.h",
    "gpu/aw_content_gpu_client.cc",
    "gpu/aw_content_gpu_client.h",
    "lib/aw_main_delegate.cc",
    "lib/aw_main_delegate.h",
    "lib/webview_jni_onload.cc",
    "lib/webview_jni_onload.h",
    "public/browser/draw_gl.h",
    "public/browser/draw_sw.h",
    "renderer/aw_content_renderer_client.cc",
    "renderer/aw_content_renderer_client.h",
    "renderer/aw_content_settings_client.cc",
    "renderer/aw_content_settings_client.h",
    "renderer/aw_key_systems.cc",
    "renderer/aw_key_systems.h",
    "renderer/aw_print_render_frame_helper_delegate.cc",
    "renderer/aw_print_render_frame_helper_delegate.h",
    "renderer/aw_render_frame_ext.cc",
    "renderer/aw_render_frame_ext.h",
    "renderer/aw_render_thread_observer.cc",
    "renderer/aw_render_thread_observer.h",
    "renderer/aw_render_view_ext.cc",
    "renderer/aw_render_view_ext.h",
    "renderer/print_render_frame_observer.cc",
    "renderer/print_render_frame_observer.h",
  ]

  deps = [
    ":generate_aw_resources",
    ":generate_aw_strings",
    ":generate_components_strings",
    ":native_jni",
    "//android_webview:generate_components_strings",
    "//base",
    "//base/third_party/dynamic_annotations:dynamic_annotations",
    "//components/autofill/android:provider",
    "//components/autofill/content/browser",
    "//components/autofill/content/renderer",
    "//components/cdm/browser",
    "//components/cdm/renderer",
    "//components/crash/content/app",
    "//components/crash/content/browser",
    "//components/google/core/browser",
    "//components/metrics",
    "//components/metrics:gpu",
    "//components/metrics:net",
    "//components/metrics:ui",
    "//components/navigation_interception",
    "//components/network_session_configurator/common",
    "//components/policy:generated",
    "//components/policy/core/browser",
    "//components/prefs",
    "//components/printing/browser",
    "//components/printing/common",
    "//components/printing/renderer",
    "//components/safe_browsing",
    "//components/safe_browsing/android:safe_browsing_mobile",
    "//components/safe_browsing/browser",
    "//components/safe_browsing/common",
    "//components/safe_browsing/renderer:throttles",
    "//components/safe_browsing/triggers",
    "//components/safe_browsing/web_ui",
    "//components/spellcheck:build_features",
    "//components/supervised_user_error_page",
    "//components/supervised_user_error_page:gin",
    "//components/url_matcher",
    "//components/variations/service",
    "//components/version_info",
    "//components/visitedlink/browser",
    "//components/visitedlink/renderer",
    "//components/viz/service",
    "//components/web_contents_delegate_android:web_contents_delegate_android",
    "//components/web_restrictions:browser",
    "//content",
    "//content/public/app:both",
    "//content/public/browser",
    "//content/public/common:content_descriptor_keys",
    "//content/public/common:service_names",
    "//crypto",
    "//gin",
    "//gpu/command_buffer/client:gles2_c_lib",
    "//gpu/command_buffer/client:gles2_implementation",
    "//gpu/command_buffer/common:gles2_utils",
    "//gpu/command_buffer/service",
    "//gpu/config:crash_keys",
    "//gpu/ipc:gl_in_process_context",
    "//gpu/skia_bindings",
    "//media",
    "//media/midi",
    "//net",
    "//net:extras",
    "//printing",
    "//services/service_manager/public/cpp",
    "//services/viz/public/interfaces",
    "//skia",
    "//storage/browser",
    "//storage/common",
    "//third_party/WebKit/public:blink",
    "//ui/base",
    "//ui/events:gesture_detection",
    "//ui/gfx",
    "//ui/gl",
    "//ui/gl/init",
    "//ui/shell_dialogs",
    "//v8",
  ]

  if (enable_spellcheck) {
    deps += [
      "//components/spellcheck/browser",
      "//components/spellcheck/renderer",
    ]
  }

  configs += [ "//v8:external_startup_data" ]

  libs = [ "jnigraphics" ]
}

android_library("android_webview_java") {
  java_files = [
    "java/src/org/chromium/android_webview/AndroidProtocolHandler.java",
    "java/src/org/chromium/android_webview/AutofillActionModeCallback.java",
    "java/src/org/chromium/android_webview/AwActionModeCallback.java",
    "java/src/org/chromium/android_webview/AwAutofillClient.java",
    "java/src/org/chromium/android_webview/AwAutofillManager.java",
    "java/src/org/chromium/android_webview/AwAutofillProvider.java",
    "java/src/org/chromium/android_webview/AwBrowserContext.java",
    "java/src/org/chromium/android_webview/AwBrowserProcess.java",
    "java/src/org/chromium/android_webview/AwContentVideoViewEmbedder.java",
    "java/src/org/chromium/android_webview/AwContents.java",
    "java/src/org/chromium/android_webview/AwConsoleMessage.java",
    "java/src/org/chromium/android_webview/AwContentsBackgroundThreadClient.java",
    "java/src/org/chromium/android_webview/AwContentsClient.java",
    "java/src/org/chromium/android_webview/AwContentsClientBridge.java",
    "java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java",
    "java/src/org/chromium/android_webview/AwContentsIoThreadClient.java",
    "java/src/org/chromium/android_webview/AwContentsLifecycleNotifier.java",
    "java/src/org/chromium/android_webview/AwContentsStatics.java",
    "java/src/org/chromium/android_webview/AwCookieManager.java",
    "java/src/org/chromium/android_webview/AwDebug.java",
    "java/src/org/chromium/android_webview/AwDevToolsServer.java",
    "java/src/org/chromium/android_webview/AwFormDatabase.java",
    "java/src/org/chromium/android_webview/AwGeolocationPermissions.java",
    "java/src/org/chromium/android_webview/AwGLFunctor.java",
    "java/src/org/chromium/android_webview/AwHttpAuthHandler.java",
    "java/src/org/chromium/android_webview/AwLayoutSizer.java",
    "java/src/org/chromium/android_webview/AwMetricsLogUploader.java",
    "java/src/org/chromium/android_webview/AwMetricsServiceClient.java",
    "java/src/org/chromium/android_webview/AwNetworkChangeNotifierRegistrationPolicy.java",
    "java/src/org/chromium/android_webview/AwPdfExporter.java",
    "java/src/org/chromium/android_webview/AwPicture.java",
    "java/src/org/chromium/android_webview/AwPrintDocumentAdapter.java",
    "java/src/org/chromium/android_webview/AwSafeBrowsingConfigHelper.java",
    "java/src/org/chromium/android_webview/AwSafeBrowsingResponse.java",
    "java/src/org/chromium/android_webview/AwQuotaManagerBridge.java",
    "java/src/org/chromium/android_webview/AwRenderProcessGoneDetail.java",
    "java/src/org/chromium/android_webview/AwResource.java",
    "java/src/org/chromium/android_webview/AwSafeBrowsingConversionHelper.java",
    "java/src/org/chromium/android_webview/AwScrollOffsetManager.java",
    "java/src/org/chromium/android_webview/AwServiceWorkerClient.java",
    "java/src/org/chromium/android_webview/AwServiceWorkerController.java",
    "java/src/org/chromium/android_webview/AwServiceWorkerSettings.java",
    "java/src/org/chromium/android_webview/AwSettings.java",
    "java/src/org/chromium/android_webview/AwSwitches.java",
    "java/src/org/chromium/android_webview/AwTokenBindingManager.java",
    "java/src/org/chromium/android_webview/AwViewMethods.java",
    "java/src/org/chromium/android_webview/AwViewAndroidDelegate.java",
    "java/src/org/chromium/android_webview/AwWebContentsDelegate.java",
    "java/src/org/chromium/android_webview/AwWebContentsDelegateAdapter.java",
    "java/src/org/chromium/android_webview/AwWebContentsObserver.java",
    "java/src/org/chromium/android_webview/AwWebResourceResponse.java",
    "java/src/org/chromium/android_webview/AwZoomControls.java",
    "java/src/org/chromium/android_webview/CleanupReference.java",
    "java/src/org/chromium/android_webview/ClientCertLookupTable.java",
    "java/src/org/chromium/android_webview/DefaultVideoPosterRequestHandler.java",
    "java/src/org/chromium/android_webview/ErrorCodeConversionHelper.java",
    "java/src/org/chromium/android_webview/FindAddress.java",
    "java/src/org/chromium/android_webview/FullScreenView.java",
    "java/src/org/chromium/android_webview/HttpAuthDatabase.java",
    "java/src/org/chromium/android_webview/InputStreamUtil.java",
    "java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java",
    "java/src/org/chromium/android_webview/JsPromptResultReceiver.java",
    "java/src/org/chromium/android_webview/JsResultHandler.java",
    "java/src/org/chromium/android_webview/JsResultReceiver.java",
    "java/src/org/chromium/android_webview/NullAwViewMethods.java",
    "java/src/org/chromium/android_webview/OverScrollGlow.java",
    "java/src/org/chromium/android_webview/PopupTouchHandleDrawable.java",
    "java/src/org/chromium/android_webview/ResourcesContextWrapperFactory.java",
    "java/src/org/chromium/android_webview/ScrollAccessibilityHelper.java",
    "java/src/org/chromium/android_webview/SslUtil.java",
    "java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java",
    "java/src/org/chromium/android_webview/permission/AwPermissionRequest.java",
    "java/src/org/chromium/android_webview/policy/AwPolicyProvider.java",
    "java/src/org/chromium/android_webview/variations/AwVariationsConfigurationService.java",
    "java/src/org/chromium/android_webview/variations/AwVariationsSeedFetchService.java",
    "java/src/org/chromium/android_webview/variations/AwVariationsSeedHandler.java",
    "java/src/org/chromium/android_webview/variations/AwVariationsUtils.java",
  ]
  deps = [
    ":android_webview_commandline_java",
    ":android_webview_crash_services_java",
    ":android_webview_platform_services_java",
    ":resources",
    ":strings_grd",
    ":system_webview_manifest",
    "//base:base_java",
    "//components/autofill/android:autofill_java",
    "//components/autofill/android:provider_java",
    "//components/background_task_scheduler:background_task_scheduler_java",
    "//components/crash/android:java",
    "//components/minidump_uploader:minidump_uploader_java",
    "//components/navigation_interception/android:navigation_interception_java",
    "//components/policy/android:policy_java",
    "//components/safe_browsing/android:safe_browsing_java",
    "//components/variations/android:variations_java",
    "//components/web_contents_delegate_android:web_contents_delegate_android_java",
    "//components/web_restrictions:client_java",
    "//content/public/android:content_java",
    "//device/gamepad:java",
    "//device/geolocation:geolocation_java",
    "//net/android:net_java",
    "//third_party/WebKit/public:blink_headers_java",
    "//third_party/android_tools:android_support_annotations_java",
    "//ui/android:ui_java",
  ]

  if (enable_spellcheck) {
    deps += [ "//components/spellcheck/browser/android:java" ]
  }

  srcjar_deps = [
    ":aw_permission_request_resource",
    ":android_webview_java_enums_srcjar",
    ":aw_error_ui",
    ":aw_safe_browsing_action",
    "//components/safe_browsing/db:sb_threat_values",
  ]

  # Manifest used for linting (determining unused resources).
  android_manifest = system_webview_android_manifest
}

java_strings_grd("strings_grd") {
  grd_file = "java/strings/android_webview_strings.grd"
  outputs = [
    "values-am/android_webview_strings.xml",
    "values-ar/android_webview_strings.xml",
    "values-bg/android_webview_strings.xml",
    "values-ca/android_webview_strings.xml",
    "values-cs/android_webview_strings.xml",
    "values-da/android_webview_strings.xml",
    "values-de/android_webview_strings.xml",
    "values-el/android_webview_strings.xml",
    "values-en-rGB/android_webview_strings.xml",
    "values-es-rUS/android_webview_strings.xml",
    "values-es/android_webview_strings.xml",
    "values-fa/android_webview_strings.xml",
    "values-fi/android_webview_strings.xml",
    "values-fr/android_webview_strings.xml",
    "values-hi/android_webview_strings.xml",
    "values-hr/android_webview_strings.xml",
    "values-hu/android_webview_strings.xml",
    "values-in/android_webview_strings.xml",
    "values-it/android_webview_strings.xml",
    "values-iw/android_webview_strings.xml",
    "values-ja/android_webview_strings.xml",
    "values-ko/android_webview_strings.xml",
    "values-lt/android_webview_strings.xml",
    "values-lv/android_webview_strings.xml",
    "values-nb/android_webview_strings.xml",
    "values-nl/android_webview_strings.xml",
    "values-pl/android_webview_strings.xml",
    "values-pt-rBR/android_webview_strings.xml",
    "values-pt-rPT/android_webview_strings.xml",
    "values-ro/android_webview_strings.xml",
    "values-ru/android_webview_strings.xml",
    "values-sk/android_webview_strings.xml",
    "values-sl/android_webview_strings.xml",
    "values-sr/android_webview_strings.xml",
    "values-sv/android_webview_strings.xml",
    "values-sw/android_webview_strings.xml",
    "values-th/android_webview_strings.xml",
    "values-tl/android_webview_strings.xml",
    "values-tr/android_webview_strings.xml",
    "values-uk/android_webview_strings.xml",
    "values-vi/android_webview_strings.xml",
    "values-zh-rCN/android_webview_strings.xml",
    "values-zh-rTW/android_webview_strings.xml",
    "values/android_webview_strings.xml",
  ]
}

# Separate target to allow for a dependency on GmsCore without pulling in all of
# android_webview_java.
android_library("android_webview_platform_services_java") {
  java_files =
      [ "java/src/org/chromium/android_webview/PlatformServiceBridge.java" ]

  deps = [
    "//base:base_java",
    "//third_party/android_tools:android_support_annotations_java",
  ]
}

android_library("android_webview_commandline_java") {
  java_files = [ "java/src/org/chromium/android_webview/command_line/CommandLineUtil.java" ]

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

# Keep crash services separate from other WebView code to keep their deps clean
# (and make them easy to move).
android_library("android_webview_crash_services_java") {
  java_files = [
    "java/src/org/chromium/android_webview/crash/AwMinidumpUploadJobService.java",
    "java/src/org/chromium/android_webview/crash/AwMinidumpUploaderDelegate.java",
    "java/src/org/chromium/android_webview/crash/CrashReceiverService.java",
  ]
  deps = [
    ":android_webview_commandline_java",
    ":android_webview_platform_services_java",
    "//base:base_java",
    "//components/background_task_scheduler:background_task_scheduler_java",
    "//components/minidump_uploader:minidump_uploader_java",
  ]

  srcjar_deps = [ ":crash_receiver_aidl" ]
}

android_aidl("crash_receiver_aidl") {
  import_include = [ "java/src" ]
  sources = [
    "java/src/org/chromium/android_webview/crash/ICrashReceiverService.aidl",
  ]
}

if (public_android_sdk) {
  system_webview_apk_tmpl("system_webview_apk") {
    android_manifest = system_webview_android_manifest
    android_manifest_dep = ":system_webview_manifest"
    deps = [
      ":system_webview_resources",
      "//android_webview/glue",
    ]
    apk_name = "SystemWebView"
  }
}