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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 domain_ = cookie_domain; | 155 domain_ = cookie_domain; |
156 } | 156 } |
157 | 157 |
158 CanonicalCookie::~CanonicalCookie() { | 158 CanonicalCookie::~CanonicalCookie() { |
159 } | 159 } |
160 | 160 |
161 std::string CanonicalCookie::GetCookieSourceFromURL(const GURL& url) { | 161 std::string CanonicalCookie::GetCookieSourceFromURL(const GURL& url) { |
162 if (url.SchemeIsFile()) | 162 if (url.SchemeIsFile()) |
163 return url.spec(); | 163 return url.spec(); |
164 | 164 |
165 url_canon::Replacements<char> replacements; | 165 url::Replacements<char> replacements; |
166 replacements.ClearPort(); | 166 replacements.ClearPort(); |
167 if (url.SchemeIsSecure()) | 167 if (url.SchemeIsSecure()) |
168 replacements.SetScheme("http", url_parse::Component(0, 4)); | 168 replacements.SetScheme("http", url::Component(0, 4)); |
169 | 169 |
170 return url.GetOrigin().ReplaceComponents(replacements).spec(); | 170 return url.GetOrigin().ReplaceComponents(replacements).spec(); |
171 } | 171 } |
172 | 172 |
173 // static | 173 // static |
174 std::string CanonicalCookie::CanonPath(const GURL& url, | 174 std::string CanonicalCookie::CanonPath(const GURL& url, |
175 const ParsedCookie& pc) { | 175 const ParsedCookie& pc) { |
176 std::string path_string; | 176 std::string path_string; |
177 if (pc.HasPath()) | 177 if (pc.HasPath()) |
178 path_string = pc.Path(); | 178 path_string = pc.Path(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 std::string parsed_path = ParsedCookie::ParseValueString(path); | 277 std::string parsed_path = ParsedCookie::ParseValueString(path); |
278 if (parsed_path != path) | 278 if (parsed_path != path) |
279 return NULL; | 279 return NULL; |
280 | 280 |
281 std::string cookie_path = CanonPathWithString(url, parsed_path); | 281 std::string cookie_path = CanonPathWithString(url, parsed_path); |
282 // Expect that the path was either not specified (empty), or is valid. | 282 // Expect that the path was either not specified (empty), or is valid. |
283 if (!parsed_path.empty() && cookie_path != parsed_path) | 283 if (!parsed_path.empty() && cookie_path != parsed_path) |
284 return NULL; | 284 return NULL; |
285 // Canonicalize path again to make sure it escapes characters as needed. | 285 // Canonicalize path again to make sure it escapes characters as needed. |
286 url_parse::Component path_component(0, cookie_path.length()); | 286 url::Component path_component(0, cookie_path.length()); |
287 url_canon::RawCanonOutputT<char> canon_path; | 287 url::RawCanonOutputT<char> canon_path; |
288 url_parse::Component canon_path_component; | 288 url::Component canon_path_component; |
289 url_canon::CanonicalizePath(cookie_path.data(), path_component, | 289 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, |
290 &canon_path, &canon_path_component); | 290 &canon_path_component); |
291 cookie_path = std::string(canon_path.data() + canon_path_component.begin, | 291 cookie_path = std::string(canon_path.data() + canon_path_component.begin, |
292 canon_path_component.len); | 292 canon_path_component.len); |
293 | 293 |
294 return new CanonicalCookie(url, parsed_name, parsed_value, cookie_domain, | 294 return new CanonicalCookie(url, parsed_name, parsed_value, cookie_domain, |
295 cookie_path, creation, expiration, creation, | 295 cookie_path, creation, expiration, creation, |
296 secure, http_only, priority); | 296 secure, http_only, priority); |
297 } | 297 } |
298 | 298 |
299 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { | 299 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { |
300 | 300 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 std::string CanonicalCookie::DebugString() const { | 388 std::string CanonicalCookie::DebugString() const { |
389 return base::StringPrintf( | 389 return base::StringPrintf( |
390 "name: %s value: %s domain: %s path: %s creation: %" | 390 "name: %s value: %s domain: %s path: %s creation: %" |
391 PRId64, | 391 PRId64, |
392 name_.c_str(), value_.c_str(), | 392 name_.c_str(), value_.c_str(), |
393 domain_.c_str(), path_.c_str(), | 393 domain_.c_str(), path_.c_str(), |
394 static_cast<int64>(creation_date_.ToTimeT())); | 394 static_cast<int64>(creation_date_.ToTimeT())); |
395 } | 395 } |
396 | 396 |
397 } // namespace net | 397 } // namespace net |
OLD | NEW |