Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsPluginTags_h_
7 : #define nsPluginTags_h_
8 :
9 : #include "mozilla/Attributes.h"
10 : #include "nscore.h"
11 : #include "nsCOMPtr.h"
12 : #include "nsCOMArray.h"
13 : #include "nsIPluginTag.h"
14 : #include "nsITimer.h"
15 : #include "nsString.h"
16 :
17 : class nsIURI;
18 : struct PRLibrary;
19 : struct nsPluginInfo;
20 : class nsNPAPIPlugin;
21 :
22 : namespace mozilla {
23 : namespace dom {
24 : struct FakePluginTagInit;
25 : } // namespace dom
26 : } // namespace mozilla
27 :
28 : // An interface representing plugin tags internally.
29 : #define NS_IINTERNALPLUGINTAG_IID \
30 : { 0xe8fdd227, 0x27da, 0x46ee, \
31 : { 0xbe, 0xf3, 0x1a, 0xef, 0x5a, 0x8f, 0xc5, 0xb4 } }
32 :
33 : #define NS_PLUGINTAG_IID \
34 : { 0xcce2e8b9, 0x9702, 0x4d4b, \
35 : { 0xbe, 0xa4, 0x7c, 0x1e, 0x13, 0x1f, 0xaf, 0x78 } }
36 : class nsIInternalPluginTag : public nsIPluginTag
37 : {
38 : public:
39 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IINTERNALPLUGINTAG_IID)
40 :
41 : nsIInternalPluginTag();
42 : nsIInternalPluginTag(const char* aName, const char* aDescription,
43 : const char* aFileName, const char* aVersion);
44 : nsIInternalPluginTag(const char* aName, const char* aDescription,
45 : const char* aFileName, const char* aVersion,
46 : const nsTArray<nsCString>& aMimeTypes,
47 : const nsTArray<nsCString>& aMimeDescriptions,
48 : const nsTArray<nsCString>& aExtensions);
49 :
50 : virtual bool IsEnabled() = 0;
51 : virtual const nsCString& GetNiceFileName() = 0;
52 :
53 0 : const nsCString& Name() const { return mName; }
54 0 : const nsCString& Description() const { return mDescription; }
55 :
56 0 : const nsTArray<nsCString>& MimeTypes() const { return mMimeTypes; }
57 :
58 0 : const nsTArray<nsCString>& MimeDescriptions() const {
59 0 : return mMimeDescriptions;
60 : }
61 :
62 0 : const nsTArray<nsCString>& Extensions() const { return mExtensions; }
63 :
64 0 : const nsCString& FileName() const { return mFileName; }
65 :
66 0 : const nsCString& Version() const { return mVersion; }
67 :
68 : // Returns true if this plugin claims it supports this MIME type. The
69 : // comparison is done ASCII-case-insensitively.
70 : bool HasMimeType(const nsACString & aMimeType) const;
71 :
72 : // Returns true if this plugin claims it supports the given extension. In
73 : // that case, aMatchingType is set to the MIME type the plugin claims
74 : // corresponds to this extension. The match on aExtension is done
75 : // ASCII-case-insensitively.
76 : bool HasExtension(const nsACString & aExtension,
77 : /* out */ nsACString & aMatchingType) const;
78 : protected:
79 : ~nsIInternalPluginTag();
80 :
81 : nsCString mName; // UTF-8
82 : nsCString mDescription; // UTF-8
83 : nsCString mFileName; // UTF-8
84 : nsCString mVersion; // UTF-8
85 : nsTArray<nsCString> mMimeTypes; // UTF-8
86 : nsTArray<nsCString> mMimeDescriptions; // UTF-8
87 : nsTArray<nsCString> mExtensions; // UTF-8
88 : };
89 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIInternalPluginTag, NS_IINTERNALPLUGINTAG_IID)
90 :
91 : // A linked-list of plugin information that is used for instantiating plugins
92 : // and reflecting plugin information into JavaScript.
93 : class nsPluginTag final : public nsIInternalPluginTag
94 : {
95 : public:
96 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_PLUGINTAG_IID)
97 :
98 : NS_DECL_ISUPPORTS
99 : NS_DECL_NSIPLUGINTAG
100 :
101 : // These must match the STATE_* values in nsIPluginTag.idl
102 : enum PluginState {
103 : ePluginState_Disabled = 0,
104 : ePluginState_Clicktoplay = 1,
105 : ePluginState_Enabled = 2,
106 : ePluginState_MaxValue = 3,
107 : };
108 :
109 : nsPluginTag(nsPluginInfo* aPluginInfo,
110 : int64_t aLastModifiedTime,
111 : bool fromExtension);
112 : nsPluginTag(const char* aName,
113 : const char* aDescription,
114 : const char* aFileName,
115 : const char* aFullPath,
116 : const char* aVersion,
117 : const char* const* aMimeTypes,
118 : const char* const* aMimeDescriptions,
119 : const char* const* aExtensions,
120 : int32_t aVariants,
121 : int64_t aLastModifiedTime,
122 : bool fromExtension,
123 : bool aArgsAreUTF8 = false);
124 : nsPluginTag(uint32_t aId,
125 : const char* aName,
126 : const char* aDescription,
127 : const char* aFileName,
128 : const char* aFullPath,
129 : const char* aVersion,
130 : nsTArray<nsCString> aMimeTypes,
131 : nsTArray<nsCString> aMimeDescriptions,
132 : nsTArray<nsCString> aExtensions,
133 : bool aIsJavaPlugin,
134 : bool aIsFlashPlugin,
135 : bool aSupportsAsyncRender,
136 : int64_t aLastModifiedTime,
137 : bool aFromExtension,
138 : int32_t aSandboxLevel);
139 :
140 : void TryUnloadPlugin(bool inShutdown);
141 :
142 : // plugin is enabled and not blocklisted
143 : bool IsActive();
144 :
145 : bool IsEnabled() override;
146 : void SetEnabled(bool enabled);
147 : bool IsClicktoplay();
148 : bool IsBlocklisted();
149 :
150 : PluginState GetPluginState();
151 : void SetPluginState(PluginState state);
152 :
153 : bool HasSameNameAndMimes(const nsPluginTag *aPluginTag) const;
154 : const nsCString& GetNiceFileName() override;
155 :
156 : bool IsFromExtension() const;
157 :
158 : RefPtr<nsPluginTag> mNext;
159 : uint32_t mId;
160 :
161 : // Number of PluginModuleParents living in all content processes.
162 : size_t mContentProcessRunningCount;
163 :
164 : // True if we've ever created an instance of this plugin in the current process.
165 : bool mHadLocalInstance;
166 :
167 : PRLibrary *mLibrary;
168 : RefPtr<nsNPAPIPlugin> mPlugin;
169 : bool mIsJavaPlugin;
170 : bool mIsFlashPlugin;
171 : bool mSupportsAsyncRender;
172 : nsCString mFullPath; // UTF-8
173 : int64_t mLastModifiedTime;
174 : nsCOMPtr<nsITimer> mUnloadTimer;
175 : int32_t mSandboxLevel;
176 :
177 : void InvalidateBlocklistState();
178 :
179 : private:
180 : virtual ~nsPluginTag();
181 :
182 : nsCString mNiceFileName; // UTF-8
183 : uint16_t mCachedBlocklistState;
184 : bool mCachedBlocklistStateValid;
185 : bool mIsFromExtension;
186 :
187 : void InitMime(const char* const* aMimeTypes,
188 : const char* const* aMimeDescriptions,
189 : const char* const* aExtensions,
190 : uint32_t aVariantCount);
191 : void InitSandboxLevel();
192 : nsresult EnsureMembersAreUTF8();
193 : void FixupVersion();
194 :
195 : static uint32_t sNextId;
196 : };
197 : NS_DEFINE_STATIC_IID_ACCESSOR(nsPluginTag, NS_PLUGINTAG_IID)
198 :
199 : // A class representing "fake" plugin tags; that is plugin tags not
200 : // corresponding to actual NPAPI plugins. In practice these are all
201 : // JS-implemented plugins; maybe we want a better name for this class?
202 : class nsFakePluginTag : public nsIInternalPluginTag,
203 : public nsIFakePluginTag
204 : {
205 : public:
206 : NS_DECL_ISUPPORTS
207 : NS_DECL_NSIPLUGINTAG
208 : NS_DECL_NSIFAKEPLUGINTAG
209 :
210 : static nsresult Create(const mozilla::dom::FakePluginTagInit& aInitDictionary,
211 : nsFakePluginTag** aPluginTag);
212 : nsFakePluginTag(uint32_t aId,
213 : already_AddRefed<nsIURI>&& aHandlerURI,
214 : const char* aName,
215 : const char* aDescription,
216 : const nsTArray<nsCString>& aMimeTypes,
217 : const nsTArray<nsCString>& aMimeDescriptions,
218 : const nsTArray<nsCString>& aExtensions,
219 : const nsCString& aNiceName,
220 : const nsString& aSandboxScript);
221 :
222 : bool IsEnabled() override;
223 : const nsCString& GetNiceFileName() override;
224 :
225 : bool HandlerURIMatches(nsIURI* aURI);
226 :
227 0 : nsIURI* HandlerURI() const { return mHandlerURI; }
228 :
229 0 : uint32_t Id() const { return mId; }
230 :
231 0 : const nsString& SandboxScript() const { return mSandboxScript; }
232 :
233 : static const int32_t NOT_JSPLUGIN = -1;
234 :
235 : private:
236 : nsFakePluginTag();
237 : virtual ~nsFakePluginTag();
238 :
239 : // A unique id for this JS-implemented plugin. Registering a plugin through
240 : // nsPluginHost::RegisterFakePlugin assigns a new id. The id is transferred
241 : // through IPC when getting the list of JS-implemented plugins from child
242 : // processes, so it should be consistent across processes.
243 : // 0 is a valid id.
244 : uint32_t mId;
245 :
246 : // The URI of the handler for our fake plugin.
247 : // FIXME-jsplugins do we need to sanity check these?
248 : nsCOMPtr<nsIURI> mHandlerURI;
249 :
250 : nsCString mFullPath;
251 : nsCString mNiceName;
252 :
253 : nsString mSandboxScript;
254 :
255 : nsPluginTag::PluginState mState;
256 :
257 : // Stores the id to use for the JS-implemented plugin that gets registered
258 : // next through nsPluginHost::RegisterFakePlugin.
259 : static uint32_t sNextId;
260 : };
261 :
262 : #endif // nsPluginTags_h_
|