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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 * ***** END LICENSE BLOCK ***** */ | 43 * ***** END LICENSE BLOCK ***** */ |
44 | 44 |
45 #include "net/cookies/canonical_cookie.h" | 45 #include "net/cookies/canonical_cookie.h" |
46 | 46 |
47 #include "base/format_macros.h" | 47 #include "base/format_macros.h" |
48 #include "base/logging.h" | 48 #include "base/logging.h" |
49 #include "base/memory/ptr_util.h" | 49 #include "base/memory/ptr_util.h" |
50 #include "base/metrics/histogram_macros.h" | 50 #include "base/metrics/histogram_macros.h" |
51 #include "base/strings/string_util.h" | 51 #include "base/strings/string_util.h" |
52 #include "base/strings/stringprintf.h" | 52 #include "base/strings/stringprintf.h" |
| 53 #include "net/base/url_util.h" |
53 #include "net/cookies/cookie_util.h" | 54 #include "net/cookies/cookie_util.h" |
54 #include "net/cookies/parsed_cookie.h" | 55 #include "net/cookies/parsed_cookie.h" |
55 #include "url/gurl.h" | 56 #include "url/gurl.h" |
56 #include "url/url_canon.h" | 57 #include "url/url_canon.h" |
| 58 #include "url/url_util.h" |
57 | 59 |
58 using base::Time; | 60 using base::Time; |
59 using base::TimeDelta; | 61 using base::TimeDelta; |
60 | 62 |
61 namespace net { | 63 namespace net { |
62 | 64 |
63 namespace { | 65 namespace { |
64 | 66 |
65 const int kVlogSetCookies = 7; | 67 const int kVlogSetCookies = 7; |
66 | 68 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return nullptr; | 219 return nullptr; |
218 } | 220 } |
219 | 221 |
220 std::string cookie_path = CanonPathWithString( | 222 std::string cookie_path = CanonPathWithString( |
221 url, parsed_cookie.HasPath() ? parsed_cookie.Path() : std::string()); | 223 url, parsed_cookie.HasPath() ? parsed_cookie.Path() : std::string()); |
222 | 224 |
223 Time server_time(creation_time); | 225 Time server_time(creation_time); |
224 if (options.has_server_time()) | 226 if (options.has_server_time()) |
225 server_time = options.server_time(); | 227 server_time = options.server_time(); |
226 | 228 |
| 229 DCHECK(!creation_time.is_null()); |
227 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, | 230 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, |
228 creation_time, | 231 creation_time, |
229 server_time); | 232 server_time); |
230 | 233 |
231 CookiePrefix prefix = CanonicalCookie::GetCookiePrefix(parsed_cookie.Name()); | 234 CookiePrefix prefix = CanonicalCookie::GetCookiePrefix(parsed_cookie.Name()); |
232 bool is_cookie_valid = | 235 bool is_cookie_valid = |
233 CanonicalCookie::IsCookiePrefixValid(prefix, url, parsed_cookie); | 236 CanonicalCookie::IsCookiePrefixValid(prefix, url, parsed_cookie); |
234 CanonicalCookie::RecordCookiePrefixMetrics(prefix, is_cookie_valid); | 237 CanonicalCookie::RecordCookiePrefixMetrics(prefix, is_cookie_valid); |
235 if (!is_cookie_valid) { | 238 if (!is_cookie_valid) { |
236 VLOG(kVlogSetCookies) | 239 VLOG(kVlogSetCookies) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 395 |
393 if (IsSecure() != other.IsSecure()) | 396 if (IsSecure() != other.IsSecure()) |
394 return IsSecure(); | 397 return IsSecure(); |
395 | 398 |
396 if (IsHttpOnly() != other.IsHttpOnly()) | 399 if (IsHttpOnly() != other.IsHttpOnly()) |
397 return IsHttpOnly(); | 400 return IsHttpOnly(); |
398 | 401 |
399 return Priority() < other.Priority(); | 402 return Priority() < other.Priority(); |
400 } | 403 } |
401 | 404 |
| 405 bool CanonicalCookie::IsCanonical() const { |
| 406 if (name_.empty()) |
| 407 return false; |
| 408 |
| 409 if (ParsedCookie::ParseTokenString(name_) != name_ || |
| 410 ParsedCookie::ParseValueString(value_) != value_ || |
| 411 ParsedCookie::ParseValueString(domain_) != domain_ || |
| 412 ParsedCookie::ParseValueString(path_) != path_) { |
| 413 return false; |
| 414 } |
| 415 |
| 416 url::CanonHostInfo ignored; |
| 417 if (!url::HostIsIPAddress(domain_) && |
| 418 CanonicalizeHost(domain_, &ignored).empty()) { |
| 419 return false; |
| 420 } |
| 421 |
| 422 if (path_[0] != '/') |
| 423 return false; |
| 424 |
| 425 return true; |
| 426 } |
| 427 |
| 428 void CanonicalCookie::SetCreationDate(base::Time new_creation_date) { |
| 429 DCHECK(CreationDate().is_null()); |
| 430 creation_date_ = new_creation_date; |
| 431 } |
| 432 |
402 // static | 433 // static |
403 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( | 434 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( |
404 const std::string& name) { | 435 const std::string& name) { |
405 const char kSecurePrefix[] = "__Secure-"; | 436 const char kSecurePrefix[] = "__Secure-"; |
406 const char kHostPrefix[] = "__Host-"; | 437 const char kHostPrefix[] = "__Host-"; |
407 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE)) | 438 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE)) |
408 return CanonicalCookie::COOKIE_PREFIX_SECURE; | 439 return CanonicalCookie::COOKIE_PREFIX_SECURE; |
409 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE)) | 440 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE)) |
410 return CanonicalCookie::COOKIE_PREFIX_HOST; | 441 return CanonicalCookie::COOKIE_PREFIX_HOST; |
411 return CanonicalCookie::COOKIE_PREFIX_NONE; | 442 return CanonicalCookie::COOKIE_PREFIX_NONE; |
(...skipping 30 matching lines...) Expand all Loading... |
442 return true; | 473 return true; |
443 } | 474 } |
444 | 475 |
445 std::string CanonicalCookie::DomainWithoutDot() const { | 476 std::string CanonicalCookie::DomainWithoutDot() const { |
446 if (domain_.empty() || domain_[0] != '.') | 477 if (domain_.empty() || domain_[0] != '.') |
447 return domain_; | 478 return domain_; |
448 return domain_.substr(1); | 479 return domain_.substr(1); |
449 } | 480 } |
450 | 481 |
451 } // namespace net | 482 } // namespace net |
OLD | NEW |