| 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 void 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; |
| 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->UseDirectWithBypassedProxy(); |
| 46 return; | 46 return; |
| 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; |
| 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()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (scheme == "http") | 152 if (scheme == "http") |
| 153 return &proxy_for_http; | 153 return &proxy_for_http; |
| 154 if (scheme == "https") | 154 if (scheme == "https") |
| 155 return &proxy_for_https; | 155 return &proxy_for_https; |
| 156 if (scheme == "ftp") | 156 if (scheme == "ftp") |
| 157 return &proxy_for_ftp; | 157 return &proxy_for_ftp; |
| 158 return NULL; // No mapping for this scheme. | 158 return NULL; // No mapping for this scheme. |
| 159 } | 159 } |
| 160 | 160 |
| 161 ProxyConfig::ProxyConfig() | 161 ProxyConfig::ProxyConfig() |
| 162 : auto_detect_(false), pac_mandatory_(false), id_(kInvalidConfigID) { | 162 : auto_detect_(false), pac_mandatory_(false), |
| 163 source_(PROXY_CONFIG_SOURCE_UNKNOWN), id_(kInvalidConfigID) { |
| 163 } | 164 } |
| 164 | 165 |
| 165 ProxyConfig::ProxyConfig(const ProxyConfig& config) | 166 ProxyConfig::ProxyConfig(const ProxyConfig& config) |
| 166 : auto_detect_(config.auto_detect_), | 167 : auto_detect_(config.auto_detect_), |
| 167 pac_url_(config.pac_url_), | 168 pac_url_(config.pac_url_), |
| 168 pac_mandatory_(config.pac_mandatory_), | 169 pac_mandatory_(config.pac_mandatory_), |
| 169 proxy_rules_(config.proxy_rules_), | 170 proxy_rules_(config.proxy_rules_), |
| 171 source_(config.source_), |
| 170 id_(config.id_) { | 172 id_(config.id_) { |
| 171 } | 173 } |
| 172 | 174 |
| 173 ProxyConfig::~ProxyConfig() { | 175 ProxyConfig::~ProxyConfig() { |
| 174 } | 176 } |
| 175 | 177 |
| 176 ProxyConfig& ProxyConfig::operator=(const ProxyConfig& config) { | 178 ProxyConfig& ProxyConfig::operator=(const ProxyConfig& config) { |
| 177 auto_detect_ = config.auto_detect_; | 179 auto_detect_ = config.auto_detect_; |
| 178 pac_url_ = config.pac_url_; | 180 pac_url_ = config.pac_url_; |
| 179 pac_mandatory_ = config.pac_mandatory_; | 181 pac_mandatory_ = config.pac_mandatory_; |
| 180 proxy_rules_ = config.proxy_rules_; | 182 proxy_rules_ = config.proxy_rules_; |
| 183 source_ = config.source_; |
| 181 id_ = config.id_; | 184 id_ = config.id_; |
| 182 return *this; | 185 return *this; |
| 183 } | 186 } |
| 184 | 187 |
| 185 bool ProxyConfig::Equals(const ProxyConfig& other) const { | 188 bool ProxyConfig::Equals(const ProxyConfig& other) const { |
| 186 // The two configs can have different IDs. We are just interested in if they | 189 // The two configs can have different IDs and sources. We are just interested |
| 187 // have the same settings. | 190 // in if they have the same settings. |
| 188 return auto_detect_ == other.auto_detect_ && | 191 return auto_detect_ == other.auto_detect_ && |
| 189 pac_url_ == other.pac_url_ && | 192 pac_url_ == other.pac_url_ && |
| 190 pac_mandatory_ == other.pac_mandatory_ && | 193 pac_mandatory_ == other.pac_mandatory_ && |
| 191 proxy_rules_.Equals(other.proxy_rules()); | 194 proxy_rules_.Equals(other.proxy_rules()); |
| 192 } | 195 } |
| 193 | 196 |
| 194 bool ProxyConfig::HasAutomaticSettings() const { | 197 bool ProxyConfig::HasAutomaticSettings() const { |
| 195 return auto_detect_ || has_pac_url(); | 198 return auto_detect_ || has_pac_url(); |
| 196 } | 199 } |
| 197 | 200 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 for (ProxyBypassRules::RuleList::const_iterator it = | 245 for (ProxyBypassRules::RuleList::const_iterator it = |
| 243 bypass.rules().begin(); | 246 bypass.rules().begin(); |
| 244 it != bypass.rules().end(); ++it) { | 247 it != bypass.rules().end(); ++it) { |
| 245 list->Append(Value::CreateStringValue((*it)->ToString())); | 248 list->Append(Value::CreateStringValue((*it)->ToString())); |
| 246 } | 249 } |
| 247 | 250 |
| 248 dict->Set("bypass_list", list); | 251 dict->Set("bypass_list", list); |
| 249 } | 252 } |
| 250 } | 253 } |
| 251 | 254 |
| 255 // Output the source. |
| 256 dict->SetString("source", ProxyConfigSourceToString(source_)); |
| 257 |
| 252 return dict; | 258 return dict; |
| 253 } | 259 } |
| 254 | 260 |
| 255 } // namespace net | 261 } // namespace net |
| OLD | NEW |