Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1041)

Side by Side Diff: headless/public/headless_browser.h

Issue 2832963002: Reland of Add --headless flag to Windows (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « headless/lib/headless_content_main_delegate.cc ('k') | headless/public/headless_browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
25 namespace base { 29 namespace base {
26 class MessagePump; 30 class MessagePump;
27 class SingleThreadTaskRunner; 31 class SingleThreadTaskRunner;
28 } 32 }
29 33
30 namespace headless { 34 namespace headless {
31 35
32 // This class represents the global headless browser instance. To get a pointer 36 // This class represents the global headless browser instance. To get a pointer
33 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An 37 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An
34 // instance of |HeadlessBrowser| will be passed to the callback given to that 38 // instance of |HeadlessBrowser| will be passed to the callback given to that
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 86
83 protected: 87 protected:
84 HeadlessBrowser() {} 88 HeadlessBrowser() {}
85 virtual ~HeadlessBrowser() {} 89 virtual ~HeadlessBrowser() {}
86 90
87 private: 91 private:
88 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); 92 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser);
89 }; 93 };
90 94
91 // Embedding API overrides for the headless browser. 95 // Embedding API overrides for the headless browser.
92 struct HeadlessBrowser::Options { 96 struct HEADLESS_EXPORT HeadlessBrowser::Options {
93 class Builder; 97 class Builder;
94 98
95 Options(Options&& options); 99 Options(Options&& options);
96 ~Options(); 100 ~Options();
97 101
98 Options& operator=(Options&& options); 102 Options& operator=(Options&& options);
99 103
100 // Command line options to be passed to browser. 104 // Command line options to be passed to browser.
101 int argc; 105 int argc;
102 const char** argv; 106 const char** argv;
103 107
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
104 // Address at which DevTools should listen for connections. Disabled by 116 // Address at which DevTools should listen for connections. Disabled by
105 // default. 117 // default.
106 net::IPEndPoint devtools_endpoint; 118 net::IPEndPoint devtools_endpoint;
107 119
108 // Optional message pump that overrides the default. Must outlive the browser. 120 // Optional message pump that overrides the default. Must outlive the browser.
109 base::MessagePump* message_pump; 121 base::MessagePump* message_pump;
110 122
111 // Run the browser in single process mode instead of using separate renderer 123 // Run the browser in single process mode instead of using separate renderer
112 // processes as per default. Note that this also disables any sandboxing of 124 // processes as per default. Note that this also disables any sandboxing of
113 // web content, which can be a security risk. 125 // web content, which can be a security risk.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 base::FilePath crash_dumps_dir; 177 base::FilePath crash_dumps_dir;
166 178
167 // Reminder: when adding a new field here, do not forget to add it to 179 // Reminder: when adding a new field here, do not forget to add it to
168 // HeadlessBrowserContextOptions (where appropriate). 180 // HeadlessBrowserContextOptions (where appropriate).
169 private: 181 private:
170 Options(int argc, const char** argv); 182 Options(int argc, const char** argv);
171 183
172 DISALLOW_COPY_AND_ASSIGN(Options); 184 DISALLOW_COPY_AND_ASSIGN(Options);
173 }; 185 };
174 186
175 class HeadlessBrowser::Options::Builder { 187 class HEADLESS_EXPORT HeadlessBrowser::Options::Builder {
176 public: 188 public:
177 Builder(int argc, const char** argv); 189 Builder(int argc, const char** argv);
178 Builder(); 190 Builder();
179 ~Builder(); 191 ~Builder();
180 192
181 // Browser-wide settings. 193 // Browser-wide settings.
182 194
183 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); 195 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint);
184 Builder& SetMessagePump(base::MessagePump* message_pump); 196 Builder& SetMessagePump(base::MessagePump* message_pump);
185 Builder& SetSingleProcessMode(bool single_process_mode); 197 Builder& SetSingleProcessMode(bool single_process_mode);
186 Builder& SetDisableSandbox(bool disable_sandbox); 198 Builder& SetDisableSandbox(bool disable_sandbox);
187 Builder& SetGLImplementation(const std::string& gl_implementation); 199 Builder& SetGLImplementation(const std::string& gl_implementation);
188 Builder& AddMojoServiceName(const std::string& mojo_service_name); 200 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
189 205
190 // Per-context settings. 206 // Per-context settings.
191 207
192 Builder& SetProductNameAndVersion( 208 Builder& SetProductNameAndVersion(
193 const std::string& product_name_and_version); 209 const std::string& product_name_and_version);
194 Builder& SetUserAgent(const std::string& user_agent); 210 Builder& SetUserAgent(const std::string& user_agent);
195 Builder& SetProxyServer(const net::HostPortPair& proxy_server); 211 Builder& SetProxyServer(const net::HostPortPair& proxy_server);
196 Builder& SetHostResolverRules(const std::string& host_resolver_rules); 212 Builder& SetHostResolverRules(const std::string& host_resolver_rules);
197 Builder& SetWindowSize(const gfx::Size& window_size); 213 Builder& SetWindowSize(const gfx::Size& window_size);
198 Builder& SetUserDataDir(const base::FilePath& user_data_dir); 214 Builder& SetUserDataDir(const base::FilePath& user_data_dir);
(...skipping 23 matching lines...) Expand all
222 // int main(int argc, const char** argv) { 238 // int main(int argc, const char** argv) {
223 // headless::RunChildProcessIfNeeded(argc, argv); 239 // headless::RunChildProcessIfNeeded(argc, argv);
224 // headless::HeadlessBrowser::Options::Builder builder(argc, argv); 240 // headless::HeadlessBrowser::Options::Builder builder(argc, argv);
225 // return headless::HeadlessBrowserMain( 241 // return headless::HeadlessBrowserMain(
226 // builder.Build(), 242 // builder.Build(),
227 // base::Callback<void(headless::HeadlessBrowser*)>()); 243 // base::Callback<void(headless::HeadlessBrowser*)>());
228 // } 244 // }
229 // 245 //
230 // [1] 246 // [1]
231 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md 247 // https://chromium.googlesource.com/chromium/src/+/master/docs/linux_zygote.md
232 void RunChildProcessIfNeeded(int argc, const char** argv); 248 #if !defined(OS_WIN)
249 HEADLESS_EXPORT void RunChildProcessIfNeeded(int argc, const char** argv);
250 #endif
233 251
234 // Main entry point for running the headless browser. This function constructs 252 // Main entry point for running the headless browser. This function constructs
235 // the headless browser instance, passing it to the given 253 // the headless browser instance, passing it to the given
236 // |on_browser_start_callback| callback. Note that since this function executes 254 // |on_browser_start_callback| callback. Note that since this function executes
237 // the main loop, it will only return after HeadlessBrowser::Shutdown() is 255 // the main loop, it will only return after HeadlessBrowser::Shutdown() is
238 // called, returning the exit code for the process. It is not possible to 256 // called, returning the exit code for the process. It is not possible to
239 // initialize the browser again after it has been torn down. 257 // initialize the browser again after it has been torn down.
240 int HeadlessBrowserMain( 258 HEADLESS_EXPORT int HeadlessBrowserMain(
241 HeadlessBrowser::Options options, 259 HeadlessBrowser::Options options,
242 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); 260 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback);
243 261
244 } // namespace headless 262 } // namespace headless
245 263
246 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 264 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
OLDNEW
« no previous file with comments | « headless/lib/headless_content_main_delegate.cc ('k') | headless/public/headless_browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698