1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=79: */
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___
11 #include "nsWeakReference.h"
12 #include "nsIObserver.h"
13 #include "nsWrapperCache.h"
14 #include "nsPluginTags.h"
15 #include "nsPIDOMWindow.h"
17 class nsPluginElement
;
20 class nsPluginArray MOZ_FINAL
: public nsIObserver
,
21 public nsSupportsWeakReference
,
25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsPluginArray
,
32 nsPluginArray(nsPIDOMWindow
* aWindow
);
33 virtual ~nsPluginArray();
35 nsPIDOMWindow
* GetParentObject() const;
36 virtual JSObject
* WrapObject(JSContext
* aCx
,
37 JS::Handle
<JSObject
*> aScope
) MOZ_OVERRIDE
;
39 // nsPluginArray registers itself as an observer with a weak reference.
40 // This can't be done in the constructor, because at that point its
41 // refcount is 0 (and it gets destroyed upon registration). So, Init()
42 // must be called after construction.
46 void GetMimeTypes(nsTArray
<nsRefPtr
<nsMimeType
> >& aMimeTypes
,
47 nsTArray
<nsRefPtr
<nsMimeType
> >& aHiddenMimeTypes
);
49 // PluginArray WebIDL methods
51 nsPluginElement
* Item(uint32_t aIndex
);
52 nsPluginElement
* NamedItem(const nsAString
& aName
);
53 void Refresh(bool aReloadDocuments
);
54 nsPluginElement
* IndexedGetter(uint32_t aIndex
, bool &aFound
);
55 nsPluginElement
* NamedGetter(const nsAString
& aName
, bool &aFound
);
57 void GetSupportedNames(nsTArray
< nsString
>& aRetval
);
60 bool AllowPlugins() const;
63 nsCOMPtr
<nsPIDOMWindow
> mWindow
;
65 // Many sites check whether a particular plugin is installed by enumerating
66 // all navigator.plugins, checking each plugin's name. These sites should
67 // just check navigator.plugins["Popular Plugin Name"] instead. mPlugins
68 // contains those popular plugins that must be exposed in navigator.plugins
69 // enumeration to avoid breaking web content.
70 nsTArray
<nsRefPtr
<nsPluginElement
> > mPlugins
;
72 // mHiddenPlugins contains plugins that can be queried by
73 // navigator.plugins["Hidden Plugin Name"] but do not need to be exposed in
74 // navigator.plugins enumeration.
75 nsTArray
<nsRefPtr
<nsPluginElement
> > mHiddenPlugins
;
78 class nsPluginElement MOZ_FINAL
: public nsISupports
,
82 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
83 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPluginElement
)
85 nsPluginElement(nsPIDOMWindow
* aWindow
, nsPluginTag
* aPluginTag
);
87 nsPIDOMWindow
* GetParentObject() const;
88 virtual JSObject
* WrapObject(JSContext
* aCx
,
89 JS::Handle
<JSObject
*> aScope
) MOZ_OVERRIDE
;
91 nsPluginTag
* PluginTag() const
96 // Plugin WebIDL methods
98 void GetDescription(nsString
& retval
) const;
99 void GetFilename(nsString
& retval
) const;
100 void GetVersion(nsString
& retval
) const;
101 void GetName(nsString
& retval
) const;
102 nsMimeType
* Item(uint32_t index
);
103 nsMimeType
* NamedItem(const nsAString
& name
);
104 nsMimeType
* IndexedGetter(uint32_t index
, bool &found
);
105 nsMimeType
* NamedGetter(const nsAString
& name
, bool &found
);
107 void GetSupportedNames(nsTArray
< nsString
>& retval
);
109 nsTArray
<nsRefPtr
<nsMimeType
> >& MimeTypes();
112 void EnsurePluginMimeTypes();
114 nsCOMPtr
<nsPIDOMWindow
> mWindow
;
115 nsRefPtr
<nsPluginTag
> mPluginTag
;
116 nsTArray
<nsRefPtr
<nsMimeType
> > mMimeTypes
;
119 #endif /* nsPluginArray_h___ */