Skip to content

Commit 3362e20

Browse files
committed
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 UltraBlame original commit: 2f5855c3befc2e0dfbd1047e2f7e563c4cae469c
1 parent 915ba7d commit 3362e20

File tree

5 files changed

+43
-67
lines changed

5 files changed

+43
-67
lines changed

browser/components/BrowserComponents.manifest

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ category browser-window-unload moz-src:///browser/components/tabbrowser/NewTabPa
3636
category browser-window-delayed-startup resource:///modules/taskbartabs/TaskbarTabs.sys.mjs TaskbarTabs.init
3737

3838
# App startup consumers
39+
40+
category browser-first-window-ready resource:///modules/AboutNewTab.sys.mjs AboutNewTab.init
41+
category browser-first-window-ready resource:///modules/ContentCrashHandlers.sys.mjs TabCrashHandler.init
42+
category browser-first-window-ready resource:///modules/ProcessHangMonitor.sys.mjs ProcessHangMonitor.init
43+
category browser-first-window-ready resource://gre/modules/PageThumbs.sys.mjs PageThumbs.init
44+
category browser-first-window-ready resource://gre/modules/NewTabUtils.sys.mjs NewTabUtils.init
45+
category browser-first-window-ready resource:///modules/PageActions.sys.mjs PageActions.init
46+
category browser-first-window-ready resource://gre/modules/DoHController.sys.mjs DoHController.init
47+
category browser-first-window-ready moz-src:///toolkit/profile/ProfilesDatastoreService.sys.mjs ProfilesDatastoreService.init
48+
category browser-first-window-ready resource:///modules/profiles/SelectableProfileService.sys.mjs SelectableProfileService.init
49+
category browser-first-window-ready moz-src:///browser/components/protections/ContentBlockingPrefs.sys.mjs ContentBlockingPrefs.init
50+
category browser-first-window-ready resource://gre/modules/CaptchaDetectionPingUtils.sys.mjs CaptchaDetectionPingUtils.init
51+
#ifdef MOZ_SANDBOX
52+
#ifdef XP_LINUX
53+
category browser-first-window-ready resource://gre/modules/SandboxUtils.sys.mjs SandboxUtils.maybeWarnAboutMissingUserNamespaces
54+
#endif
55+
#endif
56+
3957
category browser-idle-startup resource:///modules/PlacesUIUtils.sys.mjs PlacesUIUtils.unblockToolbars
4058
category browser-idle-startup resource:///modules/BuiltInThemes.sys.mjs BuiltInThemes.ensureBuiltInThemes
4159
category browser-idle-startup resource://gre/modules/RFPHelper.sys.mjs RFPHelper.init

browser/components/BrowserGlue.sys.mjs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const lazy = {};
99

