Bug 1546973 - Add download related policies. r=jaws,flod

Differential Revision: https://phabricator.services.mozilla.com/D29277

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Michael Kaply 2019-05-03 17:53:32 +00:00
parent 0512ebbbac
commit e669c78390
5 changed files with 75 additions and 0 deletions

View File

@ -17,6 +17,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
AddonManager: "resource://gre/modules/AddonManager.jsm",
BookmarksPolicies: "resource:///modules/policies/BookmarksPolicies.jsm",
CustomizableUI: "resource:///modules/CustomizableUI.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
ProxyPolicies: "resource:///modules/policies/ProxyPolicies.jsm",
WebsiteFilter: "resource:///modules/policies/WebsiteFilter.jsm",
});
@ -286,6 +287,14 @@ var Policies = {
},
},
"DefaultDownloadDirectory": {
onBeforeAddons(manager, param) {
setDefaultPref("browser.download.dir", replacePathVariables(param));
// If a custom download directory is being used, just lock folder list to 2.
setAndLockPref("browser.download.folderList", 2);
},
},
"DisableAppUpdate": {
onBeforeAddons(manager, param) {
if (param) {
@ -498,6 +507,14 @@ var Policies = {
},
},
"DownloadDirectory": {
onBeforeAddons(manager, param) {
setAndLockPref("browser.download.dir", replacePathVariables(param));
// If a custom download directory is being used, just lock folder list to 2.
setAndLockPref("browser.download.folderList", 2);
},
},
"EnableTrackingProtection": {
onBeforeUIStartup(manager, param) {
if (param.Value) {
@ -822,6 +839,12 @@ var Policies = {
},
},
"PromptForDownloadLocation": {
onBeforeAddons(manager, param) {
setAndLockPref("browser.download.useDownloadDir", !param);
},
},
"Proxy": {
onBeforeAddons(manager, param) {
if (param.Locked) {
@ -1274,6 +1297,13 @@ function clearRunOnceModification(actionName) {
Services.prefs.clearUserPref(prefName);
}
function replacePathVariables(path) {
if (path.includes("${home}")) {
return path.replace("${home}", FileUtils.getFile("Home", []).path);
}
return path;
}
let gChromeURLSBlocked = false;
// If any about page is blocked, we block the loading of all

View File

@ -164,6 +164,10 @@
}
},
"DefaultDownloadDirectory": {
"type": "string"
},
"DisableAppUpdate": {
"type": "boolean"
},
@ -276,6 +280,10 @@
"type": "boolean"
},
"DownloadDirectory": {
"type": "string"
},
"EnableTrackingProtection": {
"type": "object",
"properties": {
@ -624,6 +632,10 @@
}
},
"PromptForDownloadLocation": {
"type": "boolean"
},
"Proxy": {
"type": "object",
"properties": {

View File

@ -49,6 +49,7 @@ skip-if = (verify && debug && (os == 'mac'))
[browser_policy_display_bookmarks.js]
[browser_policy_display_menu.js]
[browser_policy_extensions.js]
[browser_policy_downloads.js]
[browser_policy_extensionsettings.js]
[browser_policy_locale.js]
[browser_policy_firefoxhome.js]

View File

@ -0,0 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
ChromeUtils.defineModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
add_task(async function test_notice_in_aboutprefences() {
await setupPolicyEngineWithJson({
"policies": {
"DefaultDownloadDirectory": "${home}/Downloads",
"PromptForDownloadLocation": false,
},
});
await BrowserTestUtils.withNewTab("about:preferences", async browser => {
is(browser.contentDocument.getElementById("alwaysAsk").disabled, true, "alwaysAsk should be disabled.");
is(browser.contentDocument.getElementById("saveTo").selected, true, "saveTo should be selected.");
is(browser.contentDocument.getElementById("saveTo").disabled, true, "saveTo should be disabled.");
let home = FileUtils.getFile("Home", []).path;
is(Services.prefs.getStringPref("browser.download.dir"), home + "/Downloads", "browser.download.dir should be ${home}/Downloads.");
is(Services.prefs.getBoolPref("browser.download.useDownloadDir"), true, "browser.download.useDownloadDir should be true.");
is(Services.prefs.prefIsLocked("browser.download.useDownloadDir"), true, "browser.download.useDownloadDir should be locked.");
});
});

View File

@ -31,6 +31,8 @@ policy-CertificatesDescription = Add certificates or use built-in certificates.
policy-Cookies = Allow or deny websites to set cookies.
policy-DefaultDownloadDirectory = Set the default download directory.
policy-DisableAppUpdate = Prevent the browser from updating.
policy-DisableBuiltinPDFViewer = Disable PDF.js, the built-in PDF viewer in { -brand-short-name }.
@ -78,6 +80,8 @@ policy-DNSOverHTTPS = Configure DNS over HTTPS.
policy-DontCheckDefaultBrowser = Disable check for default browser on startup.
policy-DownloadDirectory = Set and lock the download directory.
# “lock” means that the user wont be able to change this setting
policy-EnableTrackingProtection = Enable or disable Content Blocking and optionally lock it.
@ -119,6 +123,8 @@ policy-PopupBlocking = Allow certain websites to display popups by default.
policy-Preferences = Set and lock the value for a subset of preferences.
policy-PromptForDownloadLocation = Ask where to save files when downloading.
policy-Proxy = Configure proxy settings.
policy-RequestedLocales = Set the list of requested locales for the application in order of preference.