Chromium Code Reviews| Index: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc |
| diff --git a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc |
| index 073718c8a63fd05d1ac47608b930a8b66e30bc6f..c7159912c88d87357b0af4812dc7e9c50d231849 100644 |
| --- a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc |
| +++ b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc |
| @@ -194,13 +194,19 @@ PaymentSheetViewController::PaymentSheetViewController( |
| : PaymentRequestSheetController(spec, state, dialog), |
| pay_button_(nullptr), |
| widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { |
| + spec->AddObserver(this); |
| state->AddObserver(this); |
| } |
| PaymentSheetViewController::~PaymentSheetViewController() { |
| + spec()->RemoveObserver(this); |
| state()->RemoveObserver(this); |
| } |
| +void PaymentSheetViewController::OnSpecUpdated() { |
| + UpdateContentView(); |
| +} |
| + |
| void PaymentSheetViewController::OnSelectedInformationChanged() { |
| UpdatePayButtonState(state()->is_ready_to_pay()); |
| UpdateContentView(); |
| @@ -240,8 +246,14 @@ void PaymentSheetViewController::FillContentView(views::View* content_view) { |
| if (spec()->request_shipping()) { |
| layout->StartRow(0, 0); |
| layout->AddView(CreateShippingRow().release()); |
| - layout->StartRow(0, 0); |
| - layout->AddView(CreateShippingOptionRow().release()); |
| + // It's possible for requestShipping to be true and for there to be no |
| + // shipping options yet (they will come in updateWith). |
| + // TODO(crbug.com/xxxxxx): Put a better placeholder row, instead of no row. |
|
anthonyvd
2017/04/03 15:09:58
nit: you might want an actual bug # here.
Mathieu
2017/04/03 16:27:27
Done.
|
| + std::unique_ptr<views::Button> shipping_row = CreateShippingOptionRow(); |
| + if (shipping_row) { |
| + layout->StartRow(0, 0); |
| + layout->AddView(shipping_row.release()); |
| + } |
| } |
| layout->StartRow(0, 0); |
| layout->AddView(CreatePaymentMethodRow().release()); |
| @@ -383,9 +395,9 @@ std::unique_ptr<views::View> |
| PaymentSheetViewController::CreateShippingSectionContent() { |
| auto* profile = state()->selected_shipping_profile(); |
| - return profile ? payments::GetShippingAddressLabel( |
| - AddressStyleType::SUMMARY, |
| - state()->GetApplicationLocale(), *profile) |
| + return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, |
| + state()->GetApplicationLocale(), |
| + *profile) |
| : base::MakeUnique<views::Label>(base::string16()); |
| } |
| @@ -486,8 +498,11 @@ PaymentSheetViewController::CreateContactInfoRow() { |
| std::unique_ptr<views::Button> |
| PaymentSheetViewController::CreateShippingOptionRow() { |
| - payments::mojom::PaymentShippingOption* selected_option = |
| - state()->selected_shipping_option(); |
| + mojom::PaymentShippingOption* selected_option = |
| + spec()->selected_shipping_option(); |
| + if (!selected_option) |
| + return nullptr; |
| + |
| std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( |
| selected_option, selected_option ? spec()->GetFormattedCurrencyAmount( |
| selected_option->amount->value) |