2018-06-30 10:11:00 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2018-11-27 13:17:33 +03:00
|
|
|
#include "BasicCardPayment.h"
|
2018-06-30 10:11:00 +03:00
|
|
|
#include "mozilla/dom/PaymentMethodChangeEvent.h"
|
|
|
|
#include "mozilla/dom/PaymentRequestUpdateEvent.h"
|
2018-11-27 13:17:33 +03:00
|
|
|
#include "PaymentRequestUtils.h"
|
2018-06-30 10:11:00 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(PaymentMethodChangeEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PaymentMethodChangeEvent,
|
|
|
|
PaymentRequestUpdateEvent)
|
2018-11-28 03:28:36 +03:00
|
|
|
tmp->mMethodDetails = nullptr;
|
|
|
|
mozilla::DropJSObjects(this);
|
2018-06-30 10:11:00 +03:00
|
|
|
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)
|
2018-11-28 03:28:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMethodDetails)
|
2018-06-30 10:11:00 +03:00
|
|
|
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,
|
2018-11-27 13:17:33 +03:00
|
|
|
const PaymentRequestUpdateEventInit& aEventInitDict,
|
|
|
|
const nsAString& aMethodName, const ChangeDetails& aMethodDetails) {
|
2018-06-30 10:11:00 +03:00
|
|
|
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);
|
2018-11-27 13:17:33 +03:00
|
|
|
e->SetMethodName(aMethodName);
|
|
|
|
e->SetMethodDetails(aMethodDetails);
|
2018-06-30 10:11:00 +03:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<PaymentMethodChangeEvent>
|
|
|
|
PaymentMethodChangeEvent::Constructor(
|
|
|
|
const GlobalObject& aGlobal, const nsAString& aType,
|
2019-09-11 17:35:28 +03:00
|
|
|
const PaymentMethodChangeEventInit& aEventInitDict) {
|
2018-06-30 10:11:00 +03:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> owner =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
2018-11-27 13:17:33 +03:00
|
|
|
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();
|
2018-06-30 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PaymentMethodChangeEvent::PaymentMethodChangeEvent(EventTarget* aOwner)
|
|
|
|
: PaymentRequestUpdateEvent(aOwner) {
|
|
|
|
MOZ_ASSERT(aOwner);
|
2018-11-28 03:28:36 +03:00
|
|
|
mozilla::HoldJSObjects(this);
|
2018-06-30 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2018-11-27 13:17:33 +03:00
|
|
|
void PaymentMethodChangeEvent::init(
|
|
|
|
const PaymentMethodChangeEventInit& aEventInitDict) {
|
2018-06-30 10:11:00 +03:00
|
|
|
mMethodName.Assign(aEventInitDict.mMethodName);
|
2018-11-28 03:28:36 +03:00
|
|
|
mMethodDetails = aEventInitDict.mMethodDetails;
|
2018-06-30 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaymentMethodChangeEvent::GetMethodName(nsAString& aMethodName) {
|
|
|
|
aMethodName.Assign(mMethodName);
|
|
|
|
}
|
|
|
|
|
2018-11-27 13:17:33 +03:00
|
|
|
void PaymentMethodChangeEvent::SetMethodName(const nsAString& aMethodName) {
|
|
|
|
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());
|
2019-03-26 02:40:23 +03:00
|
|
|
basicCardDetails.mBillingAddress =
|
2018-11-27 13:17:33 +03:00
|
|
|
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;
|
2018-06-30 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PaymentMethodChangeEvent::~PaymentMethodChangeEvent() {
|
2018-11-28 03:28:36 +03:00
|
|
|
mozilla::DropJSObjects(this);
|
2018-06-30 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* PaymentMethodChangeEvent::WrapObjectInternal(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return PaymentMethodChangeEvent_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|