| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers); | 138 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers); |
| 139 | 139 |
| 140 Options Build(); | 140 Options Build(); |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 Options options_; | 143 Options options_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(Builder); | 145 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // The headless browser may need to create child processes (e.g., a renderer |
| 149 // which runs web content). This is done by re-executing the parent process as |
| 150 // a zygote[1] and forking each child process from that zygote. |
| 151 // |
| 152 // For this to work, the embedder should call RunChildProcess as soon as |
| 153 // possible (i.e., before creating any threads) to pass control to the headless |
| 154 // library. In a browser process this function will return immediately, but in a |
| 155 // child process it will never return. For example: |
| 156 // |
| 157 // int main(int argc, const char** argv) { |
| 158 // headless::RunChildProcessIfNeeded(argc, argv); |
| 159 // headless::HeadlessBrowser::Options::Builder builder(argc, argv); |
| 160 // return headless::HeadlessBrowserMain( |
| 161 // builder.Build(), |
| 162 // base::Callback<void(headless::HeadlessBrowser*)>()); |
| 163 // } |
| 164 // |
| 165 // [1] |
| 166 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md |
| 167 void RunChildProcessIfNeeded(int argc, const char** argv); |
| 168 |
| 148 // Main entry point for running the headless browser. This function constructs | 169 // Main entry point for running the headless browser. This function constructs |
| 149 // the headless browser instance, passing it to the given | 170 // the headless browser instance, passing it to the given |
| 150 // |on_browser_start_callback| callback. Note that since this function executes | 171 // |on_browser_start_callback| callback. Note that since this function executes |
| 151 // the main loop, it will only return after HeadlessBrowser::Shutdown() is | 172 // the main loop, it will only return after HeadlessBrowser::Shutdown() is |
| 152 // called, returning the exit code for the process. | 173 // called, returning the exit code for the process. It is not possible to |
| 174 // initialize the browser again after it has been torn down. |
| 153 int HeadlessBrowserMain( | 175 int HeadlessBrowserMain( |
| 154 HeadlessBrowser::Options options, | 176 HeadlessBrowser::Options options, |
| 155 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); | 177 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); |
| 156 | 178 |
| 157 } // namespace headless | 179 } // namespace headless |
| 158 | 180 |
| 159 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 181 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| OLD | NEW |