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

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

Issue 2837093003: Revert of Add --headless flag to Windows (Closed)
Patch Set: Fix compilation issue 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
30 namespace headless { 35 namespace headless {
31 namespace { 36 namespace {
32 37
33 int RunContentMain( 38 int RunContentMain(
34 HeadlessBrowser::Options options, 39 HeadlessBrowser::Options options,
35 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { 40 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) {
36 content::ContentMainParams params(nullptr); 41 content::ContentMainParams params(nullptr);
37 #if defined(OS_WIN) 42 #if defined(OS_WIN)
38 // Sandbox info has to be set and initialized. 43 sandbox::SandboxInterfaceInfo sandbox_info = {0};
39 CHECK(options.sandbox_info); 44 content::InitializeSandboxInfo(&sandbox_info);
40 params.instance = options.instance; 45 params.sandbox_info = &sandbox_info;
41 params.sandbox_info = std::move(options.sandbox_info);
42 #elif !defined(OS_ANDROID) 46 #elif !defined(OS_ANDROID)
43 params.argc = options.argc; 47 params.argc = options.argc;
44 params.argv = options.argv; 48 params.argv = options.argv;
45 #endif 49 #endif
46 50
47 // TODO(skyostil): Implement custom message pumps. 51 // TODO(skyostil): Implement custom message pumps.
48 DCHECK(!options.message_pump); 52 DCHECK(!options.message_pump);
49 53
50 std::unique_ptr<HeadlessBrowserImpl> browser( 54 std::unique_ptr<HeadlessBrowserImpl> browser(
51 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); 55 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options)));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 193 }
190 194
191 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( 195 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId(
192 const std::string& id) { 196 const std::string& id) {
193 auto find_it = browser_contexts_.find(id); 197 auto find_it = browser_contexts_.find(id);
194 if (find_it == browser_contexts_.end()) 198 if (find_it == browser_contexts_.end())
195 return nullptr; 199 return nullptr;
196 return find_it->second.get(); 200 return find_it->second.get();
197 } 201 }
198 202
199 #if !defined(OS_WIN)
200 void RunChildProcessIfNeeded(int argc, const char** argv) { 203 void RunChildProcessIfNeeded(int argc, const char** argv) {
201 base::CommandLine::Init(argc, argv); 204 base::CommandLine::Init(argc, argv);
202 const base::CommandLine& command_line( 205 const base::CommandLine& command_line(
203 *base::CommandLine::ForCurrentProcess()); 206 *base::CommandLine::ForCurrentProcess());
204 207
205 if (!command_line.HasSwitch(::switches::kProcessType)) 208 if (!command_line.HasSwitch(::switches::kProcessType))
206 return; 209 return;
207 210
208 HeadlessBrowser::Options::Builder builder(argc, argv); 211 HeadlessBrowser::Options::Builder builder(argc, argv);
209 if (command_line.HasSwitch(switches::kUserAgent)) { 212 if (command_line.HasSwitch(switches::kUserAgent)) {
210 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); 213 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent);
211 if (net::HttpUtil::IsValidHeaderValue(ua)) 214 if (net::HttpUtil::IsValidHeaderValue(ua))
212 builder.SetUserAgent(ua); 215 builder.SetUserAgent(ua);
213 } 216 }
214 217
215 exit(RunContentMain(builder.Build(), 218 exit(RunContentMain(builder.Build(),
216 base::Callback<void(HeadlessBrowser*)>())); 219 base::Callback<void(HeadlessBrowser*)>()));
217 } 220 }
218 #endif // !defined(OS_WIN)
219 221
220 int HeadlessBrowserMain( 222 int HeadlessBrowserMain(
221 HeadlessBrowser::Options options, 223 HeadlessBrowser::Options options,
222 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { 224 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) {
223 DCHECK(!on_browser_start_callback.is_null()); 225 DCHECK(!on_browser_start_callback.is_null());
224 #if DCHECK_IS_ON() 226 #if DCHECK_IS_ON()
225 // The browser can only be initialized once. 227 // The browser can only be initialized once.
226 static bool browser_was_initialized; 228 static bool browser_was_initialized;
227 DCHECK(!browser_was_initialized); 229 DCHECK(!browser_was_initialized);
228 browser_was_initialized = true; 230 browser_was_initialized = true;
229 231
230 // Child processes should not end up here. 232 // Child processes should not end up here.
231 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( 233 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
232 ::switches::kProcessType)); 234 ::switches::kProcessType));
233 #endif 235 #endif
234 return RunContentMain(std::move(options), 236 return RunContentMain(std::move(options),
235 std::move(on_browser_start_callback)); 237 std::move(on_browser_start_callback));
236 } 238 }
237 239
238 } // namespace headless 240 } // 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