michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "CallsList.h" michael@0: #include "mozilla/dom/CallsListBinding.h" michael@0: michael@0: #include "Telephony.h" michael@0: #include "TelephonyCall.h" michael@0: #include "TelephonyCallGroup.h" michael@0: michael@0: using namespace mozilla::dom; michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(CallsList, michael@0: mTelephony, michael@0: mGroup) michael@0: michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(CallsList) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(CallsList) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CallsList) michael@0: NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY michael@0: NS_INTERFACE_MAP_ENTRY(nsISupports) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: CallsList::CallsList(Telephony* aTelephony, TelephonyCallGroup* aGroup) michael@0: : mTelephony(aTelephony), mGroup(aGroup) michael@0: { michael@0: MOZ_ASSERT(mTelephony); michael@0: michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: CallsList::~CallsList() michael@0: { michael@0: } michael@0: michael@0: nsPIDOMWindow* michael@0: CallsList::GetParentObject() const michael@0: { michael@0: return mTelephony->GetOwner(); michael@0: } michael@0: michael@0: JSObject* michael@0: CallsList::WrapObject(JSContext* aCx) michael@0: { michael@0: return CallsListBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: already_AddRefed michael@0: CallsList::Item(uint32_t aIndex) const michael@0: { michael@0: nsRefPtr call; michael@0: call = mGroup ? mGroup->CallsArray().SafeElementAt(aIndex) : michael@0: mTelephony->CallsArray().SafeElementAt(aIndex); michael@0: michael@0: return call.forget(); michael@0: } michael@0: michael@0: uint32_t michael@0: CallsList::Length() const michael@0: { michael@0: return mGroup ? mGroup->CallsArray().Length() : michael@0: mTelephony->CallsArray().Length(); michael@0: } michael@0: michael@0: already_AddRefed michael@0: CallsList::IndexedGetter(uint32_t aIndex, bool& aFound) const michael@0: { michael@0: nsRefPtr call; michael@0: call = mGroup ? mGroup->CallsArray().SafeElementAt(aIndex) : michael@0: mTelephony->CallsArray().SafeElementAt(aIndex); michael@0: aFound = call ? true : false; michael@0: michael@0: return call.forget(); michael@0: }