Bug 1477117 - Part 1 - Create new XPCOM interface for changing the payment method. r=baku
authorEden Chuang <echuang@mozilla.com>
Tue, 27 Nov 2018 06:33:13 +0100
changeset 507837 4a5132e165d819305dfe96f42aa2f09aa47e124d
parent 507836 5e5174a6ca61076e60edb00fa4223818ecd0c2fc
child 507838 b3aea4b20b5360b16336a66863927a169f5fd025
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1477117
milestone65.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 1477117 - Part 1 - Create new XPCOM interface for changing the payment method. r=baku 1. Add a new attribute nsIPaymentOptions.requestBillingAddress. 2. Add new XPCOM interfaces MethodChangeDetails, GeneralChangeDetails and BasicCardMethodChangeDetails for passing the method change details from UI code.
dom/interfaces/payments/nsIPaymentActionResponse.idl
dom/interfaces/payments/nsIPaymentRequest.idl
dom/payments/PaymentActionResponse.cpp
dom/payments/PaymentActionResponse.h
dom/payments/PaymentRequestData.cpp
dom/payments/PaymentRequestData.h
dom/payments/PaymentRequestModule.cpp
--- a/dom/interfaces/payments/nsIPaymentActionResponse.idl
+++ b/dom/interfaces/payments/nsIPaymentActionResponse.idl
@@ -287,16 +287,87 @@ interface nsIPaymentCompleteActionRespon
             in uint32_t aCompleteStatus);
 
   /**
    *  Check if the complete action is succeeded.
    */
   bool isCompleted();
 };
 
+[builtinclass, scriptable, uuid(2035e0a9-c9ab-4c9f-b8e9-28b2ed61548c)]
+interface nsIMethodChangeDetails : nsISupports
+{
+  /**
+   *  The consts for representing the method change details data type.
+   *  GENERAL_DETAILS is the general purpose details data type. Except basic
+   *  card details, all details should belong to this type.
+   *  BASICCARD_DETAILS is a special details data type for basic card change
+   *  details.
+   */
+  const uint32_t GENERAL_DETAILS = 0;
+  const uint32_t BASICCARD_DETAILS = 1;
+
+  /**
+   *  The method change details data type.
+   *  Using the above defined consts(GENERAL_DETAILS or BASICCARD_DETAILS).
+   */
+  readonly attribute uint32_t type;
+
+  /**
+   *  The initial method.
+   *  @param aType - the method change details data type.
+   */
+  void init(in uint32_t aType);
+};
+
+/**
+ * The general purpose method change details.
+ */
+[builtinclass, scriptable, uuid(e031267e-bec8-4f3c-b0b1-396b77ca260c)]
+interface nsIGeneralChangeDetails : nsIMethodChangeDetails
+{
+  /**
+   *  The stringified change details.
+   */
+  readonly attribute AString details;
+
+  /**
+   *  The initial method for nsIGeneralChangeDetails.
+   *  @param aData - the javascript object of the content.
+   */
+  [implicit_jscontext]
+  void initData(in jsval aDetails);
+};
+
+/**
+ *  The basic card change details.
+ *  Since PaymentAddress is an no constructor interface type, UI code can not
+ *  easy create PaymentAddress by calling new PaymentAddress().
+ *  Unfortunately, BasicCardResponse has a PaymentAddress attribute, billingAddress
+ *  , it means UI can not create BsaicCardChangeDetails by calling the init() with a
+ *  given JSObject directly, because PaymentAddress creation in JS code is hard.
+ *  To let UI code can create BasicCardResponse easier, nsIBasicCardResponse is
+ *  provided for UI by passing the raw data of BasicCardResponse,
+ */
+[builtinclass, scriptable, uuid(5296f79e-15ea-40c3-8196-19cfa64d328c)]
+interface nsIBasicCardChangeDetails : nsIMethodChangeDetails
+{
+  /**
+   *  The billing address.
+   */
+  readonly attribute nsIPaymentAddress billingAddress;
+
+  /**
+   *  The initial method for nsIBasicCardChangeDetails.
+   *  @param aBillingAddreess  - the billing address.
+   */
+  void initData(in nsIPaymentAddress billingAddress);
+};
+
+
 %{C++
 #define NS_GENERAL_RESPONSE_DATA_CID \
   { 0xb986773e, 0x2b30, 0x4ed2, { 0xb8, 0xfe, 0x6a, 0x96, 0x63, 0x1c, 0x80, 0x00 } }
 #define NS_GENERAL_RESPONSE_DATA_CONTRACT_ID \
   "@mozilla.org/dom/payments/general-response-data;1"
 
 #define NS_BASICCARD_RESPONSE_DATA_CID \
   { 0x0d55a5e6, 0xd185, 0x44f0, { 0xb9, 0x92, 0xa8, 0xe1, 0x32, 0x1e, 0x4b, 0xce } }
@@ -317,9 +388,19 @@ interface nsIPaymentCompleteActionRespon
   { 0x8c72bcdb, 0x0c37, 0x4786, { 0xa9, 0xe5, 0x51, 0x0a, 0xfa, 0x2f, 0x8e, 0xde } }
 #define NS_PAYMENT_ABORT_ACTION_RESPONSE_CONTRACT_ID \
   "@mozilla.org/dom/payments/payment-abort-action-response;1"
 
 #define NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID \
   { 0x62c01e69, 0x9ca4, 0x4060, { 0x99, 0xe4, 0xb9, 0x5f, 0x62, 0x8c, 0x8e, 0x6d } }
 #define NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID \
   "@mozilla.org/dom/payments/payment-complete-action-response;1"
+
+#define NS_GENERAL_CHANGE_DETAILS_CID \
+  { 0xe031267e, 0xbec8, 0x4f3c, { 0xb0, 0xb1, 0x39, 0x6b, 0x77, 0xca, 0x26, 0x0c } }
+#define NS_GENERAL_CHANGE_DETAILS_CONTRACT_ID \
+  "@mozilla.org/dom/payments/general-change-details;1"
+
+#define NS_BASICCARD_CHANGE_DETAILS_CID \
+  { 0x5296f79e, 0x15ea, 0x40c3, { 0x81, 0x96, 0x19, 0xcf, 0xa6, 0x4d, 0x32, 0x8c } }
+#define NS_BASICCARD_CHANGE_DETAILS_CONTRACT_ID \
+  "@mozilla.org/dom/payments/basiccard-change-details;1"
 %}
