зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1477117 - Part 3 - dispatch the PaymentMethodChangeEvent. r=baku
Save the changing method information in PaymentMethodChangeEvent and dispatch it. --HG-- extra : histedit_source : 583cc4efd19d22d21864527db9bb479f772839e4
This commit is contained in:
Родитель
931859451b
Коммит
f39987d3cc
|
@ -4,9 +4,10 @@
|
|||
* 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 "BasicCardPayment.h"
|
||||
#include "mozilla/dom/PaymentMethodChangeEvent.h"
|
||||
#include "mozilla/dom/PaymentRequestUpdateEvent.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "PaymentRequestUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -37,14 +38,17 @@ already_AddRefed<PaymentMethodChangeEvent>
|
|||
PaymentMethodChangeEvent::Constructor(
|
||||
mozilla::dom::EventTarget* aOwner,
|
||||
const nsAString& aType,
|
||||
const PaymentMethodChangeEventInit& aEventInitDict)
|
||||
const PaymentRequestUpdateEventInit& aEventInitDict,
|
||||
const nsAString& aMethodName,
|
||||
const ChangeDetails& aMethodDetails)
|
||||
{
|
||||
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);
|
||||
e->SetMethodName(aMethodName);
|
||||
e->SetMethodDetails(aMethodDetails);
|
||||
return e.forget();
|
||||
}
|
||||
|
||||
|
@ -57,7 +61,13 @@ PaymentMethodChangeEvent::Constructor(
|
|||
{
|
||||
nsCOMPtr<mozilla::dom::EventTarget> owner =
|
||||
do_QueryInterface(aGlobal.GetAsSupports());
|
||||
return Constructor(owner, aType, aEventInitDict);
|
||||
RefPtr<PaymentMethodChangeEvent> e = new PaymentMethodChangeEvent(owner);
|
||||
bool trusted = e->Init(owner);
|
||||
e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
|
||||
e->SetTrusted(trusted);
|
||||
e->SetComposed(aEventInitDict.mComposed);
|
||||
e->init(aEventInitDict);
|
||||
return e.forget();
|
||||
}
|
||||
|
||||
PaymentMethodChangeEvent::PaymentMethodChangeEvent(EventTarget* aOwner)
|
||||
|
@ -68,8 +78,7 @@ PaymentMethodChangeEvent::PaymentMethodChangeEvent(EventTarget* aOwner)
|
|||
}
|
||||
|
||||
void
|
||||
PaymentMethodChangeEvent::init(
|
||||
const PaymentMethodChangeEventInit& aEventInitDict)
|
||||
PaymentMethodChangeEvent::init(const PaymentMethodChangeEventInit& aEventInitDict)
|
||||
{
|
||||
mMethodName.Assign(aEventInitDict.mMethodName);
|
||||
mMethodDetails = aEventInitDict.mMethodDetails;
|
||||
|
@ -82,10 +91,83 @@ PaymentMethodChangeEvent::GetMethodName(nsAString& aMethodName)
|
|||
}
|
||||
|
||||
void
|
||||
PaymentMethodChangeEvent::GetMethodDetails(JSContext* cx,
|
||||
JS::MutableHandle<JSObject*> retval)
|
||||
PaymentMethodChangeEvent::SetMethodName(const nsAString& aMethodName)
|
||||
{
|
||||
retval.set(mMethodDetails.get());
|
||||
mMethodName = aMethodName;
|
||||
}
|
||||
|
||||
void
|
||||
PaymentMethodChangeEvent::GetMethodDetails(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetVal)
|
||||
{
|
||||
MOZ_ASSERT(aCx);
|
||||
|
||||
if (mMethodDetails) {
|
||||
aRetVal.set(mMethodDetails.get());
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<BasicCardService> service = BasicCardService::GetService();
|
||||
MOZ_ASSERT(service);
|
||||
aRetVal.set(nullptr);
|
||||
switch(mInternalDetails.type()) {
|
||||
case ChangeDetails::GeneralMethodDetails: {
|
||||
const GeneralDetails& rawDetails = mInternalDetails.generalDetails();
|
||||
DeserializeToJSObject(rawDetails.details, aCx, aRetVal);
|
||||
break;
|
||||
}
|
||||
case ChangeDetails::BasicCardMethodDetails: {
|
||||
const BasicCardDetails& rawDetails = mInternalDetails.basicCardDetails();
|
||||
BasicCardChangeDetails basicCardDetails;
|
||||
PaymentOptions options;
|
||||
mRequest->GetOptions(options);
|
||||
if (options.mRequestBillingAddress) {
|
||||
if (!rawDetails.billingAddress.country.IsEmpty() ||
|
||||
!rawDetails.billingAddress.addressLine.IsEmpty() ||
|
||||
!rawDetails.billingAddress.region.IsEmpty() ||
|
||||
!rawDetails.billingAddress.regionCode.IsEmpty() ||
|
||||
!rawDetails.billingAddress.city.IsEmpty() ||
|
||||
!rawDetails.billingAddress.dependentLocality.IsEmpty() ||
|
||||
!rawDetails.billingAddress.postalCode.IsEmpty() ||
|
||||
!rawDetails.billingAddress.sortingCode.IsEmpty() ||
|
||||
!rawDetails.billingAddress.organization.IsEmpty() ||
|
||||
!rawDetails.billingAddress.recipient.IsEmpty() ||
|
||||
!rawDetails.billingAddress.phone.IsEmpty()) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetParentObject());
|
||||
basicCardDetails.mBillingAddress.Construct();
|
||||
basicCardDetails.mBillingAddress.Value() =
|
||||
new PaymentAddress(window,
|
||||
rawDetails.billingAddress.country,
|
||||
rawDetails.billingAddress.addressLine,
|
||||
rawDetails.billingAddress.region,
|
||||
rawDetails.billingAddress.regionCode,
|
||||
rawDetails.billingAddress.city,
|
||||
rawDetails.billingAddress.dependentLocality,
|
||||
rawDetails.billingAddress.postalCode,
|
||||
rawDetails.billingAddress.sortingCode,
|
||||
rawDetails.billingAddress.organization,
|
||||
rawDetails.billingAddress.recipient,
|
||||
rawDetails.billingAddress.phone);
|
||||
}
|
||||
}
|
||||
MOZ_ASSERT(aCx);
|
||||
JS::RootedValue value(aCx);
|
||||
if (NS_WARN_IF(!basicCardDetails.ToObjectInternal(aCx, &value))) {
|
||||
return;
|
||||
}
|
||||
aRetVal.set(&value.toObject());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PaymentMethodChangeEvent::SetMethodDetails(const ChangeDetails& aMethodDetails)
|
||||
{
|
||||
mInternalDetails = aMethodDetails;
|
||||
}
|
||||
|
||||
PaymentMethodChangeEvent::~PaymentMethodChangeEvent()
|
||||
|
|
|
@ -32,7 +32,9 @@ public:
|
|||
static already_AddRefed<PaymentMethodChangeEvent> Constructor(
|
||||
EventTarget* aOwner,
|
||||
const nsAString& aType,
|
||||
const PaymentMethodChangeEventInit& aEventInitDict);
|
||||
const PaymentRequestUpdateEventInit& aEventInitDict,
|
||||
const nsAString& aMethodName,
|
||||
const ChangeDetails& aMethodDetails);
|
||||
|
||||
// Called by WebIDL constructor
|
||||
static already_AddRefed<PaymentMethodChangeEvent> Constructor(
|
||||
|
@ -42,8 +44,10 @@ public:
|
|||
ErrorResult& aRv);
|
||||
|
||||
void GetMethodName(nsAString& aMethodName);
|
||||
void SetMethodName(const nsAString& aMethodName);
|
||||
|
||||
void GetMethodDetails(JSContext* cx, JS::MutableHandle<JSObject*> retval);
|
||||
void SetMethodDetails(const ChangeDetails& aMethodDetails);
|
||||
|
||||
protected:
|
||||
void init(const PaymentMethodChangeEventInit& aEventInitDict);
|
||||
|
@ -51,6 +55,7 @@ protected:
|
|||
|
||||
private:
|
||||
JS::Heap<JSObject*> mMethodDetails;
|
||||
ChangeDetails mInternalDetails;
|
||||
nsString mMethodName;
|
||||
};
|
||||
|
||||
|
|
|
@ -1047,8 +1047,23 @@ PaymentRequest::DispatchPaymentMethodChangeEvent(const nsAString& aMethodName,
|
|||
const ChangeDetails& aMethodDetails)
|
||||
{
|
||||
MOZ_ASSERT(ReadyForUpdate());
|
||||
// TODO: create and dispatch a PaymentMethodChangeEvent
|
||||
return NS_OK;
|
||||
|
||||
PaymentRequestUpdateEventInit init;
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
|
||||
RefPtr<PaymentMethodChangeEvent> event =
|
||||
PaymentMethodChangeEvent::Constructor(this,
|
||||
NS_LITERAL_STRING("paymentmethodchange"),
|
||||
init,
|
||||
aMethodName,
|
||||
aMethodDetails);
|
||||
event->SetTrusted(true);
|
||||
event->SetRequest(this);
|
||||
|
||||
ErrorResult rv;
|
||||
DispatchEvent(*event, rv);
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
already_AddRefed<PaymentAddress>
|
||||
|
|
|
@ -54,8 +54,6 @@ public:
|
|||
|
||||
protected:
|
||||
~PaymentRequestUpdateEvent();
|
||||
|
||||
private:
|
||||
// Indicating whether an updateWith()-initiated update is currently in progress.
|
||||
bool mWaitForUpdate;
|
||||
RefPtr<PaymentRequest> mRequest;
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
mBasicCardData = aBasicCardData;
|
||||
return *this;
|
||||
}
|
||||
virtual ~ResponseData() = default;
|
||||
~ResponseData() = default;
|
||||
|
||||
const Type& type() const { return mType; }
|
||||
const GeneralData& generalData() const { return mGeneralData; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче