Skip to content

Commit

Permalink
Bug 1639067 part 4 - Generalize internal handlers in the Applications…
Browse files Browse the repository at this point in the history
… list. r=Gijs,preferences-reviewers,fluent-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D86653
  • Loading branch information
agashlin committed Aug 17, 2020
1 parent a4c25ac commit 659f21a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
47 changes: 35 additions & 12 deletions browser/components/preferences/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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);
super(TYPE_PDF, null);
}

get _appPrefLabel() {
return "applications-type-pdf";
get enabled() {
return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED);
}
}

class ViewableInternallyHandlerInfoWrapper extends InternalHandlerInfoWrapper {
constructor(extension) {
super(null, extension);
}

get enabled() {
return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED);
return DownloadIntegration.shouldViewDownloadInternally(this.type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);

Expand Down
5 changes: 0 additions & 5 deletions browser/locales/en-US/browser/preferences/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 659f21a

Please sign in to comment.