Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/autofill/autofill_dialog_controller_mac.mm

Issue 6082001: Autofill saves duplicate profiles and credit card info in preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Credit card and GUID functor. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_dialog_controller_mac.h" 5 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h"
6 #include "app/l10n_util.h" 6 #include "app/l10n_util.h"
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/mac_util.h" 9 #include "base/mac_util.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
11 #import "chrome/browser/autofill/autofill_address_model_mac.h" 11 #import "chrome/browser/autofill/autofill_address_model_mac.h"
12 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" 12 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h"
13 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" 13 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
14 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" 14 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h"
15 #import "chrome/browser/autofill/autofill-inl.h"
15 #import "chrome/browser/autofill/personal_data_manager.h" 16 #import "chrome/browser/autofill/personal_data_manager.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" 18 #import "chrome/browser/ui/cocoa/window_size_autosaver.h"
18 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/common/notification_details.h" 23 #include "chrome/common/notification_details.h"
23 #include "chrome/common/notification_observer.h" 24 #include "chrome/common/notification_observer.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Asyncronous handler for when PersonalDataManager data changes. The 88 // Asyncronous handler for when PersonalDataManager data changes. The
88 // personal data manager notifies the dialog with this method when the 89 // personal data manager notifies the dialog with this method when the
89 // data has changed. 90 // data has changed.
90 - (void)onPersonalDataChanged:(const std::vector<AutoFillProfile*>&)profiles 91 - (void)onPersonalDataChanged:(const std::vector<AutoFillProfile*>&)profiles
91 creditCards:(const std::vector<CreditCard*>&)creditCards; 92 creditCards:(const std::vector<CreditCard*>&)creditCards;
92 93
93 // Called upon changes to AutoFill preferences that should be reflected in the 94 // Called upon changes to AutoFill preferences that should be reflected in the
94 // UI. 95 // UI.
95 - (void)preferenceDidChange:(const std::string&)preferenceName; 96 - (void)preferenceDidChange:(const std::string&)preferenceName;
96 97
98 // Adjust the selected index when underlying data changes.
99 // Selects the previous row if possible, else current row, else deselect all.
100 - (void) adjustSelectionOnDelete:(NSInteger)selectedRow;
101
102 // Adjust the selected index when underlying data changes.
103 // Selects the current row if possible, else previous row, else deselect all.
104 - (void) adjustSelectionOnReload:(NSInteger)selectedRow;
105
97 // Returns true if |row| is an index to a valid profile in |tableView_|, and 106 // Returns true if |row| is an index to a valid profile in |tableView_|, and
98 // false otherwise. 107 // false otherwise.
99 - (BOOL)isProfileRow:(NSInteger)row; 108 - (BOOL)isProfileRow:(NSInteger)row;
100 109
101 // Returns true if |row| is an index to the profile group row in |tableView_|, 110 // Returns true if |row| is an index to the profile group row in |tableView_|,
102 // and false otherwise. 111 // and false otherwise.
103 - (BOOL)isProfileGroupRow:(NSInteger)row; 112 - (BOOL)isProfileGroupRow:(NSInteger)row;
104 113
105 // Returns true if |row| is an index to a valid credit card in |tableView_|, and 114 // Returns true if |row| is an index to a valid credit card in |tableView_|, and
106 // false otherwise. 115 // false otherwise.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // Add address sheet was dismissed. Non-zero |returnCode| indicates a save. 334 // Add address sheet was dismissed. Non-zero |returnCode| indicates a save.
326 - (void)addressAddDidEnd:(NSWindow*)sheet 335 - (void)addressAddDidEnd:(NSWindow*)sheet
327 returnCode:(int)returnCode 336 returnCode:(int)returnCode
328 contextInfo:(void*)contextInfo { 337 contextInfo:(void*)contextInfo {
329 DCHECK(contextInfo == NULL); 338 DCHECK(contextInfo == NULL);
330 339
331 if (returnCode) { 340 if (returnCode) {
332 // Create a new address and save it to the |profiles_| list. 341 // Create a new address and save it to the |profiles_| list.
333 AutoFillProfile newAddress; 342 AutoFillProfile newAddress;
334 [addressSheetController copyModelToProfile:&newAddress]; 343 [addressSheetController copyModelToProfile:&newAddress];
335 if (!newAddress.IsEmpty()) { 344 if (!newAddress.IsEmpty() && !FindByContents(profiles_, newAddress)) {
336 profiles_.push_back(newAddress); 345 profiles_.push_back(newAddress);
337 346
338 // Saving will save to the PDM and the table will refresh when PDM sends 347 // Saving will save to the PDM and the table will refresh when PDM sends
339 // notification that the underlying model has changed. 348 // notification that the underlying model has changed.
340 [self save]; 349 [self save];
341 350
342 // Update the selection to the newly added item. 351 // Update the selection to the newly added item.
343 NSInteger row = [self rowFromProfileIndex:profiles_.size() - 1]; 352 NSInteger row = [self rowFromProfileIndex:profiles_.size() - 1];
344 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] 353 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
345 byExtendingSelection:NO]; 354 byExtendingSelection:NO];
346 } 355 }
347 } 356 }
348 [sheet orderOut:self]; 357 [sheet orderOut:self];
349 addressSheetController.reset(nil); 358 addressSheetController.reset(nil);
350 } 359 }
351 360
352 // Add credit card sheet was dismissed. Non-zero |returnCode| indicates a save. 361 // Add credit card sheet was dismissed. Non-zero |returnCode| indicates a save.
353 - (void)creditCardAddDidEnd:(NSWindow *)sheet 362 - (void)creditCardAddDidEnd:(NSWindow *)sheet
354 returnCode:(int)returnCode 363 returnCode:(int)returnCode
355 contextInfo:(void *)contextInfo { 364 contextInfo:(void *)contextInfo {
356 DCHECK(contextInfo == NULL); 365 DCHECK(contextInfo == NULL);
357 366
358 if (returnCode) { 367 if (returnCode) {
359 // Create a new credit card and save it to the |creditCards_| list. 368 // Create a new credit card and save it to the |creditCards_| list.
360 CreditCard newCreditCard; 369 CreditCard newCreditCard;
361 [creditCardSheetController copyModelToCreditCard:&newCreditCard]; 370 [creditCardSheetController copyModelToCreditCard:&newCreditCard];
362 if (!newCreditCard.IsEmpty()) { 371 if (!newCreditCard.IsEmpty() &&
372 !FindByContents(creditCards_, newCreditCard)) {
363 creditCards_.push_back(newCreditCard); 373 creditCards_.push_back(newCreditCard);
364 374
365 // Saving will save to the PDM and the table will refresh when PDM sends 375 // Saving will save to the PDM and the table will refresh when PDM sends
366 // notification that the underlying model has changed. 376 // notification that the underlying model has changed.
367 [self save]; 377 [self save];
368 378
369 // Update the selection to the newly added item. 379 // Update the selection to the newly added item.
370 NSInteger row = [self rowFromCreditCardIndex:creditCards_.size() - 1]; 380 NSInteger row = [self rowFromCreditCardIndex:creditCards_.size() - 1];
371 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] 381 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
372 byExtendingSelection:NO]; 382 byExtendingSelection:NO];
(...skipping 20 matching lines...) Expand all
393 if ([self isProfileRow:i]) { 403 if ([self isProfileRow:i]) {
394 profiles_.erase( 404 profiles_.erase(
395 profiles_.begin() + [self profileIndexFromRow:i]); 405 profiles_.begin() + [self profileIndexFromRow:i]);
396 } else if ([self isCreditCardRow:i]) { 406 } else if ([self isCreditCardRow:i]) {
397 creditCards_.erase( 407 creditCards_.erase(
398 creditCards_.begin() + [self creditCardIndexFromRow:i]); 408 creditCards_.begin() + [self creditCardIndexFromRow:i]);
399 } 409 }
400 } 410 }
401 411
402 // Select the previous row if possible, else current row, else deselect all. 412 // Select the previous row if possible, else current row, else deselect all.
403 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { 413 [self adjustSelectionOnDelete:selectedRow];
404 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
405 byExtendingSelection:NO];
406 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
407 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
408 byExtendingSelection:NO];
409 } else {
410 [tableView_ deselectAll:self];
411 }
412 414
413 // Saving will save to the PDM and the table will refresh when PDM sends 415 // Saving will save to the PDM and the table will refresh when PDM sends
414 // notification that the underlying model has changed. 416 // notification that the underlying model has changed.
415 [self save]; 417 [self save];
416 } 418 }
417 419
418 // Edits the selected item, either address or credit card depending on the item 420 // Edits the selected item, either address or credit card depending on the item
419 // selected. 421 // selected.
420 - (IBAction)editSelection:(id)sender { 422 - (IBAction)editSelection:(id)sender {
421 NSInteger selectedRow = [tableView_ selectedRow]; 423 NSInteger selectedRow = [tableView_ selectedRow];
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); 794 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
793 iter != profiles.end(); ++iter) 795 iter != profiles.end(); ++iter)
794 profiles_.push_back(**iter); 796 profiles_.push_back(**iter);
795 797
796 // Make local copy of |creditCards|. 798 // Make local copy of |creditCards|.
797 creditCards_.clear(); 799 creditCards_.clear();
798 for (std::vector<CreditCard*>::const_iterator iter = creditCards.begin(); 800 for (std::vector<CreditCard*>::const_iterator iter = creditCards.begin();
799 iter != creditCards.end(); ++iter) 801 iter != creditCards.end(); ++iter)
800 creditCards_.push_back(**iter); 802 creditCards_.push_back(**iter);
801 803
804 [self adjustSelectionOnReload:[tableView_ selectedRow]];
802 [tableView_ reloadData]; 805 [tableView_ reloadData];
803 } 806 }
804 807
805 - (void)preferenceDidChange:(const std::string&)preferenceName { 808 - (void)preferenceDidChange:(const std::string&)preferenceName {
806 if (preferenceName == prefs::kAutoFillEnabled) { 809 if (preferenceName == prefs::kAutoFillEnabled) {
807 [self setAutoFillEnabled:autoFillEnabled_.GetValue()]; 810 [self setAutoFillEnabled:autoFillEnabled_.GetValue()];
808 [self setAutoFillManaged:autoFillEnabled_.IsManaged()]; 811 [self setAutoFillManaged:autoFillEnabled_.IsManaged()];
809 [self setAutoFillManagedAndDisabled: 812 [self setAutoFillManagedAndDisabled:
810 autoFillEnabled_.IsManaged() && !autoFillEnabled_.GetValue()]; 813 autoFillEnabled_.IsManaged() && !autoFillEnabled_.GetValue()];
811 } else if (preferenceName == prefs::kAutoFillAuxiliaryProfilesEnabled) { 814 } else if (preferenceName == prefs::kAutoFillAuxiliaryProfilesEnabled) {
812 [self setAuxiliaryEnabled:auxiliaryEnabled_.GetValue()]; 815 [self setAuxiliaryEnabled:auxiliaryEnabled_.GetValue()];
813 } else { 816 } else {
814 NOTREACHED(); 817 NOTREACHED();
815 } 818 }
816 } 819 }
817 820
821 - (void) adjustSelectionOnDelete:(NSInteger)selectedRow {
822 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
823 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
824 byExtendingSelection:NO];
825 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
826 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
827 byExtendingSelection:NO];
828 } else {
829 [tableView_ deselectAll:self];
830 }
831 }
832
833 - (void) adjustSelectionOnReload:(NSInteger)selectedRow {
834 if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
835 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
836 byExtendingSelection:NO];
837 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
838 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
839 byExtendingSelection:NO];
840 } else {
841 [tableView_ deselectAll:self];
842 }
843 }
844
818 - (BOOL)isProfileRow:(NSInteger)row { 845 - (BOOL)isProfileRow:(NSInteger)row {
819 if (row > 0 && static_cast<size_t>(row) <= profiles_.size()) 846 if (row > 0 && static_cast<size_t>(row) <= profiles_.size())
820 return YES; 847 return YES;
821 return NO; 848 return NO;
822 } 849 }
823 850
824 - (BOOL)isProfileGroupRow:(NSInteger)row { 851 - (BOOL)isProfileGroupRow:(NSInteger)row {
825 if (row == 0) 852 if (row == 0)
826 return YES; 853 return YES;
827 return NO; 854 return NO;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 if (!image) { 932 if (!image) {
906 image = rb.GetNativeImageNamed(IDR_INPUT_GOOD); 933 image = rb.GetNativeImageNamed(IDR_INPUT_GOOD);
907 DCHECK(image); 934 DCHECK(image);
908 return image; 935 return image;
909 } 936 }
910 937
911 return nil; 938 return nil;
912 } 939 }
913 940
914 @end 941 @end
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill-inl.h ('k') | chrome/browser/autofill/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698