# 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("//extensions/shell/app_shell.gni")

# Technically, this directory should not depend on files from src/chrome, but
# that's where the VERSION file is. This  should probably all be moved to
# src/build.
import("//chrome/version.gni")
import("//testing/test.gni")
import("//tools/grit/grit_rule.gni")

assert(enable_extensions)

grit("resources") {
  source = "app_shell_resources.grd"
  outputs = [
    "grit/app_shell_resources.h",
    "app_shell_resources.pak",
  ]
}

source_set("app_shell_lib") {
  # TODO(jamescook): investigate and get rid of test dependencies. This library
  # is testonly because it depends on testonly libraries, namely
  # //content/shell:content_shell_lib. See http://crbug.com/438283
  testonly = true
  deps = [
    ":resources",
    ":version_header",
    "//base",
    "//base:prefs",
    "//components/devtools_discovery",
    "//components/devtools_http_handler",
    "//components/guest_view/browser",
    "//components/guest_view/common",
    "//components/guest_view/renderer",
    "//components/pref_registry",
    "//components/update_client",
    "//components/user_prefs",
    "//components/web_cache/renderer",
    "//content",
    "//content/shell:content_shell_lib",
    "//device/core",
    "//device/hid",
    "//extensions/common/api",
    "//extensions/common/api:api_registration",
    "//extensions/browser",
    "//extensions/common",
    "//extensions/renderer",
    "//extensions/shell/common/api",
    "//extensions/shell/common/api:api_registration",
    "//extensions/utility",
    "//extensions:extensions_resources",
    "//extensions:shell_and_test_pak",
    "//mojo/environment:chromium",
    "//skia",
    "//third_party/WebKit/public:blink",
    "//third_party/mojo/src/mojo/edk/system",
    "//ui/base",
    "//ui/base/ime",
    "//v8",
  ]

  sources = rebase_path(app_shell_gypi_values.app_shell_lib_sources,
                        ".",
                        "//extensions/shell")

  if (use_aura) {
    deps += [ "//ui/wm" ]

    aura_sources = rebase_path(app_shell_gypi_values.app_shell_lib_sources_aura,
                               ".",
                               "//extensions/shell")
    sources += aura_sources
  }

  if (is_chromeos) {
    deps += [
      "//chromeos",
      "//ui/chromeos:ui_chromeos",
      "//ui/display",
    ]
    chromeos_sources =
        rebase_path(app_shell_gypi_values.app_shell_lib_sources_chromeos,
                    ".",
                    "//extensions/shell")
    sources += chromeos_sources
  }

  # TODO(GYP): Enable this when //components/nacl GN is done. See
  # http://crbug.com/430602
  if (false) {
    if (enable_nacl) {
      if (is_linux) {
        deps += [ "//components/nacl:nacl_helper" ]
      }
      deps += [
        "//components/nacl",
        "//components/nacl:browser",
        "//components/nacl:common",
        "//components/nacl:renderer",
        "//components/nacl:switches",
      ]
      nacl_sources =
          rebase_path(app_shell_gypi_values.app_shell_lib_sources_nacl,
                      ".",
                      "//extensions/shell")
      sources += nacl_sources
    }
  }

  if (enable_nacl) {
    sources += [
      "browser/shell_nacl_browser_delegate.cc",
      "browser/shell_nacl_browser_delegate.h",
    ]

    deps += [
      "//components/nacl",
      "//components/nacl:nacl_browser",
      "//components/nacl:nacl_common",
      "//components/nacl:nacl_renderer",
      "//components/nacl:nacl_switches",
      "//components/nacl/renderer/plugin:nacl_trusted_plugin",
    ]

    if (is_linux) {
      deps += [ "//components/nacl:nacl_helper" ]
    }
  }
}

if (!(is_chromeos && !use_ozone)) {
  executable("app_shell") {
    # testonly because :app_shell_lib is testonly. See :app_shell_lib comment.
    testonly = true
    sources = rebase_path(app_shell_gypi_values.app_shell_sources,
                          ".",
                          "//extensions/shell")
    deps = [
      ":app_shell_lib",
      "//extensions:shell_and_test_pak",
    ]

    if (is_win) {
      configs += [ "//build/config/win:windowed" ]
      configs -= [ "//build/config/win:console" ]
      deps += [ "//base/allocator" ]
    }

    if (is_mac) {
      # TODO(GYP): Mac bundling
    }
  }
}

# TODO(GYP): Delete this after we've converted everything to GN.
# The _run targets exist only for compatibility w/ GYP.
group("app_shell_unittests_run") {
  testonly = true
  deps = [
    ":app_shell_unittests",
  ]
}

test("app_shell_unittests") {
  sources = rebase_path(app_shell_gypi_values.app_shell_unittests_sources,
                        ".",
                        "//extensions/shell")

  data = [
    "//extensions/test/data/",
    "$root_out_dir/extensions_shell_and_test.pak",

    #"$root_out_dir/natives_blob.bin", # move to gin
    #"$root_out_dir/snapshot_blob.bin",
  ]

  deps = [
    ":app_shell_lib",
    "//base",
    "//base/test:test_support",
    "//content/test:test_support",
    "//extensions:shell_and_test_pak",
    "//extensions:test_support",
    "//testing/gtest",
  ]

  data_deps = [
    # "//gin", # TODO(dpranke): Either gin or v8 data is needed ...
    "//third_party/mesa:osmesa",
  ]

  if (use_aura) {
    deps += [ "//ui/aura:test_support" ]

    aura_sources =
        rebase_path(app_shell_gypi_values.app_shell_unittests_sources_aura,
                    ".",
                    "//extensions/shell")
    sources += aura_sources
  }

  if (is_chromeos) {
    deps += [ "//chromeos:test_support_without_gmock" ]

    chromeos_sources =
        rebase_path(app_shell_gypi_values.app_shell_unittests_sources_chromeos,
                    ".",
                    "//extensions/shell")
    sources += chromeos_sources
  }

  # TODO(GYP): Enable this when //components/nacl GN is done.
  if (false) {
    if (use_nacl) {
      nacl_sources =
          rebase_path(app_shell_gypi_values.app_shell_unittests_sources_nacl,
                      ".",
                      "//extensions/shell")
      sources += nacl_sources
    }
  }

  if (is_win) {
    deps += [ "//base/allocator" ]
  }
}

process_version("version_header") {
  template_file = "common/version.h.in"
  output = "$target_gen_dir/common/version.h"
}