forked from mirrors/gecko-dev
		
	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:
		
							parent
							
								
									a4c25ac405
								
							
						
					
					
						commit
						659f21a530
					
				
					 3 changed files with 40 additions and 19 deletions
				
			
		|  | @ -26,6 +26,15 @@ ChromeUtils.defineModuleGetter( | ||||||
|   "CloudStorage", |   "CloudStorage", | ||||||
|   "resource://gre/modules/CloudStorage.jsm" |   "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( | ChromeUtils.defineModuleGetter( | ||||||
|   this, |   this, | ||||||
|   "SelectionChangedMenulist", |   "SelectionChangedMenulist", | ||||||
|  | @ -1949,7 +1958,18 @@ var gMainPane = { | ||||||
|    * applications menu. |    * applications menu. | ||||||
|    */ |    */ | ||||||
|   _loadInternalHandlers() { |   _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) { |     for (let internalHandler of internalHandlers) { | ||||||
|       if (internalHandler.enabled) { |       if (internalHandler.enabled) { | ||||||
|         this._handledTypes[internalHandler.type] = internalHandler; |         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 the list when the user enters a filter term into the filter field. | ||||||
|    */ |    */ | ||||||
|   filter() { |   filter() { | ||||||
|     this._rebuildView(); |     this._rebuildView(); // FIXME: Should this be await since bug 1508156?
 | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   focusFilterBox() { |   focusFilterBox() { | ||||||
|  | @ -3632,8 +3652,9 @@ class HandlerInfoWrapper { | ||||||
|  * menu. |  * menu. | ||||||
|  */ |  */ | ||||||
| class InternalHandlerInfoWrapper extends HandlerInfoWrapper { | class InternalHandlerInfoWrapper extends HandlerInfoWrapper { | ||||||
|   constructor(mimeType) { |   constructor(mimeType, extension) { | ||||||
|     super(mimeType, gMIMEService.getFromTypeAndExtension(mimeType, null)); |     let type = gMIMEService.getFromTypeAndExtension(mimeType, extension); | ||||||
|  |     super(mimeType || type.type, type); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Override store so we so we can notify any code listening for registration
 |   // Override store so we so we can notify any code listening for registration
 | ||||||
|  | @ -3645,22 +3666,24 @@ class InternalHandlerInfoWrapper extends HandlerInfoWrapper { | ||||||
|   get enabled() { |   get enabled() { | ||||||
|     throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED); |     throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED); | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
|   get description() { |  | ||||||
|     return { id: this._appPrefLabel }; |  | ||||||
|   } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class PDFHandlerInfoWrapper extends InternalHandlerInfoWrapper { | class PDFHandlerInfoWrapper extends InternalHandlerInfoWrapper { | ||||||
|   constructor() { |   constructor() { | ||||||
|     super(TYPE_PDF); |     super(TYPE_PDF, null); | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   get _appPrefLabel() { |  | ||||||
|     return "applications-type-pdf"; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get enabled() { |   get enabled() { | ||||||
|     return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED); |     return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | class ViewableInternallyHandlerInfoWrapper extends InternalHandlerInfoWrapper { | ||||||
|  |   constructor(extension) { | ||||||
|  |     super(null, extension); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   get enabled() { | ||||||
|  |     return DownloadIntegration.shouldViewDownloadInternally(this.type); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -170,9 +170,12 @@ add_task(async function dialogShowsCorrectContent() { | ||||||
|   let desc = dialogWin.document.getElementById("appDescription"); |   let desc = dialogWin.document.getElementById("appDescription"); | ||||||
|   let descL10n = dialogWin.document.l10n.getAttributes(desc); |   let descL10n = dialogWin.document.l10n.getAttributes(desc); | ||||||
|   is(descL10n.id, "app-manager-handle-file", "Should have right string"); |   is(descL10n.id, "app-manager-handle-file", "Should have right string"); | ||||||
|  |   let stringBundle = Services.strings.createBundle( | ||||||
|  |     "chrome://mozapps/locale/downloads/unknownContentType.properties" | ||||||
|  |   ); | ||||||
|   is( |   is( | ||||||
|     descL10n.args.type, |     descL10n.args.type, | ||||||
|     await dialogWin.document.l10n.formatValue("applications-type-pdf"), |     stringBundle.GetStringFromName("pdfExtHandlerDescription"), | ||||||
|     "Should have PDF string bits." |     "Should have PDF string bits." | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -378,11 +378,6 @@ applications-manage-app = | ||||||
|     .label = Application Details… |     .label = Application Details… | ||||||
| applications-always-ask = | applications-always-ask = | ||||||
|     .label = 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: | # Variables: | ||||||
| #   $type-description (String) - Description of the type (e.g "Portable Document Format") | #   $type-description (String) - Description of the type (e.g "Portable Document Format") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Adam Gashlin
						Adam Gashlin