# 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("//build/config/features.gni")
import("//build/config/ui.gni")
import("//content/common/common.gni")
import("//mojo/public/tools/bindings/mojom.gni")

source_set("common") {
  # Only targets in the content tree can depend directly on this target.
  visibility = [ "//content/*" ]

  sources = rebase_path(content_common_gypi_values.private_common_sources,
                        ".", "//content")

  forward_dependent_configs_from = [
    "//gpu/command_buffer/common",
    "//third_party/WebKit/public:blink_headers",
  ]

  configs += [
    "//content:content_implementation",
    "//content:libjingle_stub_config",
  ]

  deps = [
    "//base",
    "//build/util:webkit_version",
    "//components/tracing",
    "//gpu/command_buffer/common",
    "//net",
    "//skia",
    "//third_party/icu",
    "//ui/accessibility",
    "//ui/base",
    "//ui/gfx",
    "//ui/gfx/geometry",
    "//url",
    "//third_party/WebKit/public:blink_headers",
    # TODO(GYP) convert these dependencies.
    #'../third_party/libjingle/libjingle.gyp:libjingle',
    #'../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs',
  ]

  if (!is_ios) {
    deps += [
      "//cc",
      "//ipc",
      "//mojo/environment:chromium",
      "//mojo/system",
      # TODO: the dependency on gl_in_process_context should be decoupled from
      # content and moved to android_webview. See crbug.com/365797.
      "//gpu/command_buffer/client:gl_in_process_context",
      "//gpu/command_buffer/client:gles2_c_lib",
      "//gpu/command_buffer/client:gles2_implementation",
      "//gpu/command_buffer/service",
      "//gpu/ipc",
      "//ui/gl",
      "//webkit/browser:storage",
      "//webkit/common",
      "//webkit/common:storage",
      "//webkit/common/gpu",
      #'../gpu/gpu.gyp:gl_in_process_context',
      #'../gpu/skia_bindings/skia_bindings.gyp:gpu_skia_bindings',
      #'../media/media.gyp:media',
      #'../media/media.gyp:shared_memory_support',
      #'../third_party/WebKit/public/blink.gyp:blink',
    ]
  }

  defines = []
  include_dirs = []
  libs = []
  ldflags = []

  if (is_android && use_seccomp_bpf) {
    set_sources_assignment_filter([])
    sources += [
      "sandbox_linux/sandbox_bpf_base_policy_linux.cc",
      "sandbox_linux/sandbox_bpf_base_policy_linux.h",
    ]
    set_sources_assignment_filter(sources_assignment_filter)
  }

  if (is_mac) {
    sources += [
      "gpu/client/gpu_memory_buffer_impl_io_surface.cc",
      "gpu/client/gpu_memory_buffer_impl_io_surface.h",
    ]
    sources -= [
      "plugin_list_posix.cc",
    ]

    # TODO(GYP) enable when converted to GN.
    #deps += [
    #  "//webkit:webkit_resources",
    #]
    libs += [ "QuartzCore.framework" ]
  }

  if (is_android) {
    sources += [
      "gpu/client/gpu_memory_buffer_impl_surface_texture.cc",
      "gpu/client/gpu_memory_buffer_impl_surface_texture.h",
    ]

    # TODO(GYP) enable when these targets are converted.
    #deps += [
    #  "//content:content_jni_headers",
    #  "//content:common_aidl",
    #]

    libs += [ "android" ]
  }

  if (is_ios) {
    sources -= [ "user_agent.cc" ]
    assert(false, "Need to add lots of conditions here")
  }

  if (!use_ozone) {
    sources -= [
      "cursors/webcursor_ozone.cc",
      "font_list_ozone.cc",
    ]
  }

  if (!use_aura || !use_x11) {
    sources -= [ "cursors/webcursor_aurax11.cc" ]
  }

  if (use_pango) {
    configs += [ "//build/config/linux:pangocairo" ]
    if (use_ozone) {
      # If we're using pango, never use this ozone file (it was removed in all
      # non-ozone cases above).
      sources -= [ "font_list_ozone.cc" ]
    }
  } else {
    sources -= [
      "font_list_pango.cc",
    ]
  }

  if (use_x11) {
    include_dirs += [ "//third_party/khronos" ]
    configs += [ "//build/config/linux:xcomposite" ]

    if (cpu_arch != "arm" || !is_chromeos) {
      sources +=[
        "gpu/x_util.cc",
        "gpu/x_util.h",
      ]
    }
  }

  if (enable_plugins) {
    deps += [
      "//ppapi:ppapi_shared",
    ]
  } else {
    sources -= [
      "pepper_plugin_list.cc",
      "pepper_plugin_list.h",
      "sandbox_util.cc",
    ]
  }

  if (is_android) {
    sources += [
      "gpu/media/android_video_decode_accelerator.cc",
      "gpu/media/android_video_decode_accelerator.h",
    ]
    deps += [
      # TODO(GYP) enable once supported in the GN build.
      #"//media",
    ]

    if (enable_webrtc) {
      deps += [ "//third_party/libyuv" ]
    }
  }

  if (is_chromeos && use_x11) {
    if (cpu_arch == "arm") {
      sources += [
        "gpu/media/exynos_v4l2_video_device.cc",
        "gpu/media/exynos_v4l2_video_device.h",
        "gpu/media/tegra_v4l2_video_device.cc",
        "gpu/media/tegra_v4l2_video_device.h",
        "gpu/media/v4l2_image_processor.cc",
        "gpu/media/v4l2_image_processor.h",
        "gpu/media/v4l2_video_decode_accelerator.cc",
        "gpu/media/v4l2_video_decode_accelerator.h",
        "gpu/media/v4l2_video_device.cc",
        "gpu/media/v4l2_video_device.h",
        "gpu/media/v4l2_video_encode_accelerator.cc",
        "gpu/media/v4l2_video_encode_accelerator.h",
      ]
      # TODO(GYP) enable once supported in the GN build.
      #deps += [ "//media" ]
      libs = [ "EGL", "GLESv2" ]
    } else {  # !arm
      sources += [
        "gpu/media/h264_dpb.cc",
        "gpu/media/h264_dpb.h",
        "gpu/media/va_surface.h",
        "gpu/media/vaapi_h264_decoder.cc",
        "gpu/media/vaapi_h264_decoder.h",
        "gpu/media/vaapi_video_decode_accelerator.cc",
        "gpu/media/vaapi_video_decode_accelerator.h",
        "gpu/media/vaapi_wrapper.cc",
        "gpu/media/vaapi_wrapper.h",
      ]
      assert(false, "Implement generate_stubs for libva")
    }
  }

  if (is_win) {
    sources += [
      "gpu/media/dxva_video_decode_accelerator.cc",
      "gpu/media/dxva_video_decode_accelerator.h",
    ]
    include_dirs += [ "//third_party/khronos" ]
    deps += [
      # TODO(GYP) enable once supported in the GN build.
      #"//media",
      "//ui/gl",
    ]

    # TODO(GYP): extract_xinput action.
  }

  if (!is_win || !use_aura) {
    sources -= [ "cursors/webcursor_aurawin.cc" ]
  }

  if (use_seccomp_bpf) {
    defines += [ "USE_SECCOMP_BPF" ]
  } else {
    if (is_linux) {
      sources -= [
        "sandbox_linux/bpf_cros_arm_gpu_policy_linux.cc",
        "sandbox_linux/bpf_cros_arm_gpu_policy_linux.h",
        "sandbox_linux/bpf_gpu_policy_linux.cc",
        "sandbox_linux/bpf_gpu_policy_linux.h",
        "sandbox_linux/bpf_ppapi_policy_linux.cc",
        "sandbox_linux/bpf_ppapi_policy_linux.h",
        "sandbox_linux/bpf_renderer_policy_linux.cc",
        "sandbox_linux/bpf_renderer_policy_linux.h",
        "sandbox_linux/sandbox_bpf_base_policy_linux.cc",
        "sandbox_linux/sandbox_bpf_base_policy_linux.h",
      ]
    }
    if (is_android) {
      sources -= [
        "sandbox_linux/android/sandbox_bpf_base_policy_android.cc",
        "sandbox_linux/android/sandbox_bpf_base_policy_android.h",
      ]
    }
  }
}

mojom("mojo_bindings") {
  sources = [
    "web_ui_setup.mojom",
  ]
}