| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // The path was supplied in the cookie, we'll take it. | 85 // The path was supplied in the cookie, we'll take it. |
| 86 if (!path_string.empty() && path_string[0] == '/') | 86 if (!path_string.empty() && path_string[0] == '/') |
| 87 return path_string; | 87 return path_string; |
| 88 | 88 |
| 89 // The path was not supplied in the cookie or invalid, we will default | 89 // The path was not supplied in the cookie or invalid, we will default |
| 90 // to the current URL path. | 90 // to the current URL path. |
| 91 // """Defaults to the path of the request URL that generated the | 91 // """Defaults to the path of the request URL that generated the |
| 92 // Set-Cookie response, up to, but not including, the | 92 // Set-Cookie response, up to, but not including, the |
| 93 // right-most /.""" | 93 // right-most /.""" |
| 94 // How would this work for a cookie on /? We will include it then. | 94 // How would this work for a cookie on /? We will include it then. |
| 95 const std::string& url_path = url.path(); | 95 base::StringPiece url_path = url.path(); |
| 96 | 96 |
| 97 size_t idx = url_path.find_last_of('/'); | 97 size_t idx = url_path.find_last_of('/'); |
| 98 | 98 |
| 99 // The cookie path was invalid or a single '/'. | 99 // The cookie path was invalid or a single '/'. |
| 100 if (idx == 0 || idx == std::string::npos) | 100 if (idx == 0 || idx == std::string::npos) |
| 101 return std::string("/"); | 101 return std::string("/"); |
| 102 | 102 |
| 103 // Return up to the rightmost '/'. | 103 // Return up to the rightmost '/'. |
| 104 return url_path.substr(0, idx); | 104 return url_path.as_string().substr(0, idx); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Compares cookies using name, domain and path, so that "equivalent" cookies | 107 // Compares cookies using name, domain and path, so that "equivalent" cookies |
| 108 // (per RFC 2965) are equal to each other. | 108 // (per RFC 2965) are equal to each other. |
| 109 int PartialCookieOrdering(const CanonicalCookie& a, const CanonicalCookie& b) { | 109 int PartialCookieOrdering(const CanonicalCookie& a, const CanonicalCookie& b) { |
| 110 int diff = a.Name().compare(b.Name()); | 110 int diff = a.Name().compare(b.Name()); |
| 111 if (diff != 0) | 111 if (diff != 0) |
| 112 return diff; | 112 return diff; |
| 113 | 113 |
| 114 diff = a.Domain().compare(b.Domain()); | 114 diff = a.Domain().compare(b.Domain()); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 last_access, secure, http_only, same_site, priority)); | 303 last_access, secure, http_only, same_site, priority)); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool CanonicalCookie::IsEquivalentForSecureCookieMatching( | 306 bool CanonicalCookie::IsEquivalentForSecureCookieMatching( |
| 307 const CanonicalCookie& ecc) const { | 307 const CanonicalCookie& ecc) const { |
| 308 return (name_ == ecc.Name() && (ecc.IsDomainMatch(DomainWithoutDot()) || | 308 return (name_ == ecc.Name() && (ecc.IsDomainMatch(DomainWithoutDot()) || |
| 309 IsDomainMatch(ecc.DomainWithoutDot())) && | 309 IsDomainMatch(ecc.DomainWithoutDot())) && |
| 310 ecc.IsOnPath(Path())); | 310 ecc.IsOnPath(Path())); |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { | 313 bool CanonicalCookie::IsOnPath(const base::StringPiece& url_path) const { |
| 314 | |
| 315 // A zero length would be unsafe for our trailing '/' checks, and | 314 // A zero length would be unsafe for our trailing '/' checks, and |
| 316 // would also make no sense for our prefix match. The code that | 315 // would also make no sense for our prefix match. The code that |
| 317 // creates a CanonicalCookie should make sure the path is never zero length, | 316 // creates a CanonicalCookie should make sure the path is never zero length, |
| 318 // but we double check anyway. | 317 // but we double check anyway. |
| 319 if (path_.empty()) | 318 if (path_.empty()) |
| 320 return false; | 319 return false; |
| 321 | 320 |
| 322 // The Mozilla code broke this into three cases, based on if the cookie path | 321 // The Mozilla code broke this into three cases, based on if the cookie path |
| 323 // was longer, the same length, or shorter than the length of the url path. | 322 // was longer, the same length, or shorter than the length of the url path. |
| 324 // I think the approach below is simpler. | 323 // I think the approach below is simpler. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return true; | 522 return true; |
| 524 } | 523 } |
| 525 | 524 |
| 526 std::string CanonicalCookie::DomainWithoutDot() const { | 525 std::string CanonicalCookie::DomainWithoutDot() const { |
| 527 if (domain_.empty() || domain_[0] != '.') | 526 if (domain_.empty() || domain_[0] != '.') |
| 528 return domain_; | 527 return domain_; |
| 529 return domain_.substr(1); | 528 return domain_.substr(1); |
| 530 } | 529 } |
| 531 | 530 |
| 532 } // namespace net | 531 } // namespace net |
| OLD | NEW |