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/shipping_address_editor_view_controll er.h" | 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 return autofill::ADDRESS_HOME_COUNTRY; | 69 return autofill::ADDRESS_HOME_COUNTRY; |
| 70 NOTREACHED(); | 70 NOTREACHED(); |
| 71 return autofill::UNKNOWN_TYPE; | 71 return autofill::UNKNOWN_TYPE; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 ShippingAddressEditorViewController::ShippingAddressEditorViewController( | 76 ShippingAddressEditorViewController::ShippingAddressEditorViewController( |
| 77 PaymentRequestSpec* spec, | 77 PaymentRequestSpec* spec, |
| 78 PaymentRequestState* state, | 78 PaymentRequestState* state, |
| 79 PaymentRequestDialogView* dialog) | 79 PaymentRequestDialogView* dialog, |
| 80 : EditorViewController(spec, state, dialog) { | 80 autofill::AutofillProfile* profile) |
| 81 : EditorViewController(spec, state, dialog), profile_to_edit_(profile) { | |
| 81 UpdateEditorFields(); | 82 UpdateEditorFields(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 ShippingAddressEditorViewController::~ShippingAddressEditorViewController() {} | 85 ShippingAddressEditorViewController::~ShippingAddressEditorViewController() {} |
| 85 | 86 |
| 86 std::unique_ptr<views::View> | 87 std::unique_ptr<views::View> |
| 87 ShippingAddressEditorViewController::CreateHeaderView() { | 88 ShippingAddressEditorViewController::CreateHeaderView() { |
| 88 return base::MakeUnique<views::View>(); | 89 return base::MakeUnique<views::View>(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 std::vector<EditorField> | 92 std::vector<EditorField> |
| 92 ShippingAddressEditorViewController::GetFieldDefinitions() { | 93 ShippingAddressEditorViewController::GetFieldDefinitions() { |
| 93 return editor_fields_; | 94 return editor_fields_; |
| 94 } | 95 } |
| 95 | 96 |
| 97 base::string16 ShippingAddressEditorViewController::GetInitialValueForType( | |
| 98 autofill::ServerFieldType type) { | |
| 99 if (!profile_to_edit_) | |
| 100 return base::string16(); | |
| 101 | |
| 102 // TODO(crbug.com/709451): Use GetInfo() here. | |
|
anthonyvd
2017/04/07 20:08:09
Why not use it already? I'm not sure what in that
Mathieu
2017/04/09 00:35:45
You're right, I can get the app_locale
| |
| 103 return profile_to_edit_->GetRawInfo(type); | |
| 104 } | |
| 105 | |
| 96 bool ShippingAddressEditorViewController::ValidateModelAndSave() { | 106 bool ShippingAddressEditorViewController::ValidateModelAndSave() { |
| 107 // To validate the profile first, we use a temporary object. | |
| 97 autofill::AutofillProfile profile; | 108 autofill::AutofillProfile profile; |
| 98 profile.set_origin(autofill::kSettingsOrigin); | |
| 99 for (const auto& field : text_fields()) { | 109 for (const auto& field : text_fields()) { |
| 100 // Force a blur in case the value was left untouched. | 110 // Force a blur in case the value was left untouched. |
| 101 field.first->OnBlur(); | 111 field.first->OnBlur(); |
| 102 // ValidatingTextfield* is the key, EditorField is the value. | 112 // ValidatingTextfield* is the key, EditorField is the value. |
| 103 if (field.first->invalid()) | 113 if (field.first->invalid()) |
| 104 return false; | 114 return false; |
| 105 | 115 |
| 106 profile.SetRawInfo(field.second.type, field.first->text()); | 116 profile.SetRawInfo(field.second.type, field.first->text()); |
| 107 } | 117 } |
| 108 for (const auto& field : comboboxes()) { | 118 for (const auto& field : comboboxes()) { |
| 109 // ValidatingCombobox* is the key, EditorField is the value. | 119 // ValidatingCombobox* is the key, EditorField is the value. |
| 110 ValidatingCombobox* combobox = field.first; | 120 ValidatingCombobox* combobox = field.first; |
| 111 if (combobox->invalid()) | 121 if (combobox->invalid()) |
| 112 return false; | 122 return false; |
| 113 | 123 |
| 114 if (combobox->id() == autofill::ADDRESS_HOME_COUNTRY) { | 124 if (combobox->id() == autofill::ADDRESS_HOME_COUNTRY) { |
| 115 profile.SetRawInfo( | 125 profile.SetRawInfo( |
| 116 field.second.type, | 126 field.second.type, |
| 117 base::UTF8ToUTF16(country_codes_[combobox->selected_index()])); | 127 base::UTF8ToUTF16(country_codes_[combobox->selected_index()])); |
| 118 } else { | 128 } else { |
| 119 profile.SetRawInfo(field.second.type, | 129 profile.SetRawInfo(field.second.type, |
| 120 combobox->GetTextForRow(combobox->selected_index())); | 130 combobox->GetTextForRow(combobox->selected_index())); |
| 121 } | 131 } |
| 122 } | 132 } |
| 123 | 133 |
| 124 // Add the profile (will not add a duplicate). | 134 if (!profile_to_edit_) { |
| 125 state()->GetPersonalDataManager()->AddProfile(profile); | 135 // Add the profile (will not add a duplicate). |
| 136 profile.set_origin(autofill::kSettingsOrigin); | |
|
anthonyvd
2017/04/07 20:08:09
Do we want a different origin for PaymentRequest?
Mathieu
2017/04/09 00:35:45
I don't think so. "settings" means the profile has
| |
| 137 state()->GetPersonalDataManager()->AddProfile(profile); | |
| 138 } else { | |
| 139 // Copy the temporary object's data to the object to be edited. Prefer this | |
| 140 // method to copying |profile| into |profile_to_edit_|, because the latter | |
| 141 // object needs to retain other properties (use count, use date, guid, | |
| 142 // etc.). | |
| 143 for (const auto& field : text_fields()) { | |
| 144 profile_to_edit_->SetRawInfo(field.second.type, | |
|
anthonyvd
2017/04/07 20:08:09
If GetInfo is preferred over GetRawInfo above, sho
Mathieu
2017/04/09 00:35:45
Yeah I think we should play it safe and use GetInf
| |
| 145 profile.GetRawInfo(field.second.type)); | |
| 146 } | |
| 147 for (const auto& field : comboboxes()) { | |
| 148 profile_to_edit_->SetRawInfo(field.second.type, | |
| 149 profile.GetRawInfo(field.second.type)); | |
| 150 } | |
| 151 profile_to_edit_->set_origin(autofill::kSettingsOrigin); | |
|
anthonyvd
2017/04/07 20:08:09
Same question re: origin.
Mathieu
2017/04/09 00:35:45
Acknowledged.
| |
| 152 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); | |
| 153 } | |
| 126 | 154 |
| 127 return true; | 155 return true; |
| 128 } | 156 } |
| 129 | 157 |
| 130 std::unique_ptr<ValidationDelegate> | 158 std::unique_ptr<ValidationDelegate> |
| 131 ShippingAddressEditorViewController::CreateValidationDelegate( | 159 ShippingAddressEditorViewController::CreateValidationDelegate( |
| 132 const EditorField& field) { | 160 const EditorField& field) { |
| 133 return base::MakeUnique< | 161 return base::MakeUnique< |
| 134 ShippingAddressEditorViewController::ShippingAddressValidationDelegate>( | 162 ShippingAddressEditorViewController::ShippingAddressValidationDelegate>( |
| 135 this, field); | 163 this, field); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 bool is_required_valid = !field_.required; | 356 bool is_required_valid = !field_.required; |
| 329 const base::string16 displayed_message = | 357 const base::string16 displayed_message = |
| 330 is_required_valid ? base::ASCIIToUTF16("") | 358 is_required_valid ? base::ASCIIToUTF16("") |
| 331 : l10n_util::GetStringUTF16( | 359 : l10n_util::GetStringUTF16( |
| 332 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 360 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 333 controller_->DisplayErrorMessageForField(field_, displayed_message); | 361 controller_->DisplayErrorMessageForField(field_, displayed_message); |
| 334 return is_required_valid; | 362 return is_required_valid; |
| 335 } | 363 } |
| 336 | 364 |
| 337 } // namespace payments | 365 } // namespace payments |
| OLD | NEW |