OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/signin/ios/browser/account_consistency_service.h" | 5 #include "components/signin/ios/browser/account_consistency_service.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
12 #include "base/macros.h" | 11 #include "base/macros.h" |
13 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
14 #include "components/google/core/browser/google_util.h" | 13 #include "components/google/core/browser/google_util.h" |
15 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
16 #include "components/prefs/scoped_user_pref_update.h" | 15 #include "components/prefs/scoped_user_pref_update.h" |
17 #include "components/signin/core/browser/account_reconcilor.h" | 16 #include "components/signin/core/browser/account_reconcilor.h" |
18 #include "components/signin/core/browser/signin_client.h" | 17 #include "components/signin/core/browser/signin_client.h" |
19 #include "components/signin/core/browser/signin_header_helper.h" | 18 #include "components/signin/core/browser/signin_header_helper.h" |
20 #include "ios/web/public/browser_state.h" | 19 #include "ios/web/public/browser_state.h" |
21 #include "ios/web/public/web_state/web_state_policy_decider.h" | 20 #include "ios/web/public/web_state/web_state_policy_decider.h" |
22 #include "ios/web/public/web_view_creation_util.h" | 21 #include "ios/web/public/web_view_creation_util.h" |
23 #include "net/base/mac/url_conversions.h" | 22 #include "net/base/mac/url_conversions.h" |
24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
26 | 25 |
| 26 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 27 #error "This file requires ARC support." |
| 28 #endif |
| 29 |
27 namespace { | 30 namespace { |
28 | 31 |
29 // Threshold (in hours) used to control whether the CHROME_CONNECTED cookie | 32 // Threshold (in hours) used to control whether the CHROME_CONNECTED cookie |
30 // should be added again on a domain it was previously set. | 33 // should be added again on a domain it was previously set. |
31 const int kHoursThresholdToReAddCookie = 24; | 34 const int kHoursThresholdToReAddCookie = 24; |
32 | 35 |
33 // JavaScript template used to set (or delete) the CHROME_CONNECTED cookie. | 36 // JavaScript template used to set (or delete) the CHROME_CONNECTED cookie. |
34 // It takes 3 arguments: the domain of the cookie, its value and its expiration | 37 // It takes 3 arguments: the domain of the cookie, its value and its expiration |
35 // date. It also clears the legacy X-CHROME-CONNECTED cookie. | 38 // date. It also clears the legacy X-CHROME-CONNECTED cookie. |
36 NSString* const kChromeConnectedCookieTemplate = | 39 NSString* const kChromeConnectedCookieTemplate = |
(...skipping 14 matching lines...) Expand all Loading... |
51 AccountReconcilor* account_reconcilor, | 54 AccountReconcilor* account_reconcilor, |
52 id<ManageAccountsDelegate> delegate); | 55 id<ManageAccountsDelegate> delegate); |
53 | 56 |
54 private: | 57 private: |
55 // web::WebStatePolicyDecider override | 58 // web::WebStatePolicyDecider override |
56 bool ShouldAllowResponse(NSURLResponse* response) override; | 59 bool ShouldAllowResponse(NSURLResponse* response) override; |
57 void WebStateDestroyed() override; | 60 void WebStateDestroyed() override; |
58 | 61 |
59 AccountConsistencyService* account_consistency_service_; // Weak. | 62 AccountConsistencyService* account_consistency_service_; // Weak. |
60 AccountReconcilor* account_reconcilor_; // Weak. | 63 AccountReconcilor* account_reconcilor_; // Weak. |
61 base::WeakNSProtocol<id<ManageAccountsDelegate>> delegate_; | 64 __weak id<ManageAccountsDelegate> delegate_; |
62 }; | 65 }; |
63 } | 66 } |
64 | 67 |
65 AccountConsistencyHandler::AccountConsistencyHandler( | 68 AccountConsistencyHandler::AccountConsistencyHandler( |
66 web::WebState* web_state, | 69 web::WebState* web_state, |
67 AccountConsistencyService* service, | 70 AccountConsistencyService* service, |
68 AccountReconcilor* account_reconcilor, | 71 AccountReconcilor* account_reconcilor, |
69 id<ManageAccountsDelegate> delegate) | 72 id<ManageAccountsDelegate> delegate) |
70 : web::WebStatePolicyDecider(web_state), | 73 : web::WebStatePolicyDecider(web_state), |
71 account_consistency_service_(service), | 74 account_consistency_service_(service), |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 ApplyCookieRequests(); | 386 ApplyCookieRequests(); |
384 } | 387 } |
385 | 388 |
386 WKWebView* AccountConsistencyService::GetWKWebView() { | 389 WKWebView* AccountConsistencyService::GetWKWebView() { |
387 if (!web::BrowserState::GetActiveStateManager(browser_state_)->IsActive()) { | 390 if (!web::BrowserState::GetActiveStateManager(browser_state_)->IsActive()) { |
388 // |browser_state_| is not active, WKWebView linked to this browser state | 391 // |browser_state_| is not active, WKWebView linked to this browser state |
389 // should not exist or be created. | 392 // should not exist or be created. |
390 return nil; | 393 return nil; |
391 } | 394 } |
392 if (!web_view_) { | 395 if (!web_view_) { |
393 web_view_.reset([BuildWKWebView() retain]); | 396 web_view_ = BuildWKWebView(); |
394 navigation_delegate_.reset([[AccountConsistencyNavigationDelegate alloc] | 397 navigation_delegate_ = [[AccountConsistencyNavigationDelegate alloc] |
395 initWithCallback:base::Bind(&AccountConsistencyService:: | 398 initWithCallback:base::Bind(&AccountConsistencyService:: |
396 FinishedApplyingCookieRequest, | 399 FinishedApplyingCookieRequest, |
397 base::Unretained(this), true)]); | 400 base::Unretained(this), true)]; |
398 [web_view_ setNavigationDelegate:navigation_delegate_]; | 401 [web_view_ setNavigationDelegate:navigation_delegate_]; |
399 } | 402 } |
400 return web_view_.get(); | 403 return web_view_; |
401 } | 404 } |
402 | 405 |
403 WKWebView* AccountConsistencyService::BuildWKWebView() { | 406 WKWebView* AccountConsistencyService::BuildWKWebView() { |
404 return web::BuildWKWebView(CGRectZero, browser_state_); | 407 return web::BuildWKWebView(CGRectZero, browser_state_); |
405 } | 408 } |
406 | 409 |
407 void AccountConsistencyService::ResetWKWebView() { | 410 void AccountConsistencyService::ResetWKWebView() { |
408 [web_view_ setNavigationDelegate:nil]; | 411 [web_view_ setNavigationDelegate:nil]; |
409 [web_view_ stopLoading]; | 412 [web_view_ stopLoading]; |
410 web_view_.reset(); | 413 web_view_ = nil; |
411 navigation_delegate_.reset(); | 414 navigation_delegate_ = nil; |
412 applying_cookie_requests_ = false; | 415 applying_cookie_requests_ = false; |
413 } | 416 } |
414 | 417 |
415 void AccountConsistencyService::AddChromeConnectedCookies() { | 418 void AccountConsistencyService::AddChromeConnectedCookies() { |
416 DCHECK(!browser_state_->IsOffTheRecord()); | 419 DCHECK(!browser_state_->IsOffTheRecord()); |
417 // These cookie request are preventive and not a strong signal (unlike | 420 // These cookie request are preventive and not a strong signal (unlike |
418 // navigation to a domain). Don't force update the old cookies in this case. | 421 // navigation to a domain). Don't force update the old cookies in this case. |
419 AddChromeConnectedCookieToDomain("google.com", | 422 AddChromeConnectedCookieToDomain("google.com", |
420 false /* force_update_if_too_old */); | 423 false /* force_update_if_too_old */); |
421 AddChromeConnectedCookieToDomain("youtube.com", | 424 AddChromeConnectedCookieToDomain("youtube.com", |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // |browser_state_| is now active. There might be some pending cookie requests | 476 // |browser_state_| is now active. There might be some pending cookie requests |
474 // to apply. | 477 // to apply. |
475 ApplyCookieRequests(); | 478 ApplyCookieRequests(); |
476 } | 479 } |
477 | 480 |
478 void AccountConsistencyService::OnInactive() { | 481 void AccountConsistencyService::OnInactive() { |
479 // |browser_state_| is now inactive. Stop using |web_view_| and don't create | 482 // |browser_state_| is now inactive. Stop using |web_view_| and don't create |
480 // a new one until it is active. | 483 // a new one until it is active. |
481 ResetWKWebView(); | 484 ResetWKWebView(); |
482 } | 485 } |
OLD | NEW |