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 #ifndef nsPluginArray_h___
8 #define nsPluginArray_h___
10 #include "nsWeakReference.h"
11 #include "nsWrapperCache.h"
15 #include "mozilla/Array.h"
17 class nsPIDOMWindowInner
;
18 class nsPluginElement
;
19 class nsMimeTypeArray
;
23 * Array class backing HTML's navigator.plugins. This always holds references
24 * to the hard-coded set of PDF plugins defined by HTML but it only consults
25 * them if "pdfjs.disabled" is false. There is never more than one of these
28 class nsPluginArray final
: public nsSupportsWeakReference
,
29 public nsWrapperCache
{
31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
32 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsPluginArray
)
34 explicit nsPluginArray(nsPIDOMWindowInner
* aWindow
);
35 nsPIDOMWindowInner
* GetParentObject() const;
36 virtual JSObject
* WrapObject(JSContext
* aCx
,
37 JS::Handle
<JSObject
*> aGivenProto
) override
;
39 nsMimeTypeArray
* MimeTypeArray() { return mMimeTypeArray
; }
41 // PluginArray WebIDL methods
42 uint32_t Length() { return ForceNoPlugins() ? 0 : std::size(mPlugins
); }
44 nsPluginElement
* Item(uint32_t aIndex
) {
46 return IndexedGetter(aIndex
, unused
);
49 nsPluginElement
* NamedItem(const nsAString
& aName
) {
51 return NamedGetter(aName
, unused
);
54 nsPluginElement
* IndexedGetter(uint32_t aIndex
, bool& aFound
);
56 nsPluginElement
* NamedGetter(const nsAString
& aName
, bool& aFound
);
58 void GetSupportedNames(nsTArray
<nsString
>& aRetval
);
63 virtual ~nsPluginArray();
65 bool ForceNoPlugins();
67 RefPtr
<nsMimeTypeArray
> mMimeTypeArray
;
68 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
69 mozilla::Array
<RefPtr
<nsPluginElement
>, 5> mPlugins
;
73 * Plugin class backing entries in HTML's navigator.plugins array. There is
74 * a fixed set of these, as defined by HTML.
76 class nsPluginElement final
: public nsISupports
, public nsWrapperCache
{
78 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
79 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsPluginElement
)
81 explicit nsPluginElement(nsPluginArray
* aPluginArray
,
82 nsPIDOMWindowInner
* aWindow
, const nsAString
& aName
);
84 nsPluginArray
* GetParentObject() const;
86 virtual JSObject
* WrapObject(JSContext
* aCx
,
87 JS::Handle
<JSObject
*> aGivenProto
) override
;
89 // Plugin WebIDL methods
90 void GetDescription(nsString
& retval
) const { retval
= kDescription
; }
92 void GetFilename(nsString
& retval
) const { retval
= kFilename
; }
94 void GetName(nsString
& retval
) const { retval
= mName
; }
95 const nsString
& Name() const { return mName
; }
97 nsMimeType
* Item(uint32_t index
) {
99 return IndexedGetter(index
, unused
);
102 nsMimeType
* NamedItem(const nsAString
& name
) {
104 return NamedGetter(name
, unused
);
109 nsMimeType
* IndexedGetter(uint32_t index
, bool& found
);
111 nsMimeType
* NamedGetter(const nsAString
& name
, bool& found
);
113 void GetSupportedNames(nsTArray
<nsString
>& retval
);
116 virtual ~nsPluginElement() = default;
118 nsMimeTypeArray
* MimeTypeArray() { return mPluginArray
->MimeTypeArray(); }
120 static constexpr nsLiteralString kDescription
=
121 u
"Portable Document Format"_ns
;
122 static constexpr nsLiteralString kFilename
= u
"internal-pdf-viewer"_ns
;
124 // Note that this creates an explicit reference cycle:
126 // nsPluginElement -> nsPluginArray -> nsPluginElement
128 // We rely on the cycle collector to break this cycle.
129 RefPtr
<nsPluginArray
> mPluginArray
;
130 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
134 #endif /* nsPluginArray_h___ */