Bug 1962056 - use the category manager for first window ready initialization, r=firefox-desktop-core-reviewers ,mossop

Differential Revision: https://phabricator.services.mozilla.com/D244429
This commit is contained in:
Gijs Kruitbosch
2025-05-21 21:49:20 +00:00
committed by amarc@mozilla.com
parent 2b5b645133
commit b31d9f0790
5 changed files with 43 additions and 67 deletions

View File

@@ -36,6 +36,24 @@ category browser-window-unload moz-src:///browser/components/tabbrowser/NewTabPa
category browser-window-delayed-startup resource:///modules/taskbartabs/TaskbarTabs.sys.mjs TaskbarTabs.init category browser-window-delayed-startup resource:///modules/taskbartabs/TaskbarTabs.sys.mjs TaskbarTabs.init
# App startup consumers # App startup consumers
category browser-first-window-ready resource:///modules/AboutNewTab.sys.mjs AboutNewTab.init
category browser-first-window-ready resource:///modules/ContentCrashHandlers.sys.mjs TabCrashHandler.init
category browser-first-window-ready resource:///modules/ProcessHangMonitor.sys.mjs ProcessHangMonitor.init
category browser-first-window-ready resource://gre/modules/PageThumbs.sys.mjs PageThumbs.init
category browser-first-window-ready resource://gre/modules/NewTabUtils.sys.mjs NewTabUtils.init
category browser-first-window-ready resource:///modules/PageActions.sys.mjs PageActions.init
category browser-first-window-ready resource://gre/modules/DoHController.sys.mjs DoHController.init
category browser-first-window-ready moz-src:///toolkit/profile/ProfilesDatastoreService.sys.mjs ProfilesDatastoreService.init
category browser-first-window-ready resource:///modules/profiles/SelectableProfileService.sys.mjs SelectableProfileService.init
category browser-first-window-ready moz-src:///browser/components/protections/ContentBlockingPrefs.sys.mjs ContentBlockingPrefs.init
category browser-first-window-ready resource://gre/modules/CaptchaDetectionPingUtils.sys.mjs CaptchaDetectionPingUtils.init
#ifdef MOZ_SANDBOX
#ifdef XP_LINUX
category browser-first-window-ready resource://gre/modules/SandboxUtils.sys.mjs SandboxUtils.maybeWarnAboutMissingUserNamespaces
#endif
#endif
category browser-idle-startup resource:///modules/PlacesUIUtils.sys.mjs PlacesUIUtils.unblockToolbars category browser-idle-startup resource:///modules/PlacesUIUtils.sys.mjs PlacesUIUtils.unblockToolbars
category browser-idle-startup resource:///modules/BuiltInThemes.sys.mjs BuiltInThemes.ensureBuiltInThemes category browser-idle-startup resource:///modules/BuiltInThemes.sys.mjs BuiltInThemes.ensureBuiltInThemes
category browser-idle-startup resource://gre/modules/RFPHelper.sys.mjs RFPHelper.init category browser-idle-startup resource://gre/modules/RFPHelper.sys.mjs RFPHelper.init

View File

