Chromium Code Reviews| 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/ConditionalFeatures.h" | 9 #include "bindings/core/v8/ConditionalFeatures.h" |
| 10 #include "bindings/core/v8/ExceptionState.h" | 10 #include "bindings/core/v8/ExceptionState.h" |
| 11 #include "bindings/core/v8/ScriptPromiseResolver.h" | 11 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 12 #include "bindings/core/v8/ScriptState.h" | 12 #include "bindings/core/v8/ScriptState.h" |
| 13 #include "bindings/core/v8/V8StringResource.h" | 13 #include "bindings/core/v8/V8StringResource.h" |
| 14 #include "bindings/modules/v8/V8AndroidPayMethodData.h" | 14 #include "bindings/modules/v8/V8AndroidPayMethodData.h" |
| 15 #include "bindings/modules/v8/V8BasicCardRequest.h" | 15 #include "bindings/modules/v8/V8BasicCardRequest.h" |
| 16 #include "bindings/modules/v8/V8NativeAndroidPaymentAppManifest.h" | |
| 17 #include "bindings/modules/v8/V8NativeAndroidPaymentAppManifestSection.h" | |
| 16 #include "bindings/modules/v8/V8PaymentDetails.h" | 18 #include "bindings/modules/v8/V8PaymentDetails.h" |
| 17 #include "core/EventTypeNames.h" | 19 #include "core/EventTypeNames.h" |
| 18 #include "core/dom/DOMException.h" | 20 #include "core/dom/DOMException.h" |
| 19 #include "core/dom/Document.h" | 21 #include "core/dom/Document.h" |
| 20 #include "core/dom/ExceptionCode.h" | 22 #include "core/dom/ExceptionCode.h" |
| 21 #include "core/dom/TaskRunnerHelper.h" | 23 #include "core/dom/TaskRunnerHelper.h" |
| 22 #include "core/events/Event.h" | 24 #include "core/events/Event.h" |
| 23 #include "core/events/EventQueue.h" | 25 #include "core/events/EventQueue.h" |
| 24 #include "core/frame/FrameOwner.h" | 26 #include "core/frame/FrameOwner.h" |
| 25 #include "core/html/HTMLIFrameElement.h" | 27 #include "core/html/HTMLIFrameElement.h" |
| 26 #include "core/inspector/ConsoleMessage.h" | 28 #include "core/inspector/ConsoleMessage.h" |
| 27 #include "core/inspector/ConsoleTypes.h" | 29 #include "core/inspector/ConsoleTypes.h" |
| 28 #include "modules/EventTargetModulesNames.h" | 30 #include "modules/EventTargetModulesNames.h" |
| 29 #include "modules/payments/AndroidPayMethodData.h" | 31 #include "modules/payments/AndroidPayMethodData.h" |
| 30 #include "modules/payments/AndroidPayTokenization.h" | 32 #include "modules/payments/AndroidPayTokenization.h" |
| 31 #include "modules/payments/BasicCardRequest.h" | 33 #include "modules/payments/BasicCardRequest.h" |
| 32 #include "modules/payments/HTMLIFrameElementPayments.h" | 34 #include "modules/payments/HTMLIFrameElementPayments.h" |
| 35 #include "modules/payments/NativeAndroidPaymentAppManifest.h" | |
| 36 #include "modules/payments/NativeAndroidPaymentAppManifestSection.h" | |
| 33 #include "modules/payments/PaymentAddress.h" | 37 #include "modules/payments/PaymentAddress.h" |
| 34 #include "modules/payments/PaymentItem.h" | 38 #include "modules/payments/PaymentItem.h" |
| 35 #include "modules/payments/PaymentRequestUpdateEvent.h" | 39 #include "modules/payments/PaymentRequestUpdateEvent.h" |
| 36 #include "modules/payments/PaymentResponse.h" | 40 #include "modules/payments/PaymentResponse.h" |
| 37 #include "modules/payments/PaymentShippingOption.h" | 41 #include "modules/payments/PaymentShippingOption.h" |
| 38 #include "modules/payments/PaymentsValidators.h" | 42 #include "modules/payments/PaymentsValidators.h" |
| 39 #include "mojo/public/cpp/bindings/interface_request.h" | 43 #include "mojo/public/cpp/bindings/interface_request.h" |
| 40 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
| 41 #include "platform/mojo/MojoHelper.h" | 45 #include "platform/mojo/MojoHelper.h" |
| 42 #include "public/platform/InterfaceProvider.h" | 46 #include "public/platform/InterfaceProvider.h" |
| 43 #include "public/platform/Platform.h" | 47 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebTraceLocation.h" | 48 #include "public/platform/WebTraceLocation.h" |
| 45 #include "wtf/HashSet.h" | 49 #include "wtf/HashSet.h" |
| 50 #include "wtf/Optional.h" | |
| 46 | 51 |
| 47 using payments::mojom::blink::CanMakePaymentQueryResult; | 52 namespace { |
| 48 using payments::mojom::blink::PaymentAddressPtr; | 53 |
| 49 using payments::mojom::blink::PaymentCurrencyAmount; | 54 using ::payments::mojom::blink::CanMakePaymentQueryResult; |
| 50 using payments::mojom::blink::PaymentCurrencyAmountPtr; | 55 using ::payments::mojom::blink::NativeAndroidPaymentAppManifestSection; |
| 51 using payments::mojom::blink::PaymentDetailsModifierPtr; | 56 using ::payments::mojom::blink::NativeAndroidPaymentAppManifestSectionPtr; |
| 52 using payments::mojom::blink::PaymentDetailsPtr; | 57 using ::payments::mojom::blink::PaymentAddressPtr; |
| 53 using payments::mojom::blink::PaymentErrorReason; | 58 using ::payments::mojom::blink::PaymentCurrencyAmount; |
| 54 using payments::mojom::blink::PaymentItemPtr; | 59 using ::payments::mojom::blink::PaymentCurrencyAmountPtr; |
| 55 using payments::mojom::blink::PaymentMethodDataPtr; | 60 using ::payments::mojom::blink::PaymentDetailsModifierPtr; |
| 56 using payments::mojom::blink::PaymentOptionsPtr; | 61 using ::payments::mojom::blink::PaymentDetailsPtr; |
| 57 using payments::mojom::blink::PaymentResponsePtr; | 62 using ::payments::mojom::blink::PaymentErrorReason; |
| 58 using payments::mojom::blink::PaymentShippingOptionPtr; | 63 using ::payments::mojom::blink::PaymentItemPtr; |
| 59 using payments::mojom::blink::PaymentShippingType; | 64 using ::payments::mojom::blink::PaymentMethodDataPtr; |
| 65 using ::payments::mojom::blink::PaymentOptionsPtr; | |
| 66 using ::payments::mojom::blink::PaymentResponsePtr; | |
| 67 using ::payments::mojom::blink::PaymentShippingOptionPtr; | |
| 68 using ::payments::mojom::blink::PaymentShippingType; | |
| 69 | |
| 70 } // namespace | |
| 60 | 71 |
| 61 namespace mojo { | 72 namespace mojo { |
| 62 | 73 |
| 63 template <> | 74 template <> |
| 75 struct TypeConverter<NativeAndroidPaymentAppManifestSectionPtr, | |
| 76 blink::NativeAndroidPaymentAppManifestSection> { | |
| 77 static NativeAndroidPaymentAppManifestSectionPtr Convert( | |
| 78 const blink::NativeAndroidPaymentAppManifestSection& input) { | |
| 79 NativeAndroidPaymentAppManifestSectionPtr output = | |
| 80 NativeAndroidPaymentAppManifestSection::New(); | |
| 81 output->package_name = input.package(); | |
| 82 output->version = input.hasVersion() ? input.version() : 0; | |
| 83 if (input.hasSha256_cert_fingerprints()) | |
| 84 output->sha256_cert_fingerprints = input.sha256_cert_fingerprints(); | |
| 85 return output; | |
| 86 } | |
| 87 }; | |
| 88 | |
| 89 template <> | |
| 64 struct TypeConverter<PaymentCurrencyAmountPtr, blink::PaymentCurrencyAmount> { | 90 struct TypeConverter<PaymentCurrencyAmountPtr, blink::PaymentCurrencyAmount> { |
| 65 static PaymentCurrencyAmountPtr Convert( | 91 static PaymentCurrencyAmountPtr Convert( |
| 66 const blink::PaymentCurrencyAmount& input) { | 92 const blink::PaymentCurrencyAmount& input) { |
| 67 PaymentCurrencyAmountPtr output = PaymentCurrencyAmount::New(); | 93 PaymentCurrencyAmountPtr output = PaymentCurrencyAmount::New(); |
| 68 output->currency = input.currency(); | 94 output->currency = input.currency(); |
| 69 output->value = input.value(); | 95 output->value = input.value(); |
| 70 output->currency_system = input.currencySystem(); | 96 output->currency_system = input.currencySystem(); |
| 71 return output; | 97 return output; |
| 72 } | 98 } |
| 73 }; | 99 }; |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 break; | 1073 break; |
| 1048 case CanMakePaymentQueryResult::QUERY_QUOTA_EXCEEDED: | 1074 case CanMakePaymentQueryResult::QUERY_QUOTA_EXCEEDED: |
| 1049 m_canMakePaymentResolver->reject( | 1075 m_canMakePaymentResolver->reject( |
| 1050 DOMException::create(QuotaExceededError, "Query quota exceeded")); | 1076 DOMException::create(QuotaExceededError, "Query quota exceeded")); |
| 1051 break; | 1077 break; |
| 1052 } | 1078 } |
| 1053 | 1079 |
| 1054 m_canMakePaymentResolver.clear(); | 1080 m_canMakePaymentResolver.clear(); |
| 1055 } | 1081 } |
| 1056 | 1082 |
| 1083 void PaymentRequest::ParsePaymentManifest( | |
| 1084 const String& content, | |
| 1085 const ParsePaymentManifestCallback& callback) { | |
| 1086 Optional<Vector<NativeAndroidPaymentAppManifestSectionPtr>> result; | |
| 1087 | |
| 1088 ScriptState* state = ScriptState::forMainWorld(frame()); | |
|
Marijn Kruisselbrink
2017/02/23 20:07:06
I don't think using ScriptState::forMainWorld (or
| |
| 1089 if (!state->contextIsValid()) { | |
| 1090 callback.Run(std::move(result)); | |
| 1091 return; | |
| 1092 } | |
| 1093 | |
| 1094 ScriptState::Scope scope(state); | |
| 1095 ExceptionState exceptionState(state->isolate(), | |
| 1096 ExceptionState::ConstructionContext, | |
| 1097 "NativeAndroidPaymentAppManifest"); | |
| 1098 v8::Local<v8::Value> input = | |
| 1099 fromJSONString(state->isolate(), content, exceptionState); | |
| 1100 if (exceptionState.hadException()) { | |
| 1101 callback.Run(std::move(result)); | |
| 1102 return; | |
| 1103 } | |
| 1104 | |
| 1105 NativeAndroidPaymentAppManifest manifest; | |
| 1106 V8NativeAndroidPaymentAppManifest::toImpl(state->isolate(), input, manifest, | |
| 1107 exceptionState); | |
| 1108 if (exceptionState.hadException()) { | |
| 1109 callback.Run(std::move(result)); | |
| 1110 return; | |
| 1111 } | |
| 1112 | |
| 1113 if (manifest.hasAndroid() && !manifest.android().isEmpty()) { | |
| 1114 result = Vector<NativeAndroidPaymentAppManifestSectionPtr>(); | |
| 1115 for (const auto& section : manifest.android()) { | |
| 1116 result->push_back( | |
| 1117 payments::mojom::blink::NativeAndroidPaymentAppManifestSection::From( | |
| 1118 section)); | |
| 1119 } | |
| 1120 } | |
| 1121 | |
| 1122 callback.Run(std::move(result)); | |
| 1123 } | |
| 1124 | |
| 1057 void PaymentRequest::onCompleteTimeout(TimerBase*) { | 1125 void PaymentRequest::onCompleteTimeout(TimerBase*) { |
| 1058 m_paymentProvider->Complete(payments::mojom::blink::PaymentComplete(Fail)); | 1126 m_paymentProvider->Complete(payments::mojom::blink::PaymentComplete(Fail)); |
| 1059 clearResolversAndCloseMojoConnection(); | 1127 clearResolversAndCloseMojoConnection(); |
| 1060 } | 1128 } |
| 1061 | 1129 |
| 1062 void PaymentRequest::clearResolversAndCloseMojoConnection() { | 1130 void PaymentRequest::clearResolversAndCloseMojoConnection() { |
| 1063 m_completeTimer.stop(); | 1131 m_completeTimer.stop(); |
| 1064 m_completeResolver.clear(); | 1132 m_completeResolver.clear(); |
| 1065 m_showResolver.clear(); | 1133 m_showResolver.clear(); |
| 1066 m_abortResolver.clear(); | 1134 m_abortResolver.clear(); |
| 1067 m_canMakePaymentResolver.clear(); | 1135 m_canMakePaymentResolver.clear(); |
| 1068 if (m_clientBinding.is_bound()) | 1136 if (m_clientBinding.is_bound()) |
| 1069 m_clientBinding.Close(); | 1137 m_clientBinding.Close(); |
| 1070 m_paymentProvider.reset(); | 1138 m_paymentProvider.reset(); |
| 1071 } | 1139 } |
| 1072 | 1140 |
| 1073 } // namespace blink | 1141 } // namespace blink |
| OLD | NEW |