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 // 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 394 |
| 393 if (IsSecure() != other.IsSecure()) | 395 if (IsSecure() != other.IsSecure()) |
| 394 return IsSecure(); | 396 return IsSecure(); |
| 395 | 397 |
| 396 if (IsHttpOnly() != other.IsHttpOnly()) | 398 if (IsHttpOnly() != other.IsHttpOnly()) |
| 397 return IsHttpOnly(); | 399 return IsHttpOnly(); |
| 398 | 400 |
| 399 return Priority() < other.Priority(); | 401 return Priority() < other.Priority(); |
| 400 } | 402 } |
| 401 | 403 |
| 404 bool CanonicalCookie::IsCanonical() const { | |
|
mmenke
2017/05/25 19:49:56
Is there a single method I should be comparing thi
Randy Smith (Not in Mondays)
2017/06/07 23:31:40
I modeled it after SetCookieWithDetails minus the
| |
| 405 if (name_.empty()) | |
|
mmenke
2017/05/25 19:49:56
Don't we support "Set-Cookie: =foo" and "Set-Cooki
mmenke
2017/05/25 21:25:21
Fun table that indicates we support both of these:
Randy Smith (Not in Mondays)
2017/06/07 23:31:40
Nice catch; my bad. This snuck in a couple of CLs
| |
| 406 return false; | |
| 407 | |
| 408 if (ParsedCookie::ParseTokenString(name_) != name_ || | |
| 409 ParsedCookie::ParseValueString(value_) != value_ || | |
| 410 ParsedCookie::ParseValueString(domain_) != domain_ || | |
| 411 ParsedCookie::ParseValueString(path_) != path_) { | |
| 412 return false; | |
| 413 } | |
| 414 | |
| 415 url::CanonHostInfo ignored; | |
| 416 if (!url::HostIsIPAddress(domain_) && | |
| 417 CanonicalizeHost(domain_, &ignored).empty()) { | |
|
mmenke
2017/05/25 19:49:56
What if CanonicalizeHost(domain_) != domain_?
Randy Smith (Not in Mondays)
2017/06/07 23:31:40
Also note that the DCHECK(IsCanonical()) you sugge
Randy Smith (Not in Mondays)
2017/06/07 23:31:40
Oh, tricky. So as noted above I'm copying this lo
| |
| 418 return false; | |
| 419 } | |
| 420 | |
| 421 if (path_[0] != '/') | |
| 422 return false; | |
|
mmenke
2017/05/25 19:49:56
Do we always set path to be non-empty, even when n
Randy Smith (Not in Mondays)
2017/06/07 23:31:40
Yes, at least at a couple of places in the stack--
| |
| 423 | |
| 424 return true; | |
| 425 } | |
| 426 | |
| 402 // static | 427 // static |
| 403 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( | 428 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( |
| 404 const std::string& name) { | 429 const std::string& name) { |
| 405 const char kSecurePrefix[] = "__Secure-"; | 430 const char kSecurePrefix[] = "__Secure-"; |
| 406 const char kHostPrefix[] = "__Host-"; | 431 const char kHostPrefix[] = "__Host-"; |
| 407 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE)) | 432 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE)) |
| 408 return CanonicalCookie::COOKIE_PREFIX_SECURE; | 433 return CanonicalCookie::COOKIE_PREFIX_SECURE; |
| 409 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE)) | 434 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE)) |
| 410 return CanonicalCookie::COOKIE_PREFIX_HOST; | 435 return CanonicalCookie::COOKIE_PREFIX_HOST; |
| 411 return CanonicalCookie::COOKIE_PREFIX_NONE; | 436 return CanonicalCookie::COOKIE_PREFIX_NONE; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 442 return true; | 467 return true; |
| 443 } | 468 } |
| 444 | 469 |
| 445 std::string CanonicalCookie::DomainWithoutDot() const { | 470 std::string CanonicalCookie::DomainWithoutDot() const { |
| 446 if (domain_.empty() || domain_[0] != '.') | 471 if (domain_.empty() || domain_[0] != '.') |
| 447 return domain_; | 472 return domain_; |
| 448 return domain_.substr(1); | 473 return domain_.substr(1); |
| 449 } | 474 } |
| 450 | 475 |
| 451 } // namespace net | 476 } // namespace net |
| OLD | NEW |