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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "headless/lib/browser/headless_devtools_client_impl.h" | 22 #include "headless/lib/browser/headless_devtools_client_impl.h" |
23 #include "headless/lib/browser/headless_web_contents_impl.h" | 23 #include "headless/lib/browser/headless_web_contents_impl.h" |
24 #include "headless/lib/headless_content_main_delegate.h" | 24 #include "headless/lib/headless_content_main_delegate.h" |
25 #include "net/http/http_util.h" | 25 #include "net/http/http_util.h" |
26 #include "ui/aura/client/focus_client.h" | 26 #include "ui/aura/client/focus_client.h" |
27 #include "ui/aura/env.h" | 27 #include "ui/aura/env.h" |
28 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
29 #include "ui/events/devices/device_data_manager.h" | 29 #include "ui/events/devices/device_data_manager.h" |
30 #include "ui/gfx/geometry/size.h" | 30 #include "ui/gfx/geometry/size.h" |
31 | 31 |
32 #if defined(OS_WIN) | |
33 #include "content/public/app/sandbox_helper_win.h" | |
34 #include "sandbox/win/src/sandbox_types.h" | |
35 #endif | |
36 | |
37 namespace content { | 32 namespace content { |
38 class DevToolsAgentHost; | 33 class DevToolsAgentHost; |
39 } | 34 } |
40 | 35 |
41 namespace headless { | 36 namespace headless { |
42 namespace { | 37 namespace { |
43 | 38 |
44 int RunContentMain( | 39 int RunContentMain( |
45 HeadlessBrowser::Options options, | 40 HeadlessBrowser::Options options, |
46 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 41 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
47 content::ContentMainParams params(nullptr); | 42 content::ContentMainParams params(nullptr); |
48 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
49 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 44 // Sandbox info has to be set and initialized. |
50 content::InitializeSandboxInfo(&sandbox_info); | 45 CHECK(options.sandbox_info); |
51 params.sandbox_info = &sandbox_info; | 46 params.instance = options.instance; |
| 47 params.sandbox_info = std::move(options.sandbox_info); |
52 #elif !defined(OS_ANDROID) | 48 #elif !defined(OS_ANDROID) |
53 params.argc = options.argc; | 49 params.argc = options.argc; |
54 params.argv = options.argv; | 50 params.argv = options.argv; |
55 #endif | 51 #endif |
56 | 52 |
57 // TODO(skyostil): Implement custom message pumps. | 53 // TODO(skyostil): Implement custom message pumps. |
58 DCHECK(!options.message_pump); | 54 DCHECK(!options.message_pump); |
59 | 55 |
60 std::unique_ptr<HeadlessBrowserImpl> browser( | 56 std::unique_ptr<HeadlessBrowserImpl> browser( |
61 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); | 57 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 void HeadlessBrowserImpl::DetachClient(HeadlessDevToolsClient* client) { | 226 void HeadlessBrowserImpl::DetachClient(HeadlessDevToolsClient* client) { |
231 DCHECK(agent_host_); | 227 DCHECK(agent_host_); |
232 HeadlessDevToolsClientImpl::From(client)->DetachFromHost(agent_host_.get()); | 228 HeadlessDevToolsClientImpl::From(client)->DetachFromHost(agent_host_.get()); |
233 } | 229 } |
234 | 230 |
235 bool HeadlessBrowserImpl::IsAttached() { | 231 bool HeadlessBrowserImpl::IsAttached() { |
236 DCHECK(agent_host_); | 232 DCHECK(agent_host_); |
237 return agent_host_->IsAttached(); | 233 return agent_host_->IsAttached(); |
238 } | 234 } |
239 | 235 |
| 236 #if defined(OS_WIN) |
| 237 void RunChildProcessIfNeeded(HINSTANCE instance, |
| 238 sandbox::SandboxInterfaceInfo* sandbox_info) { |
| 239 base::CommandLine::Init(0, nullptr); |
| 240 HeadlessBrowser::Options::Builder builder(0, nullptr); |
| 241 builder.SetInstance(instance); |
| 242 builder.SetSandboxInfo(std::move(sandbox_info)); |
| 243 #else |
240 void RunChildProcessIfNeeded(int argc, const char** argv) { | 244 void RunChildProcessIfNeeded(int argc, const char** argv) { |
241 base::CommandLine::Init(argc, argv); | 245 base::CommandLine::Init(argc, argv); |
| 246 HeadlessBrowser::Options::Builder builder(argc, argv); |
| 247 #endif // defined(OS_WIN) |
242 const base::CommandLine& command_line( | 248 const base::CommandLine& command_line( |
243 *base::CommandLine::ForCurrentProcess()); | 249 *base::CommandLine::ForCurrentProcess()); |
244 | 250 |
245 if (!command_line.HasSwitch(::switches::kProcessType)) | 251 if (!command_line.HasSwitch(::switches::kProcessType)) |
246 return; | 252 return; |
247 | 253 |
248 HeadlessBrowser::Options::Builder builder(argc, argv); | |
249 if (command_line.HasSwitch(switches::kUserAgent)) { | 254 if (command_line.HasSwitch(switches::kUserAgent)) { |
250 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); | 255 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); |
251 if (net::HttpUtil::IsValidHeaderValue(ua)) | 256 if (net::HttpUtil::IsValidHeaderValue(ua)) |
252 builder.SetUserAgent(ua); | 257 builder.SetUserAgent(ua); |
253 } | 258 } |
254 | 259 |
255 exit(RunContentMain(builder.Build(), | 260 exit(RunContentMain(builder.Build(), |
256 base::Callback<void(HeadlessBrowser*)>())); | 261 base::Callback<void(HeadlessBrowser*)>())); |
257 } | 262 } |
258 | 263 |
259 int HeadlessBrowserMain( | 264 int HeadlessBrowserMain( |
260 HeadlessBrowser::Options options, | 265 HeadlessBrowser::Options options, |
261 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 266 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
262 DCHECK(!on_browser_start_callback.is_null()); | 267 DCHECK(!on_browser_start_callback.is_null()); |
263 #if DCHECK_IS_ON() | 268 #if DCHECK_IS_ON() |
264 // The browser can only be initialized once. | 269 // The browser can only be initialized once. |
265 static bool browser_was_initialized; | 270 static bool browser_was_initialized; |
266 DCHECK(!browser_was_initialized); | 271 DCHECK(!browser_was_initialized); |
267 browser_was_initialized = true; | 272 browser_was_initialized = true; |
268 | 273 |
269 // Child processes should not end up here. | 274 // Child processes should not end up here. |
270 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 275 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
271 ::switches::kProcessType)); | 276 ::switches::kProcessType)); |
272 #endif | 277 #endif |
273 return RunContentMain(std::move(options), | 278 return RunContentMain(std::move(options), |
274 std::move(on_browser_start_callback)); | 279 std::move(on_browser_start_callback)); |
275 } | 280 } |
276 | 281 |
277 } // namespace headless | 282 } // namespace headless |
OLD | NEW |