Changeset 223855 in webkit
- Timestamp:
- Oct 23, 2017 2:00:45 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 14 added
- 23 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223849 r223855 1 2017-10-23 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Resolve PaymentRequest.show()'s accept promise when a payment is authorized 4 https://bugs.webkit.org/show_bug.cgi?id=178609 5 <rdar://problem/33542813> 6 7 Reviewed by Alex Christensen. 8 9 * http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https-expected.txt: Added. 10 * http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html: Copied from imported/w3c/web-platform-tests/payment-request/PaymentAddress/attributes-and-toJSON-method-manual.https.html. 11 * http/tests/paymentrequest/payment-response-complete-method.https-expected.txt: Added. 12 * http/tests/paymentrequest/payment-response-complete-method.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/complete-method-manual.https.html. 13 * http/tests/paymentrequest/payment-response-methodName-attribute.https-expected.txt: Added. 14 * http/tests/paymentrequest/payment-response-methodName-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/methodName-attribute-manual.https.html. 15 * http/tests/paymentrequest/payment-response-payerEmail-attribute.https-expected.txt: Added. 16 * http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerEmail-attribute-manual.https.html. 17 * http/tests/paymentrequest/payment-response-payerName-attribute.https-expected.txt: Added. 18 * http/tests/paymentrequest/payment-response-payerName-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerName-attribute-manual.https.html. 19 * http/tests/paymentrequest/payment-response-payerPhone-attribute.https-expected.txt: Added. 20 * http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerPhone-attribute-manual.https.html. 21 * http/tests/paymentrequest/resources/helpers.js: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/helpers.js. 22 (test): 23 (async.getPaymentResponse): 24 (async.getPaymentRequestResponse): 25 (async.runTest): 26 1 27 2017-10-23 Chris Dumez <cdumez@apple.com> 2 28 -
trunk/Source/WebCore/ChangeLog
r223854 r223855 1 2017-10-23 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Resolve PaymentRequest.show()'s accept promise when a payment is authorized 4 https://bugs.webkit.org/show_bug.cgi?id=178609 5 <rdar://problem/33542813> 6 7 Reviewed by Alex Christensen. 8 9 This patch implements the logic for resolving PaymentRequest.show()'s accept promise when 10 the user authorizes a payment, and implements PaymentResponse.complete(). 11 12 Tests: http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html 13 http/tests/paymentrequest/payment-response-complete-method.https.html 14 http/tests/paymentrequest/payment-response-methodName-attribute.https.html 15 http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html 16 http/tests/paymentrequest/payment-response-payerName-attribute.https.html 17 http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html 18 19 * DerivedSources.make: 20 * Modules/applepay/ApplePayPaymentContact.h: 21 * Modules/applepay/Payment.h: 22 (WebCore::Payment::Payment): Deleted. 23 (WebCore::Payment::pkPayment const): Deleted. 24 * Modules/applepay/PaymentContact.h: 25 (WebCore::PaymentContact::PaymentContact): Deleted. 26 (WebCore::PaymentContact::pkContact const): Deleted. 27 * Modules/applepay/cocoa/PaymentContactCocoa.mm: 28 (WebCore::convert): 29 * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp: 30 (WebCore::ApplePayPaymentHandler::hasActiveSession): 31 (WebCore::ApplePayPaymentHandler::ApplePayPaymentHandler): 32 (WebCore::ApplePayPaymentHandler::document): 33 (WebCore::ApplePayPaymentHandler::paymentCoordinator): 34 (WebCore::ApplePayPaymentHandler::convertData): 35 (WebCore::ApplePayPaymentHandler::show): 36 (WebCore::ApplePayPaymentHandler::hide): 37 (WebCore::ApplePayPaymentHandler::canMakePayment): 38 (WebCore::ApplePayPaymentHandler::complete): 39 (WebCore::convert): 40 (WebCore::ApplePayPaymentHandler::didAuthorizePayment): 41 (WebCore::ApplePayPaymentHandler::didSelectShippingMethod): 42 (WebCore::ApplePayPaymentHandler::didSelectShippingContact): 43 * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h: 44 * Modules/paymentrequest/PaymentAddress.h: 45 * Modules/paymentrequest/PaymentAddress.idl: 46 * Modules/paymentrequest/PaymentHandler.cpp: 47 (WebCore::PaymentHandler::create): 48 * Modules/paymentrequest/PaymentHandler.h: 49 * Modules/paymentrequest/PaymentRequest.cpp: 50 (WebCore::PaymentRequest::show): 51 (WebCore::PaymentRequest::stop): 52 (WebCore::PaymentRequest::canMakePayment): 53 (WebCore::PaymentRequest::canSuspendForDocumentSuspension const): 54 (WebCore::PaymentRequest::shippingAddressChanged): 55 (WebCore::PaymentRequest::shippingOptionChanged): 56 (WebCore::PaymentRequest::accept): 57 (WebCore::PaymentRequest::complete): 58 * Modules/paymentrequest/PaymentRequest.h: 59 * Modules/paymentrequest/PaymentResponse.cpp: 60 (WebCore::PaymentResponse::PaymentResponse): 61 (WebCore::PaymentResponse::complete): 62 * Modules/paymentrequest/PaymentResponse.h: 63 * WebCore.xcodeproj/project.pbxproj: 64 * testing/Internals.cpp: 65 (WebCore::Internals::Internals): 66 (WebCore::Internals::mockPaymentCoordinator const): 67 * testing/Internals.h: 68 * testing/Internals.idl: 69 * testing/MockPayment.h: Added. 70 * testing/MockPaymentAddress.h: Added. 71 * testing/MockPaymentAddress.idl: Added. 72 * testing/MockPaymentContact.h: Added. 73 * testing/MockPaymentCoordinator.cpp: 74 (WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard): 75 (WebCore::MockPaymentCoordinator::openPaymentSetup): 76 (WebCore::dispatchIfShowing): 77 (WebCore::MockPaymentCoordinator::showPaymentUI): 78 (WebCore::MockPaymentCoordinator::completeMerchantValidation): 79 (WebCore::MockPaymentCoordinator::completePaymentSession): 80 (WebCore::MockPaymentCoordinator::abortPaymentSession): 81 (WebCore::MockPaymentCoordinator::cancelPaymentSession): 82 (WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed): 83 * testing/MockPaymentCoordinator.h: 84 * testing/MockPaymentCoordinator.idl: Added. 85 1 86 2017-10-23 Dean Jackson <dino@apple.com> 2 87 -
trunk/Source/WebCore/DerivedSources.make
r223828 r223855 909 909 $(WebCore)/testing/MockContentFilterSettings.idl \ 910 910 $(WebCore)/testing/MockPageOverlay.idl \ 911 $(WebCore)/testing/MockPaymentAddress.idl \ 912 $(WebCore)/testing/MockPaymentCoordinator.idl \ 911 913 $(WebCore)/testing/TypeConversions.idl \ 912 914 $(WebCore)/workers/AbstractWorker.idl \ -
trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h
r223580 r223855 39 39 String givenName; 40 40 String familyName; 41 String localizedName; 41 42 String phoneticGivenName; 42 43 String phoneticFamilyName; 44 String localizedPhoneticName; 43 45 std::optional<Vector<String>> addressLines; 44 46 String subLocality; -
trunk/Source/WebCore/Modules/applepay/Payment.h
r223728 r223855 36 36 struct ApplePayPayment; 37 37 38 class Payment {38 class WEBCORE_EXPORT Payment { 39 39 public: 40 40 Payment() = default; … … 45 45 } 46 46 47 ApplePayPayment toApplePayPayment() const; 47 virtual ~Payment() = default; 48 49 virtual ApplePayPayment toApplePayPayment() const; 48 50 49 51 PKPayment *pkPayment() const { return m_pkPayment.get(); } -
trunk/Source/WebCore/Modules/applepay/PaymentContact.h
r220718 r223855 37 37 struct ApplePayPaymentContact; 38 38 39 class PaymentContact {39 class WEBCORE_EXPORT PaymentContact { 40 40 public: 41 41 PaymentContact() = default; … … 44 44 { 45 45 } 46 virtual ~PaymentContact() = default; 46 47 47 48 static PaymentContact fromApplePayPaymentContact(unsigned version, const ApplePayPaymentContact&); 48 ApplePayPaymentContact toApplePayPaymentContact() const;49 virtual ApplePayPaymentContact toApplePayPaymentContact() const; 49 50 50 51 PKContact *pkContact() const { return m_pkContact.get(); } -
trunk/Source/WebCore/Modules/applepay/cocoa/PaymentContactCocoa.mm
r223583 r223855 190 190 result.givenName = name.givenName; 191 191 result.familyName = name.familyName; 192 result.localizedName = [NSPersonNameComponentsFormatter localizedStringFromPersonNameComponents:name style:NSPersonNameComponentsFormatterStyleDefault options:0]; 192 193 193 194 NSPersonNameComponents *phoneticName = name.phoneticRepresentation; 194 195 result.phoneticGivenName = phoneticName.givenName; 195 196 result.phoneticFamilyName = phoneticName.familyName; 197 result.localizedPhoneticName = [NSPersonNameComponentsFormatter localizedStringFromPersonNameComponents:name style:NSPersonNameComponentsFormatterStyleDefault options:NSPersonNameComponentsFormatterPhonetic]; 196 198 197 199 CNPostalAddress *postalAddress = contact.postalAddress; -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
r223193 r223855 32 32 #include "ApplePayMerchantCapability.h" 33 33 #include "ApplePayMerchantValidationEvent.h" 34 #include "ApplePayPayment.h" 34 35 #include "ApplePaySessionPaymentRequest.h" 35 36 #include "Document.h" 36 37 #include "EventNames.h" 38 #include "JSApplePayPayment.h" 37 39 #include "JSApplePayRequest.h" 38 40 #include "LinkIconCollector.h" 39 41 #include "MainFrame.h" 40 42 #include "Page.h" 43 #include "Payment.h" 44 #include "PaymentAuthorizationStatus.h" 41 45 #include "PaymentContact.h" 42 46 #include "PaymentCoordinator.h" 43 47 #include "PaymentRequestValidator.h" 48 #include "PaymentResponse.h" 44 49 #include "Settings.h" 45 50 … … 62 67 bool ApplePayPaymentHandler::hasActiveSession(Document& document) 63 68 { 64 return paymentCoordinator(document).hasActiveSession(); 65 } 66 67 ApplePayPaymentHandler::ApplePayPaymentHandler(PaymentRequest& paymentRequest) 68 : m_paymentRequest { paymentRequest } 69 { 69 return WebCore::paymentCoordinator(document).hasActiveSession(); 70 } 71 72 ApplePayPaymentHandler::ApplePayPaymentHandler(Document& document, const PaymentRequest::MethodIdentifier& identifier, PaymentRequest& paymentRequest) 73 : ContextDestructionObserver { &document } 74 , m_identifier { identifier } 75 , m_paymentRequest { paymentRequest } 76 { 77 ASSERT(handlesIdentifier(m_identifier)); 78 } 79 80 Document& ApplePayPaymentHandler::document() 81 { 82 return downcast<Document>(*scriptExecutionContext()); 83 } 84 85 PaymentCoordinator& ApplePayPaymentHandler::paymentCoordinator() 86 { 87 return WebCore::paymentCoordinator(document()); 70 88 } 71 89 … … 141 159 } 142 160 143 ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::ExecState& execState, JSC::JSValue&& data) 144 { 145 auto throwScope = DECLARE_THROW_SCOPE(execState.vm()); 146 auto applePayRequest = convertDictionary<ApplePayRequest>(execState, WTFMove(data)); 161 ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::JSValue&& data) 162 { 163 auto& context = *scriptExecutionContext(); 164 auto throwScope = DECLARE_THROW_SCOPE(context.vm()); 165 auto applePayRequest = convertDictionary<ApplePayRequest>(*context.execState(), WTFMove(data)); 147 166 if (throwScope.exception()) 148 167 return Exception { ExistingExceptionError }; … … 152 171 } 153 172 154 ExceptionOr<void> ApplePayPaymentHandler::show( Document& document)173 ExceptionOr<void> ApplePayPaymentHandler::show() 155 174 { 156 175 auto validatedRequest = convertAndValidate(m_applePayRequest->version, *m_applePayRequest); … … 204 223 205 224 Vector<URL> linkIconURLs; 206 for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon }))225 for (auto& icon : LinkIconCollector { document() }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon })) 207 226 linkIconURLs.append(icon.url); 208 227 209 paymentCoordinator( document).beginPaymentSession(*this, document.url(), linkIconURLs, request);228 paymentCoordinator().beginPaymentSession(*this, document().url(), linkIconURLs, request); 210 229 return { }; 211 230 } 212 231 213 void ApplePayPaymentHandler::hide( Document& document)214 { 215 paymentCoordinator( document).abortPaymentSession();232 void ApplePayPaymentHandler::hide() 233 { 234 paymentCoordinator().abortPaymentSession(); 216 235 } 217 236 … … 225 244 } 226 245 227 void ApplePayPaymentHandler::canMakePayment( Document& document, WTF::Function<void(bool)>&& completionHandler)228 { 229 if (!shouldDiscloseApplePayCapability(document )) {230 completionHandler(paymentCoordinator( document).canMakePayments());246 void ApplePayPaymentHandler::canMakePayment(Function<void(bool)>&& completionHandler) 247 { 248 if (!shouldDiscloseApplePayCapability(document())) { 249 completionHandler(paymentCoordinator().canMakePayments()); 231 250 return; 232 251 } 233 252 234 paymentCoordinator(document).canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document.domain(), WTFMove(completionHandler)); 253 paymentCoordinator().canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document().domain(), WTFMove(completionHandler)); 254 } 255 256 void ApplePayPaymentHandler::complete(std::optional<PaymentComplete>&& result) 257 { 258 if (!result) { 259 paymentCoordinator().completePaymentSession(std::nullopt); 260 return; 261 } 262 263 PaymentAuthorizationResult authorizationResult; 264 switch (*result) { 265 case PaymentComplete::Fail: 266 case PaymentComplete::Unknown: 267 authorizationResult.status = PaymentAuthorizationStatus::Failure; 268 authorizationResult.errors.append({ PaymentError::Code::Unknown, { }, std::nullopt }); 269 break; 270 case PaymentComplete::Success: 271 authorizationResult.status = PaymentAuthorizationStatus::Success; 272 break; 273 } 274 275 paymentCoordinator().completePaymentSession(WTFMove(authorizationResult)); 235 276 } 236 277 … … 241 282 } 242 283 284 static Ref<PaymentAddress> convert(const ApplePayPaymentContact& contact) 285 { 286 return PaymentAddress::create(contact.countryCode, contact.addressLines.value_or(Vector<String>()), contact.administrativeArea, contact.locality, contact.subLocality, contact.postalCode, String(), String(), String(), contact.localizedName, contact.phoneNumber); 287 } 288 289 void ApplePayPaymentHandler::didAuthorizePayment(const Payment& payment) 290 { 291 auto applePayPayment = payment.toApplePayPayment(); 292 auto& execState = *document().execState(); 293 auto details = JSC::Strong<JSC::JSObject> { execState.vm(), asObject(toJS<IDLDictionary<ApplePayPayment>>(execState, *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject()), applePayPayment)) }; 294 const auto& shippingContact = applePayPayment.shippingContact.value_or(ApplePayPaymentContact()); 295 m_paymentRequest->accept(WTF::get<URL>(m_identifier).string(), WTFMove(details), convert(shippingContact), shippingContact.localizedName, shippingContact.emailAddress, shippingContact.phoneNumber); 296 } 297 298 void ApplePayPaymentHandler::didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod) 299 { 300 m_paymentRequest->shippingOptionChanged(shippingMethod.identifier); 301 } 302 303 void ApplePayPaymentHandler::didSelectShippingContact(const PaymentContact& shippingContact) 304 { 305 m_paymentRequest->shippingAddressChanged(convert(shippingContact.toApplePayPaymentContact())); 306 } 307 243 308 } // namespace WebCore 244 309 -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h
r223193 r223855 29 29 30 30 #include "ApplePayRequest.h" 31 #include "ContextDestructionObserver.h" 31 32 #include "PaymentHandler.h" 33 #include "PaymentRequest.h" 32 34 #include "PaymentSession.h" 33 35 #include <wtf/Noncopyable.h> … … 36 38 namespace WebCore { 37 39 38 class Payment Request;40 class PaymentCoordinator; 39 41 40 class ApplePayPaymentHandler final : public PaymentHandler, public PaymentSession {42 class ApplePayPaymentHandler final : public PaymentHandler, public PaymentSession, private ContextDestructionObserver { 41 43 public: 42 44 static bool handlesIdentifier(const PaymentRequest::MethodIdentifier&); … … 45 47 private: 46 48 friend class PaymentHandler; 47 explicit ApplePayPaymentHandler(PaymentRequest&); 49 explicit ApplePayPaymentHandler(Document&, const PaymentRequest::MethodIdentifier&, PaymentRequest&); 50 51 Document& document(); 52 PaymentCoordinator& paymentCoordinator(); 48 53 49 54 // PaymentHandler 50 ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) final; 51 ExceptionOr<void> show(Document&) final; 52 void hide(Document&) final; 53 void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) final; 55 ExceptionOr<void> convertData(JSC::JSValue&&) final; 56 ExceptionOr<void> show() final; 57 void hide() final; 58 void canMakePayment(WTF::Function<void(bool)>&& completionHandler) final; 59 void complete(std::optional<PaymentComplete>&&) final; 54 60 55 61 // PaymentSession 56 62 void validateMerchant(const URL&) final; 57 void didAuthorizePayment(const Payment&) final { }58 void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final { }59 void didSelectShippingContact(const PaymentContact&) final { }63 void didAuthorizePayment(const Payment&) final; 64 void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final; 65 void didSelectShippingContact(const PaymentContact&) final; 60 66 void didSelectPaymentMethod(const PaymentMethod&) final { } 61 67 void didCancelPaymentSession() final { } 62 68 69 PaymentRequest::MethodIdentifier m_identifier; 63 70 Ref<PaymentRequest> m_paymentRequest; 64 71 std::optional<ApplePayRequest> m_applePayRequest; -
trunk/Source/WebCore/Modules/paymentrequest/PaymentAddress.cpp
r223854 r223855 25 25 26 26 #include "config.h" 27 #include "Payment Handler.h"27 #include "PaymentAddress.h" 28 28 29 29 #if ENABLE(PAYMENT_REQUEST) 30 30 31 #if ENABLE(APPLE_PAY)32 #include "ApplePayPaymentHandler.h"33 #endif34 35 31 namespace WebCore { 36 32 37 RefPtr<PaymentHandler> PaymentHandler::create(PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier) 33 PaymentAddress::PaymentAddress(const String& country, const Vector<String>& addressLine, const String& region, const String& city, const String& dependentLocality, const String& postalCode, const String& sortingCode, const String& languageCode, const String& organization, const String& recipient, const String& phone) 34 : m_country { country } 35 , m_addressLine { addressLine } 36 , m_region { region } 37 , m_city { city } 38 , m_dependentLocality { dependentLocality } 39 , m_postalCode { postalCode } 40 , m_sortingCode { sortingCode } 41 , m_languageCode { languageCode } 42 , m_organization { organization } 43 , m_recipient { recipient } 44 , m_phone { phone } 38 45 { 39 #if ENABLE(APPLE_PAY)40 if (ApplePayPaymentHandler::handlesIdentifier(identifier))41 return adoptRef(new ApplePayPaymentHandler(paymentRequest));42 #else43 UNUSED_PARAM(paymentRequest);44 UNUSED_PARAM(identifier);45 #endif46 47 return nullptr;48 }49 50 bool PaymentHandler::hasActiveSession(Document& document)51 {52 #if ENABLE(APPLE_PAY)53 return ApplePayPaymentHandler::hasActiveSession(document);54 #else55 UNUSED_PARAM(document);56 return false;57 #endif58 46 } 59 47 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentAddress.h
r220955 r223855 36 36 class PaymentAddress final : public RefCounted<PaymentAddress> { 37 37 public: 38 template <typename... Args> static Ref<PaymentAddress> create(Args&&... args) 39 { 40 return adoptRef(*new PaymentAddress(std::forward<Args>(args)...)); 41 } 42 38 43 const String& country() const { return m_country; } 39 44 const Vector<String>& addressLine() const { return m_addressLine; } … … 49 54 50 55 private: 56 PaymentAddress(const String& country, const Vector<String>& addressLine, const String& region, const String& city, const String& dependentLocality, const String& postalCode, const String& sortingCode, const String& languageCode, const String& organization, const String& recipient, const String& phone); 57 51 58 String m_country; 52 59 Vector<String> m_addressLine; -
trunk/Source/WebCore/Modules/paymentrequest/PaymentAddress.idl
r220955 r223855 27 27 Conditional=PAYMENT_REQUEST, 28 28 EnabledBySetting=PaymentRequest, 29 Exposed=Window, 29 30 ImplementationLacksVTable, 30 31 SecureContext -
trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp
r223076 r223855 35 35 namespace WebCore { 36 36 37 RefPtr<PaymentHandler> PaymentHandler::create( PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier)37 RefPtr<PaymentHandler> PaymentHandler::create(Document& document, PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier) 38 38 { 39 39 #if ENABLE(APPLE_PAY) 40 40 if (ApplePayPaymentHandler::handlesIdentifier(identifier)) 41 return adoptRef(new ApplePayPaymentHandler( paymentRequest));41 return adoptRef(new ApplePayPaymentHandler(document, identifier, paymentRequest)); 42 42 #else 43 UNUSED_PARAM(document); 43 44 UNUSED_PARAM(paymentRequest); 44 45 UNUSED_PARAM(identifier); -
trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h
r223160 r223855 33 33 34 34 namespace JSC { 35 class ExecState;36 35 class JSValue; 37 36 } … … 43 42 class PaymentHandler : public virtual PaymentSessionBase { 44 43 public: 45 static RefPtr<PaymentHandler> create( PaymentRequest&, const PaymentRequest::MethodIdentifier&);44 static RefPtr<PaymentHandler> create(Document&, PaymentRequest&, const PaymentRequest::MethodIdentifier&); 46 45 static bool hasActiveSession(Document&); 47 46 48 virtual ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) = 0; 49 virtual ExceptionOr<void> show(Document&) = 0; 50 virtual void hide(Document&) = 0; 51 virtual void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) = 0; 47 virtual ExceptionOr<void> convertData(JSC::JSValue&&) = 0; 48 virtual ExceptionOr<void> show() = 0; 49 virtual void hide() = 0; 50 virtual void canMakePayment(WTF::Function<void(bool)>&& completionHandler) = 0; 51 virtual void complete(std::optional<PaymentComplete>&&) = 0; 52 52 }; 53 53 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
r223701 r223855 31 31 #include "ApplePayPaymentHandler.h" 32 32 #include "Document.h" 33 #include "JSPaymentResponse.h" 33 34 #include "PaymentAddress.h" 34 35 #include "PaymentCurrencyAmount.h" … … 37 38 #include "PaymentMethodData.h" 38 39 #include "PaymentOptions.h" 40 #include "PaymentResponse.h" 39 41 #include "ScriptController.h" 40 42 #include <JavaScriptCore/JSONObject.h> … … 377 379 } 378 380 379 auto handler = PaymentHandler::create( *this, paymentMethod.identifier);381 auto handler = PaymentHandler::create(document, *this, paymentMethod.identifier); 380 382 if (!handler) 381 383 continue; 382 384 383 auto result = handler->convertData( *document.execState(),data.releaseReturnValue());385 auto result = handler->convertData(data.releaseReturnValue()); 384 386 if (result.hasException()) { 385 387 m_showPromise->reject(result.releaseException()); … … 396 398 } 397 399 398 auto exception = selectedPaymentHandler->show( document);400 auto exception = selectedPaymentHandler->show(); 399 401 if (exception.hasException()) { 400 402 m_showPromise->reject(exception.releaseException()); … … 414 416 if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) { 415 417 unsetPendingActivity(this); 416 paymentHandler->hide( downcast<Document>(*scriptExecutionContext()));418 paymentHandler->hide(); 417 419 } 418 420 … … 446 448 continue; 447 449 448 auto handler = PaymentHandler::create( *this, paymentMethod.identifier);450 auto handler = PaymentHandler::create(document, *this, paymentMethod.identifier); 449 451 if (!handler) 450 452 continue; 451 453 452 auto exception = handler->convertData( *document.execState(),data.releaseReturnValue());454 auto exception = handler->convertData(data.releaseReturnValue()); 453 455 if (exception.hasException()) 454 456 continue; 455 457 456 handler->canMakePayment( document,[promise = WTFMove(promise)](bool canMakePayment) mutable {458 handler->canMakePayment([promise = WTFMove(promise)](bool canMakePayment) mutable { 457 459 promise.resolve(canMakePayment); 458 460 }); … … 479 481 switch (m_state) { 480 482 case State::Created: 481 case State::Closed:482 483 ASSERT(!m_activePaymentHandler); 483 484 return true; 484 485 case State::Interactive: 486 case State::Closed: 485 487 return !m_activePaymentHandler; 486 488 } 487 489 } 488 490 491 void PaymentRequest::shippingAddressChanged(Ref<PaymentAddress>&& shippingAddress) 492 { 493 ASSERT(m_state == State::Interactive); 494 m_shippingAddress = WTFMove(shippingAddress); 495 // FIXME: run the PaymentRequest updated algorithm. 496 } 497 498 void PaymentRequest::shippingOptionChanged(const String& shippingOption) 499 { 500 ASSERT(m_state == State::Interactive); 501 m_shippingOption = shippingOption; 502 // FIXME: run the PaymentRequest updated algorithm. 503 } 504 505 void PaymentRequest::accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone) 506 { 507 ASSERT(m_state == State::Interactive); 508 509 auto response = PaymentResponse::create(*this); 510 response->setRequestId(m_details.id); 511 response->setMethodName(methodName); 512 response->setDetails(WTFMove(details)); 513 514 if (m_options.requestShipping) { 515 response->setShippingAddress(shippingAddress.ptr()); 516 response->setShippingOption(m_shippingOption); 517 } 518 519 if (m_options.requestPayerName) 520 response->setPayerName(payerName); 521 522 if (m_options.requestPayerEmail) 523 response->setPayerEmail(payerEmail); 524 525 if (m_options.requestPayerPhone) 526 response->setPayerPhone(payerPhone); 527 528 m_showPromise->resolve(response.get()); 529 m_state = State::Closed; 530 } 531 532 void PaymentRequest::complete(std::optional<PaymentComplete>&& result) 533 { 534 ASSERT(m_state == State::Closed); 535 std::exchange(m_activePaymentHandler, nullptr)->complete(WTFMove(result)); 536 } 537 489 538 } // namespace WebCore 490 539 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h
r223160 r223855 43 43 class PaymentHandler; 44 44 class PaymentResponse; 45 enum class PaymentComplete; 45 46 enum class PaymentShippingType; 46 47 struct PaymentMethodData; … … 66 67 const PaymentOptions& paymentOptions() const { return m_options; } 67 68 const PaymentDetailsInit& paymentDetails() const { return m_details; } 69 70 void shippingAddressChanged(Ref<PaymentAddress>&&); 71 void shippingOptionChanged(const String& shippingOption); 72 void accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone); 73 void complete(std::optional<PaymentComplete>&&); 68 74 69 75 using MethodIdentifier = Variant<String, URL>; -
trunk/Source/WebCore/Modules/paymentrequest/PaymentResponse.cpp
r220955 r223855 29 29 #if ENABLE(PAYMENT_REQUEST) 30 30 31 #include "PaymentRequest.h" 31 32 #include <wtf/RunLoop.h> 32 33 33 34 namespace WebCore { 34 35 35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise) 36 PaymentResponse::PaymentResponse(PaymentRequest& request) 37 : m_request { request } 36 38 { 37 promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") }); 39 } 40 41 PaymentResponse::~PaymentResponse() = default; 42 43 void PaymentResponse::complete(std::optional<PaymentComplete>&& result, DOMPromiseDeferred<void>&& promise) 44 { 45 if (m_completeCalled) { 46 promise.reject(Exception { InvalidStateError }); 47 return; 48 } 49 50 m_completeCalled = true; 51 m_request->complete(WTFMove(result)); 52 promise.resolve(); 38 53 } 39 54 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentResponse.h
r220955 r223855 33 33 34 34 namespace WebCore { 35 36 class Document; 37 class PaymentRequest; 35 38 36 39 class PaymentResponse final : public RefCounted<PaymentResponse> { 37 40 public: 41 static Ref<PaymentResponse> create(PaymentRequest& request) 42 { 43 return adoptRef(*new PaymentResponse(request)); 44 } 45 46 ~PaymentResponse(); 47 38 48 const String& requestId() const { return m_requestId; } 49 void setRequestId(const String& requestId) { m_requestId = requestId; } 50 39 51 const String& methodName() const { return m_methodName; } 52 void setMethodName(const String& methodName) { m_methodName = methodName; } 53 40 54 const JSC::Strong<JSC::JSObject>& details() const { return m_details; } 55 void setDetails(JSC::Strong<JSC::JSObject>&& details) { m_details = WTFMove(details); } 56 41 57 PaymentAddress* shippingAddress() const { return m_shippingAddress.get(); } 58 void setShippingAddress(PaymentAddress* shippingAddress) { m_shippingAddress = shippingAddress; } 59 42 60 const String& shippingOption() const { return m_shippingOption; } 61 void setShippingOption(const String& shippingOption) { m_shippingOption = shippingOption; } 62 43 63 const String& payerName() const { return m_payerName; } 64 void setPayerName(const String& payerName) { m_payerName = payerName; } 65 44 66 const String& payerEmail() const { return m_payerEmail; } 67 void setPayerEmail(const String& payerEmail) { m_payerEmail = payerEmail; } 68 45 69 const String& payerPhone() const { return m_payerPhone; } 70 void setPayerPhone(const String& payerPhone) { m_payerPhone = payerPhone; } 46 71 47 72 void complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&&); 48 73 49 74 private: 75 explicit PaymentResponse(PaymentRequest&); 76 77 Ref<PaymentRequest> m_request; 50 78 String m_requestId; 51 79 String m_methodName; … … 56 84 String m_payerEmail; 57 85 String m_payerPhone; 86 bool m_completeCalled { false }; 58 87 }; 59 88 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r223850 r223855 3873 3873 A14090FB1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A14090FA1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm */; }; 3874 3874 A14090FD1AA51E480091191A /* ContentFilterUnblockHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = A14090FC1AA51E480091191A /* ContentFilterUnblockHandler.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3875 A146D31A1F99BCF800D29196 /* JSMockPaymentCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */; }; 3876 A146D31B1F99BCFB00D29196 /* JSMockPaymentCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */; }; 3877 A146D3211F99CB1A00D29196 /* MockPaymentAddress.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D31C1F99C9C200D29196 /* MockPaymentAddress.h */; }; 3878 A146D3221F99D0EC00D29196 /* JSMockPaymentAddress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A146D3201F99CA3E00D29196 /* JSMockPaymentAddress.cpp */; }; 3879 A146D3231F99D0EF00D29196 /* JSMockPaymentAddress.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D31F1F99CA3D00D29196 /* JSMockPaymentAddress.h */; }; 3880 A146D3251F99D69800D29196 /* MockPaymentContact.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D3241F99D69800D29196 /* MockPaymentContact.h */; }; 3875 3881 A14832B0187F618D00DA63A6 /* WAKAppKitStubs.h in Headers */ = {isa = PBXBuildFile; fileRef = A148328C187F508700DA63A6 /* WAKAppKitStubs.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3876 3882 A14832B1187F61E100DA63A6 /* WAKAppKitStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = A148328D187F508700DA63A6 /* WAKAppKitStubs.m */; }; … … 3907 3913 A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A149786D1ABAF33800CEF7E4 /* ContentFilter.h */; }; 3908 3914 A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */; }; 3915 A14BB0A01F9813B800605A35 /* MockPayment.h in Headers */ = {isa = PBXBuildFile; fileRef = A14BB09E1F9813B800605A35 /* MockPayment.h */; }; 3909 3916 A15D75151E68F7C400A35FBC /* BlobCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A15D75121E68F7B100A35FBC /* BlobCallback.cpp */; }; 3910 3917 A15D75161E68F7C800A35FBC /* BlobCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = A15D75131E68F7B100A35FBC /* BlobCallback.h */; }; … … 3952 3959 A1CC567D1F4614B200A4555B /* JSPaymentShippingOption.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC56591F46145C00A4555B /* JSPaymentShippingOption.h */; }; 3953 3960 A1CC567F1F4614B700A4555B /* JSPaymentShippingType.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC56501F46145300A4555B /* JSPaymentShippingType.h */; }; 3961 A1CFE0321F9E71290065C345 /* PaymentAddress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1CFE0311F9E71290065C345 /* PaymentAddress.cpp */; }; 3954 3962 A1DE712D18612AC100734192 /* TouchEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1DE712B18612AC100734192 /* TouchEvents.cpp */; }; 3955 3963 A1DF5A7F1F7EBD0B0058A477 /* ApplePayRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF5A7C1F7EBD0B0058A477 /* ApplePayRequest.h */; }; … … 12130 12138 A14090FA1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentFilterUnblockHandlerCocoa.mm; sourceTree = "<group>"; }; 12131 12139 A14090FC1AA51E480091191A /* ContentFilterUnblockHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilterUnblockHandler.h; sourceTree = "<group>"; }; 12140 A146D3161F99B53D00D29196 /* MockPaymentCoordinator.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MockPaymentCoordinator.idl; sourceTree = "<group>"; }; 12141 A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMockPaymentCoordinator.h; sourceTree = "<group>"; }; 12142 A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMockPaymentCoordinator.cpp; sourceTree = "<group>"; }; 12143 A146D31C1F99C9C200D29196 /* MockPaymentAddress.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPaymentAddress.h; sourceTree = "<group>"; }; 12144 A146D31E1F99C9C200D29196 /* MockPaymentAddress.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MockPaymentAddress.idl; sourceTree = "<group>"; }; 12145 A146D31F1F99CA3D00D29196 /* JSMockPaymentAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMockPaymentAddress.h; sourceTree = "<group>"; }; 12146 A146D3201F99CA3E00D29196 /* JSMockPaymentAddress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMockPaymentAddress.cpp; sourceTree = "<group>"; }; 12147 A146D3241F99D69800D29196 /* MockPaymentContact.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPaymentContact.h; sourceTree = "<group>"; }; 12132 12148 A148328C187F508700DA63A6 /* WAKAppKitStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WAKAppKitStubs.h; sourceTree = "<group>"; }; 12133 12149 A148328D187F508700DA63A6 /* WAKAppKitStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WAKAppKitStubs.m; sourceTree = "<group>"; }; … … 12164 12180 A149786D1ABAF33800CEF7E4 /* ContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilter.h; sourceTree = "<group>"; }; 12165 12181 A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformContentFilter.h; sourceTree = "<group>"; }; 12182 A14BB09E1F9813B800605A35 /* MockPayment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPayment.h; sourceTree = "<group>"; }; 12166 12183 A15D75121E68F7B100A35FBC /* BlobCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobCallback.cpp; sourceTree = "<group>"; }; 12167 12184 A15D75131E68F7B100A35FBC /* BlobCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobCallback.h; sourceTree = "<group>"; }; … … 12227 12244 A1CC56641F46146700A4555B /* JSPaymentResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentResponse.h; sourceTree = "<group>"; }; 12228 12245 A1CC56651F46146800A4555B /* JSPaymentAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentAddress.h; sourceTree = "<group>"; }; 12246 A1CFE0311F9E71290065C345 /* PaymentAddress.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PaymentAddress.cpp; sourceTree = "<group>"; }; 12229 12247 A1DE712B18612AC100734192 /* TouchEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TouchEvents.cpp; sourceTree = "<group>"; }; 12230 12248 A1DF5A7C1F7EBD0B0058A477 /* ApplePayRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePayRequest.h; sourceTree = "<group>"; }; … … 17501 17519 2DAAE32C19DCAF6000E002D2 /* MockPageOverlayClient.cpp */, 17502 17520 2DAAE32D19DCAF6000E002D2 /* MockPageOverlayClient.h */, 17521 A14BB09E1F9813B800605A35 /* MockPayment.h */, 17522 A146D31C1F99C9C200D29196 /* MockPaymentAddress.h */, 17523 A146D31E1F99C9C200D29196 /* MockPaymentAddress.idl */, 17524 A146D3241F99D69800D29196 /* MockPaymentContact.h */, 17503 17525 A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */, 17504 17526 A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */, 17527 A146D3161F99B53D00D29196 /* MockPaymentCoordinator.idl */, 17505 17528 A14061891E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp */, 17506 17529 A140618A1E2ECA0A0032B34E /* MockPreviewLoaderClient.h */, … … 17533 17556 2D6F3E921C1F85550061DBD4 /* JSMockPageOverlay.cpp */, 17534 17557 2D6F3E931C1F85550061DBD4 /* JSMockPageOverlay.h */, 17558 A146D3201F99CA3E00D29196 /* JSMockPaymentAddress.cpp */, 17559 A146D31F1F99CA3D00D29196 /* JSMockPaymentAddress.h */, 17560 A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */, 17561 A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */, 17535 17562 EBF5121A1696496C0056BD25 /* JSTypeConversions.cpp */, 17536 17563 EBF5121B1696496C0056BD25 /* JSTypeConversions.h */, … … 21262 21289 isa = PBXGroup; 21263 21290 children = ( 21291 A1CFE0311F9E71290065C345 /* PaymentAddress.cpp */, 21264 21292 A1F76B401F44CF7F0014C318 /* PaymentAddress.h */, 21265 21293 A1F76B421F44CF7F0014C318 /* PaymentAddress.idl */, … … 26674 26702 A19AEA211AAA808600B52B25 /* JSMockContentFilterSettings.h in Headers */, 26675 26703 538EC9341F99B9F7004D22A8 /* JSMockPageOverlay.h in Headers */, 26704 A146D3231F99D0EF00D29196 /* JSMockPaymentAddress.h in Headers */, 26705 A146D31B1F99BCFB00D29196 /* JSMockPaymentCoordinator.h in Headers */, 26676 26706 EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */, 26677 26707 CDC26B41160A8CCE0026757B /* LegacyMockCDM.h in Headers */, … … 26683 26713 2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */, 26684 26714 2D97F04819DD4140001EE9C3 /* MockPageOverlayClient.h in Headers */, 26715 A14BB0A01F9813B800605A35 /* MockPayment.h in Headers */, 26716 A146D3211F99CB1A00D29196 /* MockPaymentAddress.h in Headers */, 26717 A146D3251F99D69800D29196 /* MockPaymentContact.h in Headers */, 26685 26718 A1AFEDE61F8BFF6D0087013F /* MockPaymentCoordinator.h in Headers */, 26686 26719 A140618C1E2ECA0A0032B34E /* MockPreviewLoaderClient.h in Headers */, … … 30899 30932 A19AEA221AAA808A00B52B25 /* JSMockContentFilterSettings.cpp in Sources */, 30900 30933 2D4150DE1C1F868C000A3BA2 /* JSMockPageOverlay.cpp in Sources */, 30934 A146D3221F99D0EC00D29196 /* JSMockPaymentAddress.cpp in Sources */, 30935 A146D31A1F99BCF800D29196 /* JSMockPaymentCoordinator.cpp in Sources */, 30901 30936 EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */, 30902 30937 CDC26B40160A8CC60026757B /* LegacyMockCDM.cpp in Sources */, … … 32208 32243 A8FA6E5E0E4CFDED00D5CF49 /* Pattern.cpp in Sources */, 32209 32244 A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */, 32245 A1CFE0321F9E71290065C345 /* PaymentAddress.cpp in Sources */, 32210 32246 1A8A646C1D19FF8700D0E00F /* PaymentCocoa.mm in Sources */, 32211 32247 1A8A646D1D19FF8700D0E00F /* PaymentContactCocoa.mm in Sources */, -
trunk/Source/WebCore/testing/Internals.cpp
r223839 r223855 514 514 515 515 #if ENABLE(APPLE_PAY) 516 if (auto frame = document.frame()) 517 frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*new MockPaymentCoordinator(frame->mainFrame()))); 516 auto* frame = document.frame(); 517 if (frame && frame->isMainFrame()) { 518 m_mockPaymentCoordinator = new MockPaymentCoordinator(frame->mainFrame()); 519 frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*m_mockPaymentCoordinator)); 520 } 518 521 #endif 519 522 } … … 4259 4262 } 4260 4263 4264 #if ENABLE(APPLE_PAY) 4265 MockPaymentCoordinator& Internals::mockPaymentCoordinator() const 4266 { 4267 return *m_mockPaymentCoordinator; 4268 } 4269 #endif 4270 4261 4271 } // namespace WebCore -
trunk/Source/WebCore/testing/Internals.h
r223839 r223855 74 74 class MockContentFilterSettings; 75 75 class MockPageOverlay; 76 class MockPaymentCoordinator; 76 77 class NodeList; 77 78 class Page; … … 619 620 620 621 bool hasServiceWorkerRegisteredForOrigin(const String&); 622 623 #if ENABLE(APPLE_PAY) 624 MockPaymentCoordinator& mockPaymentCoordinator() const; 625 #endif 621 626 622 627 String timelineDescription(AnimationTimeline&); … … 643 648 std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend; 644 649 RefPtr<CacheStorageConnection> m_cacheStorageConnection; 650 651 #if ENABLE(APPLE_PAY) 652 MockPaymentCoordinator* m_mockPaymentCoordinator { nullptr }; 653 #endif 645 654 }; 646 655 -
trunk/Source/WebCore/testing/Internals.idl
r223839 r223855 564 564 565 565 [EnabledAtRuntime=WebAnimations] DOMString timelineDescription(AnimationTimeline timeline); 566 }; 566 [Conditional=APPLE_PAY] readonly attribute MockPaymentCoordinator mockPaymentCoordinator; 567 }; -
trunk/Source/WebCore/testing/MockPayment.h
r223854 r223855 24 24 */ 25 25 26 #include "config.h" 27 #include "PaymentResponse.h" 26 #pragma once 28 27 29 #if ENABLE( PAYMENT_REQUEST)28 #if ENABLE(APPLE_PAY) 30 29 31 #include <wtf/RunLoop.h> 30 #include "ApplePayPayment.h" 31 #include "Payment.h" 32 32 33 33 namespace WebCore { 34 34 35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise) 36 { 37 promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") }); 38 } 35 class MockPayment final : public Payment { 36 public: 37 explicit MockPayment(ApplePayPayment&& applePayPayment) 38 : m_applePayPayment { WTFMove(applePayPayment) } 39 { 40 } 41 42 ApplePayPayment toApplePayPayment() const final { return m_applePayPayment; } 43 44 private: 45 ApplePayPayment m_applePayPayment; 46 }; 39 47 40 48 } // namespace WebCore 41 49 42 #endif // ENABLE( PAYMENT_REQUEST)50 #endif // ENABLE(APPLE_PAY) -
trunk/Source/WebCore/testing/MockPaymentAddress.h
r223854 r223855 24 24 */ 25 25 26 #include "config.h" 27 #include "PaymentResponse.h" 26 #pragma once 28 27 29 #if ENABLE( PAYMENT_REQUEST)28 #if ENABLE(APPLE_PAY) 30 29 31 #include <wtf/RunLoop.h>30 #include "ApplePayPaymentContact.h" 32 31 33 32 namespace WebCore { 34 33 35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise) 36 { 37 promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") }); 38 } 34 struct MockPaymentAddress : ApplePayPaymentContact { 35 }; 39 36 40 37 } // namespace WebCore 41 38 42 #endif // ENABLE( PAYMENT_REQUEST)39 #endif // ENABLE(APPLE_PAY) -
trunk/Source/WebCore/testing/MockPaymentAddress.idl
r223854 r223855 24 24 */ 25 25 26 #include "config.h" 27 #include "PaymentResponse.h" 28 29 #if ENABLE(PAYMENT_REQUEST) 30 31 #include <wtf/RunLoop.h> 32 33 namespace WebCore { 34 35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise) 36 { 37 promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") }); 38 } 39 40 } // namespace WebCore 41 42 #endif // ENABLE(PAYMENT_REQUEST) 26 [ 27 Conditional=APPLE_PAY 28 ] dictionary MockPaymentAddress { 29 DOMString countryCode; 30 FrozenArray<DOMString> addressLines; 31 DOMString administrativeArea; 32 DOMString locality; 33 DOMString subLocality; 34 DOMString postalCode; 35 DOMString localizedName; 36 DOMString phoneNumber; 37 DOMString emailAddress; 38 }; -
trunk/Source/WebCore/testing/MockPaymentContact.h
r223854 r223855 24 24 */ 25 25 26 #include "config.h" 27 #include "PaymentResponse.h" 26 #pragma once 28 27 29 #if ENABLE( PAYMENT_REQUEST)28 #if ENABLE(APPLE_PAY) 30 29 31 #include <wtf/RunLoop.h> 30 #include "ApplePayPaymentContact.h" 31 #include "PaymentContact.h" 32 32 33 33 namespace WebCore { 34 34 35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise) 36 { 37 promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") }); 38 } 35 class MockPaymentContact final : public PaymentContact { 36 public: 37 explicit MockPaymentContact(ApplePayPaymentContact&& applePayPaymentContact) 38 : m_applePayPaymentContact { WTFMove(applePayPaymentContact) } 39 { 40 } 41 42 ApplePayPaymentContact toApplePayPaymentContact() const final { return m_applePayPaymentContact; } 43 44 private: 45 ApplePayPaymentContact m_applePayPaymentContact; 46 }; 39 47 40 48 } // namespace WebCore 41 49 42 #endif // ENABLE( PAYMENT_REQUEST)50 #endif // ENABLE(APPLE_PAY) -
trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp
r223193 r223855 30 30 31 31 #include "MainFrame.h" 32 #include "MockPayment.h" 33 #include "MockPaymentContact.h" 32 34 #include "PaymentCoordinator.h" 33 35 #include "URL.h" … … 59 61 } 60 62 61 void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, WTF::Function<void(bool)>&& completionHandler)63 void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, Function<void(bool)>&& completionHandler) 62 64 { 63 65 RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() { … … 66 68 } 67 69 68 void MockPaymentCoordinator::openPaymentSetup(const String&, const String&, WTF::Function<void(bool)>&& completionHandler)70 void MockPaymentCoordinator::openPaymentSetup(const String&, const String&, Function<void(bool)>&& completionHandler) 69 71 { 70 72 RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() { … … 73 75 } 74 76 77 static uint64_t showCount; 78 static uint64_t hideCount; 79 80 static void dispatchIfShowing(Function<void()>&& function) 81 { 82 ASSERT(showCount > hideCount); 83 RunLoop::main().dispatch([currentShowCount = showCount, function = WTFMove(function)]() { 84 if (showCount > hideCount && showCount == currentShowCount) 85 function(); 86 }); 87 } 88 75 89 bool MockPaymentCoordinator::showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&) 76 90 { 77 RunLoop::main().dispatch([mainFrame = makeRef(m_mainFrame)]() { 91 ASSERT(showCount == hideCount); 92 ++showCount; 93 dispatchIfShowing([mainFrame = makeRef(m_mainFrame)]() { 78 94 mainFrame->paymentCoordinator().validateMerchant({ URL(), ASCIILiteral("https://webkit.org/") }); 79 95 }); … … 81 97 } 82 98 99 void MockPaymentCoordinator::completeMerchantValidation(const PaymentMerchantSession&) 100 { 101 dispatchIfShowing([mainFrame = makeRef(m_mainFrame), shippingAddress = m_shippingAddress]() { 102 ApplePayPaymentContact contact = shippingAddress; 103 mainFrame->paymentCoordinator().didSelectShippingContact(MockPaymentContact { WTFMove(contact) }); 104 105 ApplePayPayment payment; 106 payment.shippingContact = shippingAddress; 107 mainFrame->paymentCoordinator().didAuthorizePayment(MockPayment { WTFMove(payment) }); 108 }); 109 } 110 111 void MockPaymentCoordinator::completePaymentSession(std::optional<PaymentAuthorizationResult>&&) 112 { 113 ++hideCount; 114 ASSERT(showCount == hideCount); 115 } 116 117 void MockPaymentCoordinator::abortPaymentSession() 118 { 119 ++hideCount; 120 ASSERT(showCount == hideCount); 121 } 122 123 void MockPaymentCoordinator::cancelPaymentSession() 124 { 125 ++hideCount; 126 ASSERT(showCount == hideCount); 127 } 128 83 129 void MockPaymentCoordinator::paymentCoordinatorDestroyed() 84 130 { 131 ASSERT(showCount == hideCount); 85 132 delete this; 86 133 } -
trunk/Source/WebCore/testing/MockPaymentCoordinator.h
r223193 r223855 28 28 #if ENABLE(APPLE_PAY) 29 29 30 #include "MockPaymentAddress.h" 30 31 #include "PaymentCoordinatorClient.h" 31 32 … … 38 39 explicit MockPaymentCoordinator(MainFrame&); 39 40 41 void setShippingAddress(MockPaymentAddress&& shippingAddress) { m_shippingAddress = WTFMove(shippingAddress); } 42 43 void ref() const { } 44 void deref() const { } 45 40 46 private: 41 47 bool supportsVersion(unsigned) final; … … 44 50 void openPaymentSetup(const String&, const String&, WTF::Function<void(bool)>&&); 45 51 bool showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&) final; 46 void completeMerchantValidation(const PaymentMerchantSession&) final { }52 void completeMerchantValidation(const PaymentMerchantSession&) final; 47 53 void completeShippingMethodSelection(std::optional<ShippingMethodUpdate>&&) final { } 48 54 void completeShippingContactSelection(std::optional<ShippingContactUpdate>&&) final { } 49 55 void completePaymentMethodSelection(std::optional<PaymentMethodUpdate>&&) final { } 50 void completePaymentSession(std::optional<PaymentAuthorizationResult>&&) final { }51 void abortPaymentSession() final { }52 void cancelPaymentSession() final { }56 void completePaymentSession(std::optional<PaymentAuthorizationResult>&&) final; 57 void abortPaymentSession() final; 58 void cancelPaymentSession() final; 53 59 void paymentCoordinatorDestroyed() final; 54 60 55 61 MainFrame& m_mainFrame; 62 MockPaymentAddress m_shippingAddress; 56 63 }; 57 64 -
trunk/Source/WebCore/testing/MockPaymentCoordinator.idl
r223854 r223855 24 24 */ 25 25 26 #include "config.h" 27 #include "PaymentResponse.h" 28 29 #if ENABLE(PAYMENT_REQUEST) 30 31 #include <wtf/RunLoop.h> 32 33 namespace WebCore { 34 35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise) 36 { 37 promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") }); 38 } 39 40 } // namespace WebCore 41 42 #endif // ENABLE(PAYMENT_REQUEST) 26 [ 27 Conditional=APPLE_PAY, 28 NoInterfaceObject, 29 ] interface MockPaymentCoordinator { 30 void setShippingAddress(MockPaymentAddress shippingAddress); 31 };
Note: See TracChangeset
for help on using the changeset viewer.