| 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 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control
ler.h" | 5 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control
ler.h" |
| 6 | 6 |
| 7 #import "base/ios/weak_nsobject.h" | |
| 8 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | |
| 10 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
| 12 #include "components/password_manager/core/browser/affiliation_utils.h" | 10 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 13 #include "components/password_manager/core/browser/password_store.h" | 11 #include "components/password_manager/core/browser/password_store.h" |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 15 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 19 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 17 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 20 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" | 18 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" |
| 21 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" | 19 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" |
| 22 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" | 20 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" |
| 23 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 21 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
| 24 #include "ios/chrome/grit/ios_strings.h" | 22 #include "ios/chrome/grit/ios_strings.h" |
| 25 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 23 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 26 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 24 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 27 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" | 25 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" |
| 28 #include "ui/base/l10n/l10n_util_mac.h" | 26 #include "ui/base/l10n/l10n_util_mac.h" |
| 29 | 27 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." |
| 30 #endif |
| 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 34 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 33 SectionIdentifierUsername = kSectionIdentifierEnumZero, | 35 SectionIdentifierUsername = kSectionIdentifierEnumZero, |
| 34 SectionIdentifierPassword, | 36 SectionIdentifierPassword, |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 typedef NS_ENUM(NSInteger, ItemType) { | 39 typedef NS_ENUM(NSInteger, ItemType) { |
| 38 ItemTypeHeader = kItemTypeEnumZero, | 40 ItemTypeHeader = kItemTypeEnumZero, |
| 39 ItemTypeUsername, | 41 ItemTypeUsername, |
| 40 ItemTypePassword, | 42 ItemTypePassword, |
| 41 ItemTypeShowHide, | 43 ItemTypeShowHide, |
| 42 ItemTypeCopy, | 44 ItemTypeCopy, |
| 43 ItemTypeDelete, | 45 ItemTypeDelete, |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 } // namespace | 48 } // namespace |
| 47 | 49 |
| 48 @interface PasswordDetailsCollectionViewController () { | 50 @interface PasswordDetailsCollectionViewController () { |
| 49 // The username to which the saved password belongs. | 51 // The username to which the saved password belongs. |
| 50 base::scoped_nsobject<NSString> _username; | 52 NSString* _username; |
| 51 // The saved password. | 53 // The saved password. |
| 52 base::scoped_nsobject<NSString> _password; | 54 NSString* _password; |
| 53 // Whether the password is shown in plain text form or in obscured form. | 55 // Whether the password is shown in plain text form or in obscured form. |
| 54 BOOL _plainTextPasswordShown; | 56 BOOL _plainTextPasswordShown; |
| 55 // The password form. | 57 // The password form. |
| 56 autofill::PasswordForm _passwordForm; | 58 autofill::PasswordForm _passwordForm; |
| 57 // Instance of the parent view controller needed in order to update the | 59 // Instance of the parent view controller needed in order to update the |
| 58 // password list when a password is deleted. | 60 // password list when a password is deleted. |
| 59 base::WeakNSProtocol<id<PasswordDetailsCollectionViewControllerDelegate>> | 61 __weak id<PasswordDetailsCollectionViewControllerDelegate> _weakDelegate; |
| 60 _weakDelegate; | |
| 61 // Module containing the reauthentication mechanism for viewing and copying | 62 // Module containing the reauthentication mechanism for viewing and copying |
| 62 // passwords. | 63 // passwords. |
| 63 base::WeakNSProtocol<id<ReauthenticationProtocol>> | 64 __weak id<ReauthenticationProtocol> _weakReauthenticationModule; |
| 64 _weakReauthenticationModule; | |
| 65 // The password item. | 65 // The password item. |
| 66 base::scoped_nsobject<PasswordDetailsItem> _passwordItem; | 66 PasswordDetailsItem* _passwordItem; |
| 67 } | 67 } |
| 68 | 68 |
| 69 @end | 69 @end |
| 70 | 70 |
| 71 @implementation PasswordDetailsCollectionViewController | 71 @implementation PasswordDetailsCollectionViewController |
| 72 | 72 |
| 73 - (instancetype) | 73 - (instancetype) |
| 74 initWithPasswordForm:(autofill::PasswordForm)passwordForm | 74 initWithPasswordForm:(autofill::PasswordForm)passwordForm |
| 75 delegate: | 75 delegate: |
| 76 (id<PasswordDetailsCollectionViewControllerDelegate>)delegate | 76 (id<PasswordDetailsCollectionViewControllerDelegate>)delegate |
| 77 reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule | 77 reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| 78 username:(NSString*)username | 78 username:(NSString*)username |
| 79 password:(NSString*)password | 79 password:(NSString*)password |
| 80 origin:(NSString*)origin { | 80 origin:(NSString*)origin { |
| 81 DCHECK(delegate); | 81 DCHECK(delegate); |
| 82 DCHECK(reauthenticationModule); | 82 DCHECK(reauthenticationModule); |
| 83 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 83 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 84 if (self) { | 84 if (self) { |
| 85 _weakDelegate.reset(delegate); | 85 _weakDelegate = delegate; |
| 86 _weakReauthenticationModule.reset(reauthenticationModule); | 86 _weakReauthenticationModule = reauthenticationModule; |
| 87 _passwordForm = passwordForm; | 87 _passwordForm = passwordForm; |
| 88 _username.reset([username copy]); | 88 _username = [username copy]; |
| 89 _password.reset([password copy]); | 89 _password = [password copy]; |
| 90 self.title = | 90 self.title = |
| 91 [PasswordDetailsCollectionViewController simplifyOrigin:origin]; | 91 [PasswordDetailsCollectionViewController simplifyOrigin:origin]; |
| 92 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 92 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 93 [defaultCenter addObserver:self | 93 [defaultCenter addObserver:self |
| 94 selector:@selector(hidePassword) | 94 selector:@selector(hidePassword) |
| 95 name:UIApplicationDidEnterBackgroundNotification | 95 name:UIApplicationDidEnterBackgroundNotification |
| 96 object:nil]; | 96 object:nil]; |
| 97 | 97 |
| 98 [self loadModel]; | 98 [self loadModel]; |
| 99 } | 99 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 [[originWithoutScheme componentsSeparatedByString:@"/"] objectAtIndex:0]; | 112 [[originWithoutScheme componentsSeparatedByString:@"/"] objectAtIndex:0]; |
| 113 } | 113 } |
| 114 | 114 |
| 115 #pragma mark - SettingsRootCollectionViewController | 115 #pragma mark - SettingsRootCollectionViewController |
| 116 | 116 |
| 117 - (void)loadModel { | 117 - (void)loadModel { |
| 118 [super loadModel]; | 118 [super loadModel]; |
| 119 CollectionViewModel* model = self.collectionViewModel; | 119 CollectionViewModel* model = self.collectionViewModel; |
| 120 | 120 |
| 121 [model addSectionWithIdentifier:SectionIdentifierUsername]; | 121 [model addSectionWithIdentifier:SectionIdentifierUsername]; |
| 122 CollectionViewTextItem* usernameHeader = [ | 122 CollectionViewTextItem* usernameHeader = |
| 123 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 123 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 124 usernameHeader.text = | 124 usernameHeader.text = |
| 125 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); | 125 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); |
| 126 usernameHeader.textColor = [[MDCPalette greyPalette] tint500]; | 126 usernameHeader.textColor = [[MDCPalette greyPalette] tint500]; |
| 127 [model setHeader:usernameHeader | 127 [model setHeader:usernameHeader |
| 128 forSectionWithIdentifier:SectionIdentifierUsername]; | 128 forSectionWithIdentifier:SectionIdentifierUsername]; |
| 129 PasswordDetailsItem* usernameItem = | 129 PasswordDetailsItem* usernameItem = |
| 130 [[[PasswordDetailsItem alloc] initWithType:ItemTypeUsername] autorelease]; | 130 [[PasswordDetailsItem alloc] initWithType:ItemTypeUsername]; |
| 131 usernameItem.text = _username; | 131 usernameItem.text = _username; |
| 132 usernameItem.showingText = YES; | 132 usernameItem.showingText = YES; |
| 133 [model addItem:usernameItem | 133 [model addItem:usernameItem |
| 134 toSectionWithIdentifier:SectionIdentifierUsername]; | 134 toSectionWithIdentifier:SectionIdentifierUsername]; |
| 135 | 135 |
| 136 [model addSectionWithIdentifier:SectionIdentifierPassword]; | 136 [model addSectionWithIdentifier:SectionIdentifierPassword]; |
| 137 CollectionViewTextItem* passwordHeader = [ | 137 CollectionViewTextItem* passwordHeader = |
| 138 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 138 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 139 passwordHeader.text = | 139 passwordHeader.text = |
| 140 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); | 140 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); |
| 141 passwordHeader.textColor = [[MDCPalette greyPalette] tint500]; | 141 passwordHeader.textColor = [[MDCPalette greyPalette] tint500]; |
| 142 [model setHeader:passwordHeader | 142 [model setHeader:passwordHeader |
| 143 forSectionWithIdentifier:SectionIdentifierPassword]; | 143 forSectionWithIdentifier:SectionIdentifierPassword]; |
| 144 _passwordItem.reset( | 144 _passwordItem = [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]; |
| 145 [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]); | 145 _passwordItem.text = _password; |
| 146 _passwordItem.get().text = _password; | 146 _passwordItem.showingText = NO; |
| 147 _passwordItem.get().showingText = NO; | |
| 148 [model addItem:_passwordItem | 147 [model addItem:_passwordItem |
| 149 toSectionWithIdentifier:SectionIdentifierPassword]; | 148 toSectionWithIdentifier:SectionIdentifierPassword]; |
| 150 | 149 |
| 151 // TODO(crbug.com/159166): Change the style of the buttons once there are | 150 // TODO(crbug.com/159166): Change the style of the buttons once there are |
| 152 // final mocks. | 151 // final mocks. |
| 153 [model addItem:[self showHidePasswordButtonItem] | 152 [model addItem:[self showHidePasswordButtonItem] |
| 154 toSectionWithIdentifier:SectionIdentifierPassword]; | 153 toSectionWithIdentifier:SectionIdentifierPassword]; |
| 155 [model addItem:[self passwordCopyButtonItem] | 154 [model addItem:[self passwordCopyButtonItem] |
| 156 toSectionWithIdentifier:SectionIdentifierPassword]; | 155 toSectionWithIdentifier:SectionIdentifierPassword]; |
| 157 [model addItem:[self deletePasswordButtonItem] | 156 [model addItem:[self deletePasswordButtonItem] |
| 158 toSectionWithIdentifier:SectionIdentifierPassword]; | 157 toSectionWithIdentifier:SectionIdentifierPassword]; |
| 159 } | 158 } |
| 160 | 159 |
| 161 - (void)dealloc { | 160 - (void)dealloc { |
| 162 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 161 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 163 [super dealloc]; | |
| 164 } | 162 } |
| 165 | 163 |
| 166 #pragma mark - Items | 164 #pragma mark - Items |
| 167 | 165 |
| 168 - (CollectionViewItem*)passwordCopyButtonItem { | 166 - (CollectionViewItem*)passwordCopyButtonItem { |
| 169 CollectionViewTextItem* item = | 167 CollectionViewTextItem* item = |
| 170 [[[CollectionViewTextItem alloc] initWithType:ItemTypeCopy] autorelease]; | 168 [[CollectionViewTextItem alloc] initWithType:ItemTypeCopy]; |
| 171 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON); | 169 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON); |
| 172 item.accessibilityTraits |= UIAccessibilityTraitButton; | 170 item.accessibilityTraits |= UIAccessibilityTraitButton; |
| 173 return item; | 171 return item; |
| 174 } | 172 } |
| 175 | 173 |
| 176 - (CollectionViewItem*)showHidePasswordButtonItem { | 174 - (CollectionViewItem*)showHidePasswordButtonItem { |
| 177 CollectionViewTextItem* item = [[[CollectionViewTextItem alloc] | 175 CollectionViewTextItem* item = |
| 178 initWithType:ItemTypeShowHide] autorelease]; | 176 [[CollectionViewTextItem alloc] initWithType:ItemTypeShowHide]; |
| 179 item.text = [self showHideButtonText]; | 177 item.text = [self showHideButtonText]; |
| 180 item.accessibilityTraits |= UIAccessibilityTraitButton; | 178 item.accessibilityTraits |= UIAccessibilityTraitButton; |
| 181 return item; | 179 return item; |
| 182 } | 180 } |
| 183 | 181 |
| 184 - (CollectionViewItem*)deletePasswordButtonItem { | 182 - (CollectionViewItem*)deletePasswordButtonItem { |
| 185 CollectionViewTextItem* item = [ | 183 CollectionViewTextItem* item = |
| 186 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete] autorelease]; | 184 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete]; |
| 187 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); | 185 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); |
| 188 item.textColor = [[MDCPalette cr_redPalette] tint500]; | 186 item.textColor = [[MDCPalette cr_redPalette] tint500]; |
| 189 item.accessibilityTraits |= UIAccessibilityTraitButton; | 187 item.accessibilityTraits |= UIAccessibilityTraitButton; |
| 190 return item; | 188 return item; |
| 191 } | 189 } |
| 192 | 190 |
| 193 #pragma mark - Actions | 191 #pragma mark - Actions |
| 194 | 192 |
| 195 - (NSString*)showHideButtonText { | 193 - (NSString*)showHideButtonText { |
| 196 if (_plainTextPasswordShown) { | 194 if (_plainTextPasswordShown) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 213 inSectionWithIdentifier:SectionIdentifierPassword]; | 211 inSectionWithIdentifier:SectionIdentifierPassword]; |
| 214 [self.collectionView.collectionViewLayout invalidateLayout]; | 212 [self.collectionView.collectionViewLayout invalidateLayout]; |
| 215 } | 213 } |
| 216 | 214 |
| 217 - (void)showPassword { | 215 - (void)showPassword { |
| 218 if (_plainTextPasswordShown) { | 216 if (_plainTextPasswordShown) { |
| 219 return; | 217 return; |
| 220 } | 218 } |
| 221 | 219 |
| 222 if ([_weakReauthenticationModule canAttemptReauth]) { | 220 if ([_weakReauthenticationModule canAttemptReauth]) { |
| 223 base::WeakNSObject<PasswordDetailsCollectionViewController> weakSelf(self); | 221 __weak PasswordDetailsCollectionViewController* weakSelf = self; |
| 224 void (^showPasswordHandler)(BOOL) = ^(BOOL success) { | 222 void (^showPasswordHandler)(BOOL) = ^(BOOL success) { |
| 225 base::scoped_nsobject<PasswordDetailsCollectionViewController> strongSelf( | 223 PasswordDetailsCollectionViewController* strongSelf = weakSelf; |
| 226 [weakSelf retain]); | |
| 227 if (!strongSelf || !success) | 224 if (!strongSelf || !success) |
| 228 return; | 225 return; |
| 229 PasswordDetailsItem* passwordItem = strongSelf.get()->_passwordItem.get(); | 226 PasswordDetailsItem* passwordItem = strongSelf->_passwordItem; |
| 230 passwordItem.showingText = YES; | 227 passwordItem.showingText = YES; |
| 231 [strongSelf reconfigureCellsForItems:@[ passwordItem ] | 228 [strongSelf reconfigureCellsForItems:@[ passwordItem ] |
| 232 inSectionWithIdentifier:SectionIdentifierPassword]; | 229 inSectionWithIdentifier:SectionIdentifierPassword]; |
| 233 [[strongSelf collectionView].collectionViewLayout invalidateLayout]; | 230 [[strongSelf collectionView].collectionViewLayout invalidateLayout]; |
| 234 strongSelf.get()->_plainTextPasswordShown = YES; | 231 strongSelf->_plainTextPasswordShown = YES; |
| 235 [strongSelf toggleShowHideButton]; | 232 [strongSelf toggleShowHideButton]; |
| 236 }; | 233 }; |
| 237 | 234 |
| 238 [_weakReauthenticationModule | 235 [_weakReauthenticationModule |
| 239 attemptReauthWithLocalizedReason: | 236 attemptReauthWithLocalizedReason: |
| 240 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_SHOW) | 237 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_SHOW) |
| 241 handler:showPasswordHandler]; | 238 handler:showPasswordHandler]; |
| 242 } | 239 } |
| 243 } | 240 } |
| 244 | 241 |
| 245 - (void)hidePassword { | 242 - (void)hidePassword { |
| 246 if (!_plainTextPasswordShown) { | 243 if (!_plainTextPasswordShown) { |
| 247 return; | 244 return; |
| 248 } | 245 } |
| 249 _passwordItem.get().showingText = NO; | 246 _passwordItem.showingText = NO; |
| 250 [self reconfigureCellsForItems:@[ _passwordItem ] | 247 [self reconfigureCellsForItems:@[ _passwordItem ] |
| 251 inSectionWithIdentifier:SectionIdentifierPassword]; | 248 inSectionWithIdentifier:SectionIdentifierPassword]; |
| 252 [self.collectionView.collectionViewLayout invalidateLayout]; | 249 [self.collectionView.collectionViewLayout invalidateLayout]; |
| 253 _plainTextPasswordShown = NO; | 250 _plainTextPasswordShown = NO; |
| 254 [self toggleShowHideButton]; | 251 [self toggleShowHideButton]; |
| 255 } | 252 } |
| 256 | 253 |
| 257 - (void)copyPassword { | 254 - (void)copyPassword { |
| 258 // If the password is displayed in plain text, there is no need to | 255 // If the password is displayed in plain text, there is no need to |
| 259 // re-authenticate the user when copying the password because they are already | 256 // re-authenticate the user when copying the password because they are already |
| 260 // granted access to it. | 257 // granted access to it. |
| 261 if (_plainTextPasswordShown) { | 258 if (_plainTextPasswordShown) { |
| 262 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | 259 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| 263 generalPasteboard.string = _password; | 260 generalPasteboard.string = _password; |
| 264 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); | 261 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
| 265 [self showCopyPasswordResultToast: | 262 [self showCopyPasswordResultToast: |
| 266 l10n_util::GetNSString( | 263 l10n_util::GetNSString( |
| 267 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; | 264 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| 268 } else if ([_weakReauthenticationModule canAttemptReauth]) { | 265 } else if ([_weakReauthenticationModule canAttemptReauth]) { |
| 269 base::WeakNSObject<PasswordDetailsCollectionViewController> weakSelf(self); | 266 __weak PasswordDetailsCollectionViewController* weakSelf = self; |
| 270 void (^copyPasswordHandler)(BOOL) = ^(BOOL success) { | 267 void (^copyPasswordHandler)(BOOL) = ^(BOOL success) { |
| 271 base::scoped_nsobject<PasswordDetailsCollectionViewController> strongSelf( | 268 PasswordDetailsCollectionViewController* strongSelf = weakSelf; |
| 272 [weakSelf retain]); | |
| 273 if (!strongSelf) | 269 if (!strongSelf) |
| 274 return; | 270 return; |
| 275 if (success) { | 271 if (success) { |
| 276 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | 272 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| 277 generalPasteboard.string = strongSelf.get()->_password; | 273 generalPasteboard.string = strongSelf->_password; |
| 278 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); | 274 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
| 279 [strongSelf showCopyPasswordResultToast: | 275 [strongSelf showCopyPasswordResultToast: |
| 280 l10n_util::GetNSString( | 276 l10n_util::GetNSString( |
| 281 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; | 277 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| 282 } else { | 278 } else { |
| 283 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeError); | 279 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeError); |
| 284 [strongSelf showCopyPasswordResultToast: | 280 [strongSelf showCopyPasswordResultToast: |
| 285 l10n_util::GetNSString( | 281 l10n_util::GetNSString( |
| 286 IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE)]; | 282 IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE)]; |
| 287 } | 283 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 case ItemTypePassword: | 336 case ItemTypePassword: |
| 341 return [MDCCollectionViewCell | 337 return [MDCCollectionViewCell |
| 342 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 338 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| 343 forItem:item]; | 339 forItem:item]; |
| 344 default: | 340 default: |
| 345 return MDCCellDefaultOneLineHeight; | 341 return MDCCellDefaultOneLineHeight; |
| 346 } | 342 } |
| 347 } | 343 } |
| 348 | 344 |
| 349 @end | 345 @end |
| OLD | NEW |