From 1dda577d89b8d971d4a71bd0e090b3ce709fb80c Mon Sep 17 00:00:00 2001 From: amla70 Date: Sat, 14 Aug 2010 11:14:39 +0000 Subject: [PATCH] Protection if someone did change defaults for mms or mmsto --- .../modules/protocolHandlers.js | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/third_party/firefox_sendtophone/modules/protocolHandlers.js b/third_party/firefox_sendtophone/modules/protocolHandlers.js index bed756a..4c42df2 100644 --- a/third_party/firefox_sendtophone/modules/protocolHandlers.js +++ b/third_party/firefox_sendtophone/modules/protocolHandlers.js @@ -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();