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> | |
11 | 10 |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
15 #include "headless/public/headless_export.h" | 14 #include "headless/public/headless_export.h" |
16 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
17 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
18 #include "net/url_request/url_request_job_factory.h" | |
19 | 17 |
20 namespace base { | 18 namespace base { |
21 class MessagePump; | 19 class MessagePump; |
22 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
23 } | 21 } |
24 | 22 |
25 namespace gfx { | 23 namespace gfx { |
26 class Size; | 24 class Size; |
27 } | 25 } |
28 | 26 |
(...skipping 27 matching lines...) Expand all Loading... |
56 virtual void Shutdown() = 0; | 54 virtual void Shutdown() = 0; |
57 | 55 |
58 protected: | 56 protected: |
59 HeadlessBrowser() {} | 57 HeadlessBrowser() {} |
60 virtual ~HeadlessBrowser() {} | 58 virtual ~HeadlessBrowser() {} |
61 | 59 |
62 private: | 60 private: |
63 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); | 61 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); |
64 }; | 62 }; |
65 | 63 |
66 using ProtocolHandlerMap = std::unordered_map< | |
67 std::string, | |
68 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>>; | |
69 | |
70 // Embedding API overrides for the headless browser. | 64 // Embedding API overrides for the headless browser. |
71 struct HeadlessBrowser::Options { | 65 struct HeadlessBrowser::Options { |
72 class Builder; | 66 class Builder; |
73 | 67 |
74 Options(Options&& options); | 68 Options(Options&& options); |
75 ~Options(); | 69 ~Options(); |
76 | 70 |
77 Options& operator=(Options&& options); | 71 Options& operator=(Options&& options); |
78 | 72 |
79 // Command line options to be passed to browser. | 73 // Command line options to be passed to browser. |
(...skipping 16 matching lines...) Expand all Loading... |
96 | 90 |
97 // Comma-separated list of rules that control how hostnames are mapped. See | 91 // Comma-separated list of rules that control how hostnames are mapped. See |
98 // chrome::switches::kHostRules for a description for the format. | 92 // chrome::switches::kHostRules for a description for the format. |
99 std::string host_resolver_rules; | 93 std::string host_resolver_rules; |
100 | 94 |
101 // Run the browser in single process mode instead of using separate renderer | 95 // Run the browser in single process mode instead of using separate renderer |
102 // processes as per default. Note that this also disables any sandboxing of | 96 // processes as per default. Note that this also disables any sandboxing of |
103 // web content, which can be a security risk. | 97 // web content, which can be a security risk. |
104 bool single_process_mode; | 98 bool single_process_mode; |
105 | 99 |
106 // Custom network protocol handlers. These can be used to override URL | |
107 // fetching for different network schemes. | |
108 ProtocolHandlerMap protocol_handlers; | |
109 | |
110 private: | 100 private: |
111 Options(int argc, const char** argv); | 101 Options(int argc, const char** argv); |
112 | 102 |
113 DISALLOW_COPY_AND_ASSIGN(Options); | 103 DISALLOW_COPY_AND_ASSIGN(Options); |
114 }; | 104 }; |
115 | 105 |
116 class HeadlessBrowser::Options::Builder { | 106 class HeadlessBrowser::Options::Builder { |
117 public: | 107 public: |
118 Builder(int argc, const char** argv); | 108 Builder(int argc, const char** argv); |
119 Builder(); | 109 Builder(); |
120 ~Builder(); | 110 ~Builder(); |
121 | 111 |
122 Builder& SetUserAgent(const std::string& user_agent); | 112 Builder& SetUserAgent(const std::string& user_agent); |
123 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); | 113 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); |
124 Builder& SetMessagePump(base::MessagePump* message_pump); | 114 Builder& SetMessagePump(base::MessagePump* message_pump); |
125 Builder& SetProxyServer(const net::HostPortPair& proxy_server); | 115 Builder& SetProxyServer(const net::HostPortPair& proxy_server); |
126 Builder& SetHostResolverRules(const std::string& host_resolver_rules); | 116 Builder& SetHostResolverRules(const std::string& host_resolver_rules); |
127 Builder& SetSingleProcessMode(bool single_process_mode); | 117 Builder& SetSingleProcessMode(bool single_process_mode); |
128 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers); | |
129 | 118 |
130 Options Build(); | 119 Options Build(); |
131 | 120 |
132 private: | 121 private: |
133 Options options_; | 122 Options options_; |
134 | 123 |
135 DISALLOW_COPY_AND_ASSIGN(Builder); | 124 DISALLOW_COPY_AND_ASSIGN(Builder); |
136 }; | 125 }; |
137 | 126 |
138 // Main entry point for running the headless browser. This function constructs | 127 // Main entry point for running the headless browser. This function constructs |
139 // the headless browser instance, passing it to the given | 128 // the headless browser instance, passing it to the given |
140 // |on_browser_start_callback| callback. Note that since this function executes | 129 // |on_browser_start_callback| callback. Note that since this function executes |
141 // the main loop, it will only return after HeadlessBrowser::Shutdown() is | 130 // the main loop, it will only return after HeadlessBrowser::Shutdown() is |
142 // called, returning the exit code for the process. | 131 // called, returning the exit code for the process. |
143 int HeadlessBrowserMain( | 132 int HeadlessBrowserMain( |
144 HeadlessBrowser::Options options, | 133 HeadlessBrowser::Options options, |
145 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); | 134 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); |
146 | 135 |
147 } // namespace headless | 136 } // namespace headless |
148 | 137 |
149 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ | 138 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
OLD | NEW |