Chromium Code Reviews| 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 | |
| 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 Loading... | |
| 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; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // WARNING: We cannot provide any guarantees about the stability of the | 161 // WARNING: We cannot provide any guarantees about the stability of the |
| 158 // exposed WebPreferences API, so use with care. | 162 // exposed WebPreferences API, so use with care. |
| 159 base::Callback<void(WebPreferences*)> override_web_preferences_callback; | 163 base::Callback<void(WebPreferences*)> override_web_preferences_callback; |
| 160 | 164 |
| 161 // Minidump crash reporter settings. Crash reporting is disabled by default. | 165 // Minidump crash reporter settings. Crash reporting is disabled by default. |
| 162 // By default crash dumps are written to the directory containing the | 166 // By default crash dumps are written to the directory containing the |
| 163 // executable. | 167 // executable. |
| 164 bool enable_crash_reporter; | 168 bool enable_crash_reporter; |
| 165 base::FilePath crash_dumps_dir; | 169 base::FilePath crash_dumps_dir; |
| 166 | 170 |
| 171 #if defined(OS_WIN) | |
| 172 // Set hardware instance if available, otherwise it defaults to 0. | |
| 173 HINSTANCE instance; | |
|
Sami
2017/03/27 14:07:58
Looks like both of these are uninitialized.
dvallet
2017/03/28 02:36:00
They are set in HeadlessShellMain and headlessExam
Sami
2017/03/28 11:49:32
I meant Options::Options should set them to null l
dvallet
2017/03/29 06:27:56
Gotcha, Done.
| |
| 174 | |
| 175 // Set with sandboc information. This has to be already initialized. | |
| 176 sandbox::SandboxInterfaceInfo* sandbox_info; | |
| 177 #endif | |
| 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 Loading... | |
| 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_ |
| OLD | NEW |