SecurityLevelUIUtils.sys.mjs (2253B)
1 /** 2 * Common methods for the desktop security level components. 3 */ 4 export const SecurityLevelUIUtils = { 5 /** 6 * Create an element that gives a description of the security level. To be 7 * used in the settings. 8 * 9 * @param {string} level - The security level to describe. 10 * @param {Document} doc - The document where the element will be inserted. 11 * 12 * @returns {Element} - The newly created element. 13 */ 14 createDescriptionElement(level, doc) { 15 const el = doc.createElement("div"); 16 el.classList.add("security-level-description"); 17 18 let l10nIdSummary; 19 let bullets; 20 switch (level) { 21 case "standard": 22 l10nIdSummary = "security-level-summary-standard"; 23 break; 24 case "safer": 25 l10nIdSummary = "security-level-summary-safer"; 26 bullets = [ 27 "security-level-preferences-bullet-https-only-javascript", 28 "security-level-preferences-bullet-limit-font-and-symbols", 29 "security-level-preferences-bullet-limit-media", 30 ]; 31 break; 32 case "safest": 33 l10nIdSummary = "security-level-summary-safest"; 34 bullets = [ 35 "security-level-preferences-bullet-disabled-javascript", 36 "security-level-preferences-bullet-limit-font-and-symbols-and-images", 37 "security-level-preferences-bullet-limit-media", 38 ]; 39 break; 40 case "custom": 41 l10nIdSummary = "security-level-summary-custom"; 42 break; 43 default: 44 throw Error(`Unhandled level: ${level}`); 45 } 46 47 const summaryEl = doc.createElement("div"); 48 summaryEl.classList.add("security-level-summary"); 49 doc.l10n.setAttributes(summaryEl, l10nIdSummary); 50 51 el.append(summaryEl); 52 53 if (!bullets) { 54 return el; 55 } 56 57 const listEl = doc.createElement("ul"); 58 listEl.classList.add("security-level-description-extra"); 59 // Add a mozilla styling class as well: 60 listEl.classList.add("privacy-extra-information"); 61 for (const l10nId of bullets) { 62 const bulletEl = doc.createElement("li"); 63 bulletEl.classList.add("security-level-description-bullet"); 64 65 doc.l10n.setAttributes(bulletEl, l10nId); 66 67 listEl.append(bulletEl); 68 } 69 70 el.append(listEl); 71 return el; 72 }, 73 };