| 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 #ifndef HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 5 #ifndef HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| 6 #define HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 6 #define HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 Builder& SetCrashDumpsDir(const base::FilePath& dir); | 219 Builder& SetCrashDumpsDir(const base::FilePath& dir); |
| 220 | 220 |
| 221 Options Build(); | 221 Options Build(); |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 Options options_; | 224 Options options_; |
| 225 | 225 |
| 226 DISALLOW_COPY_AND_ASSIGN(Builder); | 226 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 #if !defined(OS_WIN) |
| 229 // The headless browser may need to create child processes (e.g., a renderer | 230 // The headless browser may need to create child processes (e.g., a renderer |
| 230 // which runs web content). This is done by re-executing the parent process as | 231 // which runs web content). This is done by re-executing the parent process as |
| 231 // a zygote[1] and forking each child process from that zygote. | 232 // a zygote[1] and forking each child process from that zygote. |
| 232 // | 233 // |
| 233 // For this to work, the embedder should call RunChildProcess as soon as | 234 // For this to work, the embedder should call RunChildProcess as soon as |
| 234 // possible (i.e., before creating any threads) to pass control to the headless | 235 // possible (i.e., before creating any threads) to pass control to the headless |
| 235 // library. In a browser process this function will return immediately, but in a | 236 // library. In a browser process this function will return immediately, but in a |
| 236 // child process it will never return. For example: | 237 // child process it will never return. For example: |
| 237 // | 238 // |
| 238 // int main(int argc, const char** argv) { | 239 // int main(int argc, const char** argv) { |
| 239 // headless::RunChildProcessIfNeeded(argc, argv); | 240 // headless::RunChildProcessIfNeeded(argc, argv); |
| 240 // headless::HeadlessBrowser::Options::Builder builder(argc, argv); | 241 // headless::HeadlessBrowser::Options::Builder builder(argc, argv); |
| 241 // return headless::HeadlessBrowserMain( | 242 // return headless::HeadlessBrowserMain( |
| 242 // builder.Build(), | 243 // builder.Build(), |
| 243 // base::Callback<void(headless::HeadlessBrowser*)>()); | 244 // base::Callback<void(headless::HeadlessBrowser*)>()); |
| 244 // } | 245 // } |
| 245 // | 246 // |
| 246 // [1] | 247 // [1] |
| 247 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md | 248 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md |
| 248 #if !defined(OS_WIN) | |
| 249 HEADLESS_EXPORT void RunChildProcessIfNeeded(int argc, const char** argv); | 249 HEADLESS_EXPORT void RunChildProcessIfNeeded(int argc, const char** argv); |
| 250 #endif | 250 #else |
| 251 // In Windows, the headless browser may need to create child processes. This is |
| 252 // done by re-executing the parent process which may have been initialized with |
| 253 // different libraries (e.g. child_dll). In this case, the embedder has to pass |
| 254 // the appropiate HINSTANCE and initalization sandbox_info to properly launch |
| 255 // the child process. |
| 256 HEADLESS_EXPORT void RunChildProcessIfNeeded( |
| 257 HINSTANCE instance, |
| 258 sandbox::SandboxInterfaceInfo* sandbox_info); |
| 259 #endif // !defined(OS_WIN) |
| 251 | 260 |
| 252 // Main entry point for running the headless browser. This function constructs | 261 // Main entry point for running the headless browser. This function constructs |
| 253 // the headless browser instance, passing it to the given | 262 // the headless browser instance, passing it to the given |
| 254 // |on_browser_start_callback| callback. Note that since this function executes | 263 // |on_browser_start_callback| callback. Note that since this function executes |
| 255 // the main loop, it will only return after HeadlessBrowser::Shutdown() is | 264 // the main loop, it will only return after HeadlessBrowser::Shutdown() is |
| 256 // called, returning the exit code for the process. It is not possible to | 265 // called, returning the exit code for the process. It is not possible to |
| 257 // initialize the browser again after it has been torn down. | 266 // initialize the browser again after it has been torn down. |
| 258 HEADLESS_EXPORT int HeadlessBrowserMain( | 267 HEADLESS_EXPORT int HeadlessBrowserMain( |
| 259 HeadlessBrowser::Options options, | 268 HeadlessBrowser::Options options, |
| 260 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); | 269 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); |
| 261 | 270 |
| 262 } // namespace headless | 271 } // namespace headless |
| 263 | 272 |
| 264 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 273 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| OLD | NEW |