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 #include "nsMimeTypeArray.h"
9 #include "mozilla/dom/MimeTypeArrayBinding.h"
10 #include "mozilla/dom/MimeTypeBinding.h"
11 #include "nsPluginArray.h"
12 #include "mozilla/StaticPrefs_pdfjs.h"
13 #include "nsContentUtils.h"
15 using namespace mozilla
;
16 using namespace mozilla::dom
;
18 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsMimeTypeArray
)
19 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsMimeTypeArray
)
20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsMimeTypeArray
)
21 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 NS_INTERFACE_MAP_ENTRY(nsISupports
)
25 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsMimeTypeArray
, mWindow
, mMimeTypes
[0],
28 nsMimeTypeArray::nsMimeTypeArray(
29 nsPIDOMWindowInner
* aWindow
,
30 const mozilla::Array
<RefPtr
<nsMimeType
>, 2>& aMimeTypes
)
31 : mWindow(aWindow
), mMimeTypes(aMimeTypes
) {}
33 nsMimeTypeArray::~nsMimeTypeArray() = default;
35 JSObject
* nsMimeTypeArray::WrapObject(JSContext
* aCx
,
36 JS::Handle
<JSObject
*> aGivenProto
) {
37 return MimeTypeArray_Binding::Wrap(aCx
, this, aGivenProto
);
40 nsPIDOMWindowInner
* nsMimeTypeArray::GetParentObject() const {
45 nsMimeType
* nsMimeTypeArray::IndexedGetter(uint32_t aIndex
, bool& aFound
) {
46 if (!ForceNoPlugins() && aIndex
< ArrayLength(mMimeTypes
)) {
48 return mMimeTypes
[aIndex
];
55 nsMimeType
* nsMimeTypeArray::NamedGetter(const nsAString
& aName
, bool& aFound
) {
56 if (ForceNoPlugins()) {
61 for (const auto& mimeType
: mMimeTypes
) {
62 if (mimeType
->Name().Equals(aName
)) {
72 void nsMimeTypeArray::GetSupportedNames(nsTArray
<nsString
>& retval
) {
73 if (ForceNoPlugins()) {
77 for (auto& mimeType
: mMimeTypes
) {
78 retval
.AppendElement(mimeType
->Name());
82 bool nsMimeTypeArray::ForceNoPlugins() { return StaticPrefs::pdfjs_disabled(); }
84 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsMimeType
, mPluginElement
)
86 nsMimeType::nsMimeType(nsPluginElement
* aPluginElement
, const nsAString
& aName
)
87 : mPluginElement(aPluginElement
), mName(aName
) {
88 MOZ_ASSERT(aPluginElement
);
91 nsMimeType::~nsMimeType() = default;
93 JSObject
* nsMimeType::WrapObject(JSContext
* aCx
,
94 JS::Handle
<JSObject
*> aGivenProto
) {
95 return MimeType_Binding::Wrap(aCx
, this, aGivenProto
);
98 already_AddRefed
<nsPluginElement
> nsMimeType::EnabledPlugin() const {
99 return do_AddRef(mPluginElement
);