Bug 1639069 - Add download context menu items to 'Use' and 'Always use' the system viewer to open the download. r=jaws

Differential Revision: https://phabricator.services.mozilla.com/D79396
This commit is contained in:
Sam Foster
2020-06-25 22:19:37 +00:00
parent 20a6f91e8b
commit 19f6f1121e
13 changed files with 389 additions and 8 deletions

View File

@@ -705,6 +705,9 @@ DownloadsPlacesView.prototype = {
// Set the state attribute so that only the appropriate items are displayed.
let contextMenu = document.getElementById("downloadsContextMenu");
let download = element._shell.download;
let { preferredAction, useSystemDefault } = DownloadsCommon.getMimeInfo(
download
);
contextMenu.setAttribute(
"state",
DownloadsCommon.stateOfDownload(download)
@@ -712,6 +715,31 @@ DownloadsPlacesView.prototype = {
contextMenu.setAttribute("exists", "true");
contextMenu.classList.toggle("temporary-block", !!download.hasBlockedData);
if (element.hasAttribute("is-pdf")) {
contextMenu.setAttribute("is-pdf", "true");
let alwaysUseSystemViewerItem = contextMenu.querySelector(
".downloadAlwaysUseSystemDefaultMenuItem"
);
if (preferredAction === useSystemDefault) {
alwaysUseSystemViewerItem.setAttribute("checked", "true");
} else {
alwaysUseSystemViewerItem.removeAttribute("checked");
}
alwaysUseSystemViewerItem.toggleAttribute(
"enabled",
DownloadsCommon.alwaysOpenInSystemViewerItemEnabled
);
let useSystemViewerItem = contextMenu.querySelector(
".downloadUseSystemDefaultMenuItem"
);
useSystemViewerItem.toggleAttribute(
"enabled",
DownloadsCommon.openInSystemViewerItemEnabled
);
} else {
contextMenu.removeAttribute("is-pdf");
}
if (!download.stopped) {
// The hasPartialData property of a download may change at any time after
// it has started, so ensure we update the related command now.