Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: chrome/browser/ui/views/payments/profile_list_view_controller.cc

Issue 2923533002: [Merge M60][Payments] Do not select an address if the merchant doesn't support it (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/profile_list_view_controller.h" 5 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
9 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 9 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
10 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 10 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 : ProfileListViewController(spec, state, dialog) { 112 : ProfileListViewController(spec, state, dialog) {
113 spec->AddObserver(this); 113 spec->AddObserver(this);
114 PopulateList(); 114 PopulateList();
115 } 115 }
116 ~ShippingProfileViewController() override { spec()->RemoveObserver(this); } 116 ~ShippingProfileViewController() override { spec()->RemoveObserver(this); }
117 117
118 protected: 118 protected:
119 // ProfileListViewController: 119 // ProfileListViewController:
120 std::unique_ptr<views::View> GetLabel( 120 std::unique_ptr<views::View> GetLabel(
121 autofill::AutofillProfile* profile) override { 121 autofill::AutofillProfile* profile) override {
122 if (!IsEnabled(profile)) {
123 // The error is not shown in the label itself on this screen, but the
124 // entry is disabled.
125 return GetShippingAddressLabelWithError(
126 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile,
127 /*error=*/base::string16(), /*disabled_state=*/true);
128 }
129 return GetShippingAddressLabelWithMissingInfo( 122 return GetShippingAddressLabelWithMissingInfo(
130 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, 123 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile,
131 *(state()->profile_comparator())); 124 *(state()->profile_comparator()),
125 /*enabled=*/IsEnabled(profile));
132 } 126 }
133 127
134 void SelectProfile(autofill::AutofillProfile* profile) override { 128 void SelectProfile(autofill::AutofillProfile* profile) override {
129 // This will trigger a merchant update as well as a full spinner on top
130 // of the profile list. When the spec comes back updated (in OnSpecUpdated),
131 // the decision will be made to either stay on this screen or go back to the
132 // payment sheet.
135 state()->SetSelectedShippingProfile(profile); 133 state()->SetSelectedShippingProfile(profile);
136 } 134 }
137 135
138 void ShowEditor(autofill::AutofillProfile* profile) override { 136 void ShowEditor(autofill::AutofillProfile* profile) override {
139 dialog()->ShowShippingAddressEditor( 137 dialog()->ShowShippingAddressEditor(
140 BackNavigationType::kPaymentSheet, 138 BackNavigationType::kPaymentSheet,
141 /*on_edited=*/ 139 /*on_edited=*/
142 base::BindOnce(&PaymentRequestState::SetSelectedShippingProfile, 140 base::BindOnce(&PaymentRequestState::SetSelectedShippingProfile,
143 base::Unretained(state()), profile), 141 base::Unretained(state()), profile),
144 /*on_added=*/ 142 /*on_added=*/
145 base::BindOnce(&PaymentRequestState::AddAutofillShippingProfile, 143 base::BindOnce(&PaymentRequestState::AddAutofillShippingProfile,
146 base::Unretained(state()), /*selected=*/true), 144 base::Unretained(state()), /*selected=*/true),
147 profile); 145 profile);
148 } 146 }
149 147
150 autofill::AutofillProfile* GetSelectedProfile() override { 148 autofill::AutofillProfile* GetSelectedProfile() override {
151 // If there are no errors with the currently selected profile, return it. 149 return state()->selected_shipping_profile();
152 return spec()->selected_shipping_option_error().empty()
153 ? state()->selected_shipping_profile()
154 : nullptr;
155 } 150 }
156 151
157 bool IsValidProfile(const autofill::AutofillProfile& profile) override { 152 bool IsValidProfile(const autofill::AutofillProfile& profile) override {
158 return state()->profile_comparator()->IsShippingComplete(&profile); 153 return state()->profile_comparator()->IsShippingComplete(&profile);
159 } 154 }
160 155
161 std::vector<autofill::AutofillProfile*> GetProfiles() override { 156 std::vector<autofill::AutofillProfile*> GetProfiles() override {
162 return state()->shipping_profiles(); 157 return state()->shipping_profiles();
163 } 158 }
164 159
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 207
213 int GetSecondaryButtonTag() override { 208 int GetSecondaryButtonTag() override {
214 return static_cast<int>( 209 return static_cast<int>(
215 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON); 210 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON);
216 } 211 }
217 212
218 int GetSecondaryButtonViewId() override { 213 int GetSecondaryButtonViewId() override {
219 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); 214 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON);
220 } 215 }
221 216
217 bool IsEnabled(autofill::AutofillProfile* profile) override {
218 // If selected_shipping_option_error_profile() is null, then no error is
219 // reported by the merchant and all items are enabled. If it is not null and
220 // equal to |profile|, then |profile| should be disabled.
221 return !state()->selected_shipping_option_error_profile() ||
222 profile != state()->selected_shipping_option_error_profile();
223 }
224
222 private: 225 private:
223 void OnSpecUpdated() override { 226 void OnSpecUpdated() override {
224 // If there's an error, stay on this screen so the user can select a 227 // If there's an error, stay on this screen so the user can select a
225 // different address. Otherwise, go back to the payment sheet. 228 // different address. Otherwise, go back to the payment sheet.
226 if (spec()->current_update_reason() == 229 if (spec()->current_update_reason() ==
227 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) { 230 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) {
228 if (spec()->selected_shipping_option_error().empty()) { 231 if (!state()->selected_shipping_option_error_profile()) {
229 dialog()->GoBack(); 232 dialog()->GoBack();
230 } else { 233 } else {
234 // The error profile is known, refresh the view to display it correctly.
231 UpdateContentView(); 235 UpdateContentView();
232 } 236 }
233 } 237 }
234 } 238 }
235 239
236 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); 240 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController);
237 }; 241 };
238 242
239 class ContactProfileViewController : public ProfileListViewController { 243 class ContactProfileViewController : public ProfileListViewController {
240 public: 244 public:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 336
333 ProfileListViewController::ProfileListViewController( 337 ProfileListViewController::ProfileListViewController(
334 PaymentRequestSpec* spec, 338 PaymentRequestSpec* spec,
335 PaymentRequestState* state, 339 PaymentRequestState* state,
336 PaymentRequestDialogView* dialog) 340 PaymentRequestDialogView* dialog)
337 : PaymentRequestSheetController(spec, state, dialog) {} 341 : PaymentRequestSheetController(spec, state, dialog) {}
338 342
339 ProfileListViewController::~ProfileListViewController() {} 343 ProfileListViewController::~ProfileListViewController() {}
340 344
341 bool ProfileListViewController::IsEnabled(autofill::AutofillProfile* profile) { 345 bool ProfileListViewController::IsEnabled(autofill::AutofillProfile* profile) {
342 // If selected_shipping_option_error() is not empty, it means the current 346 return true;
343 // selected_shipping_profile() is not supported by this merchant and should be
344 // shown in a disabled state. Therefore, |profile| is enabled in cases where
345 // (1) it's not the selected_shipping_profile
346 // OR
347 // (2) if it is, there is no shipping option error reported by the merchant.
348 return profile != state()->selected_shipping_profile() ||
349 spec()->selected_shipping_option_error().empty();
350 } 347 }
351 348
352 std::unique_ptr<views::View> ProfileListViewController::CreateHeaderView() { 349 std::unique_ptr<views::View> ProfileListViewController::CreateHeaderView() {
353 return nullptr; 350 return nullptr;
354 } 351 }
355 352
356 void ProfileListViewController::PopulateList() { 353 void ProfileListViewController::PopulateList() {
357 autofill::AutofillProfile* selected_profile = GetSelectedProfile(); 354 autofill::AutofillProfile* selected_profile = GetSelectedProfile();
358 355
359 // This must be done at Create-time, rather than construct-time, because 356 // This must be done at Create-time, rather than construct-time, because
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 395
399 void ProfileListViewController::ButtonPressed(views::Button* sender, 396 void ProfileListViewController::ButtonPressed(views::Button* sender,
400 const ui::Event& event) { 397 const ui::Event& event) {
401 if (sender->tag() == GetSecondaryButtonTag()) 398 if (sender->tag() == GetSecondaryButtonTag())
402 ShowEditor(nullptr); 399 ShowEditor(nullptr);
403 else 400 else
404 PaymentRequestSheetController::ButtonPressed(sender, event); 401 PaymentRequestSheetController::ButtonPressed(sender, event);
405 } 402 }
406 403
407 } // namespace payments 404 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698