Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / dom / base / nsPluginArray.h
blob7b1cc6544075abd54f03e29b1c347edfbc28c72d
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"
12 #include "nsCOMPtr.h"
13 #include "nsString.h"
14 #include "nsTArray.h"
15 #include "mozilla/Array.h"
17 class nsPIDOMWindowInner;
18 class nsPluginElement;
19 class nsMimeTypeArray;
20 class nsMimeType;
22 /**
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
26 * per DOM window.
28 class nsPluginArray final : public nsSupportsWeakReference,
29 public nsWrapperCache {
30 public:
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 : ArrayLength(mPlugins); }
44 nsPluginElement* Item(uint32_t aIndex) {
45 bool unused;
46 return IndexedGetter(aIndex, unused);
49 nsPluginElement* NamedItem(const nsAString& aName) {
50 bool unused;
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);
60 void Refresh() {}
62 private:
63 virtual ~nsPluginArray();
65 bool ForceNoPlugins();
67 RefPtr<nsMimeTypeArray> mMimeTypeArray;
68 nsCOMPtr<nsPIDOMWindowInner> mWindow;
69 mozilla::Array<RefPtr<nsPluginElement>, 5> mPlugins;
72 /**
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 {
77 public:
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) {
98 bool unused;
99 return IndexedGetter(index, unused);
102 nsMimeType* NamedItem(const nsAString& name) {
103 bool unused;
104 return NamedGetter(name, unused);
107 uint32_t Length();
109 nsMimeType* IndexedGetter(uint32_t index, bool& found);
111 nsMimeType* NamedGetter(const nsAString& name, bool& found);
113 void GetSupportedNames(nsTArray<nsString>& retval);
115 protected:
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;
131 nsString mName;
134 #endif /* nsPluginArray_h___ */