Backed out changeset 0a1f354d13a0 (bug 907585)

This commit is contained in:
Ed Morley 2013-09-04 11:50:52 +01:00
Родитель 4b2242afc2
Коммит 663a0d5d4d
2 изменённых файлов: 99 добавлений и 103 удалений

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

@ -79,6 +79,7 @@ const RIL_IPC_MOBILECONNECTION_MSG_NAMES = [
"RIL:SelectNetworkAuto",
"RIL:SendMMI",
"RIL:CancelMMI",
"RIL:RegisterMobileConnectionMsg",
"RIL:SetCallForwardingOption",
"RIL:GetCallForwardingOption",
"RIL:SetCallBarringOption",
@ -108,13 +109,19 @@ const RIL_IPC_ICCMANAGER_MSG_NAMES = [
"RIL:IccExchangeAPDU",
"RIL:IccCloseChannel",
"RIL:ReadIccContacts",
"RIL:UpdateIccContact"
"RIL:UpdateIccContact",
"RIL:RegisterIccMsg"
];
const RIL_IPC_VOICEMAIL_MSG_NAMES = [
"RIL:RegisterVoicemailMsg",
"RIL:GetVoicemailInfo"
];
const RIL_IPC_CELLBROADCAST_MSG_NAMES = [
"RIL:RegisterCellBroadcastMsg"
];
XPCOMUtils.defineLazyServiceGetter(this, "gPowerManagerService",
"@mozilla.org/power/powermanagerservice;1",
"nsIPowerManagerService");
@ -174,16 +181,7 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
});
function RadioInterfaceLayer() {
let callback = this._receiveMessage.bind(this);
gMessageManager.registerMessageListeners("icc",
RIL_IPC_ICCMANAGER_MSG_NAMES,
callback);
gMessageManager.registerMessageListeners("mobileconnection",
RIL_IPC_MOBILECONNECTION_MSG_NAMES,
callback);
gMessageManager.registerMessageListeners("voicemail",
RIL_IPC_VOICEMAIL_MSG_NAMES,
callback);
gMessageManager.init(this);
let options = {
debug: debugPref,
@ -218,17 +216,6 @@ RadioInterfaceLayer.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer,
Ci.nsIObserver]),
_receiveMessage: function _receiveMessage(topic, msg) {
let clientId = msg.json.clientId || 0;
let radioInterface = this.getRadioInterface(clientId);
if (!radioInterface) {
if (DEBUG) debug("No such radio interface: " + clientId);
return null;
}
return radioInterface.receiveMessage(msg);
},
/**
* nsIObserver interface methods.
*/

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

