Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: headless/lib/browser/headless_browser_impl.cc

Issue 2832963002: Reland of Add --headless flag to Windows (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « headless/lib/browser/DEPS ('k') | headless/lib/headless_browser_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/app/headless_shell_switches.h"
19 #include "headless/lib/browser/headless_browser_context_impl.h" 19 #include "headless/lib/browser/headless_browser_context_impl.h"
20 #include "headless/lib/browser/headless_browser_main_parts.h" 20 #include "headless/lib/browser/headless_browser_main_parts.h"
21 #include "headless/lib/browser/headless_web_contents_impl.h" 21 #include "headless/lib/browser/headless_web_contents_impl.h"
22 #include "headless/lib/headless_content_main_delegate.h" 22 #include "headless/lib/headless_content_main_delegate.h"
23 #include "net/http/http_util.h" 23 #include "net/http/http_util.h"
24 #include "ui/aura/client/focus_client.h" 24 #include "ui/aura/client/focus_client.h"
25 #include "ui/aura/env.h" 25 #include "ui/aura/env.h"
26 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
27 #include "ui/events/devices/device_data_manager.h" 27 #include "ui/events/devices/device_data_manager.h"
28 #include "ui/gfx/geometry/size.h" 28 #include "ui/gfx/geometry/size.h"
29 29
30 #if defined(OS_WIN)
31 #include "content/public/app/sandbox_helper_win.h"
32 #include "sandbox/win/src/sandbox_types.h"
33 #endif
34
35 namespace headless { 30 namespace headless {
36 namespace { 31 namespace {
37 32
38 int RunContentMain( 33 int RunContentMain(
39 HeadlessBrowser::Options options, 34 HeadlessBrowser::Options options,
40 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { 35 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) {
41 content::ContentMainParams params(nullptr); 36 content::ContentMainParams params(nullptr);
42 #if defined(OS_WIN) 37 #if defined(OS_WIN)
43 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 38 // Sandbox info has to be set and initialized.
44 content::InitializeSandboxInfo(&sandbox_info); 39 CHECK(options.sandbox_info);
45 params.sandbox_info = &sandbox_info; 40 params.instance = options.instance;
41 params.sandbox_info = std::move(options.sandbox_info);
46 #elif !defined(OS_ANDROID) 42 #elif !defined(OS_ANDROID)
47 params.argc = options.argc; 43 params.argc = options.argc;
48 params.argv = options.argv; 44 params.argv = options.argv;
49 #endif 45 #endif
50 46
51 // TODO(skyostil): Implement custom message pumps. 47 // TODO(skyostil): Implement custom message pumps.
52 DCHECK(!options.message_pump); 48 DCHECK(!options.message_pump);
53 49
54 std::unique_ptr<HeadlessBrowserImpl> browser( 50 std::unique_ptr<HeadlessBrowserImpl> browser(
55 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); 51 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options)));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 189 }
194 190
195 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( 191 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId(
196 const std::string& id) { 192 const std::string& id) {
197 auto find_it = browser_contexts_.find(id); 193 auto find_it = browser_contexts_.find(id);
198 if (find_it == browser_contexts_.end()) 194 if (find_it == browser_contexts_.end())
199 return nullptr; 195 return nullptr;
200 return find_it->second.get(); 196 return find_it->second.get();
201 } 197 }
202 198
199 #if !defined(OS_WIN)
203 void RunChildProcessIfNeeded(int argc, const char** argv) { 200 void RunChildProcessIfNeeded(int argc, const char** argv) {
204 base::CommandLine::Init(argc, argv); 201 base::CommandLine::Init(argc, argv);
205 const base::CommandLine& command_line( 202 const base::CommandLine& command_line(
206 *base::CommandLine::ForCurrentProcess()); 203 *base::CommandLine::ForCurrentProcess());
207 204
208 if (!command_line.HasSwitch(::switches::kProcessType)) 205 if (!command_line.HasSwitch(::switches::kProcessType))
209 return; 206 return;
210 207
211 HeadlessBrowser::Options::Builder builder(argc, argv); 208 HeadlessBrowser::Options::Builder builder(argc, argv);
212 if (command_line.HasSwitch(switches::kUserAgent)) { 209 if (command_line.HasSwitch(switches::kUserAgent)) {
213 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); 210 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent);
214 if (net::HttpUtil::IsValidHeaderValue(ua)) 211 if (net::HttpUtil::IsValidHeaderValue(ua))
215 builder.SetUserAgent(ua); 212 builder.SetUserAgent(ua);
216 } 213 }
217 214
218 exit(RunContentMain(builder.Build(), 215 exit(RunContentMain(builder.Build(),
219 base::Callback<void(HeadlessBrowser*)>())); 216 base::Callback<void(HeadlessBrowser*)>()));
220 } 217 }
218 #endif // !defined(OS_WIN)
221 219
222 int HeadlessBrowserMain( 220 int HeadlessBrowserMain(
223 HeadlessBrowser::Options options, 221 HeadlessBrowser::Options options,
224 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { 222 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) {
225 DCHECK(!on_browser_start_callback.is_null()); 223 DCHECK(!on_browser_start_callback.is_null());
226 #if DCHECK_IS_ON() 224 #if DCHECK_IS_ON()
227 // The browser can only be initialized once. 225 // The browser can only be initialized once.
228 static bool browser_was_initialized; 226 static bool browser_was_initialized;
229 DCHECK(!browser_was_initialized); 227 DCHECK(!browser_was_initialized);
230 browser_was_initialized = true; 228 browser_was_initialized = true;
231 229
232 // Child processes should not end up here. 230 // Child processes should not end up here.
233 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( 231 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
234 ::switches::kProcessType)); 232 ::switches::kProcessType));
235 #endif 233 #endif
236 return RunContentMain(std::move(options), 234 return RunContentMain(std::move(options),
237 std::move(on_browser_start_callback)); 235 std::move(on_browser_start_callback));
238 } 236 }
239 237
240 } // namespace headless 238 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/DEPS ('k') | headless/lib/headless_browser_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698