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 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
10 #include "components/password_manager/core/browser/affiliation_utils.h" | 10 #include "components/password_manager/core/browser/affiliation_utils.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // |_plainTextPasswordShown|. | 203 // |_plainTextPasswordShown|. |
204 - (void)toggleShowHideButton { | 204 - (void)toggleShowHideButton { |
205 CollectionViewModel* model = self.collectionViewModel; | 205 CollectionViewModel* model = self.collectionViewModel; |
206 NSIndexPath* path = [model indexPathForItemType:ItemTypeShowHide | 206 NSIndexPath* path = [model indexPathForItemType:ItemTypeShowHide |
207 sectionIdentifier:SectionIdentifierPassword]; | 207 sectionIdentifier:SectionIdentifierPassword]; |
208 CollectionViewTextItem* item = | 208 CollectionViewTextItem* item = |
209 base::mac::ObjCCastStrict<CollectionViewTextItem>( | 209 base::mac::ObjCCastStrict<CollectionViewTextItem>( |
210 [model itemAtIndexPath:path]); | 210 [model itemAtIndexPath:path]); |
211 item.text = [self showHideButtonText]; | 211 item.text = [self showHideButtonText]; |
212 item.textColor = [[MDCPalette cr_bluePalette] tint500]; | 212 item.textColor = [[MDCPalette cr_bluePalette] tint500]; |
213 [self reconfigureCellsForItems:@[ item ] | 213 [self reconfigureCellsForItems:@[ item ]]; |
214 inSectionWithIdentifier:SectionIdentifierPassword]; | |
215 [self.collectionView.collectionViewLayout invalidateLayout]; | 214 [self.collectionView.collectionViewLayout invalidateLayout]; |
216 } | 215 } |
217 | 216 |
218 - (void)showPassword { | 217 - (void)showPassword { |
219 if (_plainTextPasswordShown) { | 218 if (_plainTextPasswordShown) { |
220 return; | 219 return; |
221 } | 220 } |
222 | 221 |
223 if ([_weakReauthenticationModule canAttemptReauth]) { | 222 if ([_weakReauthenticationModule canAttemptReauth]) { |
224 __weak PasswordDetailsCollectionViewController* weakSelf = self; | 223 __weak PasswordDetailsCollectionViewController* weakSelf = self; |
225 void (^showPasswordHandler)(BOOL) = ^(BOOL success) { | 224 void (^showPasswordHandler)(BOOL) = ^(BOOL success) { |
226 PasswordDetailsCollectionViewController* strongSelf = weakSelf; | 225 PasswordDetailsCollectionViewController* strongSelf = weakSelf; |
227 if (!strongSelf || !success) | 226 if (!strongSelf || !success) |
228 return; | 227 return; |
229 PasswordDetailsItem* passwordItem = strongSelf->_passwordItem; | 228 PasswordDetailsItem* passwordItem = strongSelf->_passwordItem; |
230 passwordItem.showingText = YES; | 229 passwordItem.showingText = YES; |
231 [strongSelf reconfigureCellsForItems:@[ passwordItem ] | 230 [strongSelf reconfigureCellsForItems:@[ passwordItem ]]; |
232 inSectionWithIdentifier:SectionIdentifierPassword]; | |
233 [[strongSelf collectionView].collectionViewLayout invalidateLayout]; | 231 [[strongSelf collectionView].collectionViewLayout invalidateLayout]; |
234 strongSelf->_plainTextPasswordShown = YES; | 232 strongSelf->_plainTextPasswordShown = YES; |
235 [strongSelf toggleShowHideButton]; | 233 [strongSelf toggleShowHideButton]; |
236 }; | 234 }; |
237 | 235 |
238 [_weakReauthenticationModule | 236 [_weakReauthenticationModule |
239 attemptReauthWithLocalizedReason: | 237 attemptReauthWithLocalizedReason: |
240 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_SHOW) | 238 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_SHOW) |
241 handler:showPasswordHandler]; | 239 handler:showPasswordHandler]; |
242 } | 240 } |
243 } | 241 } |
244 | 242 |
245 - (void)hidePassword { | 243 - (void)hidePassword { |
246 if (!_plainTextPasswordShown) { | 244 if (!_plainTextPasswordShown) { |
247 return; | 245 return; |
248 } | 246 } |
249 _passwordItem.showingText = NO; | 247 _passwordItem.showingText = NO; |
250 [self reconfigureCellsForItems:@[ _passwordItem ] | 248 [self reconfigureCellsForItems:@[ _passwordItem ]]; |
251 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) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 case ItemTypePassword: | 336 case ItemTypePassword: |
340 return [MDCCollectionViewCell | 337 return [MDCCollectionViewCell |
341 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 338 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
342 forItem:item]; | 339 forItem:item]; |
343 default: | 340 default: |
344 return MDCCellDefaultOneLineHeight; | 341 return MDCCellDefaultOneLineHeight; |
345 } | 342 } |
346 } | 343 } |
347 | 344 |
348 @end | 345 @end |
OLD | NEW |