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

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

Issue 2744633002: [Web Payments] Add the shipping method section to the payment sheet (Closed)
Patch Set: Rename shipping method to shipping option. 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
« no previous file with comments | « components/payments/content/payment_request.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fe5827b0d4ac9c9b3edb0951df3e46986c647d8d 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>
@@ -38,7 +39,8 @@ PaymentRequest::PaymentRequest(
is_ready_to_pay_(false),
selected_shipping_profile_(nullptr),
selected_contact_profile_(nullptr),
- selected_credit_card_(nullptr) {
+ selected_credit_card_(nullptr),
+ selected_shipping_option_(nullptr) {
// OnConnectionTerminated will be called when the Mojo pipe is closed. This
// will happen as a result of many renderer-side events (both successful and
// erroneous in nature).
@@ -68,6 +70,7 @@ void PaymentRequest::Init(
PopulateValidatedMethodData(method_data);
PopulateProfileCache();
SetDefaultProfileSelections();
+ UpdateSelectedShippingOptionFromDetails();
}
void PaymentRequest::Show() {
@@ -387,4 +390,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();
+ }
+}
+
} // namespace payments
« no previous file with comments | « components/payments/content/payment_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698