OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/payments/PaymentRequest.h" | 5 #include "modules/payments/PaymentRequest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "modules/payments/PaymentAddress.h" | 32 #include "modules/payments/PaymentAddress.h" |
33 #include "modules/payments/PaymentDetailsInit.h" | 33 #include "modules/payments/PaymentDetailsInit.h" |
34 #include "modules/payments/PaymentDetailsUpdate.h" | 34 #include "modules/payments/PaymentDetailsUpdate.h" |
35 #include "modules/payments/PaymentItem.h" | 35 #include "modules/payments/PaymentItem.h" |
36 #include "modules/payments/PaymentRequestUpdateEvent.h" | 36 #include "modules/payments/PaymentRequestUpdateEvent.h" |
37 #include "modules/payments/PaymentResponse.h" | 37 #include "modules/payments/PaymentResponse.h" |
38 #include "modules/payments/PaymentShippingOption.h" | 38 #include "modules/payments/PaymentShippingOption.h" |
39 #include "modules/payments/PaymentsValidators.h" | 39 #include "modules/payments/PaymentsValidators.h" |
40 #include "mojo/public/cpp/bindings/interface_request.h" | 40 #include "mojo/public/cpp/bindings/interface_request.h" |
41 #include "platform/RuntimeEnabledFeatures.h" | 41 #include "platform/RuntimeEnabledFeatures.h" |
42 #include "platform/UUID.h" | |
42 #include "platform/mojo/MojoHelper.h" | 43 #include "platform/mojo/MojoHelper.h" |
43 #include "public/platform/InterfaceProvider.h" | 44 #include "public/platform/InterfaceProvider.h" |
44 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
45 #include "public/platform/WebTraceLocation.h" | 46 #include "public/platform/WebTraceLocation.h" |
46 #include "wtf/HashSet.h" | 47 #include "wtf/HashSet.h" |
47 | 48 |
48 using payments::mojom::blink::CanMakePaymentQueryResult; | 49 using payments::mojom::blink::CanMakePaymentQueryResult; |
49 using payments::mojom::blink::PaymentAddressPtr; | 50 using payments::mojom::blink::PaymentAddressPtr; |
50 using payments::mojom::blink::PaymentCurrencyAmount; | 51 using payments::mojom::blink::PaymentCurrencyAmount; |
51 using payments::mojom::blink::PaymentCurrencyAmountPtr; | 52 using payments::mojom::blink::PaymentCurrencyAmountPtr; |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 shippingOptionOutput, executionContext, | 515 shippingOptionOutput, executionContext, |
515 exceptionState); | 516 exceptionState); |
516 if (exceptionState.hadException()) | 517 if (exceptionState.hadException()) |
517 return; | 518 return; |
518 | 519 |
519 if (!input.hasTotal()) { | 520 if (!input.hasTotal()) { |
520 exceptionState.throwTypeError("Must specify total"); | 521 exceptionState.throwTypeError("Must specify total"); |
521 return; | 522 return; |
522 } | 523 } |
523 | 524 |
525 if (!input.id().isEmpty()) | |
please use gerrit instead
2017/03/27 16:22:36
The spec says non-normatively:
"If an id member i
rwlbuis
2017/03/27 20:45:29
Done.
| |
526 output->id = input.id(); | |
527 else | |
528 output->id = createCanonicalUUIDString(); | |
529 | |
524 validateAndConvertTotal(input.total(), output->total, exceptionState); | 530 validateAndConvertTotal(input.total(), output->total, exceptionState); |
525 } | 531 } |
526 | 532 |
527 void validateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input, | 533 void validateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input, |
528 bool requestShipping, | 534 bool requestShipping, |
529 PaymentDetailsPtr& output, | 535 PaymentDetailsPtr& output, |
530 String& shippingOptionOutput, | 536 String& shippingOptionOutput, |
531 ExecutionContext& executionContext, | 537 ExecutionContext& executionContext, |
532 ExceptionState& exceptionState) { | 538 ExceptionState& exceptionState) { |
533 validateAndConvertPaymentDetailsBase(input, requestShipping, output, | 539 validateAndConvertPaymentDetailsBase(input, requestShipping, output, |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 } | 882 } |
877 | 883 |
878 PaymentDetailsPtr validatedDetails = | 884 PaymentDetailsPtr validatedDetails = |
879 payments::mojom::blink::PaymentDetails::New(); | 885 payments::mojom::blink::PaymentDetails::New(); |
880 validateAndConvertPaymentDetailsInit(details, m_options.requestShipping(), | 886 validateAndConvertPaymentDetailsInit(details, m_options.requestShipping(), |
881 validatedDetails, m_shippingOption, | 887 validatedDetails, m_shippingOption, |
882 *getExecutionContext(), exceptionState); | 888 *getExecutionContext(), exceptionState); |
883 if (exceptionState.hadException()) | 889 if (exceptionState.hadException()) |
884 return; | 890 return; |
885 | 891 |
892 m_id = validatedDetails->id; | |
893 | |
886 if (m_options.requestShipping()) | 894 if (m_options.requestShipping()) |
887 m_shippingType = getValidShippingType(m_options.shippingType()); | 895 m_shippingType = getValidShippingType(m_options.shippingType()); |
888 | 896 |
889 frame()->interfaceProvider()->getInterface( | 897 frame()->interfaceProvider()->getInterface( |
890 mojo::MakeRequest(&m_paymentProvider)); | 898 mojo::MakeRequest(&m_paymentProvider)); |
891 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( | 899 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( |
892 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), | 900 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), |
893 PaymentErrorReason::UNKNOWN))); | 901 PaymentErrorReason::UNKNOWN))); |
894 m_paymentProvider->Init( | 902 m_paymentProvider->Init( |
895 m_clientBinding.CreateInterfacePtrAndBind(), | 903 m_clientBinding.CreateInterfacePtrAndBind(), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 (!m_options.requestPayerName() && !response->payer_name.isNull()) || | 979 (!m_options.requestPayerName() && !response->payer_name.isNull()) || |
972 (!m_options.requestPayerEmail() && !response->payer_email.isNull()) || | 980 (!m_options.requestPayerEmail() && !response->payer_email.isNull()) || |
973 (!m_options.requestPayerPhone() && !response->payer_phone.isNull())) { | 981 (!m_options.requestPayerPhone() && !response->payer_phone.isNull())) { |
974 m_showResolver->reject(DOMException::create(SyntaxError)); | 982 m_showResolver->reject(DOMException::create(SyntaxError)); |
975 clearResolversAndCloseMojoConnection(); | 983 clearResolversAndCloseMojoConnection(); |
976 return; | 984 return; |
977 } | 985 } |
978 | 986 |
979 m_completeTimer.startOneShot(completeTimeoutSeconds, BLINK_FROM_HERE); | 987 m_completeTimer.startOneShot(completeTimeoutSeconds, BLINK_FROM_HERE); |
980 | 988 |
981 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); | 989 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); |
please use gerrit instead
2017/03/27 16:22:36
Please pass the "mId" member into the "new Payment
rwlbuis
2017/03/27 20:45:29
Done.
| |
982 | 990 |
983 // Do not close the mojo connection here. The merchant website should call | 991 // Do not close the mojo connection here. The merchant website should call |
984 // PaymentResponse::complete(String), which will be forwarded over the mojo | 992 // PaymentResponse::complete(String), which will be forwarded over the mojo |
985 // connection to display a success or failure message to the user. | 993 // connection to display a success or failure message to the user. |
986 m_showResolver.clear(); | 994 m_showResolver.clear(); |
987 } | 995 } |
988 | 996 |
989 void PaymentRequest::OnError(PaymentErrorReason error) { | 997 void PaymentRequest::OnError(PaymentErrorReason error) { |
990 ExceptionCode ec = UnknownError; | 998 ExceptionCode ec = UnknownError; |
991 String message; | 999 String message; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 m_completeResolver.clear(); | 1080 m_completeResolver.clear(); |
1073 m_showResolver.clear(); | 1081 m_showResolver.clear(); |
1074 m_abortResolver.clear(); | 1082 m_abortResolver.clear(); |
1075 m_canMakePaymentResolver.clear(); | 1083 m_canMakePaymentResolver.clear(); |
1076 if (m_clientBinding.is_bound()) | 1084 if (m_clientBinding.is_bound()) |
1077 m_clientBinding.Close(); | 1085 m_clientBinding.Close(); |
1078 m_paymentProvider.reset(); | 1086 m_paymentProvider.reset(); |
1079 } | 1087 } |
1080 | 1088 |
1081 } // namespace blink | 1089 } // namespace blink |
OLD | NEW |