OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "ios/net/cookies/cookie_store_ios.h" | 5 #include "ios/net/cookies/cookie_store_ios.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 DCHECK(thread_checker_.CalledOnValidThread()); | 367 DCHECK(thread_checker_.CalledOnValidThread()); |
368 // If cookies are not allowed, they are stashed in the CookieMonster, and | 368 // If cookies are not allowed, they are stashed in the CookieMonster, and |
369 // should be written there instead. | 369 // should be written there instead. |
370 DCHECK(SystemCookiesAllowed()); | 370 DCHECK(SystemCookiesAllowed()); |
371 | 371 |
372 bool success = false; | 372 bool success = false; |
373 | 373 |
374 if (creation_time.is_null()) | 374 if (creation_time.is_null()) |
375 creation_time = base::Time::Now(); | 375 creation_time = base::Time::Now(); |
376 | 376 |
377 // Validate consistency of passed arguments. | |
378 if (ParsedCookie::ParseTokenString(name) != name || | |
379 ParsedCookie::ParseValueString(value) != value || | |
380 ParsedCookie::ParseValueString(domain) != domain || | |
381 ParsedCookie::ParseValueString(path) != path) { | |
382 if (!callback.is_null()) | |
383 callback.Run(false); | |
384 return; | |
385 } | |
386 | |
387 // Validate passed arguments against URL. | |
388 std::string cookie_domain; | |
389 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path); | |
390 if ((secure && !url.SchemeIsCryptographic()) || | |
391 !cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain) || | |
392 (!path.empty() && cookie_path != path)) { | |
393 if (!callback.is_null()) | |
394 callback.Run(false); | |
395 return; | |
396 } | |
397 | |
398 // Canonicalize path again to make sure it escapes characters as needed. | |
399 url::Component path_component(0, cookie_path.length()); | |
400 url::RawCanonOutputT<char> canon_path; | |
401 url::Component canon_path_component; | |
402 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, | |
403 &canon_path_component); | |
404 cookie_path = std::string(canon_path.data() + canon_path_component.begin, | |
405 canon_path_component.len); | |
406 | |
377 // First create a CanonicalCookie, to normalize the arguments, | 407 // First create a CanonicalCookie, to normalize the arguments, |
378 // particularly domain and path, and perform validation. | 408 // particularly domain and path, and perform validation. |
379 std::unique_ptr<net::CanonicalCookie> canonical_cookie = | 409 std::unique_ptr<net::CanonicalCookie> canonical_cookie = |
380 net::CanonicalCookie::Create( | 410 net::CanonicalCookie::Create( |
381 url, name, value, domain, path, creation_time, expiration_time, | 411 name, value, cookie_domain, cookie_path, creation_time, |
382 secure, http_only, same_site, priority); | 412 // TODO(rdsmith): Check with ios reviewer about whether to use |
Elly Fong-Jones
2017/05/11 17:24:35
I would use creation_time, which is what the old :
Randy Smith (Not in Mondays)
2017/05/12 17:02:02
Done.
| |
413 // last_access_time here. Wasn't used in original implementation. | |
414 expiration_time, base::Time(), secure, http_only, same_site, | |
415 priority); | |
383 | 416 |
384 if (canonical_cookie) { | 417 if (canonical_cookie) { |
385 NSHTTPCookie* cookie = SystemCookieFromCanonicalCookie(*canonical_cookie); | 418 NSHTTPCookie* cookie = SystemCookieFromCanonicalCookie(*canonical_cookie); |
386 | 419 |
387 if (cookie != nil) { | 420 if (cookie != nil) { |
388 [system_store_ setCookie:cookie]; | 421 [system_store_ setCookie:cookie]; |
389 creation_time_manager_->SetCreationTime( | 422 creation_time_manager_->SetCreationTime( |
390 cookie, creation_time_manager_->MakeUniqueCreationTime( | 423 cookie, creation_time_manager_->MakeUniqueCreationTime( |
391 canonical_cookie->CreationDate())); | 424 canonical_cookie->CreationDate())); |
392 success = true; | 425 success = true; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 net::CookieList cookie_list; | 849 net::CookieList cookie_list; |
817 cookie_list.reserve([cookies count]); | 850 cookie_list.reserve([cookies count]); |
818 for (NSHTTPCookie* cookie in cookies) { | 851 for (NSHTTPCookie* cookie in cookies) { |
819 base::Time created = creation_time_manager_->GetCreationTime(cookie); | 852 base::Time created = creation_time_manager_->GetCreationTime(cookie); |
820 cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created)); | 853 cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created)); |
821 } | 854 } |
822 return cookie_list; | 855 return cookie_list; |
823 } | 856 } |
824 | 857 |
825 } // namespace net | 858 } // namespace net |
OLD | NEW |