dom/mobileconnection/src/MobileConnectionArray.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial