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" | |
17 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/switches.h" |
18 #include "ui/gl/gl_switches.h" | 17 #include "ui/gl/gl_switches.h" |
19 #include "ui/ozone/public/ozone_switches.h" | 18 #include "ui/ozone/public/ozone_switches.h" |
20 | 19 |
21 namespace headless { | 20 namespace headless { |
22 namespace { | 21 namespace { |
23 // Keep in sync with content/common/content_constants_internal.h. | 22 // Keep in sync with content/common/content_constants_internal.h. |
24 // TODO(skyostil): Add a tracing test for this. | 23 // TODO(skyostil): Add a tracing test for this. |
25 const int kTraceEventBrowserProcessSortIndex = -6; | 24 const int kTraceEventBrowserProcessSortIndex = -6; |
26 | 25 |
27 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; | 26 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; |
28 } // namespace | 27 } // namespace |
29 | 28 |
30 HeadlessContentMainDelegate::HeadlessContentMainDelegate( | 29 HeadlessContentMainDelegate::HeadlessContentMainDelegate( |
31 std::unique_ptr<HeadlessBrowserImpl> browser) | 30 std::unique_ptr<HeadlessBrowserImpl> browser) |
32 : content_client_(browser->options()), browser_(std::move(browser)) { | 31 : content_client_(browser->options()), browser_(std::move(browser)) { |
33 DCHECK(!g_current_headless_content_main_delegate); | 32 DCHECK(!g_current_headless_content_main_delegate); |
34 g_current_headless_content_main_delegate = this; | 33 g_current_headless_content_main_delegate = this; |
35 } | 34 } |
36 | 35 |
37 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { | 36 HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { |
38 DCHECK(g_current_headless_content_main_delegate == this); | 37 DCHECK(g_current_headless_content_main_delegate == this); |
39 g_current_headless_content_main_delegate = nullptr; | 38 g_current_headless_content_main_delegate = nullptr; |
40 } | 39 } |
41 | 40 |
42 bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { | 41 bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) { |
43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
44 | 43 |
| 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 |
45 if (browser_->options()->single_process_mode) | 48 if (browser_->options()->single_process_mode) |
46 command_line->AppendSwitch(switches::kSingleProcess); | 49 command_line->AppendSwitch(switches::kSingleProcess); |
47 | 50 |
48 if (browser_->options()->disable_sandbox) | 51 if (browser_->options()->disable_sandbox) |
49 command_line->AppendSwitch(switches::kNoSandbox); | 52 command_line->AppendSwitch(switches::kNoSandbox); |
50 | 53 |
| 54 #if defined(USE_OZONE) |
51 // The headless backend is automatically chosen for a headless build, but also | 55 // The headless backend is automatically chosen for a headless build, but also |
52 // adding it here allows us to run in a non-headless build too. | 56 // adding it here allows us to run in a non-headless build too. |
53 command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless"); | 57 command_line->AppendSwitchASCII(switches::kOzonePlatform, "headless"); |
| 58 #endif |
54 | 59 |
55 if (!browser_->options()->gl_implementation.empty()) { | 60 if (!browser_->options()->gl_implementation.empty()) { |
56 command_line->AppendSwitchASCII(switches::kUseGL, | 61 command_line->AppendSwitchASCII(switches::kUseGL, |
57 browser_->options()->gl_implementation); | 62 browser_->options()->gl_implementation); |
58 } else { | 63 } else { |
59 command_line->AppendSwitch(switches::kDisableGpu); | 64 command_line->AppendSwitch(switches::kDisableGpu); |
60 } | 65 } |
61 | 66 |
62 SetContentClient(&content_client_); | 67 SetContentClient(&content_client_); |
63 return false; | 68 return false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 pak_file = pak_file.Append(FILE_PATH_LITERAL("headless_lib.pak")); | 115 pak_file = pak_file.Append(FILE_PATH_LITERAL("headless_lib.pak")); |
111 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 116 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
112 } | 117 } |
113 | 118 |
114 content::ContentBrowserClient* | 119 content::ContentBrowserClient* |
115 HeadlessContentMainDelegate::CreateContentBrowserClient() { | 120 HeadlessContentMainDelegate::CreateContentBrowserClient() { |
116 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); | 121 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); |
117 return browser_client_.get(); | 122 return browser_client_.get(); |
118 } | 123 } |
119 | 124 |
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 | |
132 } // namespace headless | 125 } // namespace headless |
OLD | NEW |