1010
ChromeUtils.defineESModuleGetters(lazy, {
1111
AboutHomeStartupCache: "resource:///modules/AboutHomeStartupCache.sys.mjs",
12-
AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
1312
AWToolbarButton: "resource:///modules/aboutwelcome/AWToolbarUtils.sys.mjs",
1413
ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs",
1514
ASRouterDefaultConfig:
@@ -22,8 +21,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
2221
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
2322
BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs",
2423
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
25-
CaptchaDetectionPingUtils:
26-
"resource://gre/modules/CaptchaDetectionPingUtils.sys.mjs",
2724
ContentBlockingPrefs:
2825
"moz-src:///browser/components/protections/ContentBlockingPrefs.sys.mjs",
2926
ContextualIdentityService:
@@ -36,7 +33,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
3633
"moz-src:///browser/components/DesktopActorRegistry.sys.mjs",
3734
Discovery: "resource:///modules/Discovery.sys.mjs",
3835
DistributionManagement: "resource:///modules/distribution.sys.mjs",
39-
DoHController: "resource://gre/modules/DoHController.sys.mjs",
4036
DownloadsViewableInternally:
4137
"resource:///modules/DownloadsViewableInternally.sys.mjs",
4238
ExtensionsUI: "resource:///modules/ExtensionsUI.sys.mjs",
@@ -48,36 +44,27 @@ ChromeUtils.defineESModuleGetters(lazy, {
4844
LoginBreaches: "resource:///modules/LoginBreaches.sys.mjs",
4945
LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs",
5046
MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
51-
NewTabUtils: "resource://gre/modules/NewTabUtils.sys.mjs",
5247
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
5348
OnboardingMessageProvider:
5449
"resource:///modules/asrouter/OnboardingMessageProvider.sys.mjs",
55-
PageActions: "resource:///modules/PageActions.sys.mjs",
5650
PageDataService: "resource:///modules/pagedata/PageDataService.sys.mjs",
57-
PageThumbs: "resource://gre/modules/PageThumbs.sys.mjs",
5851
PdfJs: "resource://pdf.js/PdfJs.sys.mjs",
5952
PlacesBrowserStartup:
6053
"moz-src:///browser/components/places/PlacesBrowserStartup.sys.mjs",
6154
// PluginManager is used by the `listeners` object below.
6255
// eslint-disable-next-line mozilla/valid-lazy
6356
PluginManager: "resource:///actors/PluginParent.sys.mjs",
6457
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
65-
ProcessHangMonitor: "resource:///modules/ProcessHangMonitor.sys.mjs",
6658
ProfileDataUpgrader:
6759
"moz-src:///browser/components/ProfileDataUpgrader.sys.mjs",
68-
ProfilesDatastoreService:
69-
"moz-src:///toolkit/profile/ProfilesDatastoreService.sys.mjs",
7060
RemoteSecuritySettings:
7161
"resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs",
7262
RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
7363
SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
7464
Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
75-
SandboxUtils: "resource://gre/modules/SandboxUtils.sys.mjs",
7665
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
7766
SearchSERPTelemetry:
7867
"moz-src:///browser/components/search/SearchSERPTelemetry.sys.mjs",
79-
SelectableProfileService:
80-
"resource:///modules/profiles/SelectableProfileService.sys.mjs",
8168
SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
8269
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
8370
ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
@@ -88,7 +75,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
8875
TelemetryReportingPolicy:
8976
"resource://gre/modules/TelemetryReportingPolicy.sys.mjs",
9077
TRRRacer: "resource:///modules/TRRPerformance.sys.mjs",
91-
TabCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
9278
WebChannel: "resource://gre/modules/WebChannel.sys.mjs",
9379
WebProtocolHandlerRegistrar:
9480
"resource:///modules/WebProtocolHandlerRegistrar.sys.mjs",
@@ -661,16 +647,6 @@ BrowserGlue.prototype = {
661647
);
662648
},
663649

664-
_verifySandboxUserNamespaces: function BG_verifySandboxUserNamespaces(aWin) {
665-
if (!AppConstants.MOZ_SANDBOX) {
666-
return;
667-
}
668-
669-
lazy.SandboxUtils.maybeWarnAboutMissingUserNamespaces(
670-
aWin.gNotificationBox
671-
);
672-
},
673-
674650
_earlyBlankFirstPaint(cmdLine) {
675651
let startTime = Cu.now();
676652

@@ -818,12 +794,6 @@ BrowserGlue.prototype = {
818794

819795
// the first browser window has finished initializing
820796
_onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) {
821-
lazy.AboutNewTab.init();
822-
823-
lazy.TabCrashHandler.init();
824-
825-
lazy.ProcessHangMonitor.init();
826-
827797
// A channel for "remote troubleshooting" code...
828798
let channel = new lazy.WebChannel(
829799
"remote-troubleshooting",
@@ -854,31 +824,15 @@ BrowserGlue.prototype = {
854824
lazy.WeaveService.init();
855825
}
856826

857-
lazy.PageThumbs.init();
858-
859-
lazy.NewTabUtils.init();
860-
861-
lazy.PageActions.init();
862-
863-
lazy.DoHController.init();
864-
865-
lazy.ProfilesDatastoreService.init().catch(console.error);
866-
lazy.SelectableProfileService.init().catch(console.error);
867-
868-
this._firstWindowTelemetry(aWindow);
869-
870-
lazy.ContentBlockingPrefs.init();
871-
lazy.CaptchaDetectionPingUtils.init();
872-
873-
this._verifySandboxUserNamespaces(aWindow);
874-
875827
lazy.BrowserUtils.callModulesFromCategory(
876828
{
877829
categoryName: "browser-first-window-ready",
878830
profilerMarker: "browserFirstWindowReady",
879831
},
880832
aWindow
881833
);
834+
835+
this._firstWindowTelemetry(aWindow);
882836
},
883837

884838
_maybeOfferProfileReset() {

browser/components/tests/browser/browser_browserGlue_userNamespacesNotification.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
"use strict";
55

6-
const kCID = "@mozilla.org/browser/browserglue;1";
7-
const BrowserGlue = Cc[kCID].getService(Ci.nsISupports).wrappedJSObject;
8-
96
const kNotificationSelector =
107
'notification-message[message-bar-type="infobar"]' +
118
'[value="sandbox-unprivileged-namespaces"]';
@@ -39,6 +36,9 @@ async function getNotification(shouldBeNull = false) {
3936
}
4037

4138
if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
39+
let { SandboxUtils } = ChromeUtils.importESModule(
40+
"resource://gre/modules/SandboxUtils.sys.mjs"
41+
);
4242
add_setup(async function setup() {
4343
await SpecialPowers.pushPrefEnv({
4444
set: [["security.sandbox.warn_unprivileged_namespaces", true]],
@@ -59,7 +59,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
5959
"No existing notification"
6060
);
6161
setHasUsernamespaces(true);
62-
BrowserGlue._verifySandboxUserNamespaces(window);
62+
SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
6363

6464
const notification = await getNotification( true);
6565
Assert.equal(
@@ -76,7 +76,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
7676
"No existing notification"
7777
);
7878
setHasUsernamespaces(false);
79-
BrowserGlue._verifySandboxUserNamespaces(window);
79+
SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
8080

8181
const notification = await getNotification();
8282
Assert.notEqual(
@@ -97,7 +97,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
9797
set: [["security.sandbox.warn_unprivileged_namespaces", false]],
9898
});
9999
setHasUsernamespaces(false);
100-
BrowserGlue._verifySandboxUserNamespaces(window);
100+
SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
101101

102102
const notification = await getNotification( true);
103103
Assert.equal(
@@ -125,7 +125,7 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
125125
"Pref is enabled"
126126
);
127127
setHasUsernamespaces(false);
128-
BrowserGlue._verifySandboxUserNamespaces(window);
128+
SandboxUtils.maybeWarnAboutMissingUserNamespaces(window);
129129

130130
const notification = await getNotification();
131131
const dontShowAgain = notification.querySelector(".notification-button");
@@ -147,8 +147,10 @@ if (AppConstants.platform === "linux" && AppConstants.MOZ_SANDBOX) {
147147
document.querySelector(kNotificationSelector),
148148
"No existing notification"
149149
);
150-
BrowserGlue._verifySandboxUserNamespaces(window);
151-
const notification = await getNotification( true);
152-
Assert.equal(null, notification, "Notification is not shown on non linux");
150+
await Assert.rejects(
151+
fetch("resource://gre/modules/SandboxUtils.sys.mjs"),
152+
/NetworkError when attempting to fetch/,
153+
"SandboxUtils should not be packaged."
154+
);
153155
});
154156
}

security/sandbox/common/SandboxUtils.sys.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export var SandboxUtils = {
88
/**
99
* Show a notification bar if user is running without unprivileged namespace
1010
*
11-
* @param {NotificationBox} aNotificationBox
12-
* The target notification box where notification will be added
11+
* @param {Window} aWindow
12+
* The window where the notification will be displayed.
1313
*/
1414
maybeWarnAboutMissingUserNamespaces:
15-
function SU_maybeWarnAboutMissingUserNamespaces(aNotificationBox) {
15+
function SU_maybeWarnAboutMissingUserNamespaces(aWindow) {
1616
if (AppConstants.platform !== "linux") {
1717
return;
1818
}
@@ -41,7 +41,8 @@ export var SandboxUtils = {
4141
return;
4242
}
4343

44-
const mozXulElement = aNotificationBox.stack.ownerGlobal.MozXULElement;
44+
let box = aWindow.gNotificationBox;
45+
const mozXulElement = box.stack.ownerGlobal.MozXULElement;
4546
mozXulElement.insertFTLIfNeeded("toolkit/updates/elevation.ftl");
4647

4748
let buttons = [
@@ -58,11 +59,11 @@ export var SandboxUtils = {
5859
];
5960

6061
// Now actually create the notification
61-
aNotificationBox.appendNotification(
62+
box.appendNotification(
6263
"sandbox-unprivileged-namespaces",
6364
{
6465
label: { "l10n-id": "sandbox-missing-unprivileged-namespaces" },
65-
priority: aNotificationBox.PRIORITY_WARNING_HIGH,
66+
priority: box.PRIORITY_WARNING_HIGH,
6667
},
6768
buttons
6869
);

security/sandbox/common/moz.build

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ if CONFIG["MOZ_SANDBOX"] and CONFIG["MOZ_DEBUG"] and CONFIG["ENABLE_TESTS"]:
4545
"/netwerk/base",
4646
]
4747

48-
EXTRA_JS_MODULES += [
49-
"SandboxUtils.sys.mjs",
50-
]
48+
if CONFIG["MOZ_SANDBOX"] and CONFIG["OS_TARGET"] == "Linux":
49+
EXTRA_JS_MODULES += [
50+
"SandboxUtils.sys.mjs",
51+
]
5152

5253
include("/ipc/chromium/chromium-config.mozbuild")
5354

0 commit comments

Comments
 (0)