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

Unified Diff: components/payments/content/payment_request.cc

Issue 2744633002: [Web Payments] Add the shipping method section to the payment sheet (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698