Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "MobileConnectionArray.h" |
michael@0 | 8 | #include "mozilla/dom/MozMobileConnectionArrayBinding.h" |
michael@0 | 9 | #include "mozilla/Preferences.h" |
michael@0 | 10 | |
michael@0 | 11 | using namespace mozilla::dom; |
michael@0 | 12 | |
michael@0 | 13 | NS_IMPL_CYCLE_COLLECTION_CLASS(MobileConnectionArray) |
michael@0 | 14 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MobileConnectionArray) |
michael@0 | 15 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow) |
michael@0 | 16 | // Notify our mobile connections that we're going away. |
michael@0 | 17 | tmp->DropConnections(); |
michael@0 | 18 | NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER |
michael@0 | 19 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
michael@0 | 20 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MobileConnectionArray) |
michael@0 | 21 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow) |
michael@0 | 22 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections) |
michael@0 | 23 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS |
michael@0 | 24 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
michael@0 | 25 | NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(MobileConnectionArray) |
michael@0 | 26 | |
michael@0 | 27 | NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileConnectionArray) |
michael@0 | 28 | NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileConnectionArray) |
michael@0 | 29 | |
michael@0 | 30 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileConnectionArray) |
michael@0 | 31 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
michael@0 | 32 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 33 | NS_INTERFACE_MAP_END |
michael@0 | 34 | |
michael@0 | 35 | MobileConnectionArray::MobileConnectionArray(nsPIDOMWindow* aWindow) |
michael@0 | 36 | : mWindow(aWindow), mInitialized(false) |
michael@0 | 37 | { |
michael@0 | 38 | uint32_t numRil = mozilla::Preferences::GetUint("ril.numRadioInterfaces", 1); |
michael@0 | 39 | MOZ_ASSERT(numRil > 0); |
michael@0 | 40 | |
michael@0 | 41 | mMobileConnections.SetLength(numRil); |
michael@0 | 42 | |
michael@0 | 43 | SetIsDOMBinding(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | MobileConnectionArray::~MobileConnectionArray() |
michael@0 | 47 | { |
michael@0 | 48 | DropConnections(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | void |
michael@0 | 52 | MobileConnectionArray::Init() |
michael@0 | 53 | { |
michael@0 | 54 | mInitialized = true; |
michael@0 | 55 | |
michael@0 | 56 | for (uint32_t id = 0; id < mMobileConnections.Length(); id++) { |
michael@0 | 57 | nsRefPtr<MobileConnection> mobileConnection = new MobileConnection(id); |
michael@0 | 58 | mobileConnection->Init(mWindow); |
michael@0 | 59 | mMobileConnections[id] = mobileConnection; |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void |
michael@0 | 64 | MobileConnectionArray::DropConnections() |
michael@0 | 65 | { |
michael@0 | 66 | if (mInitialized) { |
michael@0 | 67 | for (uint32_t i = 0; i < mMobileConnections.Length(); i++) { |
michael@0 | 68 | mMobileConnections[i]->Shutdown(); |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | mMobileConnections.Clear(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | nsPIDOMWindow* |
michael@0 | 76 | MobileConnectionArray::GetParentObject() const |
michael@0 | 77 | { |
michael@0 | 78 | MOZ_ASSERT(mWindow); |
michael@0 | 79 | return mWindow; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | JSObject* |
michael@0 | 83 | MobileConnectionArray::WrapObject(JSContext* aCx) |
michael@0 | 84 | { |
michael@0 | 85 | return MozMobileConnectionArrayBinding::Wrap(aCx, this); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | nsIDOMMozMobileConnection* |
michael@0 | 89 | MobileConnectionArray::Item(uint32_t aIndex) |
michael@0 | 90 | { |
michael@0 | 91 | bool unused; |
michael@0 | 92 | return IndexedGetter(aIndex, unused); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | uint32_t |
michael@0 | 96 | MobileConnectionArray::Length() const |
michael@0 | 97 | { |
michael@0 | 98 | return mMobileConnections.Length(); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | nsIDOMMozMobileConnection* |
michael@0 | 102 | MobileConnectionArray::IndexedGetter(uint32_t aIndex, bool& aFound) |
michael@0 | 103 | { |
michael@0 | 104 | if (!mInitialized) { |
michael@0 | 105 | Init(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | aFound = false; |
michael@0 | 109 | aFound = aIndex < mMobileConnections.Length(); |
michael@0 | 110 | |
michael@0 | 111 | return aFound ? mMobileConnections[aIndex] : nullptr; |
michael@0 | 112 | } |