dom/payments/PaymentMethodChangeEvent.cpp
author Narcis Beleuzu <nbeleuzu@mozilla.com>
Sun, 29 Jul 2018 03:55:23 +0300
changeset 483986 aaee68beff800bcf076d9c49b5c1f6531b135579
parent 479694 5bad07995b937efcddf56ba99e7033d1e0422e46
child 490412 f7d509458e63f9cc004ed8d7c702a23a9e752b1a
permissions -rw-r--r--
Backed out 2 changesets (bug 1463016, bug 1463291) for geckoview failures Backed out changeset fcfb99baa0f0 (bug 1463291) Backed out changeset 0d69b4fb1ed4 (bug 1463016)

/* -*- 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