@@ -9,7 +9,6 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, { ChromeUtils.defineESModuleGetters(lazy, {
AboutHomeStartupCache: "resource:///modules/AboutHomeStartupCache.sys.mjs", AboutHomeStartupCache: "resource:///modules/AboutHomeStartupCache.sys.mjs",
AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
AWToolbarButton: "resource:///modules/aboutwelcome/AWToolbarUtils.sys.mjs", AWToolbarButton: "resource:///modules/aboutwelcome/AWToolbarUtils.sys.mjs",
ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs", ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs",
ASRouterDefaultConfig: ASRouterDefaultConfig:
@@ -22,8 +21,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs", BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs", BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
CaptchaDetectionPingUtils:
"resource://gre/modules/CaptchaDetectionPingUtils.sys.mjs",
ContentBlockingPrefs: ContentBlockingPrefs:
"moz-src:///browser/components/protections/ContentBlockingPrefs.sys.mjs", "moz-src:///browser/components/protections/ContentBlockingPrefs.sys.mjs",
ContextualIdentityService: ContextualIdentityService:
@@ -36,7 +33,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
"moz-src:///browser/components/DesktopActorRegistry.sys.mjs", "moz-src:///browser/components/DesktopActorRegistry.sys.mjs",
Discovery: "resource:///modules/Discovery.sys.mjs", Discovery: "resource:///modules/Discovery.sys.mjs",
DistributionManagement: "resource:///modules/distribution.sys.mjs", DistributionManagement: "resource:///modules/distribution.sys.mjs",
DoHController: "resource://gre/modules/DoHController.sys.mjs",
DownloadsViewableInternally: DownloadsViewableInternally:
"resource:///modules/DownloadsViewableInternally.sys.mjs", "resource:///modules/DownloadsViewableInternally.sys.mjs",
ExtensionsUI: "resource:///modules/ExtensionsUI.sys.mjs", ExtensionsUI: "resource:///modules/ExtensionsUI.sys.mjs",
@@ -48,13 +44,10 @@ ChromeUtils.defineESModuleGetters(lazy, {
LoginBreaches: "resource:///modules/LoginBreaches.sys.mjs", LoginBreaches: "resource:///modules/LoginBreaches.sys.mjs",
LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs", LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs",
MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs", MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
NewTabUtils: "resource://gre/modules/NewTabUtils.sys.mjs",
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
OnboardingMessageProvider: OnboardingMessageProvider:
"resource:///modules/asrouter/OnboardingMessageProvider.sys.mjs", "resource:///modules/asrouter/OnboardingMessageProvider.sys.mjs",
PageActions: "resource:///modules/PageActions.sys.mjs",
PageDataService: "resource:///modules/pagedata/PageDataService.sys.mjs", PageDataService: "resource:///modules/pagedata/PageDataService.sys.mjs",
PageThumbs: "resource://gre/modules/PageThumbs.sys.mjs",
PdfJs: "resource://pdf.js/PdfJs.sys.mjs", PdfJs: "resource://pdf.js/PdfJs.sys.mjs",
PlacesBrowserStartup: PlacesBrowserStartup:
"moz-src:///browser/components/places/PlacesBrowserStartup.sys.mjs", "moz-src:///browser/components/places/PlacesBrowserStartup.sys.mjs",
@@ -62,22 +55,16 @@ ChromeUtils.defineESModuleGetters(lazy, {
// eslint-disable-next-line mozilla/valid-lazy // eslint-disable-next-line mozilla/valid-lazy
PluginManager: "resource:///actors/PluginParent.sys.mjs", PluginManager: "resource:///actors/PluginParent.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
ProcessHangMonitor: "resource:///modules/ProcessHangMonitor.sys.mjs",
ProfileDataUpgrader: ProfileDataUpgrader:
"moz-src:///browser/components/ProfileDataUpgrader.sys.mjs", "moz-src:///browser/components/ProfileDataUpgrader.sys.mjs",
ProfilesDatastoreService:
"moz-src:///toolkit/profile/ProfilesDatastoreService.sys.mjs",
RemoteSecuritySettings: RemoteSecuritySettings:
"resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs", "resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs",
RemoteSettings: "resource://services-settings/remote-settings.sys.mjs", RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs", SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
Sanitizer: "resource:///modules/Sanitizer.sys.mjs", Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
SandboxUtils: "resource://gre/modules/SandboxUtils.sys.mjs",
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs", ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
SearchSERPTelemetry: SearchSERPTelemetry:
"moz-src:///browser/components/search/SearchSERPTelemetry.sys.mjs", "moz-src:///browser/components/search/SearchSERPTelemetry.sys.mjs",
SelectableProfileService:
"resource:///modules/profiles/SelectableProfileService.sys.mjs",
SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs", SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs", ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
@@ -88,7 +75,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
TelemetryReportingPolicy: TelemetryReportingPolicy:
"resource://gre/modules/TelemetryReportingPolicy.sys.mjs", "resource://gre/modules/TelemetryReportingPolicy.sys.mjs",
TRRRacer: "resource:///modules/TRRPerformance.sys.mjs", TRRRacer: "resource:///modules/TRRPerformance.sys.mjs",
TabCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
WebChannel: "resource://gre/modules/WebChannel.sys.mjs", WebChannel: "resource://gre/modules/WebChannel.sys.mjs",
WebProtocolHandlerRegistrar: WebProtocolHandlerRegistrar:
"resource:///modules/WebProtocolHandlerRegistrar.sys.mjs", "resource:///modules/WebProtocolHandlerRegistrar.sys.mjs",
@@ -661,16 +647,6 @@ BrowserGlue.prototype = {
); );
}, },
_verifySandboxUserNamespaces: function BG_verifySandboxUserNamespaces(aWin) {
if (!AppConstants.MOZ_SANDBOX) {
return;
}
lazy.SandboxUtils.maybeWarnAboutMissingUserNamespaces(
aWin.gNotificationBox
);
},
_earlyBlankFirstPaint(cmdLine) { _earlyBlankFirstPaint(cmdLine) {
let startTime = Cu.now(); let startTime = Cu.now();
@@ -818,12 +794,6 @@ BrowserGlue.prototype = {
// the first browser window has finished initializing // the first browser window has finished initializing
_onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) { _onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) {
lazy.AboutNewTab.init();
lazy.TabCrashHandler.init();
lazy.ProcessHangMonitor.init();
// A channel for "remote troubleshooting" code... // A channel for "remote troubleshooting" code...
let channel = new lazy.WebChannel( let channel = new lazy.WebChannel(
"remote-troubleshooting", "remote-troubleshooting",
@@ -854,24 +824,6 @@ BrowserGlue.prototype = {
lazy.WeaveService.init(); lazy.WeaveService.init();
} }
lazy.PageThumbs.init();
lazy.NewTabUtils.init();
lazy.PageActions.init();
lazy.DoHController.init();
lazy.ProfilesDatastoreService.init().catch(console.error);
lazy.SelectableProfileService.init().catch(console.error);
this._firstWindowTelemetry(aWindow);
lazy.ContentBlockingPrefs.init();
lazy.CaptchaDetectionPingUtils.init();
this._verifySandboxUserNamespaces(aWindow);
lazy.BrowserUtils.callModulesFromCategory( lazy.BrowserUtils.callModulesFromCategory(
{ {
categoryName: "browser-first-window-ready", categoryName: "browser-first-window-ready",
@@ -879,6 +831,8 @@ BrowserGlue.prototype = {
}, },
aWindow aWindow
); );
this._firstWindowTelemetry(aWindow);
}, },
_maybeOfferProfileReset() { _maybeOfferProfileReset() {

View File

@@ -3,9 +3,6 @@
"use strict"; "use strict";
const kCID = "@mozilla.org/browser/browserglue;1";
const BrowserGlue = Cc[kCID].getService(Ci.nsISupports).wrappedJSObject;
const kNotificationSelector = const kNotificationSelector =
'notification-message[message-bar-type="infobar"]' + 'notification-message[message-bar-type="infobar"]' +
'[value="sandbox-unprivileged-namespaces"]'; '[value="sandbox-unprivileged-namespaces"]';
@@ -39,6 +36,9 @@ async function getNotification(shouldBeNull = false) {
} }
if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) { if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
let { SandboxUtils } = ChromeUtils.importESModule(
"resource://gre/modules/SandboxUtils.sys.mjs"
);
add_setup(async function setup() { add_setup(async function setup() {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["security.sandbox.warn_unprivileged_namespaces", true]], set: [["security.sandbox.warn_unprivileged_namespaces", true]],
@@ -59,7 +59,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
"No existing notification" "No existing notification"
); );
setHasUsernamespaces(true); setHasUsernamespaces(true);
BrowserGlue._verifySandboxUserNamespaces(window); SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
const notification = await getNotification(/* shouldBeNull */ true); const notification = await getNotification(/* shouldBeNull */ true);
Assert.equal( Assert.equal(
@@ -76,7 +76,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
"No existing notification" "No existing notification"
); );
setHasUsernamespaces(false); setHasUsernamespaces(false);
BrowserGlue._verifySandboxUserNamespaces(window); SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
const notification = await getNotification(); const notification = await getNotification();
Assert.notEqual( Assert.notEqual(
@@ -97,7 +97,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
set: [["security.sandbox.warn_unprivileged_namespaces", false]], set: [["security.sandbox.warn_unprivileged_namespaces", false]],
}); });
setHasUsernamespaces(false); setHasUsernamespaces(false);
BrowserGlue._verifySandboxUserNamespaces(window); SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
const notification = await getNotification(/* shouldBeNull */ true); const notification = await getNotification(/* shouldBeNull */ true);
Assert.equal( Assert.equal(
@@ -125,7 +125,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
"Pref is enabled" "Pref is enabled"
); );
setHasUsernamespaces(false); setHasUsernamespaces(false);
BrowserGlue._verifySandboxUserNamespaces(window); SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
const notification = await getNotification(); const notification = await getNotification();
const dontShowAgain = notification.querySelector(".notification-button"); const dontShowAgain = notification.querySelector(".notification-button");
@@ -147,8 +147,10 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
document.querySelector(kNotificationSelector), document.querySelector(kNotificationSelector),
"No existing notification" "No existing notification"
); );
BrowserGlue._verifySandboxUserNamespaces(window); await Assert.rejects(
const notification = await getNotification(/* shouldBeNull */ true); fetch("resource://gre/modules/SandboxUtils.sys.mjs"),
Assert.equal(null, notification, "Notification is not shown on non linux"); /NetworkError when attempting to fetch/,
"SandboxUtils should not be packaged."
);
}); });
} }

