From a4c25ac4052378fa8c711a2f26a7edc6eeb1ee7d Mon Sep 17 00:00:00 2001 From: Adam Gashlin Date: Mon, 17 Aug 2020 21:24:45 +0000 Subject: [PATCH] Bug 1639067 part 3 - Extend "Open In System Viewer" from PDF to all viewable internally. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D86652 --- .../components/downloads/DownloadsSubview.jsm | 12 +++++----- .../components/downloads/DownloadsViewUI.jsm | 24 +++++++++++++++---- .../downloads/content/allDownloadsView.js | 6 ++--- .../downloads/content/downloads.css | 4 ++-- .../components/downloads/content/downloads.js | 6 ++--- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/browser/components/downloads/DownloadsSubview.jsm b/browser/components/downloads/DownloadsSubview.jsm index 4253bdae16f8..e58e3cce07d7 100644 --- a/browser/components/downloads/DownloadsSubview.jsm +++ b/browser/components/downloads/DownloadsSubview.jsm @@ -311,14 +311,14 @@ class DownloadsSubview extends DownloadsViewUI.BaseView { "temporary-block", button.classList.contains("temporary-block") ); - // menu items are conditionally displayed via CSS based on an is-pdf attribute + // menu items are conditionally displayed via CSS based on a viewable-internally attribute DownloadsCommon.log( - "DownloadsSubview, updateContextMenu, download is pdf? ", + "DownloadsSubview, updateContextMenu, download is viewable internally? ", download.target.path, - button.hasAttribute("is-pdf") + button.hasAttribute("viewable-internally") ); - if (button.hasAttribute("is-pdf")) { - menu.setAttribute("is-pdf", "true"); + if (button.hasAttribute("viewable-internally")) { + menu.setAttribute("viewable-internally", "true"); let alwaysUseSystemViewerItem = menu.querySelector( ".downloadAlwaysUseSystemDefaultMenuItem" ); @@ -339,7 +339,7 @@ class DownloadsSubview extends DownloadsViewUI.BaseView { DownloadsCommon.openInSystemViewerItemEnabled ); } else { - menu.removeAttribute("is-pdf"); + menu.removeAttribute("viewable-internally"); } for (let menuitem of menu.getElementsByTagName("menuitem")) { diff --git a/browser/components/downloads/DownloadsViewUI.jsm b/browser/components/downloads/DownloadsViewUI.jsm index 82c7fb031fd4..3ab1cdb15d57 100644 --- a/browser/components/downloads/DownloadsViewUI.jsm +++ b/browser/components/downloads/DownloadsViewUI.jsm @@ -31,6 +31,17 @@ XPCOMUtils.defineLazyServiceGetter( "nsIHandlerService" ); +const { Integration } = ChromeUtils.import( + "resource://gre/modules/Integration.jsm" +); + +/* global DownloadIntegration */ +Integration.downloads.defineModuleGetter( + this, + "DownloadIntegration", + "resource://gre/modules/DownloadIntegration.jsm" +); + const HTML_NS = "http://www.w3.org/1999/xhtml"; var gDownloadElementButtons = { @@ -465,11 +476,12 @@ DownloadsViewUI.DownloadElementShell.prototype = { // This is a completed download, and the target file still exists. this.element.setAttribute("exists", "true"); - const isPDF = DownloadsCommon.isFileOfType( - this.download, - "application/pdf" + this.element.toggleAttribute( + "viewable-internally", + DownloadIntegration.shouldViewDownloadInternally( + DownloadsCommon.getMimeInfo(this.download)?.type + ) ); - this.element.toggleAttribute("is-pdf", isPDF); let sizeWithUnits = DownloadsViewUI.getSizeWithUnits(this.download); if (this.isPanel) { @@ -741,7 +753,9 @@ DownloadsViewUI.DownloadElementShell.prototype = { return this.download.stopped; case "downloadsCmd_openInSystemViewer": case "downloadsCmd_alwaysOpenInSystemViewer": - return DownloadsCommon.isFileOfType(this.download, "application/pdf"); + return DownloadIntegration.shouldViewDownloadInternally( + DownloadsCommon.getMimeInfo(this.download)?.type + ); } return DownloadsViewUI.isCommandName(aCommand) && !!this[aCommand]; }, diff --git a/browser/components/downloads/content/allDownloadsView.js b/browser/components/downloads/content/allDownloadsView.js index 7b14b75ab5f0..27a95fbca438 100644 --- a/browser/components/downloads/content/allDownloadsView.js +++ b/browser/components/downloads/content/allDownloadsView.js @@ -715,8 +715,8 @@ DownloadsPlacesView.prototype = { contextMenu.setAttribute("exists", "true"); contextMenu.classList.toggle("temporary-block", !!download.hasBlockedData); - if (element.hasAttribute("is-pdf")) { - contextMenu.setAttribute("is-pdf", "true"); + if (element.hasAttribute("viewable-internally")) { + contextMenu.setAttribute("viewable-internally", "true"); let alwaysUseSystemViewerItem = contextMenu.querySelector( ".downloadAlwaysUseSystemDefaultMenuItem" ); @@ -737,7 +737,7 @@ DownloadsPlacesView.prototype = { DownloadsCommon.openInSystemViewerItemEnabled ); } else { - contextMenu.removeAttribute("is-pdf"); + contextMenu.removeAttribute("viewable-internally"); } if (!download.stopped) { diff --git a/browser/components/downloads/content/downloads.css b/browser/components/downloads/content/downloads.css index 0f034ef1522f..3af84ba94d49 100644 --- a/browser/components/downloads/content/downloads.css +++ b/browser/components/downloads/content/downloads.css @@ -99,10 +99,10 @@ /* the system-viewer context menu items are only shown for certain mime-types and can be individually enabled via prefs */ -.download-state:not([is-pdf]) .downloadUseSystemDefaultMenuItem, +.download-state:not([viewable-internally]) .downloadUseSystemDefaultMenuItem, .download-state .downloadUseSystemDefaultMenuItem:not([enabled]), .download-state .downloadAlwaysUseSystemDefaultMenuItem:not([enabled]), -.download-state:not([is-pdf]) .downloadAlwaysUseSystemDefaultMenuItem +.download-state:not([viewable-internally]) .downloadAlwaysUseSystemDefaultMenuItem { display: none; } diff --git a/browser/components/downloads/content/downloads.js b/browser/components/downloads/content/downloads.js index 7e9dfa855975..0ec0700656ad 100644 --- a/browser/components/downloads/content/downloads.js +++ b/browser/components/downloads/content/downloads.js @@ -953,8 +953,8 @@ var DownloadsView = { "temporary-block", element.classList.contains("temporary-block") ); - if (element.hasAttribute("is-pdf")) { - contextMenu.setAttribute("is-pdf", "true"); + if (element.hasAttribute("viewable-internally")) { + contextMenu.setAttribute("viewable-internally", "true"); let alwaysUseSystemViewerItem = contextMenu.querySelector( ".downloadAlwaysUseSystemDefaultMenuItem" ); @@ -975,7 +975,7 @@ var DownloadsView = { DownloadsCommon.openInSystemViewerItemEnabled ); } else { - contextMenu.removeAttribute("is-pdf"); + contextMenu.removeAttribute("viewable-internally"); } },