--- a/dom/interfaces/payments/nsIPaymentRequest.idl
+++ b/dom/interfaces/payments/nsIPaymentRequest.idl
@@ -70,16 +70,17 @@ interface nsIPaymentDetails : nsISupport
 
 [scriptable, builtinclass, uuid(d53f9f20-138e-47cc-9fd5-db16a3f6d301)]
 interface nsIPaymentOptions : nsISupports
 {
   readonly attribute boolean requestPayerName;
   readonly attribute boolean requestPayerEmail;
   readonly attribute boolean requestPayerPhone;
   readonly attribute boolean requestShipping;
+  readonly attribute boolean requestBillingAddress;
   readonly attribute AString shippingType;
 };
 
 [scriptable, builtinclass, uuid(2fa36783-d684-4487-b7a8-9def6ae3128f)]
 interface nsIPaymentRequest : nsISupports
 {
   readonly attribute uint64_t topOuterWindowId;
   readonly attribute nsIPrincipal topLevelPrincipal;
--- a/dom/payments/PaymentActionResponse.cpp
+++ b/dom/payments/PaymentActionResponse.cpp
@@ -384,10 +384,93 @@ PaymentCompleteActionResponse::GetComple
 nsresult
 PaymentCompleteActionResponse::IsCompleted(bool* aIsCompleted)
 {
   NS_ENSURE_ARG_POINTER(aIsCompleted);
   *aIsCompleted = (mCompleteStatus == nsIPaymentActionResponse::COMPLETE_SUCCEEDED);
   return NS_OK;
 }
 
+/* PaymentChangeDetails */
+
+NS_IMPL_ISUPPORTS(MethodChangeDetails, nsIMethodChangeDetails)
+
+NS_IMETHODIMP
+MethodChangeDetails::GetType(uint32_t* aType)
+{
+  NS_ENSURE_ARG_POINTER(aType);
+  *aType = mType;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+MethodChangeDetails::Init(const uint32_t aType)
+{
+  if (aType != nsIMethodChangeDetails::GENERAL_DETAILS &&
+      aType != nsIMethodChangeDetails::BASICCARD_DETAILS) {
+    return NS_ERROR_FAILURE;
+  }
+  mType = aType;
+  return NS_OK;
+}
+
+/* GeneralMethodChangeDetails */
+
+NS_IMPL_ISUPPORTS_INHERITED(GeneralMethodChangeDetails,
+                            MethodChangeDetails,
+                            nsIGeneralChangeDetails)
+
+GeneralMethodChangeDetails::GeneralMethodChangeDetails()
+  : mDetails(NS_LITERAL_STRING("{}"))
+{
+  Init(nsIMethodChangeDetails::GENERAL_DETAILS);
+}
+
+NS_IMETHODIMP
+GeneralMethodChangeDetails::GetDetails(nsAString& aDetails)
+{
+  aDetails = mDetails;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+GeneralMethodChangeDetails::InitData(JS::HandleValue aDetails, JSContext* aCx)
+{
+  if (aDetails.isNullOrUndefined()) {
+    return NS_ERROR_FAILURE;
+  }
+  nsresult rv = SerializeFromJSVal(aCx, aDetails, mDetails);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+  return NS_OK;
+}
+
+/* BasicCardMethodChangeDetails */
+
+NS_IMPL_ISUPPORTS_INHERITED(BasicCardMethodChangeDetails,
+                            MethodChangeDetails,
+                            nsIBasicCardChangeDetails)
+
+BasicCardMethodChangeDetails::BasicCardMethodChangeDetails()
+{
+  Init(nsIMethodChangeDetails::BASICCARD_DETAILS);
+}
+
+NS_IMETHODIMP
+BasicCardMethodChangeDetails::GetBillingAddress(nsIPaymentAddress** aBillingAddress)
+{
+  NS_ENSURE_ARG_POINTER(aBillingAddress);
+  nsCOMPtr<nsIPaymentAddress> address;
+  address = mBillingAddress;
+  address.forget(aBillingAddress);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+BasicCardMethodChangeDetails::InitData(nsIPaymentAddress* aBillingAddress)
+{
+  mBillingAddress = aBillingAddress;
+  return NS_OK;
+}
+
 } // end of namespace dom
 } // end of namespace mozilla
--- a/dom/payments/PaymentActionResponse.h
+++ b/dom/payments/PaymentActionResponse.h
@@ -144,12 +144,58 @@ public:
   PaymentCompleteActionResponse();
 
 private:
   ~PaymentCompleteActionResponse() = default;
 
   uint32_t mCompleteStatus;
 };
 
+class MethodChangeDetails : public nsIMethodChangeDetails
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIMETHODCHANGEDETAILS
+
+  MethodChangeDetails() = default;
+
+protected:
+  virtual ~MethodChangeDetails() = default;
+
+  uint32_t mType;
+};
+
+class GeneralMethodChangeDetails final : public MethodChangeDetails
+                                       , public nsIGeneralChangeDetails
+{
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_FORWARD_NSIMETHODCHANGEDETAILS(MethodChangeDetails::)
+  NS_DECL_NSIGENERALCHANGEDETAILS
+
+  GeneralMethodChangeDetails();
+
+private:
+  ~GeneralMethodChangeDetails() = default;
+
+  nsString mDetails;
+};
+
+class BasicCardMethodChangeDetails final : public MethodChangeDetails
+                                         , public nsIBasicCardChangeDetails
+{
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_FORWARD_NSIMETHODCHANGEDETAILS(MethodChangeDetails::)
+  NS_DECL_NSIBASICCARDCHANGEDETAILS
+
+  BasicCardMethodChangeDetails();
+
+private:
+  ~BasicCardMethodChangeDetails() = default;
+
+  nsCOMPtr<nsIPaymentAddress> mBillingAddress;
+};
+
 } // end of dom
 } // end of namespace mozilla
 
 #endif
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -600,36 +600,39 @@ PaymentDetails::UpdateErrors(const nsASt
 
 NS_IMPL_ISUPPORTS(PaymentOptions,
                   nsIPaymentOptions)
 
 PaymentOptions::PaymentOptions(const bool aRequestPayerName,
                                const bool aRequestPayerEmail,
                                const bool aRequestPayerPhone,
                                const bool aRequestShipping,
+                               const bool aRequestBillingAddress,
                                const nsAString& aShippingType)
   : mRequestPayerName(aRequestPayerName)
   , mRequestPayerEmail(aRequestPayerEmail)
   , mRequestPayerPhone(aRequestPayerPhone)
   , mRequestShipping(aRequestShipping)
+  , mRequestBillingAddress(aRequestBillingAddress)
   , mShippingType(aShippingType)
 {
 }
 
 nsresult
 PaymentOptions::Create(const IPCPaymentOptions& aIPCOptions,
                        nsIPaymentOptions** aOptions)
 {
   NS_ENSURE_ARG_POINTER(aOptions);
 
   nsCOMPtr<nsIPaymentOptions> options =
     new PaymentOptions(aIPCOptions.requestPayerName(),
                        aIPCOptions.requestPayerEmail(),
                        aIPCOptions.requestPayerPhone(),
                        aIPCOptions.requestShipping(),
+                       false, //aIPCOptions.requestBillingAddress(),
                        aIPCOptions.shippingType());
   options.forget(aOptions);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PaymentOptions::GetRequestPayerName(bool* aRequestPayerName)
 {
@@ -658,16 +661,24 @@ NS_IMETHODIMP
 PaymentOptions::GetRequestShipping(bool* aRequestShipping)
 {
   NS_ENSURE_ARG_POINTER(aRequestShipping);
   *aRequestShipping = mRequestShipping;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+PaymentOptions::GetRequestBillingAddress(bool* aRequestBillingAddress)
+{
+  NS_ENSURE_ARG_POINTER(aRequestBillingAddress);
+  *aRequestBillingAddress = mRequestBillingAddress;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 PaymentOptions::GetShippingType(nsAString& aShippingType)
 {
   aShippingType = mShippingType;
   return NS_OK;
 }
 
 /* PaymentReqeust */
 
--- a/dom/payments/PaymentRequestData.h
+++ b/dom/payments/PaymentRequestData.h
@@ -171,23 +171,25 @@ public:
   static nsresult Create(const IPCPaymentOptions& aIPCOptions,
                          nsIPaymentOptions** aOptions);
 
 private:
   PaymentOptions(const bool aRequestPayerName,
                  const bool aRequestPayerEmail,
                  const bool aRequestPayerPhone,
                  const bool aRequestShipping,
+                 const bool aRequestBillingAddress,
                  const nsAString& aShippintType);
   ~PaymentOptions() = default;
 
   bool mRequestPayerName;
   bool mRequestPayerEmail;
   bool mRequestPayerPhone;
   bool mRequestShipping;
+  bool mRequestBillingAddress;
   nsString mShippingType;
 };
 
 class PaymentRequest final : public nsIPaymentRequest
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPAYMENTREQUEST
--- a/dom/payments/PaymentRequestModule.cpp
+++ b/dom/payments/PaymentRequestModule.cpp
@@ -10,69 +10,81 @@
 #include "PaymentRequestService.h"
 
 using mozilla::dom::GeneralResponseData;
 using mozilla::dom::BasicCardResponseData;
 using mozilla::dom::PaymentCanMakeActionResponse;
 using mozilla::dom::PaymentAbortActionResponse;
 using mozilla::dom::PaymentShowActionResponse;
 using mozilla::dom::PaymentCompleteActionResponse;
+using mozilla::dom::GeneralMethodChangeDetails;
+using mozilla::dom::BasicCardMethodChangeDetails;
 using mozilla::dom::payments::PaymentAddress;
 using mozilla::dom::PaymentRequestService;
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(GeneralResponseData)
 NS_GENERIC_FACTORY_CONSTRUCTOR(BasicCardResponseData)
 NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentCanMakeActionResponse)
 NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentAbortActionResponse)
 NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentShowActionResponse)
 NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentCompleteActionResponse)
