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

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

Issue 2101463002: PaymentRequest: Implement PaymentDetailsModifier dictionary (in blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments 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 5660628384c046f4e1bb6780fb3a0699765bc16a..e45fe15a6c24dc681ad5a9b1631ed57258775b5e 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
@@ -32,6 +32,8 @@ namespace mojo {
using blink::mojom::blink::PaymentCurrencyAmount;
using blink::mojom::blink::PaymentCurrencyAmountPtr;
using blink::mojom::blink::PaymentDetails;
+using blink::mojom::blink::PaymentDetailsModifier;
+using blink::mojom::blink::PaymentDetailsModifierPtr;
using blink::mojom::blink::PaymentDetailsPtr;
using blink::mojom::blink::PaymentItem;
using blink::mojom::blink::PaymentItemPtr;
@@ -78,6 +80,27 @@ struct TypeConverter<PaymentShippingOptionPtr, blink::PaymentShippingOption> {
};
template <>
+struct TypeConverter<PaymentDetailsModifierPtr, blink::PaymentDetailsModifier> {
+ static PaymentDetailsModifierPtr Convert(const blink::PaymentDetailsModifier& input)
+ {
+ PaymentDetailsModifierPtr output = PaymentDetailsModifier::New();
+ output->supported_methods = WTF::Vector<WTF::String>(input.supportedMethods());
+
+ if (input.hasTotal())
+ output->total = PaymentItem::From(input.total());
+ else
+ output->total = PaymentItem::New();
+
+ if (input.hasAdditionalDisplayItems())
+ output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::From(input.additionalDisplayItems());
+ else
+ output->additional_display_items = mojo::WTFArray<PaymentItemPtr>::New(0);
+
+ return output;
+ }
+};
+
+template <>
struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> {
static PaymentDetailsPtr Convert(const blink::PaymentDetails& input)
{
@@ -94,6 +117,11 @@ struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> {
else
output->shipping_options = mojo::WTFArray<PaymentShippingOptionPtr>::New(0);
+ if (input.hasModifiers())
+ output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::From(input.modifiers());
+ else
+ output->modifiers = mojo::WTFArray<PaymentDetailsModifierPtr>::New(0);
+
return output;
}
};
@@ -189,6 +217,38 @@ void validateShippingOptions(const HeapVector<PaymentShippingOption>& options, E
}
}
+void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& modifiers, ExceptionState& exceptionState)
+{
+ if (modifiers.isEmpty()) {
+ exceptionState.throwTypeError("Must specify at least one payment details modifier");
+ return;
+ }
+
+ for (const auto& modifier : modifiers) {
+ if (modifier.supportedMethods().isEmpty()) {
+ exceptionState.throwTypeError("Must specify at least one payment method identifier");
+ return;
+ }
+
+ if (modifier.hasTotal()) {
+ validateShippingOptionOrPaymentItem(modifier.total(), exceptionState);
+ if (exceptionState.hadException())
+ return;
+
+ if (modifier.total().amount().value()[0] == '-') {
+ exceptionState.throwTypeError("Total amount value should be non-negative");
+ return;
+ }
+ }
+
+ if (modifier.hasAdditionalDisplayItems()) {
+ validateDisplayItems(modifier.additionalDisplayItems(), exceptionState);
+ if (exceptionState.hadException())
+ return;
+ }
+ }
+}
+
void validatePaymentDetails(const PaymentDetails& details, ExceptionState& exceptionState)
{
if (!details.hasTotal()) {
@@ -213,6 +273,12 @@ void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep
if (details.hasShippingOptions()) {
validateShippingOptions(details.shippingOptions(), exceptionState);
+ if (exceptionState.hadException())
+ return;
+ }
+
+ if (details.hasModifiers()) {
+ validatePaymentDetailsModifiers(details.modifiers(), exceptionState);
}
}

Powered by Google App Engine
This is Rietveld 408576698