Files
palemoon27/dom/base/nsPluginArray.cpp
T
roytam1 ee118c4b83 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1051146 - Part 1: Introduce the B2G specific build flags, initially enabled. r=smaug (341c7565d)
-  Bug 1051146 - art 2: Introduce the new Pocketsphinx and Sphinxbase code with no build integration. r=smaug, r=gerv (f29eafa78)
- Bug 1051146 - Part 3: Introduce build system changes for the new Pocketsphinx and Sphinxbase code. r=smaug, r=gps (06c60429d)
- Bug 1051146 - Part 4: Introduce build system changes for the MOZ_WEBSPEECH_TEST_BACKEND flag. r=smaug, r=gps (16195e66e)
- Bug 1051146 - Part 5: Introduce new English model with no build integration. r=smaug (24996aa9c)
- Bug 1051146 - Part 6: Introduce build integration of new English model. r=smaug, r=gps (b718751a9)
- Bug 1051146 - Part 7: Introduce update scripts for Pocketsphinx and Sphinxbase code. r=smaug (5a85c7ed2)
- Bug 1051148 - Part 1: Patch that introduces WebSpeech API implementation. r=smaug (d18e5d86e)
- Bug 1171249 - Modified configure.in so MOZ_WEBSPEECH undefined implies both MOZ_WEBSPEECH_TEST_BACKEND and MOZ_WEBSPEECH_MODELS are undefined. r=gps (47d13fc61)
- Bug 1051148 - Part 2: Patch that turns off the WebSpeech API implementation using flags. r=gps (8b2ceef89)
- Bug 1051146 - Disable Pocketsphinx building on Windows due to bustage. r=gps (48f4a1c27)
- Bug 1204703 - Make nsContentSecurityManager scriptable (r=sicking) (fb514951a)
- Bug 1215745: Safer implemetation of nsJarChannel::AsyncOpen2. r=ckerschb (3ad0270b4)
- partial of Bug 1178892 - Split the profiler into Core & Gecko files and break apart monolithic headers. r=mstange (eda571469)
- Bug 1213407 - PluginModuleContentParent should delete its Transport. r=billm (153a54404)
- Bug 1169945 - Remove unused plugins.enumerable_names whitelist. r=bsmedberg (52126cbd8)
- Bug 1160166 - Disabled plugin meta information often isn't available to content processes. r=jimm (d63331192)
- Bug 1165981 - Only allow flash as a plugin on Windows 64-bit builds; r=bsmedberg (bfc073186)
- missing bit of 1164543 (5ef55bc55)
- Bug 1178963 part 1. Use nsIPluginTagInternal instead of nsPluginTag in cases where it may be nsFakePluginTag. r=peterv (f8702aead)
- Bug 1200484 (part 1) - Expose the column number in JS::DescribeScriptedCaller(). r=luke. (85cf65a1c)
- Bug 1200484 (part 2) - Use JS column numbers in ReportWrapperDenial(). r=mrbkap. (1de0e6331)
- Bug 1200484 (part 3) - Use JS column numbers in WebSocket.cpp. r=baku. (3febdd8bc)
- Bug 1200484 (part 4) - Expose the column number in nsJSUtils::GetCallingLocation(). r=mrbkap. (479ae5e2a)
- Bug 1200484 (part 5) - Use JS column numbers in XPCNativeInterface::NewInstance(). r=mrbkap. (63e5e4e41)
- Bug 1200484 (part 6) - Use JS column numbers in ContentParent::OnChannelError(). r=billm. (4c84ef09d)
- Bug 1139718 - Warning when sending MM messages that include XPCOM data (r=smaug) (d50774823)
- Bug 1200484 (part 7) - Use JS column numbers in GetParamsForMessage() (bf19fc4cb)
- Bug 1200484 (part 8) - Use JS column numbers in EventSource. r=khuey. (64374ed83)
- Bug 1200484 (part 9) - Use JS column numbers in nsContentUtils::ReportToConsoleNonLocalized. r=khuey. (4d81c5f4f)
- Bug 1200484 (part 10) - Use JS column numbers in indexedDB. r=khuey. (64eec5da6)
- Bug 1200484 (part 11) - Set source location when initializing an nsJSScriptTimeoutHandler from a Function. r=peterv. (f135b3a2c)
- Bug 1200484 (part 12) - Use JS column numbers in nsJSTimeoutHandler. r=peterv. (8ec21dc04)
- Bug 1163664 - Don't check for plugin blocklist state on Android. r=jimm, r=jchen (14b8f3e57)
- Bug 1178963 part 2. Implement nsFakePluginTag to represent a non-NPAPI "plugin" that is actually implemented in JavaScript. r=peterv (ba11d6de0)
- Bug 1178896 - Add support for determining if a plugin is OOP to nsIPluginHost. r=aklotz (e8689641f)
- Bug 1178963 part 3. Make nsPluginHost aware of fake plugins. r=peterv (a2a9f8cb3)
2021-11-01 11:54:37 +08:00

