1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsPluginArray.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=79: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsPluginArray_h___ 1.11 +#define nsPluginArray_h___ 1.12 + 1.13 +#include "nsTArray.h" 1.14 +#include "nsWeakReference.h" 1.15 +#include "nsIObserver.h" 1.16 +#include "nsWrapperCache.h" 1.17 +#include "nsPluginTags.h" 1.18 +#include "nsPIDOMWindow.h" 1.19 + 1.20 +class nsPluginElement; 1.21 +class nsMimeType; 1.22 + 1.23 +class nsPluginArray MOZ_FINAL : public nsIObserver, 1.24 + public nsSupportsWeakReference, 1.25 + public nsWrapperCache 1.26 +{ 1.27 +public: 1.28 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.29 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsPluginArray, 1.30 + nsIObserver) 1.31 + 1.32 + // nsIObserver 1.33 + NS_DECL_NSIOBSERVER 1.34 + 1.35 + nsPluginArray(nsPIDOMWindow* aWindow); 1.36 + virtual ~nsPluginArray(); 1.37 + 1.38 + nsPIDOMWindow* GetParentObject() const; 1.39 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.40 + 1.41 + // nsPluginArray registers itself as an observer with a weak reference. 1.42 + // This can't be done in the constructor, because at that point its 1.43 + // refcount is 0 (and it gets destroyed upon registration). So, Init() 1.44 + // must be called after construction. 1.45 + void Init(); 1.46 + void Invalidate(); 1.47 + 1.48 + void GetMimeTypes(nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes, 1.49 + nsTArray<nsRefPtr<nsMimeType> >& aHiddenMimeTypes); 1.50 + 1.51 + // PluginArray WebIDL methods 1.52 + 1.53 + nsPluginElement* Item(uint32_t aIndex); 1.54 + nsPluginElement* NamedItem(const nsAString& aName); 1.55 + void Refresh(bool aReloadDocuments); 1.56 + nsPluginElement* IndexedGetter(uint32_t aIndex, bool &aFound); 1.57 + nsPluginElement* NamedGetter(const nsAString& aName, bool &aFound); 1.58 + bool NameIsEnumerable(const nsAString& aName); 1.59 + uint32_t Length(); 1.60 + void GetSupportedNames(unsigned, nsTArray<nsString>& aRetval); 1.61 + 1.62 +private: 1.63 + bool AllowPlugins() const; 1.64 + void EnsurePlugins(); 1.65 + 1.66 + nsCOMPtr<nsPIDOMWindow> mWindow; 1.67 + 1.68 + // Many sites check whether a particular plugin is installed by enumerating 1.69 + // all navigator.plugins, checking each plugin's name. These sites should 1.70 + // just check navigator.plugins["Popular Plugin Name"] instead. mPlugins 1.71 + // contains those popular plugins that must be exposed in navigator.plugins 1.72 + // enumeration to avoid breaking web content. 1.73 + nsTArray<nsRefPtr<nsPluginElement> > mPlugins; 1.74 + 1.75 + // mHiddenPlugins contains plugins that can be queried by 1.76 + // navigator.plugins["Hidden Plugin Name"] but do not need to be exposed in 1.77 + // navigator.plugins enumeration. 1.78 + nsTArray<nsRefPtr<nsPluginElement> > mHiddenPlugins; 1.79 +}; 1.80 + 1.81 +class nsPluginElement MOZ_FINAL : public nsISupports, 1.82 + public nsWrapperCache 1.83 +{ 1.84 +public: 1.85 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.86 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPluginElement) 1.87 + 1.88 + nsPluginElement(nsPIDOMWindow* aWindow, nsPluginTag* aPluginTag); 1.89 + 1.90 + nsPIDOMWindow* GetParentObject() const; 1.91 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.92 + 1.93 + nsPluginTag* PluginTag() const 1.94 + { 1.95 + return mPluginTag; 1.96 + } 1.97 + 1.98 + // Plugin WebIDL methods 1.99 + 1.100 + void GetDescription(nsString& retval) const; 1.101 + void GetFilename(nsString& retval) const; 1.102 + void GetVersion(nsString& retval) const; 1.103 + void GetName(nsString& retval) const; 1.104 + nsMimeType* Item(uint32_t index); 1.105 + nsMimeType* NamedItem(const nsAString& name); 1.106 + nsMimeType* IndexedGetter(uint32_t index, bool &found); 1.107 + nsMimeType* NamedGetter(const nsAString& name, bool &found); 1.108 + bool NameIsEnumerable(const nsAString& aName); 1.109 + uint32_t Length(); 1.110 + void GetSupportedNames(unsigned, nsTArray<nsString>& retval); 1.111 + 1.112 + nsTArray<nsRefPtr<nsMimeType> >& MimeTypes(); 1.113 + 1.114 +protected: 1.115 + void EnsurePluginMimeTypes(); 1.116 + 1.117 + nsCOMPtr<nsPIDOMWindow> mWindow; 1.118 + nsRefPtr<nsPluginTag> mPluginTag; 1.119 + nsTArray<nsRefPtr<nsMimeType> > mMimeTypes; 1.120 +}; 1.121 + 1.122 +#endif /* nsPluginArray_h___ */