1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 "nsWrapperCache.h"
12 #include "nsPIDOMWindow.h"
14 #include "mozilla/dom/BindingDeclarations.h"
17 class nsPluginElement
;
20 * Array class backing HTML's navigator.mimeTypes. This always holds
21 * references to the hard-coded set of PDF MIME types defined by HTML but it
22 * only consults them if "pdfjs.disabled" is false. There is never more
23 * than one of these per DOM window.
25 class nsMimeTypeArray final
: public nsISupports
, public nsWrapperCache
{
27 nsMimeTypeArray(nsPIDOMWindowInner
* aWindow
,
28 const mozilla::Array
<RefPtr
<nsMimeType
>, 2>& aMimeTypes
);
30 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsMimeTypeArray
)
33 nsPIDOMWindowInner
* GetParentObject() const;
34 virtual JSObject
* WrapObject(JSContext
* aCx
,
35 JS::Handle
<JSObject
*> aGivenProto
) override
;
37 // MimeTypeArray WebIDL methods
38 uint32_t Length() { return ForceNoPlugins() ? 0 : std::size(mMimeTypes
); }
40 nsMimeType
* Item(uint32_t aIndex
) {
42 return IndexedGetter(aIndex
, unused
);
45 nsMimeType
* NamedItem(const nsAString
& aName
) {
47 return NamedGetter(aName
, unused
);
50 nsMimeType
* IndexedGetter(uint32_t index
, bool& found
);
52 nsMimeType
* NamedGetter(const nsAString
& name
, bool& found
);
54 void GetSupportedNames(nsTArray
<nsString
>& retval
);
57 virtual ~nsMimeTypeArray();
59 bool ForceNoPlugins();
61 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
62 mozilla::Array
<RefPtr
<nsMimeType
>, 2> mMimeTypes
;
66 * Mime type class backing entries in HTML's navigator.mimeTypes array. There
67 * is a fixed set of these, as defined by HTML.
69 class nsMimeType final
: public nsWrapperCache
{
71 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsMimeType
)
72 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(nsMimeType
)
74 nsMimeType(nsPluginElement
* aPluginElement
, const nsAString
& aName
);
76 nsPluginElement
* GetParentObject() const { return mPluginElement
; }
78 virtual JSObject
* WrapObject(JSContext
* aCx
,
79 JS::Handle
<JSObject
*> aGivenProto
) override
;
81 // MimeType WebIDL methods
82 void GetDescription(mozilla::dom::DOMString
& retval
) const {
83 retval
.SetKnownLiveString(kMimeDescription
);
86 already_AddRefed
<nsPluginElement
> EnabledPlugin() const;
88 void GetSuffixes(mozilla::dom::DOMString
& retval
) const {
89 retval
.SetKnownLiveString(kMimeSuffix
);
92 void GetType(nsString
& retval
) const { retval
= mName
; }
93 const nsString
& Name() const { return mName
; }
96 virtual ~nsMimeType();
98 static constexpr nsLiteralString kMimeDescription
=
99 u
"Portable Document Format"_ns
;
100 static constexpr nsLiteralString kMimeSuffix
= u
"pdf"_ns
;
102 // Note that this creates an explicit reference cycle:
104 // nsMimeType -> nsPluginElement -> nsPluginArray ->
105 // nsMimeTypeArray -> nsMimeType
107 // We rely on the cycle collector to break this cycle.
108 RefPtr
<nsPluginElement
> mPluginElement
;
112 #endif /* nsMimeTypeArray_h___ */