477 lines
10 KiB
C++

/* -*- 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 "nsPluginArray.h"
#include "mozilla/dom/PluginArrayBinding.h"
#include "mozilla/dom/PluginBinding.h"
#include "nsMimeTypeArray.h"
#include "Navigator.h"
#include "nsIDocShell.h"
#include "nsIWebNavigation.h"
#include "nsPluginHost.h"
#include "nsPluginTags.h"
#include "nsIObserverService.h"
#include "nsIWeakReference.h"
#include "mozilla/Services.h"
#include "nsIInterfaceRequestorUtils.h"
using namespace mozilla;
using namespace mozilla::dom;
nsPluginArray::nsPluginArray(nsPIDOMWindow* aWindow)
: mWindow(aWindow)
{
}
void
nsPluginArray::Init()
{
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService) {
obsService->AddObserver(this, "plugin-info-updated", true);
}
}
nsPluginArray::~nsPluginArray()
{
}
nsPIDOMWindow*
nsPluginArray::GetParentObject() const
{
MOZ_ASSERT(mWindow);
return mWindow;
}
JSObject*
nsPluginArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return PluginArrayBinding::Wrap(aCx, this, aGivenProto);
}
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPluginArray)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPluginArray)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPluginArray)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPluginArray,
mWindow,
mPlugins)
static void
GetPluginMimeTypes(const nsTArray<nsRefPtr<nsPluginElement> >& aPlugins,
nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes)
{
for (uint32_t i = 0; i < aPlugins.Length(); ++i) {
nsPluginElement *plugin = aPlugins[i];
aMimeTypes.AppendElements(plugin->MimeTypes());
}
}
static bool
operator<(const nsRefPtr<nsMimeType>& lhs, const nsRefPtr<nsMimeType>& rhs)
{
// Sort MIME types alphabetically by type name.
return lhs->Type() < rhs->Type();
}
void
nsPluginArray::GetMimeTypes(nsTArray<nsRefPtr<nsMimeType>>& aMimeTypes)
{
aMimeTypes.Clear();
if (!AllowPlugins()) {
return;
}
EnsurePlugins();
GetPluginMimeTypes(mPlugins, aMimeTypes);
// Alphabetize the enumeration order of non-hidden MIME types to reduce
// fingerprintable entropy based on plugins' installation file times.
aMimeTypes.Sort();
}
nsPluginElement*
nsPluginArray::Item(uint32_t aIndex)
{
bool unused;
return IndexedGetter(aIndex, unused);
}
nsPluginElement*
nsPluginArray::NamedItem(const nsAString& aName)
{
bool unused;
return NamedGetter(aName, unused);
}
void
nsPluginArray::Refresh(bool aReloadDocuments)
{
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if(!AllowPlugins() || !pluginHost) {
return;
}
// NS_ERROR_PLUGINS_PLUGINSNOTCHANGED on reloading plugins indicates
// that plugins did not change and was not reloaded
if (pluginHost->ReloadPlugins() ==
NS_ERROR_PLUGINS_PLUGINSNOTCHANGED) {
nsTArray<nsCOMPtr<nsIInternalPluginTag> > newPluginTags;
pluginHost->GetPlugins(newPluginTags);
// Check if the number of plugins we know about are different from
// the number of plugin tags the plugin host knows about. If the
// lengths are different, we refresh. This is safe because we're
// notified for every plugin enabling/disabling event that
// happens, and therefore the lengths will be in sync only when
// the both arrays contain the same plugin tags (though as
// different types).
if (newPluginTags.Length() == mPlugins.Length()) {
return;
}
}
mPlugins.Clear();
nsCOMPtr<nsIDOMNavigator> navigator;
mWindow->GetNavigator(getter_AddRefs(navigator));
if (!navigator) {
return;
}
static_cast<mozilla::dom::Navigator*>(navigator.get())->RefreshMIMEArray();
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
if (aReloadDocuments && webNav) {
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
}
}
nsPluginElement*
nsPluginArray::IndexedGetter(uint32_t aIndex, bool &aFound)
{
aFound = false;
if (!AllowPlugins()) {
return nullptr;
}
EnsurePlugins();
aFound = aIndex < mPlugins.Length();
if (!aFound) {
return nullptr;
}
return mPlugins[aIndex];
}
void
nsPluginArray::Invalidate()
{
nsCOMPtr<nsIObserverService> obsService =
mozilla::services::GetObserverService();
if (obsService) {
obsService->RemoveObserver(this, "plugin-info-updated");
}
}
static nsPluginElement*
FindPlugin(const nsTArray<nsRefPtr<nsPluginElement> >& aPlugins,
const nsAString& aName)
{
for (uint32_t i = 0; i < aPlugins.Length(); ++i) {
nsAutoString pluginName;
nsPluginElement* plugin = aPlugins[i];
plugin->GetName(pluginName);
if (pluginName.Equals(aName)) {
return plugin;
}
}
return nullptr;
}
nsPluginElement*
nsPluginArray::NamedGetter(const nsAString& aName, bool &aFound)
{
aFound = false;
if (!AllowPlugins()) {
return nullptr;
}
EnsurePlugins();
nsPluginElement* plugin = FindPlugin(mPlugins, aName);
aFound = (plugin != nullptr);
return plugin;
}
bool
nsPluginArray::NameIsEnumerable(const nsAString& aName)
{
return true;
}
uint32_t
nsPluginArray::Length()
{
if (!AllowPlugins()) {
return 0;
}
EnsurePlugins();
return mPlugins.Length();
}
void
nsPluginArray::GetSupportedNames(unsigned, nsTArray<nsString>& aRetval)
{
aRetval.Clear();
if (!AllowPlugins()) {
return;
}
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
nsAutoString pluginName;
mPlugins[i]->GetName(pluginName);
aRetval.AppendElement(pluginName);
}
}
NS_IMETHODIMP
nsPluginArray::Observe(nsISupports *aSubject, const char *aTopic,
const char16_t *aData) {
if (!nsCRT::strcmp(aTopic, "plugin-info-updated")) {
Refresh(false);
}
return NS_OK;
}
bool
nsPluginArray::AllowPlugins() const
{
nsCOMPtr<nsIDocShell> docShell = mWindow ? mWindow->GetDocShell() : nullptr;
return docShell && docShell->PluginsAllowedInCurrentDoc();
}
static bool
operator<(const nsRefPtr<nsPluginElement>& lhs,
const nsRefPtr<nsPluginElement>& rhs)
{
// Sort plugins alphabetically by name.
return lhs->PluginTag()->Name() < rhs->PluginTag()->Name();
}
void
nsPluginArray::EnsurePlugins()
{
if (!mPlugins.IsEmpty()) {
// We already have an array of plugin elements.
return;
}
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
if (!pluginHost) {
// We have no plugin host.
return;
}
nsTArray<nsCOMPtr<nsIInternalPluginTag> > pluginTags;
pluginHost->GetPlugins(pluginTags);
// need to wrap each of these with a nsPluginElement, which is
// scriptable.
for (uint32_t i = 0; i < pluginTags.Length(); ++i) {
mPlugins.AppendElement(new nsPluginElement(mWindow, pluginTags[i]));
}
// Alphabetize the enumeration order of non-hidden plugins to reduce
// fingerprintable entropy based on plugins' installation file times.
mPlugins.Sort();
}
// nsPluginElement implementation.
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPluginElement)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPluginElement)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPluginElement)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPluginElement, mWindow, mMimeTypes)
nsPluginElement::nsPluginElement(nsPIDOMWindow* aWindow,
nsIInternalPluginTag* aPluginTag)
: mWindow(aWindow),
mPluginTag(aPluginTag)
{
}
nsPluginElement::~nsPluginElement()
{
}
nsPIDOMWindow*
nsPluginElement::GetParentObject() const
{
MOZ_ASSERT(mWindow);
return mWindow;
}
JSObject*
nsPluginElement::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return PluginBinding::Wrap(aCx, this, aGivenProto);
}
void
nsPluginElement::GetDescription(nsString& retval) const
{
CopyUTF8toUTF16(mPluginTag->Description(), retval);
}
void
nsPluginElement::GetFilename(nsString& retval) const
{
CopyUTF8toUTF16(mPluginTag->FileName(), retval);
}
void
nsPluginElement::GetVersion(nsString& retval) const
{
CopyUTF8toUTF16(mPluginTag->Version(), retval);
}
void
nsPluginElement::GetName(nsString& retval) const
{
CopyUTF8toUTF16(mPluginTag->Name(), retval);
}
nsMimeType*
nsPluginElement::Item(uint32_t aIndex)
{
EnsurePluginMimeTypes();
return mMimeTypes.SafeElementAt(aIndex);
}
nsMimeType*
nsPluginElement::NamedItem(const nsAString& aName)
{
bool unused;
return NamedGetter(aName, unused);
}
nsMimeType*
nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
{
EnsurePluginMimeTypes();
aFound = aIndex < mMimeTypes.Length();
if (!aFound) {
return nullptr;
}
return mMimeTypes[aIndex];
}
nsMimeType*
nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
{
EnsurePluginMimeTypes();
aFound = false;
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
if (mMimeTypes[i]->Type().Equals(aName)) {
aFound = true;
return mMimeTypes[i];
}
}
return nullptr;
}
bool
nsPluginElement::NameIsEnumerable(const nsAString& aName)
{
return true;
}
uint32_t
nsPluginElement::Length()
{
EnsurePluginMimeTypes();
return mMimeTypes.Length();
}
void
nsPluginElement::GetSupportedNames(unsigned, nsTArray<nsString>& retval)
{
EnsurePluginMimeTypes();
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
retval.AppendElement(mMimeTypes[i]->Type());
}
}
nsTArray<nsRefPtr<nsMimeType> >&
nsPluginElement::MimeTypes()
{
EnsurePluginMimeTypes();
return mMimeTypes;
}
void
nsPluginElement::EnsurePluginMimeTypes()
{
if (!mMimeTypes.IsEmpty()) {
return;
}
if (mPluginTag->MimeTypes().Length() != mPluginTag->MimeDescriptions().Length() ||
mPluginTag->MimeTypes().Length() != mPluginTag->Extensions().Length()) {
MOZ_ASSERT(false, "mime type arrays expected to be the same length");
return;
}
for (uint32_t i = 0; i < mPluginTag->MimeTypes().Length(); ++i) {
NS_ConvertUTF8toUTF16 type(mPluginTag->MimeTypes()[i]);
NS_ConvertUTF8toUTF16 description(mPluginTag->MimeDescriptions()[i]);
NS_ConvertUTF8toUTF16 extension(mPluginTag->Extensions()[i]);
mMimeTypes.AppendElement(new nsMimeType(mWindow, this, type, description,
extension));
}
}