@ -27,20 +27,7 @@ this.RilMessageManager = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener,
Ci.nsIObserver]),
topicRegistrationNames: {
cellbroadcast: "RIL:RegisterCellBroadcastMsg",
icc: "RIL:RegisterIccMsg",
mobileconnection: "RIL:RegisterMobileConnectionMsg",
voicemail: "RIL:RegisterVoicemailMsg",
},
/**
* this.callbacksByName[< A string message name>] = {
* topic: <A string topic>,
* callback: <A callback that accepts two parameters -- topic and msg>,
* }
*/
callbacksByName: {},
ril: null,
// Manage message targets in terms of topic. Only the authorized and
// registered contents can receive related messages.
@ -50,32 +37,55 @@ this.RilMessageManager = {
targetMessageQueue: [],
ready: false,
_init: function _init() {
init: function init(ril) {
this.ril = ril;
Services.obs.addObserver(this, "xpcom-shutdown", false);
Services.obs.addObserver(this, kSysMsgListenerReadyObserverTopic, false);
ppmm.addMessageListener("child-process-shutdown", this);
let callback = this._registerMessageTarget.bind(this);
for (let topic in this.topicRegistrationNames) {
let name = this.topicRegistrationNames[topic];
this.registerMessageListeners(topic, [name], callback);
}
this._registerMessageListeners();
},
_shutdown: function _shutdown() {
this.ril = null;
Services.obs.removeObserver(this, "xpcom-shutdown");
this._unregisterMessageListeners();
},
for (let name in this.callbacksByName) {
ppmm.removeMessageListener(name, this);
_registerMessageListeners: function _registerMessageListeners() {
ppmm.addMessageListener("child-process-shutdown", this);
for (let msgname of RIL_IPC_MOBILECONNECTION_MSG_NAMES) {
ppmm.addMessageListener(msgname, this);
}
this.callbacksByName = null;
for (let msgName of RIL_IPC_ICCMANAGER_MSG_NAMES) {
ppmm.addMessageListener(msgName, this);
}
for (let msgname of RIL_IPC_VOICEMAIL_MSG_NAMES) {
ppmm.addMessageListener(msgname, this);
}
for (let msgname of RIL_IPC_CELLBROADCAST_MSG_NAMES) {
ppmm.addMessageListener(msgname, this);
}
},
_unregisterMessageListeners: function _unregisterMessageListeners() {
ppmm.removeMessageListener("child-process-shutdown", this);
for (let msgname of RIL_IPC_MOBILECONNECTION_MSG_NAMES) {
ppmm.removeMessageListener(msgname, this);
}
for (let msgName of RIL_IPC_ICCMANAGER_MSG_NAMES) {
ppmm.removeMessageListener(msgName, this);
}
for (let msgname of RIL_IPC_VOICEMAIL_MSG_NAMES) {
ppmm.removeMessageListener(msgname, this);
}
for (let msgname of RIL_IPC_CELLBROADCAST_MSG_NAMES) {
ppmm.removeMessageListener(msgname, this);
}
ppmm = null;
},
_registerMessageTarget: function _registerMessageTarget(topic, msg) {
_registerMessageTarget: function _registerMessageTarget(topic, target) {
let targets = this.targetsByTopic[topic];
if (!targets) {
targets = this.targetsByTopic[topic] = [];
@ -85,7 +95,6 @@ this.RilMessageManager = {
}
}
let target = msg.target;
if (targets.indexOf(target) != -1) {
if (DEBUG) debug("Already registered this target!");
return;
@ -179,21 +188,66 @@ this.RilMessageManager = {
return;
}
let entry = this.callbacksByName[msg.name];
if (!entry) {
if (RIL_IPC_MOBILECONNECTION_MSG_NAMES.indexOf(msg.name) != -1) {
if (!msg.target.assertPermission("mobileconnection")) {
if (DEBUG) {
debug("MobileConnection message " + msg.name +
" from a content process with no 'mobileconnection' privileges.");
}
return null;
}
} else if (RIL_IPC_ICCMANAGER_MSG_NAMES.indexOf(msg.name) != -1) {
if (!msg.target.assertPermission("mobileconnection")) {
if (DEBUG) {
debug("IccManager message " + msg.name +
" from a content process with no 'mobileconnection' privileges.");
}
return null;
}
} else if (RIL_IPC_VOICEMAIL_MSG_NAMES.indexOf(msg.name) != -1) {
if (!msg.target.assertPermission("voicemail")) {
if (DEBUG) {
debug("Voicemail message " + msg.name +
" from a content process with no 'voicemail' privileges.");
}
return null;
}
} else if (RIL_IPC_CELLBROADCAST_MSG_NAMES.indexOf(msg.name) != -1) {
if (!msg.target.assertPermission("cellbroadcast")) {
if (DEBUG) {
debug("Cell Broadcast message " + msg.name +
" from a content process with no 'cellbroadcast' privileges.");
}
return null;
}
} else {
if (DEBUG) debug("Ignoring unknown message type: " + msg.name);
return null;
}
if (entry.topic && !msg.target.assertPermission(entry.topic)) {
if (DEBUG) {
debug("Message " + msg.name + " from a content process with no '" +
entry.topic + "' privileges.");
}
switch (msg.name) {
case "RIL:RegisterMobileConnectionMsg":
this._registerMessageTarget("mobileconnection", msg.target);
return;
case "RIL:RegisterIccMsg":
this._registerMessageTarget("icc", msg.target);
return;
case "RIL:RegisterVoicemailMsg":
this._registerMessageTarget("voicemail", msg.target);
return;
case "RIL:RegisterCellBroadcastMsg":
this._registerMessageTarget("cellbroadcast", msg.target);
return;
}
let clientId = msg.json.clientId || 0;
let radioInterface = this.ril.getRadioInterface(clientId);
if (!radioInterface) {
if (DEBUG) debug("No such radio interface: " + clientId);
return null;
}
return entry.callback(entry.topic, msg);
return radioInterface.receiveMessage(msg);
},
/**
@ -216,49 +270,6 @@ this.RilMessageManager = {
* Public methods.
*/
/**
* @param topic
* A string for the topic of the registrating names. Also the
* permission to listen messages of these names.
* @param names
* An array of string message names to listen.
* @param callback
* A callback that accepts two parameters -- topic and msg.
*/
registerMessageListeners: function registerMessageListeners(topic, names,
callback) {
for (let name of names) {
if (this.callbacksByName[name]) {
if (DEBUG) {
debug("Message name '" + name + "' was already registered. Ignored.");
}
continue;
}
this.callbacksByName[name] = { topic: topic, callback: callback };
ppmm.addMessageListener(name, this);
}
},
/**
* Remove all listening names with specified callback.
*
* @param callback
* The callback previously registered for messages.
*/
unregisterMessageListeners: function unregisterMessageListeners(callback) {
let remains = {};
for (let name in this.callbacksByName) {
let entry = this.callbacksByName[name];
if (entry.callback != callback) {
remains[name] = entry;
} else {
ppmm.removeMessageListener(name, this);
}
}
this.callbacksByName = remains;
},
sendMobileConnectionMessage: function sendMobileConnectionMessage(name, clientId, data) {
this._sendTargetMessage("mobileconnection", name, {
clientId: clientId,
@ -288,6 +299,4 @@ this.RilMessageManager = {
}
};
RilMessageManager._init();
this.EXPORTED_SYMBOLS = ["RilMessageManager"];