bug 388388: differentiate between MIME and protocol nsIHandlerInfo objects by not allowing protocol objects to be QIed to nsIMIMEInfo, and expose the scheme for a protocol object via the new nsIHandlerInfo::type attribute (which also holds the MIME type for a MIME object and deprecates nsIMIMEInfo::MIMEType); r=dmose, sr=biesi

This commit is contained in:
myk%mozilla.org 2007-07-24 20:29:52 +00:00
Родитель 5ea4c12c19
Коммит bf48d38d93
13 изменённых файлов: 86 добавлений и 20 удалений

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

@ -49,8 +49,16 @@ typedef long nsHandlerInfoAction;
* nsIHandlerInfo gives access to the information about how a given protocol * nsIHandlerInfo gives access to the information about how a given protocol
* scheme or MIME-type is handled. * scheme or MIME-type is handled.
*/ */
[scriptable, uuid(2ec1216d-59e7-424c-aa1e-70aa3c897520)] [scriptable, uuid(51ddc1c5-7077-4c58-a5bd-327d00777b46)]
interface nsIHandlerInfo : nsISupports { interface nsIHandlerInfo : nsISupports {
/**
* The type of this handler info. For MIME handlers, this is the MIME type.
* For protocol handlers, it's the scheme.
*
* @return String representing the type.
*/
readonly attribute ACString type;
/** /**
* A human readable description of the handler type * A human readable description of the handler type
*/ */
@ -158,6 +166,8 @@ interface nsIMIMEInfo : nsIHandlerInfo {
* The MIME type of this MIMEInfo. * The MIME type of this MIMEInfo.
* *
* @return String representing the MIME type. * @return String representing the MIME type.
*
* @deprecated use nsIHandlerInfo::type instead.
*/ */
readonly attribute ACString MIMEType; readonly attribute ACString MIMEType;

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

@ -43,6 +43,8 @@ class nsMIMEInfoBeOS : public nsMIMEInfoImpl {
public: public:
nsMIMEInfoBeOS(const char* aType = "") : nsMIMEInfoImpl(aType) {} nsMIMEInfoBeOS(const char* aType = "") : nsMIMEInfoImpl(aType) {}
nsMIMEInfoBeOS(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {} nsMIMEInfoBeOS(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {}
nsMIMEInfoBeOS(const nsACString& aType, HandlerClass aClass) :
nsMIMEInfoImpl(aType, aClass) {}
virtual ~nsMIMEInfoBeOS(); virtual ~nsMIMEInfoBeOS();
protected: protected:

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

@ -275,7 +275,8 @@ nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
&exists); &exists);
NS_ENSURE_SUCCESS(rv, nsnull); NS_ENSURE_SUCCESS(rv, nsnull);
nsMIMEInfoBeOS *handlerInfo = new nsMIMEInfoBeOS(); nsMIMEInfoBeOS *handlerInfo =
new nsMIMEInfoBeOS(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull); NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo); NS_ADDREF(handlerInfo);

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

@ -43,6 +43,8 @@ class nsMIMEInfoMac : public nsMIMEInfoImpl {
public: public:
nsMIMEInfoMac(const char* aMIMEType = "") : nsMIMEInfoImpl(aMIMEType) {} nsMIMEInfoMac(const char* aMIMEType = "") : nsMIMEInfoImpl(aMIMEType) {}
nsMIMEInfoMac(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {} nsMIMEInfoMac(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {}
nsMIMEInfoMac(const nsACString& aType, HandlerClass aClass) :
nsMIMEInfoImpl(aType, aClass) {}
NS_IMETHOD LaunchWithURI(nsIURI* aURI); NS_IMETHOD LaunchWithURI(nsIURI* aURI);

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

@ -343,7 +343,8 @@ nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
&exists); &exists);
NS_ENSURE_SUCCESS(rv, nsnull); NS_ENSURE_SUCCESS(rv, nsnull);
nsMIMEInfoMac *handlerInfo = new nsMIMEInfoMac(); nsMIMEInfoMac *handlerInfo =
new nsMIMEInfoMac(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull); NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo); NS_ADDREF(handlerInfo);

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

@ -244,9 +244,7 @@ HandlerService.prototype = {
* @returns {string} the ID * @returns {string} the ID
*/ */
_getClass: function HS__getClass(aHandlerInfo) { _getClass: function HS__getClass(aHandlerInfo) {
if (aHandlerInfo instanceof Ci.nsIMIMEInfo && if (aHandlerInfo instanceof Ci.nsIMIMEInfo)
// FIXME: remove this extra condition in the fix for bug 388388.
aHandlerInfo.QueryInterface(Ci.nsIMIMEInfo).MIMEType)
return "mimetype"; return "mimetype";
else else
return "scheme"; return "scheme";
@ -265,10 +263,7 @@ HandlerService.prototype = {
* @returns {string} the ID * @returns {string} the ID
*/ */
_getTypeID: function HS__getTypeID(aHandlerInfo) { _getTypeID: function HS__getTypeID(aHandlerInfo) {
return "urn:" + this._getClass(aHandlerInfo) + ":" + return "urn:" + this._getClass(aHandlerInfo) + ":" + aHandlerInfo.type;
// FIXME: change this to aHandlerInfo.type in the fix for bug 388388.
aHandlerInfo.QueryInterface(Ci.nsIMIMEInfo).MIMEType;
}, },
/** /**
@ -288,8 +283,7 @@ HandlerService.prototype = {
*/ */
_getInfoID: function HS__getInfoID(aHandlerInfo) { _getInfoID: function HS__getInfoID(aHandlerInfo) {
return "urn:" + this._getClass(aHandlerInfo) + ":handler:" + return "urn:" + this._getClass(aHandlerInfo) + ":handler:" +
// FIXME: change this to aHandlerInfo.type in the fix for bug 388388. aHandlerInfo.type;
aHandlerInfo.QueryInterface(Ci.nsIMIMEInfo).MIMEType;
}, },
/** /**
@ -314,8 +308,7 @@ HandlerService.prototype = {
*/ */
_getPreferredHandlerID: function HS__getPreferredHandlerID(aHandlerInfo) { _getPreferredHandlerID: function HS__getPreferredHandlerID(aHandlerInfo) {
return "urn:" + this._getClass(aHandlerInfo) + ":externalApplication:" + return "urn:" + this._getClass(aHandlerInfo) + ":externalApplication:" +
// FIXME: change this to aHandlerInfo.type in the fix for bug 388388. aHandlerInfo.type;
aHandlerInfo.QueryInterface(Ci.nsIMIMEInfo).MIMEType;
}, },
/** /**
@ -383,9 +376,7 @@ HandlerService.prototype = {
// Create a basic type record for this type. // Create a basic type record for this type.
typeList.AppendElement(type); typeList.AppendElement(type);
this._setLiteral(typeID, NC_EDITABLE, "true"); this._setLiteral(typeID, NC_EDITABLE, "true");
this._setLiteral(typeID, NC_VALUE, this._setLiteral(typeID, NC_VALUE, aHandlerInfo.type);
// FIXME: change this to aHandlerInfo.type in the fix for bug 388388.
aHandlerInfo.QueryInterface(Ci.nsIMIMEInfo).MIMEType);
// Create a basic info record for this type. // Create a basic info record for this type.
var infoID = this._getInfoID(aHandlerInfo); var infoID = this._getInfoID(aHandlerInfo);

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

@ -45,12 +45,23 @@
#include "nsIFileURL.h" #include "nsIFileURL.h"
// nsISupports methods // nsISupports methods
NS_IMPL_THREADSAFE_ISUPPORTS2(nsMIMEInfoBase, nsIMIMEInfo, nsIHandlerInfo) NS_IMPL_THREADSAFE_ADDREF(nsMIMEInfoBase)
NS_IMPL_THREADSAFE_RELEASE(nsMIMEInfoBase)
NS_INTERFACE_MAP_BEGIN(nsMIMEInfoBase)
NS_INTERFACE_MAP_ENTRY(nsIHandlerInfo)
// This is only an nsIMIMEInfo if it's a MIME handler with a MIME type.
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIMIMEInfo, !mMIMEType.IsEmpty())
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIHandlerInfo)
NS_INTERFACE_MAP_END_THREADSAFE
// nsMIMEInfoImpl methods // nsMIMEInfoImpl methods
// Constructors for a MIME handler.
nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) : nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) :
mMacType(0), mMacType(0),
mMacCreator(0), mMacCreator(0),
mType(aMIMEType),
mMIMEType(aMIMEType), mMIMEType(aMIMEType),
mPreferredAction(nsIMIMEInfo::saveToDisk), mPreferredAction(nsIMIMEInfo::saveToDisk),
mAlwaysAskBeforeHandling(PR_TRUE) mAlwaysAskBeforeHandling(PR_TRUE)
@ -60,12 +71,29 @@ nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) :
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aMIMEType) : nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aMIMEType) :
mMacType(0), mMacType(0),
mMacCreator(0), mMacCreator(0),
mType(aMIMEType),
mMIMEType(aMIMEType), mMIMEType(aMIMEType),
mPreferredAction(nsIMIMEInfo::saveToDisk), mPreferredAction(nsIMIMEInfo::saveToDisk),
mAlwaysAskBeforeHandling(PR_TRUE) mAlwaysAskBeforeHandling(PR_TRUE)
{ {
} }
// Constructor for a handler that lets the caller specify whether this is a
// MIME handler or a protocol handler. In the long run, these will be distinct
// classes (f.e. nsMIMEInfo and nsProtocolInfo), but for now we reuse this class
// for both and distinguish between the two kinds of handlers via the aClass
// argument to this method, which can be either eMIMEInfo or eProtocolInfo.
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass) :
mMacType(0),
mMacCreator(0),
mType(aType),
mPreferredAction(nsIMIMEInfo::saveToDisk),
mAlwaysAskBeforeHandling(PR_TRUE)
{
if (aClass == eMIMEInfo)
mMIMEType = aType;
}
nsMIMEInfoBase::~nsMIMEInfoBase() nsMIMEInfoBase::~nsMIMEInfoBase()
{ {
} }
@ -136,6 +164,16 @@ nsMIMEInfoBase::AppendExtension(const nsACString& aExtension)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsMIMEInfoBase::GetType(nsACString& aType)
{
if (mType.IsEmpty())
return NS_ERROR_NOT_INITIALIZED;
aType = mType;
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsMIMEInfoBase::GetMIMEType(nsACString& aMIMEType) nsMIMEInfoBase::GetMIMEType(nsACString& aMIMEType)
{ {

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

@ -74,6 +74,7 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
NS_IMETHOD AppendExtension(const nsACString & aExtension); NS_IMETHOD AppendExtension(const nsACString & aExtension);
NS_IMETHOD GetPrimaryExtension(nsACString & aPrimaryExtension); NS_IMETHOD GetPrimaryExtension(nsACString & aPrimaryExtension);
NS_IMETHOD SetPrimaryExtension(const nsACString & aPrimaryExtension); NS_IMETHOD SetPrimaryExtension(const nsACString & aPrimaryExtension);
NS_IMETHOD GetType(nsACString & aType);
NS_IMETHOD GetMIMEType(nsACString & aMIMEType); NS_IMETHOD GetMIMEType(nsACString & aMIMEType);
NS_IMETHOD GetDescription(nsAString & aDescription); NS_IMETHOD GetDescription(nsAString & aDescription);
NS_IMETHOD SetDescription(const nsAString & aDescription); NS_IMETHOD SetDescription(const nsAString & aDescription);
@ -91,11 +92,19 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling); NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling);
NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling); NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling);
enum HandlerClass {
eMIMEInfo,
eProtocolInfo
};
// nsMIMEInfoBase methods // nsMIMEInfoBase methods
nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN; nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN;
nsMIMEInfoBase(const nsACString& aMIMEType) NS_HIDDEN; nsMIMEInfoBase(const nsACString& aMIMEType) NS_HIDDEN;
nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass) NS_HIDDEN;
virtual ~nsMIMEInfoBase(); // must be virtual, as the the base class's Release should call the subclass's destructor virtual ~nsMIMEInfoBase(); // must be virtual, as the the base class's Release should call the subclass's destructor
void SetType(const nsACString & aType) { mType = aType; }
void SetMIMEType(const nsACString & aMIMEType) { mMIMEType = aMIMEType; } void SetMIMEType(const nsACString & aMIMEType) { mMIMEType = aMIMEType; }
void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; } void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; }
@ -158,6 +167,7 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
nsCStringArray mExtensions; ///< array of file extensions associated w/ this MIME obj nsCStringArray mExtensions; ///< array of file extensions associated w/ this MIME obj
nsString mDescription; ///< human readable description nsString mDescription; ///< human readable description
PRUint32 mMacType, mMacCreator; ///< Mac file type and creator PRUint32 mMacType, mMacCreator; ///< Mac file type and creator
nsCString mType;
nsCString mMIMEType; nsCString mMIMEType;
nsCOMPtr<nsIHandlerApp> mPreferredApplication; nsCOMPtr<nsIHandlerApp> mPreferredApplication;
nsHandlerInfoAction mPreferredAction; ///< preferred action to associate with this type nsHandlerInfoAction mPreferredAction; ///< preferred action to associate with this type
@ -179,6 +189,8 @@ class nsMIMEInfoImpl : public nsMIMEInfoBase {
public: public:
nsMIMEInfoImpl(const char *aMIMEType = "") : nsMIMEInfoBase(aMIMEType) {} nsMIMEInfoImpl(const char *aMIMEType = "") : nsMIMEInfoBase(aMIMEType) {}
nsMIMEInfoImpl(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {} nsMIMEInfoImpl(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {}
nsMIMEInfoImpl(const nsACString& aType, HandlerClass aClass) :
nsMIMEInfoBase(aType, aClass) {}
virtual ~nsMIMEInfoImpl() {} virtual ~nsMIMEInfoImpl() {}
// nsIMIMEInfo methods // nsIMIMEInfo methods

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

@ -44,6 +44,8 @@ class nsMIMEInfoOS2 : public nsMIMEInfoImpl
public: public:
nsMIMEInfoOS2(const char* aType = "") : nsMIMEInfoImpl(aType) {} nsMIMEInfoOS2(const char* aType = "") : nsMIMEInfoImpl(aType) {}
nsMIMEInfoOS2(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {} nsMIMEInfoOS2(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {}
nsMIMEInfoOS2(const nsACString& aType, HandlerClass aClass) :
nsMIMEInfoImpl(aType, aClass) {}
virtual ~nsMIMEInfoOS2(); virtual ~nsMIMEInfoOS2();
NS_IMETHOD LaunchWithURI(nsIURI* aURI); NS_IMETHOD LaunchWithURI(nsIURI* aURI);

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

@ -83,6 +83,9 @@ function run_test() {
// Make sure it's also an nsIHandlerInfo. // Make sure it's also an nsIHandlerInfo.
do_check_true(handlerInfo instanceof Ci.nsIHandlerInfo); do_check_true(handlerInfo instanceof Ci.nsIHandlerInfo);
do_check_eq(handlerInfo.type, "nonexistent/type");
// Deprecated property, but we should still make sure it's set correctly.
do_check_eq(handlerInfo.MIMEType, "nonexistent/type"); do_check_eq(handlerInfo.MIMEType, "nonexistent/type");
// These three properties are the ones the handler service knows how to store. // These three properties are the ones the handler service knows how to store.

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

@ -1683,7 +1683,8 @@ nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
&exists); &exists);
NS_ENSURE_SUCCESS(rv, nsnull); NS_ENSURE_SUCCESS(rv, nsnull);
nsMIMEInfoImpl *handlerInfo = new nsMIMEInfoImpl(); nsMIMEInfoImpl *handlerInfo =
new nsMIMEInfoImpl(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull); NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo); NS_ADDREF(handlerInfo);

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

@ -44,6 +44,8 @@ class nsMIMEInfoWin : public nsMIMEInfoBase, public nsIPropertyBag {
public: public:
nsMIMEInfoWin(const char* aType = "") : nsMIMEInfoBase(aType) {} nsMIMEInfoWin(const char* aType = "") : nsMIMEInfoBase(aType) {}
nsMIMEInfoWin(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {} nsMIMEInfoWin(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {}
nsMIMEInfoWin(const nsACString& aType, HandlerClass aClass) :
nsMIMEInfoImpl(aType, aClass) {}
virtual ~nsMIMEInfoWin(); virtual ~nsMIMEInfoWin();
NS_IMETHOD GetHasDefaultHandler(PRBool * _retval); NS_IMETHOD GetHasDefaultHandler(PRBool * _retval);

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

@ -598,7 +598,8 @@ nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
&exists); &exists);
NS_ENSURE_SUCCESS(rv, nsnull); NS_ENSURE_SUCCESS(rv, nsnull);
nsMIMEInfoWin *handlerInfo = new nsMIMEInfoWin(); nsMIMEInfoWin *handlerInfo =
new nsMIMEInfoWin(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull); NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo); NS_ADDREF(handlerInfo);