Chromium Code Reviews| 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 3fffe48cfff3743d5bc689904177867ee4c7864d..44cc1b24f5a1d2eca8934d8e28b0da976ca19d9a 100644 |
| --- a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp |
| @@ -12,7 +12,7 @@ |
| #include "bindings/core/v8/V8StringResource.h" |
| #include "bindings/modules/v8/V8AndroidPayMethodData.h" |
| #include "bindings/modules/v8/V8BasicCardRequest.h" |
| -#include "bindings/modules/v8/V8PaymentDetails.h" |
| +#include "bindings/modules/v8/V8PaymentDetailsUpdate.h" |
| #include "core/EventTypeNames.h" |
| #include "core/dom/DOMException.h" |
| #include "core/dom/Document.h" |
| @@ -472,21 +472,12 @@ String getSelectedShippingOption( |
| return result; |
| } |
| -void validateAndConvertPaymentDetails(const PaymentDetails& input, |
| - bool requestShipping, |
| - PaymentDetailsPtr& output, |
| - String& shippingOptionOutput, |
| - ExecutionContext& executionContext, |
| - ExceptionState& exceptionState) { |
| - if (!input.hasTotal()) { |
| - exceptionState.throwTypeError("Must specify total"); |
| - return; |
| - } |
| - |
| - validateAndConvertTotal(input.total(), output->total, exceptionState); |
| - if (exceptionState.hadException()) |
| - return; |
| - |
| +void validateAndConvertPaymentDetailsBase(const PaymentDetailsBase& input, |
| + bool requestShipping, |
| + PaymentDetailsPtr& output, |
| + String& shippingOptionOutput, |
| + ExecutionContext& executionContext, |
| + ExceptionState& exceptionState) { |
| if (input.hasDisplayItems()) { |
| validateAndConvertDisplayItems(input.displayItems(), output->display_items, |
| exceptionState); |
| @@ -509,6 +500,44 @@ void validateAndConvertPaymentDetails(const PaymentDetails& input, |
| if (exceptionState.hadException()) |
| return; |
| } |
| +} |
| + |
| +void validateAndConvertPaymentDetailsInit(const PaymentDetailsInit& input, |
| + bool requestShipping, |
| + PaymentDetailsPtr& output, |
| + String& shippingOptionOutput, |
| + ExecutionContext& executionContext, |
| + ExceptionState& exceptionState) { |
| + validateAndConvertPaymentDetailsBase(input, requestShipping, output, |
| + shippingOptionOutput, executionContext, |
| + exceptionState); |
|
please use gerrit instead
2017/03/21 13:42:21
Check for error in the exception state, please. If
zino
2017/03/22 16:43:45
Done.
|
| + if (!input.hasTotal()) { |
| + exceptionState.throwTypeError("Must specify total"); |
| + return; |
| + } |
| + |
| + validateAndConvertTotal(input.total(), output->total, exceptionState); |
| + if (exceptionState.hadException()) |
|
please use gerrit instead
2017/03/21 13:42:21
No need for this exception state check, because yo
zino
2017/03/22 16:43:44
Done.
|
| + return; |
| +} |
| + |
| +void validateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input, |
| + bool requestShipping, |
| + PaymentDetailsPtr& output, |
| + String& shippingOptionOutput, |
| + ExecutionContext& executionContext, |
| + ExceptionState& exceptionState) { |
| + validateAndConvertPaymentDetailsBase(input, requestShipping, output, |
| + shippingOptionOutput, executionContext, |
| + exceptionState); |
|
please use gerrit instead
2017/03/21 13:42:21
Check for error in the exception state, please. If
zino
2017/03/22 16:43:45
Done.
|
| + if (!input.hasTotal()) { |
|
please use gerrit instead
2017/03/21 13:42:21
Total is optional in PaymentDetailsUpdate. If it's
zino
2017/03/22 16:43:45
Done.
|
| + exceptionState.throwTypeError("Must specify total"); |
| + return; |
| + } |
| + |
| + validateAndConvertTotal(input.total(), output->total, exceptionState); |
| + if (exceptionState.hadException()) |
| + return; |
| if (input.hasError() && !input.error().isNull()) { |
| String errorMessage; |
| @@ -628,7 +657,7 @@ bool allowedToUsePaymentRequest(const Frame* frame) { |
| PaymentRequest* PaymentRequest::create( |
| ExecutionContext* executionContext, |
| const HeapVector<PaymentMethodData>& methodData, |
| - const PaymentDetails& details, |
| + const PaymentDetailsInit& details, |
| ExceptionState& exceptionState) { |
| return new PaymentRequest(executionContext, methodData, details, |
| PaymentOptions(), exceptionState); |
| @@ -637,7 +666,7 @@ PaymentRequest* PaymentRequest::create( |
| PaymentRequest* PaymentRequest::create( |
| ExecutionContext* executionContext, |
| const HeapVector<PaymentMethodData>& methodData, |
| - const PaymentDetails& details, |
| + const PaymentDetailsInit& details, |
| const PaymentOptions& options, |
| ExceptionState& exceptionState) { |
| return new PaymentRequest(executionContext, methodData, details, options, |
| @@ -761,13 +790,13 @@ void PaymentRequest::onUpdatePaymentDetails( |
| if (!m_showResolver || !m_paymentProvider) |
| return; |
| - PaymentDetails details; |
| + PaymentDetailsUpdate details; |
| ExceptionState exceptionState(v8::Isolate::GetCurrent(), |
| ExceptionState::ConstructionContext, |
| - "PaymentDetails"); |
| - V8PaymentDetails::toImpl(detailsScriptValue.isolate(), |
| - detailsScriptValue.v8Value(), details, |
| - exceptionState); |
| + "PaymentDetailsUpdate"); |
| + V8PaymentDetailsUpdate::toImpl(detailsScriptValue.isolate(), |
| + detailsScriptValue.v8Value(), details, |
| + exceptionState); |
| if (exceptionState.hadException()) { |
| m_showResolver->reject( |
| DOMException::create(SyntaxError, exceptionState.message())); |
| @@ -777,9 +806,9 @@ void PaymentRequest::onUpdatePaymentDetails( |
| PaymentDetailsPtr validatedDetails = |
| payments::mojom::blink::PaymentDetails::New(); |
| - validateAndConvertPaymentDetails(details, m_options.requestShipping(), |
| - validatedDetails, m_shippingOption, |
| - *getExecutionContext(), exceptionState); |
| + validateAndConvertPaymentDetailsUpdate( |
| + details, m_options.requestShipping(), validatedDetails, m_shippingOption, |
| + *getExecutionContext(), exceptionState); |
| if (exceptionState.hadException()) { |
| m_showResolver->reject( |
| DOMException::create(SyntaxError, exceptionState.message())); |
| @@ -816,7 +845,7 @@ void PaymentRequest::onCompleteTimeoutForTesting() { |
| PaymentRequest::PaymentRequest(ExecutionContext* executionContext, |
| const HeapVector<PaymentMethodData>& methodData, |
| - const PaymentDetails& details, |
| + const PaymentDetailsInit& details, |
| const PaymentOptions& options, |
| ExceptionState& exceptionState) |
| : ContextLifecycleObserver(executionContext), |
| @@ -845,17 +874,12 @@ PaymentRequest::PaymentRequest(ExecutionContext* executionContext, |
| PaymentDetailsPtr validatedDetails = |
| payments::mojom::blink::PaymentDetails::New(); |
| - validateAndConvertPaymentDetails(details, m_options.requestShipping(), |
| - validatedDetails, m_shippingOption, |
| - *getExecutionContext(), exceptionState); |
| + validateAndConvertPaymentDetailsInit(details, m_options.requestShipping(), |
| + validatedDetails, m_shippingOption, |
| + *getExecutionContext(), exceptionState); |
| if (exceptionState.hadException()) |
| return; |
| - if (details.hasError()) { |
| - exceptionState.throwTypeError("Error message not allowed in constructor"); |
| - return; |
| - } |
| - |
| if (m_options.requestShipping()) |
| m_shippingType = getValidShippingType(m_options.shippingType()); |