+NS_GENERIC_FACTORY_CONSTRUCTOR(GeneralMethodChangeDetails)
+NS_GENERIC_FACTORY_CONSTRUCTOR(BasicCardMethodChangeDetails)
 NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentAddress)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(PaymentRequestService,
                                          PaymentRequestService::GetSingleton)
 
 NS_DEFINE_NAMED_CID(NS_GENERAL_RESPONSE_DATA_CID);
 NS_DEFINE_NAMED_CID(NS_BASICCARD_RESPONSE_DATA_CID);
 NS_DEFINE_NAMED_CID(NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CID);
 NS_DEFINE_NAMED_CID(NS_PAYMENT_ABORT_ACTION_RESPONSE_CID);
 NS_DEFINE_NAMED_CID(NS_PAYMENT_SHOW_ACTION_RESPONSE_CID);
 NS_DEFINE_NAMED_CID(NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID);
+NS_DEFINE_NAMED_CID(NS_GENERAL_CHANGE_DETAILS_CID);
+NS_DEFINE_NAMED_CID(NS_BASICCARD_CHANGE_DETAILS_CID);
 NS_DEFINE_NAMED_CID(NS_PAYMENT_ADDRESS_CID);
 NS_DEFINE_NAMED_CID(NS_PAYMENT_REQUEST_SERVICE_CID);
 
 static const mozilla::Module::CIDEntry kPaymentRequestCIDs[] = {
   { &kNS_GENERAL_RESPONSE_DATA_CID, false, nullptr, GeneralResponseDataConstructor},
   { &kNS_BASICCARD_RESPONSE_DATA_CID, false, nullptr, BasicCardResponseDataConstructor},
   { &kNS_PAYMENT_CANMAKE_ACTION_RESPONSE_CID, false, nullptr, PaymentCanMakeActionResponseConstructor},
   { &kNS_PAYMENT_ABORT_ACTION_RESPONSE_CID, false, nullptr, PaymentAbortActionResponseConstructor},
   { &kNS_PAYMENT_SHOW_ACTION_RESPONSE_CID, false, nullptr, PaymentShowActionResponseConstructor},
   { &kNS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID, false, nullptr, PaymentCompleteActionResponseConstructor},
+  { &kNS_GENERAL_CHANGE_DETAILS_CID, false, nullptr, GeneralMethodChangeDetailsConstructor},
+  { &kNS_BASICCARD_CHANGE_DETAILS_CID, false, nullptr, BasicCardMethodChangeDetailsConstructor},
   { &kNS_PAYMENT_ADDRESS_CID, false, nullptr, PaymentAddressConstructor},
   { &kNS_PAYMENT_REQUEST_SERVICE_CID, true, nullptr, PaymentRequestServiceConstructor },
   { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kPaymentRequestContracts[] = {
   { NS_GENERAL_RESPONSE_DATA_CONTRACT_ID, &kNS_GENERAL_RESPONSE_DATA_CID },
   { NS_BASICCARD_RESPONSE_DATA_CONTRACT_ID, &kNS_BASICCARD_RESPONSE_DATA_CID },
   { NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_CANMAKE_ACTION_RESPONSE_CID },
   { NS_PAYMENT_ABORT_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_ABORT_ACTION_RESPONSE_CID },
   { NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_SHOW_ACTION_RESPONSE_CID },
   { NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID },
+  { NS_GENERAL_CHANGE_DETAILS_CONTRACT_ID, &kNS_GENERAL_CHANGE_DETAILS_CID },
+  { NS_BASICCARD_CHANGE_DETAILS_CONTRACT_ID, &kNS_BASICCARD_CHANGE_DETAILS_CID },
   { NS_PAYMENT_ADDRESS_CONTRACT_ID, &kNS_PAYMENT_ADDRESS_CID },
   { NS_PAYMENT_REQUEST_SERVICE_CONTRACT_ID, &kNS_PAYMENT_REQUEST_SERVICE_CID },
   { nullptr }
 };
 
 static const mozilla::Module::CategoryEntry kPaymentRequestCategories[] = {
   { "payment-request", "GeneralResponseData", NS_GENERAL_RESPONSE_DATA_CONTRACT_ID },
   { "payment-request", "BasicCardResponseData", NS_BASICCARD_RESPONSE_DATA_CONTRACT_ID },
   { "payment-request", "PaymentCanMakeActionResponse", NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CONTRACT_ID },
   { "payment-request", "PaymentAbortActionResponse", NS_PAYMENT_ABORT_ACTION_RESPONSE_CONTRACT_ID },
   { "payment-request", "PaymentShowActionResponse", NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID },
   { "payment-request", "PaymentCompleteActionResponse", NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID },
+  { "payment-request", "GeneralMethodChangeDetails", NS_GENERAL_CHANGE_DETAILS_CONTRACT_ID },
+  { "payment-request", "BasicCardMethodChangeDetails", NS_BASICCARD_CHANGE_DETAILS_CONTRACT_ID },
   { "payment-request", "PaymentAddress", NS_PAYMENT_ADDRESS_CONTRACT_ID },
   { "payment-request", "PaymentRequestService", NS_PAYMENT_REQUEST_SERVICE_CONTRACT_ID },
   { nullptr }
 };
 
 static const mozilla::Module kPaymentRequestModule = {
   mozilla::Module::kVersion,
   kPaymentRequestCIDs,