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 "ios/chrome/browser/ui/authentication/chrome_signin_view_controller.h" | 5 #include "ios/chrome/browser/ui/authentication/chrome_signin_view_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #import <CoreGraphics/CoreGraphics.h> | 11 #import <CoreGraphics/CoreGraphics.h> |
12 #import <QuartzCore/QuartzCore.h> | 12 #import <QuartzCore/QuartzCore.h> |
13 | 13 |
14 #import "base/ios/block_types.h" | 14 #import "base/ios/block_types.h" |
15 #import "base/ios/ios_util.h" | 15 #import "base/ios/ios_util.h" |
16 #import "base/ios/weak_nsobject.h" | |
17 #import "base/mac/bind_objc_block.h" | 16 #import "base/mac/bind_objc_block.h" |
18 #import "base/mac/scoped_nsobject.h" | |
19 #include "base/metrics/user_metrics.h" | 17 #include "base/metrics/user_metrics.h" |
20 #import "base/strings/sys_string_conversions.h" | 18 #import "base/strings/sys_string_conversions.h" |
21 #include "base/timer/elapsed_timer.h" | 19 #include "base/timer/elapsed_timer.h" |
22 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
23 #include "components/signin/core/browser/signin_metrics.h" | 21 #include "components/signin/core/browser/signin_metrics.h" |
24 #include "components/strings/grit/components_strings.h" | 22 #include "components/strings/grit/components_strings.h" |
25 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" | 23 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" |
26 #include "ios/chrome/browser/chrome_url_constants.h" | 24 #include "ios/chrome/browser/chrome_url_constants.h" |
27 #import "ios/chrome/browser/signin/authentication_service.h" | 25 #import "ios/chrome/browser/signin/authentication_service.h" |
28 #import "ios/chrome/browser/signin/authentication_service_factory.h" | 26 #import "ios/chrome/browser/signin/authentication_service_factory.h" |
(...skipping 20 matching lines...) Expand all Loading... |
49 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 47 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
50 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 48 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
51 #import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_m
anager.h" | 49 #import "ios/public/provider/chrome/browser/signin/chrome_identity_interaction_m
anager.h" |
52 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 50 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
53 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato
r/src/MaterialActivityIndicator.h" | 51 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato
r/src/MaterialActivityIndicator.h" |
54 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 52 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
55 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 53 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
56 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 54 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
57 #import "ui/base/l10n/l10n_util.h" | 55 #import "ui/base/l10n/l10n_util.h" |
58 | 56 |
| 57 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 58 #error "This file requires ARC support." |
| 59 #endif |
| 60 |
59 namespace { | 61 namespace { |
60 | 62 |
61 // Default animation duration. | 63 // Default animation duration. |
62 const CGFloat kAnimationDuration = 0.5f; | 64 const CGFloat kAnimationDuration = 0.5f; |
63 | 65 |
64 enum LayoutType { | 66 enum LayoutType { |
65 LAYOUT_REGULAR, | 67 LAYOUT_REGULAR, |
66 LAYOUT_COMPACT, | 68 LAYOUT_COMPACT, |
67 }; | 69 }; |
68 | 70 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 127 } |
126 | 128 |
127 } // namespace | 129 } // namespace |
128 | 130 |
129 @interface ChromeSigninViewController ()< | 131 @interface ChromeSigninViewController ()< |
130 ChromeIdentityInteractionManagerDelegate, | 132 ChromeIdentityInteractionManagerDelegate, |
131 ChromeIdentityServiceObserver, | 133 ChromeIdentityServiceObserver, |
132 SigninAccountSelectorViewControllerDelegate, | 134 SigninAccountSelectorViewControllerDelegate, |
133 SigninConfirmationViewControllerDelegate, | 135 SigninConfirmationViewControllerDelegate, |
134 MDCActivityIndicatorDelegate> | 136 MDCActivityIndicatorDelegate> |
135 @property(nonatomic, retain) ChromeIdentity* selectedIdentity; | 137 @property(nonatomic, strong) ChromeIdentity* selectedIdentity; |
136 | 138 |
137 @end | 139 @end |
138 | 140 |
139 @implementation ChromeSigninViewController { | 141 @implementation ChromeSigninViewController { |
140 ios::ChromeBrowserState* _browserState; // weak | 142 ios::ChromeBrowserState* _browserState; // weak |
141 base::WeakNSProtocol<id<ChromeSigninViewControllerDelegate>> _delegate; | 143 __weak id<ChromeSigninViewControllerDelegate> _delegate; |
142 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; | 144 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; |
143 base::scoped_nsobject<ChromeIdentity> _selectedIdentity; | 145 ChromeIdentity* _selectedIdentity; |
144 | 146 |
145 // Authentication | 147 // Authentication |
146 base::scoped_nsobject<AlertCoordinator> _alertCoordinator; | 148 AlertCoordinator* _alertCoordinator; |
147 base::scoped_nsobject<AuthenticationFlow> _authenticationFlow; | 149 AuthenticationFlow* _authenticationFlow; |
148 BOOL _addedAccount; | 150 BOOL _addedAccount; |
149 BOOL _autoSignIn; | 151 BOOL _autoSignIn; |
150 BOOL _didSignIn; | 152 BOOL _didSignIn; |
151 BOOL _didAcceptSignIn; | 153 BOOL _didAcceptSignIn; |
152 BOOL _didFinishSignIn; | 154 BOOL _didFinishSignIn; |
153 BOOL _isPresentedOnSettings; | 155 BOOL _isPresentedOnSettings; |
154 signin_metrics::AccessPoint _accessPoint; | 156 signin_metrics::AccessPoint _accessPoint; |
155 signin_metrics::PromoAction _promoAction; | 157 signin_metrics::PromoAction _promoAction; |
156 base::scoped_nsobject<ChromeIdentityInteractionManager> _interactionManager; | 158 ChromeIdentityInteractionManager* _interactionManager; |
157 | 159 |
158 // Basic state. | 160 // Basic state. |
159 AuthenticationState _currentState; | 161 AuthenticationState _currentState; |
160 BOOL _ongoingStateChange; | 162 BOOL _ongoingStateChange; |
161 base::scoped_nsobject<MDCActivityIndicator> _activityIndicator; | 163 MDCActivityIndicator* _activityIndicator; |
162 base::scoped_nsobject<MDCButton> _primaryButton; | 164 MDCButton* _primaryButton; |
163 base::scoped_nsobject<MDCButton> _secondaryButton; | 165 MDCButton* _secondaryButton; |
164 base::scoped_nsobject<UIView> _gradientView; | 166 UIView* _gradientView; |
165 base::scoped_nsobject<CAGradientLayer> _gradientLayer; | 167 CAGradientLayer* _gradientLayer; |
166 | 168 |
167 // Identity picker state. | 169 // Identity picker state. |
168 base::scoped_nsobject<SigninAccountSelectorViewController> _accountSelectorVC; | 170 SigninAccountSelectorViewController* _accountSelectorVC; |
169 | 171 |
170 // Signin pending state. | 172 // Signin pending state. |
171 AuthenticationState _activityIndicatorNextState; | 173 AuthenticationState _activityIndicatorNextState; |
172 std::unique_ptr<base::ElapsedTimer> _pendingStateTimer; | 174 std::unique_ptr<base::ElapsedTimer> _pendingStateTimer; |
173 std::unique_ptr<base::Timer> _leavingPendingStateTimer; | 175 std::unique_ptr<base::Timer> _leavingPendingStateTimer; |
174 | 176 |
175 // Identity selected state. | 177 // Identity selected state. |
176 base::scoped_nsobject<SigninConfirmationViewController> _confirmationVC; | 178 SigninConfirmationViewController* _confirmationVC; |
177 BOOL _hasConfirmationScreenReachedBottom; | 179 BOOL _hasConfirmationScreenReachedBottom; |
178 } | 180 } |
179 | 181 |
| 182 @synthesize delegate = _delegate; |
180 @synthesize shouldClearData = _shouldClearData; | 183 @synthesize shouldClearData = _shouldClearData; |
181 | 184 |
182 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 185 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
183 isPresentedOnSettings:(BOOL)isPresentedOnSettings | 186 isPresentedOnSettings:(BOOL)isPresentedOnSettings |
184 accessPoint:(signin_metrics::AccessPoint)accessPoint | 187 accessPoint:(signin_metrics::AccessPoint)accessPoint |
185 promoAction:(signin_metrics::PromoAction)promoAction | 188 promoAction:(signin_metrics::PromoAction)promoAction |
186 signInIdentity:(ChromeIdentity*)identity { | 189 signInIdentity:(ChromeIdentity*)identity { |
187 self = [super init]; | 190 self = [super init]; |
188 if (self) { | 191 if (self) { |
189 _browserState = browserState; | 192 _browserState = browserState; |
(...skipping 17 matching lines...) Expand all Loading... |
207 // after the creation of those objects, so if the objects are not nil, then | 210 // after the creation of those objects, so if the objects are not nil, then |
208 // it is safe to call -[UIControl removeTarget:action:forControlEvents:]. | 211 // it is safe to call -[UIControl removeTarget:action:forControlEvents:]. |
209 // If they are nil, then the call does nothing. | 212 // If they are nil, then the call does nothing. |
210 [_primaryButton removeTarget:self | 213 [_primaryButton removeTarget:self |
211 action:@selector(onPrimaryButtonPressed:) | 214 action:@selector(onPrimaryButtonPressed:) |
212 forControlEvents:UIControlEventTouchDown]; | 215 forControlEvents:UIControlEventTouchDown]; |
213 [_secondaryButton removeTarget:self | 216 [_secondaryButton removeTarget:self |
214 action:@selector(onSecondaryButtonPressed:) | 217 action:@selector(onSecondaryButtonPressed:) |
215 forControlEvents:UIControlEventTouchDown]; | 218 forControlEvents:UIControlEventTouchDown]; |
216 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 219 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
217 [super dealloc]; | |
218 } | 220 } |
219 | 221 |
220 - (void)cancel { | 222 - (void)cancel { |
221 if (_alertCoordinator) { | 223 if (_alertCoordinator) { |
222 DCHECK(!_authenticationFlow && !_interactionManager); | 224 DCHECK(!_authenticationFlow && !_interactionManager); |
223 [_alertCoordinator executeCancelHandler]; | 225 [_alertCoordinator executeCancelHandler]; |
224 [_alertCoordinator stop]; | 226 [_alertCoordinator stop]; |
225 } | 227 } |
226 if (_interactionManager) { | 228 if (_interactionManager) { |
227 DCHECK(!_alertCoordinator && !_authenticationFlow); | 229 DCHECK(!_alertCoordinator && !_authenticationFlow); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 #pragma mark - Properties | 286 #pragma mark - Properties |
285 | 287 |
286 - (ios::ChromeBrowserState*)browserState { | 288 - (ios::ChromeBrowserState*)browserState { |
287 return _browserState; | 289 return _browserState; |
288 } | 290 } |
289 | 291 |
290 - (id<ChromeSigninViewControllerDelegate>)delegate { | 292 - (id<ChromeSigninViewControllerDelegate>)delegate { |
291 return _delegate; | 293 return _delegate; |
292 } | 294 } |
293 | 295 |
294 - (void)setDelegate:(id<ChromeSigninViewControllerDelegate>)delegate { | |
295 _delegate.reset(delegate); | |
296 } | |
297 | |
298 - (UIColor*)backgroundColor { | 296 - (UIColor*)backgroundColor { |
299 return [[MDCPalette greyPalette] tint50]; | 297 return [[MDCPalette greyPalette] tint50]; |
300 } | 298 } |
301 | 299 |
302 - (NSString*)identityPickerTitle { | 300 - (NSString*)identityPickerTitle { |
303 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_TITLE); | 301 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_TITLE); |
304 } | 302 } |
305 | 303 |
306 - (NSString*)acceptSigninButtonTitle { | 304 - (NSString*)acceptSigninButtonTitle { |
307 return l10n_util::GetNSString( | 305 return l10n_util::GetNSString( |
308 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON); | 306 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON); |
309 } | 307 } |
310 | 308 |
311 - (NSString*)skipSigninButtonTitle { | 309 - (NSString*)skipSigninButtonTitle { |
312 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); | 310 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); |
313 } | 311 } |
314 | 312 |
315 - (UIButton*)primaryButton { | 313 - (UIButton*)primaryButton { |
316 return _primaryButton; | 314 return _primaryButton; |
317 } | 315 } |
318 | 316 |
319 - (UIButton*)secondaryButton { | 317 - (UIButton*)secondaryButton { |
320 return _secondaryButton; | 318 return _secondaryButton; |
321 } | 319 } |
322 | 320 |
323 - (void)setSelectedIdentity:(ChromeIdentity*)identity { | 321 - (void)setSelectedIdentity:(ChromeIdentity*)identity { |
324 DCHECK(identity || (IDENTITY_PICKER_STATE == _currentState)); | 322 DCHECK(identity || (IDENTITY_PICKER_STATE == _currentState)); |
325 _selectedIdentity.reset([identity retain]); | 323 _selectedIdentity = identity; |
326 } | 324 } |
327 | 325 |
328 - (ChromeIdentity*)selectedIdentity { | 326 - (ChromeIdentity*)selectedIdentity { |
329 return _selectedIdentity; | 327 return _selectedIdentity; |
330 } | 328 } |
331 | 329 |
332 #pragma mark - Authentication | 330 #pragma mark - Authentication |
333 | 331 |
334 - (void)handleAuthenticationError:(NSError*)error { | 332 - (void)handleAuthenticationError:(NSError*)error { |
335 // Filter out cancel and errors handled internally by ChromeIdentity. | 333 // Filter out cancel and errors handled internally by ChromeIdentity. |
336 if (!ShouldHandleSigninError(error)) { | 334 if (!ShouldHandleSigninError(error)) { |
337 return; | 335 return; |
338 } | 336 } |
339 _alertCoordinator.reset( | 337 _alertCoordinator = ios_internal::ErrorCoordinator(error, nil, self); |
340 [ios_internal::ErrorCoordinator(error, nil, self) retain]); | |
341 [_alertCoordinator start]; | 338 [_alertCoordinator start]; |
342 } | 339 } |
343 | 340 |
344 - (void)signIntoIdentity:(ChromeIdentity*)identity { | 341 - (void)signIntoIdentity:(ChromeIdentity*)identity { |
345 [_delegate willStartSignIn:self]; | 342 [_delegate willStartSignIn:self]; |
346 DCHECK(!_authenticationFlow); | 343 DCHECK(!_authenticationFlow); |
347 _authenticationFlow.reset([[AuthenticationFlow alloc] | 344 _authenticationFlow = |
348 initWithBrowserState:_browserState | 345 [[AuthenticationFlow alloc] initWithBrowserState:_browserState |
349 identity:identity | 346 identity:identity |
350 shouldClearData:_shouldClearData | 347 shouldClearData:_shouldClearData |
351 postSignInAction:POST_SIGNIN_ACTION_NONE | 348 postSignInAction:POST_SIGNIN_ACTION_NONE |
352 presentingViewController:self]); | 349 presentingViewController:self]; |
353 base::WeakNSObject<ChromeSigninViewController> weakSelf(self); | 350 __weak ChromeSigninViewController* weakSelf = self; |
354 [_authenticationFlow startSignInWithCompletion:^(BOOL success) { | 351 [_authenticationFlow startSignInWithCompletion:^(BOOL success) { |
355 [weakSelf onAccountSigninCompletion:success]; | 352 [weakSelf onAccountSigninCompletion:success]; |
356 }]; | 353 }]; |
357 } | 354 } |
358 | 355 |
359 - (void)openAuthenticationDialogAddIdentity { | 356 - (void)openAuthenticationDialogAddIdentity { |
360 DCHECK(!_interactionManager); | 357 DCHECK(!_interactionManager); |
361 _interactionManager = | 358 _interactionManager = |
362 ios::GetChromeBrowserProvider() | 359 ios::GetChromeBrowserProvider() |
363 ->GetChromeIdentityService() | 360 ->GetChromeIdentityService() |
364 ->NewChromeIdentityInteractionManager(_browserState, self); | 361 ->NewChromeIdentityInteractionManager(_browserState, self); |
365 base::WeakNSObject<ChromeSigninViewController> weakSelf(self); | 362 __weak ChromeSigninViewController* weakSelf = self; |
366 SigninCompletionCallback completion = | 363 SigninCompletionCallback completion = |
367 ^(ChromeIdentity* identity, NSError* error) { | 364 ^(ChromeIdentity* identity, NSError* error) { |
368 base::scoped_nsobject<ChromeSigninViewController> strongSelf( | 365 ChromeSigninViewController* strongSelf = weakSelf; |
369 [weakSelf retain]); | 366 if (!strongSelf || !strongSelf->_interactionManager) |
370 if (!strongSelf || !strongSelf.get()->_interactionManager) | |
371 return; | 367 return; |
372 // The ChromeIdentityInteractionManager is not used anymore at this | 368 // The ChromeIdentityInteractionManager is not used anymore at this |
373 // point. | 369 // point. |
374 strongSelf.get()->_interactionManager.reset(); | 370 strongSelf->_interactionManager = nil; |
375 | 371 |
376 if (error) { | 372 if (error) { |
377 [strongSelf handleAuthenticationError:error]; | 373 [strongSelf handleAuthenticationError:error]; |
378 return; | 374 return; |
379 } | 375 } |
380 strongSelf.get()->_addedAccount = YES; | 376 strongSelf->_addedAccount = YES; |
381 [strongSelf onIdentityListChanged]; | 377 [strongSelf onIdentityListChanged]; |
382 [strongSelf setSelectedIdentity:identity]; | 378 [strongSelf setSelectedIdentity:identity]; |
383 [strongSelf changeToState:SIGNIN_PENDING_STATE]; | 379 [strongSelf changeToState:SIGNIN_PENDING_STATE]; |
384 }; | 380 }; |
385 [_delegate willStartAddAccount:self]; | 381 [_delegate willStartAddAccount:self]; |
386 [_interactionManager addAccountWithCompletion:completion]; | 382 [_interactionManager addAccountWithCompletion:completion]; |
387 } | 383 } |
388 | 384 |
389 - (void)onAccountSigninCompletion:(BOOL)success { | 385 - (void)onAccountSigninCompletion:(BOOL)success { |
390 _authenticationFlow.reset(); | 386 _authenticationFlow = nil; |
391 if (success) { | 387 if (success) { |
392 DCHECK(!_didSignIn); | 388 DCHECK(!_didSignIn); |
393 _didSignIn = YES; | 389 _didSignIn = YES; |
394 [_delegate didSignIn:self]; | 390 [_delegate didSignIn:self]; |
395 [self changeToState:IDENTITY_SELECTED_STATE]; | 391 [self changeToState:IDENTITY_SELECTED_STATE]; |
396 } else { | 392 } else { |
397 [self changeToState:IDENTITY_PICKER_STATE]; | 393 [self changeToState:IDENTITY_PICKER_STATE]; |
398 } | 394 } |
399 } | 395 } |
400 | 396 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; | 482 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; |
487 [_primaryButton setImage:nil forState:UIControlStateNormal]; | 483 [_primaryButton setImage:nil forState:UIControlStateNormal]; |
488 [self.view setNeedsLayout]; | 484 [self.view setNeedsLayout]; |
489 } | 485 } |
490 | 486 |
491 - (void)enterIdentityPickerState { | 487 - (void)enterIdentityPickerState { |
492 // Reset the selected identity. | 488 // Reset the selected identity. |
493 [self setSelectedIdentity:nil]; | 489 [self setSelectedIdentity:nil]; |
494 | 490 |
495 // Add the account selector view controller. | 491 // Add the account selector view controller. |
496 _accountSelectorVC.reset([[SigninAccountSelectorViewController alloc] init]); | 492 _accountSelectorVC = [[SigninAccountSelectorViewController alloc] init]; |
497 _accountSelectorVC.get().delegate = self; | 493 _accountSelectorVC.delegate = self; |
498 [_accountSelectorVC willMoveToParentViewController:self]; | 494 [_accountSelectorVC willMoveToParentViewController:self]; |
499 [self addChildViewController:_accountSelectorVC]; | 495 [self addChildViewController:_accountSelectorVC]; |
500 _accountSelectorVC.get().view.frame = self.view.bounds; | 496 _accountSelectorVC.view.frame = self.view.bounds; |
501 [self.view insertSubview:_accountSelectorVC.get().view | 497 [self.view insertSubview:_accountSelectorVC.view belowSubview:_primaryButton]; |
502 belowSubview:_primaryButton]; | |
503 [_accountSelectorVC didMoveToParentViewController:self]; | 498 [_accountSelectorVC didMoveToParentViewController:self]; |
504 | 499 |
505 // Update the button title. | 500 // Update the button title. |
506 [self updatePrimaryButtonTitle]; | 501 [self updatePrimaryButtonTitle]; |
507 [_secondaryButton setTitle:self.skipSigninButtonTitle | 502 [_secondaryButton setTitle:self.skipSigninButtonTitle |
508 forState:UIControlStateNormal]; | 503 forState:UIControlStateNormal]; |
509 [self.view setNeedsLayout]; | 504 [self.view setNeedsLayout]; |
510 | 505 |
511 HideButton(_primaryButton); | 506 HideButton(_primaryButton); |
512 HideButton(_secondaryButton); | 507 HideButton(_secondaryButton); |
(...skipping 14 matching lines...) Expand all Loading... |
527 - (void)leaveIdentityPickerState:(AuthenticationState)nextState { | 522 - (void)leaveIdentityPickerState:(AuthenticationState)nextState { |
528 [UIView animateWithDuration:kAnimationDuration | 523 [UIView animateWithDuration:kAnimationDuration |
529 animations:^{ | 524 animations:^{ |
530 HideButton(_primaryButton); | 525 HideButton(_primaryButton); |
531 HideButton(_secondaryButton); | 526 HideButton(_secondaryButton); |
532 } | 527 } |
533 completion:^(BOOL finished) { | 528 completion:^(BOOL finished) { |
534 [_accountSelectorVC willMoveToParentViewController:nil]; | 529 [_accountSelectorVC willMoveToParentViewController:nil]; |
535 [[_accountSelectorVC view] removeFromSuperview]; | 530 [[_accountSelectorVC view] removeFromSuperview]; |
536 [_accountSelectorVC removeFromParentViewController]; | 531 [_accountSelectorVC removeFromParentViewController]; |
537 _accountSelectorVC.reset(); | 532 _accountSelectorVC = nil; |
538 [self enterState:nextState]; | 533 [self enterState:nextState]; |
539 }]; | 534 }]; |
540 } | 535 } |
541 | 536 |
542 #pragma mark - SigninPendingState | 537 #pragma mark - SigninPendingState |
543 | 538 |
544 - (void)enterSigninPendingState { | 539 - (void)enterSigninPendingState { |
545 [_secondaryButton setTitle:l10n_util::GetNSString(IDS_CANCEL) | 540 [_secondaryButton setTitle:l10n_util::GetNSString(IDS_CANCEL) |
546 forState:UIControlStateNormal]; | 541 forState:UIControlStateNormal]; |
547 [self.view setNeedsLayout]; | 542 [self.view setNeedsLayout]; |
(...skipping 17 matching lines...) Expand all Loading... |
565 | 560 |
566 - (void)leaveSigninPendingState:(AuthenticationState)nextState { | 561 - (void)leaveSigninPendingState:(AuthenticationState)nextState { |
567 if (!_pendingStateTimer) { | 562 if (!_pendingStateTimer) { |
568 // The controller is already leaving the signin pending state, simply update | 563 // The controller is already leaving the signin pending state, simply update |
569 // the new state to take into account the last request only. | 564 // the new state to take into account the last request only. |
570 _activityIndicatorNextState = nextState; | 565 _activityIndicatorNextState = nextState; |
571 return; | 566 return; |
572 } | 567 } |
573 | 568 |
574 _activityIndicatorNextState = nextState; | 569 _activityIndicatorNextState = nextState; |
575 _activityIndicator.get().delegate = self; | 570 _activityIndicator.delegate = self; |
576 | 571 |
577 base::TimeDelta remainingTime = | 572 base::TimeDelta remainingTime = |
578 base::TimeDelta::FromMilliseconds(kMinimunPendingStateDurationMs) - | 573 base::TimeDelta::FromMilliseconds(kMinimunPendingStateDurationMs) - |
579 _pendingStateTimer->Elapsed(); | 574 _pendingStateTimer->Elapsed(); |
580 _pendingStateTimer.reset(); | 575 _pendingStateTimer.reset(); |
581 | 576 |
582 if (remainingTime.InMilliseconds() < 0) { | 577 if (remainingTime.InMilliseconds() < 0) { |
583 [_activityIndicator stopAnimating]; | 578 [_activityIndicator stopAnimating]; |
584 } else { | 579 } else { |
585 // If the signin pending state is too fast, the screen will appear to | 580 // If the signin pending state is too fast, the screen will appear to |
586 // flicker. Make sure to animate for at least | 581 // flicker. Make sure to animate for at least |
587 // |kMinimunPendingStateDurationMs| milliseconds. | 582 // |kMinimunPendingStateDurationMs| milliseconds. |
588 base::WeakNSObject<ChromeSigninViewController> weakSelf(self); | 583 __weak ChromeSigninViewController* weakSelf = self; |
589 ProceduralBlock completionBlock = ^{ | 584 ProceduralBlock completionBlock = ^{ |
590 base::scoped_nsobject<ChromeSigninViewController> strongSelf( | 585 ChromeSigninViewController* strongSelf = weakSelf; |
591 [weakSelf retain]); | |
592 if (!strongSelf) | 586 if (!strongSelf) |
593 return; | 587 return; |
594 [strongSelf.get()->_activityIndicator stopAnimating]; | 588 [strongSelf->_activityIndicator stopAnimating]; |
595 strongSelf.get()->_leavingPendingStateTimer.reset(); | 589 strongSelf->_leavingPendingStateTimer.reset(); |
596 }; | 590 }; |
597 _leavingPendingStateTimer.reset(new base::Timer(false, false)); | 591 _leavingPendingStateTimer.reset(new base::Timer(false, false)); |
598 _leavingPendingStateTimer->Start(FROM_HERE, remainingTime, | 592 _leavingPendingStateTimer->Start(FROM_HERE, remainingTime, |
599 base::BindBlock(completionBlock)); | 593 base::BindBlockArc(completionBlock)); |
600 } | 594 } |
601 } | 595 } |
602 | 596 |
603 #pragma mark - IdentitySelectedState | 597 #pragma mark - IdentitySelectedState |
604 | 598 |
605 - (void)enterIdentitySelectedState { | 599 - (void)enterIdentitySelectedState { |
606 _confirmationVC.reset([[SigninConfirmationViewController alloc] | 600 _confirmationVC = [[SigninConfirmationViewController alloc] |
607 initWithIdentity:self.selectedIdentity]); | 601 initWithIdentity:self.selectedIdentity]; |
608 _confirmationVC.get().delegate = self; | 602 _confirmationVC.delegate = self; |
609 | 603 |
610 _hasConfirmationScreenReachedBottom = NO; | 604 _hasConfirmationScreenReachedBottom = NO; |
611 [_confirmationVC willMoveToParentViewController:self]; | 605 [_confirmationVC willMoveToParentViewController:self]; |
612 [self addChildViewController:_confirmationVC]; | 606 [self addChildViewController:_confirmationVC]; |
613 _confirmationVC.get().view.frame = self.view.bounds; | 607 _confirmationVC.view.frame = self.view.bounds; |
614 [self.view insertSubview:_confirmationVC.get().view | 608 [self.view insertSubview:_confirmationVC.view belowSubview:_primaryButton]; |
615 belowSubview:_primaryButton]; | |
616 [_confirmationVC didMoveToParentViewController:self]; | 609 [_confirmationVC didMoveToParentViewController:self]; |
617 | 610 |
618 [self setSecondaryButtonStyling:_primaryButton]; | 611 [self setSecondaryButtonStyling:_primaryButton]; |
619 NSString* primaryButtonTitle = l10n_util::GetNSString( | 612 NSString* primaryButtonTitle = l10n_util::GetNSString( |
620 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SCROLL_BUTTON); | 613 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SCROLL_BUTTON); |
621 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; | 614 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; |
622 [_primaryButton setImage:[UIImage imageNamed:@"signin_confirmation_more"] | 615 [_primaryButton setImage:[UIImage imageNamed:@"signin_confirmation_more"] |
623 forState:UIControlStateNormal]; | 616 forState:UIControlStateNormal]; |
624 NSString* secondaryButtonTitle = l10n_util::GetNSString( | 617 NSString* secondaryButtonTitle = l10n_util::GetNSString( |
625 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); | 618 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); |
(...skipping 18 matching lines...) Expand all Loading... |
644 if (!isSelectedIdentityValid) { | 637 if (!isSelectedIdentityValid) { |
645 [self changeToState:IDENTITY_PICKER_STATE]; | 638 [self changeToState:IDENTITY_PICKER_STATE]; |
646 return; | 639 return; |
647 } | 640 } |
648 } | 641 } |
649 | 642 |
650 - (void)leaveIdentitySelectedState:(AuthenticationState)nextState { | 643 - (void)leaveIdentitySelectedState:(AuthenticationState)nextState { |
651 [_confirmationVC willMoveToParentViewController:nil]; | 644 [_confirmationVC willMoveToParentViewController:nil]; |
652 [[_confirmationVC view] removeFromSuperview]; | 645 [[_confirmationVC view] removeFromSuperview]; |
653 [_confirmationVC removeFromParentViewController]; | 646 [_confirmationVC removeFromParentViewController]; |
654 _confirmationVC.reset(); | 647 _confirmationVC = nil; |
655 [self setPrimaryButtonStyling:_primaryButton]; | 648 [self setPrimaryButtonStyling:_primaryButton]; |
656 HideButton(_primaryButton); | 649 HideButton(_primaryButton); |
657 HideButton(_secondaryButton); | 650 HideButton(_secondaryButton); |
658 [self undoSignIn]; | 651 [self undoSignIn]; |
659 [self enterState:nextState]; | 652 [self enterState:nextState]; |
660 } | 653 } |
661 | 654 |
662 #pragma mark - UIViewController | 655 #pragma mark - UIViewController |
663 | 656 |
664 - (void)viewDidLoad { | 657 - (void)viewDidLoad { |
665 [super viewDidLoad]; | 658 [super viewDidLoad]; |
666 self.view.backgroundColor = self.backgroundColor; | 659 self.view.backgroundColor = self.backgroundColor; |
667 | 660 |
668 _primaryButton.reset([[MDCFlatButton alloc] init]); | 661 _primaryButton = [[MDCFlatButton alloc] init]; |
669 [self setPrimaryButtonStyling:_primaryButton]; | 662 [self setPrimaryButtonStyling:_primaryButton]; |
670 [_primaryButton addTarget:self | 663 [_primaryButton addTarget:self |
671 action:@selector(onPrimaryButtonPressed:) | 664 action:@selector(onPrimaryButtonPressed:) |
672 forControlEvents:UIControlEventTouchUpInside]; | 665 forControlEvents:UIControlEventTouchUpInside]; |
673 HideButton(_primaryButton); | 666 HideButton(_primaryButton); |
674 [self.view addSubview:_primaryButton]; | 667 [self.view addSubview:_primaryButton]; |
675 | 668 |
676 _secondaryButton.reset([[MDCFlatButton alloc] init]); | 669 _secondaryButton = [[MDCFlatButton alloc] init]; |
677 [self setSecondaryButtonStyling:_secondaryButton]; | 670 [self setSecondaryButtonStyling:_secondaryButton]; |
678 [_secondaryButton addTarget:self | 671 [_secondaryButton addTarget:self |
679 action:@selector(onSecondaryButtonPressed:) | 672 action:@selector(onSecondaryButtonPressed:) |
680 forControlEvents:UIControlEventTouchUpInside]; | 673 forControlEvents:UIControlEventTouchUpInside]; |
681 [_secondaryButton setAccessibilityIdentifier:@"ic_close"]; | 674 [_secondaryButton setAccessibilityIdentifier:@"ic_close"]; |
682 HideButton(_secondaryButton); | 675 HideButton(_secondaryButton); |
683 [self.view addSubview:_secondaryButton]; | 676 [self.view addSubview:_secondaryButton]; |
684 | 677 |
685 _activityIndicator.reset( | 678 _activityIndicator = [[MDCActivityIndicator alloc] initWithFrame:CGRectZero]; |
686 [[MDCActivityIndicator alloc] initWithFrame:CGRectZero]); | |
687 [_activityIndicator setDelegate:self]; | 679 [_activityIndicator setDelegate:self]; |
688 [_activityIndicator setStrokeWidth:3]; | 680 [_activityIndicator setStrokeWidth:3]; |
689 [_activityIndicator | 681 [_activityIndicator |
690 setCycleColors:@[ [[MDCPalette cr_bluePalette] tint500] ]]; | 682 setCycleColors:@[ [[MDCPalette cr_bluePalette] tint500] ]]; |
691 [self.view addSubview:_activityIndicator]; | 683 [self.view addSubview:_activityIndicator]; |
692 | 684 |
693 _gradientView.reset([[UIView alloc] initWithFrame:CGRectZero]); | 685 _gradientView = [[UIView alloc] initWithFrame:CGRectZero]; |
694 _gradientLayer.reset([[CAGradientLayer layer] retain]); | 686 _gradientLayer = [CAGradientLayer layer]; |
695 [_gradientView setUserInteractionEnabled:NO]; | 687 [_gradientView setUserInteractionEnabled:NO]; |
696 _gradientLayer.get().colors = [NSArray | 688 _gradientLayer.colors = [NSArray |
697 arrayWithObjects:(id)[[UIColor colorWithWhite:1 alpha:0] CGColor], | 689 arrayWithObjects:(id)[[UIColor colorWithWhite:1 alpha:0] CGColor], |
698 (id)[self.backgroundColor CGColor], nil]; | 690 (id)[self.backgroundColor CGColor], nil]; |
699 [[_gradientView layer] insertSublayer:_gradientLayer atIndex:0]; | 691 [[_gradientView layer] insertSublayer:_gradientLayer atIndex:0]; |
700 [self.view addSubview:_gradientView]; | 692 [self.view addSubview:_gradientView]; |
701 } | 693 } |
702 | 694 |
703 - (void)viewWillAppear:(BOOL)animated { | 695 - (void)viewWillAppear:(BOOL)animated { |
704 [super viewWillAppear:animated]; | 696 [super viewWillAppear:animated]; |
705 | 697 |
706 if (_currentState != NULL_STATE) { | 698 if (_currentState != NULL_STATE) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 UIUserInterfaceSizeClassRegular) { | 804 UIUserInterfaceSizeClassRegular) { |
813 constants = kRegularConstants; | 805 constants = kRegularConstants; |
814 } else { | 806 } else { |
815 constants = kCompactConstants; | 807 constants = kCompactConstants; |
816 } | 808 } |
817 | 809 |
818 [self layoutButtons:constants]; | 810 [self layoutButtons:constants]; |
819 | 811 |
820 CGSize viewSize = self.view.bounds.size; | 812 CGSize viewSize = self.view.bounds.size; |
821 CGFloat collectionViewHeight = viewSize.height - | 813 CGFloat collectionViewHeight = viewSize.height - |
822 _primaryButton.get().frame.size.height - | 814 _primaryButton.frame.size.height - |
823 constants.ButtonVerticalPadding; | 815 constants.ButtonVerticalPadding; |
824 CGRect collectionViewFrame = | 816 CGRect collectionViewFrame = |
825 CGRectMake(0, 0, viewSize.width, collectionViewHeight); | 817 CGRectMake(0, 0, viewSize.width, collectionViewHeight); |
826 [_accountSelectorVC.get().view setFrame:collectionViewFrame]; | 818 [_accountSelectorVC.view setFrame:collectionViewFrame]; |
827 [_confirmationVC.get().view setFrame:collectionViewFrame]; | 819 [_confirmationVC.view setFrame:collectionViewFrame]; |
828 | 820 |
829 // Layout the gradient view right above the buttons. | 821 // Layout the gradient view right above the buttons. |
830 CGFloat gradientOriginY = CGRectGetHeight(self.view.bounds) - | 822 CGFloat gradientOriginY = CGRectGetHeight(self.view.bounds) - |
831 constants.ButtonVerticalPadding - | 823 constants.ButtonVerticalPadding - |
832 constants.ButtonHeight - constants.GradientHeight; | 824 constants.ButtonHeight - constants.GradientHeight; |
833 [_gradientView setFrame:CGRectMake(0, gradientOriginY, viewSize.width, | 825 [_gradientView setFrame:CGRectMake(0, gradientOriginY, viewSize.width, |
834 constants.GradientHeight)]; | 826 constants.GradientHeight)]; |
835 [_gradientLayer setFrame:[_gradientView bounds]]; | 827 [_gradientLayer setFrame:[_gradientView bounds]]; |
836 | 828 |
837 // Layout the activity indicator in the center of the view. | 829 // Layout the activity indicator in the center of the view. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 [self openAuthenticationDialogAddIdentity]; | 916 [self openAuthenticationDialogAddIdentity]; |
925 } | 917 } |
926 | 918 |
927 #pragma mark - SigninConfirmationViewControllerDelegate | 919 #pragma mark - SigninConfirmationViewControllerDelegate |
928 | 920 |
929 // Callback for when a link in the label is pressed. | 921 // Callback for when a link in the label is pressed. |
930 - (void)signinConfirmationControllerDidTapSettingsLink: | 922 - (void)signinConfirmationControllerDidTapSettingsLink: |
931 (SigninConfirmationViewController*)controller { | 923 (SigninConfirmationViewController*)controller { |
932 DCHECK_EQ(_confirmationVC, controller); | 924 DCHECK_EQ(_confirmationVC, controller); |
933 | 925 |
934 base::scoped_nsobject<GenericChromeCommand> command( | 926 GenericChromeCommand* command = |
935 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]); | 927 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]; |
936 [self acceptSignInAndExecuteCommand:command]; | 928 [self acceptSignInAndExecuteCommand:command]; |
937 } | 929 } |
938 | 930 |
939 - (void)signinConfirmationControllerDidReachBottom: | 931 - (void)signinConfirmationControllerDidReachBottom: |
940 (SigninConfirmationViewController*)controller { | 932 (SigninConfirmationViewController*)controller { |
941 if (_hasConfirmationScreenReachedBottom) { | 933 if (_hasConfirmationScreenReachedBottom) { |
942 return; | 934 return; |
943 } | 935 } |
944 _hasConfirmationScreenReachedBottom = YES; | 936 _hasConfirmationScreenReachedBottom = YES; |
945 [self setPrimaryButtonStyling:_primaryButton]; | 937 [self setPrimaryButtonStyling:_primaryButton]; |
946 [_primaryButton setTitle:[self acceptSigninButtonTitle] | 938 [_primaryButton setTitle:[self acceptSigninButtonTitle] |
947 forState:UIControlStateNormal]; | 939 forState:UIControlStateNormal]; |
948 [_primaryButton setImage:nil forState:UIControlStateNormal]; | 940 [_primaryButton setImage:nil forState:UIControlStateNormal]; |
949 [self.view setNeedsLayout]; | 941 [self.view setNeedsLayout]; |
950 } | 942 } |
951 | 943 |
952 @end | 944 @end |
OLD | NEW |