dom/base/MessagePortList.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     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 #ifndef mozilla_dom_MessagePortList_h
     8 #define mozilla_dom_MessagePortList_h
    10 #include "mozilla/Attributes.h"
    11 #include "mozilla/ErrorResult.h"
    12 #include "nsCycleCollectionParticipant.h"
    13 #include "mozilla/dom/MessagePort.h"
    14 #include "nsWrapperCache.h"
    15 #include "nsAutoPtr.h"
    16 #include "nsTArray.h"
    18 namespace mozilla {
    19 namespace dom {
    21 class MessagePortList MOZ_FINAL : public nsISupports
    22                                 , public nsWrapperCache
    23 {
    24 public:
    25   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    26   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MessagePortList)
    28 public:
    29   MessagePortList(nsISupports* aOwner, nsTArray<nsRefPtr<MessagePortBase>>& aPorts)
    30     : mOwner(aOwner)
    31     , mPorts(aPorts)
    32   {
    33     SetIsDOMBinding();
    34   }
    36   nsISupports*
    37   GetParentObject() const
    38   {
    39     return mOwner;
    40   }
    42   virtual JSObject*
    43   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    45   uint32_t
    46   Length() const
    47   {
    48     return mPorts.Length();
    49   }
    51   MessagePortBase*
    52   Item(uint32_t aIndex)
    53   {
    54     return mPorts.SafeElementAt(aIndex);
    55   }
    57   MessagePortBase*
    58   IndexedGetter(uint32_t aIndex, bool &aFound)
    59   {
    60     aFound = aIndex < mPorts.Length();
    61     if (!aFound) {
    62       return nullptr;
    63     }
    64     return mPorts[aIndex];
    65   }
    67 public:
    68   nsCOMPtr<nsISupports> mOwner;
    69   nsTArray<nsRefPtr<MessagePortBase>> mPorts;
    70 };
    72 } // namespace dom
    73 } // namespace mozilla
    75 #endif // mozilla_dom_MessagePortList_h

mercurial