Commit b7a354c7 authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1432355 - Add a policy to disable private browsing. r=Gijs

MozReview-Commit-ID: AprbL6usEv5

--HG--
extra : rebase_source : d0a9255aae8b8d038c69978cbeabbfc394ad46cd
parent 90a5e0e5
......@@ -1371,6 +1371,13 @@ var gBrowserInit = {
this._boundDelayedStartup = this._delayedStartup.bind(this);
window.addEventListener("MozAfterPaint", this._boundDelayedStartup);
if (!PrivateBrowsingUtils.enabled) {
document.getElementById("Tools:PrivateBrowsing").hidden = true;
// Setting disabled doesn't disable the shortcut, so we just remove
// the keybinding.
document.getElementById("key_privatebrowsing").remove();
}
this._loadHandled = true;
},
......@@ -1972,6 +1979,9 @@ if (AppConstants.platform == "macosx") {
if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
document.getElementById("macDockMenuNewWindow").hidden = true;
}
if (!PrivateBrowsingUtils.enabled) {
document.getElementById("macDockMenuNewPrivateWindow").hidden = true;
}
this._delayedStartupTimeoutId = setTimeout(this.nonBrowserWindowDelayedStartup.bind(this), 0);
};
......@@ -4140,7 +4150,7 @@ function OpenBrowserWindow(options) {
var wintype = document.documentElement.getAttribute("windowtype");
var extraFeatures = "";
if (options && options.private) {
if (options && options.private && PrivateBrowsingUtils.enabled) {
extraFeatures = ",private";
if (!PrivateBrowsingUtils.permanentPrivateBrowsing) {
// Force the new window to load about:privatebrowsing instead of the default home page
......
......@@ -58,7 +58,8 @@
the application. -->
<menuitem label="&newNavigatorCmd.label;" oncommand="OpenBrowserWindowFromDockMenu();"
id="macDockMenuNewWindow" />
<menuitem label="&newPrivateWindow.label;" oncommand="OpenBrowserWindowFromDockMenu({private: true});" />
<menuitem label="&newPrivateWindow.label;" oncommand="OpenBrowserWindowFromDockMenu({private: true});"
id="macDockMenuNewPrivateWindow" />
</menupopup>
</popupset>
......
......@@ -359,7 +359,7 @@ nsContextMenu.prototype = {
var isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
var showContainers = Services.prefs.getBoolPref("privacy.userContext.enabled");
this.showItem("context-openlink", shouldShow && !isWindowPrivate);
this.showItem("context-openlinkprivate", shouldShow);
this.showItem("context-openlinkprivate", shouldShow && PrivateBrowsingUtils.enabled);
this.showItem("context-openlinkintab", shouldShow && !inContainer);
this.showItem("context-openlinkincontainertab", shouldShow && inContainer);
this.showItem("context-openlinkinusercontext-menu", shouldShow && !isWindowPrivate && showContainers);
......
......@@ -238,13 +238,6 @@ const CustomizableWidgets = [
panelview.appendChild(body);
panelview.appendChild(footer);
}
}, {
id: "privatebrowsing-button",
shortcutId: "key_privatebrowsing",
onCommand(e) {
let win = e.target.ownerGlobal;
win.OpenBrowserWindow({private: true});
}
}, {
id: "save-page-button",
shortcutId: "key_savePage",
......@@ -948,3 +941,14 @@ if (Services.prefs.getBoolPref("privacy.panicButton.enabled")) {
},
});
}
if (PrivateBrowsingUtils.enabled) {
CustomizableWidgets.push({
id: "privatebrowsing-button",
shortcutId: "key_privatebrowsing",
onCommand(e) {
let win = e.target.ownerGlobal;
win.OpenBrowserWindow({private: true});
}
});
}
......@@ -172,6 +172,17 @@ var Policies = {
}
},
"DisablePrivateBrowsing": {
onBeforeAddons(manager, param) {
if (param) {
manager.disallowFeature("privatebrowsing");
manager.disallowFeature("about:privatebrowsing", true);
setAndLockPref("browser.privatebrowsing.autostart", false);
}
}
},
"DisplayBookmarksToolbar": {
onBeforeUIStartup(manager, param) {
if (param) {
......
......@@ -153,6 +153,14 @@
"enum": [true]
},
"DisablePrivateBrowsing": {
"description": "Disables private browsing.",
"first_available": "60.0",
"type": "boolean",
"enum": [true]
},
"DisplayBookmarksToolbar": {
"description": "Causes the bookmarks toolbar to be displayed by default.",
"first_available": "60.0",
......
......@@ -25,6 +25,7 @@ support-files =
[browser_policy_disable_fxscreenshots.js]
[browser_policy_disable_masterpassword.js]
[browser_policy_disable_pocket.js]
[browser_policy_disable_privatebrowsing.js]
[browser_policy_disable_shield.js]
[browser_policy_display_bookmarks.js]
[browser_policy_display_menu.js]
......
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
ChromeUtils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
add_task(async function setup() {
await setupPolicyEngineWithJson({
"policies": {
"DisablePrivateBrowsing": true
}
});
});
add_task(async function test_menu_shown() {
is(PrivateBrowsingUtils.enabled, false, "Private browsing should be disabled");
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let privateBrowsingCommand = newWin.document.getElementById("Tools:PrivateBrowsing");
is(privateBrowsingCommand.hidden, true, "The private browsing command should be hidden");
await BrowserTestUtils.closeWindow(newWin);
});
......@@ -128,6 +128,9 @@ this.windows = class extends ExtensionAPI {
if (createData.incognito !== null && createData.incognito != incognito) {
return Promise.reject({message: "`incognito` property must match the incognito state of tab"});
}
if (createData.incognito && !PrivateBrowsingUtils.enabled) {
return Promise.reject({message: "`incognito` cannot be used if incognito mode is disabled"});
}
createData.incognito = incognito;
args.appendElement(tab);
......
......@@ -381,7 +381,7 @@ nsBrowserContentHandler.prototype = {
};
if (isLocal(resolvedURI)) {
// If the URI is local, we are sure it won't wrongly inherit chrome privs
var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
let features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
openWindow(null, resolvedURI.spec, "_blank", features);
cmdLine.preventDefault = true;
} else {
......@@ -402,10 +402,18 @@ nsBrowserContentHandler.prototype = {
try {
var privateWindowParam = cmdLine.handleFlagWithParam("private-window", false);
if (privateWindowParam) {
let resolvedURI = resolveURIInternal(cmdLine, privateWindowParam);
handURIToExistingBrowser(resolvedURI, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine, true,
let forcePrivate = true;
let resolvedURI;
if (!PrivateBrowsingUtils.enabled) {
// Load about:privatebrowsing in a normal tab, which will display an error indicating
// access to private browsing has been disabled.
forcePrivate = false;
resolvedURI = Services.io.newURI("about:privatebrowsing");
} else {
resolvedURI = resolveURIInternal(cmdLine, privateWindowParam);
}
handURIToExistingBrowser(resolvedURI, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine, forcePrivate,
Services.scriptSecurityManager.getSystemPrincipal());
cmdLine.preventDefault = true;
}
} catch (e) {
if (e.result != Cr.NS_ERROR_INVALID_ARG) {
......@@ -413,8 +421,12 @@ nsBrowserContentHandler.prototype = {
}
// NS_ERROR_INVALID_ARG is thrown when flag exists, but has no param.
if (cmdLine.handleFlag("private-window", false)) {
let features = "chrome,dialog=no,all";
if (PrivateBrowsingUtils.enabled) {
features += ",private";
}
openWindow(null, this.chromeURL, "_blank",
"chrome,dialog=no,private,all" + this.getFeatures(cmdLine),
features + this.getFeatures(cmdLine),
"about:privatebrowsing");
cmdLine.preventDefault = true;
}
......@@ -428,7 +440,7 @@ nsBrowserContentHandler.prototype = {
// The global PB Service consumes this flag, so only eat it in per-window
// PB builds.
if (cmdLine.handleFlag("private", false)) {
if (cmdLine.handleFlag("private", false) && PrivateBrowsingUtils.enabled) {
PrivateBrowsingUtils.enterTemporaryAutoStartMode();
}
......
......@@ -465,6 +465,10 @@ PlacesController.prototype = {
* and the item can be displayed, false otherwise.
*/
_shouldShowMenuItem: function PC__shouldShowMenuItem(aMenuItem, aMetaData) {
if (aMenuItem.hasAttribute("hideifprivatebrowsing") && !PrivateBrowsingUtils.enabled) {
return false;
}
var selectiontype = aMenuItem.getAttribute("selectiontype");
if (!selectiontype) {
selectiontype = "single|multiple";
......
......@@ -459,6 +459,11 @@ var gPrivacyPane = {
bundlePrefs.getString("removeSelectedCookies.label"),
]);
if (!PrivateBrowsingUtils.enabled) {
document.getElementById("privateBrowsingAutoStart").hidden = true;
document.querySelector("menuitem[value='dontremember']").hidden = true;
}
// Notify observers that the UI is now ready
Services.obs.notifyObservers(window, "privacy-pane-loaded");
},
......
......@@ -6,6 +6,9 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
let { getChromeWindow } = ChromeUtils.import("resource:///modules/syncedtabs/util.js", {});
let log = ChromeUtils.import("resource://gre/modules/Log.jsm", {})
......@@ -520,8 +523,10 @@ TabListView.prototype = {
while (el) {
let show = false;
if (showTabOptions) {
if (el.getAttribute("id") != "syncedTabsOpenAllInTabs" &&
el.getAttribute("id") != "syncedTabsManageDevices") {
if (el.getAttribute("id") == "syncedTabsOpenSelectedInPrivateWindow") {
show = PrivateBrowsingUtils.enabled;
} else if (el.getAttribute("id") != "syncedTabsOpenAllInTabs" &&
el.getAttribute("id") != "syncedTabsManageDevices") {
show = true;
}
} else if (el.getAttribute("id") == "syncedTabsOpenAllInTabs") {
......
......@@ -101,19 +101,19 @@ var tasksCfg = [
close: true, // No point, but we don't always update the list on
// shutdown. Thus true for consistency.
},
// Open new private window
{
get title() { return _getString("taskbar.tasks.newPrivateWindow.label"); },
get description() { return _getString("taskbar.tasks.newPrivateWindow.description"); },
args: "-private-window",
iconIndex: 4, // Private browsing mode icon
open: true,
close: true, // No point, but we don't always update the list on
// shutdown. Thus true for consistency.
},
];
// Open new private window
let privateWindowTask = {
get title() { return _getString("taskbar.tasks.newPrivateWindow.label"); },
get description() { return _getString("taskbar.tasks.newPrivateWindow.description"); },
args: "-private-window",
iconIndex: 4, // Private browsing mode icon
open: true,
close: true, // No point, but we don't always update the list on
// shutdown. Thus true for consistency.
};
// Implementation
var WinTaskbarJumpList =
......@@ -134,6 +134,10 @@ var WinTaskbarJumpList =
// Store our task list config data
this._tasks = tasksCfg;
if (PrivateBrowsingUtils.enabled) {
tasksCfg.push(privateWindowTask);
}
// retrieve taskbar related prefs.
this._refreshPrefs();
......
......@@ -13,6 +13,10 @@ const kAutoStartPref = "browser.privatebrowsing.autostart";
var gTemporaryAutoStartMode = false;
var PrivateBrowsingUtils = {
get enabled() {
return Services.policies.isAllowed("privatebrowsing");
},
// Rather than passing content windows to this function, please use
// isBrowserPrivate since it works with e10s.
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment