Bug 1468356 - Implement onpaymentmethodchange attribute. r=mrbkap
authorMarcos Cáceres <marcos@marcosc.com>
Sat, 30 Jun 2018 10:11:00 +0300
changeset 424596 5bad07995b937efcddf56ba99e7033d1e0422e46
parent 424591 da2d9d2b562e04ce033b371be0716208658a1808
child 424597 a5e810e1c07cc4c8f4b07b88566c6db113a0e37b
push id34219
push userccoroiu@mozilla.com
push dateMon, 02 Jul 2018 09:45:21 +0000
treeherdermozilla-central@9c02d2ecf220 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1468356
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1468356 - Implement onpaymentmethodchange attribute. r=mrbkap
dom/payments/PaymentMethodChangeEvent.cpp
dom/payments/PaymentMethodChangeEvent.h
dom/payments/PaymentRequest.h
dom/payments/PaymentRequestUpdateEvent.h
dom/payments/moz.build
dom/webidl/PaymentMethodChangeEvent.webidl
dom/webidl/PaymentRequest.webidl
dom/webidl/moz.build
xpcom/ds/nsGkAtomList.h
new file mode 100644
--- /dev/null
+++ b/dom/payments/PaymentMethodChangeEvent.cpp
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/dom/PaymentMethodChangeEvent.h"
+#include "mozilla/dom/PaymentRequestUpdateEvent.h"
+#include "mozilla/HoldDropJSObjects.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(PaymentMethodChangeEvent)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PaymentMethodChangeEvent,
+                                                PaymentRequestUpdateEvent)
+  tmp->mMethodDetails = nullptr;
+  mozilla::DropJSObjects(this);
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PaymentMethodChangeEvent,
+                                                  PaymentRequestUpdateEvent)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PaymentMethodChangeEvent,
+                                               PaymentRequestUpdateEvent)
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMethodDetails)
+NS_IMPL_CYCLE_COLLECTION_TRACE_END
+
+NS_IMPL_ADDREF_INHERITED(PaymentMethodChangeEvent, PaymentRequestUpdateEvent)
+NS_IMPL_RELEASE_INHERITED(PaymentMethodChangeEvent, PaymentRequestUpdateEvent)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PaymentMethodChangeEvent)
+NS_INTERFACE_MAP_END_INHERITING(PaymentRequestUpdateEvent)
+
+already_AddRefed<PaymentMethodChangeEvent>
+PaymentMethodChangeEvent::Constructor(
+  mozilla::dom::EventTarget* aOwner,
+  const nsAString& aType,
+  const PaymentMethodChangeEventInit& aEventInitDict)
+{
+  RefPtr<PaymentMethodChangeEvent> e = new PaymentMethodChangeEvent(aOwner);
+  bool trusted = e->Init(aOwner);
+  e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
+  e->SetTrusted(trusted);
+  e->SetComposed(aEventInitDict.mComposed);
+  e->init(aEventInitDict);
+  return e.forget();
+}
+
+already_AddRefed<PaymentMethodChangeEvent>
+PaymentMethodChangeEvent::Constructor(
+  const GlobalObject& aGlobal,
+  const nsAString& aType,
+  const PaymentMethodChangeEventInit& aEventInitDict,
+  ErrorResult& aRv)
+{
+  nsCOMPtr<mozilla::dom::EventTarget> owner =
+    do_QueryInterface(aGlobal.GetAsSupports());
+  return Constructor(owner, aType, aEventInitDict);
+}
+
+PaymentMethodChangeEvent::PaymentMethodChangeEvent(EventTarget* aOwner)
+  : PaymentRequestUpdateEvent(aOwner)
+{
+  MOZ_ASSERT(aOwner);
+  mozilla::HoldJSObjects(this);
+}
+
+void
+PaymentMethodChangeEvent::init(
+  const PaymentMethodChangeEventInit& aEventInitDict)
+{
+  mMethodName.Assign(aEventInitDict.mMethodName);
+  if (aEventInitDict.mMethodDetails.WasPassed()) {
+    mMethodDetails = aEventInitDict.mMethodDetails.Value();
+  }
+}
+
+void
+PaymentMethodChangeEvent::GetMethodName(nsAString& aMethodName)
+{
+  aMethodName.Assign(mMethodName);
+}
+
+void
+PaymentMethodChangeEvent::GetMethodDetails(JSContext* cx,
+                                           JS::MutableHandle<JSObject*> retval)
+{
+  retval.set(mMethodDetails.get());
+}
+
+PaymentMethodChangeEvent::~PaymentMethodChangeEvent()
+{
+  mozilla::DropJSObjects(this);
+}
+
+JSObject*
+PaymentMethodChangeEvent::WrapObjectInternal(JSContext* aCx,
+                                             JS::Handle<JSObject*> aGivenProto)
+{
+  return PaymentMethodChangeEvent_Binding::Wrap(aCx, this, aGivenProto);
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/payments/PaymentMethodChangeEvent.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_PaymentMethodChangeEvent_h
+#define mozilla_dom_PaymentMethodChangeEvent_h
+
+#include "mozilla/ErrorResult.h"
+#include "mozilla/dom/PaymentMethodChangeEventBinding.h"
+#include "mozilla/dom/PaymentRequestUpdateEvent.h"
+
+namespace mozilla {
+namespace dom {
+class PaymentRequestUpdateEvent;
+class PaymentMethodChangeEvent final : public PaymentRequestUpdateEvent
+{
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
+    PaymentMethodChangeEvent,
+    PaymentRequestUpdateEvent)
+
+  explicit PaymentMethodChangeEvent(EventTarget* aOwner);
+
+  virtual JSObject* WrapObjectInternal(
+    JSContext* aCx,
+    JS::Handle<JSObject*> aGivenProto) override;
+
+  static already_AddRefed<PaymentMethodChangeEvent> Constructor(
+    EventTarget* aOwner,
+    const nsAString& aType,
+    const PaymentMethodChangeEventInit& aEventInitDict);
+
+  // Called by WebIDL constructor
+  static already_AddRefed<PaymentMethodChangeEvent> Constructor(
+    const GlobalObject& aGlobal,
+    const nsAString& aType,
+    const PaymentMethodChangeEventInit& aEventInitDict,
+    ErrorResult& aRv);
+
+  void GetMethodName(nsAString& aMethodName);
+
+  void GetMethodDetails(JSContext* cx, JS::MutableHandle<JSObject*> retval);
+
+protected:
+  void init(const PaymentMethodChangeEventInit& aEventInitDict);
+  ~PaymentMethodChangeEvent();
+
+private:
+  JS::Heap<JSObject*> mMethodDetails;
+  nsString mMethodName;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_PaymentMethodChangeEvent_h
--- a/dom/payments/PaymentRequest.h
+++ b/dom/payments/PaymentRequest.h
@@ -150,16 +150,17 @@ public:
 
   void
   ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
   void
   RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
 
   IMPL_EVENT_HANDLER(shippingaddresschange);
   IMPL_EVENT_HANDLER(shippingoptionchange);
+  IMPL_EVENT_HANDLER(paymentmethodchange);
 
   void SetIPC(PaymentRequestChild* aChild)
   {
     mIPC = aChild;
   }
 
   PaymentRequestChild* GetIPC()
   {
--- a/dom/payments/PaymentRequestUpdateEvent.h
+++ b/dom/payments/PaymentRequestUpdateEvent.h
@@ -12,19 +12,19 @@
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/PaymentRequestUpdateEventBinding.h"
 #include "mozilla/dom/PromiseNativeHandler.h"
 
 namespace mozilla {
 namespace dom {
 
 class Promise;
-
-class PaymentRequestUpdateEvent final : public Event
-                                      , public PromiseNativeHandler
+class PaymentRequest;
+class PaymentRequestUpdateEvent : public Event
+                                , public PromiseNativeHandler
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PaymentRequestUpdateEvent, Event)
 
   explicit PaymentRequestUpdateEvent(EventTarget* aOwner);
 
   virtual JSObject*
--- a/dom/payments/moz.build
+++ b/dom/payments/moz.build
@@ -10,27 +10,29 @@ DIRS += [
 
 EXPORTS += [
     'PaymentRequestData.h',
     'PaymentRequestService.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'PaymentAddress.h',
+    'PaymentMethodChangeEvent.h',
     'PaymentRequest.h',
     'PaymentRequestManager.h',
     'PaymentRequestUpdateEvent.h',
     'PaymentResponse.h',
 ]
 
 UNIFIED_SOURCES += [
     'BasicCardPayment.cpp',
     'PaymentActionRequest.cpp',
     'PaymentActionResponse.cpp',
     'PaymentAddress.cpp',
+    'PaymentMethodChangeEvent.cpp',
     'PaymentRequest.cpp',
     'PaymentRequestData.cpp',
     'PaymentRequestManager.cpp',
     'PaymentRequestModule.cpp',
     'PaymentRequestService.cpp',
     'PaymentRequestUpdateEvent.cpp',
     'PaymentRequestUtils.cpp',
     'PaymentResponse.cpp',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/PaymentMethodChangeEvent.webidl
@@ -0,0 +1,13 @@
+[Constructor(DOMString type, optional PaymentMethodChangeEventInit eventInitDict),
+ SecureContext,
+ Exposed=Window,
+ Func="mozilla::dom::PaymentRequest::PrefEnabled"]
+interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent {
+    readonly attribute DOMString methodName;
+    readonly attribute object?   methodDetails;
+};
+
+dictionary PaymentMethodChangeEventInit : PaymentRequestUpdateEventInit {
+    required DOMString methodName;
+             object?   methodDetails;
+};
--- a/dom/webidl/PaymentRequest.webidl
+++ b/dom/webidl/PaymentRequest.webidl
@@ -103,9 +103,10 @@ interface PaymentRequest : EventTarget {
 
   readonly attribute DOMString            id;
   readonly attribute PaymentAddress?      shippingAddress;
   readonly attribute DOMString?           shippingOption;
   readonly attribute PaymentShippingType? shippingType;
 
            attribute EventHandler         onshippingaddresschange;
            attribute EventHandler         onshippingoptionchange;
+           attribute EventHandler         onpaymentmethodchange;
 };
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -693,16 +693,17 @@ WEBIDL_FILES = [
     'OscillatorNode.webidl',
     'PaintRequest.webidl',
     'PaintRequestList.webidl',
     'PaintWorkletGlobalScope.webidl',
     'PannerNode.webidl',
     'ParentNode.webidl',
     'ParentSHistory.webidl',
     'PaymentAddress.webidl',
+    'PaymentMethodChangeEvent.webidl',
     'PaymentRequest.webidl',
     'PaymentRequestUpdateEvent.webidl',
     'PaymentResponse.webidl',
     'Performance.webidl',
     'PerformanceEntry.webidl',
     'PerformanceMark.webidl',
     'PerformanceMeasure.webidl',
     'PerformanceNavigation.webidl',
--- a/xpcom/ds/nsGkAtomList.h
+++ b/xpcom/ds/nsGkAtomList.h
@@ -796,16 +796,17 @@ GK_ATOM(onobsolete, "onobsolete")
 GK_ATOM(ononline, "ononline")
 GK_ATOM(onoffline, "onoffline")
 GK_ATOM(onopen, "onopen")
 GK_ATOM(onorientationchange, "onorientationchange")
 GK_ATOM(onoverflow, "onoverflow")
 GK_ATOM(onpagehide, "onpagehide")
 GK_ATOM(onpageshow, "onpageshow")
 GK_ATOM(onpaste, "onpaste")
+GK_ATOM(onpaymentmethodchange, "onpaymentmethodchange")
 GK_ATOM(onpointerlockchange, "onpointerlockchange")
 GK_ATOM(onpointerlockerror, "onpointerlockerror")
 GK_ATOM(onpopuphidden, "onpopuphidden")
 GK_ATOM(onpopuphiding, "onpopuphiding")
 GK_ATOM(onpopuppositioned, "onpopuppositioned")
 GK_ATOM(onpopupshowing, "onpopupshowing")
 GK_ATOM(onpopupshown, "onpopupshown")
 GK_ATOM(onprocessorerror, "onprocessorerror")