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

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

Issue 2374063002: Headless: expose WebPreferences to embedder, add --hide-scrollbars. (Closed)
Patch Set: Created 4 years, 2 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/browser/headless_content_browser_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/optional.h" 14 #include "base/optional.h"
15 #include "content/public/common/web_preferences.h"
15 #include "headless/public/headless_export.h" 16 #include "headless/public/headless_export.h"
16 #include "headless/public/headless_web_contents.h" 17 #include "headless/public/headless_web_contents.h"
17 #include "net/base/host_port_pair.h" 18 #include "net/base/host_port_pair.h"
18 #include "net/url_request/url_request_job_factory.h" 19 #include "net/url_request/url_request_job_factory.h"
19 20
20 namespace base { 21 namespace base {
21 class FilePath; 22 class FilePath;
22 } 23 }
23 24
24 namespace headless { 25 namespace headless {
25 class HeadlessBrowserImpl; 26 class HeadlessBrowserImpl;
26 class HeadlessBrowserContextOptions; 27 class HeadlessBrowserContextOptions;
27 28
29 // Imported into headless namespace for
30 // Builder::SetOverrideWebPreferencesCallback().
31 using content::WebPreferences;
32
28 using ProtocolHandlerMap = std::unordered_map< 33 using ProtocolHandlerMap = std::unordered_map<
29 std::string, 34 std::string,
30 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>>; 35 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>>;
31 36
32 // Represents an isolated session with a unique cache, cookies, and other 37 // Represents an isolated session with a unique cache, cookies, and other
33 // profile/session related data. 38 // profile/session related data.
34 // When browser context is deleted, all associated web contents are closed. 39 // When browser context is deleted, all associated web contents are closed.
35 class HEADLESS_EXPORT HeadlessBrowserContext { 40 class HEADLESS_EXPORT HeadlessBrowserContext {
36 public: 41 public:
37 class Builder; 42 class Builder;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // access to these bindings. If you know what you're doing it may be OK to 95 // 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 96 // 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. 97 // framework which serves the web content from disk that's likely ok.
93 // 98 //
94 // That said, best pratice is to add a ProtocolHandler to serve the 99 // 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 100 // webcontent over a custom protocol. That way you can be sure that only the
96 // things you intend have access to mojo. 101 // things you intend have access to mojo.
97 Builder& EnableUnsafeNetworkAccessWithMojoBindings( 102 Builder& EnableUnsafeNetworkAccessWithMojoBindings(
98 bool enable_http_and_https_if_mojo_used); 103 bool enable_http_and_https_if_mojo_used);
99 104
105 // Set a callback that is invoked to override WebPreferences for RenderViews
106 // created within this HeadlessBrowserContext.
Sami 2016/09/29 09:38:26 This is called on the browser main thread, right?
Eric Seckler 2016/09/30 09:17:50 It's definitely called multiple times (whenever th
107 //
108 // WARNING: We cannot provide any guarantees about the stability of the
109 // exposed WebPreferences API, so use with care.
110 Builder& SetOverrideWebPreferencesCallback(
111 std::function<void(WebPreferences*)> callback);
Sami 2016/09/29 09:38:26 This should probably be a base::Callback since mos
Eric Seckler 2016/09/30 09:17:50 Done.
112
100 // By default |HeadlessBrowserContext| inherits the following options from 113 // By default |HeadlessBrowserContext| inherits the following options from
101 // the browser instance. The methods below can be used to override these 114 // the browser instance. The methods below can be used to override these
102 // settings. See HeadlessBrowser::Options for their meaning. 115 // settings. See HeadlessBrowser::Options for their meaning.
103 Builder& SetUserAgent(const std::string& user_agent); 116 Builder& SetUserAgent(const std::string& user_agent);
104 Builder& SetProxyServer(const net::HostPortPair& proxy_server); 117 Builder& SetProxyServer(const net::HostPortPair& proxy_server);
105 Builder& SetHostResolverRules(const std::string& host_resolver_rules); 118 Builder& SetHostResolverRules(const std::string& host_resolver_rules);
106 Builder& SetWindowSize(const gfx::Size& window_size); 119 Builder& SetWindowSize(const gfx::Size& window_size);
107 Builder& SetUserDataDir(const base::FilePath& user_data_dir); 120 Builder& SetUserDataDir(const base::FilePath& user_data_dir);
108 Builder& SetIncognitoMode(bool incognito_mode); 121 Builder& SetIncognitoMode(bool incognito_mode);
109 122
(...skipping 22 matching lines...) Expand all
132 145
133 std::list<MojoBindings> mojo_bindings_; 146 std::list<MojoBindings> mojo_bindings_;
134 bool enable_http_and_https_if_mojo_used_; 147 bool enable_http_and_https_if_mojo_used_;
135 148
136 DISALLOW_COPY_AND_ASSIGN(Builder); 149 DISALLOW_COPY_AND_ASSIGN(Builder);
137 }; 150 };
138 151
139 } // namespace headless 152 } // namespace headless
140 153
141 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_ 154 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_CONTEXT_H_
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_content_browser_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698