2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsPluginArray.h"
|
2013-08-13 23:56:21 -07:00
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-07-09 06:58:21 -07:00
|
|
|
#include "mozilla/dom/PluginArrayBinding.h"
|
|
|
|
#include "mozilla/dom/PluginBinding.h"
|
2013-10-31 22:19:09 -07:00
|
|
|
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsMimeTypeArray.h"
|
2011-11-02 06:44:16 -07:00
|
|
|
#include "Navigator.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2011-05-21 06:28:54 -07:00
|
|
|
#include "nsPluginHost.h"
|
2013-07-09 06:58:21 -07:00
|
|
|
#include "nsPluginTags.h"
|
2013-04-10 13:59:45 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIWeakReference.h"
|
|
|
|
#include "mozilla/Services.h"
|
2013-07-09 06:58:21 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2013-08-28 13:55:29 -07:00
|
|
|
nsPluginArray::nsPluginArray(nsPIDOMWindow* aWindow)
|
2013-07-09 06:58:21 -07:00
|
|
|
: mWindow(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-10 13:59:45 -07:00
|
|
|
void
|
|
|
|
nsPluginArray::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
|
|
|
obsService->AddObserver(this, "plugin-info-updated", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPluginArray::~nsPluginArray()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPIDOMWindow*
|
|
|
|
nsPluginArray::GetParentObject() const
|
|
|
|
{
|
2013-08-28 13:55:29 -07:00
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
return mWindow;
|
2013-07-09 06:58:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
nsPluginArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-09 06:58:21 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return PluginArrayBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-09 06:58:21 -07:00
|
|
|
}
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
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)
|
2013-04-10 13:59:45 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPluginArray,
|
|
|
|
mWindow,
|
|
|
|
mPlugins,
|
|
|
|
mHiddenPlugins)
|
2013-10-31 22:19:09 -07:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-18 00:56:14 -07:00
|
|
|
static bool
|
|
|
|
operator<(const nsRefPtr<nsMimeType>& lhs, const nsRefPtr<nsMimeType>& rhs)
|
|
|
|
{
|
|
|
|
// Sort MIME types alphabetically by type name.
|
|
|
|
return lhs->Type() < rhs->Type();
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
2013-10-31 22:19:09 -07:00
|
|
|
nsPluginArray::GetMimeTypes(nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes,
|
|
|
|
nsTArray<nsRefPtr<nsMimeType> >& aHiddenMimeTypes)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-17 00:19:43 -07:00
|
|
|
aMimeTypes.Clear();
|
2013-10-31 22:19:09 -07:00
|
|
|
aHiddenMimeTypes.Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-01 00:28:16 -08:00
|
|
|
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePlugins();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
GetPluginMimeTypes(mPlugins, aMimeTypes);
|
|
|
|
GetPluginMimeTypes(mHiddenPlugins, aHiddenMimeTypes);
|
2012-09-18 00:56:14 -07:00
|
|
|
|
|
|
|
// Alphabetize the enumeration order of non-hidden MIME types to reduce
|
|
|
|
// fingerprintable entropy based on plugins' installation file times.
|
|
|
|
aMimeTypes.Sort();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPluginElement*
|
|
|
|
nsPluginArray::Item(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
bool unused;
|
|
|
|
return IndexedGetter(aIndex, unused);
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPluginElement*
|
|
|
|
nsPluginArray::NamedItem(const nsAString& aName)
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
bool unused;
|
|
|
|
return NamedGetter(aName, unused);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
|
|
|
nsPluginArray::Refresh(bool aReloadDocuments)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
if(!AllowPlugins() || !pluginHost) {
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
// 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<nsRefPtr<nsPluginTag> > 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).
|
2013-10-31 22:19:09 -07:00
|
|
|
uint32_t pluginCount = mPlugins.Length() + mHiddenPlugins.Length();
|
|
|
|
if (newPluginTags.Length() == pluginCount) {
|
2013-07-09 06:58:21 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
mPlugins.Clear();
|
2013-10-31 22:19:09 -07:00
|
|
|
mHiddenPlugins.Clear();
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsCOMPtr<nsIDOMNavigator> navigator;
|
2013-08-28 13:55:29 -07:00
|
|
|
mWindow->GetNavigator(getter_AddRefs(navigator));
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
if (!navigator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static_cast<mozilla::dom::Navigator*>(navigator.get())->RefreshMIMEArray();
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2013-08-28 13:55:29 -07:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
|
2013-07-09 06:58:21 -07:00
|
|
|
if (aReloadDocuments && webNav) {
|
|
|
|
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPluginElement*
|
|
|
|
nsPluginArray::IndexedGetter(uint32_t aIndex, bool &aFound)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
aFound = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePlugins();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
aFound = aIndex < mPlugins.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
return aFound ? mPlugins[aIndex] : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-12 21:05:05 -07:00
|
|
|
void
|
|
|
|
nsPluginArray::Invalidate()
|
|
|
|
{
|
2013-04-10 13:59:45 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
|
|
|
obsService->RemoveObserver(this, "plugin-info-updated");
|
|
|
|
}
|
2010-08-12 21:05:05 -07:00
|
|
|
}
|
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPluginElement*
|
|
|
|
nsPluginArray::NamedGetter(const nsAString& aName, bool &aFound)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
aFound = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePlugins();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
nsPluginElement* plugin = FindPlugin(mPlugins, aName);
|
|
|
|
if (!plugin) {
|
|
|
|
plugin = FindPlugin(mHiddenPlugins, aName);
|
2013-07-09 06:58:21 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
aFound = (plugin != nullptr);
|
|
|
|
return plugin;
|
2013-07-09 06:58:21 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-15 19:58:44 -07:00
|
|
|
bool
|
|
|
|
nsPluginArray::NameIsEnumerable(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
uint32_t
|
|
|
|
nsPluginArray::Length()
|
|
|
|
{
|
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePlugins();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
return mPlugins.Length();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
2014-04-15 19:58:44 -07:00
|
|
|
nsPluginArray::GetSupportedNames(unsigned, nsTArray<nsString>& aRetval)
|
2013-07-09 06:58:21 -07:00
|
|
|
{
|
|
|
|
aRetval.Clear();
|
|
|
|
|
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
|
|
|
|
nsAutoString pluginName;
|
|
|
|
mPlugins[i]->GetName(pluginName);
|
|
|
|
|
|
|
|
aRetval.AppendElement(pluginName);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 13:59:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginArray::Observe(nsISupports *aSubject, const char *aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aData) {
|
2013-04-10 13:59:45 -07:00
|
|
|
if (!nsCRT::strcmp(aTopic, "plugin-info-updated")) {
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
bool
|
|
|
|
nsPluginArray::AllowPlugins() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = mWindow ? mWindow->GetDocShell() : nullptr;
|
2013-07-09 06:58:21 -07:00
|
|
|
|
|
|
|
return docShell && docShell->PluginsAllowedInCurrentDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
static bool
|
|
|
|
HasStringPrefix(const nsCString& str, const nsACString& prefix) {
|
|
|
|
return str.Compare(prefix.BeginReading(), false, prefix.Length()) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsPluginEnumerable(const nsTArray<nsCString>& enumerableNames,
|
|
|
|
const nsPluginTag* pluginTag)
|
|
|
|
{
|
|
|
|
const nsCString& pluginName = pluginTag->mName;
|
|
|
|
|
|
|
|
const uint32_t length = enumerableNames.Length();
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
const nsCString& name = enumerableNames[i];
|
|
|
|
if (HasStringPrefix(pluginName, name)) {
|
|
|
|
return true; // don't hide plugin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // hide plugin!
|
|
|
|
}
|
|
|
|
|
2012-09-18 00:56:14 -07:00
|
|
|
static bool
|
|
|
|
operator<(const nsRefPtr<nsPluginElement>& lhs,
|
|
|
|
const nsRefPtr<nsPluginElement>& rhs)
|
|
|
|
{
|
|
|
|
// Sort plugins alphabetically by name.
|
|
|
|
return lhs->PluginTag()->mName < rhs->PluginTag()->mName;
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
|
|
|
nsPluginArray::EnsurePlugins()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-31 22:19:09 -07:00
|
|
|
if (!mPlugins.IsEmpty() || !mHiddenPlugins.IsEmpty()) {
|
2013-10-20 00:05:05 -07:00
|
|
|
// We already have an array of plugin elements.
|
|
|
|
return;
|
|
|
|
}
|
2013-07-09 06:58:21 -07:00
|
|
|
|
2013-10-20 00:05:05 -07:00
|
|
|
nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
|
|
|
if (!pluginHost) {
|
|
|
|
// We have no plugin host.
|
2013-07-09 06:58:21 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsTArray<nsRefPtr<nsPluginTag> > pluginTags;
|
|
|
|
pluginHost->GetPlugins(pluginTags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-31 22:19:09 -07:00
|
|
|
nsTArray<nsCString> enumerableNames;
|
|
|
|
|
|
|
|
const nsAdoptingCString& enumerableNamesPref =
|
|
|
|
Preferences::GetCString("plugins.enumerable_names");
|
|
|
|
|
|
|
|
bool disablePluginHiding = !enumerableNamesPref ||
|
|
|
|
enumerableNamesPref.EqualsLiteral("*");
|
|
|
|
|
|
|
|
if (!disablePluginHiding) {
|
|
|
|
nsCCharSeparatedTokenizer tokens(enumerableNamesPref, ',');
|
|
|
|
while (tokens.hasMoreTokens()) {
|
|
|
|
const nsCSubstring& token = tokens.nextToken();
|
|
|
|
if (!token.IsEmpty()) {
|
|
|
|
enumerableNames.AppendElement(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
// need to wrap each of these with a nsPluginElement, which is
|
|
|
|
// scriptable.
|
|
|
|
for (uint32_t i = 0; i < pluginTags.Length(); ++i) {
|
2013-10-31 22:19:09 -07:00
|
|
|
nsPluginTag* pluginTag = pluginTags[i];
|
|
|
|
|
|
|
|
// Add the plugin to the list of hidden plugins or non-hidden plugins?
|
|
|
|
nsTArray<nsRefPtr<nsPluginElement> >& pluginArray =
|
|
|
|
(disablePluginHiding || IsPluginEnumerable(enumerableNames, pluginTag))
|
|
|
|
? mPlugins
|
|
|
|
: mHiddenPlugins;
|
|
|
|
|
|
|
|
pluginArray.AppendElement(new nsPluginElement(mWindow, pluginTag));
|
2013-07-09 06:58:21 -07:00
|
|
|
}
|
2012-09-18 00:56:14 -07:00
|
|
|
|
|
|
|
// Alphabetize the enumeration order of non-hidden plugins to reduce
|
|
|
|
// fingerprintable entropy based on plugins' installation file times.
|
|
|
|
mPlugins.Sort();
|
2013-07-09 06:58:21 -07:00
|
|
|
}
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
// 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
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPluginElement, mWindow, mMimeTypes)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-28 13:55:29 -07:00
|
|
|
nsPluginElement::nsPluginElement(nsPIDOMWindow* aWindow,
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPluginTag* aPluginTag)
|
|
|
|
: mWindow(aWindow),
|
|
|
|
mPluginTag(aPluginTag)
|
|
|
|
{
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-30 16:00:30 -07:00
|
|
|
nsPluginElement::~nsPluginElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsPIDOMWindow*
|
|
|
|
nsPluginElement::GetParentObject() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-28 13:55:29 -07:00
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
return mWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
nsPluginElement::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2009-04-22 12:13:10 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return PluginBinding::Wrap(aCx, this, aGivenProto);
|
2009-04-22 12:13:10 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
|
|
|
nsPluginElement::GetDescription(nsString& retval) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
CopyUTF8toUTF16(mPluginTag->mDescription, retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
|
|
|
nsPluginElement::GetFilename(nsString& retval) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
CopyUTF8toUTF16(mPluginTag->mFileName, retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
|
|
|
nsPluginElement::GetVersion(nsString& retval) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-09 06:58:21 -07:00
|
|
|
CopyUTF8toUTF16(mPluginTag->mVersion, retval);
|
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
|
|
|
nsPluginElement::GetName(nsString& retval) const
|
|
|
|
{
|
|
|
|
CopyUTF8toUTF16(mPluginTag->mName, retval);
|
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::Item(uint32_t aIndex)
|
|
|
|
{
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
return mMimeTypes.SafeElementAt(aIndex);
|
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::NamedItem(const nsAString& aName)
|
|
|
|
{
|
|
|
|
bool unused;
|
|
|
|
return NamedGetter(aName, unused);
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
aFound = aIndex < mMimeTypes.Length();
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
return aFound ? mMimeTypes[aIndex] : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePluginMimeTypes();
|
2013-07-09 06:58:21 -07:00
|
|
|
|
|
|
|
aFound = false;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
|
|
|
|
if (mMimeTypes[i]->Type().Equals(aName)) {
|
|
|
|
aFound = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
return mMimeTypes[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-31 14:40:35 -07:00
|
|
|
}
|
|
|
|
|
2014-04-15 19:58:44 -07:00
|
|
|
bool
|
|
|
|
nsPluginElement::NameIsEnumerable(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
uint32_t
|
|
|
|
nsPluginElement::Length()
|
2008-10-31 14:40:35 -07:00
|
|
|
{
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
return mMimeTypes.Length();
|
|
|
|
}
|
2008-10-31 14:40:35 -07:00
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
void
|
2014-04-15 19:58:44 -07:00
|
|
|
nsPluginElement::GetSupportedNames(unsigned, nsTArray<nsString>& retval)
|
2013-07-09 06:58:21 -07:00
|
|
|
{
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePluginMimeTypes();
|
2013-07-09 06:58:21 -07:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
|
|
|
|
retval.AppendElement(mMimeTypes[i]->Type());
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsTArray<nsRefPtr<nsMimeType> >&
|
|
|
|
nsPluginElement::MimeTypes()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-20 00:05:05 -07:00
|
|
|
EnsurePluginMimeTypes();
|
2013-07-09 06:58:21 -07:00
|
|
|
|
|
|
|
return mMimeTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-20 00:05:05 -07:00
|
|
|
nsPluginElement::EnsurePluginMimeTypes()
|
2013-07-09 06:58:21 -07:00
|
|
|
{
|
|
|
|
if (!mMimeTypes.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mPluginTag->mMimeTypes.Length(); ++i) {
|
|
|
|
NS_ConvertUTF8toUTF16 type(mPluginTag->mMimeTypes[i]);
|
|
|
|
mMimeTypes.AppendElement(new nsMimeType(mWindow, this, i, type));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|