OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "headless/lib/headless_content_main_delegate.h" | 5 #include "headless/lib/headless_content_main_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "content/public/browser/browser_main_runner.h" | 11 #include "content/public/browser/browser_main_runner.h" |
12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
13 #include "headless/lib/browser/headless_browser_impl.h" | 13 #include "headless/lib/browser/headless_browser_impl.h" |
14 #include "headless/lib/browser/headless_content_browser_client.h" | 14 #include "headless/lib/browser/headless_content_browser_client.h" |
| 15 #include "headless/lib/renderer/headless_content_renderer_client.h" |
| 16 #include "headless/lib/utility/headless_content_utility_client.h" |
15 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/switches.h" | |
17 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
18 #include "ui/ozone/public/ozone_switches.h" | 19 #include "ui/ozone/public/ozone_switches.h" |
19 | 20 |
20 namespace headless { | 21 namespace headless { |
21 namespace { | 22 namespace { |
22 // Keep in sync with content/common/content_constants_internal.h. | 23 // Keep in sync with content/common/content_constants_internal.h. |
23 // TODO(skyostil): Add a tracing test for this. | 24 // TODO(skyostil): Add a tracing test for this. |
24 const int kTraceEventBrowserProcessSortIndex = -6; | 25 const int kTraceEventBrowserProcessSortIndex = -6; |
25 | 26 |
26 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; | 27 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 HeadlessContentMainDelegate::HeadlessContentMainDelegate( | 30 HeadlessContentMainDelegate::HeadlessContentMainDelegate( |
30 std::unique_ptr<HeadlessBrowserImpl> browser) | 31 std::unique_ptr<HeadlessBrowserImpl> browser) |
31 : content_client_(browser->options()), browser_(std::move(browser)) { | 32 : content_client_(browser->options()), browser_(std::move(browser)) { |
32 DCHECK(!g_current_headless_content_main_delegate); | 33 DCHECK(!g_current_headless_content_main_delegate); |
33 g_current_headless_content_main_delegate = this; | 34 g_current_headless_content_main_delegate = this; |
34 } | 35 } |
35 | 36 |
36 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { | 37 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { |
37 DCHECK(g_current_headless_content_main_delegate == this); | 38 DCHECK(g_current_headless_content_main_delegate == this); |
38 g_current_headless_content_main_delegate = nullptr; | 39 g_current_headless_content_main_delegate = nullptr; |
39 } | 40 } |
40 | 41 |
41 bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { | 42 bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { |
42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
43 | 44 |
44 // Make sure all processes know that we're in headless mode. | |
45 if (!command_line->HasSwitch(switches::kHeadless)) | |
46 command_line->AppendSwitch(switches::kHeadless); | |
47 | |
48 if (browser_->options()->single_process_mode) | 45 if (browser_->options()->single_process_mode) |
49 command_line->AppendSwitch(switches::kSingleProcess); | 46 command_line->AppendSwitch(switches::kSingleProcess); |
50 | 47 |
51 if (browser_->options()->disable_sandbox) | 48 if (browser_->options()->disable_sandbox) |
52 command_line->AppendSwitch(switches::kNoSandbox); | 49 command_line->AppendSwitch(switches::kNoSandbox); |
53 | 50 |
54 #if defined(USE_OZONE) | |
55 // The headless backend is automatically chosen for a headless build, but also | 51 // The headless backend is automatically chosen for a headless build, but also |
56 // adding it here allows us to run in a non-headless build too. | 52 // adding it here allows us to run in a non-headless build too. |
57 command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless"); | 53 command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless"); |
58 #endif | |
59 | 54 |
60 if (!browser_->options()->gl_implementation.empty()) { | 55 if (!browser_->options()->gl_implementation.empty()) { |
61 command_line->AppendSwitchASCII(switches::kUseGL, | 56 command_line->AppendSwitchASCII(switches::kUseGL, |
62 browser_->options()->gl_implementation); | 57 browser_->options()->gl_implementation); |
63 } else { | 58 } else { |
64 command_line->AppendSwitch(switches::kDisableGpu); | 59 command_line->AppendSwitch(switches::kDisableGpu); |
65 } | 60 } |
66 | 61 |
67 SetContentClient(&content_client_); | 62 SetContentClient(&content_client_); |
68 return false; | 63 return false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 pak_file = pak_file.Append(FILE_PATH_LITERAL("headless_lib.pak")); | 110 pak_file = pak_file.Append(FILE_PATH_LITERAL("headless_lib.pak")); |
116 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 111 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
117 } | 112 } |
118 | 113 |
119 content::ContentBrowserClient* | 114 content::ContentBrowserClient* |
120 HeadlessContentMainDelegate::CreateContentBrowserClient() { | 115 HeadlessContentMainDelegate::CreateContentBrowserClient() { |
121 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); | 116 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); |
122 return browser_client_.get(); | 117 return browser_client_.get(); |
123 } | 118 } |
124 | 119 |
| 120 content::ContentRendererClient* |
| 121 HeadlessContentMainDelegate::CreateContentRendererClient() { |
| 122 renderer_client_.reset(new HeadlessContentRendererClient); |
| 123 return renderer_client_.get(); |
| 124 } |
| 125 |
| 126 content::ContentUtilityClient* |
| 127 HeadlessContentMainDelegate::CreateContentUtilityClient() { |
| 128 utility_client_.reset(new HeadlessContentUtilityClient); |
| 129 return utility_client_.get(); |
| 130 } |
| 131 |
125 } // namespace headless | 132 } // namespace headless |
OLD | NEW |