# 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 the public target should depend on this. All other targets (even
  # internal content ones) should depend on the public one.
  visibility = [ "//content/public/common:common_sources" ]

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

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

  public_deps = [
    "//gpu/command_buffer/common",
    "//third_party/WebKit/public:blink_headers",
  ]
  deps = [
    "//base",
    "//build/util:webkit_version",
    "//components/tracing",
    "//gpu/command_buffer/client:gles2_interface",
    "//net",
    "//skia",
    "//third_party/icu",
    "//ui/accessibility",
    "//ui/base",
    "//ui/gfx",
    "//ui/gfx/geometry",
    "//ui/gfx/ipc",
    "//ui/shell_dialogs",
    "//url",
    "//third_party/libjingle",
  ]

  if (!is_ios) {
    deps += [
      "//cc",
      "//ipc",
      "//ipc/mojo",
      # 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_cmd_helper",
      "//gpu/command_buffer/client:gles2_implementation",
      "//gpu/command_buffer/service",
      "//gpu/ipc",
      "//gpu/skia_bindings",
      "//media",
      "//media:shared_memory_support",
      "//mojo/environment:chromium",
      "//mojo/public/interfaces/application",
      "//mojo/system",
      "//sandbox",
      "//storage/browser",
      "//storage/common",
      "//third_party/WebKit/public:blink",
      "//ui/gl",
      "//webkit/common/gpu",
    ]
  }

  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",
    ]

    deps += [
      "//content/app/resources",
      "//content:resources",
      "//third_party/WebKit/public: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",
    ]

    deps += [
      "//content/public/android:jni",
      "//content/public/android: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",
      "gpu/gpu_memory_buffer_factory_ozone.cc",
    ]
  }

  if (!use_aura) {
    sources -= [ "cursors/webcursor_aura.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) {
    sources += [
      "gpu/gpu_memory_buffer_factory_x11_pixmap.cc",
      "common/gpu/gpu_memory_buffer_factory_x11_pixmap.h",
    ]
    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",
      ]
    }
  } else {
    sources -= [
      "gpu/gpu_memory_buffer_factory_x11.cc",
    ]
  }

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

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

    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",
      ]
      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 += [
      "//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/bpf_utility_policy_linux.cc",
        "sandbox_linux/bpf_utility_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 = [
    "render_frame_setup.mojom",
  ]

  deps = [
    "//mojo/public/interfaces/application:application",
  ]
}