Enables compositing support for webview.
[chromium-blink-merge.git] / net / proxy / proxy_config.h
blob29619dff1e36ae3cd4ac02e96365b660b2817ef4
1 // Copyright (c) 2012 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.
5 #ifndef NET_PROXY_PROXY_CONFIG_H_
6 #define NET_PROXY_PROXY_CONFIG_H_
8 #include <string>
10 #include "googleurl/src/gurl.h"
11 #include "net/base/net_export.h"
12 #include "net/proxy/proxy_bypass_rules.h"
13 #include "net/proxy/proxy_config_source.h"
14 #include "net/proxy/proxy_server.h"
16 namespace base {
17 class Value;
20 namespace net {
22 class ProxyInfo;
24 // ProxyConfig describes a user's proxy settings.
26 // There are two categories of proxy settings:
27 // (1) Automatic (indicates the methods to obtain a PAC script)
28 // (2) Manual (simple set of proxy servers per scheme, and bypass patterns)
30 // When both automatic and manual settings are specified, the Automatic ones
31 // take precedence over the manual ones.
33 // For more details see:
34 // http://www.chromium.org/developers/design-documents/proxy-settings-fallback
35 class NET_EXPORT ProxyConfig {
36 public:
37 // ProxyRules describes the "manual" proxy settings.
38 // TODO(eroman): Turn this into a class.
39 struct NET_EXPORT ProxyRules {
40 enum Type {
41 TYPE_NO_RULES,
42 TYPE_SINGLE_PROXY,
43 TYPE_PROXY_PER_SCHEME,
46 // Note that the default of TYPE_NO_RULES results in direct connections
47 // being made when using this ProxyConfig.
48 ProxyRules();
49 ~ProxyRules();
51 bool empty() const {
52 return type == TYPE_NO_RULES;
55 // Sets |result| with the proxy to use for |url| based on the current rules.
56 void Apply(const GURL& url, ProxyInfo* result) const;
58 // Parses the rules from a string, indicating which proxies to use.
60 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>]
62 // If the proxy to use depends on the scheme of the URL, can instead specify
63 // a semicolon separated list of:
65 // <url-scheme>"="<proxy-uri>
67 // For example:
68 // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http://
69 // URLs, and HTTP proxy "foopy2:80" for
70 // ftp:// URLs.
71 // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs.
72 // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all
73 // URLs.
74 void ParseFromString(const std::string& proxy_rules);
76 // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp,
77 // &fallback_proxy}, or NULL if there is no proxy to use.
78 // Should only call this if the type is TYPE_PROXY_PER_SCHEME.
79 const ProxyServer* MapUrlSchemeToProxy(const std::string& url_scheme) const;
81 // Returns true if |*this| describes the same configuration as |other|.
82 bool Equals(const ProxyRules& other) const;
84 // Exceptions for when not to use a proxy.
85 ProxyBypassRules bypass_rules;
87 // Reverse the meaning of |bypass_rules|.
88 bool reverse_bypass;
90 Type type;
92 // Set if |type| is TYPE_SINGLE_PROXY.
93 ProxyServer single_proxy;
95 // Set if |type| is TYPE_PROXY_PER_SCHEME.
96 ProxyServer proxy_for_http;
97 ProxyServer proxy_for_https;
98 ProxyServer proxy_for_ftp;
100 // Used when there isn't a more specific per-scheme proxy server.
101 ProxyServer fallback_proxy;
103 private:
104 // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp}
105 // or NULL if it is a scheme that we don't have a mapping
106 // for. Should only call this if the type is TYPE_PROXY_PER_SCHEME.
107 ProxyServer* MapUrlSchemeToProxyNoFallback(const std::string& scheme);
110 typedef int ID;
112 // Indicates an invalid proxy config.
113 static const ID kInvalidConfigID = 0;
115 ProxyConfig();
116 ProxyConfig(const ProxyConfig& config);
117 ~ProxyConfig();
118 ProxyConfig& operator=(const ProxyConfig& config);
120 // Used to numerically identify this configuration.
121 ID id() const { return id_; }
122 void set_id(ID id) { id_ = id; }
123 bool is_valid() const { return id_ != kInvalidConfigID; }
125 // Returns true if the given config is equivalent to this config. The
126 // comparison ignores differences in |id()| and |source()|.
127 bool Equals(const ProxyConfig& other) const;
129 // Returns true if this config contains any "automatic" settings. See the
130 // class description for what that means.
131 bool HasAutomaticSettings() const;
133 void ClearAutomaticSettings();
135 // Creates a Value dump of this configuration. The caller is responsible for
136 // deleting the returned value.
137 base::Value* ToValue() const;
139 ProxyRules& proxy_rules() {
140 return proxy_rules_;
143 const ProxyRules& proxy_rules() const {
144 return proxy_rules_;
147 void set_pac_url(const GURL& url) {
148 pac_url_ = url;
151 const GURL& pac_url() const {
152 return pac_url_;
155 void set_pac_mandatory(bool enable_pac_mandatory) {
156 pac_mandatory_ = enable_pac_mandatory;
159 bool pac_mandatory() const {
160 return pac_mandatory_;
163 bool has_pac_url() const {
164 return pac_url_.is_valid();
167 void set_auto_detect(bool enable_auto_detect) {
168 auto_detect_ = enable_auto_detect;
171 bool auto_detect() const {
172 return auto_detect_;
175 void set_source(ProxyConfigSource source) {
176 source_ = source;
179 ProxyConfigSource source() const {
180 return source_;
183 // Helpers to construct some common proxy configurations.
185 static ProxyConfig CreateDirect() {
186 return ProxyConfig();
189 static ProxyConfig CreateAutoDetect() {
190 ProxyConfig config;
191 config.set_auto_detect(true);
192 return config;
195 static ProxyConfig CreateFromCustomPacURL(const GURL& pac_url) {
196 ProxyConfig config;
197 config.set_pac_url(pac_url);
198 // By default fall back to direct connection in case PAC script fails.
199 config.set_pac_mandatory(false);
200 return config;
203 private:
204 // True if the proxy configuration should be auto-detected.
205 bool auto_detect_;
207 // If non-empty, indicates the URL of the proxy auto-config file to use.
208 GURL pac_url_;
210 // If true, blocks all traffic in case fetching the pac script from |pac_url_|
211 // fails. Only valid if |pac_url_| is non-empty.
212 bool pac_mandatory_;
214 // Manual proxy settings.
215 ProxyRules proxy_rules_;
217 // Source of proxy settings.
218 ProxyConfigSource source_;
220 ID id_;
223 } // namespace net
227 #endif // NET_PROXY_PROXY_CONFIG_H_