| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 189 } |
| 190 | 190 |
| 191 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( | 191 HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId( |
| 192 const std::string& id) { | 192 const std::string& id) { |
| 193 auto find_it = browser_contexts_.find(id); | 193 auto find_it = browser_contexts_.find(id); |
| 194 if (find_it == browser_contexts_.end()) | 194 if (find_it == browser_contexts_.end()) |
| 195 return nullptr; | 195 return nullptr; |
| 196 return find_it->second.get(); | 196 return find_it->second.get(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 #if !defined(OS_WIN) | 199 #if defined(OS_WIN) |
| 200 void RunChildProcessIfNeeded(HINSTANCE instance, |
| 201 sandbox::SandboxInterfaceInfo* sandbox_info) { |
| 202 base::CommandLine::Init(0, nullptr); |
| 203 HeadlessBrowser::Options::Builder builder(0, nullptr); |
| 204 builder.SetInstance(instance); |
| 205 builder.SetSandboxInfo(std::move(sandbox_info)); |
| 206 #else |
| 200 void RunChildProcessIfNeeded(int argc, const char** argv) { | 207 void RunChildProcessIfNeeded(int argc, const char** argv) { |
| 201 base::CommandLine::Init(argc, argv); | 208 base::CommandLine::Init(argc, argv); |
| 209 HeadlessBrowser::Options::Builder builder(argc, argv); |
| 210 #endif // defined(OS_WIN) |
| 202 const base::CommandLine& command_line( | 211 const base::CommandLine& command_line( |
| 203 *base::CommandLine::ForCurrentProcess()); | 212 *base::CommandLine::ForCurrentProcess()); |
| 204 | 213 |
| 205 if (!command_line.HasSwitch(::switches::kProcessType)) | 214 if (!command_line.HasSwitch(::switches::kProcessType)) |
| 206 return; | 215 return; |
| 207 | 216 |
| 208 HeadlessBrowser::Options::Builder builder(argc, argv); | |
| 209 if (command_line.HasSwitch(switches::kUserAgent)) { | 217 if (command_line.HasSwitch(switches::kUserAgent)) { |
| 210 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); | 218 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); |
| 211 if (net::HttpUtil::IsValidHeaderValue(ua)) | 219 if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 212 builder.SetUserAgent(ua); | 220 builder.SetUserAgent(ua); |
| 213 } | 221 } |
| 214 | 222 |
| 215 exit(RunContentMain(builder.Build(), | 223 exit(RunContentMain(builder.Build(), |
| 216 base::Callback<void(HeadlessBrowser*)>())); | 224 base::Callback<void(HeadlessBrowser*)>())); |
| 217 } | 225 } |
| 218 #endif // !defined(OS_WIN) | |
| 219 | 226 |
| 220 int HeadlessBrowserMain( | 227 int HeadlessBrowserMain( |
| 221 HeadlessBrowser::Options options, | 228 HeadlessBrowser::Options options, |
| 222 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 229 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
| 223 DCHECK(!on_browser_start_callback.is_null()); | 230 DCHECK(!on_browser_start_callback.is_null()); |
| 224 #if DCHECK_IS_ON() | 231 #if DCHECK_IS_ON() |
| 225 // The browser can only be initialized once. | 232 // The browser can only be initialized once. |
| 226 static bool browser_was_initialized; | 233 static bool browser_was_initialized; |
| 227 DCHECK(!browser_was_initialized); | 234 DCHECK(!browser_was_initialized); |
| 228 browser_was_initialized = true; | 235 browser_was_initialized = true; |
| 229 | 236 |
| 230 // Child processes should not end up here. | 237 // Child processes should not end up here. |
| 231 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 238 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 232 ::switches::kProcessType)); | 239 ::switches::kProcessType)); |
| 233 #endif | 240 #endif |
| 234 return RunContentMain(std::move(options), | 241 return RunContentMain(std::move(options), |
| 235 std::move(on_browser_start_callback)); | 242 std::move(on_browser_start_callback)); |
| 236 } | 243 } |
| 237 | 244 |
| 238 } // namespace headless | 245 } // namespace headless |
| OLD | NEW |