perf: part 2 - Improved startup speed/performance and added some tests for private browsing, b=no-bug, c=common, kbs, mods, tests, glance, workspaces

This commit is contained in:
Mr. M
2025-06-07 01:02:03 +02:00
parent a1bd202b51
commit 8ef4460f00
15 changed files with 115 additions and 65 deletions

View File

@@ -1,12 +1,11 @@
diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js
index bcbfab4a3781ff3c7349115751b3830976eec4bf..1ab08a9344b16cbe791182fce3f6fbf59ca3df91 100644
index bcbfab4a3781ff3c7349115751b3830976eec4bf..8176656b6f5e70ccf3766ad9f5406758fdb7034b 100644
--- a/browser/base/content/browser-init.js
+++ b/browser/base/content/browser-init.js
@@ -186,6 +186,8 @@ var gBrowserInit = {
@@ -186,6 +186,7 @@ var gBrowserInit = {
},
onLoad() {
+ Services.scriptloader.loadSubScript("chrome://browser/content/ZenStartup.mjs", window);
+ Services.scriptloader.loadSubScript("chrome://browser/content/zenThemeModifier.js", window);
gBrowser.addEventListener("DOMUpdateBlockedPopups", e =>
PopupBlockerObserver.handleEvent(e)

View File

@@ -1,5 +1,5 @@
diff --git a/browser/base/content/browser.xhtml b/browser/base/content/browser.xhtml
index 8f8c5536cb6e54300897180ca3f950974c60e930..403f821f561a2dfcf6ad23db7e61712aac867716 100644
index 8f8c5536cb6e54300897180ca3f950974c60e930..78076e29faf749b83d6c8e099af6767621f34d58 100644
--- a/browser/base/content/browser.xhtml
+++ b/browser/base/content/browser.xhtml
@@ -26,6 +26,7 @@
@@ -10,19 +10,18 @@ index 8f8c5536cb6e54300897180ca3f950974c60e930..403f821f561a2dfcf6ad23db7e61712a
persist="screenX screenY width height sizemode"
data-l10n-sync="true">
<head>
@@ -105,8 +106,11 @@
@@ -105,8 +106,10 @@
<title data-l10n-id="browser-main-window-default-title"></title>
+#include zen-preloaded.inc.xhtml
+
<script src="chrome://browser/content/global-scripts.js"></script>
<script src="chrome://browser/content/browser-main.js"></script>
+#include zen-assets.inc.xhtml
</head>
<html:body xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
# All sets except for popupsets (commands, keys, and stringbundles)
@@ -128,9 +132,11 @@
@@ -128,9 +131,11 @@
</vbox>
</html:template>

View File

@@ -1,3 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include zen-locales.inc.xhtml
# Styles used all over the browser
@@ -28,16 +32,26 @@
<link rel="stylesheet" type="text/css" href="chrome://browser/content/zen-styles/zen-download-box-animation.css" />
</linkset>
# Startup "preloaded" scripts that requre globals such as gBrowser and gURLBar
# JS files which are needed by browser.xhtml but no other top level windows to
# support MacOS specific features should be loaded directly from browser-main.js
# rather than this file.
#
# If you update this list, you may need to add a mapping within the following
# file so that ESLint works correctly:
# tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
<script type="text/javascript" src="chrome://browser/content/ZenPreloadedScripts.js"></script>
# Scripts used all over the browser
<script src="chrome://browser/content/ZenUIManager.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenFolders.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenMods.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenCompactMode.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenPinnedTabsStorage.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenWorkspacesStorage.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenPinnedTabManager.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenGradientGenerator.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenViewSplitter.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenGlanceManager.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenMediaController.mjs"></script>
<script src="chrome://browser/content/zen-components/ZenDownloadAnimation.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/ZenUIManager.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenFolders.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenMods.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenCompactMode.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenPinnedTabsStorage.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenWorkspacesStorage.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenPinnedTabManager.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenGradientGenerator.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenViewSplitter.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenGlanceManager.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenMediaController.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenDownloadAnimation.mjs"></script>

View File

@@ -1,7 +1,10 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
content/browser/zenThemeModifier.js (../../zen/common/zenThemeModifier.js)
content/browser/ZenStartup.mjs (../../zen/common/ZenStartup.mjs)
content/browser/ZenPreloadedScripts.js (../../zen/common/ZenPreloadedScripts.js)
content/browser/zen-sets.js (../../zen/common/zen-sets.js)
content/browser/ZenUIManager.mjs (../../zen/common/ZenUIManager.mjs)
content/browser/zen-components/ZenActorsManager.mjs (../../zen/common/ZenActorsManager.mjs)

View File

@@ -10,4 +10,3 @@
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenWorkspacesSync.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenActorsManager.mjs"></script>
<script type="text/javascript" src="chrome://browser/content/zen-components/ZenSessionStore.mjs"></script>

View File

@@ -0,0 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// prettier-ignore
// eslint-disable-next-line no-lone-blocks
{
Services.scriptloader.loadSubScript("chrome://browser/content/ZenStartup.mjs", this);
}

View File

@@ -5,12 +5,11 @@
var ZenStartup = {
_watermarkIgnoreElements: ['zen-browser-background', 'zen-toast-container'],
init() {
async init() {
this.openWatermark();
this._initBrowserBackground();
await this._initBrowserBackground();
this._changeSidebarLocation();
this._zenInitBrowserLayout();
this._initSearchBar();
},
_initBrowserBackground() {
@@ -22,11 +21,10 @@
document.getElementById('browser').prepend(background);
},
_zenInitBrowserLayout() {
async _zenInitBrowserLayout() {
if (this.__hasInitBrowserLayout) return;
this.__hasInitBrowserLayout = true;
try {
console.info('ZenThemeModifier: init browser layout');
const kNavbarItems = ['nav-bar', 'PersonalToolbar'];
const kNewContainerId = 'zen-appcontent-navbar-container';
let newContainer = document.getElementById(kNewContainerId);
@@ -46,7 +44,6 @@
this._hideUnusedElements();
gZenWorkspaces.init();
gZenVerticalTabsManager.init();
gZenUIManager.init();
this._checkForWelcomePage();
@@ -78,6 +75,8 @@
gZenWorkspaces.promiseInitialized.then(async () => {
await delayedStartupPromise;
await SessionStore.promiseAllWindowsRestored;
delete gZenUIManager.promiseInitialized;
this._initSearchBar();
setTimeout(() => {
gZenCompactModeManager.init();
setTimeout(() => {
@@ -162,10 +161,6 @@
_initSearchBar() {
// Only focus the url bar
gURLBar.focus();
gURLBar._initCopyCutController();
gURLBar._initPasteAndGo();
gURLBar._initStripOnShare();
},
_checkForWelcomePage() {
@@ -179,5 +174,11 @@
},
};
window.addEventListener(
'MozBeforeInitialXULLayout',
() => {
ZenStartup.init();
},
{ once: true }
);
}

View File

@@ -34,8 +34,6 @@ var gZenUIManager = {
true
);
gURLBar._zenTrimURL = this.urlbarTrim.bind(this);
document.addEventListener('mousedown', this.handleMouseDown.bind(this), true);
ChromeUtils.defineLazyGetter(this, 'motion', () => {
@@ -48,6 +46,8 @@ var gZenUIManager = {
return document.getElementById('zen-toast-container');
});
gURLBar._zenTrimURL = this.urlbarTrim.bind(this);
new ResizeObserver(this.updateTabsToolbar.bind(this)).observe(
document.getElementById('TabsToolbar')
);
@@ -67,6 +67,7 @@ var gZenUIManager = {
window.addEventListener('TabClose', this.onTabClose.bind(this));
gZenMediaController.init();
gZenVerticalTabsManager.init();
},
handleMouseDown(event) {
@@ -956,6 +957,10 @@ var gZenVerticalTabsManager = {
gZenCompactModeManager.getAndApplySidebarWidth();
}
gZenUIManager.updateTabsToolbar();
gURLBar._initCopyCutController();
gURLBar._initPasteAndGo();
gURLBar._initStripOnShare();
} catch (e) {
console.error(e);
}

View File

@@ -1019,8 +1019,6 @@ var gZenKeyboardShortcutsManager = {
this._applyShortcuts();
await this._saveShortcuts();
console.info('Zen CKS: Initialized');
}
},

View File

@@ -21,8 +21,6 @@
}).format(new Date().getTime());
constructor() {
console.log('[ZenMods]: Initializing ZenMods module');
super();
}

View File

@@ -11,8 +11,8 @@ add_task(async function test_Glance_Next_Tab() {
const tabToCheck = gBrowser.selectedTab;
gBrowser.selectedTab = selectedTab;
await openGlanceOnTab(async (glanceTab) => {
const next = gBrowser.tabContainer.findNextTab(glanceTab, { direction: 1 });
Assert.equal(next, tabToCheck, 'Next glance tab should equal');
gBrowser.tabContainer.advanceSelectedTab(1);
Assert.equal(gBrowser.selectedTab, tabToCheck, 'Next glance tab should equal');
});
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

View File

@@ -10,8 +10,8 @@ add_task(async function test_Glance_Prev_Tab() {
});
const tabToCheck = gBrowser.selectedTab;
gBrowser.selectedTab = glanceTab;
const next = gBrowser.tabContainer.findNextTab(glanceTab, { direction: -1 });
Assert.equal(next, tabToCheck, 'Previous glance tab should equal');
gBrowser.tabContainer.advanceSelectedTab(-1);
Assert.equal(gBrowser.selectedTab, tabToCheck, 'Previous glance tab should equal');
await BrowserTestUtils.removeTab(tabToCheck);
});
});

View File

@@ -7,3 +7,4 @@ support-files = [
["browser_workspace_bookmarks.js"]
["browser_double_click_newtab.js"]
["browser_overflow_scrollbox.js"]
["browser_private_mode.js"]

View File

@@ -0,0 +1,21 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
add_task(async function testPrivateMode() {
await SpecialPowers.pushPrefEnv({
set: [['privacy.userContext.enabled', true]],
});
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({
private: true,
});
await privateWindow.gZenWorkspaces.promiseInitialized;
ok(
privateWindow.document.documentElement.hasAttribute('zen-workspace-id'),
'Private window should have a zen-workspace-id attribute'
);
await BrowserTestUtils.closeWindow(privateWindow);
});

View File

@@ -42,7 +42,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._resolveInitialized = resolve;
});
async waitForPromises() {
async #waitForPromises() {
if (this.privateWindowOrDisabled) {
return;
}
@@ -116,6 +116,9 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
window.addEventListener('resize', this.onWindowResize.bind(this));
this.addPopupListeners();
await this.#waitForPromises();
await this._workspaces();
await this.afterLoadInit();
}
@@ -294,7 +297,6 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
return;
}
this._pinnedTabsResizeObserver = new ResizeObserver(this.onPinnedTabsResize.bind(this));
await this.waitForPromises();
await this._createDefaultWorkspaceIfNeeded();
}
@@ -738,11 +740,12 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
get shouldHaveWorkspaces() {
if (typeof this._shouldHaveWorkspaces === 'undefined') {
let docElement = document.documentElement;
this._shouldHaveWorkspaces = !(
docElement.getAttribute('chromehidden').includes('toolbar') ||
docElement.getAttribute('chromehidden').includes('menubar')
);
let chromeFlags = docShell.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIAppWindow).chromeFlags;
this._shouldHaveWorkspaces =
chromeFlags & Ci.nsIWebBrowserChrome.CHROME_TOOLBAR ||
chromeFlags & Ci.nsIWebBrowserChrome.CHROME_MENUBAR;
return this._shouldHaveWorkspaces;
}
return this._shouldHaveWorkspaces;
@@ -851,7 +854,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
await this.workspaceBookmarks();
await gZenPinnedTabManager.refreshPinnedTabs({ init: true });
await this.changeWorkspace(activeWorkspace, { onInit: true });
await this._selectStartPage();
await this.#selectStartPage();
this._fixTabPositions();
this._resolveInitialized();
this._clearAnyZombieTabs(); // Dont call with await
@@ -868,7 +871,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
}
async _selectStartPage() {
async #selectStartPage() {
if (gZenUIManager.testingEnabled) {
return;
}
@@ -2017,7 +2020,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
) {
delete this._alwaysAnimatePaddingTop;
const essentialsHeight = essentialContainer.getBoundingClientRect().height;
if (!forAnimation && animateContainer) {
if (!forAnimation && animateContainer && gZenUIManager.motion) {
gZenUIManager.motion.animate(
workspaceElement,
{