| 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 578971e71759787a5919c8b86588a58bbcb4abfd..ffaac4e2d1cc52c327238dcc6bb483374dce2e6c 100644
|
| --- a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
|
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
|
| @@ -229,26 +229,29 @@
|
| }
|
| }
|
|
|
| -void validateShippingOptions(HeapVector<PaymentShippingOption>& options,
|
| +// Returns false if |options| should be ignored, even if an exception was not
|
| +// thrown. TODO(rouslan): Clear shipping options instead of ignoring them when
|
| +// http://crbug.com/601193 is fixed.
|
| +bool validateShippingOptions(const HeapVector<PaymentShippingOption>& options,
|
| ExceptionState& exceptionState) {
|
| HashSet<String> uniqueIds;
|
| for (const auto& option : options) {
|
| if (!option.hasId() || option.id().isEmpty()) {
|
| exceptionState.throwTypeError("ShippingOption id required");
|
| - return;
|
| - }
|
| -
|
| - if (uniqueIds.contains(option.id())) {
|
| - options.clear();
|
| - return;
|
| - }
|
| + return false;
|
| + }
|
| +
|
| + if (uniqueIds.contains(option.id()))
|
| + return false;
|
|
|
| uniqueIds.add(option.id());
|
|
|
| validateShippingOptionOrPaymentItem(option, exceptionState);
|
| if (exceptionState.hadException())
|
| - return;
|
| - }
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| }
|
|
|
| void validatePaymentDetailsModifiers(
|
| @@ -297,41 +300,43 @@
|
| }
|
| }
|
|
|
| -void validatePaymentDetails(PaymentDetails& details,
|
| +// Returns false if the shipping options should be ignored without throwing an
|
| +// exception.
|
| +bool validatePaymentDetails(const PaymentDetails& details,
|
| ExceptionState& exceptionState) {
|
| + bool keepShippingOptions = true;
|
| if (!details.hasTotal()) {
|
| exceptionState.throwTypeError("Must specify total");
|
| - return;
|
| + return keepShippingOptions;
|
| }
|
|
|
| validateShippingOptionOrPaymentItem(details.total(), exceptionState);
|
| if (exceptionState.hadException())
|
| - return;
|
| + return keepShippingOptions;
|
|
|
| if (details.total().amount().value()[0] == '-') {
|
| exceptionState.throwTypeError("Total amount value should be non-negative");
|
| - return;
|
| + return keepShippingOptions;
|
| }
|
|
|
| if (details.hasDisplayItems()) {
|
| validateDisplayItems(details.displayItems(), exceptionState);
|
| if (exceptionState.hadException())
|
| - return;
|
| + return keepShippingOptions;
|
| }
|
|
|
| if (details.hasShippingOptions()) {
|
| - HeapVector<PaymentShippingOption> options = details.shippingOptions();
|
| - validateShippingOptions(options, exceptionState);
|
| - details.setShippingOptions(options);
|
| + keepShippingOptions =
|
| + validateShippingOptions(details.shippingOptions(), exceptionState);
|
|
|
| if (exceptionState.hadException())
|
| - return;
|
| + return keepShippingOptions;
|
| }
|
|
|
| if (details.hasModifiers()) {
|
| validatePaymentDetailsModifiers(details.modifiers(), exceptionState);
|
| if (exceptionState.hadException())
|
| - return;
|
| + return keepShippingOptions;
|
| }
|
|
|
| String errorMessage;
|
| @@ -339,6 +344,8 @@
|
| &errorMessage)) {
|
| exceptionState.throwTypeError(errorMessage);
|
| }
|
| +
|
| + return keepShippingOptions;
|
| }
|
|
|
| void validateAndConvertPaymentMethodData(
|
| @@ -417,6 +424,15 @@
|
| return validValues[0];
|
| }
|
|
|
| +mojom::blink::PaymentDetailsPtr maybeKeepShippingOptions(
|
| + mojom::blink::PaymentDetailsPtr details,
|
| + bool keep) {
|
| + if (!keep)
|
| + details->shipping_options.resize(0);
|
| +
|
| + return details;
|
| +}
|
| +
|
| bool allowedToUsePaymentRequest(const Frame* frame) {
|
| // To determine whether a Document object |document| is allowed to use the
|
| // feature indicated by attribute name |allowpaymentrequest|, run these steps:
|
| @@ -575,7 +591,7 @@
|
| return;
|
| }
|
|
|
| - validatePaymentDetails(details, exceptionState);
|
| + bool keepShippingOptions = validatePaymentDetails(details, exceptionState);
|
| if (exceptionState.hadException()) {
|
| m_showResolver->reject(
|
| DOMException::create(SyntaxError, exceptionState.message()));
|
| @@ -583,10 +599,15 @@
|
| return;
|
| }
|
|
|
| - if (m_options.requestShipping())
|
| - m_shippingOption = getSelectedShippingOption(details);
|
| -
|
| - m_paymentProvider->UpdateWith(mojom::blink::PaymentDetails::From(details));
|
| + if (m_options.requestShipping()) {
|
| + if (keepShippingOptions)
|
| + m_shippingOption = getSelectedShippingOption(details);
|
| + else
|
| + m_shippingOption = String();
|
| + }
|
| +
|
| + m_paymentProvider->UpdateWith(maybeKeepShippingOptions(
|
| + mojom::blink::PaymentDetails::From(details), keepShippingOptions));
|
| }
|
|
|
| void PaymentRequest::onUpdatePaymentDetailsFailure(const String& error) {
|
| @@ -640,21 +661,19 @@
|
| return;
|
| }
|
|
|
| - PaymentDetails fixedDetails = details;
|
| - validatePaymentDetails(fixedDetails, exceptionState);
|
| + bool keepShippingOptions = validatePaymentDetails(details, exceptionState);
|
| if (exceptionState.hadException())
|
| return;
|
|
|
| - if (fixedDetails.hasError() && !fixedDetails.error().isEmpty()) {
|
| + if (details.hasError() && !details.error().isEmpty()) {
|
| exceptionState.throwTypeError("Error value should be empty");
|
| return;
|
| }
|
|
|
| if (m_options.requestShipping()) {
|
| - m_shippingOption = getSelectedShippingOption(fixedDetails);
|
| + if (keepShippingOptions)
|
| + m_shippingOption = getSelectedShippingOption(details);
|
| m_shippingType = getValidShippingType(m_options.shippingType());
|
| - } else {
|
| - fixedDetails.setShippingOptions(HeapVector<PaymentShippingOption>());
|
| }
|
|
|
| scriptState->domWindow()->frame()->interfaceProvider()->getInterface(
|
| @@ -662,10 +681,13 @@
|
| m_paymentProvider.set_connection_error_handler(convertToBaseCallback(
|
| WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this),
|
| mojom::blink::PaymentErrorReason::UNKNOWN)));
|
| - m_paymentProvider->Init(m_clientBinding.CreateInterfacePtrAndBind(),
|
| - ConvertPaymentMethodData(validatedMethodData),
|
| - mojom::blink::PaymentDetails::From(fixedDetails),
|
| - mojom::blink::PaymentOptions::From(m_options));
|
| + m_paymentProvider->Init(
|
| + m_clientBinding.CreateInterfacePtrAndBind(),
|
| + ConvertPaymentMethodData(validatedMethodData),
|
| + maybeKeepShippingOptions(
|
| + mojom::blink::PaymentDetails::From(details),
|
| + keepShippingOptions && m_options.requestShipping()),
|
| + mojom::blink::PaymentOptions::From(m_options));
|
| }
|
|
|
| void PaymentRequest::contextDestroyed() {
|
|
|