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 nsMimeTypeArray_h___
8 #define nsMimeTypeArray_h___
10 #include "nsString.h"
11 #include "nsTArray.h"
12 #include "nsWrapperCache.h"
13 #include "nsAutoPtr.h"
14 #include "nsPIDOMWindow.h"
16 class nsMimeType;
17 class nsPluginElement;
19 class nsMimeTypeArray MOZ_FINAL : public nsISupports,
20 public nsWrapperCache
21 {
22 public:
23 nsMimeTypeArray(nsPIDOMWindow* aWindow);
24 virtual ~nsMimeTypeArray();
26 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsMimeTypeArray)
29 nsPIDOMWindow* GetParentObject() const;
30 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
32 void Refresh();
34 // MimeTypeArray WebIDL methods
35 nsMimeType* Item(uint32_t index);
36 nsMimeType* NamedItem(const nsAString& name);
37 nsMimeType* IndexedGetter(uint32_t index, bool &found);
38 nsMimeType* NamedGetter(const nsAString& name, bool &found);
39 bool NameIsEnumerable(const nsAString& name);
40 uint32_t Length();
41 void GetSupportedNames(unsigned, nsTArray< nsString >& retval);
43 protected:
44 void EnsurePluginMimeTypes();
45 void Clear();
47 nsCOMPtr<nsPIDOMWindow> mWindow;
49 // mMimeTypes contains MIME types handled by non-hidden plugins, those
50 // popular plugins that must be exposed in navigator.plugins enumeration to
51 // avoid breaking web content. Likewise, mMimeTypes are exposed in
52 // navigator.mimeTypes enumeration.
53 nsTArray<nsRefPtr<nsMimeType> > mMimeTypes;
55 // mHiddenMimeTypes contains MIME types handled by plugins hidden from
56 // navigator.plugins enumeration or by an OS PreferredApplicationHandler.
57 // mHiddenMimeTypes are hidden from navigator.mimeTypes enumeration.
58 nsTArray<nsRefPtr<nsMimeType> > mHiddenMimeTypes;
59 };
61 class nsMimeType MOZ_FINAL : public nsWrapperCache
62 {
63 public:
64 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsMimeType)
65 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsMimeType)
67 nsMimeType(nsPIDOMWindow* aWindow, nsPluginElement* aPluginElement,
68 uint32_t aPluginTagMimeIndex, const nsAString& aMimeType);
69 nsMimeType(nsPIDOMWindow* aWindow, const nsAString& aMimeType);
70 virtual ~nsMimeType();
72 nsPIDOMWindow* GetParentObject() const;
73 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
75 const nsString& Type() const
76 {
77 return mType;
78 }
80 // MimeType WebIDL methods
81 void GetDescription(nsString& retval) const;
82 nsPluginElement *GetEnabledPlugin() const;
83 void GetSuffixes(nsString& retval) const;
84 void GetType(nsString& retval) const;
86 protected:
87 nsCOMPtr<nsPIDOMWindow> mWindow;
89 // Strong reference to the active plugin, if any. Note that this
90 // creates an explicit reference cycle through the plugin element's
91 // mimetype array. We rely on the cycle collector to break this
92 // cycle.
93 nsRefPtr<nsPluginElement> mPluginElement;
94 uint32_t mPluginTagMimeIndex;
95 nsString mType;
96 };
98 #endif /* nsMimeTypeArray_h___ */