2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2010-08-13 08:05:05 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=79: */
|
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"
|
1999-04-20 23:18:51 +04:00
|
|
|
#include "nsIDOMNavigator.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"
|
2013-07-18 07:23:52 +04:00
|
|
|
#include "Navigator.h"
|
2013-09-23 07:35:05 +04:00
|
|
|
#include "nsServiceManagerUtils.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
|
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(nsMimeTypeArray,
|
2013-08-29 00:55:29 +04:00
|
|
|
mWindow,
|
2013-11-01 09:19:09 +04:00
|
|
|
mMimeTypes,
|
|
|
|
mHiddenMimeTypes)
|
2013-07-09 17:58:21 +04:00
|
|
|
|
2013-08-29 00:55:29 +04:00
|
|
|
nsMimeTypeArray::nsMimeTypeArray(nsPIDOMWindow* aWindow)
|
2013-11-01 09:19:09 +04:00
|
|
|
: mWindow(aWindow)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
SetIsDOMBinding();
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
nsMimeTypeArray::WrapObject(JSContext* aCx)
|
2013-07-09 17:58:21 +04:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-09 02:27:17 +04:00
|
|
|
return MimeTypeArrayBinding::Wrap(aCx, this);
|
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();
|
2013-11-01 09:19:09 +04:00
|
|
|
mHiddenMimeTypes.Clear();
|
2013-07-09 17:58:21 +04:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-08-29 00:55:29 +04:00
|
|
|
nsPIDOMWindow*
|
2013-07-09 17:58:21 +04:00
|
|
|
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
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsMimeTypeArray::Item(uint32_t aIndex)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
bool unused;
|
|
|
|
return IndexedGetter(aIndex, unused);
|
|
|
|
}
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsMimeTypeArray::NamedItem(const nsAString& aName)
|
|
|
|
{
|
|
|
|
bool unused;
|
|
|
|
return NamedGetter(aName, unused);
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool &aFound)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = false;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
static nsMimeType*
|
|
|
|
FindMimeType(const nsTArray<nsRefPtr<nsMimeType> >& aMimeTypes,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType*
|
|
|
|
nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
aFound = false;
|
1999-04-20 23:18:51 +04:00
|
|
|
|
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) {
|
2014-03-21 02:41:51 +04:00
|
|
|
mimeType = FindMimeType(mHiddenMimeTypes, lowerName);
|
2013-11-01 09:19:09 +04:00
|
|
|
}
|
2000-04-19 02:08:05 +04:00
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
if (mimeType) {
|
|
|
|
aFound = true;
|
|
|
|
return mimeType;
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now let's check with the MIME service.
|
|
|
|
nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
|
2013-07-09 17:58:21 +04:00
|
|
|
if (!mimeSrv) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-02-27 02:54:55 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
2014-03-21 02:41:51 +04:00
|
|
|
mimeSrv->GetFromTypeAndExtension(NS_ConvertUTF16toUTF8(lowerName),
|
|
|
|
EmptyCString(), getter_AddRefs(mimeInfo));
|
2013-07-09 17:58:21 +04:00
|
|
|
if (!mimeInfo) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
// Now we check whether we can really claim to support this type
|
|
|
|
nsHandlerInfoAction action = nsIHandlerInfo::saveToDisk;
|
|
|
|
mimeInfo->GetPreferredAction(&action);
|
|
|
|
if (action != nsIMIMEInfo::handleInternally) {
|
|
|
|
bool hasHelper = false;
|
|
|
|
mimeInfo->GetHasDefaultHandler(&hasHelper);
|
|
|
|
|
|
|
|
if (!hasHelper) {
|
|
|
|
nsCOMPtr<nsIHandlerApp> helper;
|
|
|
|
mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper));
|
|
|
|
|
|
|
|
if (!helper) {
|
|
|
|
// mime info from the OS may not have a PreferredApplicationHandler
|
|
|
|
// so just check for an empty default description
|
|
|
|
nsAutoString defaultDescription;
|
|
|
|
mimeInfo->GetDefaultDescription(defaultDescription);
|
|
|
|
|
|
|
|
if (defaultDescription.IsEmpty()) {
|
|
|
|
// no support; just leave
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
2000-04-19 02:08:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
// If we got here, we support this type! Say so.
|
|
|
|
aFound = true;
|
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
// We don't want navigator.mimeTypes enumeration to expose MIME types with
|
|
|
|
// application handlers, so add them to the list of hidden MIME types.
|
2014-03-21 02:41:51 +04:00
|
|
|
nsMimeType *mt = new nsMimeType(mWindow, lowerName);
|
2013-11-01 09:19:09 +04:00
|
|
|
mHiddenMimeTypes.AppendElement(mt);
|
2013-07-09 17:58:21 +04:00
|
|
|
|
|
|
|
return mt;
|
2008-11-01 00:40:35 +03:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:58:44 +04:00
|
|
|
bool
|
|
|
|
nsMimeTypeArray::NameIsEnumerable(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
uint32_t
|
|
|
|
nsMimeTypeArray::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-11-01 09:19:09 +04:00
|
|
|
return mMimeTypes.Length();
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2011-12-01 12:28:16 +04:00
|
|
|
void
|
2014-04-16 06:58:44 +04:00
|
|
|
nsMimeTypeArray::GetSupportedNames(unsigned, nsTArray< nsString >& aRetval)
|
2001-07-23 09:36:52 +04:00
|
|
|
{
|
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-07-09 17:58:21 +04:00
|
|
|
void
|
2013-10-20 11:05:05 +04:00
|
|
|
nsMimeTypeArray::EnsurePluginMimeTypes()
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-11-01 09:19:09 +04:00
|
|
|
if (!mMimeTypes.IsEmpty() || !mHiddenMimeTypes.IsEmpty() || !mWindow) {
|
2013-07-09 17:58:21 +04:00
|
|
|
return;
|
2010-08-13 08:05:05 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
nsCOMPtr<nsIDOMNavigator> navigator;
|
2013-08-29 00:55:29 +04:00
|
|
|
mWindow->GetNavigator(getter_AddRefs(navigator));
|
2013-07-09 17:58:21 +04:00
|
|
|
|
|
|
|
if (!navigator) {
|
|
|
|
return;
|
2005-01-05 03:21:06 +03:00
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
ErrorResult rv;
|
2013-07-09 17:58:21 +04:00
|
|
|
nsPluginArray *pluginArray =
|
2013-07-18 07:23:52 +04:00
|
|
|
static_cast<Navigator*>(navigator.get())->GetPlugins(rv);
|
|
|
|
if (!pluginArray) {
|
|
|
|
return;
|
|
|
|
}
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-11-01 09:19:09 +04:00
|
|
|
pluginArray->GetMimeTypes(mMimeTypes, mHiddenMimeTypes);
|
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
|
|
|
|
2013-08-29 00:55:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(nsMimeType, mWindow, mPluginElement)
|
1999-04-20 23:18:51 +04:00
|
|
|
|
2013-08-29 00:55:29 +04:00
|
|
|
nsMimeType::nsMimeType(nsPIDOMWindow* aWindow, nsPluginElement* aPluginElement,
|
2013-07-09 17:58:21 +04:00
|
|
|
uint32_t aPluginTagMimeIndex, const nsAString& aType)
|
|
|
|
: mWindow(aWindow),
|
|
|
|
mPluginElement(aPluginElement),
|
|
|
|
mPluginTagMimeIndex(aPluginTagMimeIndex),
|
|
|
|
mType(aType)
|
1999-04-20 23:18:51 +04:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
SetIsDOMBinding();
|
1999-04-20 23:18:51 +04:00
|
|
|
}
|
|
|
|
|
2013-08-29 00:55:29 +04:00
|
|
|
nsMimeType::nsMimeType(nsPIDOMWindow* aWindow, const nsAString& aType)
|
2013-07-09 17:58:21 +04:00
|
|
|
: mWindow(aWindow),
|
|
|
|
mPluginElement(nullptr),
|
|
|
|
mPluginTagMimeIndex(0),
|
|
|
|
mType(aType)
|
2005-01-05 03:21:06 +03:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
SetIsDOMBinding();
|
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-08-29 00:55:29 +04:00
|
|
|
nsPIDOMWindow*
|
2013-07-09 17:58:21 +04:00
|
|
|
nsMimeType::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
|
|
|
}
|
2003-02-27 02:54:55 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
nsMimeType::WrapObject(JSContext* aCx)
|
2003-02-27 02:54:55 +03:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-09 02:27:17 +04:00
|
|
|
return MimeTypeBinding::Wrap(aCx, this);
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsMimeType::GetDescription(nsString& retval) const
|
2003-02-27 02:54:55 +03:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
retval.Truncate();
|
|
|
|
|
|
|
|
if (mPluginElement) {
|
|
|
|
CopyUTF8toUTF16(mPluginElement->PluginTag()->
|
|
|
|
mMimeDescriptions[mPluginTagMimeIndex], retval);
|
|
|
|
}
|
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
|
2003-02-27 02:54:55 +03:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
return (mPluginElement && mPluginElement->PluginTag()->IsEnabled()) ?
|
|
|
|
mPluginElement : nullptr;
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
2005-01-05 03:21:06 +03:00
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsMimeType::GetSuffixes(nsString& retval) const
|
2003-02-27 02:54:55 +03:00
|
|
|
{
|
2013-07-09 17:58:21 +04:00
|
|
|
retval.Truncate();
|
|
|
|
|
|
|
|
if (mPluginElement) {
|
|
|
|
CopyUTF8toUTF16(mPluginElement->PluginTag()->
|
|
|
|
mExtensions[mPluginTagMimeIndex], retval);
|
|
|
|
}
|
2003-02-27 02:54:55 +03:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
void
|
|
|
|
nsMimeType::GetType(nsString& aRetval) const
|
|
|
|
{
|
|
|
|
aRetval = mType;
|
|
|
|
}
|