contentAreaDownloadsView.js (3235B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* import-globals-from allDownloadsView.js */ 6 7 const { PrivateBrowsingUtils } = ChromeUtils.importESModule( 8 "resource://gre/modules/PrivateBrowsingUtils.sys.mjs" 9 ); 10 11 const { DownloadsTorWarning } = ChromeUtils.importESModule( 12 "moz-src:///browser/components/downloads/DownloadsTorWarning.sys.mjs" 13 ); 14 15 var ContentAreaDownloadsView = { 16 init() { 17 let box = document.getElementById("downloadsListBox"); 18 19 const torWarning = new DownloadsTorWarning( 20 document.getElementById("aboutDownloadsTorWarning"), 21 false, 22 () => { 23 // Try and focus the downloads list. 24 // NOTE: If #downloadsListBox is still hidden, this will do nothing. 25 // But in this case there are no other focusable targets within the 26 // view, so we just leave it up to the focus handler. 27 box.focus({ preventFocusRing: true }); 28 } 29 ); 30 torWarning.activate(); 31 window.addEventListener("unload", () => { 32 torWarning.deactivate(); 33 }); 34 35 let suppressionFlag = DownloadsCommon.SUPPRESS_CONTENT_AREA_DOWNLOADS_OPEN; 36 box.addEventListener( 37 "InitialDownloadsLoaded", 38 () => { 39 // Set focus to Downloads list once it is created 40 // And prevent it from showing the focus ring around the richlistbox (Bug 1702694) 41 // Prevent focusing the list whilst the tor browser warning is shown. 42 // Some screen readers (tested with Orca and NVDA) will not read out 43 // alerts if they are already present on page load. In that case, a 44 // screen reader user may not be aware of the warning before they 45 // interact with the downloads list, which we do not want. 46 // Some hacky workarounds were tested with Orca to get it to read back 47 // the alert before the focus is read, but this was inconsistent and the 48 // experience was bad. 49 // Without auto-focusing the downloads list, a screen reader should not 50 // skip beyond the alert's content. 51 if (torWarning.hidden) { 52 document 53 .getElementById("downloadsListBox") 54 .focus({ focusVisible: false }); 55 } 56 57 // Pause the indicator if the browser is active. 58 if (document.visibilityState === "visible") { 59 DownloadsCommon.getIndicatorData(window).attentionSuppressed |= 60 suppressionFlag; 61 } 62 }, 63 { once: true } 64 ); 65 let view = new DownloadsPlacesView(box, true, suppressionFlag); 66 document.addEventListener("visibilitychange", () => { 67 let indicator = DownloadsCommon.getIndicatorData(window); 68 if (document.visibilityState === "visible") { 69 indicator.attentionSuppressed |= suppressionFlag; 70 } else { 71 indicator.attentionSuppressed &= ~suppressionFlag; 72 } 73 }); 74 // Do not display the Places downloads in private windows 75 if (!PrivateBrowsingUtils.isContentWindowPrivate(window)) { 76 view.place = "place:transition=7&sort=4"; 77 } 78 }, 79 }; 80 81 window.onload = function () { 82 ContentAreaDownloadsView.init(); 83 };