# Copyright 2022 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/config/ui.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
import("//tools/v8_context_snapshot/v8_context_snapshot.gni")

assert(use_aura)

static_library("webui_examples_lib") {
  testonly = true

  sources = [
    "app/main_delegate.cc",
    "app/main_delegate.h",
    "browser/browser_context.cc",
    "browser/browser_context.h",
    "browser/browser_main_parts.cc",
    "browser/browser_main_parts.h",
    "browser/content_browser_client.cc",
    "browser/content_browser_client.h",
    "browser/devtools/devtools_frontend.cc",
    "browser/devtools/devtools_frontend.h",
    "browser/devtools/devtools_manager_delegate.cc",
    "browser/devtools/devtools_manager_delegate.h",
    "browser/devtools/devtools_server.cc",
    "browser/devtools/devtools_server.h",
    "browser/ui/aura/aura_context.cc",
    "browser/ui/aura/aura_context.h",
    "browser/ui/aura/content_window.cc",
    "browser/ui/aura/content_window.h",
    "browser/ui/aura/fill_layout.cc",
    "browser/ui/aura/fill_layout.h",
    "browser/ui/web/webui.cc",
    "browser/ui/web/webui.h",
    "browser/webui_controller_factory.cc",
    "browser/webui_controller_factory.h",
    "common/content_client.cc",
    "common/content_client.h",
  ]

  data_deps = [ "//tools/v8_context_snapshot" ]

  deps = [
    ":pak",
    ":resources_grit",
    "//base",
    "//chrome/browser/resources/webui_gallery:resources",
    "//content/public/app",
    "//content/public/browser",
    "//ipc",
    "//net",
    "//ui/aura",
    "//ui/aura:test_support",
    "//ui/base",
    "//ui/display",
    "//ui/platform_window",
    "//ui/wm",
    "//ui/wm/public",
    "//url",
  ]
}

grit("resources") {
  testonly = true
  grit_flags = [
    "-E",
    "root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
  ]
  source = "resources/webui_examples_resources.grd"
  outputs = [
    "grit/webui_examples_resources.h",
    "webui_examples_resources.pak",
  ]
}

repack("pak") {
  testonly = true
  sources = [
    "$root_gen_dir/chrome/webui_gallery_resources.pak",
    "$root_gen_dir/content/browser/devtools/devtools_resources.pak",
    "$root_gen_dir/third_party/blink/public/resources/blink_resources.pak",
    "$root_gen_dir/third_party/blink/public/resources/blink_scaled_resources_100_percent.pak",
    "$root_gen_dir/third_party/blink/public/resources/inspector_overlay_resources.pak",
    "$root_gen_dir/ui/resources/webui_resources.pak",
    "$root_gen_dir/ui/strings/app_locale_settings_en-US.pak",
    "$root_gen_dir/ui/strings/ui_strings_en-US.pak",
    "$target_gen_dir/webui_examples_resources.pak",
  ]
  deps = [
    ":resources",
    "//chrome/browser/resources/webui_gallery:resources",
    "//content/browser/devtools:devtools_resources",
    "//third_party/blink/public:devtools_inspector_resources",
    "//third_party/blink/public:resources",
    "//third_party/blink/public:scaled_resources_100_percent",
    "//ui/resources",
    "//ui/strings",
  ]
  output = "$root_out_dir/webui_examples.pak"
}

executable("webui_examples") {
  testonly = true

  sources = [ "app/main.cc" ]

  deps = [
    ":webui_examples_lib",
    "//base",
    "//content/public/app",
  ]

  if (is_win) {
    configs += [ "//build/config/win:windowed" ]

    deps += [
      "//build/win:default_exe_manifest",
      "//content:sandbox_helper_win",
      "//sandbox/win:sandbox",
    ]
  }
}