# 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("//build/config/ios/rules.gni")
import("//ios/build/config.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//services/service_manager/public/service_manifest.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")

ios_app_bundle("ios_web_shell") {
  info_plist = "Info.plist"

  deps = [
    ":shell",

    # All shared libraries must have the sanitizer deps to properly link in
    # asan mode (this target will be empty in other cases).
    "//build/config:exe_and_shlib_deps",
  ]

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

  assert_no_deps = ios_assert_no_deps
}

bundle_data("shell_bundle_data") {
  visibility = [ ":shell" ]
  sources = [
    "Default.png",
    "textfield_background@2x.png",
    "toolbar_back@2x.png",
    "toolbar_forward@2x.png",
  ]
  outputs = [
    "{{bundle_resources_dir}}/{{source_file_part}}",
  ]
}

service_manifest("shell_packaged_services_manifest_overlay") {
  source = "web_shell_packaged_services_manifest_overlay.json"
  packaged_services = [ "//services/test/echo:manifest" ]
}

service_manifest("shell_browser_manifest_overlay") {
  source = "web_shell_browser_manifest_overlay.json"
  packaged_services = [ "//services/test/user_id:manifest" ]
}

grit("resources") {
  visibility = [ ":*" ]
  source = "shell_resources.grd"

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

  grit_flags = [
    "-E",
    "root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
  ]
  outputs = [
    "grit/shell_resources.h",
    "shell_resources.pak",
  ]
  deps = [
    ":shell_browser_manifest_overlay",
    ":shell_packaged_services_manifest_overlay",
  ]
}

repack("packed_resources") {
  visibility = [ ":shell" ]
  sources = [
    "$root_gen_dir/ios/web/ios_web_resources.pak",
    "$root_gen_dir/ios/web/shell/shell_resources.pak",
  ]
  deps = [
    "//ios/web:resources",
  ]
  public_deps = [
    ":resources",
  ]
  output = "$target_gen_dir/web_shell_resources.pak"
  copy_data_to_bundle = true
}

mojom("shell_interfaces") {
  sources = [
    "web_usage_controller.mojom",
  ]
}

source_set("shell") {
  sources = [
    "app_delegate.h",
    "app_delegate.mm",
    "shell_browser_state.h",
    "shell_browser_state.mm",
    "shell_main_delegate.h",
    "shell_main_delegate.mm",
    "shell_network_delegate.cc",
    "shell_network_delegate.h",
    "shell_url_request_context_getter.h",
    "shell_url_request_context_getter.mm",
    "shell_web_client.h",
    "shell_web_client.mm",
    "shell_web_main_parts.h",
    "shell_web_main_parts.mm",
    "view_controller.h",
    "view_controller.mm",
    "web_exe_main.mm",
  ]

  deps = [
    ":packed_resources",
    ":shell_bundle_data",
    ":shell_interfaces",
    "//base",
    "//ios/net",
    "//ios/web",
    "//ios/web/public",
    "//ios/web/public/app",
    "//net",
    "//net:extras",
    "//services/service_manager/public/cpp",
    "//services/test/echo:lib",
    "//services/test/echo/public/interfaces",
    "//services/test/user_id:lib",
    "//services/test/user_id/public/interfaces",
    "//ui/base",
  ]

  libs = [
    "CoreGraphics.framework",
    "CoreFoundation.framework",
    "Foundation.framework",
    "UIKit.framework",
  ]

  configs += [ "//build/config/compiler:enable_arc" ]
}