Bug 873348 - System Message API: s/sendSystemMessage/openAppForSystemMessage/ in the shell.js. r=fabrice

This commit is contained in:
Gene Lian 2013-05-24 16:17:54 +08:00
parent f34ce8f6d9
commit 50e1cb681f

View File

@ -431,8 +431,8 @@ var shell = {
}, },
lastHardwareButtonEventType: null, // property for the hack above lastHardwareButtonEventType: null, // property for the hack above
needBufferSysMsgs: true, needBufferOpenAppReq: true,
bufferedSysMsgs: [], bufferedOpenAppReqs: [],
timer: null, timer: null,
visibleNormalAudioActive: false, visibleNormalAudioActive: false,
@ -548,7 +548,7 @@ var shell = {
ObjectWrapper.wrap(details, getContentWindow())); ObjectWrapper.wrap(details, getContentWindow()));
}, },
sendSystemMessage: function shell_sendSystemMessage(msg) { openAppForSystemMessage: function shell_openAppForSystemMessage(msg) {
let origin = Services.io.newURI(msg.manifest, null, null).prePath; let origin = Services.io.newURI(msg.manifest, null, null).prePath;
this.sendChromeEvent({ this.sendChromeEvent({
type: 'open-app', type: 'open-app',
@ -623,16 +623,16 @@ nsBrowserAccess.prototype = {
} }
}; };
// Listen for system messages and relay them to Gaia. // Listen for the request of opening app and relay them to Gaia.
Services.obs.addObserver(function onSystemMessage(subject, topic, data) { Services.obs.addObserver(function onSystemMessageOpenApp(subject, topic, data) {
let msg = JSON.parse(data); let msg = JSON.parse(data);
// Buffer non-activity messages until content starts to load for 10 seconds. // Buffer non-activity request until content starts to load for 10 seconds.
// We'll revisit this later if new kind of messages don't need to be cached. // We'll revisit this later if new kind of requests don't need to be cached.
if (shell.needBufferSysMsgs && msg.type !== 'activity') { if (shell.needBufferOpenAppReq && msg.type !== 'activity') {
shell.bufferedSysMsgs.push(msg); shell.bufferedOpenAppReqs.push(msg);
return; return;
} }
shell.sendSystemMessage(msg); shell.openAppForSystemMessage(msg);
}, 'system-messages-open-app', false); }, 'system-messages-open-app', false);
Services.obs.addObserver(function(aSubject, aTopic, aData) { Services.obs.addObserver(function(aSubject, aTopic, aData) {
@ -662,14 +662,17 @@ var CustomEventManager = {
content.addEventListener("mozContentEvent", this, false, true); content.addEventListener("mozContentEvent", this, false, true);
// After content starts to load for 10 seconds, send and // After content starts to load for 10 seconds, send and
// clean up the buffered system messages if there is any. // clean up the buffered open-app requests if there is any.
//
// TODO: Bug 793420 - Remove the waiting timer for the 'open-app'
// mozChromeEvents requested by System Message
shell.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); shell.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
shell.timer.initWithCallback(function timerCallback() { shell.timer.initWithCallback(function timerCallback() {
shell.bufferedSysMsgs.forEach(function sendSysMsg(msg) { shell.bufferedOpenAppReqs.forEach(function bufferOpenAppReq(msg) {
shell.sendSystemMessage(msg); shell.openAppForSystemMessage(msg);
}); });
shell.bufferedSysMsgs.length = 0; shell.bufferedOpenAppReqs.length = 0;
shell.needBufferSysMsgs = false; shell.needBufferOpenAppReq = false;
shell.timer = null; shell.timer = null;
}, 10000, Ci.nsITimer.TYPE_ONE_SHOT); }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
}).bind(this), false); }).bind(this), false);