| 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> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "headless/public/headless_browser_context.h" | 18 #include "headless/public/headless_browser_context.h" |
| 19 #include "headless/public/headless_export.h" | 19 #include "headless/public/headless_export.h" |
| 20 #include "headless/public/headless_web_contents.h" | 20 #include "headless/public/headless_web_contents.h" |
| 21 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
| 22 #include "net/base/ip_endpoint.h" | 22 #include "net/base/ip_endpoint.h" |
| 23 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
| 24 | 24 |
| 25 #if defined(OS_WIN) | |
| 26 #include "sandbox/win/src/sandbox_types.h" | |
| 27 #endif | |
| 28 | |
| 29 namespace base { | 25 namespace base { |
| 30 class MessagePump; | 26 class MessagePump; |
| 31 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
| 32 } | 28 } |
| 33 | 29 |
| 34 namespace headless { | 30 namespace headless { |
| 35 | 31 |
| 36 // This class represents the global headless browser instance. To get a pointer | 32 // This class represents the global headless browser instance. To get a pointer |
| 37 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An | 33 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An |
| 38 // instance of |HeadlessBrowser| will be passed to the callback given to that | 34 // instance of |HeadlessBrowser| will be passed to the callback given to that |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 82 |
| 87 protected: | 83 protected: |
| 88 HeadlessBrowser() {} | 84 HeadlessBrowser() {} |
| 89 virtual ~HeadlessBrowser() {} | 85 virtual ~HeadlessBrowser() {} |
| 90 | 86 |
| 91 private: | 87 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); | 88 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); |
| 93 }; | 89 }; |
| 94 | 90 |
| 95 // Embedding API overrides for the headless browser. | 91 // Embedding API overrides for the headless browser. |
| 96 struct HEADLESS_EXPORT HeadlessBrowser::Options { | 92 struct HeadlessBrowser::Options { |
| 97 class Builder; | 93 class Builder; |
| 98 | 94 |
| 99 Options(Options&& options); | 95 Options(Options&& options); |
| 100 ~Options(); | 96 ~Options(); |
| 101 | 97 |
| 102 Options& operator=(Options&& options); | 98 Options& operator=(Options&& options); |
| 103 | 99 |
| 104 // Command line options to be passed to browser. | 100 // Command line options to be passed to browser. |
| 105 int argc; | 101 int argc; |
| 106 const char** argv; | 102 const char** argv; |
| 107 | 103 |
| 108 #if defined(OS_WIN) | |
| 109 // Set hardware instance if available, otherwise it defaults to 0. | |
| 110 HINSTANCE instance; | |
| 111 | |
| 112 // Set with sandbox information. This has to be already initialized. | |
| 113 sandbox::SandboxInterfaceInfo* sandbox_info; | |
| 114 #endif | |
| 115 | |
| 116 // Address at which DevTools should listen for connections. Disabled by | 104 // Address at which DevTools should listen for connections. Disabled by |
| 117 // default. | 105 // default. |
| 118 net::IPEndPoint devtools_endpoint; | 106 net::IPEndPoint devtools_endpoint; |
| 119 | 107 |
| 120 // Optional message pump that overrides the default. Must outlive the browser. | 108 // Optional message pump that overrides the default. Must outlive the browser. |
| 121 base::MessagePump* message_pump; | 109 base::MessagePump* message_pump; |
| 122 | 110 |
| 123 // Run the browser in single process mode instead of using separate renderer | 111 // Run the browser in single process mode instead of using separate renderer |
| 124 // processes as per default. Note that this also disables any sandboxing of | 112 // processes as per default. Note that this also disables any sandboxing of |
| 125 // web content, which can be a security risk. | 113 // web content, which can be a security risk. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 base::FilePath crash_dumps_dir; | 165 base::FilePath crash_dumps_dir; |
| 178 | 166 |
| 179 // Reminder: when adding a new field here, do not forget to add it to | 167 // Reminder: when adding a new field here, do not forget to add it to |
| 180 // HeadlessBrowserContextOptions (where appropriate). | 168 // HeadlessBrowserContextOptions (where appropriate). |
| 181 private: | 169 private: |
| 182 Options(int argc, const char** argv); | 170 Options(int argc, const char** argv); |
| 183 | 171 |
| 184 DISALLOW_COPY_AND_ASSIGN(Options); | 172 DISALLOW_COPY_AND_ASSIGN(Options); |
| 185 }; | 173 }; |
| 186 | 174 |
| 187 class HEADLESS_EXPORT HeadlessBrowser::Options::Builder { | 175 class HeadlessBrowser::Options::Builder { |
| 188 public: | 176 public: |
| 189 Builder(int argc, const char** argv); | 177 Builder(int argc, const char** argv); |
| 190 Builder(); | 178 Builder(); |
| 191 ~Builder(); | 179 ~Builder(); |
| 192 | 180 |
| 193 // Browser-wide settings. | 181 // Browser-wide settings. |
| 194 | 182 |
| 195 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); | 183 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); |
| 196 Builder& SetMessagePump(base::MessagePump* message_pump); | 184 Builder& SetMessagePump(base::MessagePump* message_pump); |
| 197 Builder& SetSingleProcessMode(bool single_process_mode); | 185 Builder& SetSingleProcessMode(bool single_process_mode); |
| 198 Builder& SetDisableSandbox(bool disable_sandbox); | 186 Builder& SetDisableSandbox(bool disable_sandbox); |
| 199 Builder& SetGLImplementation(const std::string& gl_implementation); | 187 Builder& SetGLImplementation(const std::string& gl_implementation); |
| 200 Builder& AddMojoServiceName(const std::string& mojo_service_name); | 188 Builder& AddMojoServiceName(const std::string& mojo_service_name); |
| 201 #if defined(OS_WIN) | |
| 202 Builder& SetInstance(HINSTANCE instance); | |
| 203 Builder& SetSandboxInfo(sandbox::SandboxInterfaceInfo* sandbox_info); | |
| 204 #endif | |
| 205 | 189 |
| 206 // Per-context settings. | 190 // Per-context settings. |
| 207 | 191 |
| 208 Builder& SetProductNameAndVersion( | 192 Builder& SetProductNameAndVersion( |
| 209 const std::string& product_name_and_version); | 193 const std::string& product_name_and_version); |
| 210 Builder& SetUserAgent(const std::string& user_agent); | 194 Builder& SetUserAgent(const std::string& user_agent); |
| 211 Builder& SetProxyServer(const net::HostPortPair& proxy_server); | 195 Builder& SetProxyServer(const net::HostPortPair& proxy_server); |
| 212 Builder& SetHostResolverRules(const std::string& host_resolver_rules); | 196 Builder& SetHostResolverRules(const std::string& host_resolver_rules); |
| 213 Builder& SetWindowSize(const gfx::Size& window_size); | 197 Builder& SetWindowSize(const gfx::Size& window_size); |
| 214 Builder& SetUserDataDir(const base::FilePath& user_data_dir); | 198 Builder& SetUserDataDir(const base::FilePath& user_data_dir); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 238 // int main(int argc, const char** argv) { | 222 // int main(int argc, const char** argv) { |
| 239 // headless::RunChildProcessIfNeeded(argc, argv); | 223 // headless::RunChildProcessIfNeeded(argc, argv); |
| 240 // headless::HeadlessBrowser::Options::Builder builder(argc, argv); | 224 // headless::HeadlessBrowser::Options::Builder builder(argc, argv); |
| 241 // return headless::HeadlessBrowserMain( | 225 // return headless::HeadlessBrowserMain( |
| 242 // builder.Build(), | 226 // builder.Build(), |
| 243 // base::Callback<void(headless::HeadlessBrowser*)>()); | 227 // base::Callback<void(headless::HeadlessBrowser*)>()); |
| 244 // } | 228 // } |
| 245 // | 229 // |
| 246 // [1] | 230 // [1] |
| 247 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md | 231 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md |
| 248 #if !defined(OS_WIN) | 232 void RunChildProcessIfNeeded(int argc, const char** argv); |
| 249 HEADLESS_EXPORT void RunChildProcessIfNeeded(int argc, const char** argv); | |
| 250 #endif | |
| 251 | 233 |
| 252 // Main entry point for running the headless browser. This function constructs | 234 // Main entry point for running the headless browser. This function constructs |
| 253 // the headless browser instance, passing it to the given | 235 // the headless browser instance, passing it to the given |
| 254 // |on_browser_start_callback| callback. Note that since this function executes | 236 // |on_browser_start_callback| callback. Note that since this function executes |
| 255 // the main loop, it will only return after HeadlessBrowser::Shutdown() is | 237 // 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 | 238 // called, returning the exit code for the process. It is not possible to |
| 257 // initialize the browser again after it has been torn down. | 239 // initialize the browser again after it has been torn down. |
| 258 HEADLESS_EXPORT int HeadlessBrowserMain( | 240 int HeadlessBrowserMain( |
| 259 HeadlessBrowser::Options options, | 241 HeadlessBrowser::Options options, |
| 260 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); | 242 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); |
| 261 | 243 |
| 262 } // namespace headless | 244 } // namespace headless |
| 263 | 245 |
| 264 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 246 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| OLD | NEW |