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 "nsMimeTypeArray.h"
|
2013-08-14 10:56:21 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
#include "mozilla/dom/MimeTypeArrayBinding.h"
|
|
|
|
#include "mozilla/dom/MimeTypeBinding.h"
|
2015-05-20 16:30:05 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-07-09 17:58:21 +04:00
|
|
|
#include "nsPluginArray.h"
|
2003-02-27 02:54:55 +03:00
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsIMIMEInfo.h"
|
2018-01-22 20:59:15 +03:00
|
|
|
#include "mozilla/dom/Navigator.h"
|
2013-09-23 07:35:05 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2016-06-30 09:40:00 +03:00
|
|
|
#include "nsContentUtils.h"
|
2015-05-20 16:30:05 +03:00
|
|
|
#include "nsPluginTags.h"
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
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
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsMimeTypeArray, mWindow, mMimeTypes,
|
2016-07-28 00:45:48 +03:00
|
|
|
mCTPMimeTypes)
|
2013-07-09 17:58:21 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsMimeTypeArray::nsMimeTypeArray(nsPIDOMWindowInner* aWindow)
|
2013-11-01 09:19:09 +04:00
|
|
|
: mWindow(aWindow) {}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
nsMimeTypeArray::~nsMimeTypeArray() {}
|
1999-04-20 23:18:51 +04: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 17:13:33 +03:00
|
|
|
JSObject* nsMimeTypeArray::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return MimeTypeArray_Binding::Wrap(aCx, this, aGivenProto);
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void nsMimeTypeArray::Refresh() {
|
|
|
|
mMimeTypes.Clear();
|
2016-07-28 00:45:48 +03:00
|
|
|
mCTPMimeTypes.Clear();
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPIDOMWindowInner* nsMimeTypeArray::GetParentObject() const {
|
2013-08-29 00:55:29 +04:00
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
return mWindow;
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
nsMimeType* nsMimeTypeArray::Item(uint32_t aIndex, CallerType aCallerType) {
|
2013-07-09 17:58:21 +04:00
|
|
|
bool unused;
|
2016-12-17 08:25:52 +03:00
|
|
|
return IndexedGetter(aIndex, unused, aCallerType);
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
nsMimeType* nsMimeTypeArray::NamedItem(const nsAString& aName,
|
|
|
|
CallerType aCallerType) {
|
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
|
|
|
}
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
nsMimeType* nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool& aFound,
|
|
|
|
CallerType aCallerType) {
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = false;
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2016-06-30 09:40:00 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
if (aIndex >= mMimeTypes.Length()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2005-01-05 03:21:06 +03:00
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = true;
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
return mMimeTypes[aIndex];
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2016-05-11 03:57:29 +03:00
|
|
|
static nsMimeType* FindMimeType(const nsTArray<RefPtr<nsMimeType>>& aMimeTypes,
|
2013-11-01 09:19:09 +04:00
|
|
|
const nsAString& aType) {
|
|
|
|
for (uint32_t i = 0; i < aMimeTypes.Length(); ++i) {
|
|
|
|
nsMimeType* mimeType = aMimeTypes[i];
|
|
|
|
if (aType.Equals(mimeType->Type())) {
|
|
|
|
return mimeType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
nsMimeType* nsMimeTypeArray::NamedGetter(const nsAString& aName, bool& aFound,
|
|
|
|
CallerType aCallerType) {
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = false;
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2016-06-30 09:40:00 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2008-10-31 18:55:59 +03:00
|
|
|
|
2014-03-21 02:41:51 +04:00
|
|
|
nsString lowerName(aName);
|
|
|
|
ToLowerCase(lowerName);
|
|
|
|
|
|
|
|
nsMimeType* mimeType = FindMimeType(mMimeTypes, lowerName);
|
2013-11-01 09:19:09 +04:00
|
|
|
if (mimeType) {
|
|
|
|
aFound = true;
|
|
|
|
return mimeType;
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
2016-07-28 00:45:48 +03:00
|
|
|
nsMimeType* hiddenType = FindMimeType(mCTPMimeTypes, lowerName);
|
|
|
|
if (hiddenType) {
|
|
|
|
nsPluginArray::NotifyHiddenPluginTouched(hiddenType->GetEnabledPlugin());
|
|
|
|
}
|
2003-02-27 02:54:55 +03:00
|
|
|
|
2016-03-21 18:01:49 +03:00
|
|
|
return nullptr;
|
2008-11-01 00:40:35 +03:00
|
|
|
}
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
uint32_t nsMimeTypeArray::Length(CallerType aCallerType) {
|
2016-12-17 08:25:52 +03:00
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
2016-06-30 09:40:00 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
return mMimeTypes.Length();
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
void nsMimeTypeArray::GetSupportedNames(nsTArray<nsString>& aRetval,
|
|
|
|
CallerType aCallerType) {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
EnsurePluginMimeTypes();
|
2001-07-23 09:36:52 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
for (uint32_t i = 0; i < mMimeTypes.Length(); ++i) {
|
|
|
|
aRetval.AppendElement(mMimeTypes[i]->Type());
|
|
|
|
}
|
2001-07-23 09:36:52 +04:00
|
|
|
}
|
|
|
|
|
2013-10-20 11:05:05 +04:00
|
|
|
void nsMimeTypeArray::EnsurePluginMimeTypes() {
|
2015-05-30 08:42:23 +03:00
|
|
|
if (!mMimeTypes.IsEmpty() || !mWindow) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return;
|
2010-08-13 08:05:05 +04:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
RefPtr<Navigator> navigator = mWindow->Navigator();
|
2013-07-09 17:58:21 +04:00
|
|
|
|
2018-02-01 22:21:14 +03:00
|
|
|
nsPluginArray* pluginArray = navigator->GetPlugins(IgnoreErrors());
|
2013-07-18 07:23:52 +04:00
|
|
|
if (!pluginArray) {
|
|
|
|
return;
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2015-05-30 08:42:23 +03:00
|
|
|
pluginArray->GetMimeTypes(mMimeTypes);
|
2016-07-28 00:45:48 +03:00
|
|
|
pluginArray->GetCTPMimeTypes(mCTPMimeTypes);
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
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-07-09 17:58:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsMimeType, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsMimeType, Release)
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsMimeType, mWindow, mPluginElement)
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsMimeType::nsMimeType(nsPIDOMWindowInner* aWindow,
|
2015-05-20 16:30:05 +03:00
|
|
|
nsPluginElement* aPluginElement, const nsAString& aType,
|
|
|
|
const nsAString& aDescription,
|
|
|
|
const nsAString& aExtension)
|
2013-07-09 17:58:21 +04:00
|
|
|
: mWindow(aWindow),
|
|
|
|
mPluginElement(aPluginElement),
|
2015-05-20 16:30:05 +03:00
|
|
|
mType(aType),
|
|
|
|
mDescription(aDescription),
|
|
|
|
mExtension(aExtension) {
|
2016-03-21 18:01:49 +03:00
|
|
|
MOZ_ASSERT(aPluginElement);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType::~nsMimeType() {}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPIDOMWindowInner* nsMimeType::GetParentObject() const {
|
2013-08-29 00:55:29 +04:00
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
return mWindow;
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
2003-02-27 02:54:55 +03: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 17:13:33 +03:00
|
|
|
JSObject* nsMimeType::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return MimeType_Binding::Wrap(aCx, this, aGivenProto);
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
|
|
|
|
2015-05-20 16:30:05 +03:00
|
|
|
void nsMimeType::GetDescription(nsString& aRetval) const {
|
|
|
|
aRetval = mDescription;
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
2005-01-05 03:21:06 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginElement* nsMimeType::GetEnabledPlugin() const {
|
2016-03-21 18:01:49 +03:00
|
|
|
// mPluginElement might be null if we got unlinked but are still somehow being
|
|
|
|
// called into.
|
2015-08-13 15:22:48 +03:00
|
|
|
if (!mPluginElement || !mPluginElement->PluginTag()->IsEnabled()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mPluginElement;
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
2005-01-05 03:21:06 +03:00
|
|
|
|
2015-05-20 16:30:05 +03:00
|
|
|
void nsMimeType::GetSuffixes(nsString& aRetval) const { aRetval = mExtension; }
|
2003-02-27 02:54:55 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void nsMimeType::GetType(nsString& aRetval) const { aRetval = mType; }
|