Closed Bug 1474499 Opened 6 years ago Closed 6 years ago

Add support for "onmerchantvalidation" and MerchantValidationEvent

Categories

(Core :: DOM: Web Payments, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla64
Tracking Status
firefox64 --- fixed

People

(Reporter: marcosc, Assigned: marcosc)

References

(Blocks 1 open bug, )

Details

(Keywords: dev-doc-complete, Whiteboard: [webpayments-reserve])

Attachments

(1 file, 6 obsolete files)

Adds:

 * interface MerchantValidationEvent
 * PaymentRequest.prototype.onmerchantvalidation

Allowing for merchant validation to be supported. We won't fire this event - it's just there for web-compat with Safari's Apple Pay when using the payment request API.
Priority: -- → P2
Assignee: nobody → mcaceres
Whiteboard: [webpayments][triage]
Priority: P2 → --
Whiteboard: [webpayments][triage] → [webpayments] [triage]
Priority: -- → P3
Flags: qe-verify-
Whiteboard: [webpayments] [triage] → [webpayments-reserve]
Attached patch Initial implementation (obsolete) — Splinter Review
Made a reference implementation as I was working on this part of the spec. Passes web platform tests 🎉👌

Thanks for feedback on GitHub, Eden! I decided that to use URLs proper instead of nsIURI.
Attachment #9005114 - Flags: review?(echuang)
Priority: P3 → P1
Eden, should I do the UI testing service for this too? I don't mind doing it, but we don't plan on supporting these events yet in Basic Card. 

This is just for Web Platform Tests conformance.
Status: NEW → ASSIGNED
Comment on attachment 9005114 [details] [diff] [review]
Initial implementation

Review of attachment 9005114 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/payments/MerchantValidationEvent.cpp
@@ +25,5 @@
> +NS_IMPL_ADDREF_INHERITED(MerchantValidationEvent, Event)
> +NS_IMPL_RELEASE_INHERITED(MerchantValidationEvent, Event)
> +
> +class Promise;
> +class EventTarget;

Remove forward declarations, they can only be used in header file.
class Promise;
class EventTarget;

@@ +76,5 @@
> +  }
> +
> +  nsString href;
> +  url->GetHref(href);
> +  event->SetValidationURL(href);

Move code from line 55 to 80 into
  MerchantValidationEvent::Constructor(EventTarget* aOwner, const nsAString& aType, const MerchantValidationEventInit& aEventInitDict)
Or
  PaymentRequest::DispatchMerchantValidationEvent

In fact, you don't use this Constructor in PaymentRequest::DispatchMerchantValidationEvent
That means the logic would not be run when calling PaymentRequest::DispatchMerchantValidationEvent;

@@ +101,5 @@
> +  }
> +
> +  // TODO: If we eventually support merchant validation
> +  // we would verify `aValue` here.
> +  mRequest->AbortUpdate(NS_ERROR_DOM_NOT_SUPPORTED_ERR, false);

Do we really want this?
mRequest->AbortUpdate(NS_ERROR_DOM_NOT_SUPPORTED_ERR, false);
would make the PaymentRequest be aborted.

That means no matter what merchant passed into PaymentMerchantValidationEvent::complete().
PaymentRequest always is aborted with NotSupportedError.

