OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_CONTEXT_H_ | 5 #ifndef HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_ |
6 #define HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_ | 6 #define HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/callback.h" |
14 #include "base/optional.h" | 15 #include "base/optional.h" |
| 16 #include "content/public/common/web_preferences.h" |
15 #include "headless/public/headless_export.h" | 17 #include "headless/public/headless_export.h" |
16 #include "headless/public/headless_web_contents.h" | 18 #include "headless/public/headless_web_contents.h" |
17 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
18 #include "net/url_request/url_request_job_factory.h" | 20 #include "net/url_request/url_request_job_factory.h" |
19 | 21 |
20 namespace base { | 22 namespace base { |
21 class FilePath; | 23 class FilePath; |
22 } | 24 } |
23 | 25 |
24 namespace headless { | 26 namespace headless { |
25 class HeadlessBrowserImpl; | 27 class HeadlessBrowserImpl; |
26 class HeadlessBrowserContextOptions; | 28 class HeadlessBrowserContextOptions; |
27 | 29 |
| 30 // Imported into headless namespace for |
| 31 // Builder::SetOverrideWebPreferencesCallback(). |
| 32 using content::WebPreferences; |
| 33 |
28 using ProtocolHandlerMap = std::unordered_map< | 34 using ProtocolHandlerMap = std::unordered_map< |
29 std::string, | 35 std::string, |
30 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>>; | 36 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>>; |
31 | 37 |
32 // Represents an isolated session with a unique cache, cookies, and other | 38 // Represents an isolated session with a unique cache, cookies, and other |
33 // profile/session related data. | 39 // profile/session related data. |
34 // When browser context is deleted, all associated web contents are closed. | 40 // When browser context is deleted, all associated web contents are closed. |
35 class HEADLESS_EXPORT HeadlessBrowserContext { | 41 class HEADLESS_EXPORT HeadlessBrowserContext { |
36 public: | 42 public: |
37 class Builder; | 43 class Builder; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // access to these bindings. If you know what you're doing it may be OK to | 96 // access to these bindings. If you know what you're doing it may be OK to |
91 // turn them back on. E.g. if headless_lib is being used in a testing | 97 // turn them back on. E.g. if headless_lib is being used in a testing |
92 // framework which serves the web content from disk that's likely ok. | 98 // framework which serves the web content from disk that's likely ok. |
93 // | 99 // |
94 // That said, best pratice is to add a ProtocolHandler to serve the | 100 // That said, best pratice is to add a ProtocolHandler to serve the |
95 // webcontent over a custom protocol. That way you can be sure that only the | 101 // webcontent over a custom protocol. That way you can be sure that only the |
96 // things you intend have access to mojo. | 102 // things you intend have access to mojo. |
97 Builder& EnableUnsafeNetworkAccessWithMojoBindings( | 103 Builder& EnableUnsafeNetworkAccessWithMojoBindings( |
98 bool enable_http_and_https_if_mojo_used); | 104 bool enable_http_and_https_if_mojo_used); |
99 | 105 |
| 106 // Set a callback that is invoked to override WebPreferences for RenderViews |
| 107 // created within this HeadlessBrowserContext. Called whenever the |
| 108 // WebPreferences of a RenderView change. Executed on the browser main thread. |
| 109 // |
| 110 // WARNING: We cannot provide any guarantees about the stability of the |
| 111 // exposed WebPreferences API, so use with care. |
| 112 Builder& SetOverrideWebPreferencesCallback( |
| 113 base::Callback<void(WebPreferences*)> callback); |
| 114 |
100 // By default |HeadlessBrowserContext| inherits the following options from | 115 // By default |HeadlessBrowserContext| inherits the following options from |
101 // the browser instance. The methods below can be used to override these | 116 // the browser instance. The methods below can be used to override these |
102 // settings. See HeadlessBrowser::Options for their meaning. | 117 // settings. See HeadlessBrowser::Options for their meaning. |
103 Builder& SetUserAgent(const std::string& user_agent); | 118 Builder& SetUserAgent(const std::string& user_agent); |
104 Builder& SetProxyServer(const net::HostPortPair& proxy_server); | 119 Builder& SetProxyServer(const net::HostPortPair& proxy_server); |
105 Builder& SetHostResolverRules(const std::string& host_resolver_rules); | 120 Builder& SetHostResolverRules(const std::string& host_resolver_rules); |
106 Builder& SetWindowSize(const gfx::Size& window_size); | 121 Builder& SetWindowSize(const gfx::Size& window_size); |
107 Builder& SetUserDataDir(const base::FilePath& user_data_dir); | 122 Builder& SetUserDataDir(const base::FilePath& user_data_dir); |
108 Builder& SetIncognitoMode(bool incognito_mode); | 123 Builder& SetIncognitoMode(bool incognito_mode); |
109 | 124 |
(...skipping 22 matching lines...) Expand all Loading... |
132 | 147 |
133 std::list<MojoBindings> mojo_bindings_; | 148 std::list<MojoBindings> mojo_bindings_; |
134 bool enable_http_and_https_if_mojo_used_; | 149 bool enable_http_and_https_if_mojo_used_; |
135 | 150 |
136 DISALLOW_COPY_AND_ASSIGN(Builder); | 151 DISALLOW_COPY_AND_ASSIGN(Builder); |
137 }; | 152 }; |
138 | 153 |
139 } // namespace headless | 154 } // namespace headless |
140 | 155 |
141 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_ | 156 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_ |
OLD | NEW |