Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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
23 {
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 nsPluginArray(nsPIDOMWindow* aWindow);
33 virtual ~nsPluginArray();
35 nsPIDOMWindow* GetParentObject() const;
36 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
38 // nsPluginArray registers itself as an observer with a weak reference.
39 // This can't be done in the constructor, because at that point its
40 // refcount is 0 (and it gets destroyed upon registration). So, Init()
41 // must be called after construction.
42 void Init();
43 void Invalidate();
45 void GetMimeTypes(nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes,
46 nsTArray<nsRefPtr<nsMimeType> >& aHiddenMimeTypes);
48 // PluginArray WebIDL methods
50 nsPluginElement* Item(uint32_t aIndex);
51 nsPluginElement* NamedItem(const nsAString& aName);
52 void Refresh(bool aReloadDocuments);
53 nsPluginElement* IndexedGetter(uint32_t aIndex, bool &aFound);
54 nsPluginElement* NamedGetter(const nsAString& aName, bool &aFound);
55 bool NameIsEnumerable(const nsAString& aName);
56 uint32_t Length();
57 void GetSupportedNames(unsigned, nsTArray<nsString>& aRetval);
59 private:
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;
76 };
78 class nsPluginElement MOZ_FINAL : public nsISupports,
79 public nsWrapperCache
80 {
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
91 {
92 return mPluginTag;
93 }
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 void EnsurePluginMimeTypes();
114 nsCOMPtr<nsPIDOMWindow> mWindow;
115 nsRefPtr<nsPluginTag> mPluginTag;
116 nsTArray<nsRefPtr<nsMimeType> > mMimeTypes;
117 };
119 #endif /* nsPluginArray_h___ */