Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / nsMimeTypeArray.h
blobaaeedba3ae2621261afd98190136f1e9124adf26
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"
11 #include "nsCOMPtr.h"
12 #include "nsPIDOMWindow.h"
13 #include "nsTArray.h"
14 #include "mozilla/dom/BindingDeclarations.h"
16 class nsMimeType;
17 class nsPluginElement;
19 /**
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 {
26 public:
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 : ArrayLength(mMimeTypes); }
40 nsMimeType* Item(uint32_t aIndex) {
41 bool unused;
42 return IndexedGetter(aIndex, unused);
45 nsMimeType* NamedItem(const nsAString& aName) {
46 bool unused;
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);
56 protected:
57 virtual ~nsMimeTypeArray();
59 bool ForceNoPlugins();
61 nsCOMPtr<nsPIDOMWindowInner> mWindow;
62 mozilla::Array<RefPtr<nsMimeType>, 2> mMimeTypes;
65 /**
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 {
70 public:
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 {
87 return do_AddRef(mPluginElement);
90 void GetSuffixes(mozilla::dom::DOMString& retval) const {
91 retval.SetKnownLiveString(kMimeSuffix);
94 void GetType(nsString& retval) const { retval = mName; }
95 const nsString& Name() const { return mName; }
97 protected:
98 virtual ~nsMimeType();
100 static constexpr nsLiteralString kMimeDescription =
101 u"Portable Document Format"_ns;
102 static constexpr nsLiteralString kMimeSuffix = u"pdf"_ns;
104 // Note that this creates an explicit reference cycle:
106 // nsMimeType -> nsPluginElement -> nsPluginArray ->
107 // nsMimeTypeArray -> nsMimeType
109 // We rely on the cycle collector to break this cycle.
110 RefPtr<nsPluginElement> mPluginElement;
111 nsString mName;
114 #endif /* nsMimeTypeArray_h___ */