Skip to content

Commit 579d85c

Browse files
committed
Bug 2065138 - Enforce setDefaultBrowser policy in ShellService r=nalexander
Differential Revision: https://phabricator.services.mozilla.com/D320233
1 parent cb8819b commit 579d85c

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,31 @@ add_task(async function test_default_browser_setting_disabled() {
5151
);
5252
await checkSetDefaultUI({ isHidden: true });
5353
});
54+
55+
add_task(async function test_set_default_browser_blocked_by_policy() {
56+
const { sinon } = ChromeUtils.importESModule(
57+
"resource://testing-common/Sinon.sys.mjs"
58+
);
59+
const sandbox = sinon.createSandbox();
60+
// Stubbed so a regression in the guard cannot change the real system default.
61+
const userChoiceStub = sandbox
62+
.stub(ShellService, "setAsDefaultUserChoice")
63+
.resolves();
64+
const setDefaultStub = sinon.stub();
65+
sandbox
66+
.stub(ShellService, "shellService")
67+
.value({ setDefaultBrowser: setDefaultStub });
68+
69+
await setupPolicyEngineWithJson({
70+
policies: {
71+
DefaultBrowserSettingEnabled: false,
72+
},
73+
});
74+
75+
await ShellService.setDefaultBrowser(false);
76+
77+
Assert.ok(userChoiceStub.notCalled, "UserChoice method not called");
78+
Assert.ok(setDefaultStub.notCalled, "Fallback method not called");
79+
80+
sandbox.restore();
81+
});

‎browser/components/shell/ShellService.sys.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ let ShellServiceInternal = {
440440

441441
// override nsIShellService.setDefaultBrowser() on the ShellService proxy.
442442
async setDefaultBrowser(forAllUsers) {
443+
if (!Services.policies.isAllowed("setDefaultBrowser")) {
444+
lazy.log.warn("Setting the default browser is disallowed by policy");
445+
return;
446+
}
447+
443448
// On Windows, our best chance is to set UserChoice, so try that first.
444449
if (
445450
AppConstants.platform == "win" &&

0 commit comments

Comments
 (0)