View File

@@ -8,11 +8,11 @@ export var SandboxUtils = {
/** /**
* Show a notification bar if user is running without unprivileged namespace * Show a notification bar if user is running without unprivileged namespace
* *
* @param {NotificationBox} aNotificationBox * @param {Window} aWindow
* The target notification box where notification will be added * The window where the notification will be displayed.
*/ */
maybeWarnAboutMissingUserNamespaces: maybeWarnAboutMissingUserNamespaces:
function SU_maybeWarnAboutMissingUserNamespaces(aNotificationBox) { function SU_maybeWarnAboutMissingUserNamespaces(aWindow) {
if (AppConstants.platform !== "linux") { if (AppConstants.platform !== "linux") {
return; return;
} }
@@ -41,7 +41,8 @@ export var SandboxUtils = {
return; return;
} }
const mozXulElement = aNotificationBox.stack.ownerGlobal.MozXULElement; let box = aWindow.gNotificationBox;
const mozXulElement = box.stack.ownerGlobal.MozXULElement;
mozXulElement.insertFTLIfNeeded("toolkit/updates/elevation.ftl"); mozXulElement.insertFTLIfNeeded("toolkit/updates/elevation.ftl");
let buttons = [ let buttons = [
@@ -58,11 +59,11 @@ export var SandboxUtils = {
]; ];
// Now actually create the notification // Now actually create the notification
aNotificationBox.appendNotification( box.appendNotification(
"sandbox-unprivileged-namespaces", "sandbox-unprivileged-namespaces",
{ {
label: { "l10n-id": "sandbox-missing-unprivileged-namespaces" }, label: { "l10n-id": "sandbox-missing-unprivileged-namespaces" },
priority: aNotificationBox.PRIORITY_WARNING_HIGH, priority: box.PRIORITY_WARNING_HIGH,
}, },
buttons buttons
); );

View File

@@ -45,9 +45,10 @@ if CONFIG["MOZ_SANDBOX"] and CONFIG["MOZ_DEBUG"] and CONFIG["ENABLE_TESTS"]:
"/netwerk/base", "/netwerk/base",
] ]
EXTRA_JS_MODULES += [ if CONFIG["MOZ_SANDBOX"] and CONFIG["OS_TARGET"] == "Linux":
EXTRA_JS_MODULES += [
"SandboxUtils.sys.mjs", "SandboxUtils.sys.mjs",
] ]
include("/ipc/chromium/chromium-config.mozbuild") include("/ipc/chromium/chromium-config.mozbuild")