Bug 1639067 part 4 - Generalize internal handlers in the Applications list. r=Gijs,preferences-reviewers,fluent-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D86653
This commit is contained in:
Adam Gashlin 2020-08-17 21:24:47 +00:00
parent a4c25ac405
commit 659f21a530
3 changed files with 40 additions and 19 deletions

View file

@ -26,6 +26,15 @@ ChromeUtils.defineModuleGetter(
"CloudStorage",
"resource://gre/modules/CloudStorage.jsm"
);
var { Integration } = ChromeUtils.import(
"resource://gre/modules/Integration.jsm"
);
/* global DownloadIntegration */
Integration.downloads.defineModuleGetter(
this,
"DownloadIntegration",
"resource://gre/modules/DownloadIntegration.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"SelectionChangedMenulist",
@ -1949,7 +1958,18 @@ var gMainPane = {
* applications menu.
*/
_loadInternalHandlers() {
var internalHandlers = [new PDFHandlerInfoWrapper()];
let internalHandlers = [new PDFHandlerInfoWrapper()];
let enabledHandlers = Services.prefs
.getCharPref("browser.download.viewableInternally.enabledTypes", "")
.trim();
if (enabledHandlers) {
for (let ext of enabledHandlers.split(",")) {
internalHandlers.push(
new ViewableInternallyHandlerInfoWrapper(ext.trim())
);
}
}
for (let internalHandler of internalHandlers) {
if (internalHandler.enabled) {
this._handledTypes[internalHandler.type] = internalHandler;
@ -2542,7 +2562,7 @@ var gMainPane = {
* Filter the list when the user enters a filter term into the filter field.
*/
filter() {
this._rebuildView();
this._rebuildView(); // FIXME: Should this be await since bug 1508156?
},
focusFilterBox() {
@ -3632,8 +3652,9 @@ class HandlerInfoWrapper {
* menu.
*/
class InternalHandlerInfoWrapper extends HandlerInfoWrapper {
constructor(mimeType) {
super(mimeType, gMIMEService.getFromTypeAndExtension(mimeType, null));
constructor(mimeType, extension) {
let type = gMIMEService.getFromTypeAndExtension(mimeType, extension);
super(mimeType || type.type, type);
}
// Override store so we so we can notify any code listening for registration
@ -3645,22 +3666,24 @@ class InternalHandlerInfoWrapper extends HandlerInfoWrapper {
get enabled() {
throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
}
get description() {
return { id: this._appPrefLabel };
}
}
class PDFHandlerInfoWrapper extends InternalHandlerInfoWrapper {
constructor() {
super(TYPE_PDF);
}
get _appPrefLabel() {
return "applications-type-pdf";
super(TYPE_PDF, null);
}
get enabled() {
return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED);
}
}
class ViewableInternallyHandlerInfoWrapper extends InternalHandlerInfoWrapper {
constructor(extension) {
super(null, extension);
}
get enabled() {
return DownloadIntegration.shouldViewDownloadInternally(this.type);
}
}

View file

@ -170,9 +170,12 @@ add_task(async function dialogShowsCorrectContent() {
let desc = dialogWin.document.getElementById("appDescription");
let descL10n = dialogWin.document.l10n.getAttributes(desc);
is(descL10n.id, "app-manager-handle-file", "Should have right string");
let stringBundle = Services.strings.createBundle(
"chrome://mozapps/locale/downloads/unknownContentType.properties"
);
is(
descL10n.args.type,
await dialogWin.document.l10n.formatValue("applications-type-pdf"),
stringBundle.GetStringFromName("pdfExtHandlerDescription"),
"Should have PDF string bits."
);

View file

@ -378,11 +378,6 @@ applications-manage-app =
.label = Application Details…
applications-always-ask =
.label = Always ask
applications-type-pdf = Portable Document Format (PDF)
# Variables:
# $type (String) - the MIME type (e.g application/binary)
applications-type-pdf-with-type = { applications-type-pdf } ({ $type })
# Variables:
# $type-description (String) - Description of the type (e.g "Portable Document Format")