Skip to content

Commit f7b5903

Browse files
iain-mozillaHarshitSohaney
authored andcommitted
Bug 2053447: Part 5 - Update for enterprise policies.r=mkaply
Update to support the DisableLaunchOnLogin enterprise policy Differential Revision: https://phabricator.services.mozilla.com/D316049
1 parent 6ec8289 commit f7b5903

5 files changed

Lines changed: 33 additions & 15 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +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",
32+
LaunchOnLogin: "resource://gre/modules/LaunchOnLogin.sys.mjs",
3333

3434
PoliciesUtils: "resource://gre/modules/PoliciesHelpers.sys.mjs",
3535
addAllowDenyPermissions: "resource://gre/modules/PoliciesHelpers.sys.mjs",
@@ -1221,15 +1221,15 @@ export var Policies = {
12211221

12221222
DisableLaunchOnLogin: {
12231223
onBeforeAddons(manager, param) {
1224-
if (!param || AppConstants.platform !== "win") {
1224+
if (!param) {
12251225
return;
12261226
}
12271227
manager.disallowFeature("launchOnLogin");
12281228
lazy.PoliciesUtils.setAndLockPref(
12291229
"browser.startup.windowsLaunchOnLogin.enabled",
12301230
false
12311231
);
1232-
lazy.WindowsLaunchOnLogin.removeLaunchOnLogin();
1232+
lazy.LaunchOnLogin.disable();
12331233
},
12341234
},
12351235

‎browser/components/enterprisepolicies/tests/browser/browser_policy_disable_launch_on_login.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"use strict";
55

66
ChromeUtils.defineESModuleGetters(this, {
7-
WindowsLaunchOnLogin: "resource://gre/modules/WindowsLaunchOnLogin.sys.mjs",
7+
LaunchOnLogin: "resource://gre/modules/LaunchOnLogin.sys.mjs",
8+
WindowsLaunchOnLogin:
9+
"resource://gre/modules/launchonlogin/WindowsLaunchOnLogin.sys.mjs",
810
});
911

1012
const { MockRegistry } = ChromeUtils.importESModule(
@@ -47,7 +49,7 @@ async function hasRegistryKey() {
4749
add_task(async function test_disable_launch_on_login() {
4850
// Simulate the user having previously enabled launch on login.
4951
if (!isMSIX) {
50-
await WindowsLaunchOnLogin.createLaunchOnLogin();
52+
await LaunchOnLogin.enable();
5153
ok(await hasRegistryKey(), "Registry key exists before the policy applies");
5254
}
5355

@@ -70,10 +72,10 @@ add_task(async function test_disable_launch_on_login() {
7072
"Waiting for the launch on login registry key to be removed"
7173
);
7274

73-
await WindowsLaunchOnLogin.createLaunchOnLogin();
75+
await LaunchOnLogin.enable();
7476
ok(
7577
!(await hasRegistryKey()),
76-
"createLaunchOnLogin is blocked while the policy is active"
78+
"LaunchOnLogin.enable is blocked while the policy is active"
7779
);
7880
}
7981

‎toolkit/modules/launchonlogin/LaunchOnLogin.sys.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export var LaunchOnLogin = {
4949
* Whether LaunchOnLogin was enabled.
5050
*/
5151
async enable() {
52+
if (Services.policies && !Services.policies.isAllowed("launchOnLogin")) {
53+
return Promise.resolve(false);
54+
}
55+
5256
return await lazy.gImpl.createLaunchOnLogin();
5357
},
5458

@@ -69,6 +73,10 @@ export var LaunchOnLogin = {
6973
* Whether LaunchOnLogin is allowed.
7074
*/
7175
async isAllowed() {
76+
if (Services.policies && !Services.policies.isAllowed("launchOnLogin")) {
77+
return Promise.resolve(false);
78+
}
79+
7280
return await lazy.gImpl.getLaunchOnLoginApproved();
7381
},
7482

@@ -79,6 +87,10 @@ export var LaunchOnLogin = {
7987
* Whether LaunchOnLogin is allowed.
8088
*/
8189
async isEnabled() {
90+
if (Services.policies && !Services.policies.isAllowed("launchOnLogin")) {
91+
return Promise.resolve(false);
92+
}
93+
8294
return await lazy.gImpl.getLaunchOnLoginEnabled();
8395
},
8496

@@ -102,6 +114,9 @@ export var LaunchOnLogin = {
102114
);
103115
}
104116

117+
if (Services.policies && !Services.policies.isAllowed("launchOnLogin")) {
118+
details.isAllowedByPolicy = false;
119+
}
105120
return details;
106121
},
107122
};

‎toolkit/modules/launchonlogin/UnsupportedLaunchOnLogin.sys.mjs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44

55
export var UnsupportedLaunchOnLogin = {
66
async createLaunchOnLogin() {
7-
return await Promise.reject(new Error("unsupported"));
7+
return await Promise.resolve(false);
88
},
99

1010
async removeLaunchOnLogin() {
11-
return await Promise.reject(new Error("unsupported"));
11+
return await Promise.resolve(true);
1212
},
1313

1414
async getLaunchOnLoginApproved() {
15-
return await Promise.reject(new Error("unsupported"));
15+
return await Promise.resolve(false);
1616
},
1717

1818
async getLaunchOnLoginEnabled() {
19-
return await Promise.reject(new Error("unsupported"));
19+
return await Promise.resolve(false);
2020
},
2121

2222
async getLaunchOnLoginEnablementDetails() {
23-
return await Promise.reject(new Error("unsupported"));
23+
return await Promise.resolve({
24+
isEnabled: false,
25+
isSupported: false,
26+
isAllowedByPolicy: false,
27+
});
2428
},
2529
};

‎toolkit/modules/launchonlogin/WindowsLaunchOnLogin.sys.mjs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ 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-
}
8279
if (Services.sysinfo.getProperty("hasWinPackageId")) {
8380
await this.enableLaunchOnLoginMSIX();
8481
} else {

0 commit comments

Comments
 (0)