mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 907585 [3/3]: some small refinements. r=yoshi
This commit is contained in:
parent
a7fcf45ed8
commit
bcdbae90bf
@ -16,7 +16,15 @@ XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
||||
"nsIMessageBroadcaster");
|
||||
|
||||
// Observer topics.
|
||||
const kPrefenceChangedObserverTopic = "nsPref:changed";
|
||||
const kSysMsgListenerReadyObserverTopic = "system-message-listener-ready";
|
||||
const kXpcomShutdownObserverTopic = "xpcom-shutdown";
|
||||
|
||||
// Preference keys.
|
||||
const kPrefKeyRilDebuggingEnabled = "ril.debugging.enabled";
|
||||
|
||||
// Frame message names.
|
||||
const kMsgNameChildProcessShutdown = "child-process-shutdown";
|
||||
|
||||
let DEBUG;
|
||||
function debug(s) {
|
||||
@ -51,10 +59,13 @@ this.RilMessageManager = {
|
||||
ready: false,
|
||||
|
||||
_init: function _init() {
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
Services.obs.addObserver(this, kSysMsgListenerReadyObserverTopic, false);
|
||||
this._updateDebugFlag();
|
||||
|
||||
ppmm.addMessageListener("child-process-shutdown", this);
|
||||
Services.obs.addObserver(this, kPrefenceChangedObserverTopic, false);
|
||||
Services.obs.addObserver(this, kSysMsgListenerReadyObserverTopic, false);
|
||||
Services.obs.addObserver(this, kXpcomShutdownObserverTopic, false);
|
||||
|
||||
ppmm.addMessageListener(kMsgNameChildProcessShutdown, this);
|
||||
|
||||
let callback = this._registerMessageTarget.bind(this);
|
||||
for (let topic in this.topicRegistrationNames) {
|
||||
@ -64,15 +75,22 @@ this.RilMessageManager = {
|
||||
},
|
||||
|
||||
_shutdown: function _shutdown() {
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
if (!this.ready) {
|
||||
Services.obs.removeObserver(this, kSysMsgListenerReadyObserverTopic);
|
||||
}
|
||||
Services.obs.removeObserver(this, kPrefenceChangedObserverTopic);
|
||||
Services.obs.removeObserver(this, kXpcomShutdownObserverTopic);
|
||||
|
||||
for (let name in this.callbacksByName) {
|
||||
ppmm.removeMessageListener(name, this);
|
||||
}
|
||||
this.callbacksByName = null;
|
||||
|
||||
ppmm.removeMessageListener("child-process-shutdown", this);
|
||||
ppmm.removeMessageListener(kMsgNameChildProcessShutdown, this);
|
||||
ppmm = null;
|
||||
|
||||
this.targetsByTopic = null;
|
||||
this.targetMessageQueue = null;
|
||||
},
|
||||
|
||||
_registerMessageTarget: function _registerMessageTarget(topic, msg) {
|
||||
@ -151,12 +169,9 @@ this.RilMessageManager = {
|
||||
},
|
||||
|
||||
_resendQueuedTargetMessage: function _resendQueuedTargetMessage() {
|
||||
this.ready = true;
|
||||
|
||||
// Here uses this._sendTargetMessage() to resend message, which will
|
||||
// enqueue message if listener is not ready.
|
||||
// So only resend after listener is ready, or it will cause infinate loop and
|
||||
// hang the system.
|
||||
// enqueue message if listener is not ready. So only resend after listener
|
||||
// is ready, or it will cause infinate loop and hang the system.
|
||||
|
||||
// Dequeue and resend messages.
|
||||
for (let msg of this.targetMessageQueue) {
|
||||
@ -165,13 +180,23 @@ this.RilMessageManager = {
|
||||
this.targetMessageQueue = null;
|
||||
},
|
||||
|
||||
_updateDebugFlag: function _updateDebugFlag() {
|
||||
try {
|
||||
DEBUG = RIL.DEBUG_RIL ||
|
||||
Services.prefs.getBoolPref(kPrefKeyRilDebuggingEnabled);
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
/**
|
||||
* nsIMessageListener interface methods.
|
||||
*/
|
||||
|
||||
receiveMessage: function receiveMessage(msg) {
|
||||
if (DEBUG) debug("Received '" + msg.name + "' message from content process");
|
||||
if (msg.name == "child-process-shutdown") {
|
||||
if (DEBUG) {
|
||||
debug("Received '" + msg.name + "' message from content process");
|
||||
}
|
||||
|
||||
if (msg.name == kMsgNameChildProcessShutdown) {
|
||||
// By the time we receive child-process-shutdown, the child process has
|
||||
// already forgotten its permissions so we need to unregister the target
|
||||
// for every permission.
|
||||
@ -203,10 +228,19 @@ this.RilMessageManager = {
|
||||
observe: function observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case kSysMsgListenerReadyObserverTopic:
|
||||
this.ready = true;
|
||||
Services.obs.removeObserver(this, kSysMsgListenerReadyObserverTopic);
|
||||
|
||||
this._resendQueuedTargetMessage();
|
||||
break;
|
||||
case "xpcom-shutdown":
|
||||
|
||||
case kPrefenceChangedObserverTopic:
|
||||
if (data === kPrefKeyRilDebuggingEnabled) {
|
||||
this._updateDebugFlag();
|
||||
}
|
||||
break;
|
||||
|
||||
case kXpcomShutdownObserverTopic:
|
||||
this._shutdown();
|
||||
break;
|
||||
}
|
||||
@ -259,7 +293,9 @@ this.RilMessageManager = {
|
||||
this.callbacksByName = remains;
|
||||
},
|
||||
|
||||
sendMobileConnectionMessage: function sendMobileConnectionMessage(name, clientId, data) {
|
||||
sendMobileConnectionMessage: function sendMobileConnectionMessage(name,
|
||||
clientId,
|
||||
data) {
|
||||
this._sendTargetMessage("mobileconnection", name, {
|
||||
clientId: clientId,
|
||||
data: data
|
||||
@ -273,7 +309,8 @@ this.RilMessageManager = {
|
||||
});
|
||||
},
|
||||
|
||||
sendCellBroadcastMessage: function sendCellBroadcastMessage(name, clientId, data) {
|
||||
sendCellBroadcastMessage: function sendCellBroadcastMessage(name, clientId,
|
||||
data) {
|
||||
this._sendTargetMessage("cellbroadcast", name, {
|
||||
clientId: clientId,
|
||||
data: data
|
||||
|
Loading…
Reference in New Issue
Block a user