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

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

Issue 2181413002: [headless] Remove default browser context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 4 years, 4 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_web_contents_browsertest.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 <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "headless/public/headless_browser_context.h" 17 #include "headless/public/headless_browser_context.h"
17 #include "headless/public/headless_export.h" 18 #include "headless/public/headless_export.h"
18 #include "headless/public/headless_web_contents.h" 19 #include "headless/public/headless_web_contents.h"
19 #include "net/base/host_port_pair.h" 20 #include "net/base/host_port_pair.h"
20 #include "net/base/ip_endpoint.h" 21 #include "net/base/ip_endpoint.h"
21 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
22 23
23 namespace base { 24 namespace base {
24 class MessagePump; 25 class MessagePump;
25 class SingleThreadTaskRunner; 26 class SingleThreadTaskRunner;
26 } 27 }
27 28
28 namespace headless { 29 namespace headless {
29 30
30 // This class represents the global headless browser instance. To get a pointer 31 // This class represents the global headless browser instance. To get a pointer
31 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An 32 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An
32 // instance of |HeadlessBrowser| will be passed to the callback given to that 33 // instance of |HeadlessBrowser| will be passed to the callback given to that
33 // function. 34 // function.
34 class HEADLESS_EXPORT HeadlessBrowser { 35 class HEADLESS_EXPORT HeadlessBrowser {
35 public: 36 public:
36 struct Options; 37 struct Options;
37 38
38 // Open a new tab. Returns a builder object which can be used to set 39 // Create a new browser context which can be used to create tabs and isolate
39 // properties for the new tab. 40 // them from one another.
40 virtual HeadlessWebContents::Builder CreateWebContentsBuilder() = 0; 41 // User owns newly created HeadlessBrowserContext and should delete them
Sami 2016/08/03 14:25:49 s/them/it/
41 42 // before calling HeadlessBrowser::Shutdown().
42 // Deprecated. Use CreateWebContentsBuilder() instead. 43 virtual HeadlessBrowserContext::Builder CreateBrowserContextBuilder() = 0;
43 virtual HeadlessWebContents* CreateWebContents(const GURL& initial_url,
44 const gfx::Size& size) = 0;
45 44
46 virtual std::vector<HeadlessWebContents*> GetAllWebContents() = 0; 45 virtual std::vector<HeadlessWebContents*> GetAllWebContents() = 0;
47 46
48 // Returns the HeadlessWebContents associated with the 47 // Returns the HeadlessWebContents associated with the
49 // |devtools_agent_host_id| if any. Otherwise returns null. 48 // |devtools_agent_host_id| if any. Otherwise returns null.
50 virtual HeadlessWebContents* GetWebContentsForDevtoolsAgentHostId( 49 virtual HeadlessWebContents* GetWebContentsForDevtoolsAgentHostId(
51 const std::string& devtools_agent_host_id) = 0; 50 const std::string& devtools_agent_host_id) = 0;
52 51
53 // Returns a task runner for submitting work to the browser main thread. 52 // Returns a task runner for submitting work to the browser main thread.
54 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() 53 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread()
55 const = 0; 54 const = 0;
56 55
57 // Returns a task runner for submitting work to the browser file thread. 56 // Returns a task runner for submitting work to the browser file thread.
58 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserFileThread() 57 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserFileThread()
59 const = 0; 58 const = 0;
60 59
61 // Requests browser to stop as soon as possible. |Run| will return as soon as 60 // Requests browser to stop as soon as possible. |Run| will return as soon as
62 // browser stops. 61 // browser stops.
63 virtual void Shutdown() = 0; 62 virtual void Shutdown() = 0;
64 63
65 // Create a new browser context, which can be used to isolate
66 // HeadlessWebContents from one another.
67 virtual HeadlessBrowserContext::Builder CreateBrowserContextBuilder() = 0;
68
69 protected: 64 protected:
70 HeadlessBrowser() {} 65 HeadlessBrowser() {}
71 virtual ~HeadlessBrowser() {} 66 virtual ~HeadlessBrowser() {}
72 67
73 private: 68 private:
74 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); 69 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser);
75 }; 70 };
76 71
77 // Embedding API overrides for the headless browser. 72 // Embedding API overrides for the headless browser.
78 struct HeadlessBrowser::Options { 73 struct HeadlessBrowser::Options {
79 class Builder; 74 class Builder;
80 75
81 Options(Options&& options); 76 Options(Options&& options);
82 ~Options(); 77 ~Options();
83 78
84 Options& operator=(Options&& options); 79 Options& operator=(Options&& options);
85 80
86 // Command line options to be passed to browser. 81 // Command line options to be passed to browser.
87 int argc; 82 int argc;
88 const char** argv; 83 const char** argv;
89 84
90 std::string user_agent;
91 std::string navigator_platform;
92
93 // Address at which DevTools should listen for connections. Disabled by 85 // Address at which DevTools should listen for connections. Disabled by
94 // default. 86 // default.
95 net::IPEndPoint devtools_endpoint; 87 net::IPEndPoint devtools_endpoint;
96 88
97 // Address of the HTTP/HTTPS proxy server to use. The system proxy settings
98 // are used by default.
99 net::HostPortPair proxy_server;
100
101 // Optional message pump that overrides the default. Must outlive the browser. 89 // Optional message pump that overrides the default. Must outlive the browser.
102 base::MessagePump* message_pump; 90 base::MessagePump* message_pump;
103 91
104 // Comma-separated list of rules that control how hostnames are mapped. See
105 // chrome::switches::kHostRules for a description for the format.
106 std::string host_resolver_rules;
107
108 // Run the browser in single process mode instead of using separate renderer 92 // Run the browser in single process mode instead of using separate renderer
109 // processes as per default. Note that this also disables any sandboxing of 93 // processes as per default. Note that this also disables any sandboxing of
110 // web content, which can be a security risk. 94 // web content, which can be a security risk.
111 bool single_process_mode; 95 bool single_process_mode;
112 96
113 // Run the browser without renderer sandbox. This option can be 97 // Run the browser without renderer sandbox. This option can be
114 // a security risk and should be used with caution. 98 // a security risk and should be used with caution.
115 bool disable_sandbox; 99 bool disable_sandbox;
116 100
117 // Custom network protocol handlers. These can be used to override URL
118 // fetching for different network schemes.
119 ProtocolHandlerMap protocol_handlers;
120
121 // Choose the GL implementation to use for rendering. A suitable 101 // Choose the GL implementation to use for rendering. A suitable
122 // implementantion is selected by default. Setting this to an empty 102 // implementantion is selected by default. Setting this to an empty
123 // string can be used to disable GL rendering (e.g., WebGL support). 103 // string can be used to disable GL rendering (e.g., WebGL support).
124 std::string gl_implementation; 104 std::string gl_implementation;
125 105
106 // Default per-context options, can be specialized on per-context basis.
107
108 std::string user_agent;
109
110 // Address of the HTTP/HTTPS proxy server to use. The system proxy settings
111 // are used by default.
112 net::HostPortPair proxy_server;
113
114 // Comma-separated list of rules that control how hostnames are mapped. See
115 // chrome::switches::kHostRules for a description for the format.
116 std::string host_resolver_rules;
117
126 // Default window size. This is also used to create the window tree host and 118 // Default window size. This is also used to create the window tree host and
127 // as initial screen size. Defaults to 800x600. 119 // as initial screen size. Defaults to 800x600.
128 gfx::Size window_size; 120 gfx::Size window_size;
129 121
122 // Path to user data directory, where browser will look for its state.
123 // If empty, default directory (where the binary is located) will be used.
124 base::FilePath user_data_dir;
125
126 // Reminder: when adding a new field here, do not forget to add it to
127 // HeadlessBrowserContextOptions (where appropriate).
130 private: 128 private:
131 Options(int argc, const char** argv); 129 Options(int argc, const char** argv);
132 130
133 DISALLOW_COPY_AND_ASSIGN(Options); 131 DISALLOW_COPY_AND_ASSIGN(Options);
134 }; 132 };
135 133
136 class HeadlessBrowser::Options::Builder { 134 class HeadlessBrowser::Options::Builder {
137 public: 135 public:
138 Builder(int argc, const char** argv); 136 Builder(int argc, const char** argv);
139 Builder(); 137 Builder();
140 ~Builder(); 138 ~Builder();
141 139
142 Builder& SetUserAgent(const std::string& user_agent); 140 // Browser-wide settings.
141
143 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); 142 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint);
144 Builder& SetMessagePump(base::MessagePump* message_pump); 143 Builder& SetMessagePump(base::MessagePump* message_pump);
144 Builder& SetSingleProcessMode(bool single_process_mode);
145 Builder& SetDisableSandbox(bool disable_sandbox);
146 Builder& SetGLImplementation(const std::string& gl_implementation);
147
148 // Per-context settings.
149
150 Builder& SetUserAgent(const std::string& user_agent);
145 Builder& SetProxyServer(const net::HostPortPair& proxy_server); 151 Builder& SetProxyServer(const net::HostPortPair& proxy_server);
146 Builder& SetHostResolverRules(const std::string& host_resolver_rules); 152 Builder& SetHostResolverRules(const std::string& host_resolver_rules);
147 Builder& SetSingleProcessMode(bool single_process_mode);
148 Builder& SetDisableSandbox(bool disable_sandbox);
149 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers);
150 Builder& SetGLImplementation(const std::string& gl_implementation);
151 Builder& SetWindowSize(const gfx::Size& window_size); 153 Builder& SetWindowSize(const gfx::Size& window_size);
154 Builder& SetUserDataDir(const base::FilePath& user_data_dir);
152 155
153 Options Build(); 156 Options Build();
154 157
155 private: 158 private:
156 Options options_; 159 Options options_;
157 160
158 DISALLOW_COPY_AND_ASSIGN(Builder); 161 DISALLOW_COPY_AND_ASSIGN(Builder);
159 }; 162 };
160 163
161 // The headless browser may need to create child processes (e.g., a renderer 164 // The headless browser may need to create child processes (e.g., a renderer
(...skipping 23 matching lines...) Expand all
185 // the main loop, it will only return after HeadlessBrowser::Shutdown() is 188 // the main loop, it will only return after HeadlessBrowser::Shutdown() is
186 // called, returning the exit code for the process. It is not possible to 189 // called, returning the exit code for the process. It is not possible to
187 // initialize the browser again after it has been torn down. 190 // initialize the browser again after it has been torn down.
188 int HeadlessBrowserMain( 191 int HeadlessBrowserMain(
189 HeadlessBrowser::Options options, 192 HeadlessBrowser::Options options,
190 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); 193 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback);
191 194
192 } // namespace headless 195 } // namespace headless
193 196
194 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 197 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
OLDNEW
« no previous file with comments | « headless/lib/headless_web_contents_browsertest.cc ('k') | headless/public/headless_browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698