# Copyright 2015 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/apple/tweak_info_plist.gni")
import("//build/config/mac/rules.gni")
import("//build/util/branding.gni")

# This is the part of the shim process compiled into Chrome. It runs only
# in the shim process, after the shim finds and loads the Chrome
# Framework bundle.
source_set("app_shim") {
  sources = [
    "../app/chrome_crash_reporter_client.h",
    "app_shim_controller.h",
    "app_shim_controller.mm",
    "app_shim_delegate.h",
    "app_shim_delegate.mm",
    "app_shim_render_widget_host_view_mac_delegate.h",
    "app_shim_render_widget_host_view_mac_delegate.mm",
    "chrome_main_app_mode_mac.mm",
  ]

  deps = [
    "//base/allocator:early_zone_registration_apple",
    "//build:chromeos_buildflags",
    "//cef/libcef/features:buildflags",
    "//chrome:strings",
    "//chrome/app:command_ids",
    "//chrome/browser/renderer_host:history_swiper",
    "//chrome/browser/ui",
    "//chrome/common",
    "//chrome/common:mojo_bindings",
    "//chrome/services/mac_notifications",
    "//components/crash/core/app",
    "//components/remote_cocoa/app_shim",
    "//components/variations/field_trial_config",
    "//content/public/browser",
    "//ipc",
    "//mojo/core/embedder",
    "//mojo/core/embedder:features",
    "//ui/accelerated_widget_mac",
    "//ui/base",
  ]
}

tweak_info_plist("tweak_app_mode_loader_plist") {
  info_plist = "app_mode-Info.plist"
  args = [
    "--breakpad=0",
    "--keystone=0",
    "--scm=0",
  ]
}

mac_info_plist("app_mode_loader_plist") {
  info_plist_target = ":tweak_app_mode_loader_plist"

  executable_name = "app_mode_loader"

  extra_substitutions = [
    "APP_MODE_APP_BUNDLE_ID=$chrome_mac_bundle_id.app.@APP_MODE_SHORTCUT_ID@",
  ]
}

bundle_data("app_mode_loader_plist_bundle_data") {
  sources = get_target_outputs(":app_mode_loader_plist")

  outputs = [ "{{bundle_resources_dir}}/app_mode-Info.plist" ]

  public_deps = [ ":app_mode_loader_plist" ]
}

executable("app_mode_loader") {
  configs += [ "//build/config/compiler:wexit_time_destructors" ]

  sources = [ "app_mode_loader_mac.mm" ]

  if (is_component_build || is_asan || is_ubsan_any) {
    # Loaders are installed to ~/Applications. In a component build, reserve
    # enough space in the header to be able to add the out dir to the library
    # search path so that components can be found at launch. Note that directly
    # including the (current) out dir in the library search path doesn't work
    # since the build might be moved to a different path before running (for
    # example when running tests on bots).
    ldflags = [
      "-Wl,-headerpad",
      "-Wl,256",
    ]
  }

  deps = [
    "//base",
    "//base/allocator:early_zone_registration_apple",
    "//chrome/common:app_mode_app_support",
    "//chrome/common:constants",
    "//chrome/common:non_code_constants",
  ]

  frameworks = [
    "AppKit.framework",
    "CoreFoundation.framework",
    "Foundation.framework",
  ]
}

source_set("browser_tests") {
  testonly = true
  sources = [ "app_shim_controller_browsertest.mm" ]
  defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
  deps = [
    "//chrome/app_shim",
    "//chrome/browser/ui",
    "//chrome/browser/web_applications:web_applications_test_support",
    "//chrome/test:test_support",
    "//components/remote_cocoa/app_shim",
    "//content/test:test_support",
  ]
}