| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 CanonicalCookie::CanonicalCookie() | 107 CanonicalCookie::CanonicalCookie() |
| 108 : secure_(false), | 108 : secure_(false), |
| 109 httponly_(false) { | 109 httponly_(false) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 CanonicalCookie::CanonicalCookie( | 112 CanonicalCookie::CanonicalCookie( |
| 113 const GURL& url, const std::string& name, const std::string& value, | 113 const GURL& url, const std::string& name, const std::string& value, |
| 114 const std::string& domain, const std::string& path, | 114 const std::string& domain, const std::string& path, |
| 115 const base::Time& creation, const base::Time& expiration, | 115 const base::Time& creation, const base::Time& expiration, |
| 116 const base::Time& last_access, bool secure, bool httponly) | 116 const base::Time& last_access, bool secure, bool httponly, |
| 117 CookiePriority priority) |
| 117 : source_(GetCookieSourceFromURL(url)), | 118 : source_(GetCookieSourceFromURL(url)), |
| 118 name_(name), | 119 name_(name), |
| 119 value_(value), | 120 value_(value), |
| 120 domain_(domain), | 121 domain_(domain), |
| 121 path_(path), | 122 path_(path), |
| 122 creation_date_(creation), | 123 creation_date_(creation), |
| 123 expiry_date_(expiration), | 124 expiry_date_(expiration), |
| 124 last_access_date_(last_access), | 125 last_access_date_(last_access), |
| 125 secure_(secure), | 126 secure_(secure), |
| 126 httponly_(httponly) { | 127 httponly_(httponly), |
| 128 priority_(priority) { |
| 127 } | 129 } |
| 128 | 130 |
| 129 CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) | 131 CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) |
| 130 : source_(GetCookieSourceFromURL(url)), | 132 : source_(GetCookieSourceFromURL(url)), |
| 131 name_(pc.Name()), | 133 name_(pc.Name()), |
| 132 value_(pc.Value()), | 134 value_(pc.Value()), |
| 133 path_(CanonPath(url, pc)), | 135 path_(CanonPath(url, pc)), |
| 134 creation_date_(Time::Now()), | 136 creation_date_(Time::Now()), |
| 135 last_access_date_(Time()), | 137 last_access_date_(Time()), |
| 136 secure_(pc.IsSecure()), | 138 secure_(pc.IsSecure()), |
| 137 httponly_(pc.IsHttpOnly()) { | 139 httponly_(pc.IsHttpOnly()), |
| 140 priority_(pc.Priority()) { |
| 138 if (pc.HasExpires()) | 141 if (pc.HasExpires()) |
| 139 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_); | 142 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_); |
| 140 | 143 |
| 141 // Do the best we can with the domain. | 144 // Do the best we can with the domain. |
| 142 std::string cookie_domain; | 145 std::string cookie_domain; |
| 143 std::string domain_string; | 146 std::string domain_string; |
| 144 if (pc.HasDomain()) { | 147 if (pc.HasDomain()) { |
| 145 domain_string = pc.Domain(); | 148 domain_string = pc.Domain(); |
| 146 } | 149 } |
| 147 bool result | 150 bool result |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 server_time = options.server_time(); | 235 server_time = options.server_time(); |
| 233 | 236 |
| 234 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, | 237 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, |
| 235 creation_time, | 238 creation_time, |
| 236 server_time); | 239 server_time); |
| 237 | 240 |
| 238 return new CanonicalCookie(url, parsed_cookie.Name(), parsed_cookie.Value(), | 241 return new CanonicalCookie(url, parsed_cookie.Name(), parsed_cookie.Value(), |
| 239 cookie_domain, cookie_path, creation_time, | 242 cookie_domain, cookie_path, creation_time, |
| 240 cookie_expires, creation_time, | 243 cookie_expires, creation_time, |
| 241 parsed_cookie.IsSecure(), | 244 parsed_cookie.IsSecure(), |
| 242 parsed_cookie.IsHttpOnly()); | 245 parsed_cookie.IsHttpOnly(), |
| 246 parsed_cookie.Priority()); |
| 243 } | 247 } |
| 244 | 248 |
| 245 CanonicalCookie* CanonicalCookie::Create(const GURL& url, | 249 CanonicalCookie* CanonicalCookie::Create(const GURL& url, |
| 246 const std::string& name, | 250 const std::string& name, |
| 247 const std::string& value, | 251 const std::string& value, |
| 248 const std::string& domain, | 252 const std::string& domain, |
| 249 const std::string& path, | 253 const std::string& path, |
| 250 const base::Time& creation, | 254 const base::Time& creation, |
| 251 const base::Time& expiration, | 255 const base::Time& expiration, |
| 252 bool secure, | 256 bool secure, |
| 253 bool http_only) { | 257 bool http_only, |
| 258 CookiePriority priority) { |
| 254 // Expect valid attribute tokens and values, as defined by the ParsedCookie | 259 // Expect valid attribute tokens and values, as defined by the ParsedCookie |
| 255 // logic, otherwise don't create the cookie. | 260 // logic, otherwise don't create the cookie. |
| 256 std::string parsed_name = ParsedCookie::ParseTokenString(name); | 261 std::string parsed_name = ParsedCookie::ParseTokenString(name); |
| 257 if (parsed_name != name) | 262 if (parsed_name != name) |
| 258 return NULL; | 263 return NULL; |
| 259 std::string parsed_value = ParsedCookie::ParseValueString(value); | 264 std::string parsed_value = ParsedCookie::ParseValueString(value); |
| 260 if (parsed_value != value) | 265 if (parsed_value != value) |
| 261 return NULL; | 266 return NULL; |
| 262 | 267 |
| 263 std::string parsed_domain = ParsedCookie::ParseValueString(domain); | 268 std::string parsed_domain = ParsedCookie::ParseValueString(domain); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 281 url_parse::Component path_component(0, cookie_path.length()); | 286 url_parse::Component path_component(0, cookie_path.length()); |
| 282 url_canon::RawCanonOutputT<char> canon_path; | 287 url_canon::RawCanonOutputT<char> canon_path; |
| 283 url_parse::Component canon_path_component; | 288 url_parse::Component canon_path_component; |
| 284 url_canon::CanonicalizePath(cookie_path.data(), path_component, | 289 url_canon::CanonicalizePath(cookie_path.data(), path_component, |
| 285 &canon_path, &canon_path_component); | 290 &canon_path, &canon_path_component); |
| 286 cookie_path = std::string(canon_path.data() + canon_path_component.begin, | 291 cookie_path = std::string(canon_path.data() + canon_path_component.begin, |
| 287 canon_path_component.len); | 292 canon_path_component.len); |
| 288 | 293 |
| 289 return new CanonicalCookie(url, parsed_name, parsed_value, cookie_domain, | 294 return new CanonicalCookie(url, parsed_name, parsed_value, cookie_domain, |
| 290 cookie_path, creation, expiration, creation, | 295 cookie_path, creation, expiration, creation, |
| 291 secure, http_only); | 296 secure, http_only, priority); |
| 292 } | 297 } |
| 293 | 298 |
| 294 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { | 299 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { |
| 295 | 300 |
| 296 // A zero length would be unsafe for our trailing '/' checks, and | 301 // A zero length would be unsafe for our trailing '/' checks, and |
| 297 // would also make no sense for our prefix match. The code that | 302 // would also make no sense for our prefix match. The code that |
| 298 // creates a CanonicalCookie should make sure the path is never zero length, | 303 // creates a CanonicalCookie should make sure the path is never zero length, |
| 299 // but we double check anyway. | 304 // but we double check anyway. |
| 300 if (path_.empty()) | 305 if (path_.empty()) |
| 301 return false; | 306 return false; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 std::string CanonicalCookie::DebugString() const { | 388 std::string CanonicalCookie::DebugString() const { |
| 384 return base::StringPrintf( | 389 return base::StringPrintf( |
| 385 "name: %s value: %s domain: %s path: %s creation: %" | 390 "name: %s value: %s domain: %s path: %s creation: %" |
| 386 PRId64, | 391 PRId64, |
| 387 name_.c_str(), value_.c_str(), | 392 name_.c_str(), value_.c_str(), |
| 388 domain_.c_str(), path_.c_str(), | 393 domain_.c_str(), path_.c_str(), |
| 389 static_cast<int64>(creation_date_.ToTimeT())); | 394 static_cast<int64>(creation_date_.ToTimeT())); |
| 390 } | 395 } |
| 391 | 396 |
| 392 } // namespace net | 397 } // namespace net |
| OLD | NEW |