Bug 1580117 - Skip preloaded browsers in minimized windows. r=mattwoodrow,Gijs

If the browser window is minimized, it's unlikely that a preloaded browser will
be useful in the near future. This change skips creating one in such a case.

This avoids an issue in the graphics layer where about:newtab content marks
itself as `renderLayers = true`, and will try to composite content in windows
which are not compositing (because they are hidden).

As an additional level of safety, we also check the preloaded browser's owner
window's minimized state just before setting `renderLayers`, in case it may have
changed after the preloaded browser was created.

Differential Revision: https://phabricator.services.mozilla.com/D85955
This commit is contained in:
J. Ryan Stinnett 2020-09-17 16:57:35 +00:00
Родитель b1df6f0420
Коммит a43303bc1b
3 изменённых файлов: 54 добавлений и 30 удалений

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

@ -288,11 +288,16 @@ this.ActivityStreamMessageChannel = class ActivityStreamMessageChannel {
*/
onNewTabLoad(msg) {
let { browser } = msg.target;
if (this.isPreloadedBrowser(browser)) {
if (
this.isPreloadedBrowser(browser) &&
browser.ownerGlobal.windowState !== browser.ownerGlobal.STATE_MINIMIZED &&
!browser.ownerGlobal.isFullyOccluded
) {
// As a perceived performance optimization, if this loaded Activity Stream
// happens to be a preloaded browser, have it render its layers to the
// compositor now to increase the odds that by the time we switch to
// the tab, the layers are already ready to present to the user.
// happens to be a preloaded browser in a window that is not minimized or
// occluded, have it render its layers to the compositor now to increase
// the odds that by the time we switch to the tab, the layers are already
// ready to present to the user.
browser.renderLayers = true;
}

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

@ -127,14 +127,20 @@ describe("ActivityStreamMessageChannel", () => {
loaded: false,
portID: "inited",
simulated: true,
browser: { getAttribute: () => "preloaded" },
browser: {
getAttribute: () => "preloaded",
ownerGlobal: {},
},
});
RPmessagePorts.push({
url: "about:sheep",
loaded: true,
portID: "loaded",
simulated: true,
browser: { getAttribute: () => "preloaded" },
browser: {
getAttribute: () => "preloaded",
ownerGlobal: {},
},
});
mm.simulateMessagesForExistingTabs();
@ -152,7 +158,10 @@ describe("ActivityStreamMessageChannel", () => {
RPmessagePorts.push({
loaded: true,
portID: "foo",
browser: { getAttribute: () => "preloaded" },
browser: {
getAttribute: () => "preloaded",
ownerGlobal: {},
},
});
mm.simulateMessagesForExistingTabs();
@ -167,7 +176,17 @@ describe("ActivityStreamMessageChannel", () => {
RPmessagePorts.push({
loaded: true,
portID: "foo",
browser: { getAttribute: () => "preloaded" },
browser: {
getAttribute: () => "preloaded",
ownerGlobal: {
STATE_MAXIMIZED: 1,
STATE_MINIMIZED: 2,
STATE_NORMAL: 3,
STATE_FULLSCREEN: 4,
windowState: 3,
isFullyOccluded: false,
},
},
});
mm.simulateMessagesForExistingTabs();
assert.equal(RPmessagePorts[0].browser.renderLayers, true);
@ -222,9 +241,8 @@ describe("ActivityStreamMessageChannel", () => {
it("should get a preloaded browser if it exists", () => {
const port = {
browser: {
getAttribute() {
return "preloaded";
},
getAttribute: () => "preloaded",
ownerGlobal: {},
},
};
mm.createChannel();
@ -234,9 +252,8 @@ describe("ActivityStreamMessageChannel", () => {
it("should get all the preloaded browsers across windows if they exist", () => {
const port = {
browser: {
getAttribute() {
return "preloaded";
},
getAttribute: () => "preloaded",
ownerGlobal: {},
},
};
mm.createChannel();
@ -247,9 +264,8 @@ describe("ActivityStreamMessageChannel", () => {
it("should return null if there is no preloaded browser", () => {
const port = {
browser: {
getAttribute() {
return "consumed";
},
getAttribute: () => "consumed",
ownerGlobal: {},
},
};
mm.createChannel();
@ -274,7 +290,10 @@ describe("ActivityStreamMessageChannel", () => {
it("should dispatch a NEW_TAB_LOAD action", () => {
const t = {
portID: "foo",
browser: { getAttribute: () => "preloaded" },
browser: {
getAttribute: () => "preloaded",
ownerGlobal: {},
},
};
sinon.stub(mm, "onActionFromContent");
mm.onNewTabLoad({ target: t });
@ -366,9 +385,8 @@ describe("ActivityStreamMessageChannel", () => {
it("should send the message to the preloaded browser if there's data and a preloaded browser exists", () => {
const port = {
browser: {
getAttribute() {
return "preloaded";
},
getAttribute: () => "preloaded",
ownerGlobal: {},
},
sendAsyncMessage: sinon.spy(),
};
@ -385,9 +403,8 @@ describe("ActivityStreamMessageChannel", () => {
it("should send the message to all the preloaded browsers if there's data and they exist", () => {
const port = {
browser: {
getAttribute() {
return "preloaded";
},
getAttribute: () => "preloaded",
ownerGlobal: {},
},
sendAsyncMessage: sinon.spy(),
};
@ -400,9 +417,8 @@ describe("ActivityStreamMessageChannel", () => {
it("should not send the message to the preloaded browser if there's no data and a preloaded browser does not exists", () => {
const port = {
browser: {
getAttribute() {
return "consumed";
},
getAttribute: () => "consumed",
ownerGlobal: {},
},
sendAsyncMessage: sinon.spy(),
};

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

@ -101,12 +101,15 @@ let NewTabPagePreloading = {
},
maybeCreatePreloadedBrowser(window) {
// If we're not enabled, have already got one, or are in a popup window,
// don't bother creating a preload browser - there's no point.
// If we're not enabled, have already got one, are in a popup window, or the
// window is minimized / occluded, don't bother creating a preload browser -
// there's no point.
if (
!this.enabled ||
window.gBrowser.preloadedBrowser ||
!window.toolbar.visible
!window.toolbar.visible ||
window.windowState == window.STATE_MINIMIZED ||
window.isFullyOccluded
) {
return;
}