Bug 1439875: Fire MozBeforeInitialXULLayout before sizing the window. r=florian,smaug

This gives the chance to code that relies on setting the XUL window attributes
to run before we actually size the window.

This should prevent the resizing on OSX and fix some other untested stuff that
the first commit probably broke...

MozReview-Commit-ID: DhCWgmCppek
This commit is contained in:
Emilio Cobos Álvarez 2018-02-22 16:27:46 +01:00
parent 7ca346f1b8
commit e60d31cc60
2 changed files with 32 additions and 26 deletions

View File

@ -1174,7 +1174,10 @@ function RedirectLoad({ target: browser, data }) {
}
if (document.documentElement.getAttribute("windowtype") == "navigator:browser") {
addEventListener("DOMContentLoaded", function() {
document.addEventListener("MozBeforeInitialXULLayout", function() {
gBrowserInit.onBeforeInitialXULLayout();
}, { once: true });
document.addEventListener("DOMContentLoaded", function() {
gBrowserInit.onDOMContentLoaded();
}, { once: true });
}
@ -1187,6 +1190,27 @@ var delayedStartupPromise = new Promise(resolve => {
var gBrowserInit = {
delayedStartupFinished: false,
onBeforeInitialXULLayout() {
// Set a sane starting width/height for all resolutions on new profiles.
if (Services.prefs.getBoolPref("privacy.resistFingerprinting")) {
// When the fingerprinting resistance is enabled, making sure that we don't
// have a maximum window to interfere with generating rounded window dimensions.
document.documentElement.setAttribute("sizemode", "normal");
} else if (!document.documentElement.hasAttribute("width")) {
const TARGET_WIDTH = 1280;
const TARGET_HEIGHT = 1040;
let width = Math.min(screen.availWidth * .9, TARGET_WIDTH);
let height = Math.min(screen.availHeight * .9, TARGET_HEIGHT);
document.documentElement.setAttribute("width", width);
document.documentElement.setAttribute("height", height);
if (width < TARGET_WIDTH && height < TARGET_HEIGHT) {
document.documentElement.setAttribute("sizemode", "maximized");
}
}
},
onDOMContentLoaded() {
gBrowser = window._gBrowser;
delete window._gBrowser;
@ -1230,25 +1254,6 @@ var gBrowserInit = {
initBrowser.removeAttribute("blank");
}
// Set a sane starting width/height for all resolutions on new profiles.
if (Services.prefs.getBoolPref("privacy.resistFingerprinting")) {
// When the fingerprinting resistance is enabled, making sure that we don't
// have a maximum window to interfere with generating rounded window dimensions.
document.documentElement.setAttribute("sizemode", "normal");
} else if (!document.documentElement.hasAttribute("width")) {
const TARGET_WIDTH = 1280;
const TARGET_HEIGHT = 1040;
let width = Math.min(screen.availWidth * .9, TARGET_WIDTH);
let height = Math.min(screen.availHeight * .9, TARGET_HEIGHT);
document.documentElement.setAttribute("width", width);
document.documentElement.setAttribute("height", height);
if (width < TARGET_WIDTH && height < TARGET_HEIGHT) {
document.documentElement.setAttribute("sizemode", "maximized");
}
}
gBrowser.updateBrowserRemoteness(initBrowser, isRemote, {
remoteType, sameProcessAsFrameLoader
});

View File

@ -2662,6 +2662,13 @@ XULDocument::DoneWalking()
NotifyPossibleTitleChange(false);
nsContentUtils::DispatchTrustedEvent(
this,
static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
true,
false);
// Before starting layout, check whether we're a toplevel chrome
// window. If we are, setup some state so that we don't have to restyle
// the whole tree after StartLayout.
@ -2678,12 +2685,6 @@ XULDocument::DoneWalking()
}
}
nsContentUtils::DispatchTrustedEvent(this,
static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
true,
false);
StartLayout();
if (mIsWritingFastLoad && IsChromeURI(mDocumentURI))