Bug 178048 - [Payment Request] Implement PaymentRequest.canMakePayment()
Summary: [Payment Request] Implement PaymentRequest.canMakePayment()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andy Estes
URL:
Keywords: InRadar
Depends on:
Blocks: 174796
  Show dependency treegraph
 
Reported: 2017-10-07 03:48 PDT by Andy Estes
Modified: 2019-05-02 16:25 PDT (History)
13 users (show)

See Also:


Attachments
Patch (59.85 KB, patch)
2017-10-07 03:50 PDT, Andy Estes
buildbot: commit-queue-
Details | Formatted Diff | Diff
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 Details
Patch (26.67 KB, patch)
2017-10-09 17:23 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
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 Details
Patch (29.36 KB, patch)
2017-10-10 13:58 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (30.50 KB, patch)
2017-10-10 16:56 PDT, Andy Estes
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Estes 2017-10-07 03:48:36 PDT
[Payment Request] Implement PaymentRequest.canMakePayment()
Comment 1 Andy Estes 2017-10-07 03:50:34 PDT
Created attachment 323092 [details]
Patch
Comment 2 youenn fablet 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.
Comment 3 Build Bot 2017-10-07 11:58:26 PDT Comment hidden (obsolete)
Comment 4 Build Bot 2017-10-07 11:58:27 PDT Comment hidden (obsolete)
Comment 5 Andy Estes 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.
Comment 6 Andy Estes 2017-10-09 17:23:32 PDT Comment hidden (obsolete)
Comment 7 Build Bot 2017-10-09 20:10:11 PDT Comment hidden (obsolete)
Comment 8 Build Bot 2017-10-09 20:10:12 PDT Comment hidden (obsolete)
Comment 9 Andy Estes 2017-10-10 13:58:27 PDT
Created attachment 323348 [details]
Patch
Comment 10 Andy Estes 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.
Comment 11 youenn fablet 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.
Comment 12 Andy Estes 2017-10-10 16:56:45 PDT
Created attachment 323360 [details]
Patch
Comment 13 Andy Estes 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!
Comment 14 WebKit Commit Bot 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>
Comment 15 WebKit Commit Bot 2017-10-10 17:37:56 PDT
All reviewed patches have been landed.  Closing bug.
Comment 16 Radar WebKit Bug Importer 2017-10-10 17:39:30 PDT
<rdar://problem/34924234>