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 inSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch]; | 393 inSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch]; |
400 | 394 |
401 // Update the rest of the UI. | 395 // Update the rest of the UI. |
402 [self.editor setEditing:NO]; | 396 [self.editor setEditing:NO]; |
403 [self updateEditButton]; | 397 [self updateEditButton]; |
404 [self reloadData]; | 398 [self reloadData]; |
405 } | 399 } |
406 | 400 |
407 #pragma mark - Actions | 401 #pragma mark - Actions |
408 | 402 |
409 - (void)savePasswordsSwitchChanged:(UISwitch*)switchView { | 403 - (void)savePasswordsSwitchChanged:(UISwitch*)switchView { |
410 // Update the setting. | 404 // Update the setting. |
411 [passwordManagerEnabled_ setValue:switchView.on]; | 405 [passwordManagerEnabled_ setValue:switchView.on]; |
412 | 406 |
413 // Update the item. | 407 // Update the item. |
414 savePasswordsItem_.get().on = [passwordManagerEnabled_ value]; | 408 savePasswordsItem_.on = [passwordManagerEnabled_ value]; |
415 | 409 |
416 // Update the rest of the UI. | 410 // Update the rest of the UI. |
417 [self.editor setEditing:NO]; | 411 [self.editor setEditing:NO]; |
418 [self updateEditButton]; | 412 [self updateEditButton]; |
419 [self reloadData]; | 413 [self reloadData]; |
420 } | 414 } |
421 | 415 |
422 #pragma mark - Private methods | 416 #pragma mark - Private methods |
423 | 417 |
424 - (void)getLoginsFromPasswordStore { | 418 - (void)getLoginsFromPasswordStore { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 if ([model itemTypeForIndexPath:indexPath] == ItemTypeSavedPassword) { | 463 if ([model itemTypeForIndexPath:indexPath] == ItemTypeSavedPassword) { |
470 DCHECK_EQ([model sectionIdentifierForSection:indexPath.section], | 464 DCHECK_EQ([model sectionIdentifierForSection:indexPath.section], |
471 SectionIdentifierSavedPasswords); | 465 SectionIdentifierSavedPasswords); |
472 if (experimental_flags::IsViewCopyPasswordsEnabled()) { | 466 if (experimental_flags::IsViewCopyPasswordsEnabled()) { |
473 DCHECK_LT(base::checked_cast<size_t>(indexPath.item), savedForms_.size()); | 467 DCHECK_LT(base::checked_cast<size_t>(indexPath.item), savedForms_.size()); |
474 autofill::PasswordForm* form = savedForms_[indexPath.item].get(); | 468 autofill::PasswordForm* form = savedForms_[indexPath.item].get(); |
475 NSString* username = base::SysUTF16ToNSString(form->username_value); | 469 NSString* username = base::SysUTF16ToNSString(form->username_value); |
476 NSString* password = base::SysUTF16ToNSString(form->password_value); | 470 NSString* password = base::SysUTF16ToNSString(form->password_value); |
477 NSString* origin = | 471 NSString* origin = |
478 base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); | 472 base::SysUTF8ToNSString(GetHumanReadableOriginCopy(*form)); |
479 base::scoped_nsobject<UIViewController> controller( | 473 UIViewController* controller = |
480 [[PasswordDetailsCollectionViewController alloc] | 474 [[PasswordDetailsCollectionViewController alloc] |
481 initWithPasswordForm:*form | 475 initWithPasswordForm:*form |
482 delegate:self | 476 delegate:self |
483 reauthenticationModule:reauthenticationModule_ | 477 reauthenticationModule:reauthenticationModule_ |
484 username:username | 478 username:username |
485 password:password | 479 password:password |
486 origin:origin]); | 480 origin:origin]; |
487 [self.navigationController pushViewController:controller animated:YES]; | 481 [self.navigationController pushViewController:controller animated:YES]; |
488 } | 482 } |
489 } | 483 } |
490 } | 484 } |
491 | 485 |
492 #pragma mark MDCCollectionViewEditingDelegate | 486 #pragma mark MDCCollectionViewEditingDelegate |
493 | 487 |
494 - (BOOL)collectionView:(UICollectionView*)collectionView | 488 - (BOOL)collectionView:(UICollectionView*)collectionView |
495 canEditItemAtIndexPath:(NSIndexPath*)indexPath { | 489 canEditItemAtIndexPath:(NSIndexPath*)indexPath { |
496 // Only password cells are editable. | 490 // Only password cells are editable. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 NSMutableOrderedSet* sectionsToRemove = [NSMutableOrderedSet orderedSet]; | 537 NSMutableOrderedSet* sectionsToRemove = [NSMutableOrderedSet orderedSet]; |
544 // Sort and enumerate in reverse order to delete the items from the collection | 538 // Sort and enumerate in reverse order to delete the items from the collection |
545 // view model. | 539 // view model. |
546 NSArray* sortedIndexPaths = | 540 NSArray* sortedIndexPaths = |
547 [indexPaths sortedArrayUsingSelector:@selector(compare:)]; | 541 [indexPaths sortedArrayUsingSelector:@selector(compare:)]; |
548 for (NSIndexPath* indexPath in [sortedIndexPaths reverseObjectEnumerator]) { | 542 for (NSIndexPath* indexPath in [sortedIndexPaths reverseObjectEnumerator]) { |
549 if ([collectionView numberOfItemsInSection:indexPath.section] == 0) { | 543 if ([collectionView numberOfItemsInSection:indexPath.section] == 0) { |
550 [sectionsToRemove addObject:@(indexPath.section)]; | 544 [sectionsToRemove addObject:@(indexPath.section)]; |
551 } | 545 } |
552 } | 546 } |
553 base::WeakNSObject<SavePasswordsCollectionViewController> weakSelf(self); | 547 __weak SavePasswordsCollectionViewController* weakSelf = self; |
554 [self.collectionView performBatchUpdates:^{ | 548 [self.collectionView performBatchUpdates:^{ |
555 base::scoped_nsobject<SavePasswordsCollectionViewController> strongSelf( | 549 SavePasswordsCollectionViewController* strongSelf = weakSelf; |
556 [weakSelf retain]); | |
557 if (!strongSelf) | 550 if (!strongSelf) |
558 return; | 551 return; |
559 for (NSNumber* sectionNumber in sectionsToRemove) { | 552 for (NSNumber* sectionNumber in sectionsToRemove) { |
560 NSInteger section = [sectionNumber integerValue]; | 553 NSInteger section = [sectionNumber integerValue]; |
561 NSInteger sectionIdentifier = [[strongSelf collectionViewModel] | 554 NSInteger sectionIdentifier = [[strongSelf collectionViewModel] |
562 sectionIdentifierForSection:section]; | 555 sectionIdentifierForSection:section]; |
563 [[strongSelf collectionViewModel] | 556 [[strongSelf collectionViewModel] |
564 removeSectionWithIdentifier:sectionIdentifier]; | 557 removeSectionWithIdentifier:sectionIdentifier]; |
565 [[strongSelf collectionView] | 558 [[strongSelf collectionView] |
566 deleteSections:[NSIndexSet indexSetWithIndex:section]]; | 559 deleteSections:[NSIndexSet indexSetWithIndex:section]]; |
567 } | 560 } |
568 } | 561 } |
569 completion:^(BOOL finished) { | 562 completion:^(BOOL finished) { |
570 base::scoped_nsobject<SavePasswordsCollectionViewController> strongSelf( | 563 SavePasswordsCollectionViewController* strongSelf = weakSelf; |
571 [weakSelf retain]); | |
572 if (!strongSelf) | 564 if (!strongSelf) |
573 return; | 565 return; |
574 if (![strongSelf editButtonEnabled]) { | 566 if (![strongSelf editButtonEnabled]) { |
575 [strongSelf setEditing:NO]; | 567 [strongSelf setEditing:NO]; |
576 } | 568 } |
577 [strongSelf updateEditButton]; | 569 [strongSelf updateEditButton]; |
578 }]; | 570 }]; |
579 } | 571 } |
580 | 572 |
581 #pragma mark PasswordDetailsCollectionViewControllerDelegate | 573 #pragma mark PasswordDetailsCollectionViewControllerDelegate |
582 | 574 |
583 - (void)deletePassword:(const autofill::PasswordForm&)form { | 575 - (void)deletePassword:(const autofill::PasswordForm&)form { |
584 passwordStore_->RemoveLogin(form); | 576 passwordStore_->RemoveLogin(form); |
585 for (auto it = savedForms_.begin(); it != savedForms_.end(); ++it) { | 577 for (auto it = savedForms_.begin(); it != savedForms_.end(); ++it) { |
586 if (**it == form) { | 578 if (**it == form) { |
587 savedForms_.erase(it); | 579 savedForms_.erase(it); |
588 return; | 580 return; |
589 } | 581 } |
590 } | 582 } |
591 [self.navigationController popViewControllerAnimated:YES]; | 583 [self.navigationController popViewControllerAnimated:YES]; |
592 } | 584 } |
593 | 585 |
594 #pragma mark SuccessfulReauthTimeAccessor | 586 #pragma mark SuccessfulReauthTimeAccessor |
595 | 587 |
596 - (void)updateSuccessfulReauthTime { | 588 - (void)updateSuccessfulReauthTime { |
597 successfulReauthTime_.reset([[NSDate alloc] init]); | 589 successfulReauthTime_ = [[NSDate alloc] init]; |
598 } | 590 } |
599 | 591 |
600 - (NSDate*)lastSuccessfulReauthTime { | 592 - (NSDate*)lastSuccessfulReauthTime { |
601 return successfulReauthTime_.get(); | 593 return successfulReauthTime_; |
602 } | 594 } |
603 | 595 |
604 @end | 596 @end |
OLD | NEW |