| 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/save_passwords_collection_view_controlle
     r.h" |    5 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
     r.h" | 
|    6  |    6  | 
|    7 #include <memory> |    7 #include <memory> | 
|    8 #include <vector> |    8 #include <vector> | 
|    9  |    9  | 
|   10 #include "base/ios/ios_util.h" |   10 #include "base/ios/ios_util.h" | 
|   11 #import "base/ios/weak_nsobject.h" |  | 
|   12 #include "base/logging.h" |   11 #include "base/logging.h" | 
|   13 #include "base/mac/foundation_util.h" |   12 #include "base/mac/foundation_util.h" | 
|   14 #import "base/mac/objc_property_releaser.h" |   13  | 
|   15 #import "base/mac/scoped_nsobject.h" |  | 
|   16 #include "base/memory/ptr_util.h" |   14 #include "base/memory/ptr_util.h" | 
|   17 #include "base/numerics/safe_conversions.h" |   15 #include "base/numerics/safe_conversions.h" | 
|   18 #include "base/strings/sys_string_conversions.h" |   16 #include "base/strings/sys_string_conversions.h" | 
|   19 #include "base/strings/utf_string_conversions.h" |   17 #include "base/strings/utf_string_conversions.h" | 
|   20 #include "components/autofill/core/common/password_form.h" |   18 #include "components/autofill/core/common/password_form.h" | 
|   21 #include "components/google/core/browser/google_util.h" |   19 #include "components/google/core/browser/google_util.h" | 
|   22 #include "components/keyed_service/core/service_access_type.h" |   20 #include "components/keyed_service/core/service_access_type.h" | 
|   23 #include "components/password_manager/core/browser/affiliation_utils.h" |   21 #include "components/password_manager/core/browser/affiliation_utils.h" | 
|   24 #include "components/password_manager/core/browser/password_manager_constants.h" |   22 #include "components/password_manager/core/browser/password_manager_constants.h" | 
|   25 #include "components/password_manager/core/browser/password_store.h" |   23 #include "components/password_manager/core/browser/password_store.h" | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|   41 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |   39 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 
|   42 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control
     ler.h" |   40 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control
     ler.h" | 
|   43 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" |   41 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" | 
|   44 #import "ios/chrome/browser/ui/settings/settings_utils.h" |   42 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 
|   45 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" |   43 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" | 
|   46 #include "ios/chrome/grit/ios_strings.h" |   44 #include "ios/chrome/grit/ios_strings.h" | 
|   47 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
     erialPalettes.h" |   45 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
     erialPalettes.h" | 
|   48 #include "ui/base/l10n/l10n_util_mac.h" |   46 #include "ui/base/l10n/l10n_util_mac.h" | 
|   49 #include "url/gurl.h" |   47 #include "url/gurl.h" | 
|   50  |   48  | 
 |   49 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
 |   50 #error "This file requires ARC support." | 
 |   51 #endif | 
 |   52  | 
