| 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 #ifndef PaymentRequest_h | 5 #ifndef PaymentRequest_h |
| 6 #define PaymentRequest_h | 6 #define PaymentRequest_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/ScriptWrappable.h" | 10 #include "bindings/core/v8/ScriptWrappable.h" |
| 11 #include "core/dom/ContextLifecycleObserver.h" | 11 #include "core/dom/ContextLifecycleObserver.h" |
| 12 #include "core/events/EventTarget.h" | 12 #include "core/events/EventTarget.h" |
| 13 #include "modules/ModulesExport.h" | 13 #include "modules/ModulesExport.h" |
| 14 #include "modules/payments/PaymentCompleter.h" | 14 #include "modules/payments/PaymentCompleter.h" |
| 15 #include "modules/payments/PaymentDetails.h" | 15 #include "modules/payments/PaymentDetails.h" |
| 16 #include "modules/payments/PaymentMethodData.h" |
| 16 #include "modules/payments/PaymentOptions.h" | 17 #include "modules/payments/PaymentOptions.h" |
| 17 #include "modules/payments/PaymentUpdater.h" | 18 #include "modules/payments/PaymentUpdater.h" |
| 18 #include "mojo/public/cpp/bindings/binding.h" | 19 #include "mojo/public/cpp/bindings/binding.h" |
| 19 #include "platform/heap/Handle.h" | 20 #include "platform/heap/Handle.h" |
| 20 #include "public/platform/modules/payments/payment_request.mojom-blink.h" | 21 #include "public/platform/modules/payments/payment_request.mojom-blink.h" |
| 21 #include "wtf/Compiler.h" | 22 #include "wtf/Compiler.h" |
| 22 #include "wtf/Noncopyable.h" | 23 #include "wtf/Noncopyable.h" |
| 23 #include "wtf/RefPtr.h" | 24 #include "wtf/RefPtr.h" |
| 24 #include "wtf/Vector.h" | 25 #include "wtf/Vector.h" |
| 25 #include "wtf/text/WTFString.h" | 26 #include "wtf/text/WTFString.h" |
| 26 | 27 |
| 27 namespace blink { | 28 namespace blink { |
| 28 | 29 |
| 29 class ExceptionState; | 30 class ExceptionState; |
| 30 class PaymentAddress; | 31 class PaymentAddress; |
| 31 class ScriptPromiseResolver; | 32 class ScriptPromiseResolver; |
| 32 class ScriptState; | 33 class ScriptState; |
| 33 | 34 |
| 34 class MODULES_EXPORT PaymentRequest final : public EventTargetWithInlineData, WT
F_NON_EXPORTED_BASE(public mojom::blink::PaymentRequestClient), public PaymentCo
mpleter, public PaymentUpdater, public ContextLifecycleObserver, public ActiveSc
riptWrappable { | 35 class MODULES_EXPORT PaymentRequest final : public EventTargetWithInlineData, WT
F_NON_EXPORTED_BASE(public mojom::blink::PaymentRequestClient), public PaymentCo
mpleter, public PaymentUpdater, public ContextLifecycleObserver, public ActiveSc
riptWrappable { |
| 35 DEFINE_WRAPPERTYPEINFO(); | 36 DEFINE_WRAPPERTYPEINFO(); |
| 36 USING_GARBAGE_COLLECTED_MIXIN(PaymentRequest) | 37 USING_GARBAGE_COLLECTED_MIXIN(PaymentRequest) |
| 37 WTF_MAKE_NONCOPYABLE(PaymentRequest); | 38 WTF_MAKE_NONCOPYABLE(PaymentRequest); |
| 38 | 39 |
| 39 public: | 40 public: |
| 40 static PaymentRequest* create(ScriptState*, const Vector<String>& supportedM
ethods, const PaymentDetails&, ExceptionState&); | 41 static PaymentRequest* create(ScriptState*, const HeapVector<PaymentMethodDa
ta>&, const PaymentDetails&, ExceptionState&); |
| 41 static PaymentRequest* create(ScriptState*, const Vector<String>& supportedM
ethods, const PaymentDetails&, const PaymentOptions&, ExceptionState&); | 42 static PaymentRequest* create(ScriptState*, const HeapVector<PaymentMethodDa
ta>&, const PaymentDetails&, const PaymentOptions&, ExceptionState&); |
| 42 static PaymentRequest* create(ScriptState*, const Vector<String>& supportedM
ethods, const PaymentDetails&, const PaymentOptions&, const ScriptValue& data, E
xceptionState&); | |
| 43 | 43 |
| 44 virtual ~PaymentRequest(); | 44 virtual ~PaymentRequest(); |
| 45 | 45 |
| 46 struct MethodData { |
| 47 MethodData(const Vector<String>& methods, const String& data) |
| 48 : supportedMethods(methods), stringifiedData(data) {} |
| 49 Vector<String> supportedMethods; |
| 50 String stringifiedData; |
| 51 }; |
| 52 |
| 46 ScriptPromise show(ScriptState*); | 53 ScriptPromise show(ScriptState*); |
| 47 void abort(ExceptionState&); | 54 void abort(ExceptionState&); |
| 48 | 55 |
| 49 PaymentAddress* getShippingAddress() const { return m_shippingAddress.get();
} | 56 PaymentAddress* getShippingAddress() const { return m_shippingAddress.get();
} |
| 50 const String& shippingOption() const { return m_shippingOption; } | 57 const String& shippingOption() const { return m_shippingOption; } |
| 51 | 58 |
| 52 DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingaddresschange); | 59 DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingaddresschange); |
| 53 DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingoptionchange); | 60 DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingoptionchange); |
| 54 | 61 |
| 55 // EventTargetWithInlineData: | 62 // EventTargetWithInlineData: |
| 56 const AtomicString& interfaceName() const override; | 63 const AtomicString& interfaceName() const override; |
| 57 ExecutionContext* getExecutionContext() const override; | 64 ExecutionContext* getExecutionContext() const override; |
| 58 | 65 |
| 59 // PaymentCompleter: | 66 // PaymentCompleter: |
| 60 ScriptPromise complete(ScriptState*, bool success) override; | 67 ScriptPromise complete(ScriptState*, bool success) override; |
| 61 | 68 |
| 62 // PaymentUpdater: | 69 // PaymentUpdater: |
| 63 void onUpdatePaymentDetails(const ScriptValue& detailsScriptValue) override; | 70 void onUpdatePaymentDetails(const ScriptValue& detailsScriptValue) override; |
| 64 void onUpdatePaymentDetailsFailure(const ScriptValue& error) override; | 71 void onUpdatePaymentDetailsFailure(const ScriptValue& error) override; |
| 65 | 72 |
| 66 DECLARE_TRACE(); | 73 DECLARE_TRACE(); |
| 67 | 74 |
| 68 private: | 75 private: |
| 69 PaymentRequest(ScriptState*, const Vector<String>& supportedMethods, const P
aymentDetails&, const PaymentOptions&, const ScriptValue& data, ExceptionState&)
; | 76 PaymentRequest(ScriptState*, const HeapVector<PaymentMethodData>&, const Pay
mentDetails&, const PaymentOptions&, ExceptionState&); |
| 70 | 77 |
| 71 // LifecycleObserver: | 78 // LifecycleObserver: |
| 72 void contextDestroyed() override; | 79 void contextDestroyed() override; |
| 73 | 80 |
| 74 // ActiveScriptWrappable: | 81 // ActiveScriptWrappable: |
| 75 bool hasPendingActivity() const override; | 82 bool hasPendingActivity() const override; |
| 76 | 83 |
| 77 // mojom::blink::PaymentRequestClient: | 84 // mojom::blink::PaymentRequestClient: |
| 78 void OnShippingAddressChange(mojom::blink::PaymentAddressPtr) override; | 85 void OnShippingAddressChange(mojom::blink::PaymentAddressPtr) override; |
| 79 void OnShippingOptionChange(const String& shippingOptionId) override; | 86 void OnShippingOptionChange(const String& shippingOptionId) override; |
| 80 void OnPaymentResponse(mojom::blink::PaymentResponsePtr) override; | 87 void OnPaymentResponse(mojom::blink::PaymentResponsePtr) override; |
| 81 void OnError() override; | 88 void OnError() override; |
| 82 void OnComplete() override; | 89 void OnComplete() override; |
| 83 | 90 |
| 84 // Clears the promise resolvers and closes the Mojo connection. | 91 // Clears the promise resolvers and closes the Mojo connection. |
| 85 void clearResolversAndCloseMojoConnection(); | 92 void clearResolversAndCloseMojoConnection(); |
| 86 | 93 |
| 87 Vector<String> m_supportedMethods; | 94 Vector<MethodData> m_methodData; |
| 88 PaymentDetails m_details; | 95 PaymentDetails m_details; |
| 89 PaymentOptions m_options; | 96 PaymentOptions m_options; |
| 90 String m_stringifiedData; | |
| 91 Member<PaymentAddress> m_shippingAddress; | 97 Member<PaymentAddress> m_shippingAddress; |
| 92 String m_shippingOption; | 98 String m_shippingOption; |
| 93 Member<ScriptPromiseResolver> m_showResolver; | 99 Member<ScriptPromiseResolver> m_showResolver; |
| 94 Member<ScriptPromiseResolver> m_completeResolver; | 100 Member<ScriptPromiseResolver> m_completeResolver; |
| 95 mojom::blink::PaymentRequestPtr m_paymentProvider; | 101 mojom::blink::PaymentRequestPtr m_paymentProvider; |
| 96 mojo::Binding<mojom::blink::PaymentRequestClient> m_clientBinding; | 102 mojo::Binding<mojom::blink::PaymentRequestClient> m_clientBinding; |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 } // namespace blink | 105 } // namespace blink |
| 100 | 106 |
| 101 #endif // PaymentRequest_h | 107 #endif // PaymentRequest_h |
| OLD | NEW |