OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "net/proxy/proxy_config.h" | 5 #include "net/proxy/proxy_config.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_tokenizer.h" | 8 #include "base/string_tokenizer.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "net/proxy/proxy_info.h" | 11 #include "net/proxy/proxy_info.h" |
(...skipping 13 matching lines...) Expand all Loading... |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 ProxyConfig::ProxyRules::ProxyRules() | 27 ProxyConfig::ProxyRules::ProxyRules() |
28 : reverse_bypass(false), | 28 : reverse_bypass(false), |
29 type(TYPE_NO_RULES) { | 29 type(TYPE_NO_RULES) { |
30 } | 30 } |
31 | 31 |
32 ProxyConfig::ProxyRules::~ProxyRules() { | 32 ProxyConfig::ProxyRules::~ProxyRules() { |
33 } | 33 } |
34 | 34 |
35 void ProxyConfig::ProxyRules::Apply(const GURL& url, ProxyInfo* result) { | 35 bool ProxyConfig::ProxyRules::Apply(const GURL& url, ProxyInfo* result) const { |
36 if (empty()) { | 36 if (empty()) { |
37 result->UseDirect(); | 37 result->UseDirect(); |
38 return; | 38 return false; |
39 } | 39 } |
40 | 40 |
41 bool bypass_proxy = bypass_rules.Matches(url); | 41 bool bypass_proxy = bypass_rules.Matches(url); |
42 if (reverse_bypass) | 42 if (reverse_bypass) |
43 bypass_proxy = !bypass_proxy; | 43 bypass_proxy = !bypass_proxy; |
44 if (bypass_proxy) { | 44 if (bypass_proxy) { |
45 result->UseDirect(); | 45 result->UseDirect(); |
46 return; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 switch (type) { | 49 switch (type) { |
50 case ProxyRules::TYPE_SINGLE_PROXY: { | 50 case ProxyRules::TYPE_SINGLE_PROXY: { |
51 result->UseProxyServer(single_proxy); | 51 result->UseProxyServer(single_proxy); |
52 return; | 52 return true; |
53 } | 53 } |
54 case ProxyRules::TYPE_PROXY_PER_SCHEME: { | 54 case ProxyRules::TYPE_PROXY_PER_SCHEME: { |
55 const ProxyServer* entry = MapUrlSchemeToProxy(url.scheme()); | 55 const ProxyServer* entry = MapUrlSchemeToProxy(url.scheme()); |
56 if (entry) { | 56 if (entry) { |
57 result->UseProxyServer(*entry); | 57 result->UseProxyServer(*entry); |
| 58 return true; |
58 } else { | 59 } else { |
59 // We failed to find a matching proxy server for the current URL | 60 // We failed to find a matching proxy server for the current URL |
60 // scheme. Default to direct. | 61 // scheme. Default to direct. |
61 result->UseDirect(); | 62 result->UseDirect(); |
| 63 return false; |
62 } | 64 } |
63 return; | |
64 } | 65 } |
65 default: { | 66 default: { |
66 result->UseDirect(); | 67 result->UseDirect(); |
67 NOTREACHED(); | 68 NOTREACHED(); |
68 return; | 69 return false; |
69 } | 70 } |
70 } | 71 } |
71 } | 72 } |
72 | 73 |
73 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { | 74 void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { |
74 // Reset. | 75 // Reset. |
75 type = TYPE_NO_RULES; | 76 type = TYPE_NO_RULES; |
76 single_proxy = ProxyServer(); | 77 single_proxy = ProxyServer(); |
77 proxy_for_http = ProxyServer(); | 78 proxy_for_http = ProxyServer(); |
78 proxy_for_https = ProxyServer(); | 79 proxy_for_https = ProxyServer(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (scheme == "http") | 153 if (scheme == "http") |
153 return &proxy_for_http; | 154 return &proxy_for_http; |
154 if (scheme == "https") | 155 if (scheme == "https") |
155 return &proxy_for_https; | 156 return &proxy_for_https; |
156 if (scheme == "ftp") | 157 if (scheme == "ftp") |
157 return &proxy_for_ftp; | 158 return &proxy_for_ftp; |
158 return NULL; // No mapping for this scheme. | 159 return NULL; // No mapping for this scheme. |
159 } | 160 } |
160 | 161 |
161 ProxyConfig::ProxyConfig() | 162 ProxyConfig::ProxyConfig() |
162 : auto_detect_(false), pac_mandatory_(false), id_(kInvalidConfigID) { | 163 : auto_detect_(false), pac_mandatory_(false), |
| 164 source_(PROXY_CONFIG_SOURCE_UNKNOWN), id_(kInvalidConfigID) { |
163 } | 165 } |
164 | 166 |
165 ProxyConfig::ProxyConfig(const ProxyConfig& config) | 167 ProxyConfig::ProxyConfig(const ProxyConfig& config) |
166 : auto_detect_(config.auto_detect_), | 168 : auto_detect_(config.auto_detect_), |
167 pac_url_(config.pac_url_), | 169 pac_url_(config.pac_url_), |
168 pac_mandatory_(config.pac_mandatory_), | 170 pac_mandatory_(config.pac_mandatory_), |
169 proxy_rules_(config.proxy_rules_), | 171 proxy_rules_(config.proxy_rules_), |
| 172 source_(config.source_), |
170 id_(config.id_) { | 173 id_(config.id_) { |
171 } | 174 } |
172 | 175 |
173 ProxyConfig::~ProxyConfig() { | 176 ProxyConfig::~ProxyConfig() { |
174 } | 177 } |
175 | 178 |
176 ProxyConfig& ProxyConfig::operator=(const ProxyConfig& config) { | 179 ProxyConfig& ProxyConfig::operator=(const ProxyConfig& config) { |
177 auto_detect_ = config.auto_detect_; | 180 auto_detect_ = config.auto_detect_; |
178 pac_url_ = config.pac_url_; | 181 pac_url_ = config.pac_url_; |
179 pac_mandatory_ = config.pac_mandatory_; | 182 pac_mandatory_ = config.pac_mandatory_; |
180 proxy_rules_ = config.proxy_rules_; | 183 proxy_rules_ = config.proxy_rules_; |
| 184 source_ = config.source_; |
181 id_ = config.id_; | 185 id_ = config.id_; |
182 return *this; | 186 return *this; |
183 } | 187 } |
184 | 188 |
185 bool ProxyConfig::Equals(const ProxyConfig& other) const { | 189 bool ProxyConfig::Equals(const ProxyConfig& other) const { |
186 // The two configs can have different IDs. We are just interested in if they | 190 // The two configs can have different IDs and sources. We are just interested |
187 // have the same settings. | 191 // in if they have the same settings. |
188 return auto_detect_ == other.auto_detect_ && | 192 return auto_detect_ == other.auto_detect_ && |
189 pac_url_ == other.pac_url_ && | 193 pac_url_ == other.pac_url_ && |
190 pac_mandatory_ == other.pac_mandatory_ && | 194 pac_mandatory_ == other.pac_mandatory_ && |
191 proxy_rules_.Equals(other.proxy_rules()); | 195 proxy_rules_.Equals(other.proxy_rules()); |
192 } | 196 } |
193 | 197 |
194 bool ProxyConfig::HasAutomaticSettings() const { | 198 bool ProxyConfig::HasAutomaticSettings() const { |
195 return auto_detect_ || has_pac_url(); | 199 return auto_detect_ || has_pac_url(); |
196 } | 200 } |
197 | 201 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 for (ProxyBypassRules::RuleList::const_iterator it = | 246 for (ProxyBypassRules::RuleList::const_iterator it = |
243 bypass.rules().begin(); | 247 bypass.rules().begin(); |
244 it != bypass.rules().end(); ++it) { | 248 it != bypass.rules().end(); ++it) { |
245 list->Append(Value::CreateStringValue((*it)->ToString())); | 249 list->Append(Value::CreateStringValue((*it)->ToString())); |
246 } | 250 } |
247 | 251 |
248 dict->Set("bypass_list", list); | 252 dict->Set("bypass_list", list); |
249 } | 253 } |
250 } | 254 } |
251 | 255 |
| 256 // Output the source. |
| 257 dict->SetString("source", ProxyConfigSourceToString(source_)); |
| 258 |
252 return dict; | 259 return dict; |
253 } | 260 } |
254 | 261 |
255 } // namespace net | 262 } // namespace net |
OLD | NEW |