|
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/. */ |
|
6 |
|
7 #ifndef nsPluginArray_h___ |
|
8 #define nsPluginArray_h___ |
|
9 |
|
10 #include "nsTArray.h" |
|
11 #include "nsWeakReference.h" |
|
12 #include "nsIObserver.h" |
|
13 #include "nsWrapperCache.h" |
|
14 #include "nsPluginTags.h" |
|
15 #include "nsPIDOMWindow.h" |
|
16 |
|
17 class nsPluginElement; |
|
18 class nsMimeType; |
|
19 |
|
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) |
|
28 |
|
29 // nsIObserver |
|
30 NS_DECL_NSIOBSERVER |
|
31 |
|
32 nsPluginArray(nsPIDOMWindow* aWindow); |
|
33 virtual ~nsPluginArray(); |
|
34 |
|
35 nsPIDOMWindow* GetParentObject() const; |
|
36 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
37 |
|
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(); |
|
44 |
|
45 void GetMimeTypes(nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes, |
|
46 nsTArray<nsRefPtr<nsMimeType> >& aHiddenMimeTypes); |
|
47 |
|
48 // PluginArray WebIDL methods |
|
49 |
|
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); |
|
58 |
|
59 private: |
|
60 bool AllowPlugins() const; |
|
61 void EnsurePlugins(); |
|
62 |
|
63 nsCOMPtr<nsPIDOMWindow> mWindow; |
|
64 |
|
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; |
|
71 |
|
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 }; |
|
77 |
|
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) |
|
84 |
|
85 nsPluginElement(nsPIDOMWindow* aWindow, nsPluginTag* aPluginTag); |
|
86 |
|
87 nsPIDOMWindow* GetParentObject() const; |
|
88 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
89 |
|
90 nsPluginTag* PluginTag() const |
|
91 { |
|
92 return mPluginTag; |
|
93 } |
|
94 |
|
95 // Plugin WebIDL methods |
|
96 |
|
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); |
|
108 |
|
109 nsTArray<nsRefPtr<nsMimeType> >& MimeTypes(); |
|
110 |
|
111 protected: |
|
112 void EnsurePluginMimeTypes(); |
|
113 |
|
114 nsCOMPtr<nsPIDOMWindow> mWindow; |
|
115 nsRefPtr<nsPluginTag> mPluginTag; |
|
116 nsTArray<nsRefPtr<nsMimeType> > mMimeTypes; |
|
117 }; |
|
118 |
|
119 #endif /* nsPluginArray_h___ */ |