mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Protection if someone did change defaults for mms or mmsto
This commit is contained in:
@@ -41,43 +41,43 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|||||||
function SendToPhone_ProtocolWrapper( properties )
|
function SendToPhone_ProtocolWrapper( properties )
|
||||||
{
|
{
|
||||||
var myHandler = function() {};
|
var myHandler = function() {};
|
||||||
|
|
||||||
myHandler.prototype = {
|
myHandler.prototype = {
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
|
||||||
|
|
||||||
_xpcom_factory: {
|
_xpcom_factory: {
|
||||||
singleton: null,
|
singleton: null,
|
||||||
createInstance: function (aOuter, aIID) {
|
createInstance: function (aOuter, aIID) {
|
||||||
if (aOuter) throw Components.results.NS_ERROR_NO_AGGREGATION;
|
if (aOuter) throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||||
|
|
||||||
if (!this.singleton) this.singleton = new myHandler();
|
if (!this.singleton) this.singleton = new myHandler();
|
||||||
return this.singleton.QueryInterface(aIID);
|
return this.singleton.QueryInterface(aIID);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// nsIProtocolHandler implementation:
|
// nsIProtocolHandler implementation:
|
||||||
|
|
||||||
// default attributes
|
// default attributes
|
||||||
protocolFlags : Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
|
protocolFlags : Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
|
||||||
defaultPort : -1,
|
defaultPort : -1,
|
||||||
|
|
||||||
newURI : function(aSpec, aCharset, aBaseURI)
|
newURI : function(aSpec, aCharset, aBaseURI)
|
||||||
{
|
{
|
||||||
var uri = Components.classes["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
|
var uri = Components.classes["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
|
||||||
uri.spec = aSpec;
|
uri.spec = aSpec;
|
||||||
return uri;
|
return uri;
|
||||||
},
|
},
|
||||||
|
|
||||||
newChannel : function(aURI)
|
newChannel : function(aURI)
|
||||||
{
|
{
|
||||||
var myURI = decodeURI(aURI.spec);
|
var myURI = decodeURI(aURI.spec);
|
||||||
|
|
||||||
// Core functions loaded on demand
|
// Core functions loaded on demand
|
||||||
if (typeof sendtophoneCore == "undefined")
|
if (typeof sendtophoneCore == "undefined")
|
||||||
Components.utils.import("resource://sendtophone/sendtophone.js");
|
Components.utils.import("resource://sendtophone/sendtophone.js");
|
||||||
|
|
||||||
sendtophoneCore.send(this.linkTitle, myURI, "")
|
sendtophoneCore.send(this.linkTitle, myURI, "")
|
||||||
|
|
||||||
// return a fake empty channel so current window doesn't change
|
// return a fake empty channel so current window doesn't change
|
||||||
return Components.classes[ "@mozilla.org/network/input-stream-channel;1" ].createInstance(Ci.nsIChannel);
|
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,
|
contractID : "@mozilla.org/network/protocol;1?name=" + properties.scheme,
|
||||||
linkTitle : strings.GetStringFromName( properties.scheme + "Link" ) // Translations
|
linkTitle : strings.GetStringFromName( properties.scheme + "Link" ) // Translations
|
||||||
}
|
}
|
||||||
|
|
||||||
return myHandler;
|
return myHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +99,11 @@ function toggleProtocolHandler(branch, name)
|
|||||||
var register = branch.getBoolPref(name);
|
var register = branch.getBoolPref(name);
|
||||||
// Retrieve the object for that protocol
|
// Retrieve the object for that protocol
|
||||||
var protocolHandler = sendToPhoneProtocols[ name ];
|
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;
|
var proto = protocolHandler.prototype;
|
||||||
|
|
||||||
if (register)
|
if (register)
|
||||||
@@ -108,7 +113,7 @@ function toggleProtocolHandler(branch, name)
|
|||||||
proto.classDescription,
|
proto.classDescription,
|
||||||
proto.contractID,
|
proto.contractID,
|
||||||
proto._xpcom_factory);
|
proto._xpcom_factory);
|
||||||
|
|
||||||
protocolHandler.registered = true;
|
protocolHandler.registered = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -124,9 +129,9 @@ var sendToPhoneProtocols = {
|
|||||||
market: SendToPhone_ProtocolWrapper( { scheme: "market", ID: "{751de080-95d1-11df-981c-0800200c9a66}" } ) ,
|
market: SendToPhone_ProtocolWrapper( { scheme: "market", ID: "{751de080-95d1-11df-981c-0800200c9a66}" } ) ,
|
||||||
sms: SendToPhone_ProtocolWrapper( { scheme: "sms", ID: "{345de080-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}" } ) ,
|
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);
|
var preferencesListener = new PrefListener("extensions.sendtophone.protocols.", toggleProtocolHandler);
|
||||||
preferencesListener.register();
|
preferencesListener.register();
|
||||||
|
|||||||
Reference in New Issue
Block a user