| OLD | NEW | 
|---|
| 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  Loading... | 
| 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  Loading... | 
| 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]; | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 393     if ([self isProfileRow:i]) { | 402     if ([self isProfileRow:i]) { | 
| 394       profiles_.erase( | 403       profiles_.erase( | 
| 395           profiles_.begin() + [self profileIndexFromRow:i]); | 404           profiles_.begin() + [self profileIndexFromRow:i]); | 
| 396     } else if ([self isCreditCardRow:i]) { | 405     } else if ([self isCreditCardRow:i]) { | 
| 397       creditCards_.erase( | 406       creditCards_.erase( | 
| 398           creditCards_.begin() + [self creditCardIndexFromRow:i]); | 407           creditCards_.begin() + [self creditCardIndexFromRow:i]); | 
| 399     } | 408     } | 
| 400   } | 409   } | 
| 401 | 410 | 
| 402   // Select the previous row if possible, else current row, else deselect all. | 411   // Select the previous row if possible, else current row, else deselect all. | 
| 403   if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 412   [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 | 413 | 
| 413   // Saving will save to the PDM and the table will refresh when PDM sends | 414   // Saving will save to the PDM and the table will refresh when PDM sends | 
| 414   // notification that the underlying model has changed. | 415   // notification that the underlying model has changed. | 
| 415   [self save]; | 416   [self save]; | 
| 416 } | 417 } | 
| 417 | 418 | 
| 418 // Edits the selected item, either address or credit card depending on the item | 419 // Edits the selected item, either address or credit card depending on the item | 
| 419 // selected. | 420 // selected. | 
| 420 - (IBAction)editSelection:(id)sender { | 421 - (IBAction)editSelection:(id)sender { | 
| 421   NSInteger selectedRow = [tableView_ selectedRow]; | 422   NSInteger selectedRow = [tableView_ selectedRow]; | 
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 792   for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); | 793   for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); | 
| 793        iter != profiles.end(); ++iter) | 794        iter != profiles.end(); ++iter) | 
| 794     profiles_.push_back(**iter); | 795     profiles_.push_back(**iter); | 
| 795 | 796 | 
| 796   // Make local copy of |creditCards|. | 797   // Make local copy of |creditCards|. | 
| 797   creditCards_.clear(); | 798   creditCards_.clear(); | 
| 798   for (std::vector<CreditCard*>::const_iterator iter = creditCards.begin(); | 799   for (std::vector<CreditCard*>::const_iterator iter = creditCards.begin(); | 
| 799        iter != creditCards.end(); ++iter) | 800        iter != creditCards.end(); ++iter) | 
| 800     creditCards_.push_back(**iter); | 801     creditCards_.push_back(**iter); | 
| 801 | 802 | 
|  | 803   [self adjustSelectionOnReload:[tableView_ selectedRow]]; | 
| 802   [tableView_ reloadData]; | 804   [tableView_ reloadData]; | 
| 803 } | 805 } | 
| 804 | 806 | 
| 805 - (void)preferenceDidChange:(const std::string&)preferenceName { | 807 - (void)preferenceDidChange:(const std::string&)preferenceName { | 
| 806   if (preferenceName == prefs::kAutoFillEnabled) { | 808   if (preferenceName == prefs::kAutoFillEnabled) { | 
| 807     [self setAutoFillEnabled:autoFillEnabled_.GetValue()]; | 809     [self setAutoFillEnabled:autoFillEnabled_.GetValue()]; | 
| 808     [self setAutoFillManaged:autoFillEnabled_.IsManaged()]; | 810     [self setAutoFillManaged:autoFillEnabled_.IsManaged()]; | 
| 809     [self setAutoFillManagedAndDisabled: | 811     [self setAutoFillManagedAndDisabled: | 
| 810         autoFillEnabled_.IsManaged() && !autoFillEnabled_.GetValue()]; | 812         autoFillEnabled_.IsManaged() && !autoFillEnabled_.GetValue()]; | 
| 811   } else if (preferenceName == prefs::kAutoFillAuxiliaryProfilesEnabled) { | 813   } else if (preferenceName == prefs::kAutoFillAuxiliaryProfilesEnabled) { | 
| 812     [self setAuxiliaryEnabled:auxiliaryEnabled_.GetValue()]; | 814     [self setAuxiliaryEnabled:auxiliaryEnabled_.GetValue()]; | 
| 813   } else { | 815   } else { | 
| 814     NOTREACHED(); | 816     NOTREACHED(); | 
| 815   } | 817   } | 
| 816 } | 818 } | 
| 817 | 819 | 
|  | 820 - (void) adjustSelectionOnDelete:(NSInteger)selectedRow { | 
|  | 821   if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 
|  | 822     [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 
|  | 823             byExtendingSelection:NO]; | 
|  | 824   } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 
|  | 825     [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] | 
|  | 826             byExtendingSelection:NO]; | 
|  | 827   } else { | 
|  | 828     [tableView_ deselectAll:self]; | 
|  | 829   } | 
|  | 830 } | 
|  | 831 | 
|  | 832 - (void) adjustSelectionOnReload:(NSInteger)selectedRow { | 
|  | 833   if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 
|  | 834     [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] | 
|  | 835             byExtendingSelection:NO]; | 
|  | 836   } else if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 
|  | 837     [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 
|  | 838             byExtendingSelection:NO]; | 
|  | 839   } else { | 
|  | 840     [tableView_ deselectAll:self]; | 
|  | 841   } | 
|  | 842 } | 
|  | 843 | 
| 818 - (BOOL)isProfileRow:(NSInteger)row { | 844 - (BOOL)isProfileRow:(NSInteger)row { | 
| 819   if (row > 0 && static_cast<size_t>(row) <= profiles_.size()) | 845   if (row > 0 && static_cast<size_t>(row) <= profiles_.size()) | 
| 820     return YES; | 846     return YES; | 
| 821   return NO; | 847   return NO; | 
| 822 } | 848 } | 
| 823 | 849 | 
| 824 - (BOOL)isProfileGroupRow:(NSInteger)row { | 850 - (BOOL)isProfileGroupRow:(NSInteger)row { | 
| 825   if (row == 0) | 851   if (row == 0) | 
| 826     return YES; | 852     return YES; | 
| 827   return NO; | 853   return NO; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 905   if (!image) { | 931   if (!image) { | 
| 906     image = rb.GetNativeImageNamed(IDR_INPUT_GOOD); | 932     image = rb.GetNativeImageNamed(IDR_INPUT_GOOD); | 
| 907     DCHECK(image); | 933     DCHECK(image); | 
| 908     return image; | 934     return image; | 
| 909   } | 935   } | 
| 910 | 936 | 
| 911   return nil; | 937   return nil; | 
| 912 } | 938 } | 
| 913 | 939 | 
| 914 @end | 940 @end | 
| OLD | NEW | 
|---|