Fixing the DOM navigator.mimeType array to be able to test for installed helper applications, bug 58811, patch by bzbarsky@mit.edu r=peter, sr=jst

This commit is contained in:
peterlubczynski%netscape.com 2003-02-26 23:54:55 +00:00
Родитель 83101081ca
Коммит d1b6c0d64d
5 изменённых файлов: 108 добавлений и 8 удалений

Просмотреть файл

@ -42,6 +42,7 @@ REQUIRES = xpcom \
pref \
oji \
necko \
mimetype \
java \
locale \
uriloader \

Просмотреть файл

@ -43,6 +43,9 @@
#include "nsIDOMPluginArray.h"
#include "nsIDOMPlugin.h"
#include "nsDOMClassInfo.h"
#include "nsIMIMEService.h"
#include "nsIMIMEInfo.h"
#include "nsIFile.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -125,7 +128,50 @@ MimeTypeArrayImpl::NamedItem(const nsAString& aName,
NS_ADDREF(*aReturn);
break;
return NS_OK;
}
}
// Now let's check with the MIME service.
nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
if (mimeSrv) {
nsCOMPtr<nsIMIMEInfo> mimeInfo;
mimeSrv->GetFromMIMEType(NS_ConvertUCS2toUTF8(aName).get(),
getter_AddRefs(mimeInfo));
if (mimeInfo) {
// Now we check whether we can really claim to support this type
nsMIMEInfoHandleAction action = nsIMIMEInfo::saveToDisk;
mimeInfo->GetPreferredAction(&action);
if (action != nsIMIMEInfo::handleInternally) {
nsCOMPtr<nsIFile> helper;
mimeInfo->GetDefaultApplicationHandler(getter_AddRefs(helper));
if (!helper) {
mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper));
if (!helper) {
// mime info from the OS may not have a PreferredApplicaitonHandler
// so just check for an empty default description
nsXPIDLString defaultDescription;
mimeInfo->GetDefaultDescription(getter_Copies(defaultDescription));
if (defaultDescription.IsEmpty()) {
// no support; just leave
return NS_OK;
}
}
}
}
// If we got here, we support this type! Say so.
nsCOMPtr<nsIDOMMimeType> helperImpl = new HelperMimeTypeImpl(aName);
if (!helperImpl) {
return NS_ERROR_OUT_OF_MEMORY;
}
MimeTypeElementImpl* entry = new MimeTypeElementImpl(nsnull, helperImpl);
if (!entry) {
return NS_ERROR_OUT_OF_MEMORY;
}
return CallQueryInterface(entry, aReturn);
}
}
@ -206,7 +252,6 @@ MimeTypeElementImpl::MimeTypeElementImpl(nsIDOMPlugin* aPlugin,
MimeTypeElementImpl::~MimeTypeElementImpl()
{
NS_IF_RELEASE(mMimeType);
}
@ -232,7 +277,7 @@ NS_IMETHODIMP
MimeTypeElementImpl::GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin)
{
*aEnabledPlugin = mPlugin;
NS_IF_ADDREF(mPlugin);
NS_IF_ADDREF(*aEnabledPlugin);
return NS_OK;
}
@ -247,3 +292,35 @@ MimeTypeElementImpl::GetType(nsAString& aType)
{
return mMimeType->GetType(aType);
}
// QueryInterface implementation for HelperMimeTypeImpl
NS_IMPL_ISUPPORTS1(HelperMimeTypeImpl, nsIDOMMimeType);
NS_IMETHODIMP
HelperMimeTypeImpl::GetDescription(nsAString& aDescription)
{
aDescription.Truncate();
return NS_OK;
}
NS_IMETHODIMP
HelperMimeTypeImpl::GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin)
{
*aEnabledPlugin = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HelperMimeTypeImpl::GetSuffixes(nsAString& aSuffixes)
{
aSuffixes.Truncate();
return NS_OK;
}
NS_IMETHODIMP
HelperMimeTypeImpl::GetType(nsAString& aType)
{
aType = mType;
return NS_OK;
}

Просмотреть файл

@ -41,6 +41,8 @@
#include "nsIDOMMimeTypeArray.h"
#include "nsIDOMMimeType.h"
#include "nsString2.h"
#include "nsCOMPtr.h"
class nsIDOMNavigator;
@ -82,7 +84,27 @@ public:
protected:
nsIDOMPlugin* mPlugin;
nsIDOMMimeType* mMimeType;
nsCOMPtr<nsIDOMMimeType> mMimeType;
};
class HelperMimeTypeImpl : public nsIDOMMimeType
{
public:
HelperMimeTypeImpl(const nsAString& aType)
: mType(aType)
{}
virtual ~HelperMimeTypeImpl() {}
NS_DECL_ISUPPORTS
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD GetEnabledPlugin(nsIDOMPlugin** aEnabledPlugin);
NS_IMETHOD GetSuffixes(nsAString& aSuffixes);
NS_IMETHOD GetType(nsAString& aType);
private:
nsString mType;
};
#endif /* nsMimeTypeArray_h___ */

Просмотреть файл

@ -394,13 +394,12 @@ PluginElementImpl::GetMimeTypes()
if (mMimeTypeArray == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
for (PRUint32 i = 0; i < mMimeTypeCount; i++) {
nsIDOMMimeType* mimeType = nsnull;
rv = mPlugin->Item(i, &mimeType);
nsCOMPtr<nsIDOMMimeType> mimeType;
rv = mPlugin->Item(i, getter_AddRefs(mimeType));
if (rv != NS_OK)
break;
mimeType = new MimeTypeElementImpl(this, mimeType);
NS_IF_ADDREF(mimeType);
mMimeTypeArray[i] = mimeType;
NS_IF_ADDREF(mMimeTypeArray[i] = mimeType);
}
}
return rv;

Просмотреть файл

@ -2434,6 +2434,7 @@ nsresult nsExternalHelperAppService::AddDefaultMimeTypesToCache()
mimeInfo->SetDescription(NS_ConvertASCIItoUCS2(defaultMimeEntries[index].mDescription).get());
mimeInfo->SetMacType(defaultMimeEntries[index].mMactype);
mimeInfo->SetMacCreator(defaultMimeEntries[index].mMacCreator);
mimeInfo->SetPreferredAction(nsIMIMEInfo::handleInternally);
AddMimeInfoToCache(mimeInfo);
}