Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 - (void)setRetriableErrorMessage:(const base::string16&)text { | 203 - (void)setRetriableErrorMessage:(const base::string16&)text { |
| 204 NSAttributedString* attributedString = | 204 NSAttributedString* attributedString = |
| 205 constrained_window::GetAttributedLabelString( | 205 constrained_window::GetAttributedLabelString( |
| 206 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, | 206 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, |
| 207 NSLineBreakByWordWrapping); | 207 NSLineBreakByWordWrapping); |
| 208 [errorLabel_ setAttributedStringValue:attributedString]; | 208 [errorLabel_ setAttributedStringValue:attributedString]; |
| 209 [self performLayoutAndDisplay:YES]; | 209 [self performLayoutAndDisplay:YES]; |
| 210 } | 210 } |
| 211 | 211 |
| 212 - (void)updateVerifyButtonEnabled { | 212 - (void)updateVerifyButtonEnabled { |
| 213 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 213 BOOL enable = ![inputRowView_ isHidden] && |
| 214 DCHECK(controller); | 214 bridge_->GetController()->InputCvcIsValid( |
|
bondd
2015/03/25 21:03:59
After looking deeper into dialog close+destruction
| |
| 215 | 215 base::SysNSStringToUTF16([cvcInput_ stringValue])) && |
| 216 BOOL enable = | 216 [self expirationDateIsValid]; |
| 217 ![inputRowView_ isHidden] && | |
| 218 controller->InputCvcIsValid( | |
| 219 base::SysNSStringToUTF16([cvcInput_ stringValue])) && | |
| 220 (!monthPopup_ || | |
| 221 [monthPopup_ indexOfSelectedItem] != monthPopupDefaultIndex_) && | |
| 222 (!yearPopup_ || | |
| 223 [yearPopup_ indexOfSelectedItem] != yearPopupDefaultIndex_); | |
| 224 | 217 |
| 225 [verifyButton_ setEnabled:enable]; | 218 [verifyButton_ setEnabled:enable]; |
| 226 } | 219 } |
| 227 | 220 |
| 228 - (void)onVerify:(id)sender { | 221 - (void)onVerify:(id)sender { |
| 229 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 222 bridge_->GetController()->OnUnmaskResponse( |
| 230 DCHECK(controller); | |
|
bondd
2015/03/25 21:03:59
Same here.
| |
| 231 | |
| 232 controller->OnUnmaskResponse( | |
| 233 base::SysNSStringToUTF16([cvcInput_ stringValue]), | 223 base::SysNSStringToUTF16([cvcInput_ stringValue]), |
| 234 base::SysNSStringToUTF16([monthPopup_ titleOfSelectedItem]), | 224 base::SysNSStringToUTF16([monthPopup_ titleOfSelectedItem]), |
| 235 base::SysNSStringToUTF16([yearPopup_ titleOfSelectedItem]), | 225 base::SysNSStringToUTF16([yearPopup_ titleOfSelectedItem]), |
| 236 [storageCheckbox_ state] == NSOnState); | 226 [storageCheckbox_ state] == NSOnState); |
| 237 } | 227 } |
| 238 | 228 |
| 239 - (void)onCancel:(id)sender { | 229 - (void)onCancel:(id)sender { |
| 240 bridge_->PerformClose(); | 230 bridge_->PerformClose(); |
| 241 } | 231 } |
| 242 | 232 |
| 233 - (BOOL)expirationDateIsValid { | |
| 234 if (!bridge_->GetController()->ShouldRequestExpirationDate()) | |
| 235 return true; | |
| 236 | |
| 237 return bridge_->GetController()->InputExpirationIsValid( | |
| 238 base::SysNSStringToUTF16([monthPopup_ titleOfSelectedItem]), | |
| 239 base::SysNSStringToUTF16([yearPopup_ titleOfSelectedItem])); | |
| 240 } | |
| 241 | |
| 243 - (void)onExpirationDateChanged:(id)sender { | 242 - (void)onExpirationDateChanged:(id)sender { |
| 243 if ([self expirationDateIsValid]) { | |
| 244 [self setRetriableErrorMessage:base::string16()]; | |
|
bondd
2015/03/25 21:03:59
Open CL https://codereview.chromium.org/1038503003
| |
| 245 } else if ([monthPopup_ indexOfSelectedItem] != monthPopupDefaultIndex_ && | |
|
groby-ooo-7-16
2015/03/25 21:44:58
Why would the default month/year not be validated?
bondd
2015/03/26 00:42:27
Yeah, I noticed this too. My guess is that it's be
groby-ooo-7-16
2015/03/26 01:24:41
Is the default item at least not selectable? (I.e.
| |
| 246 [yearPopup_ indexOfSelectedItem] != yearPopupDefaultIndex_) { | |
| 247 [self setRetriableErrorMessage: | |
| 248 l10n_util::GetStringUTF16( | |
| 249 IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE)]; | |
| 250 } | |
| 251 | |
| 244 [self updateVerifyButtonEnabled]; | 252 [self updateVerifyButtonEnabled]; |
| 245 } | 253 } |
| 246 | 254 |
| 247 // Called when text in CVC input field changes. | 255 // Called when text in CVC input field changes. |
| 248 - (void)controlTextDidChange:(NSNotification*)notification { | 256 - (void)controlTextDidChange:(NSNotification*)notification { |
| 249 [self updateVerifyButtonEnabled]; | 257 [self updateVerifyButtonEnabled]; |
| 250 } | 258 } |
| 251 | 259 |
| 252 - (base::scoped_nsobject<NSView>)createStorageViewWithController: | 260 - (base::scoped_nsobject<NSView>)createStorageViewWithController: |
| 253 (autofill::CardUnmaskPromptController*)controller { | 261 (autofill::CardUnmaskPromptController*)controller { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 | 480 |
| 473 // Layout inputRowView_. | 481 // Layout inputRowView_. |
| 474 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_]; | 482 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_]; |
| 475 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_]; | 483 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_]; |
| 476 | 484 |
| 477 [self setView:mainView]; | 485 [self setView:mainView]; |
| 478 [self performLayoutAndDisplay:NO]; | 486 [self performLayoutAndDisplay:NO]; |
| 479 } | 487 } |
| 480 | 488 |
| 481 @end | 489 @end |
| OLD | NEW |