|   51 namespace { |   53 namespace { | 
|   52  |   54  | 
|   53 typedef NS_ENUM(NSInteger, SectionIdentifier) { |   55 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 
|   54   SectionIdentifierMessage = kSectionIdentifierEnumZero, |   56   SectionIdentifierMessage = kSectionIdentifierEnumZero, | 
|   55   SectionIdentifierSavePasswordsSwitch, |   57   SectionIdentifierSavePasswordsSwitch, | 
|   56   SectionIdentifierSavedPasswords, |   58   SectionIdentifierSavedPasswords, | 
|   57   SectionIdentifierBlacklist, |   59   SectionIdentifierBlacklist, | 
|   58 }; |   60 }; | 
|   59  |   61  | 
|   60 typedef NS_ENUM(NSInteger, ItemType) { |   62 typedef NS_ENUM(NSInteger, ItemType) { | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  124 @end |  126 @end | 
|  125 @implementation BlacklistedFormContentItem |  127 @implementation BlacklistedFormContentItem | 
|  126 @end |  128 @end | 
|  127  |  129  | 
|  128 @interface SavePasswordsCollectionViewController ()< |  130 @interface SavePasswordsCollectionViewController ()< | 
|  129     BooleanObserver, |  131     BooleanObserver, | 
|  130     PasswordDetailsCollectionViewControllerDelegate, |  132     PasswordDetailsCollectionViewControllerDelegate, | 
|  131     SuccessfulReauthTimeAccessor> { |  133     SuccessfulReauthTimeAccessor> { | 
|  132   // The observable boolean that binds to the password manager setting state. |  134   // The observable boolean that binds to the password manager setting state. | 
|  133   // Saved passwords are only on if the password manager is enabled. |  135   // Saved passwords are only on if the password manager is enabled. | 
|  134   base::scoped_nsobject<PrefBackedBoolean> passwordManagerEnabled_; |  136   PrefBackedBoolean* passwordManagerEnabled_; | 
|  135   // The item related to the switch for the password manager setting. |  137   // The item related to the switch for the password manager setting. | 
|  136   base::scoped_nsobject<CollectionViewSwitchItem> savePasswordsItem_; |  138   CollectionViewSwitchItem* savePasswordsItem_; | 
|  137   // The interface for getting and manipulating a user's saved passwords. |  139   // The interface for getting and manipulating a user's saved passwords. | 
|  138   scoped_refptr<password_manager::PasswordStore> passwordStore_; |  140   scoped_refptr<password_manager::PasswordStore> passwordStore_; | 
|  139   // A helper object for passing data about saved passwords from a finished |  141   // A helper object for passing data about saved passwords from a finished | 
|  140   // password store request to the SavePasswordsCollectionViewController. |  142   // password store request to the SavePasswordsCollectionViewController. | 
|  141   std::unique_ptr<password_manager::SavePasswordsConsumer> |  143   std::unique_ptr<password_manager::SavePasswordsConsumer> | 
|  142       savedPasswordsConsumer_; |  144       savedPasswordsConsumer_; | 
|  143   // A helper object for passing data about blacklisted sites from a finished |  145   // A helper object for passing data about blacklisted sites from a finished | 
|  144   // password store request to the SavePasswordsCollectionViewController. |  146   // password store request to the SavePasswordsCollectionViewController. | 
|  145   std::unique_ptr<password_manager::SavePasswordsConsumer> |  147   std::unique_ptr<password_manager::SavePasswordsConsumer> | 
|  146       blacklistPasswordsConsumer_; |  148       blacklistPasswordsConsumer_; | 
|  147   // The list of the user's saved passwords. |  149   // The list of the user's saved passwords. | 
|  148   std::vector<std::unique_ptr<autofill::PasswordForm>> savedForms_; |  150   std::vector<std::unique_ptr<autofill::PasswordForm>> savedForms_; | 
|  149   // The list of the user's blacklisted sites. |  151   // The list of the user's blacklisted sites. | 
|  150   std::vector<std::unique_ptr<autofill::PasswordForm>> blacklistedForms_; |  152   std::vector<std::unique_ptr<autofill::PasswordForm>> blacklistedForms_; | 
|  151   // Deletion of password being asynchronous, and the method taking a reference |  153   // Deletion of password being asynchronous, and the method taking a reference | 
|  152   // to the PasswordForm, the PasswordForm must outlive the calls to |  154   // to the PasswordForm, the PasswordForm must outlive the calls to | 
|  153   // RemoveLogin. This vector will ensure this. |  155   // RemoveLogin. This vector will ensure this. | 
|  154   std::vector<std::unique_ptr<autofill::PasswordForm>> deletedForms_; |  156   std::vector<std::unique_ptr<autofill::PasswordForm>> deletedForms_; | 
|  155   // The current Chrome browser state. |  157   // The current Chrome browser state. | 
|  156   ios::ChromeBrowserState* browserState_; |  158   ios::ChromeBrowserState* browserState_; | 
|  157   // Object storing the time of the previous successful re-authentication. |  159   // Object storing the time of the previous successful re-authentication. | 
|  158   // This is meant to be used by the |ReauthenticationModule| for keeping |  160   // This is meant to be used by the |ReauthenticationModule| for keeping | 
|  159   // re-authentications valid for a certain time interval within the scope |  161   // re-authentications valid for a certain time interval within the scope | 
|  160   // of the Save Passwords Settings. |  162   // of the Save Passwords Settings. | 
|  161   base::scoped_nsobject<NSDate> successfulReauthTime_; |  163   NSDate* successfulReauthTime_; | 
|  162   // Module containing the reauthentication mechanism for viewing and copying |  164   // Module containing the reauthentication mechanism for viewing and copying | 
|  163   // passwords. |  165   // passwords. | 
|  164   base::scoped_nsobject<ReauthenticationModule> reauthenticationModule_; |  166   ReauthenticationModule* reauthenticationModule_; | 
|  165  |  | 
|  166   base::mac::ObjCPropertyReleaser |  | 
|  167       propertyReleaser_SavePasswordsCollectionViewController_; |  | 
|  168 } |  167 } | 
|  169 // Kick off async request to get logins from password store. |  168 // Kick off async request to get logins from password store. | 
|  170 - (void)getLoginsFromPasswordStore; |  169 - (void)getLoginsFromPasswordStore; | 
|  171 @end |  170 @end | 
|  172  |  171  | 
|  173 @implementation SavePasswordsCollectionViewController |  172 @implementation SavePasswordsCollectionViewController | 
|  174  |  173  | 
|  175 #pragma mark - Initialization |  174 #pragma mark - Initialization | 
|  176  |  175  | 
|  177 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |  176 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { | 
|  178   DCHECK(browserState); |  177   DCHECK(browserState); | 
|  179   self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |  178   self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 
|  180   if (self) { |  179   if (self) { | 
|  181     browserState_ = browserState; |  180     browserState_ = browserState; | 
|  182     reauthenticationModule_.reset([[ReauthenticationModule alloc] |  181     reauthenticationModule_ = [[ReauthenticationModule alloc] | 
|  183         initWithSuccessfulReauthTimeAccessor:self]); |  182         initWithSuccessfulReauthTimeAccessor:self]; | 
|  184     self.title = l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS); |  183     self.title = l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS); | 
|  185     self.shouldHideDoneButton = YES; |  184     self.shouldHideDoneButton = YES; | 
|  186     passwordStore_ = IOSChromePasswordStoreFactory::GetForBrowserState( |  185     passwordStore_ = IOSChromePasswordStoreFactory::GetForBrowserState( | 
|  187         browserState_, ServiceAccessType::EXPLICIT_ACCESS); |  186         browserState_, ServiceAccessType::EXPLICIT_ACCESS); | 
|  188     DCHECK(passwordStore_); |  187     DCHECK(passwordStore_); | 
|  189     passwordManagerEnabled_.reset([[PrefBackedBoolean alloc] |  188     passwordManagerEnabled_ = [[PrefBackedBoolean alloc] | 
|  190         initWithPrefService:browserState_->GetPrefs() |  189         initWithPrefService:browserState_->GetPrefs() | 
|  191                    prefName:password_manager::prefs:: |  190                    prefName:password_manager::prefs:: | 
|  192                                 kPasswordManagerSavingEnabled]); |  191                                 kPasswordManagerSavingEnabled]; | 
|  193     [passwordManagerEnabled_ setObserver:self]; |  192     [passwordManagerEnabled_ setObserver:self]; | 
|  194     [self getLoginsFromPasswordStore]; |  193     [self getLoginsFromPasswordStore]; | 
|  195     [self updateEditButton]; |  194     [self updateEditButton]; | 
|  196     [self loadModel]; |  195     [self loadModel]; | 
|  197  |  | 
|  198     propertyReleaser_SavePasswordsCollectionViewController_.Init( |  | 
|  199         self, [SavePasswordsCollectionViewController class]); |  | 
|  200   } |  196   } | 
|  201   return self; |  197   return self; | 
|  202 } |  198 } | 
|  203  |  199  | 
|  204 - (void)dealloc { |  200 - (void)dealloc { | 
|  205   [passwordManagerEnabled_ setObserver:nil]; |  201   [passwordManagerEnabled_ setObserver:nil]; | 
|  206   [super dealloc]; |  | 
|  207 } |  202 } | 
|  208  |  203  | 
|  209 #pragma mark - SettingsRootCollectionViewController |  204 #pragma mark - SettingsRootCollectionViewController | 
|  210  |  205  | 
|  211 - (void)loadModel { |  206 - (void)loadModel { | 
|  212   [super loadModel]; |  207   [super loadModel]; | 
|  213   CollectionViewModel* model = self.collectionViewModel; |  208   CollectionViewModel* model = self.collectionViewModel; | 
|  214  |  209  | 
|  215   // Manage account message. |  210   // Manage account message. | 
|  216   CollectionViewItem* manageAccountLinkItem = [self manageAccountLinkItem]; |  211   CollectionViewItem* manageAccountLinkItem = [self manageAccountLinkItem]; | 
|  217   if (manageAccountLinkItem) { |  212   if (manageAccountLinkItem) { | 
|  218     [model addSectionWithIdentifier:SectionIdentifierMessage]; |  213     [model addSectionWithIdentifier:SectionIdentifierMessage]; | 
|  219     [model addItem:manageAccountLinkItem |  214     [model addItem:manageAccountLinkItem | 
|  220         toSectionWithIdentifier:SectionIdentifierMessage]; |  215         toSectionWithIdentifier:SectionIdentifierMessage]; | 
|  221   } |  216   } | 
|  222  |  217  | 
|  223   // Save passwords switch. |  218   // Save passwords switch. | 
|  224   [model addSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch]; |  219   [model addSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch]; | 
|  225   savePasswordsItem_.reset([[self savePasswordsItem] retain]); |  220   savePasswordsItem_ = [self savePasswordsItem]; | 
|  226   [model addItem:savePasswordsItem_ |  221   [model addItem:savePasswordsItem_ | 
|  227       toSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch]; |  222       toSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch]; | 
|  228  |  223  | 
|  229   // Saved passwords. |  224   // Saved passwords. | 
|  230   if ([passwordManagerEnabled_ value]) { |  225   if ([passwordManagerEnabled_ value]) { | 
|  231     if (!savedForms_.empty()) { |  226     if (!savedForms_.empty()) { | 
|  232       [model addSectionWithIdentifier:SectionIdentifierSavedPasswords]; |  227       [model addSectionWithIdentifier:SectionIdentifierSavedPasswords]; | 
|  233       CollectionViewTextItem* headerItem = [[[CollectionViewTextItem alloc] |  228       CollectionViewTextItem* headerItem = | 
|  234           initWithType:ItemTypeHeader] autorelease]; |  229           [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; | 
|  235       headerItem.text = |  230       headerItem.text = | 
|  236           l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE); |  231           l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE); | 
|  237       headerItem.textColor = [[MDCPalette greyPalette] tint500]; |  232       headerItem.textColor = [[MDCPalette greyPalette] tint500]; | 
|  238       [model setHeader:headerItem |  233       [model setHeader:headerItem | 
|  239           forSectionWithIdentifier:SectionIdentifierSavedPasswords]; |  234           forSectionWithIdentifier:SectionIdentifierSavedPasswords]; | 
|  240       for (const auto& form : savedForms_) { |  235       for (const auto& form : savedForms_) { | 
|  241         [model addItem:[self savedFormItemWithForm:form.get()] |  236         [model addItem:[self savedFormItemWithForm:form.get()] | 
|  242             toSectionWithIdentifier:SectionIdentifierSavedPasswords]; |  237             toSectionWithIdentifier:SectionIdentifierSavedPasswords]; | 
|  243       } |  238       } | 
|  244     } |  239     } | 
|  245     if (!blacklistedForms_.empty()) { |  240     if (!blacklistedForms_.empty()) { | 
|  246       [model addSectionWithIdentifier:SectionIdentifierBlacklist]; |  241       [model addSectionWithIdentifier:SectionIdentifierBlacklist]; | 
|  247       CollectionViewTextItem* headerItem = [[[CollectionViewTextItem alloc] |  242       CollectionViewTextItem* headerItem = | 
|  248           initWithType:ItemTypeHeader] autorelease]; |  243           [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; | 
|  249       headerItem.text = |  244       headerItem.text = | 
|  250           l10n_util::GetNSString(IDS_PASSWORD_MANAGER_EXCEPTIONS_TAB_TITLE); |  245           l10n_util::GetNSString(IDS_PASSWORD_MANAGER_EXCEPTIONS_TAB_TITLE); | 
|  251       headerItem.textColor = [[MDCPalette greyPalette] tint500]; |  246       headerItem.textColor = [[MDCPalette greyPalette] tint500]; | 
|  252       [model setHeader:headerItem |  247       [model setHeader:headerItem | 
|  253           forSectionWithIdentifier:SectionIdentifierBlacklist]; |  248           forSectionWithIdentifier:SectionIdentifierBlacklist]; | 
|  254       for (const auto& form : blacklistedForms_) { |  249       for (const auto& form : blacklistedForms_) { | 
|  255         [model addItem:[self blacklistedFormItemWithForm:form.get()] |  250         [model addItem:[self blacklistedFormItemWithForm:form.get()] | 
|  256             toSectionWithIdentifier:SectionIdentifierBlacklist]; |  251             toSectionWithIdentifier:SectionIdentifierBlacklist]; | 
|  257       } |  252       } | 
|  258     } |  253     } | 
|  259   } |  254   } | 
|  260 } |  255 } | 
|  261  |  256  | 
|  262 #pragma mark - Items |  257 #pragma mark - Items | 
|  263  |  258  | 
|  264 - (CollectionViewItem*)manageAccountLinkItem { |  259 - (CollectionViewItem*)manageAccountLinkItem { | 
|  265   CollectionViewFooterItem* footerItem = [[[CollectionViewFooterItem alloc] |  260   CollectionViewFooterItem* footerItem = | 
|  266       initWithType:ItemTypeManageAccount] autorelease]; |  261       [[CollectionViewFooterItem alloc] initWithType:ItemTypeManageAccount]; | 
|  267   footerItem.text = |  262   footerItem.text = | 
|  268       l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS_MANAGE_ACCOUNT); |  263       l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS_MANAGE_ACCOUNT); | 
|  269   footerItem.linkURL = google_util::AppendGoogleLocaleParam( |  264   footerItem.linkURL = google_util::AppendGoogleLocaleParam( | 
|  270       GURL(password_manager::kPasswordManagerAccountDashboardURL), |  265       GURL(password_manager::kPasswordManagerAccountDashboardURL), | 
|  271       GetApplicationContext()->GetApplicationLocale()); |  266       GetApplicationContext()->GetApplicationLocale()); | 
|  272   footerItem.linkDelegate = self; |  267   footerItem.linkDelegate = self; | 
|  273   return footerItem; |  268   return footerItem; | 
|  274 } |  269 } | 
|  275  |  270  | 
|  276 - (CollectionViewSwitchItem*)savePasswordsItem { |  271 - (CollectionViewSwitchItem*)savePasswordsItem { | 
|  277   CollectionViewSwitchItem* savePasswordsItem = |  272   CollectionViewSwitchItem* savePasswordsItem = | 
|  278       [[[CollectionViewSwitchItem alloc] |  273       [[CollectionViewSwitchItem alloc] | 
|  279           initWithType:ItemTypeSavePasswordsSwitch] autorelease]; |  274           initWithType:ItemTypeSavePasswordsSwitch]; | 
|  280   savePasswordsItem.text = l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS); |  275   savePasswordsItem.text = l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS); | 
|  281   savePasswordsItem.on = [passwordManagerEnabled_ value]; |  276   savePasswordsItem.on = [passwordManagerEnabled_ value]; | 
|  282   return savePasswordsItem; |  277   return savePasswordsItem; | 
|  283 } |  278 } | 
|  284  |  279  | 
|  285 - (SavedFormContentItem*)savedFormItemWithForm:(autofill::PasswordForm*)form { |  280 - (SavedFormContentItem*)savedFormItemWithForm:(autofill::PasswordForm*)form { | 
|  286   SavedFormContentItem* passwordItem = [[[SavedFormContentItem alloc] |  281   SavedFormContentItem* passwordItem = | 
|  287       initWithType:ItemTypeSavedPassword] autorelease]; |  282       [[SavedFormContentItem alloc] initWithType:ItemTypeSavedPassword]; | 
|  288   passwordItem.text = |  283   passwordItem.text = | 
|  289       base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); |  284       base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); | 
|  290   passwordItem.detailText = base::SysUTF16ToNSString(form->username_value); |  285   passwordItem.detailText = base::SysUTF16ToNSString(form->username_value); | 
|  291   if (experimental_flags::IsViewCopyPasswordsEnabled()) { |  286   if (experimental_flags::IsViewCopyPasswordsEnabled()) { | 
|  292     passwordItem.accessibilityTraits |= UIAccessibilityTraitButton; |  287     passwordItem.accessibilityTraits |= UIAccessibilityTraitButton; | 
|  293     passwordItem.accessoryType = |  288     passwordItem.accessoryType = | 
|  294         MDCCollectionViewCellAccessoryDisclosureIndicator; |  289         MDCCollectionViewCellAccessoryDisclosureIndicator; | 
|  295   } |  290   } | 
|  296   return passwordItem; |  291   return passwordItem; | 
|  297 } |  292 } | 
|  298  |  293  | 
|  299 - (BlacklistedFormContentItem*)blacklistedFormItemWithForm: |  294 - (BlacklistedFormContentItem*)blacklistedFormItemWithForm: | 
|  300     (autofill::PasswordForm*)form { |  295     (autofill::PasswordForm*)form { | 
|  301   BlacklistedFormContentItem* passwordItem = |  296   BlacklistedFormContentItem* passwordItem = | 
|  302       [[[BlacklistedFormContentItem alloc] initWithType:ItemTypeBlacklisted] |  297       [[BlacklistedFormContentItem alloc] initWithType:ItemTypeBlacklisted]; | 
|  303           autorelease]; |  | 
|  304   passwordItem.text = |  298   passwordItem.text = | 
|  305       base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); |  299       base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); | 
|  306   return passwordItem; |  300   return passwordItem; | 
|  307 } |  301 } | 
|  308  |  302  | 
|  309 #pragma mark - MDCCollectionViewEditingDelegate |  303 #pragma mark - MDCCollectionViewEditingDelegate | 
|  310  |  304  | 
|  311 - (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView { |  305 - (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView { | 
|  312   return YES; |  306   return YES; | 
|  313 } |  307 } | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  382     [switchCell.switchView addTarget:self |  376     [switchCell.switchView addTarget:self | 
|  383                               action:@selector(savePasswordsSwitchChanged:) |  377                               action:@selector(savePasswordsSwitchChanged:) | 
|  384                     forControlEvents:UIControlEventValueChanged]; |  378                     forControlEvents:UIControlEventValueChanged]; | 
|  385   } |  379   } | 
|  386   return cell; |  380   return cell; | 
|  387 } |  381 } | 
|  388  |  382  | 
|  389 #pragma mark - BooleanObserver |  383 #pragma mark - BooleanObserver | 
|  390  |  384  | 
|  391 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { |  385 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { | 
|  392   DCHECK_EQ(observableBoolean, passwordManagerEnabled_.get()); |  386   DCHECK_EQ(observableBoolean, passwordManagerEnabled_); | 
|  393  |  387  | 
|  394   // Update the item. |  388   // Update the item. | 
|  395   savePasswordsItem_.get().on = [passwordManagerEnabled_ value]; |  389   savePasswordsItem_.on = [passwordManagerEnabled_ value]; | 
|  396  |  390  | 
|  397   // Update the cell. |  391   // Update the cell. | 
|  398   [self reconfigureCellsForItems:@[ savePasswordsItem_ ]]; |  392   [self reconfigureCellsForItems:@[ savePasswordsItem_ ]]; | 
|  399  |  393  | 
|  400   // Update the rest of the UI. |  394   // Update the rest of the UI. | 
|  401   [self.editor setEditing:NO]; |  395   [self.editor setEditing:NO]; | 
|  402   [self updateEditButton]; |  396   [self updateEditButton]; | 
|  403   [self reloadData]; |  397   [self reloadData]; | 
|  404 } |  398 } | 
|  405  |  399  | 
|  406 #pragma mark - Actions |  400 #pragma mark - Actions | 
|  407  |  401  | 
|  408 - (void)savePasswordsSwitchChanged:(UISwitch*)switchView { |  402 - (void)savePasswordsSwitchChanged:(UISwitch*)switchView { | 
|  409   // Update the setting. |  403   // Update the setting. | 
|  410   [passwordManagerEnabled_ setValue:switchView.on]; |  404   [passwordManagerEnabled_ setValue:switchView.on]; | 
|  411  |  405  | 
|  412   // Update the item. |  406   // Update the item. | 
|  413   savePasswordsItem_.get().on = [passwordManagerEnabled_ value]; |  407   savePasswordsItem_.on = [passwordManagerEnabled_ value]; | 
|  414  |  408  | 
|  415   // Update the rest of the UI. |  409   // Update the rest of the UI. | 
|  416   [self.editor setEditing:NO]; |  410   [self.editor setEditing:NO]; | 
|  417   [self updateEditButton]; |  411   [self updateEditButton]; | 
|  418   [self reloadData]; |  412   [self reloadData]; | 
|  419 } |  413 } | 
|  420  |  414  | 
|  421 #pragma mark - Private methods |  415 #pragma mark - Private methods | 
|  422  |  416  | 
|  423 - (void)getLoginsFromPasswordStore { |  417 - (void)getLoginsFromPasswordStore { | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  468   if ([model itemTypeForIndexPath:indexPath] == ItemTypeSavedPassword) { |  462   if ([model itemTypeForIndexPath:indexPath] == ItemTypeSavedPassword) { | 
|  469     DCHECK_EQ([model sectionIdentifierForSection:indexPath.section], |  463     DCHECK_EQ([model sectionIdentifierForSection:indexPath.section], | 
|  470               SectionIdentifierSavedPasswords); |  464               SectionIdentifierSavedPasswords); | 
|  471     if (experimental_flags::IsViewCopyPasswordsEnabled()) { |  465     if (experimental_flags::IsViewCopyPasswordsEnabled()) { | 
|  472       DCHECK_LT(base::checked_cast<size_t>(indexPath.item), savedForms_.size()); |  466       DCHECK_LT(base::checked_cast<size_t>(indexPath.item), savedForms_.size()); | 
|  473       autofill::PasswordForm* form = savedForms_[indexPath.item].get(); |  467       autofill::PasswordForm* form = savedForms_[indexPath.item].get(); | 
|  474       NSString* username = base::SysUTF16ToNSString(form->username_value); |  468       NSString* username = base::SysUTF16ToNSString(form->username_value); | 
|  475       NSString* password = base::SysUTF16ToNSString(form->password_value); |  469       NSString* password = base::SysUTF16ToNSString(form->password_value); | 
|  476       NSString* origin = |  470       NSString* origin = | 
|  477           base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); |  471           base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); | 
|  478       base::scoped_nsobject<UIViewController> controller( |  472       UIViewController* controller = | 
|  479           [[PasswordDetailsCollectionViewController alloc] |  473           [[PasswordDetailsCollectionViewController alloc] | 
|  480                 initWithPasswordForm:*form |  474                 initWithPasswordForm:*form | 
|  481                             delegate:self |  475                             delegate:self | 
|  482               reauthenticationModule:reauthenticationModule_ |  476               reauthenticationModule:reauthenticationModule_ | 
|  483                             username:username |  477                             username:username | 
|  484                             password:password |  478                             password:password | 
|  485                               origin:origin]); |  479                               origin:origin]; | 
|  486       [self.navigationController pushViewController:controller animated:YES]; |  480       [self.navigationController pushViewController:controller animated:YES]; | 
|  487     } |  481     } | 
|  488   } |  482   } | 
|  489 } |  483 } | 
|  490  |  484  | 
|  491 #pragma mark MDCCollectionViewEditingDelegate |  485 #pragma mark MDCCollectionViewEditingDelegate | 
|  492  |  486  | 
|  493 - (BOOL)collectionView:(UICollectionView*)collectionView |  487 - (BOOL)collectionView:(UICollectionView*)collectionView | 
|  494     canEditItemAtIndexPath:(NSIndexPath*)indexPath { |  488     canEditItemAtIndexPath:(NSIndexPath*)indexPath { | 
|  495   // Only password cells are editable. |  489   // Only password cells are editable. | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  542   NSMutableOrderedSet* sectionsToRemove = [NSMutableOrderedSet orderedSet]; |  536   NSMutableOrderedSet* sectionsToRemove = [NSMutableOrderedSet orderedSet]; | 
|  543   // Sort and enumerate in reverse order to delete the items from the collection |  537   // Sort and enumerate in reverse order to delete the items from the collection | 
|  544   // view model. |  538   // view model. | 
|  545   NSArray* sortedIndexPaths = |  539   NSArray* sortedIndexPaths = | 
|  546       [indexPaths sortedArrayUsingSelector:@selector(compare:)]; |  540       [indexPaths sortedArrayUsingSelector:@selector(compare:)]; | 
|  547   for (NSIndexPath* indexPath in [sortedIndexPaths reverseObjectEnumerator]) { |  541   for (NSIndexPath* indexPath in [sortedIndexPaths reverseObjectEnumerator]) { | 
|  548     if ([collectionView numberOfItemsInSection:indexPath.section] == 0) { |  542     if ([collectionView numberOfItemsInSection:indexPath.section] == 0) { | 
|  549       [sectionsToRemove addObject:@(indexPath.section)]; |  543       [sectionsToRemove addObject:@(indexPath.section)]; | 
|  550     } |  544     } | 
|  551   } |  545   } | 
|  552   base::WeakNSObject<SavePasswordsCollectionViewController> weakSelf(self); |  546   __weak SavePasswordsCollectionViewController* weakSelf = self; | 
|  553   [self.collectionView performBatchUpdates:^{ |  547   [self.collectionView performBatchUpdates:^{ | 
|  554     base::scoped_nsobject<SavePasswordsCollectionViewController> strongSelf( |  548     SavePasswordsCollectionViewController* strongSelf = weakSelf; | 
|  555         [weakSelf retain]); |  | 
|  556     if (!strongSelf) |  549     if (!strongSelf) | 
|  557       return; |  550       return; | 
|  558     for (NSNumber* sectionNumber in sectionsToRemove) { |  551     for (NSNumber* sectionNumber in sectionsToRemove) { | 
|  559       NSInteger section = [sectionNumber integerValue]; |  552       NSInteger section = [sectionNumber integerValue]; | 
|  560       NSInteger sectionIdentifier = [[strongSelf collectionViewModel] |  553       NSInteger sectionIdentifier = [[strongSelf collectionViewModel] | 
|  561           sectionIdentifierForSection:section]; |  554           sectionIdentifierForSection:section]; | 
|  562       [[strongSelf collectionViewModel] |  555       [[strongSelf collectionViewModel] | 
|  563           removeSectionWithIdentifier:sectionIdentifier]; |  556           removeSectionWithIdentifier:sectionIdentifier]; | 
|  564       [[strongSelf collectionView] |  557       [[strongSelf collectionView] | 
|  565           deleteSections:[NSIndexSet indexSetWithIndex:section]]; |  558           deleteSections:[NSIndexSet indexSetWithIndex:section]]; | 
|  566     } |  559     } | 
|  567   } |  560   } | 
|  568       completion:^(BOOL finished) { |  561       completion:^(BOOL finished) { | 
|  569         base::scoped_nsobject<SavePasswordsCollectionViewController> strongSelf( |  562         SavePasswordsCollectionViewController* strongSelf = weakSelf; | 
|  570             [weakSelf retain]); |  | 
|  571         if (!strongSelf) |  563         if (!strongSelf) | 
|  572           return; |  564           return; | 
|  573         if (![strongSelf editButtonEnabled]) { |  565         if (![strongSelf editButtonEnabled]) { | 
|  574           [strongSelf setEditing:NO]; |  566           [strongSelf setEditing:NO]; | 
|  575         } |  567         } | 
|  576         [strongSelf updateEditButton]; |  568         [strongSelf updateEditButton]; | 
|  577       }]; |  569       }]; | 
|  578 } |  570 } | 
|  579  |  571  | 
|  580 #pragma mark PasswordDetailsCollectionViewControllerDelegate |  572 #pragma mark PasswordDetailsCollectionViewControllerDelegate | 
|  581  |  573  | 
|  582 - (void)deletePassword:(const autofill::PasswordForm&)form { |  574 - (void)deletePassword:(const autofill::PasswordForm&)form { | 
|  583   passwordStore_->RemoveLogin(form); |  575   passwordStore_->RemoveLogin(form); | 
|  584   for (auto it = savedForms_.begin(); it != savedForms_.end(); ++it) { |  576   for (auto it = savedForms_.begin(); it != savedForms_.end(); ++it) { | 
|  585     if (**it == form) { |  577     if (**it == form) { | 
|  586       savedForms_.erase(it); |  578       savedForms_.erase(it); | 
|  587       return; |  579       return; | 
|  588     } |  580     } | 
|  589   } |  581   } | 
|  590   [self.navigationController popViewControllerAnimated:YES]; |  582   [self.navigationController popViewControllerAnimated:YES]; | 
|  591 } |  583 } | 
|  592  |  584  | 
|  593 #pragma mark SuccessfulReauthTimeAccessor |  585 #pragma mark SuccessfulReauthTimeAccessor | 
|  594  |  586  | 
|  595 - (void)updateSuccessfulReauthTime { |  587 - (void)updateSuccessfulReauthTime { | 
|  596   successfulReauthTime_.reset([[NSDate alloc] init]); |  588   successfulReauthTime_ = [[NSDate alloc] init]; | 
|  597 } |  589 } | 
|  598  |  590  | 
|  599 - (NSDate*)lastSuccessfulReauthTime { |  591 - (NSDate*)lastSuccessfulReauthTime { | 
|  600   return successfulReauthTime_.get(); |  592   return successfulReauthTime_; | 
|  601 } |  593 } | 
|  602  |  594  | 
|  603 @end |  595 @end | 
| OLD | NEW |