1
0
MozillaFirefox/firefox-ui-lockdown.patch

292 lines
13 KiB
Diff

Index: browser/base/content/browser-menubar.inc
===================================================================
--- browser/base/content/browser-menubar.inc.orig
+++ browser/base/content/browser-menubar.inc
@@ -68,9 +68,9 @@
<menuitem id="menu_saveFrame" label="&saveFrameCmd.label;" accesskey="&saveFrameCmd.accesskey;" command="Browser:SaveFrame" hidden="true"/>
<menuitem id="menu_sendLink" label="&sendPageCmd.label;" accesskey="&sendPageCmd.accesskey;" command="Browser:SendLink"/>
<menuseparator/>
- <menuitem label="&printSetupCmd.label;" accesskey="&printSetupCmd.accesskey;" command="cmd_pageSetup"/>
+ <menuitem id="menu_printSetup" label="&printSetupCmd.label;" accesskey="&printSetupCmd.accesskey;" command="cmd_pageSetup"/>
#ifndef XP_MACOSX
- <menuitem label="&printPreviewCmd.label;" accesskey="&printPreviewCmd.accesskey;" command="cmd_printPreview"/>
+ <menuitem id="menu_printPreview" label="&printPreviewCmd.label;" accesskey="&printPreviewCmd.accesskey;" oncommand="PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview);"/>
#endif
<menuitem label="&printCmd.label;" accesskey="&printCmd.accesskey;" key="printKb" command="cmd_print"/>
<menuseparator/>
Index: browser/base/content/browser.js
===================================================================
--- browser/base/content/browser.js.orig
+++ browser/base/content/browser.js
@@ -920,6 +920,152 @@ function prepareForStartup()
gBrowser.addEventListener("DOMLinkAdded", DOMLinkHandler, false);
}
+function lockdownElement(ident, disable, hideCompletely)
+{
+ var e = document.getElementById(ident);
+ if (!e) return;
+ if (hideCompletely) {
+ e.setAttribute("style", (disable) ? "display: none;" : "");
+ } else if (disable) {
+ e.setAttribute("disabled", "true");
+ } else {
+ e.removeAttribute("disabled");
+ }
+}
+
+function applyLockdown(isStartup)
+{
+ // It is important to check that Firefox code does not change the
+ // "disabled" state of these UI elements. Fortunately it mostly hides
+ // elements rather than disables them.
+ var disablePrinting = gPrefService.getBoolPref("config.lockdown.printing");
+ var disablePrintSetup = gPrefService.getBoolPref("config.lockdown.printsetup");
+ if (!isStartup || disablePrintSetup || disablePrintSetup) {
+ lockdownElement("cmd_pageSetup", disablePrinting || disablePrintSetup);
+ lockdownElement("menu_printPreview", disablePrinting || disablePrintSetup);
+ lockdownElement("cmd_print", disablePrinting);
+ }
+
+ var disableSave = gPrefService.getBoolPref("config.lockdown.savepage");
+ if (!isStartup || disableSave) {
+ lockdownElement("Browser:SavePage", disableSave);
+ lockdownElement("Browser:SaveFrame", disableSave);
+ lockdownElement("context-savepage", disableSave);
+ lockdownElement("context-saveframe", disableSave);
+ lockdownElement("context-savelink", disableSave);
+ lockdownElement("context-saveimage", disableSave);
+ lockdownElement("View:PageSource", disableSave);
+ lockdownElement("context-viewpartialsource-selection", disableSave);
+ lockdownElement("context-viewpartialsource-mathml", disableSave);
+ lockdownElement("context-viewsource", disableSave);
+ lockdownElement("context-viewframesource", disableSave);
+ lockdownElement("View:PageInfo", disableSave);
+ lockdownElement("context-viewinfo", disableSave);
+ lockdownElement("context-viewframeinfo", disableSave);
+ lockdownElement("Tasks:InspectPage", disableSave); // from DOMInspector extension
+ }
+
+ var disableBookmarks = gPrefService.getBoolPref("config.lockdown.hidebookmark");
+ var disableBookmarkEditing = gPrefService.getBoolPref("config.lockdown.bookmark");
+ if (!isStartup || disableBookmarks || disableBookmarkEditing) {
+ lockdownElement("bookmarksMenu", disableBookmarks, true);
+ lockdownElement("viewBookmarksSidebar", disableBookmarks);
+ lockdownElement("PersonalToolbar", disableBookmarks); // XXX check
+ lockdownElement("Browser:AddBookmarkAs", disableBookmarks || disableBookmarkEditing);
+ lockdownElement("Browser:ShowAllBookmarks", disableBookmarks || disableBookmarkEditing);
+ lockdownElement("manBookmark", disableBookmarks || disableBookmarkEditing);
+ lockdownElement("context-bookmarkpage", disableBookmarks || disableBookmarkEditing);
+ lockdownElement("context-bookmarklink", disableBookmarks || disableBookmarkEditing);
+
+ // hide the personal bookmarks toolbar if necessary
+ if (disableBookmarks) {
+ document.getElementById("PersonalToolbar").setAttribute("collapsed", "true");
+ }
+ }
+
+ var disableHistory = gPrefService.getBoolPref("config.lockdown.history");
+ if (!isStartup || disableHistory) {
+ lockdownElement("history-menu", disableHistory, true);
+ lockdownElement("viewHistorySidebar", disableHistory);
+ lockdownElement("Browser:ShowAllHistory", disableHistory);
+ gURLBar.setAttribute("enablehistory", disableHistory ? "false" : "true");
+ gURLBar.disableAutoComplete = disableHistory;
+ }
+
+ var defaultPrefs = Cc["@mozilla.org/preferences-service;1"]
+ .getService(Ci.nsIPrefService).getDefaultBranch(null);
+ if (isStartup && disableHistory) {
+ if (!defaultPrefs.prefIsLocked("browser.history_expire_days")) {
+ defaultPrefs.setIntPref("browser.history_expire_days", 0);
+ defaultPrefs.lockPref("browser.history_expire_days");
+ }
+ if (!defaultPrefs.prefIsLocked("browser.formfill.enable")) {
+ defaultPrefs.setBoolPref("browser.formfill.enable", false);
+ defaultPrefs.lockPref("browser.formfill.enable");
+ }
+ if (!defaultPrefs.prefIsLocked("browser.download.manager.retention")) {
+ defaultPrefs.setIntPref("browser.download.manager.retention", 0);
+ defaultPrefs.lockPref("browser.download.manager.retention");
+ }
+ gPrefService.setBoolPref("config.lockdown.history.set", true);
+ } else if (isStartup && gPrefService.prefHasUserValue("config.lockdown.history.set")) {
+ if (!defaultPrefs.prefIsLocked("browser.history_expire_days")) {
+ defaultPrefs.clearUserPref("browser.history_expire_days");
+ }
+ if (!defaultPrefs.prefIsLocked("browser.formfill.enable")) {
+ defaultPrefs.clearUserPref("browser.formfill.enable");
+ }
+ if (!defaultPrefs.prefIsLocked("browser.download.manager.retention")) {
+ defaultPrefs.clearUserPref("browser.download.manager.retention");
+ }
+ gPrefService.clearUserPref("config.lockdown.history.set");
+ }
+
+ var disableURLBar = gPrefService.getBoolPref("config.lockdown.urlbar");
+ if (!isStartup || disableURLBar) {
+ lockdownElement("urlbar", disableURLBar);
+ lockdownElement("Browser:OpenLocation", disableURLBar);
+ lockdownElement("Browser:OpenFile", disableURLBar);
+ }
+
+ var disableSearchBar = gPrefService.getBoolPref("config.lockdown.searchbar");
+ if (!isStartup || disableSearchBar) {
+ document.getElementById("search-container")
+ .setAttribute("style", (disableSearchBar) ? "display: none;" : "");
+ }
+
+ var disableToolbarEditing = gPrefService.getBoolPref("config.lockdown.toolbarediting");
+ if (!isStartup || disableToolbarEditing) {
+ var e = document.getElementById("cmd_CustomizeToolbars");
+ if (!e.getAttribute("inCustomization")) {
+ lockdownElement("cmd_CustomizeToolbars", disableToolbarEditing);
+ }
+ }
+
+ // Close sidebar if we disabled the command that's currently in use
+ var sidebarBox = document.getElementById("sidebar-box");
+ var cmd = sidebarBox.getAttribute("sidebarcommand");
+ if (cmd) {
+ var elt = document.getElementById(cmd);
+ if (elt && elt.getAttribute("disabled") == "true") {
+ toggleSidebar(cmd, false);
+ gMustLoadSidebar = false;
+ }
+ }
+}
+
+var lockdownObserver = {
+ observe: function(aSubject, aTopic, aPrefName)
+ {
+ try {
+ applyLockdown(false);
+ } catch (ex) {
+ dump("Failed lockdown: " + ex + "\n");
+ }
+ }
+};
+
+
function delayedStartup()
{
var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
@@ -928,7 +1074,16 @@ function delayedStartup()
if (!gPrefService)
gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch2);
+ .getService(Components.interfaces.nsIPrefBranchInternal);
+ try {
+ // do lockdown stuff in an exception handler so that if it fails
+ // catastrophically, the browser should still come up and function
+ applyLockdown(true);
+ gPrefService.addObserver("config.lockdown.", lockdownObserver, false);
+ } catch (ex) {
+ dump("Failed lockdown: " + ex + "\n");
+ }
+
BrowserOffline.init();
OfflineApps.init();
@@ -940,8 +1095,8 @@ function delayedStartup()
Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
if (gMustLoadSidebar) {
- var sidebar = document.getElementById("sidebar");
var sidebarBox = document.getElementById("sidebar-box");
+ var sidebar = document.getElementById("sidebar");
sidebar.setAttribute("src", sidebarBox.getAttribute("src"));
}
@@ -1132,6 +1287,8 @@ function BrowserShutdown()
os.removeObserver(gSessionHistoryObserver, "browser:purge-session-history");
os.removeObserver(gXPInstallObserver, "xpinstall-install-blocked");
+ gPrefService.removeObserver("config.lockdown.", lockdownObserver);
+
try {
gBrowser.removeProgressListener(window.XULBrowserWindow);
} catch (ex) {
@@ -3065,6 +3222,12 @@ function FillHistoryMenu(aParent) {
aParent.removeChild(children[i]);
}
+ // lockdown. Don't display anything if locked down.
+ var disableHistory = gPrefService.getBoolPref("config.lockdown.history");
+ if (disableHistory) {
+ return false;
+ }
+
var webNav = getWebNavigation();
var sessionHistory = webNav.sessionHistory;
var bundle_browser = document.getElementById("bundle_browser");
@@ -3220,6 +3383,7 @@ function BrowserCustomizeToolbar()
var cmd = document.getElementById("cmd_CustomizeToolbars");
cmd.setAttribute("disabled", "true");
+ cmd.setAttribute("inCustomization", "true");
var splitter = document.getElementById("urlbar-search-splitter");
if (splitter)
@@ -3251,6 +3415,15 @@ function BrowserCustomizeToolbar()
#endif
}
+function BrowserRestoreCustomizationDisabledState()
+{
+ var cmd = document.getElementById("cmd_CustomizeToolbars");
+ if (!gPrefService.getBoolPref("config.lockdown.toolbarediting")) {
+ cmd.removeAttribute("disabled", "true");
+ }
+ cmd.removeAttribute("inCustomization");
+}
+
function BrowserToolboxCustomizeDone(aToolboxChanged)
{
#ifdef TOOLBAR_CUSTOMIZATION_SHEET
@@ -3266,6 +3439,14 @@ function BrowserToolboxCustomizeDone(aTo
gIdentityHandler._cacheElements();
window.XULBrowserWindow.init();
+ // make sure the search bar is not put back if locked down
+ var disableSearchBar = gPrefService.getBoolPref("config.lockdown.searchbar");
+ if (disableSearchBar) {
+ document.getElementById("search-container")
+ .setAttribute("style", (disableSearchBar) ? "display: none;" : "");
+ }
+
+
var backForwardDropmarker = document.getElementById("back-forward-dropmarker");
if (backForwardDropmarker)
backForwardDropmarker.disabled =
@@ -3300,8 +3481,7 @@ function BrowserToolboxCustomizeDone(aTo
var menubar = document.getElementById("main-menubar");
for (var i = 0; i < menubar.childNodes.length; ++i)
menubar.childNodes[i].setAttribute("disabled", false);
- var cmd = document.getElementById("cmd_CustomizeToolbars");
- cmd.removeAttribute("disabled");
+ BrowserRestoreCustomizationDisabledState();
// XXXmano bug 287105: wallpaper to bug 309953,
// the reload button isn't in sync with the reload command.
@@ -4479,6 +4659,9 @@ function onViewToolbarsPopupShowing(aEve
menuItem.setAttribute("toolbarindex", i);
menuItem.setAttribute("type", "checkbox");
menuItem.setAttribute("label", toolbarName);
+ if (toolbar.getAttribute("disabled") == "true") {
+ menuItem.setAttribute("disabled", "true");
+ }
menuItem.setAttribute("accesskey", toolbar.getAttribute("accesskey"));
menuItem.setAttribute("checked", toolbar.getAttribute("collapsed") != "true");
popup.insertBefore(menuItem, firstMenuItem);
@@ -6329,7 +6512,7 @@ BookmarkAllTabsHandler.prototype = {
if (aTabClose)
numTabs--;
- if (numTabs > 1)
+ if (numTabs > 1 && !gPrefService.getBoolPref("config.lockdown.bookmark"))
this._command.removeAttribute("disabled");
else
this._command.setAttribute("disabled", "true");