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

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp

Issue 2045833002: Add 'selected' boolean to 'ShippingOption' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
index b714ad694eba2cfa9da60da2279478a1c7819b21..8a12c90ec24522d9b03c27d22b2aa86a143b7a87 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
@@ -70,6 +70,7 @@ struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> {
output->id = input.id();
output->label = input.label();
output->amount = CurrencyAmount::From(input.amount());
+ output->selected = input.hasSelected() && input.selected();
return output;
}
};
@@ -197,6 +198,21 @@ void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep
}
}
+String getSelectedShippingOption(const PaymentDetails& details)
+{
+ String result;
+ if (!details.hasShippingOptions())
+ return result;
+
+ for (size_t i = 0; i < details.shippingOptions().size(); ++i) {
+ if (details.shippingOptions()[i].hasSelected() && details.shippingOptions()[i].selected()) {
+ result = details.shippingOptions()[i].id();
+ }
+ }
+
+ return result;
+}
+
} // namespace
PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<String>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptionState)
@@ -289,11 +305,8 @@ void PaymentRequest::onUpdatePaymentDetails(const ScriptValue& detailsScriptValu
return;
}
- // Set the currently selected option if only one option was passed.
Marijn Kruisselbrink 2016/06/07 00:31:37 According to the spec having exactly one option sh
please use gerrit instead 2016/06/07 00:52:22 I am told the spec is going to change in this dire
- if (details.hasShippingOptions() && details.shippingOptions().size() == 1)
- m_shippingOption = details.shippingOptions().begin()->id();
- else
- m_shippingOption = String();
+ if (m_options.requestShipping())
+ m_shippingOption = getSelectedShippingOption(details);
m_paymentProvider->UpdateWith(mojom::blink::PaymentDetails::From(details));
}
@@ -373,9 +386,8 @@ PaymentRequest::PaymentRequest(ScriptState* scriptState, const Vector<String>& s
}
}
- // Set the currently selected option if only one option is passed and shipping is requested.
- if (options.requestShipping() && details.hasShippingOptions() && details.shippingOptions().size() == 1)
- m_shippingOption = details.shippingOptions().begin()->id();
+ if (m_options.requestShipping())
+ m_shippingOption = getSelectedShippingOption(details);
}
void PaymentRequest::contextDestroyed()

Powered by Google App Engine
This is Rietveld 408576698