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
19 namespace mozilla {
20 namespace dom {
21 struct FakePluginTagInit;
22 } // namespace dom
23 } // namespace mozilla
24
25 // An interface representing plugin tags internally.
26 #define NS_IINTERNALPLUGINTAG_IID \
27 { \
28 0xe8fdd227, 0x27da, 0x46ee, { \
29 0xbe, 0xf3, 0x1a, 0xef, 0x5a, 0x8f, 0xc5, 0xb4 \
30 } \
31 }
32
33 class nsIInternalPluginTag : public nsIPluginTag {
34 public:
35 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IINTERNALPLUGINTAG_IID)
36
37 nsIInternalPluginTag();
38 nsIInternalPluginTag(const char* aName, const char* aDescription,
39 const char* aFileName, const char* aVersion);
40 nsIInternalPluginTag(const char* aName, const char* aDescription,
41 const char* aFileName, const char* aVersion,
42 const nsTArray<nsCString>& aMimeTypes,
43 const nsTArray<nsCString>& aMimeDescriptions,
44 const nsTArray<nsCString>& aExtensions);
45
46 virtual bool IsEnabled() = 0;
47 virtual const nsCString& GetNiceFileName() = 0;
48
Name()49 const nsCString& Name() const { return mName; }
Description()50 const nsCString& Description() const { return mDescription; }
51
MimeTypes()52 const nsTArray<nsCString>& MimeTypes() const { return mMimeTypes; }
53
MimeDescriptions()54 const nsTArray<nsCString>& MimeDescriptions() const {
55 return mMimeDescriptions;
56 }
57
Extensions()58 const nsTArray<nsCString>& Extensions() const { return mExtensions; }
59
FileName()60 const nsCString& FileName() const { return mFileName; }
61
Version()62 const nsCString& Version() const { return mVersion; }
63
64 // Returns true if this plugin claims it supports this MIME type. The
65 // comparison is done ASCII-case-insensitively.
66 bool HasMimeType(const nsACString& aMimeType) const;
67
68 // Returns true if this plugin claims it supports the given extension. In
69 // that case, aMatchingType is set to the MIME type the plugin claims
70 // corresponds to this extension. The match on aExtension is done
71 // ASCII-case-insensitively.
72 bool HasExtension(const nsACString& aExtension,
73 /* out */ nsACString& aMatchingType) const;
74
75 // These must match the STATE_* values in nsIPluginTag.idl
76 enum PluginState {
77 ePluginState_Disabled = 0,
78 ePluginState_Clicktoplay = 1,
79 ePluginState_Enabled = 2,
80 ePluginState_MaxValue = 3,
81 };
82
83 protected:
84 ~nsIInternalPluginTag();
85
86 nsCString mName; // UTF-8
87 nsCString mDescription; // UTF-8
88 nsCString mFileName; // UTF-8
89 nsCString mVersion; // UTF-8
90 nsTArray<nsCString> mMimeTypes; // UTF-8
91 nsTArray<nsCString> mMimeDescriptions; // UTF-8
92 nsTArray<nsCString> mExtensions; // UTF-8
93
94 static uint32_t sNextId;
95 };
NS_DEFINE_STATIC_IID_ACCESSOR(nsIInternalPluginTag,NS_IINTERNALPLUGINTAG_IID)96 NS_DEFINE_STATIC_IID_ACCESSOR(nsIInternalPluginTag, NS_IINTERNALPLUGINTAG_IID)
97
98 // A class representing "fake" plugin tags for Javascript-based plugins.
99 // There are currently no other types of supported plugins.
100 class nsFakePluginTag : public nsIInternalPluginTag, public nsIFakePluginTag {
101 public:
102 NS_DECL_ISUPPORTS
103 NS_DECL_NSIPLUGINTAG
104 NS_DECL_NSIFAKEPLUGINTAG
105
106 static nsresult Create(const mozilla::dom::FakePluginTagInit& aInitDictionary,
107 nsFakePluginTag** aPluginTag);
108 nsFakePluginTag(uint32_t aId, already_AddRefed<nsIURI>&& aHandlerURI,
109 const char* aName, const char* aDescription,
110 const nsTArray<nsCString>& aMimeTypes,
111 const nsTArray<nsCString>& aMimeDescriptions,
112 const nsTArray<nsCString>& aExtensions,
113 const nsCString& aNiceName, const nsString& aSandboxScript);
114
115 bool IsEnabled() override;
116 const nsCString& GetNiceFileName() override;
117
118 bool HandlerURIMatches(nsIURI* aURI);
119
120 nsIURI* HandlerURI() const { return mHandlerURI; }
121
122 uint32_t Id() const { return mId; }
123
124 const nsString& SandboxScript() const { return mSandboxScript; }
125
126 static const int32_t NOT_JSPLUGIN = -1;
127
128 private:
129 nsFakePluginTag();
130 virtual ~nsFakePluginTag();
131
132 // A unique id for this JS-implemented plugin. Registering a plugin through
133 // nsPluginHost::RegisterFakePlugin assigns a new id. The id is transferred
134 // through IPC when getting the list of JS-implemented plugins from child
135 // processes, so it should be consistent across processes.
136 // 0 is a valid id.
137 uint32_t mId;
138
139 // The URI of the handler for our fake plugin.
140 // FIXME-jsplugins do we need to sanity check these?
141 nsCOMPtr<nsIURI> mHandlerURI;
142
143 nsCString mFullPath;
144 nsCString mNiceName;
145
146 nsString mSandboxScript;
147
148 PluginState mState;
149 };
150
151 #endif // nsPluginTags_h_
152