Skip to content

Commit 36f07fb

Browse files
committed
Bug 2001734 - Add a policy for launch on login. r=tgiles,iholmes,fluent-reviewers,bolsson
Differential Revision: https://phabricator.services.mozilla.com/D313712
1 parent 4e35061 commit 36f07fb

6 files changed

Lines changed: 136 additions & 0 deletions

File tree

‎browser/components/enterprisepolicies/Policies.sys.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
2929
SearchService: "moz-src:///toolkit/components/search/SearchService.sys.mjs",
3030
QuickSuggest: "moz-src:///browser/components/urlbar/QuickSuggest.sys.mjs",
3131
WebsiteFilter: "resource:///modules/policies/WebsiteFilter.sys.mjs",
32+
WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
3233

3334
PoliciesUtils: "resource://gre/modules/PoliciesHelpers.sys.mjs",
3435
addAllowDenyPermissions: "resource://gre/modules/PoliciesHelpers.sys.mjs",
@@ -1220,6 +1221,20 @@ export var Policies = {
12201221
},
12211222
},
12221223

1224+
DisableLaunchOnLogin: {
1225+
onBeforeAddons(manager, param) {
1226+
if (!param || AppConstants.platform !== "win") {
1227+
return;
1228+
}
1229+
manager.disallowFeature("launchOnLogin");
1230+
lazy.PoliciesUtils.setAndLockPref(
1231+
"browser.startup.windowsLaunchOnLogin.enabled",
1232+
false
1233+
);
1234+
lazy.WindowsLaunchOnLogin.removeLaunchOnLogin();
1235+
},
1236+
},
1237+
12231238
DisableMasterPasswordCreation: {
12241239
onBeforeUIStartup(manager, param) {
12251240
if (param) {

‎browser/components/enterprisepolicies/schemas/policies-schema.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,13 @@
897897
"examples": [true, false]
898898
},
899899

900+
"DisableLaunchOnLogin": {
901+
"type": "boolean",
902+
"x-category": "Startup",
903+
"description": "Prevent Firefox from launching automatically when the user logs in, and prevent the user from enabling this setting. This policy currently only has an effect on Windows.",
904+
"examples": [true]
905+
},
906+
900907
"DisableMasterPasswordCreation": {
901908
"type": "boolean",
902909
"x-category": "Password manager",

‎browser/components/enterprisepolicies/tests/browser/browser.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ https_first_disabled = true
6161

6262
["browser_policy_disable_fxaccounts.js"]
6363

64+
["browser_policy_disable_launch_on_login.js"]
65+
run-if = [
66+
"os == 'win'",
67+
]
68+
6469
["browser_policy_disable_masterpassword.js"]
6570

6671
["browser_policy_disable_password_reveal.js"]
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
* http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
"use strict";
5+
6+
ChromeUtils.defineESModuleGetters(this, {
7+
WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
8+
});
9+
10+
const { MockRegistry } = ChromeUtils.importESModule(
11+
"resource://testing-common/MockRegistry.sys.mjs"
12+
);
13+
14+
const ENABLED_PREF = "browser.startup.windowsLaunchOnLogin.enabled";
15+
const isMSIX = Services.sysinfo.getProperty("hasWinPackageId");
16+
17+
let registry = null;
18+
19+
add_setup(async function () {
20+
registry = new MockRegistry();
21+
registry.setValue(
22+
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
23+
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
24+
"",
25+
""
26+
);
27+
registry.setValue(
28+
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
29+
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run",
30+
"",
31+
""
32+
);
33+
registerCleanupFunction(async () => {
34+
registry.shutdown();
35+
await setupPolicyEngineWithJson("");
36+
});
37+
});
38+
39+
async function hasRegistryKey() {
40+
let exists = false;
41+
await WindowsLaunchOnLogin.withLaunchOnLoginRegistryKey(wrk => {
42+
exists = wrk.hasValue(WindowsLaunchOnLogin.getLaunchOnLoginRegistryName());
43+
});
44+
return exists;
45+
}
46+
47+
add_task(async function test_disable_launch_on_login() {
48+
// Simulate the user having previously enabled launch on login.
49+
if (!isMSIX) {
50+
await WindowsLaunchOnLogin.createLaunchOnLogin();
51+
ok(await hasRegistryKey(), "Registry key exists before the policy applies");
52+
}
53+
54+
await setupPolicyEngineWithJson({
55+
policies: {
56+
DisableLaunchOnLogin: true,
57+
},
58+
});
59+
60+
is(
61+
Services.prefs.getBoolPref(ENABLED_PREF),
62+
false,
63+
"Launch on login enabled pref is forced to false"
64+
);
65+
ok(Services.prefs.prefIsLocked(ENABLED_PREF), "Enabled pref is locked");
66+
67+
if (!isMSIX) {
68+
await TestUtils.waitForCondition(
69+
async () => !(await hasRegistryKey()),
70+
"Waiting for the launch on login registry key to be removed"
71+
);
72+
73+
await WindowsLaunchOnLogin.createLaunchOnLogin();
74+
ok(
75+
!(await hasRegistryKey()),
76+
"createLaunchOnLogin is blocked while the policy is active"
77+
);
78+
}
79+
80+
await BrowserTestUtils.withNewTab("about:preferences", async browser => {
81+
let doc = browser.contentDocument;
82+
await TestUtils.waitForCondition(
83+
() => doc.getElementById("windowsLaunchOnLogin"),
84+
"windowsLaunchOnLogin checkbox rendered"
85+
);
86+
ok(
87+
doc.getElementById("windowsLaunchOnLogin").parentElement.hidden,
88+
"Checkbox is hidden by policy"
89+
);
90+
});
91+
});
92+
93+
add_task(async function test_policy_false_is_noop() {
94+
await setupPolicyEngineWithJson({
95+
policies: {
96+
DisableLaunchOnLogin: false,
97+
},
98+
});
99+
100+
ok(
101+
!Services.prefs.prefIsLocked(ENABLED_PREF),
102+
"Enabled pref is not locked when the policy is false"
103+
);
104+
});

‎browser/locales/en-US/browser/policies/policies-descriptions.ftl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ policy-DisableForgetButton = Prevent access to the Forget button.
9595
9696
policy-DisableFormHistory = Don’t remember search and form history.
9797
98+
policy-DisableLaunchOnLogin = Prevent { -brand-short-name } from launching automatically when the user logs in.
99+
98100
policy-DisablePrimaryPasswordCreation = If true, a Primary Password can’t be created.
99101
100102
policy-DisablePasswordReveal = Do not allow passwords to be revealed in saved logins.

‎toolkit/modules/WindowsLaunchOnLogin.sys.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ export var WindowsLaunchOnLogin = {
7676
* restrictions on writing to the registry in MSIX.
7777
*/
7878
async createLaunchOnLogin() {
79+
if (Services.policies && !Services.policies.isAllowed("launchOnLogin")) {
80+
return;
81+
}
7982
if (Services.sysinfo.getProperty("hasWinPackageId")) {
8083
await this.enableLaunchOnLoginMSIX();
8184
} else {

0 commit comments

Comments
 (0)