зеркало из https://github.com/mozilla/gecko-dev.git
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. --HG-- extra : histedit_source : 680bff71f0d8a9d9333a3699fcc6a4fd9630fe1b
This commit is contained in:
Родитель
7e0a887fad
Коммит
4dff78fca8
|
@ -292,6 +292,77 @@ interface nsIPaymentCompleteActionResponse : nsIPaymentActionResponse
|
|||
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 } }
|
||||
|
@ -322,4 +393,14 @@ interface nsIPaymentCompleteActionResponse : nsIPaymentActionResponse
|
|||
{ 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"
|
||||
%}
|
||||
|
|
|
@ -75,6 +75,7 @@ interface nsIPaymentOptions : nsISupports
|
|||
readonly attribute boolean requestPayerEmail;
|
||||
readonly attribute boolean requestPayerPhone;
|
||||
readonly attribute boolean requestShipping;
|
||||
readonly attribute boolean requestBillingAddress;
|
||||
readonly attribute AString shippingType;
|
||||
};
|
||||
|
||||
|
|
|
@ -389,5 +389,88 @@ PaymentCompleteActionResponse::IsCompleted(bool* aIsCompleted)
|
|||
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
|
||||
|
|
|
@ -149,6 +149,52 @@ private:
|
|||
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
|
||||
|
||||
|
|
|
@ -605,11 +605,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
@ -625,6 +627,7 @@ PaymentOptions::Create(const IPCPaymentOptions& aIPCOptions,
|
|||
aIPCOptions.requestPayerEmail(),
|
||||
aIPCOptions.requestPayerPhone(),
|
||||
aIPCOptions.requestShipping(),
|
||||
false, //aIPCOptions.requestBillingAddress(),
|
||||
aIPCOptions.shippingType());
|
||||
options.forget(aOptions);
|
||||
return NS_OK;
|
||||
|
@ -662,6 +665,14 @@ PaymentOptions::GetRequestShipping(bool* aRequestShipping)
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -176,6 +176,7 @@ private:
|
|||
const bool aRequestPayerEmail,
|
||||
const bool aRequestPayerPhone,
|
||||
const bool aRequestShipping,
|
||||
const bool aRequestBillingAddress,
|
||||
const nsAString& aShippintType);
|
||||
~PaymentOptions() = default;
|
||||
|
||||
|
@ -183,6 +184,7 @@ private:
|
|||
bool mRequestPayerEmail;
|
||||
bool mRequestPayerPhone;
|
||||
bool mRequestShipping;
|
||||
bool mRequestBillingAddress;
|
||||
nsString mShippingType;
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ 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;
|
||||
|
||||
|
@ -24,6 +26,8 @@ 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)
|
||||
|
@ -34,6 +38,8 @@ 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);
|
||||
|
||||
|
@ -44,6 +50,8 @@ static const mozilla::Module::CIDEntry kPaymentRequestCIDs[] = {
|
|||
{ &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 }
|
||||
|
@ -56,6 +64,8 @@ static const mozilla::Module::ContractIDEntry kPaymentRequestContracts[] = {
|
|||
{ 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 }
|
||||
|
@ -68,6 +78,8 @@ static const mozilla::Module::CategoryEntry kPaymentRequestCategories[] = {
|
|||
{ "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 }
|
||||
|
|
Загрузка…
Ссылка в новой задаче