From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/base/nsMimeTypeArray.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 dom/base/nsMimeTypeArray.cpp (limited to 'dom/base/nsMimeTypeArray.cpp') diff --git a/dom/base/nsMimeTypeArray.cpp b/dom/base/nsMimeTypeArray.cpp new file mode 100644 index 0000000000..4d15e1d8a2 --- /dev/null +++ b/dom/base/nsMimeTypeArray.cpp @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsMimeTypeArray.h" + +#include "mozilla/dom/MimeTypeArrayBinding.h" +#include "mozilla/dom/MimeTypeBinding.h" +#include "nsPluginArray.h" +#include "mozilla/StaticPrefs_pdfjs.h" +#include "nsContentUtils.h" + +using namespace mozilla; +using namespace mozilla::dom; + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsMimeTypeArray) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsMimeTypeArray) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsMimeTypeArray) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsMimeTypeArray, mWindow, mMimeTypes[0], + mMimeTypes[1]) + +nsMimeTypeArray::nsMimeTypeArray( + nsPIDOMWindowInner* aWindow, + const mozilla::Array, 2>& aMimeTypes) + : mWindow(aWindow), mMimeTypes(aMimeTypes) {} + +nsMimeTypeArray::~nsMimeTypeArray() = default; + +JSObject* nsMimeTypeArray::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return MimeTypeArray_Binding::Wrap(aCx, this, aGivenProto); +} + +nsPIDOMWindowInner* nsMimeTypeArray::GetParentObject() const { + MOZ_ASSERT(mWindow); + return mWindow; +} + +nsMimeType* nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool& aFound) { + if (!ForceNoPlugins() && aIndex < ArrayLength(mMimeTypes)) { + aFound = true; + return mMimeTypes[aIndex]; + } + + aFound = false; + return nullptr; +} + +nsMimeType* nsMimeTypeArray::NamedGetter(const nsAString& aName, bool& aFound) { + if (ForceNoPlugins()) { + aFound = false; + return nullptr; + } + + for (const auto& mimeType : mMimeTypes) { + if (mimeType->Name().Equals(aName)) { + aFound = true; + return mimeType; + } + } + + aFound = false; + return nullptr; +} + +void nsMimeTypeArray::GetSupportedNames(nsTArray& retval) { + if (ForceNoPlugins()) { + return; + } + + for (auto& mimeType : mMimeTypes) { + retval.AppendElement(mimeType->Name()); + } +} + +bool nsMimeTypeArray::ForceNoPlugins() { return StaticPrefs::pdfjs_disabled(); } + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsMimeType, mPluginElement) + +nsMimeType::nsMimeType(nsPluginElement* aPluginElement, const nsAString& aName) + : mPluginElement(aPluginElement), mName(aName) { + MOZ_ASSERT(aPluginElement); +} + +nsMimeType::~nsMimeType() = default; + +JSObject* nsMimeType::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return MimeType_Binding::Wrap(aCx, this, aGivenProto); +} -- cgit v1.2.3