| 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 "base/mac_util.h" | 7 #include "base/mac_util.h" |
| 8 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 8 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
| 9 #import "chrome/browser/autofill/autofill_address_view_controller_mac.h" | 9 #import "chrome/browser/autofill/autofill_address_view_controller_mac.h" |
| 10 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 10 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
| 11 #import "chrome/browser/autofill/autofill_credit_card_view_controller_mac.h" | 11 #import "chrome/browser/autofill/autofill_credit_card_view_controller_mac.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #import "chrome/browser/cocoa/disclosure_view_controller.h" | 13 #import "chrome/browser/cocoa/disclosure_view_controller.h" |
| 14 #import "chrome/browser/cocoa/section_separator_view.h" | 14 #import "chrome/browser/cocoa/section_separator_view.h" |
| 15 #import "chrome/browser/cocoa/window_size_autosaver.h" | 15 #import "chrome/browser/cocoa/window_size_autosaver.h" |
| 16 #include "chrome/browser/pref_service.h" |
| 16 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 | 20 |
| 20 @interface AutoFillDialogController (PrivateMethods) | 21 @interface AutoFillDialogController (PrivateMethods) |
| 21 - (void)runModalDialog; | 22 - (void)runModalDialog; |
| 22 - (void)installChildViews; | 23 - (void)installChildViews; |
| 23 @end | 24 @end |
| 24 | 25 |
| 25 @implementation AutoFillDialogController | 26 @implementation AutoFillDialogController |
| 26 | 27 |
| 28 @synthesize auxiliaryEnabled = auxiliaryEnabled_; |
| 29 |
| 27 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer | 30 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer |
| 28 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles | 31 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles |
| 29 creditCards:(const std::vector<CreditCard*>&)creditCards { | 32 creditCards:(const std::vector<CreditCard*>&)creditCards |
| 33 profile:(Profile*)profile { |
| 30 AutoFillDialogController* controller = | 34 AutoFillDialogController* controller = |
| 31 [AutoFillDialogController controllerWithObserver:observer | 35 [AutoFillDialogController controllerWithObserver:observer |
| 32 autoFillProfiles:profiles | 36 autoFillProfiles:profiles |
| 33 creditCards:creditCards]; | 37 creditCards:creditCards |
| 38 profile:profile]; |
| 34 | 39 |
| 35 // Only run modal dialog if it is not already being shown. | 40 // Only run modal dialog if it is not already being shown. |
| 36 if (![controller isWindowLoaded]) { | 41 if (![controller isWindowLoaded]) { |
| 37 [controller runModalDialog]; | 42 [controller runModalDialog]; |
| 38 } | 43 } |
| 39 } | 44 } |
| 40 | 45 |
| 41 - (void)awakeFromNib { | 46 - (void)awakeFromNib { |
| 42 [addressSectionBox_ setShowTopLine:FALSE]; | 47 [addressSectionBox_ setShowTopLine:FALSE]; |
| 43 [self installChildViews]; | 48 [self installChildViews]; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 71 creditCards_.resize([creditCardFormViewControllers_ count]); | 76 creditCards_.resize([creditCardFormViewControllers_ count]); |
| 72 int j = 0; | 77 int j = 0; |
| 73 for (AutoFillCreditCardViewController* creditCardFormViewController in | 78 for (AutoFillCreditCardViewController* creditCardFormViewController in |
| 74 creditCardFormViewControllers_.get()) { | 79 creditCardFormViewControllers_.get()) { |
| 75 // Initialize the credit card here. The default initializer does not | 80 // Initialize the credit card here. The default initializer does not |
| 76 // fully initialize. | 81 // fully initialize. |
| 77 creditCards_[j] = CreditCard(ASCIIToUTF16(""), 0); | 82 creditCards_[j] = CreditCard(ASCIIToUTF16(""), 0); |
| 78 [creditCardFormViewController copyModelToCreditCard:&creditCards_[j]]; | 83 [creditCardFormViewController copyModelToCreditCard:&creditCards_[j]]; |
| 79 j++; | 84 j++; |
| 80 } | 85 } |
| 86 profile_->GetPrefs()->SetBoolean(prefs::kAutoFillAuxiliaryProfilesEnabled, |
| 87 auxiliaryEnabled_); |
| 81 observer_->OnAutoFillDialogApply(&profiles_, &creditCards_); | 88 observer_->OnAutoFillDialogApply(&profiles_, &creditCards_); |
| 82 } | 89 } |
| 83 [self closeDialog]; | 90 [self closeDialog]; |
| 84 } | 91 } |
| 85 | 92 |
| 86 // Called when the user clicks the cancel button. All we need to do is stop | 93 // Called when the user clicks the cancel button. All we need to do is stop |
| 87 // the modal session. | 94 // the modal session. |
| 88 - (IBAction)cancel:(id)sender { | 95 - (IBAction)cancel:(id)sender { |
| 89 [self closeDialog]; | 96 [self closeDialog]; |
| 90 } | 97 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return array; | 221 return array; |
| 215 } | 222 } |
| 216 | 223 |
| 217 @end | 224 @end |
| 218 | 225 |
| 219 @implementation AutoFillDialogController (ExposedForUnitTests) | 226 @implementation AutoFillDialogController (ExposedForUnitTests) |
| 220 | 227 |
| 221 + (AutoFillDialogController*)controllerWithObserver: | 228 + (AutoFillDialogController*)controllerWithObserver: |
| 222 (AutoFillDialogObserver*)observer | 229 (AutoFillDialogObserver*)observer |
| 223 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles | 230 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles |
| 224 creditCards:(const std::vector<CreditCard*>&)creditCards { | 231 creditCards:(const std::vector<CreditCard*>&)creditCards |
| 232 profile:(Profile*)profile { |
| 225 | 233 |
| 226 // Deallocation is done upon window close. See |windowWillClose:|. | 234 // Deallocation is done upon window close. See |windowWillClose:|. |
| 227 AutoFillDialogController* controller = | 235 AutoFillDialogController* controller = |
| 228 [[self alloc] initWithObserver:observer | 236 [[self alloc] initWithObserver:observer |
| 229 autoFillProfiles:profiles | 237 autoFillProfiles:profiles |
| 230 creditCards:creditCards]; | 238 creditCards:creditCards |
| 239 profile:profile]; |
| 231 return controller; | 240 return controller; |
| 232 } | 241 } |
| 233 | 242 |
| 234 | 243 |
| 235 // This is the designated initializer for this class. | 244 // This is the designated initializer for this class. |
| 236 // |profiles| are non-retained immutable list of autofill profiles. | 245 // |profiles| are non-retained immutable list of autofill profiles. |
| 237 // |creditCards| are non-retained immutable list of credit card info. | 246 // |creditCards| are non-retained immutable list of credit card info. |
| 238 - (id)initWithObserver:(AutoFillDialogObserver*)observer | 247 - (id)initWithObserver:(AutoFillDialogObserver*)observer |
| 239 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles | 248 autoFillProfiles:(const std::vector<AutoFillProfile*>&)profiles |
| 240 creditCards:(const std::vector<CreditCard*>&)creditCards { | 249 creditCards:(const std::vector<CreditCard*>&)creditCards |
| 250 profile:(Profile*)profile { |
| 251 CHECK(profile); |
| 241 // Use initWithWindowNibPath: instead of initWithWindowNibName: so we | 252 // Use initWithWindowNibPath: instead of initWithWindowNibName: so we |
| 242 // can override it in a unit test. | 253 // can override it in a unit test. |
| 243 NSString* nibpath = [mac_util::MainAppBundle() | 254 NSString* nibpath = [mac_util::MainAppBundle() |
| 244 pathForResource:@"AutoFillDialog" | 255 pathForResource:@"AutoFillDialog" |
| 245 ofType:@"nib"]; | 256 ofType:@"nib"]; |
| 246 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 257 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 247 observer_ = observer; | 258 observer_ = observer; |
| 248 | 259 |
| 249 // Make local copy of |profiles|. | 260 // Make local copy of |profiles|. |
| 250 std::vector<AutoFillProfile*>::const_iterator i; | 261 std::vector<AutoFillProfile*>::const_iterator i; |
| 251 for (i = profiles.begin(); i != profiles.end(); ++i) | 262 for (i = profiles.begin(); i != profiles.end(); ++i) |
| 252 profiles_.push_back(**i); | 263 profiles_.push_back(**i); |
| 253 | 264 |
| 254 // Make local copy of |creditCards|. | 265 // Make local copy of |creditCards|. |
| 255 std::vector<CreditCard*>::const_iterator j; | 266 std::vector<CreditCard*>::const_iterator j; |
| 256 for (j = creditCards.begin(); j != creditCards.end(); ++j) | 267 for (j = creditCards.begin(); j != creditCards.end(); ++j) |
| 257 creditCards_.push_back(**j); | 268 creditCards_.push_back(**j); |
| 258 | 269 |
| 270 profile_ = profile; |
| 271 |
| 272 // Use property here to trigger KVO binding. |
| 273 [self setAuxiliaryEnabled:profile_->GetPrefs()->GetBoolean( |
| 274 prefs::kAutoFillAuxiliaryProfilesEnabled)]; |
| 275 |
| 259 // Initialize array of sub-controllers. | 276 // Initialize array of sub-controllers. |
| 260 addressFormViewControllers_.reset([[NSMutableArray array] retain]); | 277 addressFormViewControllers_.reset([[NSMutableArray array] retain]); |
| 261 | 278 |
| 262 // Initialize array of sub-controllers. | 279 // Initialize array of sub-controllers. |
| 263 creditCardFormViewControllers_.reset([[NSMutableArray array] retain]); | 280 creditCardFormViewControllers_.reset([[NSMutableArray array] retain]); |
| 264 } | 281 } |
| 265 return self; | 282 return self; |
| 266 } | 283 } |
| 267 | 284 |
| 268 // Close the dialog. | 285 // Close the dialog. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 350 |
| 334 // Embed the child view into our (owned by us) target view. | 351 // Embed the child view into our (owned by us) target view. |
| 335 [childView_ addSubview:[creditCardViewController view] | 352 [childView_ addSubview:[creditCardViewController view] |
| 336 positioned:NSWindowBelow relativeTo:insertionPoint]; | 353 positioned:NSWindowBelow relativeTo:insertionPoint]; |
| 337 insertionPoint = [creditCardViewController view]; | 354 insertionPoint = [creditCardViewController view]; |
| 338 [[creditCardViewController view] setFrameOrigin:NSMakePoint(0, 0)]; | 355 [[creditCardViewController view] setFrameOrigin:NSMakePoint(0, 0)]; |
| 339 } | 356 } |
| 340 } | 357 } |
| 341 | 358 |
| 342 @end | 359 @end |
| OLD | NEW |