@@ -0,0 +1,432 @@
+diff --git a/browser/base/content/browser-context.inc b/browser/base/content/browser-context.inc
+index 72fd054..ea364fe 100644
+--- a/browser/base/content/browser-context.inc
++++ b/browser/base/content/browser-context.inc
+@@ -206,7 +206,8 @@
+ accesskey="&saveFrameCmd.accesskey;"
+ oncommand="saveDocument(gContextMenu.target.ownerDocument);"/>
+ <menuseparator/>
+- <menuitem label="&viewFrameSourceCmd.label;"
++ <menuitem id="context-frame-viewFrameSourceCmd"
++ label="&viewFrameSourceCmd.label;"
+ accesskey="&viewFrameSourceCmd.accesskey;"
+ oncommand="gContextMenu.viewFrameSource();"/>
+ <menuitem label="&viewFrameInfoCmd.label;"
+diff --git a/browser/base/content/browser-menubar.inc b/browser/base/content/browser-menubar.inc
+index bcf9109..0cc6740 100644
+--- a/browser/base/content/browser-menubar.inc
++++ b/browser/base/content/browser-menubar.inc
+@@ -55,9 +55,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/>
+@@ -458,7 +458,7 @@
+ #endif
+ label="&bookmarkAllCmd.label;"
+ command="Browser:BookmarkAllTabs"/>
+- <menuitem key="manBookmarkKb"
++ <menuitem id="manBookmark" key="manBookmarkKb"
+ label="&manBookmarksCmd.label;"
+ oncommand="toOpenWindowByType('bookmarks:manager', 'chrome://browser/content/bookmarks/bookmarksManager.xul');"/>
+ <menuseparator/>
+diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
+index 0dcabc8..bcad885 100644
+--- a/browser/base/content/browser.js
++++ b/browser/base/content/browser.js
+@@ -179,6 +179,12 @@ function UpdateBackForwardButtons()
+ var backBroadcaster = document.getElementById("Browser:Back");
+ var forwardBroadcaster = document.getElementById("Browser:Forward");
+
++ if (gPrefService.getBoolPref("config.lockdown.history")) {
++ backBroadcaster.setAttribute("disabled", true);
++ forwardBroadcaster.setAttribute("disabled", true);
++ return;
++ }
++
+ var webNavigation = gBrowser.webNavigation;
+
+ // Avoid setting attributes on broadcasters if the value hasn't changed!
+@@ -934,6 +940,112 @@ function prepareForStartup()
+ BrowserSearch.init();
+ }
+
++function lockdownElement(ident, disable)
++{
++ var e = document.getElementById(ident);
++ 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("menu_printSetup", 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("menu_saveFrame", disableSave);
++ lockdownElement("context-savepage", 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-frame-viewFrameSourceCmd", disableSave);
++ }
++
++ var disableBookmarks = gPrefService.getBoolPref("config.lockdown.hidebookmark");
++ var disableBookmarkEditing = gPrefService.getBoolPref("config.lockdown.bookmark");
++ if (!isStartup || disableBookmarks || disableBookmarkEditing) {
++ lockdownElement("viewBookmarksSidebar", disableBookmarks);
++ lockdownElement("PersonalToolbar", disableBookmarks); // XXX check
++ lockdownElement("Browser:AddBookmarkAs", 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("viewHistorySidebar", disableHistory);
++ UpdateBackForwardButtons();
++ var urlBar = document.getElementById("urlbar");
++ urlBar.setAttribute("enablehistory", disableHistory ? "false" : "true");
++ }
++
++ 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) {
++ lockdownElement("searchbar-textfield", disableSearchBar);
++ lockdownElement("searchbar-dropmarker", disableSearchBar);
++ }
++
++ 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);
+@@ -942,7 +1054,15 @@ function delayedStartup()
+
+ if (!gPrefService)
+ gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
+- .getService(Components.interfaces.nsIPrefBranch);
++ .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();
+
+ if (gURLBar && document.documentElement.getAttribute("chromehidden").indexOf("toolbar") != -1) {
+@@ -961,8 +1081,8 @@ function delayedStartup()
+ window.addEventListener("keypress", ctrlNumberTabSelection, false);
+
+ if (gMustLoadSidebar) {
+- var sidebar = document.getElementById("sidebar");
+ var sidebarBox = document.getElementById("sidebar-box");
++ var sidebar = document.getElementById("sidebar");
+ sidebar.setAttribute("src", sidebarBox.getAttribute("src"));
+ }
+
+@@ -1130,6 +1250,8 @@ function BrowserShutdown()
+ os.removeObserver(gSessionHistoryObserver, "browser:purge-session-history");
+ os.removeObserver(gXPInstallObserver, "xpinstall-install-blocked");
|