diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 38009786f9c3..645871610df5 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -511,6 +511,8 @@ @RESPATH@/components/RILSystemMessengerHelper.manifest @RESPATH@/components/TelephonyAudioService.js @RESPATH@/components/TelephonyAudioService.manifest +@RESPATH@/components/USSDReceivedWrapper.js +@RESPATH@/components/USSDReceivedWrapper.manifest #ifndef DISABLE_MOZ_RIL_GEOLOC @RESPATH@/components/TelephonyService.js @RESPATH@/components/TelephonyService.manifest diff --git a/dom/telephony/gonk/TelephonyService.js b/dom/telephony/gonk/TelephonyService.js index ee98a9a2b57b..9e741d329ff1 100644 --- a/dom/telephony/gonk/TelephonyService.js +++ b/dom/telephony/gonk/TelephonyService.js @@ -1699,37 +1699,4 @@ TelephonyService.prototype = { } }; -/** - * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a - * plugable way to wrap a "ussd-received" type system message. - * - * Please see SystemMessageManager.js to know how it customizes the wrapper. - */ -function USSDReceivedWrapper() { - if (DEBUG) debug("USSDReceivedWrapper()"); -} -USSDReceivedWrapper.prototype = { - // nsISystemMessagesWrapper implementation. - wrapMessage: function(aMessage, aWindow) { - if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage)); - - let session = aMessage.sessionEnded ? null : - new aWindow.USSDSession(aMessage.serviceId); - - let event = new aWindow.USSDReceivedEvent("ussdreceived", { - serviceId: aMessage.serviceId, - message: aMessage.message, - session: session - }); - - return event; - }, - - classDescription: "USSDReceivedWrapper", - classID: Components.ID("{d03684ed-ede4-4210-8206-f4f32772d9f5}"), - contractID: "@mozilla.org/dom/system-messages/wrapper/ussd-received;1", - QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper]) -}; - -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyService, - USSDReceivedWrapper]); +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyService]); diff --git a/dom/telephony/gonk/TelephonyService.manifest b/dom/telephony/gonk/TelephonyService.manifest index 28c8d8633f07..8a15cdf8dc4c 100644 --- a/dom/telephony/gonk/TelephonyService.manifest +++ b/dom/telephony/gonk/TelephonyService.manifest @@ -1,5 +1,3 @@ component {67d26434-d063-4d28-9f48-5b3189788155} TelephonyService.js contract @mozilla.org/telephony/gonktelephonyservice;1 {67d26434-d063-4d28-9f48-5b3189788155} -component {d03684ed-ede4-4210-8206-f4f32772d9f5} TelephonyService.js -contract @mozilla.org/dom/system-messages/wrapper/ussd-received;1 {d03684ed-ede4-4210-8206-f4f32772d9f5} diff --git a/dom/telephony/gonk/USSDReceivedWrapper.js b/dom/telephony/gonk/USSDReceivedWrapper.js new file mode 100644 index 000000000000..54ead325f31f --- /dev/null +++ b/dom/telephony/gonk/USSDReceivedWrapper.js @@ -0,0 +1,82 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; +const kPrefRilDebuggingEnabled = "ril.debugging.enabled"; + +let DEBUG; +function debug(s) { + dump("USSDReceivedWrapper: " + s + "\n"); +} + +XPCOMUtils.defineLazyGetter(this, "RIL", function () { + let obj = {}; + Cu.import("resource://gre/modules/ril_consts.js", obj); + return obj; +}); + +/** + * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a + * plugable way to wrap a "ussd-received" type system message. + * + * Please see SystemMessageManager.js to know how it customizes the wrapper. + */ +function USSDReceivedWrapper() { + this._updateDebugFlag(); + Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false); + if (DEBUG) debug("USSDReceivedWrapper()"); +} +USSDReceivedWrapper.prototype = { + _updateDebugFlag: function() { + try { + DEBUG = RIL.DEBUG_RIL || + Services.prefs.getBoolPref(kPrefRilDebuggingEnabled); + } catch (e) {} + }, + + /** + * nsIObserver interface. + */ + observe: function(aSubject, aTopic, aData) { + switch (aTopic) { + case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID: + if (aData === kPrefRilDebuggingEnabled) { + this._updateDebugFlag(); + } + break; + } + }, + + // nsISystemMessagesWrapper implementation. + wrapMessage: function(aMessage, aWindow) { + if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage)); + + let session = aMessage.sessionEnded ? null : + new aWindow.USSDSession(aMessage.serviceId); + + let event = new aWindow.USSDReceivedEvent("ussdreceived", { + serviceId: aMessage.serviceId, + message: aMessage.message, + session: session + }); + + return event; + }, + + classDescription: "USSDReceivedWrapper", + classID: Components.ID("{d03684ed-ede4-4210-8206-f4f32772d9f5}"), + contractID: "@mozilla.org/dom/system-messages/wrapper/ussd-received;1", + QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, + Ci.nsISystemMessagesWrapper]) +}; + +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([USSDReceivedWrapper]); diff --git a/dom/telephony/gonk/USSDReceivedWrapper.manifest b/dom/telephony/gonk/USSDReceivedWrapper.manifest new file mode 100644 index 000000000000..039498828c57 --- /dev/null +++ b/dom/telephony/gonk/USSDReceivedWrapper.manifest @@ -0,0 +1,2 @@ +component {d03684ed-ede4-4210-8206-f4f32772d9f5} USSDReceivedWrapper.js +contract @mozilla.org/dom/system-messages/wrapper/ussd-received;1 {d03684ed-ede4-4210-8206-f4f32772d9f5} diff --git a/dom/telephony/moz.build b/dom/telephony/moz.build index 8eeb46000d43..6d714894c529 100644 --- a/dom/telephony/moz.build +++ b/dom/telephony/moz.build @@ -63,6 +63,8 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']: EXTRA_COMPONENTS += [ 'gonk/TelephonyAudioService.js', 'gonk/TelephonyAudioService.manifest', + 'gonk/USSDReceivedWrapper.js', + 'gonk/USSDReceivedWrapper.manifest', ] if not CONFIG['DISABLE_MOZ_RIL_GEOLOC']: EXTRA_COMPONENTS += [