diff --git a/mozilla/browser/base/content/browser-menubar.inc b/mozilla/browser/base/content/browser-menubar.inc
index 07795f1..c035302 100644
--- a/mozilla/browser/base/content/browser-menubar.inc
+++ b/mozilla/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/>
diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js
index 288becb..249d282 100644
--- a/mozilla/browser/base/content/browser.js
+++ b/mozilla/browser/base/content/browser.js
@@ -920,6 +920,150 @@ 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("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("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("bookmarks-menu", disableBookmarks, true);
+    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("go-menu", disableHistory, true);
+    lockdownElement("viewHistorySidebar", 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 +1072,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 +1093,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"));
   }
 
@@ -1134,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) {
@@ -3222,6 +3377,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)
@@ -3253,6 +3409,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
@@ -3302,8 +3467,7 @@ function BrowserToolboxCustomizeDone(aToolboxChanged)
   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.
@@ -4481,6 +4645,9 @@ function onViewToolbarsPopupShowing(aEvent)
       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);
@@ -6353,7 +6520,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");
