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 26 matching lines...) Expand all Loading... |
37 * use your version of this file under the terms of the MPL, indicate your | 37 * use your version of this file under the terms of the MPL, indicate your |
38 * decision by deleting the provisions above and replace them with the notice | 38 * decision by deleting the provisions above and replace them with the notice |
39 * and other provisions required by the GPL or the LGPL. If you do not delete | 39 * and other provisions required by the GPL or the LGPL. If you do not delete |
40 * the provisions above, a recipient may use your version of this file under | 40 * the provisions above, a recipient may use your version of this file under |
41 * the terms of any one of the MPL, the GPL or the LGPL. | 41 * the terms of any one of the MPL, the GPL or the LGPL. |
42 * | 42 * |
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/basictypes.h" | |
48 #include "base/format_macros.h" | 47 #include "base/format_macros.h" |
49 #include "base/logging.h" | 48 #include "base/logging.h" |
50 #include "base/metrics/histogram_macros.h" | 49 #include "base/metrics/histogram_macros.h" |
51 #include "base/strings/stringprintf.h" | 50 #include "base/strings/stringprintf.h" |
52 #include "net/cookies/cookie_util.h" | 51 #include "net/cookies/cookie_util.h" |
53 #include "net/cookies/parsed_cookie.h" | 52 #include "net/cookies/parsed_cookie.h" |
54 #include "url/gurl.h" | 53 #include "url/gurl.h" |
55 #include "url/url_canon.h" | 54 #include "url/url_canon.h" |
56 | 55 |
57 using base::Time; | 56 using base::Time; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 if (pc.HasPath()) | 186 if (pc.HasPath()) |
188 path_string = pc.Path(); | 187 path_string = pc.Path(); |
189 return CanonPathWithString(url, path_string); | 188 return CanonPathWithString(url, path_string); |
190 } | 189 } |
191 | 190 |
192 // static | 191 // static |
193 Time CanonicalCookie::CanonExpiration(const ParsedCookie& pc, | 192 Time CanonicalCookie::CanonExpiration(const ParsedCookie& pc, |
194 const Time& current, | 193 const Time& current, |
195 const Time& server_time) { | 194 const Time& server_time) { |
196 // First, try the Max-Age attribute. | 195 // First, try the Max-Age attribute. |
197 uint64 max_age = 0; | 196 uint64_t max_age = 0; |
198 if (pc.HasMaxAge() && | 197 if (pc.HasMaxAge() && |
199 #ifdef COMPILER_MSVC | 198 #ifdef COMPILER_MSVC |
200 sscanf_s( | 199 sscanf_s( |
201 #else | 200 #else |
202 sscanf( | 201 sscanf( |
203 #endif | 202 #endif |
204 pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) { | 203 pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) { |
205 return current + TimeDelta::FromSeconds(max_age); | 204 return current + TimeDelta::FromSeconds(max_age); |
206 } | 205 } |
207 | 206 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 if (IsFirstPartyOnly() && !options.include_first_party_only() && | 424 if (IsFirstPartyOnly() && !options.include_first_party_only() && |
426 !options.first_party().IsSameOriginWith(url::Origin(url))) { | 425 !options.first_party().IsSameOriginWith(url::Origin(url))) { |
427 return false; | 426 return false; |
428 } | 427 } |
429 | 428 |
430 return true; | 429 return true; |
431 } | 430 } |
432 | 431 |
433 std::string CanonicalCookie::DebugString() const { | 432 std::string CanonicalCookie::DebugString() const { |
434 return base::StringPrintf( | 433 return base::StringPrintf( |
435 "name: %s value: %s domain: %s path: %s creation: %" | 434 "name: %s value: %s domain: %s path: %s creation: %" PRId64, |
436 PRId64, | 435 name_.c_str(), value_.c_str(), domain_.c_str(), path_.c_str(), |
437 name_.c_str(), value_.c_str(), | 436 static_cast<int64_t>(creation_date_.ToTimeT())); |
438 domain_.c_str(), path_.c_str(), | |
439 static_cast<int64>(creation_date_.ToTimeT())); | |
440 } | 437 } |
441 | 438 |
442 bool CanonicalCookie::PartialCompare(const CanonicalCookie& other) const { | 439 bool CanonicalCookie::PartialCompare(const CanonicalCookie& other) const { |
443 return PartialCookieOrdering(*this, other) < 0; | 440 return PartialCookieOrdering(*this, other) < 0; |
444 } | 441 } |
445 | 442 |
446 bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const { | 443 bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const { |
447 // Do the partial comparison first. | 444 // Do the partial comparison first. |
448 int diff = PartialCookieOrdering(*this, other); | 445 int diff = PartialCookieOrdering(*this, other); |
449 if (diff != 0) | 446 if (diff != 0) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 if (prefix == CanonicalCookie::COOKIE_PREFIX_SECURE) | 508 if (prefix == CanonicalCookie::COOKIE_PREFIX_SECURE) |
512 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic(); | 509 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic(); |
513 if (prefix == CanonicalCookie::COOKIE_PREFIX_HOST) { | 510 if (prefix == CanonicalCookie::COOKIE_PREFIX_HOST) { |
514 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic() && | 511 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic() && |
515 !parsed_cookie.HasDomain() && parsed_cookie.Path() == "/"; | 512 !parsed_cookie.HasDomain() && parsed_cookie.Path() == "/"; |
516 } | 513 } |
517 return true; | 514 return true; |
518 } | 515 } |
519 | 516 |
520 } // namespace net | 517 } // namespace net |
OLD | NEW |