Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 years.reserve(kNumberOfExpirationYears); | 80 years.reserve(kNumberOfExpirationYears); |
| 81 | 81 |
| 82 base::Time::Exploded now_exploded; | 82 base::Time::Exploded now_exploded; |
| 83 autofill::AutofillClock::Now().LocalExplode(&now_exploded); | 83 autofill::AutofillClock::Now().LocalExplode(&now_exploded); |
| 84 for (int i = 0; i < kNumberOfExpirationYears; i++) { | 84 for (int i = 0; i < kNumberOfExpirationYears; i++) { |
| 85 years.push_back(base::UTF8ToUTF16(std::to_string(now_exploded.year + i))); | 85 years.push_back(base::UTF8ToUTF16(std::to_string(now_exploded.year + i))); |
| 86 } | 86 } |
| 87 return years; | 87 return years; |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool IsCardExpired(const base::string16& month, | |
| 91 base::string16& year, | |
| 92 const std::string& app_locale) { | |
| 93 autofill::CreditCard card; | |
| 94 card.SetExpirationMonthFromString(month, app_locale); | |
| 95 card.SetExpirationYearFromString(year); | |
| 96 return card.IsExpired(autofill::AutofillClock::Now()); | |
| 97 } | |
| 98 | |
| 99 // Validates the two comboboxes used for expiration date. | |
| 100 class ExpirationDateValidationDelegate : public ValidationDelegate { | |
| 101 public: | |
| 102 ExpirationDateValidationDelegate(EditorViewController* controller, | |
| 103 const std::string& app_locale) | |
| 104 : controller_(controller), app_locale_(app_locale) {} | |
| 105 | |
| 106 bool IsValidTextfield(views::Textfield* textfield) override { return true; } | |
|
anthonyvd
2017/05/22 13:18:17
nit: NOTREACHED() ?
Mathieu
2017/05/22 16:30:40
Done.
| |
| 107 | |
| 108 bool IsValidCombobox(views::Combobox* combobox) override { | |
| 109 // Get the combined date from the month and year dropdowns. | |
| 110 views::View* view_parent = combobox->parent(); | |
| 111 | |
| 112 views::Combobox* month_combobox = static_cast<views::Combobox*>( | |
| 113 view_parent->GetViewByID(EditorViewController::GetInputFieldViewId( | |
| 114 autofill::CREDIT_CARD_EXP_MONTH))); | |
| 115 base::string16 month = | |
| 116 month_combobox->model()->GetItemAt(month_combobox->selected_index()); | |
| 117 | |
| 118 views::Combobox* year_combobox = static_cast<views::Combobox*>( | |
| 119 view_parent->GetViewByID(EditorViewController::GetInputFieldViewId( | |
| 120 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR))); | |
| 121 base::string16 year = | |
| 122 year_combobox->model()->GetItemAt(year_combobox->selected_index()); | |
| 123 | |
| 124 bool is_expired = IsCardExpired(month, year, app_locale_); | |
| 125 month_combobox->SetInvalid(is_expired); | |
| 126 year_combobox->SetInvalid(is_expired); | |
| 127 | |
| 128 return !is_expired; | |
| 129 } | |
| 130 | |
| 131 bool TextfieldValueChanged(views::Textfield* textfield) override { | |
| 132 return true; | |
|
anthonyvd
2017/05/22 13:18:17
nit NOTREACHED() ?
Mathieu
2017/05/22 16:30:40
Done.
| |
| 133 } | |
| 134 | |
| 135 bool ComboboxValueChanged(views::Combobox* combobox) override { | |
| 136 bool is_valid = IsValidCombobox(combobox); | |
| 137 controller_->DisplayErrorMessageForField( | |
| 138 autofill::CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, | |
| 139 is_valid ? base::string16() | |
| 140 : l10n_util::GetStringUTF16( | |
| 141 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED)); | |
| 142 return is_valid; | |
| 143 } | |
| 144 | |
| 145 void ComboboxModelChanged(views::Combobox* combobox) override {} | |
| 146 | |
| 147 private: | |
| 148 EditorViewController* controller_; | |
| 149 const std::string app_locale_; | |
| 150 | |
| 151 DISALLOW_COPY_AND_ASSIGN(ExpirationDateValidationDelegate); | |
| 152 }; | |
| 153 | |
| 90 } // namespace | 154 } // namespace |
| 91 | 155 |
| 92 CreditCardEditorViewController::CreditCardEditorViewController( | 156 CreditCardEditorViewController::CreditCardEditorViewController( |
| 93 PaymentRequestSpec* spec, | 157 PaymentRequestSpec* spec, |
| 94 PaymentRequestState* state, | 158 PaymentRequestState* state, |
| 95 PaymentRequestDialogView* dialog, | 159 PaymentRequestDialogView* dialog, |
| 96 BackNavigationType back_navigation, | 160 BackNavigationType back_navigation, |
| 97 int next_ui_tag, | 161 int next_ui_tag, |
| 98 base::OnceClosure on_edited, | 162 base::OnceClosure on_edited, |
| 99 base::OnceCallback<void(const autofill::CreditCard&)> on_added, | 163 base::OnceCallback<void(const autofill::CreditCard&)> on_added, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 card_icon_view->SetImageSize(kCardIconSize); | 222 card_icon_view->SetImageSize(kCardIconSize); |
| 159 | 223 |
| 160 icons_row->AddChildView(card_icon_view.release()); | 224 icons_row->AddChildView(card_icon_view.release()); |
| 161 } | 225 } |
| 162 view->AddChildView(icons_row.release()); | 226 view->AddChildView(icons_row.release()); |
| 163 | 227 |
| 164 return view; | 228 return view; |
| 165 } | 229 } |
| 166 | 230 |
| 167 std::unique_ptr<views::View> | 231 std::unique_ptr<views::View> |
| 232 CreditCardEditorViewController::CreateCustomFieldView( | |
| 233 autofill::ServerFieldType type, | |
| 234 views::View** focusable_field, | |
| 235 bool* valid) { | |
| 236 DCHECK_EQ(type, autofill::CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); | |
| 237 | |
| 238 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | |
| 239 std::unique_ptr<views::GridLayout> combobox_layout = | |
| 240 base::MakeUnique<views::GridLayout>(view.get()); | |
| 241 // Column set for short fields. | |
|
anthonyvd
2017/05/22 13:18:17
nit: not sure this comment is relevant anymore
Mathieu
2017/05/22 16:30:40
Done.
| |
| 242 views::ColumnSet* columns = combobox_layout->AddColumnSet(0); | |
| 243 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 1, | |
| 244 views::GridLayout::USE_PREF, 0, 0); | |
| 245 // Space between the two comboboxes. | |
| 246 constexpr int kHorizontalSpacing = 8; | |
| 247 columns->AddPaddingColumn(0, kHorizontalSpacing); | |
| 248 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 1, | |
| 249 views::GridLayout::USE_PREF, 0, 0); | |
| 250 | |
| 251 combobox_layout->StartRow(0, 0); | |
| 252 constexpr int kInputFieldHeight = 28; | |
| 253 EditorField tmp_month{autofill::CREDIT_CARD_EXP_MONTH, base::string16(), | |
| 254 EditorField::LengthHint::HINT_SHORT, | |
| 255 /*required=*/true, EditorField::ControlType::COMBOBOX}; | |
| 256 std::unique_ptr<ValidatingCombobox> month_combobox = | |
| 257 CreateComboboxForField(tmp_month); | |
| 258 *focusable_field = month_combobox.get(); | |
| 259 combobox_layout->AddView(month_combobox.release(), 1, 1, | |
| 260 views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
| 261 kInputFieldHeight); | |
| 262 | |
| 263 EditorField tmp_year{autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR, base::string16(), | |
| 264 EditorField::LengthHint::HINT_SHORT, | |
| 265 /*required=*/true, EditorField::ControlType::COMBOBOX}; | |
| 266 std::unique_ptr<ValidatingCombobox> year_combobox = | |
| 267 CreateComboboxForField(tmp_year); | |
| 268 combobox_layout->AddView(year_combobox.release(), 1, 1, | |
| 269 views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
| 270 kInputFieldHeight); | |
| 271 | |
| 272 view->SetLayoutManager(combobox_layout.release()); | |
| 273 | |
| 274 // Set the initial validity of the custom view. | |
| 275 base::string16 month = | |
| 276 GetInitialValueForType(autofill::CREDIT_CARD_EXP_MONTH); | |
| 277 base::string16 year = | |
| 278 GetInitialValueForType(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR); | |
| 279 *valid = IsCardExpired(month, year, state()->GetApplicationLocale()); | |
| 280 return view; | |
| 281 } | |
| 282 | |
| 283 std::unique_ptr<views::View> | |
| 168 CreditCardEditorViewController::CreateExtraViewForField( | 284 CreditCardEditorViewController::CreateExtraViewForField( |
| 169 autofill::ServerFieldType type) { | 285 autofill::ServerFieldType type) { |
| 170 if (type != kBillingAddressType) | 286 if (type != kBillingAddressType) |
| 171 return nullptr; | 287 return nullptr; |
| 172 | 288 |
| 173 std::unique_ptr<views::View> button_view = base::MakeUnique<views::View>(); | 289 std::unique_ptr<views::View> button_view = base::MakeUnique<views::View>(); |
| 174 button_view->SetLayoutManager(new views::FillLayout); | 290 button_view->SetLayoutManager(new views::FillLayout); |
| 175 | 291 |
| 176 // The button to add new billing addresses. | 292 // The button to add new billing addresses. |
| 177 std::unique_ptr<views::Button> add_button( | 293 std::unique_ptr<views::Button> add_button( |
| 178 views::MdTextButton::Create(this, l10n_util::GetStringUTF16(IDS_ADD))); | 294 views::MdTextButton::Create(this, l10n_util::GetStringUTF16(IDS_ADD))); |
| 179 add_button->set_id( | 295 add_button->set_id( |
| 180 static_cast<int>(DialogViewID::ADD_BILLING_ADDRESS_BUTTON)); | 296 static_cast<int>(DialogViewID::ADD_BILLING_ADDRESS_BUTTON)); |
| 181 add_button->set_tag(add_billing_address_button_tag_); | 297 add_button->set_tag(add_billing_address_button_tag_); |
| 182 button_view->AddChildView(add_button.release()); | 298 button_view->AddChildView(add_button.release()); |
| 183 return button_view; | 299 return button_view; |
| 184 } | 300 } |
| 185 | 301 |
| 186 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { | 302 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { |
| 187 return std::vector<EditorField>{ | 303 return std::vector<EditorField>{ |
| 188 {autofill::CREDIT_CARD_NUMBER, | 304 {autofill::CREDIT_CARD_NUMBER, |
| 189 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), | 305 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), |
| 190 EditorField::LengthHint::HINT_SHORT, /* required= */ true, | 306 EditorField::LengthHint::HINT_SHORT, /*required=*/true, |
| 191 EditorField::ControlType::TEXTFIELD_NUMBER}, | 307 EditorField::ControlType::TEXTFIELD_NUMBER}, |
| 192 {autofill::CREDIT_CARD_NAME_FULL, | 308 {autofill::CREDIT_CARD_NAME_FULL, |
| 193 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), | 309 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), |
| 194 EditorField::LengthHint::HINT_SHORT, /* required= */ true}, | 310 EditorField::LengthHint::HINT_SHORT, /*required=*/true}, |
| 195 {autofill::CREDIT_CARD_EXP_MONTH, | 311 {autofill::CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, |
| 196 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH), | 312 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE), |
| 197 EditorField::LengthHint::HINT_SHORT, /* required= */ true, | 313 EditorField::LengthHint::HINT_SHORT, /*required=*/true, |
| 198 EditorField::ControlType::COMBOBOX}, | 314 EditorField::ControlType::CUSTOMFIELD}, |
| 199 {autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR, | |
| 200 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_YEAR), | |
| 201 EditorField::LengthHint::HINT_SHORT, /* required= */ true, | |
| 202 EditorField::ControlType::COMBOBOX}, | |
| 203 {kBillingAddressType, | 315 {kBillingAddressType, |
| 204 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_BILLING_ADDRESS), | 316 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_BILLING_ADDRESS), |
| 205 EditorField::LengthHint::HINT_SHORT, /* required= */ true, | 317 EditorField::LengthHint::HINT_SHORT, /*required=*/true, |
| 206 EditorField::ControlType::COMBOBOX}}; | 318 EditorField::ControlType::COMBOBOX}}; |
| 207 } | 319 } |
| 208 | 320 |
| 209 base::string16 CreditCardEditorViewController::GetInitialValueForType( | 321 base::string16 CreditCardEditorViewController::GetInitialValueForType( |
| 210 autofill::ServerFieldType type) { | 322 autofill::ServerFieldType type) { |
| 211 if (!credit_card_to_edit_ || type == kBillingAddressType) | 323 if (!credit_card_to_edit_ || type == kBillingAddressType) |
| 212 return base::string16(); | 324 return base::string16(); |
| 213 | 325 |
| 214 return credit_card_to_edit_->GetInfo(autofill::AutofillType(type), | 326 return credit_card_to_edit_->GetInfo(autofill::AutofillType(type), |
| 215 state()->GetApplicationLocale()); | 327 state()->GetApplicationLocale()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 232 field.first->text(), locale); | 344 field.first->text(), locale); |
| 233 } | 345 } |
| 234 for (const auto& field : comboboxes()) { | 346 for (const auto& field : comboboxes()) { |
| 235 // ValidatingCombobox* is the key, EditorField is the value. | 347 // ValidatingCombobox* is the key, EditorField is the value. |
| 236 ValidatingCombobox* combobox = field.first; | 348 ValidatingCombobox* combobox = field.first; |
| 237 if (combobox->invalid()) | 349 if (combobox->invalid()) |
| 238 return false; | 350 return false; |
| 239 | 351 |
| 240 if (field.second.type == kBillingAddressType) { | 352 if (field.second.type == kBillingAddressType) { |
| 241 views::Combobox* address_combobox = static_cast<views::Combobox*>( | 353 views::Combobox* address_combobox = static_cast<views::Combobox*>( |
| 242 dialog()->GetViewByID(kBillingAddressType)); | 354 dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType))); |
| 243 autofill::AddressComboboxModel* model = | 355 autofill::AddressComboboxModel* model = |
| 244 static_cast<autofill::AddressComboboxModel*>( | 356 static_cast<autofill::AddressComboboxModel*>( |
| 245 address_combobox->model()); | 357 address_combobox->model()); |
| 246 | 358 |
| 247 credit_card.set_billing_address_id( | 359 credit_card.set_billing_address_id( |
| 248 model->GetItemIdentifierAt(address_combobox->selected_index())); | 360 model->GetItemIdentifierAt(address_combobox->selected_index())); |
| 249 } else { | 361 } else { |
| 250 credit_card.SetInfo(autofill::AutofillType(field.second.type), | 362 credit_card.SetInfo(autofill::AutofillType(field.second.type), |
| 251 combobox->GetTextForRow(combobox->selected_index()), | 363 combobox->GetTextForRow(combobox->selected_index()), |
| 252 locale); | 364 locale); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 } | 405 } |
| 294 | 406 |
| 295 return true; | 407 return true; |
| 296 } | 408 } |
| 297 | 409 |
| 298 std::unique_ptr<ValidationDelegate> | 410 std::unique_ptr<ValidationDelegate> |
| 299 CreditCardEditorViewController::CreateValidationDelegate( | 411 CreditCardEditorViewController::CreateValidationDelegate( |
| 300 const EditorField& field) { | 412 const EditorField& field) { |
| 301 // The supported card networks for non-cc-number types are not passed to avoid | 413 // The supported card networks for non-cc-number types are not passed to avoid |
| 302 // the data copy in the delegate. | 414 // the data copy in the delegate. |
| 415 if (field.type == autofill::CREDIT_CARD_EXP_MONTH || | |
| 416 field.type == autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR) | |
| 417 return base::MakeUnique<ExpirationDateValidationDelegate>( | |
| 418 this, state()->GetApplicationLocale()); | |
| 303 return base::MakeUnique< | 419 return base::MakeUnique< |
| 304 CreditCardEditorViewController::CreditCardValidationDelegate>( | 420 CreditCardEditorViewController::CreditCardValidationDelegate>( |
| 305 field, this, | 421 field, this, |
| 306 field.type == autofill::CREDIT_CARD_NUMBER | 422 field.type == autofill::CREDIT_CARD_NUMBER |
| 307 ? spec()->supported_card_networks() | 423 ? spec()->supported_card_networks() |
| 308 : std::vector<std::string>()); | 424 : std::vector<std::string>()); |
| 309 } | 425 } |
| 310 | 426 |
| 311 std::unique_ptr<ui::ComboboxModel> | 427 std::unique_ptr<ui::ComboboxModel> |
| 312 CreditCardEditorViewController::GetComboboxModelForType( | 428 CreditCardEditorViewController::GetComboboxModelForType( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 335 } | 451 } |
| 336 return std::unique_ptr<ui::ComboboxModel>(); | 452 return std::unique_ptr<ui::ComboboxModel>(); |
| 337 } | 453 } |
| 338 | 454 |
| 339 void CreditCardEditorViewController::FillContentView( | 455 void CreditCardEditorViewController::FillContentView( |
| 340 views::View* content_view) { | 456 views::View* content_view) { |
| 341 EditorViewController::FillContentView(content_view); | 457 EditorViewController::FillContentView(content_view); |
| 342 // We need to search from the content view here, since the dialog may not have | 458 // We need to search from the content view here, since the dialog may not have |
| 343 // the content view added to it yet. | 459 // the content view added to it yet. |
| 344 views::Combobox* combobox = static_cast<views::Combobox*>( | 460 views::Combobox* combobox = static_cast<views::Combobox*>( |
| 345 content_view->GetViewByID(kBillingAddressType)); | 461 content_view->GetViewByID(GetInputFieldViewId(kBillingAddressType))); |
| 346 // When the combobox has a single item, it's because it has no addresses | 462 // When the combobox has a single item, it's because it has no addresses |
| 347 // (otherwise, it would have the select header, and a separator before the | 463 // (otherwise, it would have the select header, and a separator before the |
| 348 // first address to choose from). | 464 // first address to choose from). |
| 349 DCHECK(combobox); | 465 DCHECK(combobox); |
| 350 combobox->SetEnabled(combobox->GetRowCount() > 1); | 466 combobox->SetEnabled(combobox->GetRowCount() > 1); |
| 351 } | 467 } |
| 352 | 468 |
| 353 base::string16 CreditCardEditorViewController::GetSheetTitle() { | 469 base::string16 CreditCardEditorViewController::GetSheetTitle() { |
| 354 if (!credit_card_to_edit_) | 470 if (!credit_card_to_edit_) |
| 355 return l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_CARD); | 471 return l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_CARD); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 375 &CreditCardEditorViewController::AddAndSelectNewBillingAddress, | 491 &CreditCardEditorViewController::AddAndSelectNewBillingAddress, |
| 376 base::Unretained(this)), | 492 base::Unretained(this)), |
| 377 /*profile=*/nullptr); | 493 /*profile=*/nullptr); |
| 378 } else { | 494 } else { |
| 379 EditorViewController::ButtonPressed(sender, event); | 495 EditorViewController::ButtonPressed(sender, event); |
| 380 } | 496 } |
| 381 } | 497 } |
| 382 | 498 |
| 383 void CreditCardEditorViewController::AddAndSelectNewBillingAddress( | 499 void CreditCardEditorViewController::AddAndSelectNewBillingAddress( |
| 384 const autofill::AutofillProfile& profile) { | 500 const autofill::AutofillProfile& profile) { |
| 385 views::Combobox* address_combobox = | 501 views::Combobox* address_combobox = static_cast<views::Combobox*>( |
| 386 static_cast<views::Combobox*>(dialog()->GetViewByID(kBillingAddressType)); | 502 dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType))); |
| 387 autofill::AddressComboboxModel* model = | 503 autofill::AddressComboboxModel* model = |
| 388 static_cast<autofill::AddressComboboxModel*>(address_combobox->model()); | 504 static_cast<autofill::AddressComboboxModel*>(address_combobox->model()); |
| 389 int index = model->AddNewProfile(profile); | 505 int index = model->AddNewProfile(profile); |
| 390 // SetSelectedIndex doesn't trigger a perform action notification, which is | 506 // SetSelectedIndex doesn't trigger a perform action notification, which is |
| 391 // needed to update the valid state. | 507 // needed to update the valid state. |
| 392 address_combobox->SetSelectedRow(index); | 508 address_combobox->SetSelectedRow(index); |
| 393 // But it needs to be blured at least once. | 509 // But it needs to be blured at least once. |
| 394 address_combobox->OnBlur(); | 510 address_combobox->OnBlur(); |
| 395 } | 511 } |
| 396 | 512 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 413 | 529 |
| 414 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 530 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 415 IsValidCombobox(views::Combobox* combobox) { | 531 IsValidCombobox(views::Combobox* combobox) { |
| 416 return ValidateCombobox(combobox, nullptr); | 532 return ValidateCombobox(combobox, nullptr); |
| 417 } | 533 } |
| 418 | 534 |
| 419 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 535 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 420 TextfieldValueChanged(views::Textfield* textfield) { | 536 TextfieldValueChanged(views::Textfield* textfield) { |
| 421 base::string16 error_message; | 537 base::string16 error_message; |
| 422 bool is_valid = ValidateValue(textfield->text(), &error_message); | 538 bool is_valid = ValidateValue(textfield->text(), &error_message); |
| 423 controller_->DisplayErrorMessageForField(field_, error_message); | 539 controller_->DisplayErrorMessageForField(field_.type, error_message); |
| 424 return is_valid; | 540 return is_valid; |
| 425 } | 541 } |
| 426 | 542 |
| 427 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 543 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 428 ComboboxValueChanged(views::Combobox* combobox) { | 544 ComboboxValueChanged(views::Combobox* combobox) { |
| 429 base::string16 error_message; | 545 base::string16 error_message; |
| 430 bool is_valid = ValidateCombobox(combobox, nullptr); | 546 bool is_valid = ValidateCombobox(combobox, nullptr); |
| 431 controller_->DisplayErrorMessageForField(field_, error_message); | 547 controller_->DisplayErrorMessageForField(field_.type, error_message); |
| 432 return is_valid; | 548 return is_valid; |
| 433 } | 549 } |
| 434 | 550 |
| 435 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 551 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 436 ValidateValue(const base::string16& value, base::string16* error_message) { | 552 ValidateValue(const base::string16& value, base::string16* error_message) { |
| 437 if (!value.empty()) { | 553 if (!value.empty()) { |
| 438 base::string16 local_error_message; | 554 base::string16 local_error_message; |
| 439 bool is_valid = | 555 bool is_valid = |
| 440 field_.type == autofill::CREDIT_CARD_NUMBER | 556 field_.type == autofill::CREDIT_CARD_NUMBER |
| 441 ? autofill::IsValidCreditCardNumberForBasicCardNetworks( | 557 ? autofill::IsValidCreditCardNumberForBasicCardNetworks( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()), | 591 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()), |
| 476 error_message); | 592 error_message); |
| 477 } | 593 } |
| 478 | 594 |
| 479 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { | 595 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { |
| 480 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; | 596 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; |
| 481 return true; | 597 return true; |
| 482 } | 598 } |
| 483 | 599 |
| 484 } // namespace payments | 600 } // namespace payments |
| OLD | NEW |