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> |
| 11 | 11 |
| 12 #include "base/bind.h" | |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 19 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | |
| 18 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 19 #include "chrome/browser/ui/views/payments/preselected_combobox_model.h" | 21 #include "chrome/browser/ui/views/payments/preselected_combobox_model.h" |
| 20 #include "chrome/browser/ui/views/payments/validating_combobox.h" | 22 #include "chrome/browser/ui/views/payments/validating_combobox.h" |
| 21 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 23 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 22 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/autofill/core/browser/address_combobox_model.h" | |
| 23 #include "components/autofill/core/browser/autofill_data_util.h" | 26 #include "components/autofill/core/browser/autofill_data_util.h" |
| 24 #include "components/autofill/core/browser/autofill_type.h" | 27 #include "components/autofill/core/browser/autofill_type.h" |
| 25 #include "components/autofill/core/browser/credit_card.h" | 28 #include "components/autofill/core/browser/credit_card.h" |
| 26 #include "components/autofill/core/browser/field_types.h" | 29 #include "components/autofill/core/browser/field_types.h" |
| 27 #include "components/autofill/core/browser/personal_data_manager.h" | 30 #include "components/autofill/core/browser/personal_data_manager.h" |
| 28 #include "components/autofill/core/browser/validation.h" | 31 #include "components/autofill/core/browser/validation.h" |
| 29 #include "components/autofill/core/common/autofill_clock.h" | 32 #include "components/autofill/core/common/autofill_clock.h" |
| 30 #include "components/autofill/core/common/autofill_constants.h" | 33 #include "components/autofill/core/common/autofill_constants.h" |
| 31 #include "components/payments/content/payment_request_spec.h" | 34 #include "components/payments/content/payment_request_spec.h" |
| 32 #include "components/payments/content/payment_request_state.h" | 35 #include "components/payments/content/payment_request_state.h" |
| 33 #include "components/strings/grit/components_strings.h" | 36 #include "components/strings/grit/components_strings.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/native_theme/native_theme.h" | 38 #include "ui/native_theme/native_theme.h" |
| 39 #include "ui/views/controls/button/md_text_button.h" | |
| 36 #include "ui/views/controls/image_view.h" | 40 #include "ui/views/controls/image_view.h" |
| 37 #include "ui/views/controls/label.h" | 41 #include "ui/views/controls/label.h" |
| 38 #include "ui/views/controls/textfield/textfield.h" | 42 #include "ui/views/controls/textfield/textfield.h" |
| 39 #include "ui/views/layout/box_layout.h" | 43 #include "ui/views/layout/box_layout.h" |
| 44 #include "ui/views/layout/grid_layout.h" | |
| 40 #include "ui/views/view.h" | 45 #include "ui/views/view.h" |
| 41 | 46 |
| 42 namespace payments { | 47 namespace payments { |
| 43 | 48 |
| 44 namespace { | 49 namespace { |
| 45 | 50 |
| 46 // Number of years (including the current one) to be shown in the expiration | 51 // Number of years (including the current one) to be shown in the expiration |
| 47 // year dropdown. | 52 // year dropdown. |
| 48 const int kNumberOfExpirationYears = 10; | 53 const int kNumberOfExpirationYears = 10; |
| 49 | 54 |
| 55 // To avoid collision with server field types which are used as view IDs. | |
| 56 const auto kBillingAddressType = autofill::MAX_VALID_FIELD_TYPE; | |
|
Mathieu
2017/05/04 20:29:19
we could use ADDRESS_BILLING_LINE_1, which is othe
MAD
2017/05/05 00:50:07
Done.
| |
| 57 | |
| 50 // Returns the items that are in the expiration month dropdown. Will return the | 58 // Returns the items that are in the expiration month dropdown. Will return the |
| 51 // months in order starting at "01" until "12". Uses a clock so that the | 59 // months in order starting at "01" until "12". Uses a clock so that the |
| 52 // |default_index| is set to the current month. | 60 // |default_index| is set to the current month. |
| 53 std::vector<base::string16> GetExpirationMonthItems(int* default_index) { | 61 std::vector<base::string16> GetExpirationMonthItems(int* default_index) { |
| 54 std::vector<base::string16> months; | 62 std::vector<base::string16> months; |
| 55 months.reserve(12); | 63 months.reserve(12); |
| 56 for (int i = 1; i <= 12; i++) | 64 for (int i = 1; i <= 12; i++) |
| 57 months.push_back(base::UTF8ToUTF16(base::StringPrintf("%02d", i))); | 65 months.push_back(base::UTF8ToUTF16(base::StringPrintf("%02d", i))); |
| 58 | 66 |
| 59 base::Time::Exploded now_exploded; | 67 base::Time::Exploded now_exploded; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 76 } | 84 } |
| 77 return years; | 85 return years; |
| 78 } | 86 } |
| 79 | 87 |
| 80 } // namespace | 88 } // namespace |
| 81 | 89 |
| 82 CreditCardEditorViewController::CreditCardEditorViewController( | 90 CreditCardEditorViewController::CreditCardEditorViewController( |
| 83 PaymentRequestSpec* spec, | 91 PaymentRequestSpec* spec, |
| 84 PaymentRequestState* state, | 92 PaymentRequestState* state, |
| 85 PaymentRequestDialogView* dialog, | 93 PaymentRequestDialogView* dialog, |
| 94 BackNavigationType back_navigation, | |
| 95 int next_ui_tag, | |
| 86 base::OnceClosure on_edited, | 96 base::OnceClosure on_edited, |
| 87 base::OnceCallback<void(const autofill::CreditCard&)> on_added, | 97 base::OnceCallback<void(const autofill::CreditCard&)> on_added, |
| 88 autofill::CreditCard* credit_card) | 98 autofill::CreditCard* credit_card) |
| 89 : EditorViewController(spec, state, dialog), | 99 : EditorViewController(spec, state, dialog, back_navigation), |
| 90 on_edited_(std::move(on_edited)), | 100 on_edited_(std::move(on_edited)), |
| 91 on_added_(std::move(on_added)), | 101 on_added_(std::move(on_added)), |
| 92 credit_card_to_edit_(credit_card) {} | 102 credit_card_to_edit_(credit_card), |
| 103 add_billing_address_button_tag_(next_ui_tag) {} | |
| 93 | 104 |
| 94 CreditCardEditorViewController::~CreditCardEditorViewController() {} | 105 CreditCardEditorViewController::~CreditCardEditorViewController() {} |
| 95 | 106 |
| 96 // Creates the "Cards accepted" view with a row of icons at the top of the | 107 // Creates the "Cards accepted" view with a row of icons at the top of the |
| 97 // credit card editor. | 108 // credit card editor. |
| 98 // +----------------------------------------------+ | 109 // +----------------------------------------------+ |
| 99 // | Cards Accepted | | 110 // | Cards Accepted | |
| 100 // | | | 111 // | | |
| 101 // | | VISA | | MC | | AMEX | | | 112 // | | VISA | | MC | | AMEX | | |
| 102 // +----------------------------------------------+ | 113 // +----------------------------------------------+ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 base::UTF8ToUTF16(supported_network)); | 152 base::UTF8ToUTF16(supported_network)); |
| 142 card_icon_view->SetImageSize(kCardIconSize); | 153 card_icon_view->SetImageSize(kCardIconSize); |
| 143 | 154 |
| 144 icons_row->AddChildView(card_icon_view.release()); | 155 icons_row->AddChildView(card_icon_view.release()); |
| 145 } | 156 } |
| 146 view->AddChildView(icons_row.release()); | 157 view->AddChildView(icons_row.release()); |
| 147 | 158 |
| 148 return view; | 159 return view; |
| 149 } | 160 } |
| 150 | 161 |
| 162 std::unique_ptr<views::View> | |
|
Mathieu
2017/05/04 20:29:19
I would add ASCII art about what you are building
MAD
2017/05/05 00:50:07
Done.
| |
| 163 CreditCardEditorViewController::CreateCustomFieldsView() { | |
| 164 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | |
| 165 | |
| 166 std::unique_ptr<views::GridLayout> layout = | |
| 167 base::MakeUnique<views::GridLayout>(view.get()); | |
| 168 | |
| 169 // Label column. | |
| 170 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 171 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
| 172 views::GridLayout::USE_PREF, 0, 0); | |
| 173 | |
| 174 // This is the horizontal padding between the label and the combobox. | |
| 175 columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); | |
| 176 | |
| 177 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
| 178 views::GridLayout::USE_PREF, 0, 0); | |
| 179 | |
| 180 // This is the horizontal padding between the combobox and the add button. | |
| 181 constexpr int kComboboxAddButtonHorizontalPadding = 8; | |
| 182 columns->AddPaddingColumn(0, kComboboxAddButtonHorizontalPadding); | |
| 183 | |
| 184 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
| 185 views::GridLayout::USE_PREF, 0, 0); | |
| 186 | |
| 187 layout->StartRow(0, 0); | |
| 188 | |
| 189 EditorField billing_address_field( | |
| 190 kBillingAddressType, | |
| 191 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_BILLING_ADDRESS), | |
| 192 EditorField::LengthHint::HINT_SHORT, /*required=*/true, | |
| 193 EditorField::ControlType::COMBOBOX); | |
| 194 | |
| 195 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | |
| 196 billing_address_field.label + base::ASCIIToUTF16("*")); | |
| 197 | |
| 198 label->SetMultiLine(true); | |
| 199 label->SetMaximumWidth(kMaximumLabelWidth); | |
| 200 layout->AddView(label.release()); | |
| 201 | |
| 202 // The combobox filled with potential billing addresses. | |
| 203 int selected_index = -1; | |
|
Mathieu
2017/05/04 20:29:19
nit: I would move this closer to the if block
MAD
2017/05/05 00:50:07
Done.
| |
| 204 std::unique_ptr<autofill::AddressComboboxModel> address_combobox_model( | |
|
Mathieu
2017/05/04 20:29:18
can use = here?
MAD
2017/05/05 00:50:07
OK, but I thought that constructor were prefered i
| |
| 205 base::MakeUnique<autofill::AddressComboboxModel>( | |
| 206 *state()->GetPersonalDataManager(), state()->GetApplicationLocale())); | |
| 207 if (credit_card_to_edit_ && | |
| 208 !credit_card_to_edit_->billing_address_id().empty()) { | |
| 209 selected_index = address_combobox_model->GetIndexOfIdentifier( | |
| 210 credit_card_to_edit_->billing_address_id()); | |
| 211 } | |
| 212 // This takes care of rare cases where the the billing address set on the | |
| 213 // current card isn't valid anymore. | |
| 214 if (selected_index == -1) | |
| 215 selected_index = address_combobox_model->GetDefaultIndex(); | |
| 216 | |
| 217 ValidatingCombobox* combobox = | |
| 218 new ValidatingCombobox(std::move(address_combobox_model), | |
| 219 CreateValidationDelegate(billing_address_field)); | |
| 220 combobox->SetSelectedIndex(selected_index); | |
| 221 | |
| 222 // Using autofill field type as a view ID (for testing). | |
| 223 combobox->set_id(static_cast<int>(billing_address_field.type)); | |
| 224 combobox->set_listener(this); | |
| 225 | |
| 226 // |combobox| will now be owned by |row|. | |
| 227 layout->AddView(combobox); | |
| 228 | |
| 229 // The button to add new billing addresses. | |
| 230 std::unique_ptr<views::Button> add_button( | |
| 231 views::MdTextButton::Create(this, l10n_util::GetStringUTF16(IDS_ADD))); | |
| 232 add_button->set_id( | |
| 233 static_cast<int>(DialogViewID::ADD_BILLING_ADDRESS_BUTTON)); | |
| 234 add_button->set_tag(add_billing_address_button_tag_); | |
| 235 | |
| 236 // |add_button| will now be owned by |row|. | |
| 237 layout->AddView(add_button.release()); | |
| 238 view->SetLayoutManager(layout.release()); | |
| 239 return view; | |
| 240 } | |
| 241 | |
| 151 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { | 242 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { |
| 152 return std::vector<EditorField>{ | 243 return std::vector<EditorField>{ |
| 153 {autofill::CREDIT_CARD_NUMBER, | 244 {autofill::CREDIT_CARD_NUMBER, |
| 154 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), | 245 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), |
| 155 EditorField::LengthHint::HINT_LONG, /* required= */ true}, | 246 EditorField::LengthHint::HINT_LONG, /* required= */ true}, |
| 156 {autofill::CREDIT_CARD_NAME_FULL, | 247 {autofill::CREDIT_CARD_NAME_FULL, |
| 157 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), | 248 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), |
| 158 EditorField::LengthHint::HINT_LONG, /* required= */ true}, | 249 EditorField::LengthHint::HINT_LONG, /* required= */ true}, |
| 159 {autofill::CREDIT_CARD_EXP_MONTH, | 250 {autofill::CREDIT_CARD_EXP_MONTH, |
| 160 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH), | 251 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 autofill::AutofillType(field.second.type).group()); | 288 autofill::AutofillType(field.second.type).group()); |
| 198 ValidatingCombobox* combobox = field.first; | 289 ValidatingCombobox* combobox = field.first; |
| 199 if (combobox->invalid()) | 290 if (combobox->invalid()) |
| 200 return false; | 291 return false; |
| 201 | 292 |
| 202 credit_card.SetInfo(autofill::AutofillType(field.second.type), | 293 credit_card.SetInfo(autofill::AutofillType(field.second.type), |
| 203 combobox->GetTextForRow(combobox->selected_index()), | 294 combobox->GetTextForRow(combobox->selected_index()), |
| 204 locale); | 295 locale); |
| 205 } | 296 } |
| 206 | 297 |
| 298 views::Combobox* address_combobox = | |
| 299 static_cast<views::Combobox*>(dialog()->GetViewByID(kBillingAddressType)); | |
| 300 autofill::AddressComboboxModel* model = | |
| 301 static_cast<autofill::AddressComboboxModel*>(address_combobox->model()); | |
| 302 | |
| 303 credit_card.set_billing_address_id( | |
| 304 model->GetItemIdentifierAt(address_combobox->selected_index())); | |
| 305 | |
| 207 // TODO(crbug.com/711365): Display global error message. | 306 // TODO(crbug.com/711365): Display global error message. |
| 208 if (autofill::GetCompletionStatusForCard(credit_card, locale) != | 307 if (autofill::GetCompletionStatusForCard( |
| 308 credit_card, locale, | |
| 309 state()->GetPersonalDataManager()->GetProfiles()) != | |
| 209 autofill::CREDIT_CARD_COMPLETE) { | 310 autofill::CREDIT_CARD_COMPLETE) { |
| 210 return false; | 311 return false; |
| 211 } | 312 } |
| 212 | 313 |
| 213 if (!credit_card_to_edit_) { | 314 if (!credit_card_to_edit_) { |
| 214 // Add the card (will not add a duplicate). | 315 // Add the card (will not add a duplicate). |
| 215 state()->GetPersonalDataManager()->AddCreditCard(credit_card); | 316 state()->GetPersonalDataManager()->AddCreditCard(credit_card); |
| 216 std::move(on_added_).Run(credit_card); | 317 std::move(on_added_).Run(credit_card); |
| 217 } else { | 318 } else { |
| 319 credit_card_to_edit_->set_billing_address_id( | |
| 320 credit_card.billing_address_id()); | |
| 218 // We were in edit mode. Copy the data from the temporary object to retain | 321 // We were in edit mode. Copy the data from the temporary object to retain |
| 219 // the edited object's other properties (use count, use date, guid, etc.). | 322 // the edited object's other properties (use count, use date, guid, etc.). |
| 220 for (const auto& field : text_fields()) { | 323 for (const auto& field : text_fields()) { |
| 221 credit_card_to_edit_->SetInfo( | 324 credit_card_to_edit_->SetInfo( |
| 222 autofill::AutofillType(field.second.type), | 325 autofill::AutofillType(field.second.type), |
| 223 credit_card.GetInfo(autofill::AutofillType(field.second.type), | 326 credit_card.GetInfo(autofill::AutofillType(field.second.type), |
| 224 locale), | 327 locale), |
| 225 locale); | 328 locale); |
| 226 } | 329 } |
| 227 for (const auto& field : comboboxes()) { | 330 for (const auto& field : comboboxes()) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 252 } | 355 } |
| 253 | 356 |
| 254 std::unique_ptr<ui::ComboboxModel> | 357 std::unique_ptr<ui::ComboboxModel> |
| 255 CreditCardEditorViewController::GetComboboxModelForType( | 358 CreditCardEditorViewController::GetComboboxModelForType( |
| 256 const autofill::ServerFieldType& type) { | 359 const autofill::ServerFieldType& type) { |
| 257 switch (type) { | 360 switch (type) { |
| 258 case autofill::CREDIT_CARD_EXP_MONTH: { | 361 case autofill::CREDIT_CARD_EXP_MONTH: { |
| 259 int default_index = 0; | 362 int default_index = 0; |
| 260 std::vector<base::string16> months = | 363 std::vector<base::string16> months = |
| 261 GetExpirationMonthItems(&default_index); | 364 GetExpirationMonthItems(&default_index); |
| 262 return std::unique_ptr<ui::ComboboxModel>( | 365 return base::MakeUnique<PreselectedComboboxModel>(months, default_index); |
| 263 new PreselectedComboboxModel(months, default_index)); | |
| 264 } | 366 } |
| 265 case autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR: | 367 case autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 266 return std::unique_ptr<ui::ComboboxModel>( | 368 return base::MakeUnique<ui::SimpleComboboxModel>( |
| 267 new ui::SimpleComboboxModel(GetExpirationYearItems())); | 369 GetExpirationYearItems()); |
| 268 default: | 370 default: |
| 269 NOTREACHED(); | 371 NOTREACHED(); |
| 270 break; | 372 break; |
| 271 } | 373 } |
| 272 return std::unique_ptr<ui::ComboboxModel>(); | 374 return std::unique_ptr<ui::ComboboxModel>(); |
| 273 } | 375 } |
| 274 | 376 |
| 275 base::string16 CreditCardEditorViewController::GetSheetTitle() { | 377 base::string16 CreditCardEditorViewController::GetSheetTitle() { |
| 276 if (!credit_card_to_edit_) | 378 if (!credit_card_to_edit_) |
| 277 return l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_CARD); | 379 return l10n_util::GetStringUTF16(IDS_PAYMENTS_ADD_CARD); |
| 278 | 380 |
| 279 // Gets the completion message, or empty if nothing is missing from the card. | 381 // Gets the completion message, or empty if nothing is missing from the card. |
| 280 base::string16 title = autofill::GetCompletionMessageForCard( | 382 base::string16 title = autofill::GetCompletionMessageForCard( |
| 281 autofill::GetCompletionStatusForCard(*credit_card_to_edit_, | 383 autofill::GetCompletionStatusForCard( |
| 282 state()->GetApplicationLocale())); | 384 *credit_card_to_edit_, state()->GetApplicationLocale(), |
| 385 state()->GetPersonalDataManager()->GetProfiles())); | |
| 283 return title.empty() ? l10n_util::GetStringUTF16(IDS_PAYMENTS_EDIT_CARD) | 386 return title.empty() ? l10n_util::GetStringUTF16(IDS_PAYMENTS_EDIT_CARD) |
| 284 : title; | 387 : title; |
| 285 } | 388 } |
| 286 | 389 |
| 390 void CreditCardEditorViewController::ButtonPressed(views::Button* sender, | |
| 391 const ui::Event& event) { | |
| 392 if (sender->tag() == add_billing_address_button_tag_) { | |
| 393 dialog()->ShowShippingAddressEditor( | |
| 394 BackNavigationType::kOneStep, | |
| 395 /*on_edited=*/ | |
| 396 base::OnceClosure(), | |
|
Mathieu
2017/05/04 20:29:19
TODO: there is a possibility that the billing addr
MAD
2017/05/05 00:50:07
Really? Should't the editor prevent the creation o
Mathieu
2017/05/05 13:51:33
We may have an incomplete billing address because
MAD
2017/05/05 18:32:33
HA OK! Got it... Added a TODO and a bug.
| |
| 397 /*on_added=*/ | |
| 398 base::BindOnce( | |
| 399 &CreditCardEditorViewController::AddAndSelectNewBillingAddress, | |
| 400 base::Unretained(this)), | |
| 401 /*profile=*/nullptr); | |
| 402 } else { | |
| 403 EditorViewController::ButtonPressed(sender, event); | |
| 404 } | |
| 405 } | |
| 406 | |
| 407 void CreditCardEditorViewController::AddAndSelectNewBillingAddress( | |
| 408 const autofill::AutofillProfile& profile) { | |
| 409 views::Combobox* address_combobox = | |
| 410 static_cast<views::Combobox*>(dialog()->GetViewByID(kBillingAddressType)); | |
| 411 autofill::AddressComboboxModel* model = | |
| 412 static_cast<autofill::AddressComboboxModel*>(address_combobox->model()); | |
| 413 int index = model->AddNewProfile(profile); | |
| 414 address_combobox->SetSelectedIndex(index); | |
| 415 // Force revalidation. | |
| 416 address_combobox->OnBlur(); | |
| 417 } | |
| 418 | |
| 287 CreditCardEditorViewController::CreditCardValidationDelegate:: | 419 CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 288 CreditCardValidationDelegate( | 420 CreditCardValidationDelegate( |
| 289 const EditorField& field, | 421 const EditorField& field, |
| 290 EditorViewController* controller, | 422 EditorViewController* controller, |
| 291 const std::vector<std::string>& supported_card_networks) | 423 const std::vector<std::string>& supported_card_networks) |
| 292 : field_(field), | 424 : field_(field), |
| 293 controller_(controller), | 425 controller_(controller), |
| 294 supported_card_networks_(supported_card_networks.begin(), | 426 supported_card_networks_(supported_card_networks.begin(), |
| 295 supported_card_networks.end()) {} | 427 supported_card_networks.end()) {} |
| 296 CreditCardEditorViewController::CreditCardValidationDelegate:: | 428 CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 297 ~CreditCardValidationDelegate() {} | 429 ~CreditCardValidationDelegate() {} |
| 298 | 430 |
| 299 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 431 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 300 ValidateTextfield(views::Textfield* textfield) { | 432 ValidateTextfield(views::Textfield* textfield) { |
| 301 return ValidateValue(textfield->text()); | 433 return ValidateValue(textfield->text()); |
| 302 } | 434 } |
| 303 | 435 |
| 304 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 436 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 305 ValidateCombobox(views::Combobox* combobox) { | 437 ValidateCombobox(views::Combobox* combobox) { |
| 438 // The address combobox value only need to not be an empty item identifier. | |
|
Mathieu
2017/05/04 20:29:19
rephrase/fix?
MAD
2017/05/05 00:50:07
Done.
| |
| 439 if (field_.type == kBillingAddressType) { | |
| 440 autofill::AddressComboboxModel* model = | |
| 441 static_cast<autofill::AddressComboboxModel*>(combobox->model()); | |
| 442 return !model->GetItemIdentifierAt(combobox->selected_index()).empty(); | |
| 443 } | |
| 306 return ValidateValue(combobox->GetTextForRow(combobox->selected_index())); | 444 return ValidateValue(combobox->GetTextForRow(combobox->selected_index())); |
| 307 } | 445 } |
| 308 | 446 |
| 309 bool CreditCardEditorViewController::CreditCardValidationDelegate:: | 447 bool CreditCardEditorViewController::CreditCardValidationDelegate:: |
| 310 ValidateValue(const base::string16& value) { | 448 ValidateValue(const base::string16& value) { |
| 311 if (!value.empty()) { | 449 if (!value.empty()) { |
| 312 base::string16 error_message; | 450 base::string16 error_message; |
| 313 bool is_valid = | 451 bool is_valid = |
| 314 field_.type == autofill::CREDIT_CARD_NUMBER | 452 field_.type == autofill::CREDIT_CARD_NUMBER |
| 315 ? autofill::IsValidCreditCardNumberForBasicCardNetworks( | 453 ? autofill::IsValidCreditCardNumberForBasicCardNetworks( |
| 316 value, supported_card_networks_, &error_message) | 454 value, supported_card_networks_, &error_message) |
| 317 : autofill::IsValidForType(value, field_.type, &error_message); | 455 : autofill::IsValidForType(value, field_.type, &error_message); |
| 318 controller_->DisplayErrorMessageForField(field_, error_message); | 456 controller_->DisplayErrorMessageForField(field_, error_message); |
| 319 return is_valid; | 457 return is_valid; |
| 320 } | 458 } |
| 321 | 459 |
| 322 bool is_required_valid = !field_.required; | 460 bool is_required_valid = !field_.required; |
| 323 const base::string16 displayed_message = | 461 const base::string16 displayed_message = |
| 324 is_required_valid ? base::ASCIIToUTF16("") | 462 is_required_valid ? base::ASCIIToUTF16("") |
| 325 : l10n_util::GetStringUTF16( | 463 : l10n_util::GetStringUTF16( |
| 326 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 464 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 327 controller_->DisplayErrorMessageForField(field_, displayed_message); | 465 controller_->DisplayErrorMessageForField(field_, displayed_message); |
| 328 return is_required_valid; | 466 return is_required_valid; |
| 329 } | 467 } |
| 330 | 468 |
| 331 } // namespace payments | 469 } // namespace payments |
| OLD | NEW |