Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: net/cookies/canonical_cookie.cc

Issue 2874843002: Shifted creation of unvalidated CanonicalCookies over to a constructor. (Closed)
Patch Set: Merged to top of dependent CL. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cookies/canonical_cookie.h ('k') | net/cookies/canonical_cookie_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 } // namespace 91 } // namespace
92 92
93 CanonicalCookie::CanonicalCookie() 93 CanonicalCookie::CanonicalCookie()
94 : secure_(false), 94 : secure_(false),
95 httponly_(false) { 95 httponly_(false) {
96 } 96 }
97 97
98 CanonicalCookie::CanonicalCookie(const CanonicalCookie& other) = default; 98 CanonicalCookie::CanonicalCookie(const CanonicalCookie& other) = default;
99 99
100 CanonicalCookie::CanonicalCookie(const std::string& name,
101 const std::string& value,
102 const std::string& domain,
103 const std::string& path,
104 const base::Time& creation,
105 const base::Time& expiration,
106 const base::Time& last_access,
107 bool secure,
108 bool httponly,
109 CookieSameSite same_site,
110 CookiePriority priority)
111 : name_(name),
112 value_(value),
113 domain_(domain),
114 path_(path),
115 creation_date_(creation),
116 expiry_date_(expiration),
117 last_access_date_(last_access),
118 secure_(secure),
119 httponly_(httponly),
120 same_site_(same_site),
121 priority_(priority) {}
122
100 CanonicalCookie::~CanonicalCookie() {} 123 CanonicalCookie::~CanonicalCookie() {}
101 124
102 // static 125 // static
103 std::string CanonicalCookie::CanonPathWithString( 126 std::string CanonicalCookie::CanonPathWithString(
104 const GURL& url, 127 const GURL& url,
105 const std::string& path_string) { 128 const std::string& path_string) {
106 // The RFC says the path should be a prefix of the current URL path. 129 // The RFC says the path should be a prefix of the current URL path.
107 // However, Mozilla allows you to set any path for compatibility with 130 // However, Mozilla allows you to set any path for compatibility with
108 // broken websites. We unfortunately will mimic this behavior. We try 131 // broken websites. We unfortunately will mimic this behavior. We try
109 // to be generous and accept cookies with an invalid path attribute, and 132 // to be generous and accept cookies with an invalid path attribute, and
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return nullptr; 238 return nullptr;
216 } 239 }
217 240
218 return base::WrapUnique(new CanonicalCookie( 241 return base::WrapUnique(new CanonicalCookie(
219 parsed_cookie.Name(), parsed_cookie.Value(), cookie_domain, cookie_path, 242 parsed_cookie.Name(), parsed_cookie.Value(), cookie_domain, cookie_path,
220 creation_time, cookie_expires, creation_time, parsed_cookie.IsSecure(), 243 creation_time, cookie_expires, creation_time, parsed_cookie.IsSecure(),
221 parsed_cookie.IsHttpOnly(), parsed_cookie.SameSite(), 244 parsed_cookie.IsHttpOnly(), parsed_cookie.SameSite(),
222 parsed_cookie.Priority())); 245 parsed_cookie.Priority()));
223 } 246 }
224 247
225 // static
226 std::unique_ptr<CanonicalCookie> CanonicalCookie::Create(
227 const std::string& name,
228 const std::string& value,
229 const std::string& domain,
230 const std::string& path,
231 const base::Time& creation,
232 const base::Time& expiration,
233 const base::Time& last_access,
234 bool secure,
235 bool http_only,
236 CookieSameSite same_site,
237 CookiePriority priority) {
238 DCHECK(!name.empty());
239 DCHECK(!path.empty());
240
241 return base::WrapUnique(
242 new CanonicalCookie(name, value, domain, path, creation, expiration,
243 last_access, secure, http_only, same_site, priority));
244 }
245
246 bool CanonicalCookie::IsEquivalentForSecureCookieMatching( 248 bool CanonicalCookie::IsEquivalentForSecureCookieMatching(
247 const CanonicalCookie& ecc) const { 249 const CanonicalCookie& ecc) const {
248 return (name_ == ecc.Name() && (ecc.IsDomainMatch(DomainWithoutDot()) || 250 return (name_ == ecc.Name() && (ecc.IsDomainMatch(DomainWithoutDot()) ||
249 IsDomainMatch(ecc.DomainWithoutDot())) && 251 IsDomainMatch(ecc.DomainWithoutDot())) &&
250 ecc.IsOnPath(Path())); 252 ecc.IsOnPath(Path()));
251 } 253 }
252 254
253 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { 255 bool CanonicalCookie::IsOnPath(const std::string& url_path) const {
254 256
255 // A zero length would be unsafe for our trailing '/' checks, and 257 // A zero length would be unsafe for our trailing '/' checks, and
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 392
391 if (IsSecure() != other.IsSecure()) 393 if (IsSecure() != other.IsSecure())
392 return IsSecure(); 394 return IsSecure();
393 395
394 if (IsHttpOnly() != other.IsHttpOnly()) 396 if (IsHttpOnly() != other.IsHttpOnly())
395 return IsHttpOnly(); 397 return IsHttpOnly();
396 398
397 return Priority() < other.Priority(); 399 return Priority() < other.Priority();
398 } 400 }
399 401
400 CanonicalCookie::CanonicalCookie(const std::string& name,
401 const std::string& value,
402 const std::string& domain,
403 const std::string& path,
404 const base::Time& creation,
405 const base::Time& expiration,
406 const base::Time& last_access,
407 bool secure,
408 bool httponly,
409 CookieSameSite same_site,
410 CookiePriority priority)
411 : name_(name),
412 value_(value),
413 domain_(domain),
414 path_(path),
415 creation_date_(creation),
416 expiry_date_(expiration),
417 last_access_date_(last_access),
418 secure_(secure),
419 httponly_(httponly),
420 same_site_(same_site),
421 priority_(priority) {}
422
423 // static 402 // static
424 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( 403 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix(
425 const std::string& name) { 404 const std::string& name) {
426 const char kSecurePrefix[] = "__Secure-"; 405 const char kSecurePrefix[] = "__Secure-";
427 const char kHostPrefix[] = "__Host-"; 406 const char kHostPrefix[] = "__Host-";
428 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE)) 407 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE))
429 return CanonicalCookie::COOKIE_PREFIX_SECURE; 408 return CanonicalCookie::COOKIE_PREFIX_SECURE;
430 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE)) 409 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE))
431 return CanonicalCookie::COOKIE_PREFIX_HOST; 410 return CanonicalCookie::COOKIE_PREFIX_HOST;
432 return CanonicalCookie::COOKIE_PREFIX_NONE; 411 return CanonicalCookie::COOKIE_PREFIX_NONE;
(...skipping 30 matching lines...) Expand all
463 return true; 442 return true;
464 } 443 }
465 444
466 std::string CanonicalCookie::DomainWithoutDot() const { 445 std::string CanonicalCookie::DomainWithoutDot() const {
467 if (domain_.empty() || domain_[0] != '.') 446 if (domain_.empty() || domain_[0] != '.')
468 return domain_; 447 return domain_;
469 return domain_.substr(1); 448 return domain_.substr(1);
470 } 449 }
471 450
472 } // namespace net 451 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.h ('k') | net/cookies/canonical_cookie_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698