Files
sousa-gecko/dom/base/nsMimeTypeArray.cpp
T
Masayuki Nakano 6388e58841 Bug 2044523 - Make nsPIDOMWindow.h stop including nsPIDOMWindowInlines.h r=dom-core-reviewers,geckoview-reviewers,media-playback-reviewers,webrtc-reviewers,win-reviewers,layout-reviewers,manuel,aosmond,smaug,bwc,gstoll,dholbert,farre,m_kato
This patch does not make some header files stop including the inline
header because fixing them require more changes.

Note that `#include "nsComponentManagerUtils.h"` is fixing a bustage
caused by "use of undeclared identifier 'do_CreateInstance'" error.

Differential Revision: https://phabricator.services.mozilla.com/D304432
2026-06-09 03:49:55 +00:00

104 lines
2.9 KiB
C++

/* 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/StaticPrefs_pdfjs.h"
#include "mozilla/dom/MimeTypeArrayBinding.h"
#include "mozilla/dom/MimeTypeBinding.h"
#include "nsContentUtils.h"
#include "nsPIDOMWindowInlines.h"
#include "nsPluginArray.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<RefPtr<nsMimeType>, 2>& aMimeTypes)
: mWindow(aWindow), mMimeTypes(aMimeTypes) {}
nsMimeTypeArray::~nsMimeTypeArray() = default;
JSObject* nsMimeTypeArray::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> 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 < std::size(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<nsString>& retval) {
if (ForceNoPlugins()) {
return;
}
for (auto& mimeType : mMimeTypes) {
retval.AppendElement(mimeType->Name());
}
}
bool nsMimeTypeArray::ForceNoPlugins() {
return StaticPrefs::pdfjs_disabled() &&
!nsContentUtils::ShouldResistFingerprinting(
mWindow ? mWindow->GetDocShell() : nullptr, RFPTarget::PdfjsSpoof);
}
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<JSObject*> aGivenProto) {
return MimeType_Binding::Wrap(aCx, this, aGivenProto);
}
already_AddRefed<nsPluginElement> nsMimeType::EnabledPlugin() const {
return do_AddRef(mPluginElement);
}