| 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 <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "headless/public/headless_browser_context.h" | 16 #include "headless/public/headless_browser_context.h" |
| 17 #include "headless/public/headless_export.h" | 17 #include "headless/public/headless_export.h" |
| 18 #include "headless/public/headless_web_contents.h" | 18 #include "headless/public/headless_web_contents.h" |
| 19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
| 20 #include "net/base/ip_endpoint.h" | 20 #include "net/base/ip_endpoint.h" |
| 21 #include "ui/gfx/geometry/size.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class MessagePump; | 24 class MessagePump; |
| 24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace gfx { | |
| 28 class Size; | |
| 29 } | |
| 30 | |
| 31 namespace headless { | 28 namespace headless { |
| 32 | 29 |
| 33 // This class represents the global headless browser instance. To get a pointer | 30 // This class represents the global headless browser instance. To get a pointer |
| 34 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An | 31 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An |
| 35 // instance of |HeadlessBrowser| will be passed to the callback given to that | 32 // instance of |HeadlessBrowser| will be passed to the callback given to that |
| 36 // function. | 33 // function. |
| 37 class HEADLESS_EXPORT HeadlessBrowser { | 34 class HEADLESS_EXPORT HeadlessBrowser { |
| 38 public: | 35 public: |
| 39 struct Options; | 36 struct Options; |
| 40 | 37 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 116 |
| 120 // Custom network protocol handlers. These can be used to override URL | 117 // Custom network protocol handlers. These can be used to override URL |
| 121 // fetching for different network schemes. | 118 // fetching for different network schemes. |
| 122 ProtocolHandlerMap protocol_handlers; | 119 ProtocolHandlerMap protocol_handlers; |
| 123 | 120 |
| 124 // Choose the GL implementation to use for rendering. A suitable | 121 // Choose the GL implementation to use for rendering. A suitable |
| 125 // implementantion is selected by default. Setting this to an empty | 122 // implementantion is selected by default. Setting this to an empty |
| 126 // string can be used to disable GL rendering (e.g., WebGL support). | 123 // string can be used to disable GL rendering (e.g., WebGL support). |
| 127 std::string gl_implementation; | 124 std::string gl_implementation; |
| 128 | 125 |
| 126 // Default window size. This is also used to create the window tree host and |
| 127 // as initial screen size. Defaults to 800x600. |
| 128 gfx::Size window_size; |
| 129 |
| 129 private: | 130 private: |
| 130 Options(int argc, const char** argv); | 131 Options(int argc, const char** argv); |
| 131 | 132 |
| 132 DISALLOW_COPY_AND_ASSIGN(Options); | 133 DISALLOW_COPY_AND_ASSIGN(Options); |
| 133 }; | 134 }; |
| 134 | 135 |
| 135 class HeadlessBrowser::Options::Builder { | 136 class HeadlessBrowser::Options::Builder { |
| 136 public: | 137 public: |
| 137 Builder(int argc, const char** argv); | 138 Builder(int argc, const char** argv); |
| 138 Builder(); | 139 Builder(); |
| 139 ~Builder(); | 140 ~Builder(); |
| 140 | 141 |
| 141 Builder& SetUserAgent(const std::string& user_agent); | 142 Builder& SetUserAgent(const std::string& user_agent); |
| 142 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); | 143 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); |
| 143 Builder& SetMessagePump(base::MessagePump* message_pump); | 144 Builder& SetMessagePump(base::MessagePump* message_pump); |
| 144 Builder& SetProxyServer(const net::HostPortPair& proxy_server); | 145 Builder& SetProxyServer(const net::HostPortPair& proxy_server); |
| 145 Builder& SetHostResolverRules(const std::string& host_resolver_rules); | 146 Builder& SetHostResolverRules(const std::string& host_resolver_rules); |
| 146 Builder& SetSingleProcessMode(bool single_process_mode); | 147 Builder& SetSingleProcessMode(bool single_process_mode); |
| 147 Builder& SetDisableSandbox(bool disable_sandbox); | 148 Builder& SetDisableSandbox(bool disable_sandbox); |
| 148 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers); | 149 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers); |
| 149 Builder& SetGLImplementation(const std::string& gl_implementation); | 150 Builder& SetGLImplementation(const std::string& gl_implementation); |
| 151 Builder& SetWindowSize(const gfx::Size& window_size); |
| 150 | 152 |
| 151 Options Build(); | 153 Options Build(); |
| 152 | 154 |
| 153 private: | 155 private: |
| 154 Options options_; | 156 Options options_; |
| 155 | 157 |
| 156 DISALLOW_COPY_AND_ASSIGN(Builder); | 158 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 // The headless browser may need to create child processes (e.g., a renderer | 161 // The headless browser may need to create child processes (e.g., a renderer |
| (...skipping 23 matching lines...) Expand all Loading... |
| 183 // the main loop, it will only return after HeadlessBrowser::Shutdown() is | 185 // the main loop, it will only return after HeadlessBrowser::Shutdown() is |
| 184 // called, returning the exit code for the process. It is not possible to | 186 // called, returning the exit code for the process. It is not possible to |
| 185 // initialize the browser again after it has been torn down. | 187 // initialize the browser again after it has been torn down. |
| 186 int HeadlessBrowserMain( | 188 int HeadlessBrowserMain( |
| 187 HeadlessBrowser::Options options, | 189 HeadlessBrowser::Options options, |
| 188 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); | 190 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); |
| 189 | 191 |
| 190 } // namespace headless | 192 } // namespace headless |
| 191 | 193 |
| 192 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 194 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| OLD | NEW |