dom/telephony/CallsList.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/telephony/CallsList.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "CallsList.h"
    1.11 +#include "mozilla/dom/CallsListBinding.h"
    1.12 +
    1.13 +#include "Telephony.h"
    1.14 +#include "TelephonyCall.h"
    1.15 +#include "TelephonyCallGroup.h"
    1.16 +
    1.17 +using namespace mozilla::dom;
    1.18 +
    1.19 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(CallsList,
    1.20 +                                        mTelephony,
    1.21 +                                        mGroup)
    1.22 +
    1.23 +NS_IMPL_CYCLE_COLLECTING_ADDREF(CallsList)
    1.24 +NS_IMPL_CYCLE_COLLECTING_RELEASE(CallsList)
    1.25 +
    1.26 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CallsList)
    1.27 +  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    1.28 +  NS_INTERFACE_MAP_ENTRY(nsISupports)
    1.29 +NS_INTERFACE_MAP_END
    1.30 +
    1.31 +CallsList::CallsList(Telephony* aTelephony, TelephonyCallGroup* aGroup)
    1.32 +: mTelephony(aTelephony), mGroup(aGroup)
    1.33 +{
    1.34 +  MOZ_ASSERT(mTelephony);
    1.35 +
    1.36 +  SetIsDOMBinding();
    1.37 +}
    1.38 +
    1.39 +CallsList::~CallsList()
    1.40 +{
    1.41 +}
    1.42 +
    1.43 +nsPIDOMWindow*
    1.44 +CallsList::GetParentObject() const
    1.45 +{
    1.46 +  return mTelephony->GetOwner();
    1.47 +}
    1.48 +
    1.49 +JSObject*
    1.50 +CallsList::WrapObject(JSContext* aCx)
    1.51 +{
    1.52 +  return CallsListBinding::Wrap(aCx, this);
    1.53 +}
    1.54 +
    1.55 +already_AddRefed<TelephonyCall>
    1.56 +CallsList::Item(uint32_t aIndex) const
    1.57 +{
    1.58 +  nsRefPtr<TelephonyCall> call;
    1.59 +  call = mGroup ? mGroup->CallsArray().SafeElementAt(aIndex) :
    1.60 +                  mTelephony->CallsArray().SafeElementAt(aIndex);
    1.61 +
    1.62 +  return call.forget();
    1.63 +}
    1.64 +
    1.65 +uint32_t
    1.66 +CallsList::Length() const
    1.67 +{
    1.68 +  return mGroup ? mGroup->CallsArray().Length() :
    1.69 +                  mTelephony->CallsArray().Length();
    1.70 +}
    1.71 +
    1.72 +already_AddRefed<TelephonyCall>
    1.73 +CallsList::IndexedGetter(uint32_t aIndex, bool& aFound) const
    1.74 +{
    1.75 +  nsRefPtr<TelephonyCall> call;
    1.76 +  call = mGroup ? mGroup->CallsArray().SafeElementAt(aIndex) :
    1.77 +                  mTelephony->CallsArray().SafeElementAt(aIndex);
    1.78 +  aFound = call ? true : false;
    1.79 +
    1.80 +  return call.forget();
    1.81 +}

mercurial