2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-04-20 23:18:51 +04:00
|
|
|
|
|
|
|
#include "nsPluginArray.h"
|
2013-08-14 10:56:21 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
#include "mozilla/dom/PluginArrayBinding.h"
|
|
|
|
#include "mozilla/dom/PluginBinding.h"
|
2015-08-04 02:24:35 +03:00
|
|
|
#include "mozilla/dom/HiddenPluginEvent.h"
|
2013-11-01 09:19:09 +04:00
|
|
|
|
1999-04-20 23:18:51 +04:00
|
|
|
#include "nsMimeTypeArray.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "Navigator.h"
|
2001-01-24 01:29:41 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2011-05-21 17:28:54 +04:00
|
|
|
#include "nsPluginHost.h"
|
2013-07-09 17:58:21 +04:00
|
|
|
#include "nsPluginTags.h"
|
2013-04-11 00:59:45 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIWeakReference.h"
|
|
|
|
#include "mozilla/Services.h"
|
2013-07-09 17:58:21 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2016-06-30 09:40:00 +03:00
|
|
|
#include "nsContentUtils.h"
|
2015-08-04 02:24:35 +03:00
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIDocument.h"
|
2016-10-05 16:46:45 +03:00
|
|
|
#include "nsIBlocklistService.h"
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPluginArray::nsPluginArray(nsPIDOMWindowInner* aWindow)
|
2013-07-09 17:58:21 +04:00
|
|
|
: mWindow(aWindow)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-11 00:59:45 +04:00
|
|
|
void
|
|
|
|
nsPluginArray::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
|
|
|
obsService->AddObserver(this, "plugin-info-updated", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-14 12:40:37 +03:00
|
|
|
nsPluginArray::~nsPluginArray() = default;
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginArray::GetParentObject() const
|
|
|
|
{
|
2013-08-29 00:55:29 +04:00
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
return mWindow;
|
2013-07-09 17:58:21 +04: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 17:13:33 +03:00
|
|
|
nsPluginArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-09 17:58:21 +04:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return PluginArray_Binding::Wrap(aCx, this, aGivenProto);
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2013-07-09 17:58:21 +04: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-11 00:59:45 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPluginArray,
|
|
|
|
mWindow,
|
2015-08-04 02:24:35 +03:00
|
|
|
mPlugins,
|
|
|
|
mCTPPlugins)
|
2013-11-01 09:19:09 +04:00
|
|
|
|
|
|
|
static void
|
2015-10-18 08:24:48 +03:00
|
|
|
GetPluginMimeTypes(const nsTArray<RefPtr<nsPluginElement> >& aPlugins,
|
|
|
|
nsTArray<RefPtr<nsMimeType> >& aMimeTypes)
|
2013-11-01 09:19:09 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aPlugins.Length(); ++i) {
|
|
|
|
nsPluginElement *plugin = aPlugins[i];
|
|
|
|
aMimeTypes.AppendElements(plugin->MimeTypes());
|
|
|
|
}
|
|
|
|
}
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2012-09-18 11:56:14 +04:00
|
|
|
static bool
|
2015-10-18 08:24:48 +03:00
|
|
|
operator<(const RefPtr<nsMimeType>& lhs, const RefPtr<nsMimeType>& rhs)
|
2012-09-18 11:56:14 +04:00
|
|
|
{
|
|
|
|
// Sort MIME types alphabetically by type name.
|
|
|
|
return lhs->Type() < rhs->Type();
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
nsPluginArray::GetMimeTypes(nsTArray<RefPtr<nsMimeType>>& aMimeTypes)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-10-17 11:19:43 +04:00
|
|
|
aMimeTypes.Clear();
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-01 12:28:16 +04:00
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePlugins();
|
2006-03-21 08:31:59 +03:00
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
GetPluginMimeTypes(mPlugins, aMimeTypes);
|
2012-09-18 11:56:14 +04:00
|
|
|
|
|
|
|
// Alphabetize the enumeration order of non-hidden MIME types to reduce
|
|
|
|
// fingerprintable entropy based on plugins' installation file times.
|
|
|
|
aMimeTypes.Sort();
|
2006-03-21 08:31:59 +03:00
|
|
|
}
|
|
|
|
|
2016-07-28 00:45:48 +03:00
|
|
|
void
|
|
|
|
nsPluginArray::GetCTPMimeTypes(nsTArray<RefPtr<nsMimeType>>& aMimeTypes)
|
|
|
|
{
|
|
|
|
aMimeTypes.Clear();
|
|
|
|
|
|
|
|
if (!AllowPlugins()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsurePlugins();
|
|
|
|
|
|
|
|
GetPluginMimeTypes(mCTPPlugins, aMimeTypes);
|
|
|
|
|
|
|
|
// Alphabetize the enumeration order of non-hidden MIME types to reduce
|
|
|
|
// fingerprintable entropy based on plugins' installation file times.
|
|
|
|
aMimeTypes.Sort();
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginElement*
|
2016-12-17 08:25:52 +03:00
|
|
|
nsPluginArray::Item(uint32_t aIndex, CallerType aCallerType)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
bool unused;
|
2016-12-17 08:25:52 +03:00
|
|
|
return IndexedGetter(aIndex, unused, aCallerType);
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginElement*
|
2016-12-17 08:25:52 +03:00
|
|
|
nsPluginArray::NamedItem(const nsAString& aName, CallerType aCallerType)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
bool unused;
|
2016-12-17 08:25:52 +03:00
|
|
|
return NamedGetter(aName, unused, aCallerType);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsPluginArray::Refresh(bool aReloadDocuments)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
if(!AllowPlugins() || !pluginHost) {
|
|
|
|
return;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04: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) {
|
2015-05-20 16:30:05 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIInternalPluginTag> > newPluginTags;
|
2013-07-09 17:58:21 +04:00
|
|
|
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).
|
2015-05-30 08:42:23 +03:00
|
|
|
if (newPluginTags.Length() == mPlugins.Length()) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
mPlugins.Clear();
|
2015-08-04 02:24:35 +03:00
|
|
|
mCTPPlugins.Clear();
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
RefPtr<Navigator> navigator = mWindow->Navigator();
|
|
|
|
navigator->RefreshMIMEArray();
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2013-08-29 00:55:29 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
|
2013-07-09 17:58:21 +04:00
|
|
|
if (aReloadDocuments && webNav) {
|
|
|
|
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginElement*
|
2016-12-17 08:25:52 +03:00
|
|
|
nsPluginArray::IndexedGetter(uint32_t aIndex, bool &aFound, CallerType aCallerType)
|
2001-04-05 02:12:26 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = false;
|
2001-04-05 02:12:26 +04:00
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2001-04-05 02:12:26 +04:00
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePlugins();
|
2001-04-05 02:12:26 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = aIndex < mPlugins.Length();
|
2001-04-05 02:12:26 +04:00
|
|
|
|
2015-08-13 15:22:48 +03:00
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPlugins[aIndex];
|
2001-04-05 02:12:26 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 08:05:05 +04:00
|
|
|
void
|
|
|
|
nsPluginArray::Invalidate()
|
|
|
|
{
|
2013-04-11 00:59:45 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
|
|
|
obsService->RemoveObserver(this, "plugin-info-updated");
|
|
|
|
}
|
2010-08-13 08:05:05 +04:00
|
|
|
}
|
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
static nsPluginElement*
|
2015-10-18 08:24:48 +03:00
|
|
|
FindPlugin(const nsTArray<RefPtr<nsPluginElement> >& aPlugins,
|
2013-11-01 09:19:09 +04:00
|
|
|
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 17:58:21 +04:00
|
|
|
nsPluginElement*
|
2016-12-17 08:25:52 +03:00
|
|
|
nsPluginArray::NamedGetter(const nsAString& aName, bool &aFound,
|
|
|
|
CallerType aCallerType)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = false;
|
2000-12-22 03:08:31 +03:00
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return nullptr;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePlugins();
|
2000-12-22 03:08:31 +03:00
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
nsPluginElement* plugin = FindPlugin(mPlugins, aName);
|
|
|
|
aFound = (plugin != nullptr);
|
2015-08-04 02:24:35 +03:00
|
|
|
if (!aFound) {
|
|
|
|
nsPluginElement* hiddenPlugin = FindPlugin(mCTPPlugins, aName);
|
|
|
|
if (hiddenPlugin) {
|
2016-07-28 00:45:48 +03:00
|
|
|
NotifyHiddenPluginTouched(hiddenPlugin);
|
2015-08-04 02:24:35 +03:00
|
|
|
}
|
|
|
|
}
|
2013-11-01 09:19:09 +04:00
|
|
|
return plugin;
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
2002-05-17 00:41:26 +04:00
|
|
|
|
2016-07-28 00:45:48 +03:00
|
|
|
void nsPluginArray::NotifyHiddenPluginTouched(nsPluginElement* aHiddenElement)
|
|
|
|
{
|
|
|
|
HiddenPluginEventInit init;
|
|
|
|
init.mTag = aHiddenElement->PluginTag();
|
|
|
|
nsCOMPtr<nsIDocument> doc = aHiddenElement->GetParentObject()->GetDoc();
|
|
|
|
RefPtr<HiddenPluginEvent> event =
|
|
|
|
HiddenPluginEvent::Constructor(doc, NS_LITERAL_STRING("HiddenPlugin"), init);
|
|
|
|
event->SetTarget(doc);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
|
2018-04-05 20:42:41 +03:00
|
|
|
doc->DispatchEvent(*event);
|
2016-07-28 00:45:48 +03:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
uint32_t
|
2016-12-17 08:25:52 +03:00
|
|
|
nsPluginArray::Length(CallerType aCallerType)
|
2013-07-09 17:58:21 +04:00
|
|
|
{
|
2016-12-17 08:25:52 +03:00
|
|
|
if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return 0;
|
2002-05-17 00:41:26 +04:00
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePlugins();
|
2002-05-17 00:41:26 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
return mPlugins.Length();
|
|
|
|
}
|
2001-01-24 01:29:41 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
2016-12-17 08:25:52 +03:00
|
|
|
nsPluginArray::GetSupportedNames(nsTArray<nsString>& aRetval,
|
|
|
|
CallerType aCallerType)
|
2013-07-09 17:58:21 +04:00
|
|
|
{
|
|
|
|
aRetval.Clear();
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mPlugins.Length(); ++i) {
|
|
|
|
nsAutoString pluginName;
|
|
|
|
mPlugins[i]->GetName(pluginName);
|
|
|
|
|
|
|
|
aRetval.AppendElement(pluginName);
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-11 00:59:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPluginArray::Observe(nsISupports *aSubject, const char *aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aData) {
|
2013-04-11 00:59:45 +04:00
|
|
|
if (!nsCRT::strcmp(aTopic, "plugin-info-updated")) {
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
bool
|
|
|
|
nsPluginArray::AllowPlugins() const
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2017-02-06 23:47:00 +03:00
|
|
|
if (!mWindow) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-09 17:58:21 +04:00
|
|
|
|
2017-02-06 23:47:00 +03:00
|
|
|
return doc->GetAllowPlugins();
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2012-09-18 11:56:14 +04:00
|
|
|
static bool
|
2015-10-18 08:24:48 +03:00
|
|
|
operator<(const RefPtr<nsPluginElement>& lhs,
|
|
|
|
const RefPtr<nsPluginElement>& rhs)
|
2012-09-18 11:56:14 +04:00
|
|
|
{
|
|
|
|
// Sort plugins alphabetically by name.
|
2015-05-20 16:30:05 +03:00
|
|
|
return lhs->PluginTag()->Name() < rhs->PluginTag()->Name();
|
2012-09-18 11:56:14 +04:00
|
|
|
}
|
|
|
|
|
2016-08-27 02:27:43 +03:00
|
|
|
static bool
|
2016-11-15 01:15:46 +03:00
|
|
|
PluginShouldBeHidden(const nsCString& aName) {
|
2016-08-27 02:27:43 +03:00
|
|
|
// This only supports one hidden plugin
|
2017-07-31 07:28:48 +03:00
|
|
|
nsAutoCString value;
|
|
|
|
Preferences::GetCString("plugins.navigator.hidden_ctp_plugin", value);
|
|
|
|
return value.Equals(aName);
|
2016-08-27 02:27:43 +03:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsPluginArray::EnsurePlugins()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2015-08-04 02:24:35 +03:00
|
|
|
if (!mPlugins.IsEmpty() || !mCTPPlugins.IsEmpty()) {
|
2013-10-20 11:05:05 +04:00
|
|
|
// We already have an array of plugin elements.
|
|
|
|
return;
|
|
|
|
}
|
2013-07-09 17:58:21 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
2013-10-20 11:05:05 +04:00
|
|
|
if (!pluginHost) {
|
|
|
|
// We have no plugin host.
|
2013-07-09 17:58:21 +04:00
|
|
|
return;
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2015-05-20 16:30:05 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIInternalPluginTag> > pluginTags;
|
2013-07-09 17:58:21 +04:00
|
|
|
pluginHost->GetPlugins(pluginTags);
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
// need to wrap each of these with a nsPluginElement, which is
|
|
|
|
// scriptable.
|
|
|
|
for (uint32_t i = 0; i < pluginTags.Length(); ++i) {
|
2015-08-04 02:24:35 +03:00
|
|
|
nsCOMPtr<nsPluginTag> pluginTag = do_QueryInterface(pluginTags[i]);
|
|
|
|
if (!pluginTag) {
|
|
|
|
mPlugins.AppendElement(new nsPluginElement(mWindow, pluginTags[i]));
|
|
|
|
} else if (pluginTag->IsActive()) {
|
|
|
|
uint32_t permission = nsIPermissionManager::ALLOW_ACTION;
|
2016-10-05 16:46:45 +03:00
|
|
|
uint32_t blocklistState;
|
|
|
|
if (pluginTag->IsClicktoplay() &&
|
|
|
|
NS_SUCCEEDED(pluginTag->GetBlocklistState(&blocklistState)) &&
|
|
|
|
blocklistState == nsIBlocklistService::STATE_NOT_BLOCKED) {
|
2015-08-04 02:24:35 +03:00
|
|
|
nsCString name;
|
|
|
|
pluginTag->GetName(name);
|
2016-08-27 02:27:43 +03:00
|
|
|
if (PluginShouldBeHidden(name)) {
|
2015-08-04 02:24:35 +03:00
|
|
|
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
|
|
|
nsCString permString;
|
|
|
|
nsresult rv = pluginHost->GetPermissionStringForTag(pluginTag, 0, permString);
|
|
|
|
if (rv == NS_OK) {
|
2017-01-23 19:45:44 +03:00
|
|
|
nsCOMPtr<nsIDocument> currentDoc = mWindow->GetExtantDoc();
|
|
|
|
|
|
|
|
// The top-level content document gets the final say on whether or not
|
|
|
|
// a plugin is going to be hidden or not, regardless of the origin
|
|
|
|
// that a subframe is hosted at. This is to avoid spamming the user
|
|
|
|
// with the hidden plugin notification bar when third-party iframes
|
|
|
|
// attempt to access navigator.plugins after the user has already
|
|
|
|
// expressed that the top-level document has this permission.
|
|
|
|
nsCOMPtr<nsIDocument> topDoc = currentDoc->GetTopLevelContentDocument();
|
|
|
|
|
|
|
|
if (topDoc) {
|
|
|
|
nsIPrincipal* principal = topDoc->NodePrincipal();
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
permMgr->TestPermissionFromPrincipal(principal, permString.get(), &permission);
|
|
|
|
}
|
2015-08-04 02:24:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (permission == nsIPermissionManager::ALLOW_ACTION) {
|
|
|
|
mPlugins.AppendElement(new nsPluginElement(mWindow, pluginTags[i]));
|
|
|
|
} else {
|
|
|
|
mCTPPlugins.AppendElement(new nsPluginElement(mWindow, pluginTags[i]));
|
|
|
|
}
|
|
|
|
}
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
2012-09-18 11:56:14 +04:00
|
|
|
|
2016-08-24 21:02:02 +03:00
|
|
|
if (mPlugins.Length() == 0 && mCTPPlugins.Length() != 0) {
|
2017-06-28 00:23:00 +03:00
|
|
|
nsCOMPtr<nsPluginTag> hiddenTag = new nsPluginTag("Hidden Plugin", nullptr, "dummy.plugin", nullptr, nullptr,
|
Bug 1371888 - cache plugin information in pluginreg.dat to avoid sync startup load, r=florian,mossop
This changes the pluginreg.dat format to include the blocklist state.
There is now only the saved blocklist state in a plugin tag instance, rather than
looking it up from in there using the blocklist service, so it was renamed from
mCachedBlocklistState to mBlocklistState. We pass the 'right' state to the plugin
instance when the plugintag is constructed. If we don't have state, we mark it as
unblocked.
mCachedBlocklistStateChanged was never read so it's being removed.
Bug 1439519 adds a 'blocklist-loaded' notification that is fired once the blocklist is loaded.
The plugin host implementation will listen to this in the parent process and update the
blocklist state of all the plugins, and broadcast changes to the child process, just like when
we update the blocklist from the server. We now also avoid re-sending plugin content to the
content processes if the plugin state hasn't changed as a result of the blocklist having been
loaded.
Finally, because new plugins should still get an up-to-date blocklist state, and
telemetry should get up-to-date data about which plugins are and aren't enabled
once we have that data, we ensure that once we've loaded the blocklist async,
we schedule an idle task to parse it and consider it loaded.
All this means that plugin blocklist information could be mistaken between the points where
a new plugin is installed and we first run Firefox with the new plugin, and the point where
we load the blocklist. Given the trade-offs, that size of window (tiny) seems OK, also given
that there's already a much larger window in blocklist updates (which only happen once every 24h).
MozReview-Commit-ID: 1gsojRkUzTw
--HG--
extra : rebase_source : 4709916b4674ada54f8a495fd2d16fcef8c58d20
2018-02-20 19:53:48 +03:00
|
|
|
nullptr, nullptr, nullptr, 0, 0, false,
|
|
|
|
nsIBlocklistService::STATE_NOT_BLOCKED);
|
2016-08-24 21:02:02 +03:00
|
|
|
mPlugins.AppendElement(new nsPluginElement(mWindow, hiddenTag));
|
|
|
|
}
|
|
|
|
|
2012-09-18 11:56:14 +04:00
|
|
|
// Alphabetize the enumeration order of non-hidden plugins to reduce
|
|
|
|
// fingerprintable entropy based on plugins' installation file times.
|
|
|
|
mPlugins.Sort();
|
2013-07-09 17:58:21 +04: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
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPluginElement, mWindow, mMimeTypes)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPluginElement::nsPluginElement(nsPIDOMWindowInner* aWindow,
|
2015-05-20 16:30:05 +03:00
|
|
|
nsIInternalPluginTag* aPluginTag)
|
2013-07-09 17:58:21 +04:00
|
|
|
: mWindow(aWindow),
|
|
|
|
mPluginTag(aPluginTag)
|
|
|
|
{
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2016-11-14 12:40:37 +03:00
|
|
|
nsPluginElement::~nsPluginElement() = default;
|
2014-07-01 03:00:30 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginElement::GetParentObject() const
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-08-29 00:55:29 +04:00
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
return mWindow;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04: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 17:13:33 +03:00
|
|
|
nsPluginElement::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2009-04-22 23:13:10 +04:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return Plugin_Binding::Wrap(aCx, this, aGivenProto);
|
2009-04-22 23:13:10 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsPluginElement::GetDescription(nsString& retval) const
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2015-05-20 16:30:05 +03:00
|
|
|
CopyUTF8toUTF16(mPluginTag->Description(), retval);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsPluginElement::GetFilename(nsString& retval) const
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2015-05-20 16:30:05 +03:00
|
|
|
CopyUTF8toUTF16(mPluginTag->FileName(), retval);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsPluginElement::GetVersion(nsString& retval) const
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2015-05-20 16:30:05 +03:00
|
|
|
CopyUTF8toUTF16(mPluginTag->Version(), retval);
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsPluginElement::GetName(nsString& retval) const
|
|
|
|
{
|
2015-05-20 16:30:05 +03:00
|
|
|
CopyUTF8toUTF16(mPluginTag->Name(), retval);
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::Item(uint32_t aIndex)
|
|
|
|
{
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
return mMimeTypes.SafeElementAt(aIndex);
|
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::NamedItem(const nsAString& aName)
|
|
|
|
{
|
|
|
|
bool unused;
|
|
|
|
return NamedGetter(aName, unused);
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::IndexedGetter(uint32_t aIndex, bool &aFound)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = aIndex < mMimeTypes.Length();
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2015-08-13 15:22:48 +03:00
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mMimeTypes[aIndex];
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsPluginElement::NamedGetter(const nsAString& aName, bool &aFound)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2013-07-09 17:58:21 +04:00
|
|
|
|
|
|
|
aFound = false;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
|
|
|
|
if (mMimeTypes[i]->Type().Equals(aName)) {
|
|
|
|
aFound = true;
|
2000-11-29 05:26:11 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
return mMimeTypes[i];
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-11-01 00:40:35 +03:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
uint32_t
|
|
|
|
nsPluginElement::Length()
|
2008-11-01 00:40:35 +03:00
|
|
|
{
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
return mMimeTypes.Length();
|
|
|
|
}
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
2016-05-10 05:25:40 +03:00
|
|
|
nsPluginElement::GetSupportedNames(nsTArray<nsString>& retval)
|
2013-07-09 17:58:21 +04:00
|
|
|
{
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2013-07-09 17:58:21 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
|
|
|
|
retval.AppendElement(mMimeTypes[i]->Type());
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsMimeType> >&
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginElement::MimeTypes()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2013-07-09 17:58:21 +04:00
|
|
|
|
|
|
|
return mMimeTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-20 11:05:05 +04:00
|
|
|
nsPluginElement::EnsurePluginMimeTypes()
|
2013-07-09 17:58:21 +04:00
|
|
|
{
|
|
|
|
if (!mMimeTypes.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:30:05 +03:00
|
|
|
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));
|
2000-11-29 05:26:11 +03:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|