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
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1188,29 +1188,53 @@ function RedirectLoad({ target: browser,
}
};
Services.obs.addObserver(delayedStartupFinished,
"browser-delayed-startup-finished");
}
}
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 });
}
let _resolveDelayedStartup;
var delayedStartupPromise = new Promise(resolve => {
_resolveDelayedStartup = 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() {
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = window.XULBrowserWindow;
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow =
@@ -1240,35 +1264,16 @@ var gBrowserInit = {
if (linkedBrowser) {
remoteType = linkedBrowser.remoteType;
isRemote = remoteType != E10SUtils.NOT_REMOTE;
sameProcessAsFrameLoader = linkedBrowser.frameLoader;
}
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
});
gUIDensity.init();
if (AppConstants.CAN_DRAW_IN_TITLEBAR) {
gDragSpaceObserver.init();
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -2657,38 +2657,39 @@ XULDocument::DoneWalking()
// the |if (!mDocumentLoaded)| check above and since
// mInitialLayoutComplete will be false will follow the else branch
// there too. See the big comment there for how such reentry can
// happen.
mDocumentLoaded = true;
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.
if (nsCOMPtr<nsIDocShellTreeItem> item = GetDocShell()) {
nsCOMPtr<nsIDocShellTreeOwner> owner;
item->GetTreeOwner(getter_AddRefs(owner));
if (nsCOMPtr<nsIXULWindow> xulWin = do_GetInterface(owner)) {
nsCOMPtr<nsIDocShell> xulWinShell;
xulWin->GetDocShell(getter_AddRefs(xulWinShell));
if (SameCOMIdentity(xulWinShell, item)) {
// We're the chrome document!
xulWin->BeforeStartLayout();
}
}
}
- nsContentUtils::DispatchTrustedEvent(this,
- static_cast<nsIDocument*>(this),
- NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
- true,
- false);
-
StartLayout();
if (mIsWritingFastLoad && IsChromeURI(mDocumentURI))
nsXULPrototypeCache::GetInstance()->WritePrototype(mMasterPrototype);
NS_ASSERTION(mDelayFrameLoaderInitialization,
"mDelayFrameLoaderInitialization should be true!");
mDelayFrameLoaderInitialization = false;