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/lib/browser/headless_browser_context_impl.h" | 18 #include "headless/lib/browser/headless_browser_context_impl.h" |
19 #include "headless/lib/browser/headless_browser_main_parts.h" | 19 #include "headless/lib/browser/headless_browser_main_parts.h" |
20 #include "headless/lib/browser/headless_web_contents_impl.h" | 20 #include "headless/lib/browser/headless_web_contents_impl.h" |
21 #include "headless/lib/headless_content_main_delegate.h" | 21 #include "headless/lib/headless_content_main_delegate.h" |
22 #include "ui/aura/client/focus_client.h" | 22 #include "ui/aura/client/focus_client.h" |
23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
25 #include "ui/events/devices/device_data_manager.h" | 25 #include "ui/events/devices/device_data_manager.h" |
26 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
27 | 27 |
28 #if defined(OS_WIN) | |
29 #include "content/public/app/sandbox_helper_win.h" | |
30 #include "sandbox/win/src/sandbox_types.h" | |
31 #endif | |
32 | |
33 namespace headless { | 28 namespace headless { |
34 namespace { | 29 namespace { |
35 | 30 |
36 int RunContentMain( | 31 int RunContentMain( |
37 HeadlessBrowser::Options options, | 32 HeadlessBrowser::Options options, |
38 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 33 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
39 content::ContentMainParams params(nullptr); | 34 content::ContentMainParams params(nullptr); |
40 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
41 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 36 // Sandbox info has to be set and initialized. |
42 content::InitializeSandboxInfo(&sandbox_info); | 37 CHECK(options.sandbox_info); |
43 params.sandbox_info = &sandbox_info; | 38 params.instance = options.instance; |
39 params.sandbox_info = std::move(options.sandbox_info); | |
44 #elif !defined(OS_ANDROID) | 40 #elif !defined(OS_ANDROID) |
45 params.argc = options.argc; | 41 params.argc = options.argc; |
46 params.argv = options.argv; | 42 params.argv = options.argv; |
47 #endif | 43 #endif |
48 | 44 |
49 // TODO(skyostil): Implement custom message pumps. | 45 // TODO(skyostil): Implement custom message pumps. |
50 DCHECK(!options.message_pump); | 46 DCHECK(!options.message_pump); |
51 | 47 |
52 std::unique_ptr<HeadlessBrowserImpl> browser( | 48 std::unique_ptr<HeadlessBrowserImpl> browser( |
53 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); | 49 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 } | 187 } |
192 | 188 |
193 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( | 189 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( |
194 const std::string& id) { | 190 const std::string& id) { |
195 auto find_it = browser_contexts_.find(id); | 191 auto find_it = browser_contexts_.find(id); |
196 if (find_it == browser_contexts_.end()) | 192 if (find_it == browser_contexts_.end()) |
197 return nullptr; | 193 return nullptr; |
198 return find_it->second.get(); | 194 return find_it->second.get(); |
199 } | 195 } |
200 | 196 |
197 #if !defined(OS_WIN) | |
201 void RunChildProcessIfNeeded(int argc, const char** argv) { | 198 void RunChildProcessIfNeeded(int argc, const char** argv) { |
202 base::CommandLine::Init(argc, argv); | 199 base::CommandLine::Init(argc, argv); |
203 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 200 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
204 switches::kProcessType)) | 201 switches::kProcessType)) |
205 return; | 202 return; |
206 | 203 |
207 HeadlessBrowser::Options::Builder builder(argc, argv); | 204 HeadlessBrowser::Options::Builder builder(argc, argv); |
208 exit(RunContentMain(builder.Build(), | 205 exit(RunContentMain(builder.Build(), |
209 base::Callback<void(HeadlessBrowser*)>())); | 206 base::Callback<void(HeadlessBrowser*)>())); |
210 } | 207 } |
208 #endif | |
Sami
2017/03/28 11:49:33
nit: // !defined(OS_WIN)
dvallet
2017/03/29 06:27:56
Done.
dvallet
2017/03/29 06:27:56
Done.
| |
211 | 209 |
212 int HeadlessBrowserMain( | 210 int HeadlessBrowserMain( |
213 HeadlessBrowser::Options options, | 211 HeadlessBrowser::Options options, |
214 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 212 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
215 DCHECK(!on_browser_start_callback.is_null()); | 213 DCHECK(!on_browser_start_callback.is_null()); |
216 #if DCHECK_IS_ON() | 214 #if DCHECK_IS_ON() |
217 // The browser can only be initialized once. | 215 // The browser can only be initialized once. |
218 static bool browser_was_initialized; | 216 static bool browser_was_initialized; |
219 DCHECK(!browser_was_initialized); | 217 DCHECK(!browser_was_initialized); |
220 browser_was_initialized = true; | 218 browser_was_initialized = true; |
221 | 219 |
222 // Child processes should not end up here. | 220 // Child processes should not end up here. |
223 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 221 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
224 switches::kProcessType)); | 222 switches::kProcessType)); |
225 #endif | 223 #endif |
226 return RunContentMain(std::move(options), | 224 return RunContentMain(std::move(options), |
227 std::move(on_browser_start_callback)); | 225 std::move(on_browser_start_callback)); |
228 } | 226 } |
229 | 227 |
230 } // namespace headless | 228 } // namespace headless |
OLD | NEW |