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 nsMimeTypeArray_h___ michael@0: #define nsMimeTypeArray_h___ michael@0: michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsPIDOMWindow.h" michael@0: michael@0: class nsMimeType; michael@0: class nsPluginElement; michael@0: michael@0: class nsMimeTypeArray MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: nsMimeTypeArray(nsPIDOMWindow* aWindow); michael@0: virtual ~nsMimeTypeArray(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsMimeTypeArray) michael@0: michael@0: nsPIDOMWindow* GetParentObject() const; michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: void Refresh(); michael@0: michael@0: // MimeTypeArray WebIDL methods 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& name); michael@0: uint32_t Length(); michael@0: void GetSupportedNames(unsigned, nsTArray< nsString >& retval); michael@0: michael@0: protected: michael@0: void EnsurePluginMimeTypes(); michael@0: void Clear(); michael@0: michael@0: nsCOMPtr mWindow; michael@0: michael@0: // mMimeTypes contains MIME types handled by non-hidden plugins, those michael@0: // popular plugins that must be exposed in navigator.plugins enumeration to michael@0: // avoid breaking web content. Likewise, mMimeTypes are exposed in michael@0: // navigator.mimeTypes enumeration. michael@0: nsTArray > mMimeTypes; michael@0: michael@0: // mHiddenMimeTypes contains MIME types handled by plugins hidden from michael@0: // navigator.plugins enumeration or by an OS PreferredApplicationHandler. michael@0: // mHiddenMimeTypes are hidden from navigator.mimeTypes enumeration. michael@0: nsTArray > mHiddenMimeTypes; michael@0: }; michael@0: michael@0: class nsMimeType MOZ_FINAL : public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsMimeType) michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsMimeType) michael@0: michael@0: nsMimeType(nsPIDOMWindow* aWindow, nsPluginElement* aPluginElement, michael@0: uint32_t aPluginTagMimeIndex, const nsAString& aMimeType); michael@0: nsMimeType(nsPIDOMWindow* aWindow, const nsAString& aMimeType); michael@0: virtual ~nsMimeType(); michael@0: michael@0: nsPIDOMWindow* GetParentObject() const; michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: const nsString& Type() const michael@0: { michael@0: return mType; michael@0: } michael@0: michael@0: // MimeType WebIDL methods michael@0: void GetDescription(nsString& retval) const; michael@0: nsPluginElement *GetEnabledPlugin() const; michael@0: void GetSuffixes(nsString& retval) const; michael@0: void GetType(nsString& retval) const; michael@0: michael@0: protected: michael@0: nsCOMPtr mWindow; michael@0: michael@0: // Strong reference to the active plugin, if any. Note that this michael@0: // creates an explicit reference cycle through the plugin element's michael@0: // mimetype array. We rely on the cycle collector to break this michael@0: // cycle. michael@0: nsRefPtr mPluginElement; michael@0: uint32_t mPluginTagMimeIndex; michael@0: nsString mType; michael@0: }; michael@0: michael@0: #endif /* nsMimeTypeArray_h___ */