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

Side by Side Diff: ios/net/cookies/cookie_store_ios.mm

Issue 2882063002: Add a SetCanonicalCookie method for CookieMonster. (Closed)
Patch Set: Fix AW cookie store wrapper. Created 3 years, 6 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 | « ios/net/cookies/cookie_store_ios.h ('k') | ios/net/cookies/cookie_store_ios_persistent.h » ('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 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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/ios/ios_util.h" 13 #include "base/ios/ios_util.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/foundation_util.h" 16 #include "base/mac/foundation_util.h"
17 #include "base/mac/scoped_nsobject.h" 17 #include "base/mac/scoped_nsobject.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
22 #include "base/observer_list.h" 22 #include "base/observer_list.h"
23 #include "base/sequenced_task_runner.h" 23 #include "base/sequenced_task_runner.h"
24 #include "base/strings/sys_string_conversions.h" 24 #include "base/strings/sys_string_conversions.h"
25 #include "base/task_runner_util.h" 25 #include "base/task_runner_util.h"
26 #include "base/threading/thread_restrictions.h" 26 #include "base/threading/thread_restrictions.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/time/time.h"
28 #include "ios/net/cookies/cookie_creation_time_manager.h" 29 #include "ios/net/cookies/cookie_creation_time_manager.h"
29 #include "ios/net/cookies/cookie_store_ios_client.h" 30 #include "ios/net/cookies/cookie_store_ios_client.h"
30 #include "ios/net/cookies/system_cookie_util.h" 31 #include "ios/net/cookies/system_cookie_util.h"
31 #include "ios/net/ios_net_features.h" 32 #include "ios/net/ios_net_features.h"
32 #import "net/base/mac/url_conversions.h" 33 #import "net/base/mac/url_conversions.h"
33 #include "net/cookies/cookie_util.h" 34 #include "net/cookies/cookie_util.h"
34 #include "net/cookies/parsed_cookie.h" 35 #include "net/cookies/parsed_cookie.h"
35 #include "url/gurl.h" 36 #include "url/gurl.h"
36 37
37 #if !defined(__has_feature) || !__has_feature(objc_arc) 38 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 398
398 // Canonicalize path again to make sure it escapes characters as needed. 399 // Canonicalize path again to make sure it escapes characters as needed.
399 url::Component path_component(0, cookie_path.length()); 400 url::Component path_component(0, cookie_path.length());
400 url::RawCanonOutputT<char> canon_path; 401 url::RawCanonOutputT<char> canon_path;
401 url::Component canon_path_component; 402 url::Component canon_path_component;
402 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, 403 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path,
403 &canon_path_component); 404 &canon_path_component);
404 cookie_path = std::string(canon_path.data() + canon_path_component.begin, 405 cookie_path = std::string(canon_path.data() + canon_path_component.begin,
405 canon_path_component.len); 406 canon_path_component.len);
406 407
407 // First create a CanonicalCookie, to normalize the arguments,
408 // particularly domain and path, and perform validation.
409 std::unique_ptr<net::CanonicalCookie> canonical_cookie = 408 std::unique_ptr<net::CanonicalCookie> canonical_cookie =
410 base::MakeUnique<net::CanonicalCookie>( 409 base::MakeUnique<net::CanonicalCookie>(
411 name, value, cookie_domain, cookie_path, creation_time, 410 name, value, cookie_domain, cookie_path, creation_time,
412 expiration_time, creation_time, secure, http_only, same_site, 411 expiration_time, creation_time, secure, http_only, same_site,
413 priority); 412 priority);
414 413
415 if (canonical_cookie) { 414 if (canonical_cookie) {
416 NSHTTPCookie* cookie = SystemCookieFromCanonicalCookie(*canonical_cookie); 415 NSHTTPCookie* cookie = SystemCookieFromCanonicalCookie(*canonical_cookie);
417 416
418 if (cookie != nil) { 417 if (cookie != nil) {
419 [system_store_ setCookie:cookie]; 418 [system_store_ setCookie:cookie];
420 creation_time_manager_->SetCreationTime( 419 creation_time_manager_->SetCreationTime(
421 cookie, creation_time_manager_->MakeUniqueCreationTime( 420 cookie, creation_time_manager_->MakeUniqueCreationTime(
422 canonical_cookie->CreationDate())); 421 canonical_cookie->CreationDate()));
423 success = true; 422 success = true;
424 } 423 }
425 } 424 }
426 425
427 if (!callback.is_null()) 426 if (!callback.is_null())
428 callback.Run(success); 427 callback.Run(success);
429 } 428 }
430 429
430 void CookieStoreIOS::SetCanonicalCookieAsync(
431 std::unique_ptr<net::CanonicalCookie> cookie,
432 bool secure_source,
433 bool modify_http_only,
434 const SetCookiesCallback& callback) {
435 DCHECK(cookie->IsCanonical());
436 // The exclude_httponly() option would only be used by a javascript
437 // engine.
438 DCHECK(modify_http_only);
439
440 if (cookie->IsSecure() && !secure_source) {
441 if (!callback.is_null())
442 callback.Run(false);
443 return;
444 }
445
446 NSHTTPCookie* ns_cookie = SystemCookieFromCanonicalCookie(*cookie.get());
447
448 if (ns_cookie != nil) {
449 [system_store_ setCookie:ns_cookie];
450 creation_time_manager_->SetCreationTime(
451 ns_cookie,
452 creation_time_manager_->MakeUniqueCreationTime(
453 cookie->CreationDate().is_null() ? base::Time::Now()
454 : cookie->CreationDate()));
455 if (!callback.is_null())
456 callback.Run(true);
457 return;
458 }
459
460 if (!callback.is_null())
461 callback.Run(false);
462 }
463
431 void CookieStoreIOS::GetCookiesWithOptionsAsync( 464 void CookieStoreIOS::GetCookiesWithOptionsAsync(
432 const GURL& url, 465 const GURL& url,
433 const net::CookieOptions& options, 466 const net::CookieOptions& options,
434 const GetCookiesCallback& callback) { 467 const GetCookiesCallback& callback) {
435 DCHECK(thread_checker_.CalledOnValidThread()); 468 DCHECK(thread_checker_.CalledOnValidThread());
436 469
437 // If cookies are not allowed, they are stashed in the CookieMonster, and 470 // If cookies are not allowed, they are stashed in the CookieMonster, and
438 // should be read from there instead. 471 // should be read from there instead.
439 DCHECK(SystemCookiesAllowed()); 472 DCHECK(SystemCookiesAllowed());
440 // The exclude_httponly() option would only be used by a javascript 473 // The exclude_httponly() option would only be used by a javascript
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 net::CookieList cookie_list; 880 net::CookieList cookie_list;
848 cookie_list.reserve([cookies count]); 881 cookie_list.reserve([cookies count]);
849 for (NSHTTPCookie* cookie in cookies) { 882 for (NSHTTPCookie* cookie in cookies) {
850 base::Time created = creation_time_manager_->GetCreationTime(cookie); 883 base::Time created = creation_time_manager_->GetCreationTime(cookie);
851 cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created)); 884 cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created));
852 } 885 }
853 return cookie_list; 886 return cookie_list;
854 } 887 }
855 888
856 } // namespace net 889 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | ios/net/cookies/cookie_store_ios_persistent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698