|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_MessagePortList_h |
|
8 #define mozilla_dom_MessagePortList_h |
|
9 |
|
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" |
|
17 |
|
18 namespace mozilla { |
|
19 namespace dom { |
|
20 |
|
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) |
|
27 |
|
28 public: |
|
29 MessagePortList(nsISupports* aOwner, nsTArray<nsRefPtr<MessagePortBase>>& aPorts) |
|
30 : mOwner(aOwner) |
|
31 , mPorts(aPorts) |
|
32 { |
|
33 SetIsDOMBinding(); |
|
34 } |
|
35 |
|
36 nsISupports* |
|
37 GetParentObject() const |
|
38 { |
|
39 return mOwner; |
|
40 } |
|
41 |
|
42 virtual JSObject* |
|
43 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
44 |
|
45 uint32_t |
|
46 Length() const |
|
47 { |
|
48 return mPorts.Length(); |
|
49 } |
|
50 |
|
51 MessagePortBase* |
|
52 Item(uint32_t aIndex) |
|
53 { |
|
54 return mPorts.SafeElementAt(aIndex); |
|
55 } |
|
56 |
|
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 } |
|
66 |
|
67 public: |
|
68 nsCOMPtr<nsISupports> mOwner; |
|
69 nsTArray<nsRefPtr<MessagePortBase>> mPorts; |
|
70 }; |
|
71 |
|
72 } // namespace dom |
|
73 } // namespace mozilla |
|
74 |
|
75 #endif // mozilla_dom_MessagePortList_h |
|
76 |