::: dom/payments/moz.build
@@ +10,4 @@
>  
>  EXPORTS += [
>      'PaymentRequestData.h',
> +    'PaymentRequestService.h',\

nit: remove "\"
Attachment #9005114 - Flags: review?(echuang) → review-
(In reply to Eden Chuang[:edenchuang] from comment #3)
> Comment on attachment 9005114 [details] [diff] [review]
> Initial implementation
> 
> Review of attachment 9005114 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> @@ +76,5 @@
> > +  }
> > +
> > +  nsString href;
> > +  url->GetHref(href);
> > +  event->SetValidationURL(href);
> 
> Move code from line 55 to 80 into
>   MerchantValidationEvent::Constructor(EventTarget* aOwner, const nsAString&
> aType, const MerchantValidationEventInit& aEventInitDict)
> Or
>   PaymentRequest::DispatchMerchantValidationEvent
> 
> In fact, you don't use this Constructor in
> PaymentRequest::DispatchMerchantValidationEvent
> That means the logic would not be run when calling
> PaymentRequest::DispatchMerchantValidationEvent;

Or you might do it like you did in PaymentMethodChangeEvent
https://searchfox.org/mozilla-central/source/dom/payments/PaymentMethodChangeEvent.cpp#47
Declare an init function for it and set up the validationURL.
(In reply to Eden Chuang[:edenchuang] from comment #4)
> Or you might do it like you did in PaymentMethodChangeEvent
> https://searchfox.org/mozilla-central/source/dom/payments/
> PaymentMethodChangeEvent.cpp#47
> Declare an init function for it and set up the validationURL.

I'm having problems figuring out how to derive the `GlobalObject` when I refactor the code. I need a global object to be able to construct the URL. 

I also need `aRV` so I can set the exception in case the URL construction results in failure.

Any suggestions?
(In reply to Marcos Caceres [:marcosc] from comment #5)
> (In reply to Eden Chuang[:edenchuang] from comment #4)
> > Or you might do it like you did in PaymentMethodChangeEvent
> > https://searchfox.org/mozilla-central/source/dom/payments/
> > PaymentMethodChangeEvent.cpp#47
> > Declare an init function for it and set up the validationURL.
> 
> I'm having problems figuring out how to derive the `GlobalObject` when I
> refactor the code. I need a global object to be able to construct the URL. 
> 
> I also need `aRV` so I can set the exception in case the URL construction
> results in failure.
> 
> Any suggestions?

Probably you needn't construct an URL, because the URL::GetHref() comes from URI::GetSpec()

see https://searchfox.org/mozilla-central/source/dom/url/URL.cpp#148

I think the correct behavior is you need to create a new URI by the EventInitDict.mValidationURL, like this

  nsCOMPtr<nsIURI> validationUri;
  nsresult rv = NS_NewURI(getter_AddRefs(validationUri), aEventInitDict.mValidationURL, nullptr, nullptr,
                          nsContentUtils::GetIOService());

Then you can get the href by calling validationUri.GetSpec() what we done in 

https://searchfox.org/mozilla-central/source/dom/url/URL.cpp#138

  nsAutoCString utf8href;
  nsresult rv = validationUri->GetSpec(utf8href);
  if (NS_SUCCEEDED(rv)) {
    CopyUTF8toUTF16(utf8href, mValidationURL);
  }

all above code should be in MerchantValidationEvent::Init(const MerchantValidationEventInit& init);
But in current attached patch, the method is not declared, I expect to see it in the next patch.

So we have two MerchantValidationEvent::Constructor(), one has the GlobalObject parameters, and one has not.
These two constructors have different purposes. It is a little complicated, but basically we can think the one with GlobalObject is for calling from JS code which the event is generated by users code, and the other one is for C++ gecko code that means the event is generated by gecko internally. 

Usually, we reuse the implementation of the version which has no GlobalObject in the other one. PaymentRequestUpdateEvent is an good example.

https://searchfox.org/mozilla-central/source/dom/payments/PaymentRequestUpdateEvent.cpp#37

Now what we want to implement is dispatching the MerchantValidationEvent when gecko need, and that is PaymentRequest::DispatchMerchantValidationEvent().

In PaymentRequest::DispatchMerchantValidationEvent(), we have followings to do

1. Create MerchantValidationEventInit and set up it.
2. Create MerchantValidationEvent with the MerchantValidationEventInit in step 1.
3. Dispatch the event.

So in the step 1, we need set up the EventInit with a ValidationURL. How it comes?
It should come from the window object, it is the thing in the patch line 55 to 64.
Then in the step 2, we call the Constructor which has no GlobalObject one with the EventInit.

Hope the explain make you more clear about the implementation part.
Attached patch Addressed Eden's feedback. (obsolete) — Splinter Review
Baku, could you please check the Web IDL? 🙏
Attachment #9005114 - Attachment is obsolete: true
Attachment #9008007 - Flags: superreview?(amarchesini)
Attachment #9008007 - Flags: review?(echuang)
Comment on attachment 9008007 [details] [diff] [review]
Addressed Eden's feedback.

Review of attachment 9008007 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/payments/MerchantValidationEvent.cpp
@@ +64,5 @@
> +MerchantValidationEvent::init(const MerchantValidationEventInit& aEventInitDict,
> +                              ErrorResult& aRv)
> +{
> +  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetParentObject());
> +  auto principal = window->GetExtantDoc()->NodePrincipal();

GetExtantDoc can be null. Add a check.

@@ +93,5 @@
> +
> +MerchantValidationEvent::MerchantValidationEvent(EventTarget* aOwner)
> +  : Event(aOwner, nullptr, nullptr)
> +  , mWaitForUpdate(false)
> +  , mRequest(nullptr)

remove this line. It's not needed for smart pointers.

@@ +109,5 @@
> +  if (!mWaitForUpdate) {
> +    return;
> +  }
> +
> +  // TODO: If we eventually support merchant validation

Do we have a follow up for this TODO? Can you write the bug ID here?

@@ +113,5 @@
> +  // TODO: If we eventually support merchant validation
> +  // we would verify `aValue` here.
> +  mRequest->AbortUpdate(NS_ERROR_DOM_NOT_SUPPORTED_ERR, false);
> +
> +  mWaitForUpdate = false;

Move it immediately after if(!mWaitForUpdate)

@@ +124,5 @@
> +{
> +  MOZ_ASSERT(mRequest);
> +
> +  mRequest->AbortUpdate(NS_ERROR_DOM_ABORT_ERR, false);
> +  mWaitForUpdate = false;

same here.
Don't we want to check mWaitForUpdate here? Probably yes.

::: dom/webidl/MerchantValidationEvent.webidl
@@ +1,1 @@
> +[Constructor(DOMString type, optional MerchantValidationEventInit eventInitDict),

Add an header here. CopyRight + a URL of the spec.
Attachment #9008007 - Flags: superreview?(amarchesini)
Attachment #9008007 - Flags: superreview+
Attachment #9008007 - Flags: review?(echuang)
Attachment #9008007 - Flags: review+
Attached patch Addressed Baku's feedback... (obsolete) — Splinter Review
Attachment #9008007 - Attachment is obsolete: true
Attachment #9008038 - Flags: superreview+
Attachment #9008038 - Flags: review?(echuang)
Comment on attachment 9008038 [details] [diff] [review]
Addressed Baku's feedback...

Review of attachment 9008038 [details] [diff] [review]:
-----------------------------------------------------------------

Excellent. Nothing I can comment.
Attachment #9008038 - Flags: review?(echuang) → review+
Pushed by aiakab@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/ebe2c08a2454
Add support for onmerchantvalidation and MerchantValidationEvent. r=edenchuang,baku
Keywords: checkin-needed
:sheppy, when you get to this, I can write the details of how merchant validations works (and provide an example) - but would appreciate help with documenting the MerchantValidationEvent interface.
Flags: needinfo?(mcaceres)
I'm going to try assuming FAIL on Linux 32 for now. Talked to Eden and we will investigate what's happening later.
Attached patch Removed WPT stuff (obsolete) — Splinter Review
Talked to Eden about Linux 32 failures, and we are going to deal with that separately.
Attachment #9008038 - Attachment is obsolete: true
Attachment #9008629 - Flags: review+
Attached patch Convert to hg patch. (obsolete) — Splinter Review
Attachment #9008629 - Attachment is obsolete: true
Attachment #9008631 - Flags: review+
Attached patch fixupSplinter Review
Attachment #9008631 - Attachment is obsolete: true
Attachment #9008632 - Flags: review+
Blocks: 1490599
Keywords: checkin-needed
Pushed by apavel@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/72f155506bf6
Add support for onmerchantvalidation and MerchantValidationEvent. r=edenchuang,baku
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/72f155506bf6
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Bug 1490599 - Implement MerchantValidationEvent.prototype.methodName attribute. r=baku
Attachment #9008983 - Attachment is obsolete: true
Ignore the Phabricator attachment, just me experimenting.
These are great, :sheppy! Thank you! I'm giving them a once over now.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: