Changeset 223160 in webkit
- Timestamp:
- Oct 10, 2017 5:37:49 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223145 r223160 1 2017-10-10 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Implement PaymentRequest.canMakePayment() 4 https://bugs.webkit.org/show_bug.cgi?id=178048 5 6 Reviewed by Youenn Fablet. 7 8 * http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt: Added. 9 * http/tests/paymentrequest/payment-request-canmakepayment-method.https.html: Added. 10 * http/tests/ssl/applepay/PaymentRequest.https.html: 11 * platform/ios-wk2/TestExpectations: 12 * platform/mac-wk2/TestExpectations: 13 1 14 2017-10-10 Joanmarie Diggs <jdiggs@igalia.com> 2 15 -
trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html
r223076 r223160 19 19 data: { 20 20 version: 2, 21 merchantIdentifier: '', 21 22 merchantCapabilities: ['supports3DS'], 22 23 supportedNetworks: ['visa', 'masterCard'], -
trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html
r223076 r223160 14 14 data: { 15 15 version: 2, 16 merchantIdentifier: '', 16 17 merchantCapabilities: ['supports3DS'], 17 18 supportedNetworks: ['visa', 'masterCard'], -
trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html
r222921 r223160 17 17 data: { 18 18 version: 2, 19 merchantIdentifier: '', 19 20 countryCode: 'US', 20 21 currencyCode: 'USD', -
trunk/LayoutTests/imported/w3c/ChangeLog
r223117 r223160 1 2017-10-10 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Implement PaymentRequest.canMakePayment() 4 https://bugs.webkit.org/show_bug.cgi?id=178048 5 6 Reviewed by Youenn Fablet. 7 8 * web-platform-tests/payment-request/payment-request-canmakepayment-method.https-expected.txt: Removed. 9 1 10 2017-10-09 Chris Dumez <cdumez@apple.com> 2 11 -
trunk/LayoutTests/platform/ios-wk2/TestExpectations
r223115 r223160 41 41 imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ] 42 42 imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ] 43 imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https.html [ WontFix ] 43 44 44 45 # skip manual payment-request tests -
trunk/LayoutTests/platform/mac-wk2/TestExpectations
r223115 r223160 39 39 imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ] 40 40 imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ] 41 imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https.html [ WontFix ] 41 42 42 43 # skip manual payment-request tests -
trunk/Source/WebCore/ChangeLog
r223156 r223160 1 2017-10-10 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Implement PaymentRequest.canMakePayment() 4 https://bugs.webkit.org/show_bug.cgi?id=178048 5 6 Reviewed by Youenn Fablet. 7 8 Test: http/tests/paymentrequest/payment-request-canmakepayment-method.https.html 9 10 * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp: 11 (WebCore::ApplePayPaymentHandler::convertData): Moved 12 ApplePayRequest-to-ApplePaySessionPaymentRequest conversion from here to show(). 13 (WebCore::ApplePayPaymentHandler::show): Returned an exception if 14 ApplePaySessionPaymentRequest conversion fails. 15 (WebCore::shouldDiscloseApplePayCapability): Checked if we are in an ephimeral session or if 16 Settings::applePayCapabilityDisclosureAllowed() is false. 17 (WebCore::ApplePayPaymentHandler::canMakePayment): Called 18 PaymentCoordinator::canMakePayments() or PaymentCoordinator::canMakePaymentsWithActiveCard() 19 depending on shouldDiscloseApplePayCapability(). 20 * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h: 21 * Modules/applepay/paymentrequest/ApplePayRequest.h: 22 * Modules/applepay/paymentrequest/ApplePayRequest.idl: Defined merchantIdentifier. 23 * Modules/paymentrequest/PaymentHandler.h: 24 * Modules/paymentrequest/PaymentRequest.cpp: 25 (WebCore::parse): Moved JSON-parsing to here from show(). 26 (WebCore::PaymentRequest::show): Returned the exception from PaymentHandler::show(). 27 (WebCore::PaymentRequest::canMakePayment): For each payment method, try to create a 28 PaymentHandler. 29 For the first valid PaymentHandler, call canMakePayment() and pass a lambda that resolves 30 the promise. 31 * Modules/paymentrequest/PaymentRequest.h: 32 * Modules/paymentrequest/PaymentRequest.idl: Added CallWith=Document annotations to show() 33 and canMakePayment(). 34 1 35 2017-10-10 Chris Dumez <cdumez@apple.com> 2 36 -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
r223076 r223160 33 33 #include "ApplePaySessionPaymentRequest.h" 34 34 #include "Document.h" 35 #include "Frame.h"36 35 #include "JSApplePayRequest.h" 37 36 #include "LinkIconCollector.h" 38 37 #include "MainFrame.h" 38 #include "Page.h" 39 39 #include "PaymentContact.h" 40 40 #include "PaymentCoordinator.h" 41 41 #include "PaymentRequestValidator.h" 42 #include "Settings.h" 42 43 43 44 namespace WebCore { … … 109 110 return ApplePaySessionPaymentRequest::ShippingType::Shipping; 110 111 } 111 112 112 113 static ApplePaySessionPaymentRequest::ShippingMethod convert(const PaymentShippingOption& shippingOption) 113 114 { … … 126 127 return Exception { ExistingExceptionError }; 127 128 128 auto validatedRequest = convertAndValidate(applePayRequest.version, applePayRequest); 129 m_applePayRequest = WTFMove(applePayRequest); 130 return { }; 131 } 132 133 ExceptionOr<void> ApplePayPaymentHandler::show(Document& document) 134 { 135 auto validatedRequest = convertAndValidate(m_applePayRequest->version, *m_applePayRequest); 129 136 if (validatedRequest.hasException()) 130 137 return validatedRequest.releaseException(); … … 155 162 return exception.releaseException(); 156 163 157 m_applePayRequest = WTFMove(request);158 return { };159 }160 161 void ApplePayPaymentHandler::show(Document& document)162 {163 164 Vector<URL> linkIconURLs; 164 165 for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon })) 165 166 linkIconURLs.append(icon.url); 166 167 167 paymentCoordinator(document).beginPaymentSession(*this, document.url(), linkIconURLs, *m_applePayRequest); 168 paymentCoordinator(document).beginPaymentSession(*this, document.url(), linkIconURLs, request); 169 return { }; 168 170 } 169 171 … … 173 175 } 174 176 177 static bool shouldDiscloseApplePayCapability(Document& document) 178 { 179 auto* page = document.page(); 180 if (!page || page->usesEphemeralSession()) 181 return false; 182 183 return document.settings().applePayCapabilityDisclosureAllowed(); 184 } 185 186 void ApplePayPaymentHandler::canMakePayment(Document& document, WTF::Function<void(bool)>&& completionHandler) 187 { 188 if (!shouldDiscloseApplePayCapability(document)) { 189 completionHandler(paymentCoordinator(document).canMakePayments()); 190 return; 191 } 192 193 paymentCoordinator(document).canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document.domain(), WTFMove(completionHandler)); 194 } 195 175 196 } // namespace WebCore 176 197 -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h
r223076 r223160 28 28 #if ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST) 29 29 30 #include "ApplePay SessionPaymentRequest.h"30 #include "ApplePayRequest.h" 31 31 #include "PaymentHandler.h" 32 32 #include "PaymentSession.h" … … 49 49 // PaymentHandler 50 50 ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) final; 51 voidshow(Document&) final;51 ExceptionOr<void> show(Document&) final; 52 52 void hide(Document&) final; 53 void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) final; 53 54 54 55 // PaymentSession … … 61 62 62 63 Ref<PaymentRequest> m_paymentRequest; 63 std::optional<ApplePay SessionPaymentRequest> m_applePayRequest;64 std::optional<ApplePayRequest> m_applePayRequest; 64 65 }; 65 66 -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.h
r222921 r223160 34 34 struct ApplePayRequest : public ApplePayRequestBase { 35 35 unsigned long version; 36 String merchantIdentifier; 36 37 }; 37 38 -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.idl
r222921 r223160 28 28 ] dictionary ApplePayRequest : ApplePayRequestBase { 29 29 required unsigned long version; 30 required DOMString merchantIdentifier; 30 31 }; -
trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h
r223076 r223160 30 30 #include "PaymentRequest.h" 31 31 #include "PaymentSessionBase.h" 32 #include <wtf/Function.h> 32 33 33 34 namespace JSC { … … 46 47 47 48 virtual ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) = 0; 48 virtual voidshow(Document&) = 0;49 virtual ExceptionOr<void> show(Document&) = 0; 49 50 virtual void hide(Document&) = 0; 51 virtual void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) = 0; 50 52 }; 51 53 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
r223076 r223160 341 341 } 342 342 343 static ExceptionOr<JSC::JSValue> parse(ScriptExecutionContext& context, const String& string) 344 { 345 auto scope = DECLARE_THROW_SCOPE(context.vm()); 346 JSC::JSValue data = JSONParse(context.execState(), string); 347 if (scope.exception()) 348 return Exception { ExistingExceptionError }; 349 return WTFMove(data); 350 } 351 343 352 // https://www.w3.org/TR/payment-request/#show()-method 344 void PaymentRequest::show( ShowPromise&& promise)353 void PaymentRequest::show(Document& document, ShowPromise&& promise) 345 354 { 346 355 // FIXME: Reject promise with SecurityError if show() was not triggered by a user gesture. … … 352 361 } 353 362 354 auto& document = downcast<Document>(*scriptExecutionContext());355 363 if (PaymentHandler::hasActiveSession(document)) { 356 364 promise.reject(Exception { AbortError }); … … 364 372 RefPtr<PaymentHandler> selectedPaymentHandler; 365 373 for (auto& paymentMethod : m_serializedMethodData) { 366 auto scope = DECLARE_THROW_SCOPE(document.vm()); 367 JSC::JSValue data = JSONParse(document.execState(), paymentMethod.serializedData); 368 if (scope.exception()) { 369 m_showPromise->reject(Exception { ExistingExceptionError }); 374 auto data = parse(document, paymentMethod.serializedData); 375 if (data.hasException()) { 376 m_showPromise->reject(data.releaseException()); 370 377 return; 371 378 } … … 375 382 continue; 376 383 377 auto result = handler->convertData(*document.execState(), WTFMove(data));384 auto result = handler->convertData(*document.execState(), data.releaseReturnValue()); 378 385 if (result.hasException()) { 379 386 m_showPromise->reject(result.releaseException()); … … 390 397 } 391 398 399 auto exception = selectedPaymentHandler->show(document); 400 if (exception.hasException()) { 401 m_showPromise->reject(exception.releaseException()); 402 return; 403 } 404 392 405 ASSERT(!m_activePaymentHandler); 393 406 m_activePaymentHandler = WTFMove(selectedPaymentHandler); 394 395 m_activePaymentHandler->show(document); 396 setPendingActivity(this); 407 setPendingActivity(this); // unsetPendingActivity() is called below in stop() 408 } 409 410 void PaymentRequest::stop() 411 { 412 if (m_state != State::Interactive) 413 return; 414 415 if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) { 416 unsetPendingActivity(this); 417 paymentHandler->hide(downcast<Document>(*scriptExecutionContext())); 418 } 419 420 ASSERT(m_state == State::Interactive); 421 m_state = State::Closed; 422 m_showPromise->reject(Exception { AbortError }); 397 423 } 398 424 … … 409 435 410 436 // https://www.w3.org/TR/payment-request/#canmakepayment()-method 411 void PaymentRequest::canMakePayment( CanMakePaymentPromise&& promise)437 void PaymentRequest::canMakePayment(Document& document, CanMakePaymentPromise&& promise) 412 438 { 413 439 if (m_state != State::Created) { … … 416 442 } 417 443 418 // FIXME: Resolve the promise with true if we can support any of the payment methods in m_serializedMethodData. 444 for (auto& paymentMethod : m_serializedMethodData) { 445 auto data = parse(document, paymentMethod.serializedData); 446 if (data.hasException()) 447 continue; 448 449 auto handler = PaymentHandler::create(*this, paymentMethod.identifier); 450 if (!handler) 451 continue; 452 453 auto exception = handler->convertData(*document.execState(), data.releaseReturnValue()); 454 if (exception.hasException()) 455 continue; 456 457 handler->canMakePayment(document, [promise = WTFMove(promise)](bool canMakePayment) mutable { 458 promise.resolve(canMakePayment); 459 }); 460 return; 461 } 462 419 463 promise.resolve(false); 420 464 } … … 444 488 } 445 489 446 void PaymentRequest::stop()447 {448 if (m_state != State::Interactive)449 return;450 451 if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) {452 unsetPendingActivity(this);453 paymentHandler->hide(downcast<Document>(*scriptExecutionContext()));454 }455 456 ASSERT(m_state == State::Interactive);457 m_state = State::Closed;458 m_showPromise->reject(Exception { AbortError });459 }460 461 490 } // namespace WebCore 462 491 -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h
r223076 r223160 55 55 ~PaymentRequest(); 56 56 57 void show( ShowPromise&&);57 void show(Document&, ShowPromise&&); 58 58 ExceptionOr<void> abort(AbortPromise&&); 59 void canMakePayment( CanMakePaymentPromise&&);59 void canMakePayment(Document&, CanMakePaymentPromise&&); 60 60 61 61 const String& id() const; … … 104 104 State m_state { State::Created }; 105 105 std::optional<ShowPromise> m_showPromise; 106 std::optional<CanMakePaymentPromise> m_canMakePaymentPromise;107 106 RefPtr<PaymentHandler> m_activePaymentHandler; 108 107 }; -
trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl
r221020 r223160 33 33 SecureContext 34 34 ] interface PaymentRequest : EventTarget { 35 Promise<PaymentResponse> show();35 [CallWith=Document] Promise<PaymentResponse> show(); 36 36 [MayThrowException] Promise<void> abort(); 37 Promise<boolean> canMakePayment();37 [CallWith=Document] Promise<boolean> canMakePayment(); 38 38 39 39 readonly attribute DOMString id;
Note: See TracChangeset
for help on using the changeset viewer.