Bug 1212321 - Stop painting on app launch. r=fabrice

This commit is contained in:
Vivien Nicolas 2016-01-21 14:54:33 -08:00
parent d90a1537be
commit 43d70660ae
2 changed files with 45 additions and 4 deletions

View File

@ -573,8 +573,6 @@ WebappsApplication.prototype = {
launch: function(aStartPoint) { launch: function(aStartPoint) {
let request = this.createRequest(); let request = this.createRequest();
this.addMessageListeners(["Webapps:Launch:Return:OK",
"Webapps:Launch:Return:KO"]);
cpmm.sendAsyncMessage("Webapps:Launch", { origin: this.origin, cpmm.sendAsyncMessage("Webapps:Launch", { origin: this.origin,
manifestURL: this.manifestURL, manifestURL: this.manifestURL,
startPoint: aStartPoint || "", startPoint: aStartPoint || "",
@ -582,6 +580,14 @@ WebappsApplication.prototype = {
topId: this._topId, topId: this._topId,
timestamp: Date.now(), timestamp: Date.now(),
requestID: this.getRequestId(request) }); requestID: this.getRequestId(request) });
let manifestURL = AppsUtils.getAppManifestURLFromWindow(this._window);
if (manifestURL != this.manifestURL) {
Services.obs.notifyObservers(null, "will-launch-app", null);
}
this.addMessageListeners(["Webapps:Launch:Return:OK",
"Webapps:Launch:Return:KO"]);
return request; return request;
}, },

View File

@ -27,6 +27,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "ManifestObtainer",
var kLongestReturnedString = 128; var kLongestReturnedString = 128;
const Timer = Components.Constructor("@mozilla.org/timer;1",
"nsITimer",
"initWithCallback");
function debug(msg) { function debug(msg) {
//dump("BrowserElementChildPreload - " + msg + "\n"); //dump("BrowserElementChildPreload - " + msg + "\n");
} }
@ -65,7 +69,8 @@ const OBSERVED_EVENTS = [
'xpcom-shutdown', 'xpcom-shutdown',
'audio-playback', 'audio-playback',
'activity-done', 'activity-done',
'invalid-widget' 'invalid-widget',
'will-launch-app'
]; ];
/** /**
@ -316,11 +321,14 @@ BrowserElementChild.prototype = {
this.forwarder.init(); this.forwarder.init();
}, },
_paintFrozenTimer: null,
observe: function(subject, topic, data) { observe: function(subject, topic, data) {
// Ignore notifications not about our document. (Note that |content| /can/ // Ignore notifications not about our document. (Note that |content| /can/
// be null; see bug 874900.) // be null; see bug 874900.)
if (topic !== 'activity-done' && topic !== 'audio-playback' && if (topic !== 'activity-done' &&
topic !== 'audio-playback' &&
topic !== 'will-launch-app' &&
(!content || subject !== content.document)) { (!content || subject !== content.document)) {
return; return;
} }
@ -341,9 +349,31 @@ BrowserElementChild.prototype = {
case 'invalid-widget': case 'invalid-widget':
sendAsyncMsg('error', { type: 'invalid-widget' }); sendAsyncMsg('error', { type: 'invalid-widget' });
break; break;
case 'will-launch-app':
// If the launcher is not visible, let's ignore the message.
if (!docShell.isActive) {
return;
}
// If this is not a content process, let's not freeze painting.
if (Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_CONTENT) {
return;
}
docShell.contentViewer.pausePainting();
this._paintFrozenTimer && this._paintFrozenTimer.cancel();
this._paintFrozenTimer = new Timer(this, 3000, Ci.nsITimer.TYPE_ONE_SHOT);
break;
} }
}, },
notify: function(timer) {
docShell.contentViewer.resumePainting();
this._paintFrozenTimer.cancel();
this._paintFrozenTimer = null;
},
/** /**
* Called when our TabChildGlobal starts to die. This is not called when the * Called when our TabChildGlobal starts to die. This is not called when the
* page inside |content| unloads. * page inside |content| unloads.
@ -1265,6 +1295,11 @@ BrowserElementChild.prototype = {
if (docShell && docShell.isActive !== visible) { if (docShell && docShell.isActive !== visible) {
docShell.isActive = visible; docShell.isActive = visible;
sendAsyncMsg('visibilitychange', {visible: visible}); sendAsyncMsg('visibilitychange', {visible: visible});
// Ensure painting is not frozen if the app goes visible.
if (visible && this._paintFrozenTimer) {
this.notify();
}
} }
}, },