Chromium Code Reviews| Index: components/payments/content/payment_request.cc |
| diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc |
| index 27397853dea788f35455313dd81bf316519e41f9..a19cc4f66aa3ba1cd0231732b10adfa08706b202 100644 |
| --- a/components/payments/content/payment_request.cc |
| +++ b/components/payments/content/payment_request.cc |
| @@ -5,6 +5,7 @@ |
| #include "components/payments/content/payment_request.h" |
| #include <algorithm> |
| +#include <set> |
| #include <unordered_map> |
| #include <utility> |
| @@ -68,6 +69,7 @@ void PaymentRequest::Init( |
| PopulateValidatedMethodData(method_data); |
| PopulateProfileCache(); |
| SetDefaultProfileSelections(); |
| + UpdateSelectedShippingOptionFromDetails(); |
| } |
| void PaymentRequest::Show() { |
| @@ -387,4 +389,19 @@ bool PaymentRequest::ArePaymentOptionsSatisfied() { |
| return true; |
| } |
| +void PaymentRequest::UpdateSelectedShippingOptionFromDetails() { |
| + selected_shipping_option_ = nullptr; |
| + |
| + // As per the spec, the selected shipping option should initially be the last |
| + // one in the array that has its selected field set to true. |
| + auto selected_shipping_option_it = std::find_if( |
| + details()->shipping_options.rbegin(), details()->shipping_options.rend(), |
| + [](const payments::mojom::PaymentShippingOptionPtr& element) { |
| + return element->selected; |
| + }); |
| + if (selected_shipping_option_it != details()->shipping_options.rend()) { |
| + selected_shipping_option_ = selected_shipping_option_it->get(); |
|
Mathieu
2017/03/09 19:07:03
I think it's fine to keep the pointer because |det
anthonyvd
2017/03/09 19:43:55
Done.
|
| + } |
| +} |
| + |
| } // namespace payments |