Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / base / nsPluginArray.h
blobf336be17b269cfb2be1f62db46d2f6dae178b53a
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___
10 #include "nsTArray.h"
11 #include "nsWeakReference.h"
12 #include "nsIObserver.h"
13 #include "nsWrapperCache.h"
14 #include "nsPluginTags.h"
15 #include "nsPIDOMWindow.h"
17 class nsPluginElement;
18 class nsMimeType;
20 class nsPluginArray MOZ_FINAL : public nsIObserver,
21 public nsSupportsWeakReference,
22 public nsWrapperCache
24 public:
25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsPluginArray,
27 nsIObserver)
29 // nsIObserver
30 NS_DECL_NSIOBSERVER
32 explicit nsPluginArray(nsPIDOMWindow* aWindow);
33 nsPIDOMWindow* GetParentObject() const;
34 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
36 // nsPluginArray registers itself as an observer with a weak reference.
37 // This can't be done in the constructor, because at that point its
38 // refcount is 0 (and it gets destroyed upon registration). So, Init()
39 // must be called after construction.
40 void Init();
41 void Invalidate();
43 void GetMimeTypes(nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes,
44 nsTArray<nsRefPtr<nsMimeType> >& aHiddenMimeTypes);
46 // PluginArray WebIDL methods
48 nsPluginElement* Item(uint32_t aIndex);
49 nsPluginElement* NamedItem(const nsAString& aName);
50 void Refresh(bool aReloadDocuments);
51 nsPluginElement* IndexedGetter(uint32_t aIndex, bool &aFound);
52 nsPluginElement* NamedGetter(const nsAString& aName, bool &aFound);
53 bool NameIsEnumerable(const nsAString& aName);
54 uint32_t Length();
55 void GetSupportedNames(unsigned, nsTArray<nsString>& aRetval);
57 private:
58 virtual ~nsPluginArray();
60 bool AllowPlugins() const;
61 void EnsurePlugins();
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,
79 public nsWrapperCache
81 public:
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) MOZ_OVERRIDE;
90 nsPluginTag* PluginTag() const
92 return mPluginTag;
95 // Plugin WebIDL methods
97 void GetDescription(nsString& retval) const;
98 void GetFilename(nsString& retval) const;
99 void GetVersion(nsString& retval) const;
100 void GetName(nsString& retval) const;
101 nsMimeType* Item(uint32_t index);
102 nsMimeType* NamedItem(const nsAString& name);
103 nsMimeType* IndexedGetter(uint32_t index, bool &found);
104 nsMimeType* NamedGetter(const nsAString& name, bool &found);
105 bool NameIsEnumerable(const nsAString& aName);
106 uint32_t Length();
107 void GetSupportedNames(unsigned, nsTArray<nsString>& retval);
109 nsTArray<nsRefPtr<nsMimeType> >& MimeTypes();
111 protected:
112 ~nsPluginElement();
114 void EnsurePluginMimeTypes();
116 nsCOMPtr<nsPIDOMWindow> mWindow;
117 nsRefPtr<nsPluginTag> mPluginTag;
118 nsTArray<nsRefPtr<nsMimeType> > mMimeTypes;
121 #endif /* nsPluginArray_h___ */