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/browser/headless_browser_impl.h" | 5 #include "headless/lib/browser/headless_browser_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "content/public/app/content_main.h" | 14 #include "content/public/app/content_main.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "headless/app/headless_shell_switches.h" |
18 #include "headless/lib/browser/headless_browser_context_impl.h" | 19 #include "headless/lib/browser/headless_browser_context_impl.h" |
19 #include "headless/lib/browser/headless_browser_main_parts.h" | 20 #include "headless/lib/browser/headless_browser_main_parts.h" |
20 #include "headless/lib/browser/headless_web_contents_impl.h" | 21 #include "headless/lib/browser/headless_web_contents_impl.h" |
21 #include "headless/lib/headless_content_main_delegate.h" | 22 #include "headless/lib/headless_content_main_delegate.h" |
| 23 #include "net/http/http_util.h" |
22 #include "ui/aura/client/focus_client.h" | 24 #include "ui/aura/client/focus_client.h" |
23 #include "ui/aura/env.h" | 25 #include "ui/aura/env.h" |
24 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
25 #include "ui/events/devices/device_data_manager.h" | 27 #include "ui/events/devices/device_data_manager.h" |
26 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
27 | 29 |
28 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
29 #include "content/public/app/sandbox_helper_win.h" | 31 #include "content/public/app/sandbox_helper_win.h" |
30 #include "sandbox/win/src/sandbox_types.h" | 32 #include "sandbox/win/src/sandbox_types.h" |
31 #endif | 33 #endif |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( | 195 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( |
194 const std::string& id) { | 196 const std::string& id) { |
195 auto find_it = browser_contexts_.find(id); | 197 auto find_it = browser_contexts_.find(id); |
196 if (find_it == browser_contexts_.end()) | 198 if (find_it == browser_contexts_.end()) |
197 return nullptr; | 199 return nullptr; |
198 return find_it->second.get(); | 200 return find_it->second.get(); |
199 } | 201 } |
200 | 202 |
201 void RunChildProcessIfNeeded(int argc, const char** argv) { | 203 void RunChildProcessIfNeeded(int argc, const char** argv) { |
202 base::CommandLine::Init(argc, argv); | 204 base::CommandLine::Init(argc, argv); |
203 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 205 const base::CommandLine& command_line( |
204 switches::kProcessType)) | 206 *base::CommandLine::ForCurrentProcess()); |
| 207 |
| 208 if (!command_line.HasSwitch(::switches::kProcessType)) |
205 return; | 209 return; |
206 | 210 |
207 HeadlessBrowser::Options::Builder builder(argc, argv); | 211 HeadlessBrowser::Options::Builder builder(argc, argv); |
| 212 if (command_line.HasSwitch(switches::kUserAgent)) { |
| 213 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); |
| 214 if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 215 builder.SetUserAgent(ua); |
| 216 } |
| 217 |
208 exit(RunContentMain(builder.Build(), | 218 exit(RunContentMain(builder.Build(), |
209 base::Callback<void(HeadlessBrowser*)>())); | 219 base::Callback<void(HeadlessBrowser*)>())); |
210 } | 220 } |
211 | 221 |
212 int HeadlessBrowserMain( | 222 int HeadlessBrowserMain( |
213 HeadlessBrowser::Options options, | 223 HeadlessBrowser::Options options, |
214 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 224 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
215 DCHECK(!on_browser_start_callback.is_null()); | 225 DCHECK(!on_browser_start_callback.is_null()); |
216 #if DCHECK_IS_ON() | 226 #if DCHECK_IS_ON() |
217 // The browser can only be initialized once. | 227 // The browser can only be initialized once. |
218 static bool browser_was_initialized; | 228 static bool browser_was_initialized; |
219 DCHECK(!browser_was_initialized); | 229 DCHECK(!browser_was_initialized); |
220 browser_was_initialized = true; | 230 browser_was_initialized = true; |
221 | 231 |
222 // Child processes should not end up here. | 232 // Child processes should not end up here. |
223 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 233 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
224 switches::kProcessType)); | 234 ::switches::kProcessType)); |
225 #endif | 235 #endif |
226 return RunContentMain(std::move(options), | 236 return RunContentMain(std::move(options), |
227 std::move(on_browser_start_callback)); | 237 std::move(on_browser_start_callback)); |
228 } | 238 } |
229 | 239 |
230 } // namespace headless | 240 } // namespace headless |
OLD | NEW |