PrivateBrowsingUI.sys.mjs (2515B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs"; 6 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; 7 import { PanelMultiView } from "moz-src:///browser/components/customizableui/PanelMultiView.sys.mjs"; 8 9 // Note that this is also called from non-browser windows on OSX, which do 10 // share menu items but not much else. See nonbrowser-mac.js. 11 export const PrivateBrowsingUI = { 12 init: function PBUI_init(window) { 13 const document = window.document; 14 const gBrowser = window.gBrowser; 15 16 // Disable the Clear Recent History... menu item when in PB mode 17 // temporary fix until bug 463607 is fixed 18 document.getElementById("Tools:Sanitize").setAttribute("disabled", "true"); 19 20 if (window.location.href != AppConstants.BROWSER_CHROME_URL) { 21 return; 22 } 23 24 // Adjust the window's title 25 let docElement = document.documentElement; 26 docElement.setAttribute( 27 "privatebrowsingmode", 28 PrivateBrowsingUtils.permanentPrivateBrowsing ? "permanent" : "temporary" 29 ); 30 31 gBrowser.updateTitlebar(); 32 33 if (PrivateBrowsingUtils.permanentPrivateBrowsing) { 34 let hideNewWindowItem = (windowItem, privateWindowItem) => { 35 // In permanent browsing mode command "cmd_newNavigator" should act the 36 // same as "Tools:PrivateBrowsing". 37 // So we hide the redundant private window item. But we also rename the 38 // "new window" item to be "new private window". 39 // NOTE: We choose to hide privateWindowItem rather than windowItem so 40 // that we still show the "key" for "cmd_newNavigator" (Ctrl+N) rather 41 // than (Ctrl+Shift+P). 42 privateWindowItem.hidden = true; 43 windowItem.setAttribute( 44 "data-l10n-id", 45 privateWindowItem.getAttribute("data-l10n-id") 46 ); 47 }; 48 49 // Adjust the File menu items. 50 hideNewWindowItem( 51 document.getElementById("menu_newNavigator"), 52 document.getElementById("menu_newPrivateWindow") 53 ); 54 // Adjust the App menu items. 55 hideNewWindowItem( 56 PanelMultiView.getViewNode(document, "appMenu-new-window-button2"), 57 PanelMultiView.getViewNode( 58 document, 59 "appMenu-new-private-window-button2" 60 ) 61 ); 62 } 63 }, 64 };