Protection if someone did change defaults for mms or mmsto

This commit is contained in:
amla70
2010-08-14 11:14:39 +00:00
parent be7d0d867d
commit 1dda577d89

View File

@@ -41,43 +41,43 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function SendToPhone_ProtocolWrapper( properties )
{
var myHandler = function() {};
myHandler.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
_xpcom_factory: {
singleton: null,
createInstance: function (aOuter, aIID) {
createInstance: function (aOuter, aIID) {
if (aOuter) throw Components.results.NS_ERROR_NO_AGGREGATION;
if (!this.singleton) this.singleton = new myHandler();
return this.singleton.QueryInterface(aIID);
}
},
// nsIProtocolHandler implementation:
// default attributes
protocolFlags : Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
defaultPort : -1,
newURI : function(aSpec, aCharset, aBaseURI)
{
var uri = Components.classes["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
uri.spec = aSpec;
return uri;
},
newChannel : function(aURI)
{
var myURI = decodeURI(aURI.spec);
// Core functions loaded on demand
if (typeof sendtophoneCore == "undefined")
Components.utils.import("resource://sendtophone/sendtophone.js");
sendtophoneCore.send(this.linkTitle, myURI, "")
// return a fake empty channel so current window doesn't change
return Components.classes[ "@mozilla.org/network/input-stream-channel;1" ].createInstance(Ci.nsIChannel);
},
@@ -87,7 +87,7 @@ function SendToPhone_ProtocolWrapper( properties )
contractID : "@mozilla.org/network/protocol;1?name=" + properties.scheme,
linkTitle : strings.GetStringFromName( properties.scheme + "Link" ) // Translations
}
return myHandler;
}
@@ -99,6 +99,11 @@ function toggleProtocolHandler(branch, name)
var register = branch.getBoolPref(name);
// Retrieve the object for that protocol
var protocolHandler = sendToPhoneProtocols[ name ];
// If someone did change the defaults for mms or mmsto this
// function will be called, but the handlers have been removed.
if (!protocolHandler)
return;
var proto = protocolHandler.prototype;
if (register)
@@ -108,7 +113,7 @@ function toggleProtocolHandler(branch, name)
proto.classDescription,
proto.contractID,
proto._xpcom_factory);
protocolHandler.registered = true;
}
else
@@ -124,9 +129,9 @@ var sendToPhoneProtocols = {
market: SendToPhone_ProtocolWrapper( { scheme: "market", ID: "{751de080-95d1-11df-981c-0800200c9a66}" } ) ,
sms: SendToPhone_ProtocolWrapper( { scheme: "sms", ID: "{345de080-95d1-11df-981c-0800200c9a66}" } ) ,
smsto: SendToPhone_ProtocolWrapper( { scheme: "smsto", ID: "{854de080-95d1-11df-981c-0800200c9a66}" } ) ,
tel: SendToPhone_ProtocolWrapper( { scheme: "tel", ID: "{948de080-95d1-11df-981c-0800200c9a66}" } )
tel: SendToPhone_ProtocolWrapper( { scheme: "tel", ID: "{948de080-95d1-11df-981c-0800200c9a66}" } )
};
// Listen for changes in the preferences and register the protocols as needed.
// Listen for changes in the preferences and register the protocols as needed.
var preferencesListener = new PrefListener("extensions.sendtophone.protocols.", toggleProtocolHandler);
preferencesListener.register();