Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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/base/sdch_manager.h" | 5 #include "net/base/sdch_manager.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 url scheme. | 73 url scheme. |
| 74 */ | 74 */ |
| 75 if (!DomainMatch(target_url, domain_)) | 75 if (!DomainMatch(target_url, domain_)) |
| 76 return false; | 76 return false; |
| 77 if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort())) | 77 if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort())) |
| 78 return false; | 78 return false; |
| 79 if (path_.size() && !PathMatch(target_url.path(), path_)) | 79 if (path_.size() && !PathMatch(target_url.path(), path_)) |
| 80 return false; | 80 return false; |
| 81 if (!SdchManager::secure_scheme_supported() && target_url.SchemeIsSecure()) | 81 if (!SdchManager::secure_scheme_supported() && target_url.SchemeIsSecure()) |
| 82 return false; | 82 return false; |
| 83 if (target_url.SchemeIsSecure() != url_.SchemeIsSecure()) | 83 if (target_url.SchemeIsSecure() != url_.SchemeIsSecure()) |
|
mef
2014/07/30 17:14:58
Is there a problem with advertising a dictionary r
Randy Smith (Not in Mondays)
2014/07/31 14:41:54
It leaks that we got the dictionary. "Problem" is
| |
| 84 return false; | 84 return false; |
| 85 if (base::Time::Now() > expiration_) | 85 if (base::Time::Now() > expiration_) |
| 86 return false; | 86 return false; |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 //------------------------------------------------------------------------------ | 90 //------------------------------------------------------------------------------ |
| 91 // Security functions restricting loads and use of dictionaries. | 91 // Security functions restricting loads and use of dictionaries. |
| 92 | 92 |
| 93 // static | 93 // static |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 } | 213 } |
| 214 | 214 |
| 215 // static | 215 // static |
| 216 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, | 216 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, |
| 217 const std::string& restriction) { | 217 const std::string& restriction) { |
| 218 // TODO(jar): This is not precisely a domain match definition. | 218 // TODO(jar): This is not precisely a domain match definition. |
| 219 return gurl.DomainIs(restriction.data(), restriction.size()); | 219 return gurl.DomainIs(restriction.data(), restriction.size()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 //------------------------------------------------------------------------------ | 222 //------------------------------------------------------------------------------ |
| 223 SdchManager::SdchManager() { | 223 SdchManager::SdchManager() |
| 224 : fetches_count_for_testing_(0) { | |
| 224 DCHECK(CalledOnValidThread()); | 225 DCHECK(CalledOnValidThread()); |
| 225 } | 226 } |
| 226 | 227 |
| 227 SdchManager::~SdchManager() { | 228 SdchManager::~SdchManager() { |
| 228 DCHECK(CalledOnValidThread()); | 229 DCHECK(CalledOnValidThread()); |
| 229 while (!dictionaries_.empty()) { | 230 while (!dictionaries_.empty()) { |
| 230 DictionaryMap::iterator it = dictionaries_.begin(); | 231 DictionaryMap::iterator it = dictionaries_.begin(); |
| 231 dictionaries_.erase(it->first); | 232 dictionaries_.erase(it->first); |
| 232 } | 233 } |
| 233 } | 234 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 244 // is not expected to be called frequently), so we rely on meta-refresh | 245 // is not expected to be called frequently), so we rely on meta-refresh |
| 245 // to handle this case. | 246 // to handle this case. |
| 246 dictionaries_.clear(); | 247 dictionaries_.clear(); |
| 247 } | 248 } |
| 248 | 249 |
| 249 // static | 250 // static |
| 250 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { | 251 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { |
| 251 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); | 252 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { | 255 void SdchManager::set_sdch_fetcher(scoped_ptr<SdchFetcher> fetcher) { |
| 255 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
| 256 fetcher_.reset(fetcher); | 257 fetcher_ = fetcher.Pass(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 // static | 260 // static |
| 260 void SdchManager::EnableSdchSupport(bool enabled) { | 261 void SdchManager::EnableSdchSupport(bool enabled) { |
| 261 g_sdch_enabled_ = enabled; | 262 g_sdch_enabled_ = enabled; |
| 262 } | 263 } |
| 263 | 264 |
| 264 // static | 265 // static |
| 265 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 266 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
| 266 g_secure_scheme_supported_ = enabled; | 267 g_secure_scheme_supported_ = enabled; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 blacklisted_domains_[domain] = count; | 335 blacklisted_domains_[domain] = count; |
| 335 else | 336 else |
| 336 blacklisted_domains_.erase(domain); | 337 blacklisted_domains_.erase(domain); |
| 337 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); | 338 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); |
| 338 return false; | 339 return false; |
| 339 } | 340 } |
| 340 | 341 |
| 341 void SdchManager::FetchDictionary(const GURL& request_url, | 342 void SdchManager::FetchDictionary(const GURL& request_url, |
| 342 const GURL& dictionary_url) { | 343 const GURL& dictionary_url) { |
| 343 DCHECK(CalledOnValidThread()); | 344 DCHECK(CalledOnValidThread()); |
| 344 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) | 345 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) { |
| 346 ++fetches_count_for_testing_; | |
| 345 fetcher_->Schedule(dictionary_url); | 347 fetcher_->Schedule(dictionary_url); |
| 348 } | |
| 346 } | 349 } |
| 347 | 350 |
| 348 bool SdchManager::CanFetchDictionary(const GURL& referring_url, | 351 bool SdchManager::CanFetchDictionary(const GURL& referring_url, |
| 349 const GURL& dictionary_url) const { | 352 const GURL& dictionary_url) const { |
| 350 DCHECK(CalledOnValidThread()); | 353 DCHECK(CalledOnValidThread()); |
| 351 /* The user agent may retrieve a dictionary from the dictionary URL if all of | 354 /* The user agent may retrieve a dictionary from the dictionary URL if all of |
| 352 the following are true: | 355 the following are true: |
| 353 1 The dictionary URL host name matches the referrer URL host name and | 356 1 The dictionary URL host name matches the referrer URL host name and |
| 354 scheme. | 357 scheme. |
| 355 2 The dictionary URL host name domain matches the parent domain of the | 358 2 The dictionary URL host name domain matches the parent domain of the |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 SdchErrorRecovery(LATENCY_TEST_DISALLOWED); | 561 SdchErrorRecovery(LATENCY_TEST_DISALLOWED); |
| 559 allow_latency_experiment_.erase(it); | 562 allow_latency_experiment_.erase(it); |
| 560 } | 563 } |
| 561 | 564 |
| 562 // static | 565 // static |
| 563 void SdchManager::UrlSafeBase64Encode(const std::string& input, | 566 void SdchManager::UrlSafeBase64Encode(const std::string& input, |
| 564 std::string* output) { | 567 std::string* output) { |
| 565 // Since this is only done during a dictionary load, and hashes are only 8 | 568 // Since this is only done during a dictionary load, and hashes are only 8 |
| 566 // characters, we just do the simple fixup, rather than rewriting the encoder. | 569 // characters, we just do the simple fixup, rather than rewriting the encoder. |
| 567 base::Base64Encode(input, output); | 570 base::Base64Encode(input, output); |
| 568 for (size_t i = 0; i < output->size(); ++i) { | 571 std::replace(output->begin(), output->end(), '+', '-'); |
| 569 switch (output->data()[i]) { | 572 std::replace(output->begin(), output->end(), '/', '_'); |
| 570 case '+': | |
| 571 (*output)[i] = '-'; | |
| 572 continue; | |
| 573 case '/': | |
| 574 (*output)[i] = '_'; | |
| 575 continue; | |
| 576 default: | |
| 577 continue; | |
| 578 } | |
| 579 } | |
| 580 } | 573 } |
| 581 | 574 |
| 582 } // namespace net | 575 } // namespace net |
| OLD | NEW |