| 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" | 7 #import "base/ios/weak_nsobject.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
| 12 #include "components/password_manager/core/browser/affiliation_utils.h" | 12 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 13 #include "components/password_manager/core/browser/password_store.h" | 13 #include "components/password_manager/core/browser/password_store.h" |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 15 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 15 #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" | 16 #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
" | 17 #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" | 18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 19 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 19 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 20 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" | 20 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" |
| 21 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" | 21 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" |
| 22 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" | 22 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" |
| 23 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
| 23 #include "ios/chrome/grit/ios_strings.h" | 24 #include "ios/chrome/grit/ios_strings.h" |
| 24 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 25 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 25 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 26 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 26 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" | 27 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" |
| 27 #include "ui/base/l10n/l10n_util_mac.h" | 28 #include "ui/base/l10n/l10n_util_mac.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 32 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 32 SectionIdentifierUsername = kSectionIdentifierEnumZero, | 33 SectionIdentifierUsername = kSectionIdentifierEnumZero, |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 [self toggleShowHideButton]; | 251 [self toggleShowHideButton]; |
| 251 } | 252 } |
| 252 | 253 |
| 253 - (void)copyPassword { | 254 - (void)copyPassword { |
| 254 // 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 |
| 255 // 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 |
| 256 // granted access to it. | 257 // granted access to it. |
| 257 if (_plainTextPasswordShown) { | 258 if (_plainTextPasswordShown) { |
| 258 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | 259 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| 259 generalPasteboard.string = _password; | 260 generalPasteboard.string = _password; |
| 261 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
| 260 [self showCopyPasswordResultToast: | 262 [self showCopyPasswordResultToast: |
| 261 l10n_util::GetNSString( | 263 l10n_util::GetNSString( |
| 262 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; | 264 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| 263 } else if ([_weakReauthenticationModule canAttemptReauth]) { | 265 } else if ([_weakReauthenticationModule canAttemptReauth]) { |
| 264 base::WeakNSObject<PasswordDetailsCollectionViewController> weakSelf(self); | 266 base::WeakNSObject<PasswordDetailsCollectionViewController> weakSelf(self); |
| 265 void (^copyPasswordHandler)(BOOL) = ^(BOOL success) { | 267 void (^copyPasswordHandler)(BOOL) = ^(BOOL success) { |
| 266 base::scoped_nsobject<PasswordDetailsCollectionViewController> strongSelf( | 268 base::scoped_nsobject<PasswordDetailsCollectionViewController> strongSelf( |
| 267 [weakSelf retain]); | 269 [weakSelf retain]); |
| 268 if (!strongSelf) | 270 if (!strongSelf) |
| 269 return; | 271 return; |
| 270 if (success) { | 272 if (success) { |
| 271 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | 273 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| 272 generalPasteboard.string = strongSelf.get()->_password; | 274 generalPasteboard.string = strongSelf.get()->_password; |
| 275 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
| 273 [strongSelf showCopyPasswordResultToast: | 276 [strongSelf showCopyPasswordResultToast: |
| 274 l10n_util::GetNSString( | 277 l10n_util::GetNSString( |
| 275 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; | 278 IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| 276 } else { | 279 } else { |
| 280 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeError); |
| 277 [strongSelf showCopyPasswordResultToast: | 281 [strongSelf showCopyPasswordResultToast: |
| 278 l10n_util::GetNSString( | 282 l10n_util::GetNSString( |
| 279 IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE)]; | 283 IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE)]; |
| 280 } | 284 } |
| 281 }; | 285 }; |
| 282 [_weakReauthenticationModule | 286 [_weakReauthenticationModule |
| 283 attemptReauthWithLocalizedReason: | 287 attemptReauthWithLocalizedReason: |
| 284 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY) | 288 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY) |
| 285 handler:copyPasswordHandler]; | 289 handler:copyPasswordHandler]; |
| 286 } | 290 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 case ItemTypePassword: | 368 case ItemTypePassword: |
| 365 return [MDCCollectionViewCell | 369 return [MDCCollectionViewCell |
| 366 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 370 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| 367 forItem:item]; | 371 forItem:item]; |
| 368 default: | 372 default: |
| 369 return MDCCellDefaultOneLineHeight; | 373 return MDCCellDefaultOneLineHeight; |
| 370 } | 374 } |
| 371 } | 375 } |
| 372 | 376 |
| 373 @end | 377 @end |
| OLD | NEW |