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 |
180 @synthesize shouldClearData = _shouldClearData; | 182 @synthesize shouldClearData = _shouldClearData; |
181 | 183 |
182 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 184 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
183 isPresentedOnSettings:(BOOL)isPresentedOnSettings | 185 isPresentedOnSettings:(BOOL)isPresentedOnSettings |
184 accessPoint:(signin_metrics::AccessPoint)accessPoint | 186 accessPoint:(signin_metrics::AccessPoint)accessPoint |
185 promoAction:(signin_metrics::PromoAction)promoAction | 187 promoAction:(signin_metrics::PromoAction)promoAction |
186 signInIdentity:(ChromeIdentity*)identity { | 188 signInIdentity:(ChromeIdentity*)identity { |
(...skipping 20 matching lines...) Expand all Loading... | |
207 // after the creation of those objects, so if the objects are not nil, then | 209 // after the creation of those objects, so if the objects are not nil, then |
208 // it is safe to call -[UIControl removeTarget:action:forControlEvents:]. | 210 // it is safe to call -[UIControl removeTarget:action:forControlEvents:]. |
209 // If they are nil, then the call does nothing. | 211 // If they are nil, then the call does nothing. |
210 [_primaryButton removeTarget:self | 212 [_primaryButton removeTarget:self |
211 action:@selector(onPrimaryButtonPressed:) | 213 action:@selector(onPrimaryButtonPressed:) |
212 forControlEvents:UIControlEventTouchDown]; | 214 forControlEvents:UIControlEventTouchDown]; |
213 [_secondaryButton removeTarget:self | 215 [_secondaryButton removeTarget:self |
214 action:@selector(onSecondaryButtonPressed:) | 216 action:@selector(onSecondaryButtonPressed:) |
215 forControlEvents:UIControlEventTouchDown]; | 217 forControlEvents:UIControlEventTouchDown]; |
216 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 218 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
217 [super dealloc]; | |
218 } | 219 } |
219 | 220 |
220 - (void)cancel { | 221 - (void)cancel { |
221 if (_alertCoordinator) { | 222 if (_alertCoordinator) { |
222 DCHECK(!_authenticationFlow && !_interactionManager); | 223 DCHECK(!_authenticationFlow && !_interactionManager); |
223 [_alertCoordinator executeCancelHandler]; | 224 [_alertCoordinator executeCancelHandler]; |
224 [_alertCoordinator stop]; | 225 [_alertCoordinator stop]; |
225 } | 226 } |
226 if (_interactionManager) { | 227 if (_interactionManager) { |
227 DCHECK(!_alertCoordinator && !_authenticationFlow); | 228 DCHECK(!_alertCoordinator && !_authenticationFlow); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 #pragma mark - Properties | 285 #pragma mark - Properties |
285 | 286 |
286 - (ios::ChromeBrowserState*)browserState { | 287 - (ios::ChromeBrowserState*)browserState { |
287 return _browserState; | 288 return _browserState; |
288 } | 289 } |
289 | 290 |
290 - (id<ChromeSigninViewControllerDelegate>)delegate { | 291 - (id<ChromeSigninViewControllerDelegate>)delegate { |
291 return _delegate; | 292 return _delegate; |
292 } | 293 } |
293 | 294 |
294 - (void)setDelegate:(id<ChromeSigninViewControllerDelegate>)delegate { | 295 - (void)setDelegate:(id<ChromeSigninViewControllerDelegate>)delegate { |
msarda
2017/06/12 12:49:13
I think this setDelegate method can now be removed
marq (ping after 24h)
2017/06/12 14:20:40
Done.
| |
295 _delegate.reset(delegate); | 296 _delegate = delegate; |
296 } | 297 } |
297 | 298 |
298 - (UIColor*)backgroundColor { | 299 - (UIColor*)backgroundColor { |
299 return [[MDCPalette greyPalette] tint50]; | 300 return [[MDCPalette greyPalette] tint50]; |
300 } | 301 } |
301 | 302 |
302 - (NSString*)identityPickerTitle { | 303 - (NSString*)identityPickerTitle { |
303 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_TITLE); | 304 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_TITLE); |
304 } | 305 } |
305 | 306 |
306 - (NSString*)acceptSigninButtonTitle { | 307 - (NSString*)acceptSigninButtonTitle { |
307 return l10n_util::GetNSString( | 308 return l10n_util::GetNSString( |
308 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON); | 309 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON); |
309 } | 310 } |
310 | 311 |
311 - (NSString*)skipSigninButtonTitle { | 312 - (NSString*)skipSigninButtonTitle { |
312 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); | 313 return l10n_util::GetNSString(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); |
313 } | 314 } |
314 | 315 |
315 - (UIButton*)primaryButton { | 316 - (UIButton*)primaryButton { |
316 return _primaryButton; | 317 return _primaryButton; |
317 } | 318 } |
318 | 319 |
319 - (UIButton*)secondaryButton { | 320 - (UIButton*)secondaryButton { |
320 return _secondaryButton; | 321 return _secondaryButton; |
321 } | 322 } |
322 | 323 |
323 - (void)setSelectedIdentity:(ChromeIdentity*)identity { | 324 - (void)setSelectedIdentity:(ChromeIdentity*)identity { |
324 DCHECK(identity || (IDENTITY_PICKER_STATE == _currentState)); | 325 DCHECK(identity || (IDENTITY_PICKER_STATE == _currentState)); |
325 _selectedIdentity.reset([identity retain]); | 326 _selectedIdentity = identity; |
326 } | 327 } |
327 | 328 |
328 - (ChromeIdentity*)selectedIdentity { | 329 - (ChromeIdentity*)selectedIdentity { |
329 return _selectedIdentity; | 330 return _selectedIdentity; |
330 } | 331 } |
331 | 332 |
332 #pragma mark - Authentication | 333 #pragma mark - Authentication |
333 | 334 |
334 - (void)handleAuthenticationError:(NSError*)error { | 335 - (void)handleAuthenticationError:(NSError*)error { |
335 // Filter out cancel and errors handled internally by ChromeIdentity. | 336 // Filter out cancel and errors handled internally by ChromeIdentity. |
336 if (!ShouldHandleSigninError(error)) { | 337 if (!ShouldHandleSigninError(error)) { |
337 return; | 338 return; |
338 } | 339 } |
339 _alertCoordinator.reset( | 340 _alertCoordinator = ios_internal::ErrorCoordinator(error, nil, self); |
340 [ios_internal::ErrorCoordinator(error, nil, self) retain]); | |
341 [_alertCoordinator start]; | 341 [_alertCoordinator start]; |
342 } | 342 } |
343 | 343 |
344 - (void)signIntoIdentity:(ChromeIdentity*)identity { | 344 - (void)signIntoIdentity:(ChromeIdentity*)identity { |
345 [_delegate willStartSignIn:self]; | 345 [_delegate willStartSignIn:self]; |
346 DCHECK(!_authenticationFlow); | 346 DCHECK(!_authenticationFlow); |
347 _authenticationFlow.reset([[AuthenticationFlow alloc] | 347 _authenticationFlow = |
348 initWithBrowserState:_browserState | 348 [[AuthenticationFlow alloc] initWithBrowserState:_browserState |
349 identity:identity | 349 identity:identity |
350 shouldClearData:_shouldClearData | 350 shouldClearData:_shouldClearData |
351 postSignInAction:POST_SIGNIN_ACTION_NONE | 351 postSignInAction:POST_SIGNIN_ACTION_NONE |
352 presentingViewController:self]); | 352 presentingViewController:self]; |
353 base::WeakNSObject<ChromeSigninViewController> weakSelf(self); | 353 __weak ChromeSigninViewController* weakSelf = self; |
354 [_authenticationFlow startSignInWithCompletion:^(BOOL success) { | 354 [_authenticationFlow startSignInWithCompletion:^(BOOL success) { |
355 [weakSelf onAccountSigninCompletion:success]; | 355 [weakSelf onAccountSigninCompletion:success]; |
356 }]; | 356 }]; |
357 } | 357 } |
358 | 358 |
359 - (void)openAuthenticationDialogAddIdentity { | 359 - (void)openAuthenticationDialogAddIdentity { |
360 DCHECK(!_interactionManager); | 360 DCHECK(!_interactionManager); |
361 _interactionManager = | 361 _interactionManager = |
362 ios::GetChromeBrowserProvider() | 362 ios::GetChromeBrowserProvider() |
363 ->GetChromeIdentityService() | 363 ->GetChromeIdentityService() |
364 ->NewChromeIdentityInteractionManager(_browserState, self); | 364 ->NewChromeIdentityInteractionManager(_browserState, self); |
365 base::WeakNSObject<ChromeSigninViewController> weakSelf(self); | 365 __weak ChromeSigninViewController* weakSelf = self; |
366 SigninCompletionCallback completion = | 366 SigninCompletionCallback completion = |
367 ^(ChromeIdentity* identity, NSError* error) { | 367 ^(ChromeIdentity* identity, NSError* error) { |
368 base::scoped_nsobject<ChromeSigninViewController> strongSelf( | 368 ChromeSigninViewController* strongSelf = weakSelf; |
369 [weakSelf retain]); | 369 if (!strongSelf || !strongSelf->_interactionManager) |
370 if (!strongSelf || !strongSelf.get()->_interactionManager) | |
371 return; | 370 return; |
372 // The ChromeIdentityInteractionManager is not used anymore at this | 371 // The ChromeIdentityInteractionManager is not used anymore at this |
373 // point. | 372 // point. |
374 strongSelf.get()->_interactionManager.reset(); | 373 strongSelf->_interactionManager = nil; |
375 | 374 |
376 if (error) { | 375 if (error) { |
377 [strongSelf handleAuthenticationError:error]; | 376 [strongSelf handleAuthenticationError:error]; |
378 return; | 377 return; |
379 } | 378 } |
380 strongSelf.get()->_addedAccount = YES; | 379 strongSelf->_addedAccount = YES; |
381 [strongSelf onIdentityListChanged]; | 380 [strongSelf onIdentityListChanged]; |
382 [strongSelf setSelectedIdentity:identity]; | 381 [strongSelf setSelectedIdentity:identity]; |
383 [strongSelf changeToState:SIGNIN_PENDING_STATE]; | 382 [strongSelf changeToState:SIGNIN_PENDING_STATE]; |
384 }; | 383 }; |
385 [_delegate willStartAddAccount:self]; | 384 [_delegate willStartAddAccount:self]; |
386 [_interactionManager addAccountWithCompletion:completion]; | 385 [_interactionManager addAccountWithCompletion:completion]; |
387 } | 386 } |
388 | 387 |
389 - (void)onAccountSigninCompletion:(BOOL)success { | 388 - (void)onAccountSigninCompletion:(BOOL)success { |
390 _authenticationFlow.reset(); | 389 _authenticationFlow = nil; |
391 if (success) { | 390 if (success) { |
392 DCHECK(!_didSignIn); | 391 DCHECK(!_didSignIn); |
393 _didSignIn = YES; | 392 _didSignIn = YES; |
394 [_delegate didSignIn:self]; | 393 [_delegate didSignIn:self]; |
395 [self changeToState:IDENTITY_SELECTED_STATE]; | 394 [self changeToState:IDENTITY_SELECTED_STATE]; |
396 } else { | 395 } else { |
397 [self changeToState:IDENTITY_PICKER_STATE]; | 396 [self changeToState:IDENTITY_PICKER_STATE]; |
398 } | 397 } |
399 } | 398 } |
400 | 399 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; | 485 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; |
487 [_primaryButton setImage:nil forState:UIControlStateNormal]; | 486 [_primaryButton setImage:nil forState:UIControlStateNormal]; |
488 [self.view setNeedsLayout]; | 487 [self.view setNeedsLayout]; |
489 } | 488 } |
490 | 489 |
491 - (void)enterIdentityPickerState { | 490 - (void)enterIdentityPickerState { |
492 // Reset the selected identity. | 491 // Reset the selected identity. |
493 [self setSelectedIdentity:nil]; | 492 [self setSelectedIdentity:nil]; |
494 | 493 |
495 // Add the account selector view controller. | 494 // Add the account selector view controller. |
496 _accountSelectorVC.reset([[SigninAccountSelectorViewController alloc] init]); | 495 _accountSelectorVC = [[SigninAccountSelectorViewController alloc] init]; |
497 _accountSelectorVC.get().delegate = self; | 496 _accountSelectorVC.delegate = self; |
498 [_accountSelectorVC willMoveToParentViewController:self]; | 497 [_accountSelectorVC willMoveToParentViewController:self]; |
499 [self addChildViewController:_accountSelectorVC]; | 498 [self addChildViewController:_accountSelectorVC]; |
500 _accountSelectorVC.get().view.frame = self.view.bounds; | 499 _accountSelectorVC.view.frame = self.view.bounds; |
501 [self.view insertSubview:_accountSelectorVC.get().view | 500 [self.view insertSubview:_accountSelectorVC.view belowSubview:_primaryButton]; |
502 belowSubview:_primaryButton]; | |
503 [_accountSelectorVC didMoveToParentViewController:self]; | 501 [_accountSelectorVC didMoveToParentViewController:self]; |
504 | 502 |
505 // Update the button title. | 503 // Update the button title. |
506 [self updatePrimaryButtonTitle]; | 504 [self updatePrimaryButtonTitle]; |
507 [_secondaryButton setTitle:self.skipSigninButtonTitle | 505 [_secondaryButton setTitle:self.skipSigninButtonTitle |
508 forState:UIControlStateNormal]; | 506 forState:UIControlStateNormal]; |
509 [self.view setNeedsLayout]; | 507 [self.view setNeedsLayout]; |
510 | 508 |
511 HideButton(_primaryButton); | 509 HideButton(_primaryButton); |
512 HideButton(_secondaryButton); | 510 HideButton(_secondaryButton); |
(...skipping 14 matching lines...) Expand all Loading... | |
527 - (void)leaveIdentityPickerState:(AuthenticationState)nextState { | 525 - (void)leaveIdentityPickerState:(AuthenticationState)nextState { |
528 [UIView animateWithDuration:kAnimationDuration | 526 [UIView animateWithDuration:kAnimationDuration |
529 animations:^{ | 527 animations:^{ |
530 HideButton(_primaryButton); | 528 HideButton(_primaryButton); |
531 HideButton(_secondaryButton); | 529 HideButton(_secondaryButton); |
532 } | 530 } |
533 completion:^(BOOL finished) { | 531 completion:^(BOOL finished) { |
534 [_accountSelectorVC willMoveToParentViewController:nil]; | 532 [_accountSelectorVC willMoveToParentViewController:nil]; |
535 [[_accountSelectorVC view] removeFromSuperview]; | 533 [[_accountSelectorVC view] removeFromSuperview]; |
536 [_accountSelectorVC removeFromParentViewController]; | 534 [_accountSelectorVC removeFromParentViewController]; |
537 _accountSelectorVC.reset(); | 535 _accountSelectorVC = nil; |
538 [self enterState:nextState]; | 536 [self enterState:nextState]; |
539 }]; | 537 }]; |
540 } | 538 } |
541 | 539 |
542 #pragma mark - SigninPendingState | 540 #pragma mark - SigninPendingState |
543 | 541 |
544 - (void)enterSigninPendingState { | 542 - (void)enterSigninPendingState { |
545 [_secondaryButton setTitle:l10n_util::GetNSString(IDS_CANCEL) | 543 [_secondaryButton setTitle:l10n_util::GetNSString(IDS_CANCEL) |
546 forState:UIControlStateNormal]; | 544 forState:UIControlStateNormal]; |
547 [self.view setNeedsLayout]; | 545 [self.view setNeedsLayout]; |
(...skipping 17 matching lines...) Expand all Loading... | |
565 | 563 |
566 - (void)leaveSigninPendingState:(AuthenticationState)nextState { | 564 - (void)leaveSigninPendingState:(AuthenticationState)nextState { |
567 if (!_pendingStateTimer) { | 565 if (!_pendingStateTimer) { |
568 // The controller is already leaving the signin pending state, simply update | 566 // The controller is already leaving the signin pending state, simply update |
569 // the new state to take into account the last request only. | 567 // the new state to take into account the last request only. |
570 _activityIndicatorNextState = nextState; | 568 _activityIndicatorNextState = nextState; |
571 return; | 569 return; |
572 } | 570 } |
573 | 571 |
574 _activityIndicatorNextState = nextState; | 572 _activityIndicatorNextState = nextState; |
575 _activityIndicator.get().delegate = self; | 573 _activityIndicator.delegate = self; |
576 | 574 |
577 base::TimeDelta remainingTime = | 575 base::TimeDelta remainingTime = |
578 base::TimeDelta::FromMilliseconds(kMinimunPendingStateDurationMs) - | 576 base::TimeDelta::FromMilliseconds(kMinimunPendingStateDurationMs) - |
579 _pendingStateTimer->Elapsed(); | 577 _pendingStateTimer->Elapsed(); |
580 _pendingStateTimer.reset(); | 578 _pendingStateTimer.reset(); |
581 | 579 |
582 if (remainingTime.InMilliseconds() < 0) { | 580 if (remainingTime.InMilliseconds() < 0) { |
583 [_activityIndicator stopAnimating]; | 581 [_activityIndicator stopAnimating]; |
584 } else { | 582 } else { |
585 // If the signin pending state is too fast, the screen will appear to | 583 // If the signin pending state is too fast, the screen will appear to |
586 // flicker. Make sure to animate for at least | 584 // flicker. Make sure to animate for at least |
587 // |kMinimunPendingStateDurationMs| milliseconds. | 585 // |kMinimunPendingStateDurationMs| milliseconds. |
588 base::WeakNSObject<ChromeSigninViewController> weakSelf(self); | 586 __weak ChromeSigninViewController* weakSelf = self; |
589 ProceduralBlock completionBlock = ^{ | 587 ProceduralBlock completionBlock = ^{ |
590 base::scoped_nsobject<ChromeSigninViewController> strongSelf( | 588 ChromeSigninViewController* strongSelf = weakSelf; |
591 [weakSelf retain]); | |
592 if (!strongSelf) | 589 if (!strongSelf) |
593 return; | 590 return; |
594 [strongSelf.get()->_activityIndicator stopAnimating]; | 591 [strongSelf->_activityIndicator stopAnimating]; |
595 strongSelf.get()->_leavingPendingStateTimer.reset(); | 592 strongSelf->_leavingPendingStateTimer.reset(); |
596 }; | 593 }; |
597 _leavingPendingStateTimer.reset(new base::Timer(false, false)); | 594 _leavingPendingStateTimer.reset(new base::Timer(false, false)); |
598 _leavingPendingStateTimer->Start(FROM_HERE, remainingTime, | 595 _leavingPendingStateTimer->Start(FROM_HERE, remainingTime, |
599 base::BindBlock(completionBlock)); | 596 base::BindBlockArc(completionBlock)); |
600 } | 597 } |
601 } | 598 } |
602 | 599 |
603 #pragma mark - IdentitySelectedState | 600 #pragma mark - IdentitySelectedState |
604 | 601 |
605 - (void)enterIdentitySelectedState { | 602 - (void)enterIdentitySelectedState { |
606 _confirmationVC.reset([[SigninConfirmationViewController alloc] | 603 _confirmationVC = [[SigninConfirmationViewController alloc] |
607 initWithIdentity:self.selectedIdentity]); | 604 initWithIdentity:self.selectedIdentity]; |
608 _confirmationVC.get().delegate = self; | 605 _confirmationVC.delegate = self; |
609 | 606 |
610 _hasConfirmationScreenReachedBottom = NO; | 607 _hasConfirmationScreenReachedBottom = NO; |
611 [_confirmationVC willMoveToParentViewController:self]; | 608 [_confirmationVC willMoveToParentViewController:self]; |
612 [self addChildViewController:_confirmationVC]; | 609 [self addChildViewController:_confirmationVC]; |
613 _confirmationVC.get().view.frame = self.view.bounds; | 610 _confirmationVC.view.frame = self.view.bounds; |
614 [self.view insertSubview:_confirmationVC.get().view | 611 [self.view insertSubview:_confirmationVC.view belowSubview:_primaryButton]; |
615 belowSubview:_primaryButton]; | |
616 [_confirmationVC didMoveToParentViewController:self]; | 612 [_confirmationVC didMoveToParentViewController:self]; |
617 | 613 |
618 [self setSecondaryButtonStyling:_primaryButton]; | 614 [self setSecondaryButtonStyling:_primaryButton]; |
619 NSString* primaryButtonTitle = l10n_util::GetNSString( | 615 NSString* primaryButtonTitle = l10n_util::GetNSString( |
620 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SCROLL_BUTTON); | 616 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SCROLL_BUTTON); |
621 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; | 617 [_primaryButton setTitle:primaryButtonTitle forState:UIControlStateNormal]; |
622 [_primaryButton setImage:[UIImage imageNamed:@"signin_confirmation_more"] | 618 [_primaryButton setImage:[UIImage imageNamed:@"signin_confirmation_more"] |
623 forState:UIControlStateNormal]; | 619 forState:UIControlStateNormal]; |
624 NSString* secondaryButtonTitle = l10n_util::GetNSString( | 620 NSString* secondaryButtonTitle = l10n_util::GetNSString( |
625 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); | 621 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); |
(...skipping 18 matching lines...) Expand all Loading... | |
644 if (!isSelectedIdentityValid) { | 640 if (!isSelectedIdentityValid) { |
645 [self changeToState:IDENTITY_PICKER_STATE]; | 641 [self changeToState:IDENTITY_PICKER_STATE]; |
646 return; | 642 return; |
647 } | 643 } |
648 } | 644 } |
649 | 645 |
650 - (void)leaveIdentitySelectedState:(AuthenticationState)nextState { | 646 - (void)leaveIdentitySelectedState:(AuthenticationState)nextState { |
651 [_confirmationVC willMoveToParentViewController:nil]; | 647 [_confirmationVC willMoveToParentViewController:nil]; |
652 [[_confirmationVC view] removeFromSuperview]; | 648 [[_confirmationVC view] removeFromSuperview]; |
653 [_confirmationVC removeFromParentViewController]; | 649 [_confirmationVC removeFromParentViewController]; |
654 _confirmationVC.reset(); | 650 _confirmationVC = nil; |
655 [self setPrimaryButtonStyling:_primaryButton]; | 651 [self setPrimaryButtonStyling:_primaryButton]; |
656 HideButton(_primaryButton); | 652 HideButton(_primaryButton); |
657 HideButton(_secondaryButton); | 653 HideButton(_secondaryButton); |
658 [self undoSignIn]; | 654 [self undoSignIn]; |
659 [self enterState:nextState]; | 655 [self enterState:nextState]; |
660 } | 656 } |
661 | 657 |
662 #pragma mark - UIViewController | 658 #pragma mark - UIViewController |
663 | 659 |
664 - (void)viewDidLoad { | 660 - (void)viewDidLoad { |
665 [super viewDidLoad]; | 661 [super viewDidLoad]; |
666 self.view.backgroundColor = self.backgroundColor; | 662 self.view.backgroundColor = self.backgroundColor; |
667 | 663 |
668 _primaryButton.reset([[MDCFlatButton alloc] init]); | 664 _primaryButton = [[MDCFlatButton alloc] init]; |
669 [self setPrimaryButtonStyling:_primaryButton]; | 665 [self setPrimaryButtonStyling:_primaryButton]; |
670 [_primaryButton addTarget:self | 666 [_primaryButton addTarget:self |
671 action:@selector(onPrimaryButtonPressed:) | 667 action:@selector(onPrimaryButtonPressed:) |
672 forControlEvents:UIControlEventTouchUpInside]; | 668 forControlEvents:UIControlEventTouchUpInside]; |
673 HideButton(_primaryButton); | 669 HideButton(_primaryButton); |
674 [self.view addSubview:_primaryButton]; | 670 [self.view addSubview:_primaryButton]; |
675 | 671 |
676 _secondaryButton.reset([[MDCFlatButton alloc] init]); | 672 _secondaryButton = [[MDCFlatButton alloc] init]; |
677 [self setSecondaryButtonStyling:_secondaryButton]; | 673 [self setSecondaryButtonStyling:_secondaryButton]; |
678 [_secondaryButton addTarget:self | 674 [_secondaryButton addTarget:self |
679 action:@selector(onSecondaryButtonPressed:) | 675 action:@selector(onSecondaryButtonPressed:) |
680 forControlEvents:UIControlEventTouchUpInside]; | 676 forControlEvents:UIControlEventTouchUpInside]; |
681 [_secondaryButton setAccessibilityIdentifier:@"ic_close"]; | 677 [_secondaryButton setAccessibilityIdentifier:@"ic_close"]; |
682 HideButton(_secondaryButton); | 678 HideButton(_secondaryButton); |
683 [self.view addSubview:_secondaryButton]; | 679 [self.view addSubview:_secondaryButton]; |
684 | 680 |
685 _activityIndicator.reset( | 681 _activityIndicator = [[MDCActivityIndicator alloc] initWithFrame:CGRectZero]; |
686 [[MDCActivityIndicator alloc] initWithFrame:CGRectZero]); | |
687 [_activityIndicator setDelegate:self]; | 682 [_activityIndicator setDelegate:self]; |
688 [_activityIndicator setStrokeWidth:3]; | 683 [_activityIndicator setStrokeWidth:3]; |
689 [_activityIndicator | 684 [_activityIndicator |
690 setCycleColors:@[ [[MDCPalette cr_bluePalette] tint500] ]]; | 685 setCycleColors:@[ [[MDCPalette cr_bluePalette] tint500] ]]; |
691 [self.view addSubview:_activityIndicator]; | 686 [self.view addSubview:_activityIndicator]; |
692 | 687 |
693 _gradientView.reset([[UIView alloc] initWithFrame:CGRectZero]); | 688 _gradientView = [[UIView alloc] initWithFrame:CGRectZero]; |
694 _gradientLayer.reset([[CAGradientLayer layer] retain]); | 689 _gradientLayer = [CAGradientLayer layer]; |
695 [_gradientView setUserInteractionEnabled:NO]; | 690 [_gradientView setUserInteractionEnabled:NO]; |
696 _gradientLayer.get().colors = [NSArray | 691 _gradientLayer.colors = [NSArray |
697 arrayWithObjects:(id)[[UIColor colorWithWhite:1 alpha:0] CGColor], | 692 arrayWithObjects:(id)[[UIColor colorWithWhite:1 alpha:0] CGColor], |
698 (id)[self.backgroundColor CGColor], nil]; | 693 (id)[self.backgroundColor CGColor], nil]; |
699 [[_gradientView layer] insertSublayer:_gradientLayer atIndex:0]; | 694 [[_gradientView layer] insertSublayer:_gradientLayer atIndex:0]; |
700 [self.view addSubview:_gradientView]; | 695 [self.view addSubview:_gradientView]; |
701 } | 696 } |
702 | 697 |
703 - (void)viewWillAppear:(BOOL)animated { | 698 - (void)viewWillAppear:(BOOL)animated { |
704 [super viewWillAppear:animated]; | 699 [super viewWillAppear:animated]; |
705 | 700 |
706 if (_currentState != NULL_STATE) { | 701 if (_currentState != NULL_STATE) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 UIUserInterfaceSizeClassRegular) { | 807 UIUserInterfaceSizeClassRegular) { |
813 constants = kRegularConstants; | 808 constants = kRegularConstants; |
814 } else { | 809 } else { |
815 constants = kCompactConstants; | 810 constants = kCompactConstants; |
816 } | 811 } |
817 | 812 |
818 [self layoutButtons:constants]; | 813 [self layoutButtons:constants]; |
819 | 814 |
820 CGSize viewSize = self.view.bounds.size; | 815 CGSize viewSize = self.view.bounds.size; |
821 CGFloat collectionViewHeight = viewSize.height - | 816 CGFloat collectionViewHeight = viewSize.height - |
822 _primaryButton.get().frame.size.height - | 817 _primaryButton.frame.size.height - |
823 constants.ButtonVerticalPadding; | 818 constants.ButtonVerticalPadding; |
824 CGRect collectionViewFrame = | 819 CGRect collectionViewFrame = |
825 CGRectMake(0, 0, viewSize.width, collectionViewHeight); | 820 CGRectMake(0, 0, viewSize.width, collectionViewHeight); |
826 [_accountSelectorVC.get().view setFrame:collectionViewFrame]; | 821 [_accountSelectorVC.view setFrame:collectionViewFrame]; |
827 [_confirmationVC.get().view setFrame:collectionViewFrame]; | 822 [_confirmationVC.view setFrame:collectionViewFrame]; |
828 | 823 |
829 // Layout the gradient view right above the buttons. | 824 // Layout the gradient view right above the buttons. |
830 CGFloat gradientOriginY = CGRectGetHeight(self.view.bounds) - | 825 CGFloat gradientOriginY = CGRectGetHeight(self.view.bounds) - |
831 constants.ButtonVerticalPadding - | 826 constants.ButtonVerticalPadding - |
832 constants.ButtonHeight - constants.GradientHeight; | 827 constants.ButtonHeight - constants.GradientHeight; |
833 [_gradientView setFrame:CGRectMake(0, gradientOriginY, viewSize.width, | 828 [_gradientView setFrame:CGRectMake(0, gradientOriginY, viewSize.width, |
834 constants.GradientHeight)]; | 829 constants.GradientHeight)]; |
835 [_gradientLayer setFrame:[_gradientView bounds]]; | 830 [_gradientLayer setFrame:[_gradientView bounds]]; |
836 | 831 |
837 // Layout the activity indicator in the center of the view. | 832 // 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]; | 919 [self openAuthenticationDialogAddIdentity]; |
925 } | 920 } |
926 | 921 |
927 #pragma mark - SigninConfirmationViewControllerDelegate | 922 #pragma mark - SigninConfirmationViewControllerDelegate |
928 | 923 |
929 // Callback for when a link in the label is pressed. | 924 // Callback for when a link in the label is pressed. |
930 - (void)signinConfirmationControllerDidTapSettingsLink: | 925 - (void)signinConfirmationControllerDidTapSettingsLink: |
931 (SigninConfirmationViewController*)controller { | 926 (SigninConfirmationViewController*)controller { |
932 DCHECK_EQ(_confirmationVC, controller); | 927 DCHECK_EQ(_confirmationVC, controller); |
933 | 928 |
934 base::scoped_nsobject<GenericChromeCommand> command( | 929 GenericChromeCommand* command = |
935 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]); | 930 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]; |
936 [self acceptSignInAndExecuteCommand:command]; | 931 [self acceptSignInAndExecuteCommand:command]; |
937 } | 932 } |
938 | 933 |
939 - (void)signinConfirmationControllerDidReachBottom: | 934 - (void)signinConfirmationControllerDidReachBottom: |
940 (SigninConfirmationViewController*)controller { | 935 (SigninConfirmationViewController*)controller { |
941 if (_hasConfirmationScreenReachedBottom) { | 936 if (_hasConfirmationScreenReachedBottom) { |
942 return; | 937 return; |
943 } | 938 } |
944 _hasConfirmationScreenReachedBottom = YES; | 939 _hasConfirmationScreenReachedBottom = YES; |
945 [self setPrimaryButtonStyling:_primaryButton]; | 940 [self setPrimaryButtonStyling:_primaryButton]; |
946 [_primaryButton setTitle:[self acceptSigninButtonTitle] | 941 [_primaryButton setTitle:[self acceptSigninButtonTitle] |
947 forState:UIControlStateNormal]; | 942 forState:UIControlStateNormal]; |
948 [_primaryButton setImage:nil forState:UIControlStateNormal]; | 943 [_primaryButton setImage:nil forState:UIControlStateNormal]; |
949 [self.view setNeedsLayout]; | 944 [self.view setNeedsLayout]; |
950 } | 945 } |
951 | 946 |
952 @end | 947 @end |
OLD | NEW |