michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=79: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsPluginArray_h___ michael@0: #define nsPluginArray_h___ michael@0: michael@0: #include "nsTArray.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsPluginTags.h" michael@0: #include "nsPIDOMWindow.h" michael@0: michael@0: class nsPluginElement; michael@0: class nsMimeType; michael@0: michael@0: class nsPluginArray MOZ_FINAL : public nsIObserver, michael@0: public nsSupportsWeakReference, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsPluginArray, michael@0: nsIObserver) michael@0: michael@0: // nsIObserver michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: nsPluginArray(nsPIDOMWindow* aWindow); michael@0: virtual ~nsPluginArray(); michael@0: michael@0: nsPIDOMWindow* GetParentObject() const; michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // nsPluginArray registers itself as an observer with a weak reference. michael@0: // This can't be done in the constructor, because at that point its michael@0: // refcount is 0 (and it gets destroyed upon registration). So, Init() michael@0: // must be called after construction. michael@0: void Init(); michael@0: void Invalidate(); michael@0: michael@0: void GetMimeTypes(nsTArray >& aMimeTypes, michael@0: nsTArray >& aHiddenMimeTypes); michael@0: michael@0: // PluginArray WebIDL methods michael@0: michael@0: nsPluginElement* Item(uint32_t aIndex); michael@0: nsPluginElement* NamedItem(const nsAString& aName); michael@0: void Refresh(bool aReloadDocuments); michael@0: nsPluginElement* IndexedGetter(uint32_t aIndex, bool &aFound); michael@0: nsPluginElement* NamedGetter(const nsAString& aName, bool &aFound); michael@0: bool NameIsEnumerable(const nsAString& aName); michael@0: uint32_t Length(); michael@0: void GetSupportedNames(unsigned, nsTArray& aRetval); michael@0: michael@0: private: michael@0: bool AllowPlugins() const; michael@0: void EnsurePlugins(); michael@0: michael@0: nsCOMPtr mWindow; michael@0: michael@0: // Many sites check whether a particular plugin is installed by enumerating michael@0: // all navigator.plugins, checking each plugin's name. These sites should michael@0: // just check navigator.plugins["Popular Plugin Name"] instead. mPlugins michael@0: // contains those popular plugins that must be exposed in navigator.plugins michael@0: // enumeration to avoid breaking web content. michael@0: nsTArray > mPlugins; michael@0: michael@0: // mHiddenPlugins contains plugins that can be queried by michael@0: // navigator.plugins["Hidden Plugin Name"] but do not need to be exposed in michael@0: // navigator.plugins enumeration. michael@0: nsTArray > mHiddenPlugins; michael@0: }; michael@0: michael@0: class nsPluginElement MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPluginElement) michael@0: michael@0: nsPluginElement(nsPIDOMWindow* aWindow, nsPluginTag* aPluginTag); michael@0: michael@0: nsPIDOMWindow* GetParentObject() const; michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: nsPluginTag* PluginTag() const michael@0: { michael@0: return mPluginTag; michael@0: } michael@0: michael@0: // Plugin WebIDL methods michael@0: michael@0: void GetDescription(nsString& retval) const; michael@0: void GetFilename(nsString& retval) const; michael@0: void GetVersion(nsString& retval) const; michael@0: void GetName(nsString& retval) const; michael@0: nsMimeType* Item(uint32_t index); michael@0: nsMimeType* NamedItem(const nsAString& name); michael@0: nsMimeType* IndexedGetter(uint32_t index, bool &found); michael@0: nsMimeType* NamedGetter(const nsAString& name, bool &found); michael@0: bool NameIsEnumerable(const nsAString& aName); michael@0: uint32_t Length(); michael@0: void GetSupportedNames(unsigned, nsTArray& retval); michael@0: michael@0: nsTArray >& MimeTypes(); michael@0: michael@0: protected: michael@0: void EnsurePluginMimeTypes(); michael@0: michael@0: nsCOMPtr mWindow; michael@0: nsRefPtr mPluginTag; michael@0: nsTArray > mMimeTypes; michael@0: }; michael@0: michael@0: #endif /* nsPluginArray_h___ */