Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history


Add --headless flag to Windows:

Fix browser_tests not compiling properly on windows
Fix headless/BUILD.gn by:
   - Changing headless_lib to a headless component, following steps in https://chromium.googlesource.com/chromium/src/+/master/docs/component_build.md and fixing the build for linux, since it now compiles as a shared_library when component build is true.
   - Adding neccesary HEADLESS_EXPORT (submitted in https://codereview.chromium.org/2775693003/)
   - Disabling breakpad in windows (will fix in a separate CL)

BUG=686608

Review-Url: https://codereview.chromium.org/2762593002
Cr-Original-Commit-Position: refs/heads/master@{#466176}
Committed: https://chromium.googlesource.com/chromium/src/+/e3c745d4b37a659afaa0358c7de7b9bc881decb5
Review-Url: https://codereview.chromium.org/2762593002
Cr-Commit-Position: refs/heads/master@{#466259}
  • Loading branch information
dvallet authored and Commit bot committed Apr 21, 2017
1 parent 5ed3927 commit d238dae
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 74 deletions.
2 changes: 2 additions & 0 deletions chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ if (is_win) {
"//components/policy:generated",
"//content/app/resources",
"//crypto",
"//headless:headless_shell_browser_lib",
"//net:net_resources",
"//ppapi/features",
"//third_party/cld",
Expand Down Expand Up @@ -432,6 +433,7 @@ if (is_win) {
"//components/browser_watcher:browser_watcher_client",
"//components/crash/content/app",
"//content/public/app:child",
"//headless:headless_shell_child_lib",
]

ldflags = [
Expand Down
12 changes: 5 additions & 7 deletions chrome/app/chrome_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,20 @@ int ChromeMain(int argc, const char** argv) {
#else
params.argc = argc;
params.argv = argv;
#endif

#if !defined(OS_WIN)
base::CommandLine::Init(params.argc, params.argv);
#endif // defined(OS_WIN)
base::CommandLine::Init(0, nullptr);
const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
ALLOW_UNUSED_LOCAL(command_line);
#endif

#if defined(OS_LINUX) || defined(OS_MACOSX)
#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
if (command_line->HasSwitch(switches::kHeadless)) {
#if defined(OS_MACOSX)
SetUpBundleOverrides();
#endif
return headless::HeadlessShellMain(argc, argv);
return headless::HeadlessShellMain(params);
}
#endif // defined(OS_LINUX) || defined(OS_MACOSX)
#endif // defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)

#if defined(OS_CHROMEOS) && BUILDFLAG(ENABLE_PACKAGE_MASH_SERVICES)
version_info::Channel channel = chrome::GetChannel();
Expand Down
147 changes: 119 additions & 28 deletions headless/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ config("headless_implementation") {
}
}

group("headless") {
group("headless_lib") {
deps = [
"//headless:headless_lib",
"//headless:headless",
]
}

Expand Down Expand Up @@ -202,7 +202,7 @@ action("gen_devtools_client_api") {
]
}

static_library("headless_lib") {
component("headless") {
sources = generated_devtools_api + [
"app/headless_shell_switches.cc",
"app/headless_shell_switches.h",
Expand Down Expand Up @@ -244,10 +244,6 @@ static_library("headless_lib") {
"lib/headless_crash_reporter_client.h",
"lib/headless_content_client.cc",
"lib/headless_content_client.h",
"lib/headless_content_main_delegate.cc",
"lib/headless_content_main_delegate.h",
"lib/renderer/headless_content_renderer_client.cc",
"lib/renderer/headless_content_renderer_client.h",
"public/headless_browser.cc",
"public/headless_browser.h",
"public/headless_browser_context.h",
Expand Down Expand Up @@ -328,9 +324,6 @@ static_library("headless_lib") {
"//components/crash/content/browser",
"//components/security_state/content",
"//components/security_state/core",
"//content/public/app:both",
"//content/public/browser",
"//content/public/child:child",
"//content/public/common",
"//content/public/common:service_names",
"//services/service_manager/public/cpp",
Expand All @@ -342,15 +335,24 @@ static_library("headless_lib") {
"//url",
]

if (!is_mac) {
deps += [ "//ui/aura" ]
if (is_component_build) {
sources += [
"lib/headless_content_main_delegate.cc",
"lib/headless_content_main_delegate.h",
"lib/renderer/headless_content_renderer_client.cc",
"lib/renderer/headless_content_renderer_client.h",
]

if (enable_basic_printing) {
deps += [
"//components/printing/browser",
"//components/printing/renderer",
]
}
}

if (enable_basic_printing) {
deps += [
"//components/printing/browser",
"//components/printing/renderer",
]
if (!is_mac) {
deps += [ "//ui/aura" ]
}

if (headless_use_embedded_resources) {
Expand All @@ -366,10 +368,34 @@ static_library("headless_lib") {
if (use_ozone) {
deps += [ "//ui/ozone" ]
}

configs += [ ":headless_implementation" ]
}

# Headless renderer is a convenience source set that includes headless classes
# that depend on the reenderer. These are not added in case of a component build
# since in that case they are already included in the headless component.
source_set("headless_renderer") {
deps = [
":headless",
]
if (!is_component_build) {
sources = [
"lib/headless_content_main_delegate.cc",
"lib/headless_content_main_delegate.h",
"lib/renderer/headless_content_renderer_client.cc",
"lib/renderer/headless_content_renderer_client.h",
]
deps += [ "//ui/base" ]
if (enable_basic_printing) {
deps += [
"//components/printing/browser",
"//components/printing/renderer",
]
}
configs += [ ":headless_implementation" ]
}
}

group("headless_tests") {
testonly = true

Expand All @@ -392,7 +418,7 @@ test("headless_unittests") {
]

deps = [
":headless_lib",
":headless",
"//base/test:run_all_unittests",
"//base/test:test_support",
"//testing/gmock",
Expand Down Expand Up @@ -466,50 +492,115 @@ test("headless_browsertests") {
deps = [
":embedder_mojo_for_testing",
":headless_browser_tests_pak",
":headless_renderer",
"//base",
"//content/test:test_support",
"//headless:headless_lib",
"//testing/gmock",
"//testing/gtest",
]
}

static_library("headless_shell_lib") {
# Headless library with only browser dependencies. This is used when no child
# dependencies are needed in the target (e.g. chrome:main_dll).
static_library("headless_shell_browser_lib") {
if (is_multi_dll_chrome) {
defines = [ "CHROME_MULTIPLE_DLL_BROWSER" ]
}

sources = [
"app/headless_shell.cc",
"app/headless_shell.h",
"app/headless_shell_switches.cc",
"app/headless_shell_switches.h",
"app/shell_navigation_request.cc",
"app/shell_navigation_request.h",
"lib/headless_content_main_delegate.cc",
"lib/headless_content_main_delegate.h",
"public/headless_shell.h",
]

deps = [
"//headless:headless_lib",
":headless",
"//content/public/browser",
"//content/public/common",
]

if (is_win) {
deps += [
"//content:sandbox_helper_win",
"//sandbox",
]
}

configs += [ ":headless_implementation" ]
}

executable("headless_shell") {
# Headless library with child specific dependencies (e.g., renderer). This
# is used when no browser depencendies are needed (e.g. chrome:child_dll).
static_library("headless_shell_child_lib") {
if (is_multi_dll_chrome) {
defines = [ "CHROME_MULTIPLE_DLL_CHILD" ]
}

sources = [
"app/headless_shell_main.cc",
"app/headless_shell.cc",
"app/headless_shell.h",
"app/headless_shell_switches.cc",
"app/headless_shell_switches.h",
"app/shell_navigation_request.cc",
"app/shell_navigation_request.h",
"lib/headless_content_main_delegate.cc",
"lib/headless_content_main_delegate.h",
"public/headless_shell.h",
]

deps = [
"//headless:headless_shell_lib",
":headless_renderer",
"//content/public/child:child",
"//net",
"//ui/base",
]

configs += [ ":headless_implementation" ]
}

# Headless library with all included dependencies. Use this library unless you
# have browser/child dependencies restrictions.
static_library("headless_shell_lib") {
sources = [
"app/headless_shell.cc",
"app/headless_shell.h",
"app/headless_shell_switches.cc",
"app/headless_shell_switches.h",
"app/shell_navigation_request.cc",
"app/shell_navigation_request.h",
"public/headless_shell.h",
]

deps = [
":headless_renderer",
"//content/public/app:both",
"//content/public/browser",
"//content/public/child:child",
"//content/public/common",
]

if (is_win) {
deps += [
"//build/win:default_exe_manifest",
"//content:sandbox_helper_win",
"//sandbox",
]
}
}

configs += [ ":headless_implementation" ]
executable("headless_shell") {
sources = [
"app/headless_shell_main.cc",
]

deps = [
":headless_shell_lib",
]
}

process_version("version_header") {
Expand All @@ -527,6 +618,6 @@ executable("headless_example") {
]

deps = [
"//headless:headless_shell_lib",
":headless_shell_lib",
]
}
2 changes: 2 additions & 0 deletions headless/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_rules = [
"+components/crash/content/browser",
"+content/public/app",
"+content/public/browser",
"+content/public/renderer",
"+content/public/common",
"+content/public/test",
"+mojo/public",
Expand All @@ -16,5 +17,6 @@ include_rules = [
"+ui/gfx/geometry",
"+ui/gl",
"+ui/ozone/public",
"+sandbox/win/src",
"+services/service_manager/public",
]
15 changes: 15 additions & 0 deletions headless/app/headless_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "headless/public/devtools/domains/page.h"
#include "headless/public/devtools/domains/runtime.h"
#include "headless/public/headless_browser.h"
Expand All @@ -19,6 +20,11 @@
#include "headless/public/headless_web_contents.h"
#include "ui/gfx/geometry/size.h"

#if defined(OS_WIN)
#include "content/public/app/sandbox_helper_win.h"
#include "sandbox/win/src/sandbox_types.h"
#endif

// This class contains the main application logic, i.e., waiting for a page to
// load and printing its DOM. Note that browser initialization happens outside
// this class.
Expand Down Expand Up @@ -158,15 +164,24 @@ void OnHeadlessBrowserStarted(headless::HeadlessBrowser* browser) {
}

int main(int argc, const char** argv) {
#if !defined(OS_WIN)
// This function must be the first thing we call to make sure child processes
// such as the renderer are started properly. The headless library starts
// child processes by forking and exec'ing the main application.
headless::RunChildProcessIfNeeded(argc, argv);
#endif

// Create a headless browser instance. There can be one of these per process
// and it can only be initialized once.
headless::HeadlessBrowser::Options::Builder builder(argc, argv);

#if defined(OS_WIN)
// In windows, you must initialize and set the sandbox, or pass it along
// if it has already been initialized.
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
builder.SetSandboxInfo(&sandbox_info);
#endif
// Here you can customize browser options. As an example we set the window
// size.
builder.SetWindowSize(gfx::Size(800, 600));
Expand Down
Loading

0 comments on commit d238dae

Please sign in to comment.