Bug 178048

Summary: [Payment Request] Implement PaymentRequest.canMakePayment()
Product: WebKit Reporter: Andy Estes <aestes>
Component: New BugsAssignee: Andy Estes <aestes>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, beidson, buildbot, cdumez, commit-queue, dbates, esprehn+autocc, kondapallykalyan, sam, thorton, webkit-bug-importer, yellowydv23, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 174796    
Attachments:
Description Flags
Patch
buildbot: commit-queue-
Archive of layout-test-results from ews115 for mac-elcapitan
none
Patch
none
Archive of layout-test-results from ews122 for ios-simulator-wk2
none
Patch
none
Patch none

Andy Estes
Reported 2017-10-07 03:48:36 PDT
[Payment Request] Implement PaymentRequest.canMakePayment()
Attachments
Patch (59.85 KB, patch)
2017-10-07 03:50 PDT, Andy Estes
buildbot: commit-queue-
Archive of layout-test-results from ews115 for mac-elcapitan (1.88 MB, application/zip)
2017-10-07 11:58 PDT, Build Bot
no flags
Patch (26.67 KB, patch)
2017-10-09 17:23 PDT, Andy Estes
no flags
Archive of layout-test-results from ews122 for ios-simulator-wk2 (7.30 MB, application/zip)
2017-10-09 20:10 PDT, Build Bot
no flags
Patch (29.36 KB, patch)
2017-10-10 13:58 PDT, Andy Estes
no flags
Patch (30.50 KB, patch)
2017-10-10 16:56 PDT, Andy Estes
no flags
Andy Estes
Comment 1 2017-10-07 03:50:34 PDT
youenn fablet
Comment 2 2017-10-07 08:04:40 PDT
Comment on attachment 323092 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=323092&action=review > Source/WebCore/Modules/applepay/PaymentCoordinator.h:82 > + PaymentCoordinatorClient* m_testingClient { nullptr }; Would it be possible for Internals to create a PaymentsCoordinator with a mock client and replace the default PaymentsCoordinator when being used in WTR. Or are you planning to support testing clients with regular browsers? > Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:175 > + completionHandler(paymentCoordinator(document).canMakePayments()); Why not completionHandler(false)? > Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:433 > + handler->canMakePayment(downcast<Document>(*scriptExecutionContext()), [promise = WTFMove(promise)](bool canMakePayment) mutable { Can we make canMakePayment take a Document& with CallWith=Document in the IDL? I would probably also do the same for the other methods using scriptExecutionContext() with CallWith=ScriptExecutionContext. Should canMakePayment completion handler take an ExceptionOr<bool>? > Source/WebCore/testing/MockPaymentCoordinator.cpp:40 > + mockPaymentCoordinator->ref(); // Balanced by deref() in paymentCoordinatorDestroyed() That seems a bit strange. Cannot we store/access the MockPaymentCoordinator as an Internals attribute? > Source/WebCore/testing/MockPaymentCoordinator.cpp:66 > + completionHandler(true); For better mocking, should this be done asynchronously? > Source/WebCore/testing/MockPaymentCoordinator.cpp:71 > + completionHandler(true); Ditto.
Build Bot
Comment 3 2017-10-07 11:58:26 PDT Comment hidden (obsolete)
Build Bot
Comment 4 2017-10-07 11:58:27 PDT Comment hidden (obsolete)
Andy Estes
Comment 5 2017-10-09 16:40:05 PDT
(In reply to youenn fablet from comment #2) > Comment on attachment 323092 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=323092&action=review > > > Source/WebCore/Modules/applepay/PaymentCoordinator.h:82 > > + PaymentCoordinatorClient* m_testingClient { nullptr }; > > Would it be possible for Internals to create a PaymentsCoordinator with a > mock client and replace the default PaymentsCoordinator when being used in > WTR. > Or are you planning to support testing clients with regular browsers? I like this idea. I ended up implementing it in another patch since it turns out I needed a mock there too (see r223076). > > > Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:175 > > + completionHandler(paymentCoordinator(document).canMakePayments()); > > Why not completionHandler(false)? Calling canMakePayments() is the correct fallback when applePayCapabilityDisclosureAllowed() is false. > > > Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:433 > > + handler->canMakePayment(downcast<Document>(*scriptExecutionContext()), [promise = WTFMove(promise)](bool canMakePayment) mutable { > > Can we make canMakePayment take a Document& with CallWith=Document in the > IDL? > I would probably also do the same for the other methods using > scriptExecutionContext() with CallWith=ScriptExecutionContext. Ok sure. > > Should canMakePayment completion handler take an ExceptionOr<bool>? I don't think so. There are no exceptions to be thrown by the completion handler. > > > Source/WebCore/testing/MockPaymentCoordinator.cpp:40 > > + mockPaymentCoordinator->ref(); // Balanced by deref() in paymentCoordinatorDestroyed() > > That seems a bit strange. > Cannot we store/access the MockPaymentCoordinator as an Internals attribute? Yes, this probably makes sense. For now I didn't expose the mock at all since I don't (yet) need to configure it from script. > > > Source/WebCore/testing/MockPaymentCoordinator.cpp:66 > > + completionHandler(true); > > For better mocking, should this be done asynchronously? I did this in r223076.
Andy Estes
Comment 6 2017-10-09 17:23:32 PDT Comment hidden (obsolete)
Build Bot
Comment 7 2017-10-09 20:10:11 PDT Comment hidden (obsolete)
Build Bot
Comment 8 2017-10-09 20:10:12 PDT Comment hidden (obsolete)
Andy Estes
Comment 9 2017-10-10 13:58:27 PDT
Andy Estes
Comment 10 2017-10-10 16:20:43 PDT
Comment on attachment 323348 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=323348&action=review > Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:401 > + if (exception.hasException()) > + m_showPromise->reject(exception.releaseException()); Oops, I need to return after rejecting if there is an exception.
youenn fablet
Comment 11 2017-10-10 16:36:38 PDT
Comment on attachment 323348 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=323348&action=review > Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:343 > +static ExceptionOr<JSC::JSValue> parse(ScriptExecutionContext& context, const String& string) This routine is nice and might be useful elsewhere now or in the future. > Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:405 > setPendingActivity(this); I usually like to have setPendingActivity/unsetPendingActivity close one to the other. That is made a bit more easy with a call to setPendingActivity and then a lambda with an unsetPendingActivity inside it. > LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:33 > +promise_test(async t => { This mix of async/await with promise_test looks good! > LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:48 > + "if it throws, then it must be a NotAllowedError." It seems strange that we are not always expecting either an exception or no exception.
Andy Estes
Comment 12 2017-10-10 16:56:45 PDT
Andy Estes
Comment 13 2017-10-10 17:00:57 PDT
(In reply to youenn fablet from comment #11) > Comment on attachment 323348 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=323348&action=review > > > Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:405 > > setPendingActivity(this); > > I usually like to have setPendingActivity/unsetPendingActivity close one to > the other. > That is made a bit more easy with a call to setPendingActivity and then a > lambda with an unsetPendingActivity inside it. For now I moved stop() directly below show() and added a comment. > > > LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:48 > > + "if it throws, then it must be a NotAllowedError." > > It seems strange that we are not always expecting either an exception or no > exception. The reason for this check is that the user agent is allowed to abort a request if canMakePayment() is called too many times (to prevent fingerprinting/abuse). So in some implementations, the second call might abort the request resulting in a NotAllowedError. We don't implement any rate-limiting yet. Thanks for the review!
WebKit Commit Bot
Comment 14 2017-10-10 17:37:54 PDT
Comment on attachment 323360 [details] Patch Clearing flags on attachment: 323360 Committed r223160: <http://trac.webkit.org/changeset/223160>
WebKit Commit Bot
Comment 15 2017-10-10 17:37:56 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 16 2017-10-10 17:39:30 PDT
Note You need to log in before you can comment on or make changes to this bug.