OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_V8_H_ | |
6 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_V8_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" | |
12 #include "net/proxy/proxy_service.h" | |
13 #include "net/url_request/url_request_context_builder.h" | |
14 | |
15 namespace net { | |
16 | |
17 class HostResolver; | |
18 class NetLog; | |
19 class NetworkDelegate; | |
20 class MojoProxyResolverFactory; | |
21 class URLRequestContext; | |
22 | |
23 // Specialization of URLRequestContextBuilder that can create a ProxyService | |
24 // that uses a V8 ProxyResolver. PAC scripts are run by V8 in process, by | |
25 // default, but a Mojo factory can be passed in for out-of-process resolution. | |
26 // PAC scripts will be fetched using the request context itself. If a | |
27 // PoxyService is set directly via the URLRequestContextBuilder API, it will be | |
28 // used instead of the one this class normally creates. | |
29 class URLRequestContextBuilderV8 : public URLRequestContextBuilder { | |
30 public: | |
31 URLRequestContextBuilderV8(); | |
32 ~URLRequestContextBuilderV8() override; | |
33 | |
34 // If set to false, the URLrequestContextBuilder will create a ProxyService, | |
35 // which won't use V8. Defaults to true. | |
36 void set_use_v8(bool use_v8) { use_v8_ = use_v8; } | |
37 | |
38 // Sets whether quick PAC checks are enabled. Defaults to true. Ignored if | |
39 // use_v8 is false. | |
40 void set_quick_check_enabled(bool quick_check_enabled) { | |
41 quick_check_enabled_ = quick_check_enabled; | |
42 } | |
43 | |
44 // Sets policy for sanitizing URLs before passing them a PAC. Defaults to | |
45 // ProxyService::SanitizeUrlPolicy::SAFE. Ignored if use_v8 is false. | |
46 void set_pac_sanitize_url_policy( | |
47 net::ProxyService::SanitizeUrlPolicy sanitize_url_policy) { | |
48 sanitize_url_policy_ = sanitize_url_policy; | |
49 } | |
50 | |
51 // Overrides default DhcpProxyScriptFetcherFactory. Ignored if use_v8 is | |
52 // false. | |
53 void set_dhcp_fetcher_factory( | |
54 std::unique_ptr<DhcpProxyScriptFetcherFactory> dhcp_fetcher_factory) { | |
55 dhcp_fetcher_factory = std::move(dhcp_fetcher_factory_); | |
56 } | |
57 | |
58 #ifdef ENABLE_NET_MOJO | |
59 // Sets Mojo factory used to create ProxyResolvers. If not set, V8 will be | |
60 // used in process instead of Mojo. Ignored if use_v8 is false. The passed in | |
61 // factory must outlive the URLRequestContext the builder creates. | |
62 void set_mojo_proxy_resolver_factory( | |
63 MojoProxyResolverFactory* mojo_proxy_resolver_factory) { | |
64 mojo_proxy_resolver_factory_ = mojo_proxy_resolver_factory; | |
65 } | |
66 #endif // ENABLE_NET_MOJO | |
67 | |
68 private: | |
69 std::unique_ptr<ProxyService> CreateProxyService( | |
70 std::unique_ptr<ProxyConfigService> proxy_config_service, | |
71 URLRequestContext* url_request_context, | |
72 HostResolver* host_resolver, | |
73 NetworkDelegate* network_delegate, | |
74 NetLog* net_log) override; | |
75 | |
76 bool use_v8_ = true; | |
77 bool quick_check_enabled_ = true; | |
78 net::ProxyService::SanitizeUrlPolicy sanitize_url_policy_ = | |
79 net::ProxyService::SanitizeUrlPolicy::SAFE; | |
80 | |
81 std::unique_ptr<DhcpProxyScriptFetcherFactory> dhcp_fetcher_factory_; | |
82 | |
83 #ifdef ENABLE_NET_MOJO | |
84 MojoProxyResolverFactory* mojo_proxy_resolver_factory_ = nullptr; | |
85 #endif | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilderV8); | |
88 }; | |
89 | |
90 } // namespace net | |
91 | |
92 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_V8_H_ | |
OLD | NEW |