| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) | 179 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) |
| 180 return 0; | 180 return 0; |
| 181 return blacklisted_domains_[domain_lower].exponential_count; | 181 return blacklisted_domains_[domain_lower].exponential_count; |
| 182 } | 182 } |
| 183 | 183 |
| 184 SdchProblemCode SdchManager::IsInSupportedDomain(const GURL& url) { | 184 SdchProblemCode SdchManager::IsInSupportedDomain(const GURL& url) { |
| 185 DCHECK(thread_checker_.CalledOnValidThread()); | 185 DCHECK(thread_checker_.CalledOnValidThread()); |
| 186 if (!g_sdch_enabled_ ) | 186 if (!g_sdch_enabled_ ) |
| 187 return SDCH_DISABLED; | 187 return SDCH_DISABLED; |
| 188 | 188 |
| 189 if (!secure_scheme_supported() && url.SchemeIsSecure()) | 189 if (!secure_scheme_supported() && url.SchemeIsCryptographic()) |
| 190 return SDCH_SECURE_SCHEME_NOT_SUPPORTED; | 190 return SDCH_SECURE_SCHEME_NOT_SUPPORTED; |
| 191 | 191 |
| 192 if (blacklisted_domains_.empty()) | 192 if (blacklisted_domains_.empty()) |
| 193 return SDCH_OK; | 193 return SDCH_OK; |
| 194 | 194 |
| 195 DomainBlacklistInfo::iterator it = | 195 DomainBlacklistInfo::iterator it = |
| 196 blacklisted_domains_.find(base::StringToLowerASCII(url.host())); | 196 blacklisted_domains_.find(base::StringToLowerASCII(url.host())); |
| 197 if (blacklisted_domains_.end() == it || it->second.count == 0) | 197 if (blacklisted_domains_.end() == it || it->second.count == 0) |
| 198 return SDCH_OK; | 198 return SDCH_OK; |
| 199 | 199 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 referrer URL host name | 242 referrer URL host name |
| 243 3 The parent domain of the referrer URL host name is not a top level | 243 3 The parent domain of the referrer URL host name is not a top level |
| 244 domain | 244 domain |
| 245 */ | 245 */ |
| 246 // Item (1) above implies item (2). Spec should be updated. | 246 // Item (1) above implies item (2). Spec should be updated. |
| 247 // I take "host name match" to be "is identical to" | 247 // I take "host name match" to be "is identical to" |
| 248 if (referring_url.host() != dictionary_url.host() || | 248 if (referring_url.host() != dictionary_url.host() || |
| 249 referring_url.scheme() != dictionary_url.scheme()) | 249 referring_url.scheme() != dictionary_url.scheme()) |
| 250 return SDCH_DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST; | 250 return SDCH_DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST; |
| 251 | 251 |
| 252 if (!secure_scheme_supported() && referring_url.SchemeIsSecure()) | 252 if (!secure_scheme_supported() && referring_url.SchemeIsCryptographic()) |
| 253 return SDCH_DICTIONARY_SELECTED_FOR_SSL; | 253 return SDCH_DICTIONARY_SELECTED_FOR_SSL; |
| 254 | 254 |
| 255 // TODO(jar): Remove this failsafe conservative hack which is more restrictive | 255 // TODO(jar): Remove this failsafe conservative hack which is more restrictive |
| 256 // than current SDCH spec when needed, and justified by security audit. | 256 // than current SDCH spec when needed, and justified by security audit. |
| 257 if (!referring_url.SchemeIsHTTPOrHTTPS()) | 257 if (!referring_url.SchemeIsHTTPOrHTTPS()) |
| 258 return SDCH_DICTIONARY_SELECTED_FROM_NON_HTTP; | 258 return SDCH_DICTIONARY_SELECTED_FROM_NON_HTTP; |
| 259 | 259 |
| 260 return SDCH_OK; | 260 return SDCH_OK; |
| 261 } | 261 } |
| 262 | 262 |
| 263 scoped_ptr<SdchManager::DictionarySet> | 263 scoped_ptr<SdchManager::DictionarySet> |
| 264 SdchManager::GetDictionarySet(const GURL& target_url) { | 264 SdchManager::GetDictionarySet(const GURL& target_url) { |
| 265 if (IsInSupportedDomain(target_url) != SDCH_OK) | 265 if (IsInSupportedDomain(target_url) != SDCH_OK) |
| 266 return NULL; | 266 return NULL; |
| 267 | 267 |
| 268 int count = 0; | 268 int count = 0; |
| 269 scoped_ptr<SdchManager::DictionarySet> result(new DictionarySet); | 269 scoped_ptr<SdchManager::DictionarySet> result(new DictionarySet); |
| 270 for (const auto& entry: dictionaries_) { | 270 for (const auto& entry: dictionaries_) { |
| 271 if (!secure_scheme_supported() && target_url.SchemeIsSecure()) | 271 if (!secure_scheme_supported() && target_url.SchemeIsCryptographic()) |
| 272 continue; | 272 continue; |
| 273 if (entry.second->data.CanUse(target_url) != SDCH_OK) | 273 if (entry.second->data.CanUse(target_url) != SDCH_OK) |
| 274 continue; | 274 continue; |
| 275 if (entry.second->data.Expired()) | 275 if (entry.second->data.Expired()) |
| 276 continue; | 276 continue; |
| 277 ++count; | 277 ++count; |
| 278 result->AddDictionary(entry.first, entry.second); | 278 result->AddDictionary(entry.first, entry.second); |
| 279 } | 279 } |
| 280 | 280 |
| 281 if (count == 0) | 281 if (count == 0) |
| 282 return NULL; | 282 return NULL; |
| 283 | 283 |
| 284 UMA_HISTOGRAM_COUNTS("Sdch3.Advertisement_Count", count); | 284 UMA_HISTOGRAM_COUNTS("Sdch3.Advertisement_Count", count); |
| 285 | 285 |
| 286 return result.Pass(); | 286 return result.Pass(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 scoped_ptr<SdchManager::DictionarySet> | 289 scoped_ptr<SdchManager::DictionarySet> |
| 290 SdchManager::GetDictionarySetByHash( | 290 SdchManager::GetDictionarySetByHash( |
| 291 const GURL& target_url, | 291 const GURL& target_url, |
| 292 const std::string& server_hash, | 292 const std::string& server_hash, |
| 293 SdchProblemCode* problem_code) { | 293 SdchProblemCode* problem_code) { |
| 294 scoped_ptr<SdchManager::DictionarySet> result; | 294 scoped_ptr<SdchManager::DictionarySet> result; |
| 295 | 295 |
| 296 *problem_code = SDCH_DICTIONARY_HASH_NOT_FOUND; | 296 *problem_code = SDCH_DICTIONARY_HASH_NOT_FOUND; |
| 297 const auto& it = dictionaries_.find(server_hash); | 297 const auto& it = dictionaries_.find(server_hash); |
| 298 if (it == dictionaries_.end()) | 298 if (it == dictionaries_.end()) |
| 299 return result.Pass(); | 299 return result.Pass(); |
| 300 | 300 |
| 301 if (!SdchManager::secure_scheme_supported() && target_url.SchemeIsSecure()) { | 301 if (!SdchManager::secure_scheme_supported() && |
| 302 target_url.SchemeIsCryptographic()) { |
| 302 *problem_code = SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME; | 303 *problem_code = SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME; |
| 303 return result.Pass(); | 304 return result.Pass(); |
| 304 } | 305 } |
| 305 | 306 |
| 306 *problem_code = it->second->data.CanUse(target_url); | 307 *problem_code = it->second->data.CanUse(target_url); |
| 307 if (*problem_code != SDCH_OK) | 308 if (*problem_code != SDCH_OK) |
| 308 return result.Pass(); | 309 return result.Pass(); |
| 309 | 310 |
| 310 result.reset(new DictionarySet); | 311 result.reset(new DictionarySet); |
| 311 result->AddDictionary(it->first, it->second); | 312 result->AddDictionary(it->first, it->second); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 entry_dict->SetInteger("tries", it->second.count); | 517 entry_dict->SetInteger("tries", it->second.count); |
| 517 entry_dict->SetInteger("reason", it->second.reason); | 518 entry_dict->SetInteger("reason", it->second.reason); |
| 518 entry_list->Append(entry_dict); | 519 entry_list->Append(entry_dict); |
| 519 } | 520 } |
| 520 value->Set("blacklisted", entry_list); | 521 value->Set("blacklisted", entry_list); |
| 521 | 522 |
| 522 return value; | 523 return value; |
| 523 } | 524 } |
| 524 | 525 |
| 525 } // namespace net | 526 } // namespace net |
| OLD | NEW |