Bug 190058 - [Payment Request] Implement MerchantValidationEvent.methodName
Summary: [Payment Request] Implement MerchantValidationEvent.methodName
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
: 189548 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-09-27 15:36 PDT by Andy Estes
Modified: 2018-11-02 14:45 PDT (History)
13 users (show)

See Also:


Attachments
Patch (10.17 KB, patch)
2018-09-27 15:42 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (14.63 KB, patch)
2018-09-29 08:38 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (14.76 KB, patch)
2018-09-29 11:09 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (14.98 KB, patch)
2018-10-01 10:32 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (15.20 KB, patch)
2018-10-01 11:27 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (11.84 KB, patch)
2018-10-28 06:12 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 2018-09-27 15:36:55 PDT
[Payment Request] Implement MerchantValidationEvent.methodName
Comment 1 Andy Estes 2018-09-27 15:42:15 PDT Comment hidden (obsolete)
Comment 2 EWS Watchlist 2018-09-27 15:45:19 PDT Comment hidden (obsolete)
Comment 3 Darin Adler 2018-09-28 17:35:09 PDT
Comment on attachment 351014 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=351014&action=review

> Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:486
> +        m_paymentRequest->dispatchEvent(MerchantValidationEvent::create(eventNames().merchantvalidationEvent, WTF::get<URL>(m_identifier).string(), WTFMove(validationURL)).get());

I must admit I don’t understand why it’s guaranteed that m_identifier is a URL, and not some other type. But I do see this idiom elsewhere in the class so it must be OK.

> Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.cpp:49
> +    if (!methodName.isEmpty() && !convertAndValidatePaymentMethodIdentifier(methodName))
> +        return Exception { RangeError, makeString('"', methodName, "\" is an invalid payment method identifier.") };

If convertAndValidatePaymentMethodIdentifier is used elsewhere, I wonder if this exception is also needed elsewhere. Could share the code.
Comment 4 Andy Estes 2018-09-29 08:19:02 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 351014 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=351014&action=review
> 
> > Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:486
> > +        m_paymentRequest->dispatchEvent(MerchantValidationEvent::create(eventNames().merchantvalidationEvent, WTF::get<URL>(m_identifier).string(), WTFMove(validationURL)).get());
> 
> I must admit I don’t understand why it’s guaranteed that m_identifier is a
> URL, and not some other type. But I do see this idiom elsewhere in the class
> so it must be OK.

Apple Pay's payment method identifier is always a URL (enforced by ApplePayPaymentHandler::handlesIdentifier).

Given that, m_identifier could just be a URL.

Alternatively, PaymentRequest::MethodIdentifier could just be a String. We only need to verify that URL-based identifiers have the correct properties (https, no username or password), but after that we can just store a string representation of the URL.

I'll think about how to make this better.

> 
> > Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.cpp:49
> > +    if (!methodName.isEmpty() && !convertAndValidatePaymentMethodIdentifier(methodName))
> > +        return Exception { RangeError, makeString('"', methodName, "\" is an invalid payment method identifier.") };
> 
> If convertAndValidatePaymentMethodIdentifier is used elsewhere, I wonder if
> this exception is also needed elsewhere. Could share the code.

Good call, I'll change this to return an ExceptionOr<PaymentRequest::MethodIdentifier>.

Thanks for reviewing!
Comment 5 Andy Estes 2018-09-29 08:38:30 PDT Comment hidden (obsolete)
Comment 6 EWS Watchlist 2018-09-29 08:39:52 PDT Comment hidden (obsolete)
Comment 7 Andy Estes 2018-09-29 11:09:24 PDT Comment hidden (obsolete)
Comment 8 EWS Watchlist 2018-09-29 11:12:50 PDT Comment hidden (obsolete)
Comment 9 Darin Adler 2018-09-30 19:35:13 PDT
Comment on attachment 351188 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=351188&action=review

> Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.cpp:51
> +        auto validatedMethodName = convertAndValidatePaymentMethodIdentifier(methodName);
> +        if (validatedMethodName.hasException())
> +            return validatedMethodName.releaseException();

I think there is a missing line of code here:

    methodName = validatedMethodName.releaseReturnValue();

> Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.h:45
> +    static Ref<MerchantValidationEvent> create(const AtomicString& type, String methodName, URL&& validationURL);

Surprised that this uses String, and neither String&& or const String&.
Comment 10 Andy Estes 2018-10-01 10:25:14 PDT
(In reply to Darin Adler from comment #9)
> Comment on attachment 351188 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=351188&action=review
> 
> > Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.cpp:51
> > +        auto validatedMethodName = convertAndValidatePaymentMethodIdentifier(methodName);
> > +        if (validatedMethodName.hasException())
> > +            return validatedMethodName.releaseException();
> 
> I think there is a missing line of code here:
> 
>     methodName = validatedMethodName.releaseReturnValue();

It's ok to use methodName as-is so long as the validation didn't raise an exception. I'm only interested in the exception, not the converted identifier.

> 
> > Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.h:45
> > +    static Ref<MerchantValidationEvent> create(const AtomicString& type, String methodName, URL&& validationURL);
> 
> Surprised that this uses String, and neither String&& or const String&.

Yeah, I guess one copy is slightly better than one copy and one move.
Comment 11 Andy Estes 2018-10-01 10:32:10 PDT Comment hidden (obsolete)
Comment 12 Andy Estes 2018-10-01 10:33:11 PDT
(In reply to Andy Estes from comment #10)
> (In reply to Darin Adler from comment #9)
> > Comment on attachment 351188 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=351188&action=review
> > 
> > > Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.h:45
> > > +    static Ref<MerchantValidationEvent> create(const AtomicString& type, String methodName, URL&& validationURL);
> > 
> > Surprised that this uses String, and neither String&& or const String&.
> 
> Yeah, I guess one copy is slightly better than one copy and one move.

Forgot to say: Changed to use const String&.
Comment 13 EWS Watchlist 2018-10-01 10:35:36 PDT Comment hidden (obsolete)
Comment 14 Andy Estes 2018-10-01 11:27:32 PDT Comment hidden (obsolete)
Comment 15 EWS Watchlist 2018-10-01 11:28:47 PDT Comment hidden (obsolete)
Comment 16 Andy Estes 2018-10-28 06:12:41 PDT
Created attachment 353256 [details]
Patch
Comment 17 EWS Watchlist 2018-10-28 06:13:47 PDT
Attachment 353256 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/paymentrequest/MerchantValidationEvent.cpp:59:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 18 WebKit Commit Bot 2018-10-28 07:34:20 PDT
Comment on attachment 353256 [details]
Patch

Clearing flags on attachment: 353256

Committed r237521: <https://trac.webkit.org/changeset/237521>
Comment 19 WebKit Commit Bot 2018-10-28 07:34:22 PDT
All reviewed patches have been landed.  Closing bug.
Comment 20 Radar WebKit Bug Importer 2018-10-28 07:35:31 PDT
<rdar://problem/45620511>
Comment 21 Andy Estes 2018-11-02 14:45:57 PDT
*** Bug 189548 has been marked as a duplicate of this bug. ***