diff options
9 files changed, 16 insertions, 452 deletions
diff --git a/chrome/app/nibs/AutoFillAddressFormView.xib b/chrome/app/nibs/AutoFillAddressFormView.xib index 434e467..6104810 100644 --- a/chrome/app/nibs/AutoFillAddressFormView.xib +++ b/chrome/app/nibs/AutoFillAddressFormView.xib @@ -632,33 +632,6 @@ <int key="NSPeriodicInterval">25</int> </object> </object> - <object class="NSButton" id="484404016"> - <reference key="NSNextResponder" ref="195575826"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{175, 350}, {240, 18}}</string> - <reference key="NSSuperview" ref="195575826"/> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="252380842"> - <int key="NSCellFlags">-2080244224</int> - <int key="NSCellFlags2">131072</int> - <string key="NSContents">^IDS_AUTOFILL_DIALOG_MAKE_DEFAULT</string> - <reference key="NSSupport" ref="26"/> - <reference key="NSControlView" ref="484404016"/> - <int key="NSButtonFlags">1211912703</int> - <int key="NSButtonFlags2">130</int> - <object class="NSCustomResource" key="NSNormalImage"> - <string key="NSClassName">NSImage</string> - <string key="NSResourceName">NSRadioButton</string> - </object> - <object class="NSButtonImageSource" key="NSAlternateImage"> - <string key="NSImageName">NSRadioButton</string> - </object> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">200</int> - <int key="NSPeriodicInterval">25</int> - </object> - </object> </object> <string key="NSFrame">{{1, 1}, {482, 399}}</string> <reference key="NSSuperview" ref="556992356"/> @@ -934,38 +907,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> - <string key="label">enabled: canAlterDefault</string> - <reference key="source" ref="484404016"/> - <reference key="destination" ref="1001"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="484404016"/> - <reference key="NSDestination" ref="1001"/> - <string key="NSLabel">enabled: canAlterDefault</string> - <string key="NSBinding">enabled</string> - <string key="NSKeyPath">canAlterDefault</string> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">221</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: isDefault</string> - <reference key="source" ref="484404016"/> - <reference key="destination" ref="1001"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="484404016"/> - <reference key="NSDestination" ref="1001"/> - <string key="NSLabel">value: isDefault</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">isDefault</string> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">223</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> <string key="label">value: addressModel.addressCity</string> <reference key="source" ref="357318770"/> <reference key="destination" ref="1001"/> @@ -1178,7 +1119,6 @@ <reference ref="467266453"/> <reference ref="115971484"/> <reference ref="164512976"/> - <reference ref="484404016"/> </object> <reference key="parent" ref="70311064"/> </object> @@ -1593,20 +1533,6 @@ <reference key="object" ref="787258833"/> <reference key="parent" ref="164512976"/> </object> - <object class="IBObjectRecord"> - <int key="objectID">218</int> - <reference key="object" ref="484404016"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="252380842"/> - </object> - <reference key="parent" ref="556992356"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">219</int> - <reference key="object" ref="252380842"/> - <reference key="parent" ref="484404016"/> - </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -1631,8 +1557,6 @@ <string>21.IBPluginDependency</string> <string>215.IBPluginDependency</string> <string>216.IBPluginDependency</string> - <string>218.IBPluginDependency</string> - <string>219.IBPluginDependency</string> <string>22.CustomClassName</string> <string>22.IBPluginDependency</string> <string>23.IBPluginDependency</string> @@ -1721,8 +1645,6 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>AutoFillTextField</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1893,6 +1815,13 @@ <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/objc_zombie.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> <string key="minorKey">browser/cocoa/status_bubble_mac.h</string> </object> </object> diff --git a/chrome/app/nibs/AutoFillCreditCardFormView.xib b/chrome/app/nibs/AutoFillCreditCardFormView.xib index 14e0cd1..e432767 100644 --- a/chrome/app/nibs/AutoFillCreditCardFormView.xib +++ b/chrome/app/nibs/AutoFillCreditCardFormView.xib @@ -3,7 +3,7 @@ <data> <int key="IBDocument.SystemTarget">1050</int> <string key="IBDocument.SystemVersion">9L31a</string> - <string key="IBDocument.InterfaceBuilderVersion">677</string> + <string key="IBDocument.InterfaceBuilderVersion">680</string> <string key="IBDocument.AppKitVersion">949.54</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> @@ -521,33 +521,6 @@ <int key="NSPeriodicInterval">25</int> </object> </object> - <object class="NSButton" id="953837558"> - <reference key="NSNextResponder" ref="1034866434"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{173, 248}, {240, 18}}</string> - <reference key="NSSuperview" ref="1034866434"/> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="183105156"> - <int key="NSCellFlags">-2080244224</int> - <int key="NSCellFlags2">131072</int> - <string key="NSContents">^IDS_AUTOFILL_DIALOG_MAKE_DEFAULT</string> - <reference key="NSSupport" ref="26"/> - <reference key="NSControlView" ref="953837558"/> - <int key="NSButtonFlags">1211912703</int> - <int key="NSButtonFlags2">130</int> - <object class="NSCustomResource" key="NSNormalImage"> - <string key="NSClassName">NSImage</string> - <string key="NSResourceName">NSRadioButton</string> - </object> - <object class="NSButtonImageSource" key="NSAlternateImage"> - <string key="NSImageName">NSRadioButton</string> - </object> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">200</int> - <int key="NSPeriodicInterval">25</int> - </object> - </object> </object> <string key="NSFrame">{{1, 1}, {482, 297}}</string> <reference key="NSSuperview" ref="436522406"/> @@ -878,38 +851,6 @@ </object> <int key="connectionID">200</int> </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">enabled: canAlterDefault</string> - <reference key="source" ref="953837558"/> - <reference key="destination" ref="1001"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="953837558"/> - <reference key="NSDestination" ref="1001"/> - <string key="NSLabel">enabled: canAlterDefault</string> - <string key="NSBinding">enabled</string> - <string key="NSKeyPath">canAlterDefault</string> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">206</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: isDefault</string> - <reference key="source" ref="953837558"/> - <reference key="destination" ref="1001"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="953837558"/> - <reference key="NSDestination" ref="1001"/> - <string key="NSLabel">value: isDefault</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">isDefault</string> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">208</int> - </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -1015,7 +956,6 @@ <reference ref="731633316"/> <reference ref="289669180"/> <reference ref="415706256"/> - <reference ref="953837558"/> </object> <reference key="parent" ref="70311064"/> </object> @@ -1313,20 +1253,6 @@ <reference key="object" ref="632393829"/> <reference key="parent" ref="1002"/> </object> - <object class="IBObjectRecord"> - <int key="objectID">201</int> - <reference key="object" ref="953837558"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="183105156"/> - </object> - <reference key="parent" ref="436522406"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">202</int> - <reference key="object" ref="183105156"/> - <reference key="parent" ref="953837558"/> - </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -1362,8 +1288,6 @@ <string>183.IBPluginDependency</string> <string>19.IBPluginDependency</string> <string>20.IBPluginDependency</string> - <string>201.IBPluginDependency</string> - <string>202.IBPluginDependency</string> <string>21.IBPluginDependency</string> <string>22.CustomClassName</string> <string>22.IBPluginDependency</string> @@ -1427,8 +1351,6 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>AutoFillTextField</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1590,6 +1512,13 @@ <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/objc_zombie.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> <string key="minorKey">browser/cocoa/status_bubble_mac.h</string> </object> </object> diff --git a/chrome/browser/autofill/autofill_address_view_controller_mac.h b/chrome/browser/autofill/autofill_address_view_controller_mac.h index cdbb899..2367f8d 100644 --- a/chrome/browser/autofill/autofill_address_view_controller_mac.h +++ b/chrome/browser/autofill/autofill_address_view_controller_mac.h @@ -31,8 +31,6 @@ class AutoFillProfile; AutoFillDialogController* parentController_; } -@property (readonly) BOOL canAlterDefault; -@property BOOL isDefault; @property (nonatomic, retain) AutoFillAddressModel* addressModel; // Designated initializer. Takes a copy of the data in |profile|, diff --git a/chrome/browser/autofill/autofill_address_view_controller_mac.mm b/chrome/browser/autofill/autofill_address_view_controller_mac.mm index dcf8a12..e3163f8 100644 --- a/chrome/browser/autofill/autofill_address_view_controller_mac.mm +++ b/chrome/browser/autofill/autofill_address_view_controller_mac.mm @@ -12,8 +12,6 @@ @interface AutoFillAddressViewController (PrivateMethods) - (void)labelChanged:(GTMKeyValueChangeNotification*)notification; -- (void)addressesChanged:(GTMKeyValueChangeNotification*)notification; -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification; @end @implementation AutoFillAddressViewController @@ -38,22 +36,12 @@ parentController_ = parentController; // Register |self| as observer so we can notify parent controller. See - // |observeValueForKeyPath:| for details. + // |labelChanged:| for details. [addressModel_ gtm_addObserver:self forKeyPath:@"label" selector:@selector(labelChanged:) userInfo:nil options:0]; - [parentController_ gtm_addObserver:self - forKeyPath:@"addressLabels" - selector:@selector(addressesChanged:) - userInfo:nil - options:0]; - [parentController_ gtm_addObserver:self - forKeyPath:@"defaultAddressLabel" - selector:@selector(defaultChanged:) - userInfo:nil - options:0]; } return self; } @@ -62,12 +50,6 @@ [addressModel_ gtm_removeObserver:self forKeyPath:@"label" selector:@selector(labelChanged:)]; - [parentController_ gtm_removeObserver:self - forKeyPath:@"addressLabels" - selector:@selector(addressesChanged:)]; - [parentController_ gtm_removeObserver:self - forKeyPath:@"defaultAddressLabel" - selector:@selector(defaultChanged:)]; [addressModel_ release]; [super dealloc]; } @@ -78,16 +60,6 @@ [parentController_ notifyAddressChange:self]; } -- (void)addressesChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"canAlterDefault"]; - [self didChangeValueForKey:@"canAlterDefault"]; -} - -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"isDefault"]; - [self didChangeValueForKey:@"isDefault"]; -} - - (IBAction)deleteAddress:(id)sender { [parentController_ deleteAddress:self]; } @@ -96,19 +68,6 @@ [addressModel_ copyModelToProfile:profile]; } -- (BOOL)canAlterDefault { - return [[parentController_ addressLabels] count] > 1; -} - -- (BOOL)isDefault { - return - [[addressModel_ label] isEqual:[parentController_ defaultAddressLabel]]; -} - -- (void)setIsDefault:(BOOL)def { - [parentController_ setDefaultAddressLabel:def ? [addressModel_ label] : nil]; -} - @end diff --git a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h index ba62e7a..054252f 100644 --- a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h +++ b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.h @@ -44,8 +44,6 @@ class CreditCard; AutoFillDialogController* parentController_; } -@property (readonly) BOOL canAlterDefault; -@property BOOL isDefault; @property (nonatomic, retain) AutoFillCreditCardModel* creditCardModel; @property (nonatomic, retain) NSArray* billingAddressContents; @property (nonatomic, retain) NSArray* shippingAddressContents; diff --git a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm index 0151869..8e7b29c 100644 --- a/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm +++ b/chrome/browser/autofill/autofill_credit_card_view_controller_mac.mm @@ -10,14 +10,11 @@ #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" #include "chrome/browser/autofill/credit_card.h" #include "grit/generated_resources.h" -#import "third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h" // Private methods for the |AutoFillCreditCardViewController| class. @interface AutoFillCreditCardViewController (PrivateMethods) - (void)rebuildBillingAddressContents; - (void)rebuildShippingAddressContents; -- (void)creditCardsChanged:(GTMKeyValueChangeNotification*)notification; -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification; @end @implementation AutoFillCreditCardViewController @@ -45,28 +42,11 @@ // Setup initial state of popups. [self onAddressesChanged:self]; - - [parentController_ gtm_addObserver:self - forKeyPath:@"creditCardLabels" - selector:@selector(creditCardsChanged:) - userInfo:nil - options:0]; - [parentController_ gtm_addObserver:self - forKeyPath:@"defaultCreditCardLabel" - selector:@selector(defaultChanged:) - userInfo:nil - options:0]; } return self; } - (void)dealloc { - [parentController_ gtm_removeObserver:self - forKeyPath:@"creditCardLabels" - selector:@selector(creditCardsChanged:)]; - [parentController_ gtm_removeObserver:self - forKeyPath:@"defaultCreditCardLabel" - selector:@selector(defaultChanged:)]; [creditCardModel_ release]; [billingAddressContents_ release]; [shippingAddressContents_ release]; @@ -101,30 +81,6 @@ creditCard->set_shipping_address(string16()); } -- (void)creditCardsChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"canAlterDefault"]; - [self didChangeValueForKey:@"canAlterDefault"]; -} - -- (void)defaultChanged:(GTMKeyValueChangeNotification*)notification { - [self willChangeValueForKey:@"isDefault"]; - [self didChangeValueForKey:@"isDefault"]; -} - -- (BOOL)canAlterDefault { - return [[parentController_ creditCardLabels] count] > 1; -} - -- (BOOL)isDefault { - return [[creditCardModel_ label] isEqual: - [parentController_ defaultCreditCardLabel]]; -} - -- (void)setIsDefault:(BOOL)def { - [parentController_ setDefaultCreditCardLabel: - def ? [creditCardModel_ label] : nil]; -} - // Builds the |billingAddressContents_| array of strings from the list of // addresses returned by the |parentController_| and additional UI string. // Ensures that current selection is valid, if not reset it. diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.h b/chrome/browser/autofill/autofill_dialog_controller_mac.h index 220634b..3ea6900 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac.h +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.h @@ -43,9 +43,6 @@ class Profile; // Array of |AutoFillCreditCardViewController|. scoped_nsobject<NSMutableArray> creditCardFormViewControllers_; - scoped_nsobject<NSString> defaultAddressLabel_; - scoped_nsobject<NSString> defaultCreditCardLabel_; - AutoFillDialogObserver* observer_; // Weak, not retained. Profile* profile_; // Weak, not retained. AutoFillProfile* importedProfile_; // Weak, not retained. @@ -64,10 +61,6 @@ class Profile; // bound to this in nib. @property (nonatomic) BOOL auxiliaryEnabled; -// Property representing the default profile and credit card. -@property (nonatomic, copy) NSString* defaultAddressLabel; -@property (nonatomic, copy) NSString* defaultCreditCardLabel; - // Main interface for displaying an application modal autofill dialog on screen. // This class method creates a new |AutoFillDialogController| and runs it as a // modal dialog. The controller autoreleases itself when the dialog is closed. diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm index 2e3a180..c867497 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm @@ -180,13 +180,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { } profile_->GetPrefs()->SetBoolean(prefs::kAutoFillAuxiliaryProfilesEnabled, auxiliaryEnabled_); - // Make sure to use accessors here to save what the user sees. - profile_->GetPrefs()->SetString( - prefs::kAutoFillDefaultProfile, - base::SysNSStringToWide([self defaultAddressLabel])); - profile_->GetPrefs()->SetString( - prefs::kAutoFillDefaultCreditCard, - base::SysNSStringToWide([self defaultCreditCardLabel])); observer_->OnAutoFillDialogApply(&profiles_, &creditCards_); } [self closeDialog]; @@ -223,9 +216,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"addressLabels"]; [addressFormViewControllers_.get() addObject:addressViewController]; [self didChangeValueForKey:@"addressLabels"]; - // Might need to reset the default if added. - [self willChangeValueForKey:@"defaultAddressLabel"]; - [self didChangeValueForKey:@"defaultAddressLabel"]; // Embed the new address into our target view. [childView_ addSubview:[addressViewController view] @@ -263,9 +253,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"creditCardLabels"]; [creditCardFormViewControllers_.get() addObject:creditCardViewController]; [self didChangeValueForKey:@"creditCardLabels"]; - // Might need to reset the default if added. - [self willChangeValueForKey:@"defaultCreditCardLabel"]; - [self didChangeValueForKey:@"defaultCreditCardLabel"]; // Embed the new address into our target view. [childView_ addSubview:[creditCardViewController view] @@ -289,9 +276,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"addressLabels"]; [addressFormViewControllers_.get() removeObjectAtIndex:i]; [self didChangeValueForKey:@"addressLabels"]; - // Might need to reset the default if deleted. - [self willChangeValueForKey:@"defaultAddressLabel"]; - [self didChangeValueForKey:@"defaultAddressLabel"]; [self notifyAddressChange:self]; @@ -312,9 +296,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { [self willChangeValueForKey:@"creditCardLabels"]; [creditCardFormViewControllers_.get() removeObjectAtIndex:i]; [self didChangeValueForKey:@"creditCardLabels"]; - // Might need to reset the default if deleted. - [self willChangeValueForKey:@"defaultCreditCardLabel"]; - [self didChangeValueForKey:@"defaultCreditCardLabel"]; // Recalculate key view loop to account for change in view tree. [[self window] recalculateKeyViewLoop]; @@ -353,104 +334,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { return array; } -- (NSString*)defaultAddressLabel { - NSArray* labels = [self addressLabels]; - NSString* def = defaultAddressLabel_.get(); - if ([def length] && [labels containsObject:def]) - return def; - - // No valid default; pick the first item. - if ([labels count]) { - return [labels objectAtIndex:0]; - } else { - return @""; - } -} - -- (void)setDefaultAddressLabel:(NSString*)label { - if (!label) { - // Setting nil means the user un-checked an item. Find a new default. - NSUInteger itemCount = [addressFormViewControllers_ count]; - if (itemCount == 0) { - DCHECK(false) << "Attempt to set default when there are no items."; - return; - } else if (itemCount == 1) { - DCHECK(false) << "Attempt to set default when there is only one item, so " - "it should have been disabled."; - AutoFillAddressViewController* controller = - [addressFormViewControllers_ objectAtIndex:0]; - label = [[controller addressModel] label]; - } else { - AutoFillAddressViewController* controller = - [addressFormViewControllers_ objectAtIndex:0]; - NSString* firstItemsLabel = [[controller addressModel] label]; - - // If they unchecked an item that wasn't the first item, make the first - // item default. - if (![defaultAddressLabel_ isEqual:firstItemsLabel]) { - label = firstItemsLabel; - } else { - // Otherwise they unchecked the first item. Pick the second one for 'em. - AutoFillAddressViewController* controller = - [addressFormViewControllers_ objectAtIndex:1]; - label = [[controller addressModel] label]; - } - } - } - - defaultAddressLabel_.reset([label copy]); - return; -} - -- (NSString*)defaultCreditCardLabel { - NSArray* labels = [self creditCardLabels]; - NSString* def = defaultCreditCardLabel_.get(); - if ([def length] && [labels containsObject:def]) - return def; - - // No valid default; pick the first item. - if ([labels count]) { - return [labels objectAtIndex:0]; - } else { - return @""; - } -} - -- (void)setDefaultCreditCardLabel:(NSString*)label { - if (!label) { - // Setting nil means the user un-checked an item. Find a new default. - NSUInteger itemCount = [creditCardFormViewControllers_ count]; - if (itemCount == 0) { - DCHECK(false) << "Attempt to set default when there are no items."; - return; - } else if (itemCount == 1) { - DCHECK(false) << "Attempt to set default when there is only one item, so " - "it should have been disabled."; - AutoFillCreditCardViewController* controller = - [creditCardFormViewControllers_ objectAtIndex:0]; - label = [[controller creditCardModel] label]; - } else { - AutoFillCreditCardViewController* controller = - [creditCardFormViewControllers_ objectAtIndex:0]; - NSString* firstItemsLabel = [[controller creditCardModel] label]; - - // If they unchecked an item that wasn't the first item, make the first - // item default. - if (![defaultCreditCardLabel_ isEqual:firstItemsLabel]) { - label = firstItemsLabel; - } else { - // Otherwise they unchecked the first item. Pick the second one for 'em. - AutoFillCreditCardViewController* controller = - [creditCardFormViewControllers_ objectAtIndex:1]; - label = [[controller creditCardModel] label]; - } - } - } - - defaultCreditCardLabel_.reset([label copy]); - return; -} - @end @implementation AutoFillDialogController (ExposedForUnitTests) @@ -505,14 +388,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { // Initialize array of sub-controllers. creditCardFormViewControllers_.reset( [[NSMutableArray alloc] initWithCapacity:0]); - - NSString* defaultAddressLabel = base::SysWideToNSString( - profile_->GetPrefs()->GetString(prefs::kAutoFillDefaultProfile)); - defaultAddressLabel_.reset([defaultAddressLabel retain]); - - NSString* defaultCreditCardLabel = base::SysWideToNSString( - profile_->GetPrefs()->GetString(prefs::kAutoFillDefaultCreditCard)); - defaultCreditCardLabel_.reset([defaultCreditCardLabel retain]); } return self; } @@ -593,13 +468,6 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { insertionPoint = [creditCardViewController view]; [[creditCardViewController view] setFrameOrigin:NSMakePoint(0, 0)]; } - - // During initialization the default accessors were returning faulty values - // since the controller arrays weren't set up. Poke our observers. - [self willChangeValueForKey:@"defaultAddressLabel"]; - [self didChangeValueForKey:@"defaultAddressLabel"]; - [self willChangeValueForKey:@"defaultCreditCardLabel"]; - [self didChangeValueForKey:@"defaultCreditCardLabel"]; } - (void)onPersonalDataLoaded:(const std::vector<AutoFillProfile*>&)profiles diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm index bd72c29..fb1f38e 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm @@ -531,72 +531,6 @@ TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesChanged) { prefs::kAutoFillAuxiliaryProfilesEnabled)); } -TEST_F(AutoFillDialogControllerTest, DefaultsChangingLogic) { - // Two profiles, two credit cards. - AutoFillProfile profile(ASCIIToUTF16("One"), 1); - profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); - profiles().push_back(&profile); - AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); - profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); - profiles().push_back(&profile2); - CreditCard credit_card(ASCIIToUTF16("Visa"), 1); - credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); - credit_cards().push_back(&credit_card); - CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); - credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); - credit_cards().push_back(&credit_card2); - - // Invalid defaults for each. - helper_.profile()->GetPrefs()->SetString( - prefs::kAutoFillDefaultProfile, L"xxxx"); - helper_.profile()->GetPrefs()->SetString( - prefs::kAutoFillDefaultCreditCard, L"yyyy"); - - // Start 'em up. - LoadDialog(); - - // With invalid default values, the first item should be the default. - EXPECT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"One"]); - EXPECT_TRUE([[controller_ defaultCreditCardLabel] isEqualToString:@"Visa"]); - - // Explicitly set the second to be default and make sure it sticks. - [controller_ setDefaultAddressLabel:@"Two"]; - [controller_ setDefaultCreditCardLabel:@"Mastercard"]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"Two"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] - isEqualToString:@"Mastercard"]); - - // Deselect the second and the first should become default. - [controller_ setDefaultAddressLabel:nil]; - [controller_ setDefaultCreditCardLabel:nil]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"One"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] isEqualToString:@"Visa"]); - - // Deselect the first and the second should be come default. - [controller_ setDefaultAddressLabel:nil]; - [controller_ setDefaultCreditCardLabel:nil]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"Two"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] - isEqualToString:@"Mastercard"]); - - // Delete the second and the first should end up as default. - [controller_ deleteAddress:[[controller_ addressFormViewControllers] - lastObject]]; - [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers] - lastObject]]; - ASSERT_TRUE([[controller_ defaultAddressLabel] isEqualToString:@"One"]); - ASSERT_TRUE([[controller_ defaultCreditCardLabel] isEqualToString:@"Visa"]); - - // Save and that should end up in the prefs. - [controller_ save:nil]; - ASSERT_TRUE(observer_.hit_); - - ASSERT_EQ(L"One", helper_.profile()->GetPrefs()-> - GetString(prefs::kAutoFillDefaultProfile)); - ASSERT_EQ(L"Visa", helper_.profile()->GetPrefs()-> - GetString(prefs::kAutoFillDefaultCreditCard)); -} - TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) { AutoFillProfile profile(ASCIIToUTF16("Home"), 0); profiles().push_back(&profile); |