Bug 1554098 - deduce RSS media enclosures type from extension when missing. r=mkmelin
authoralta88@fixall.com
Fri, 24 May 2019 12:34:22 -0400
changeset 35688 650172622d9943613c3739eb920bd050bcea1cb9
parent 35687 def8fdac20ee35662fc7f8b696ba2345bd889ecd
child 35689 a37b55df5e0baa88da4816cfd4f3ca96b6633f79
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersmkmelin
bugs1554098
Bug 1554098 - deduce RSS media enclosures type from extension when missing. r=mkmelin
mailnews/extensions/newsblog/content/FeedItem.js
--- a/mailnews/extensions/newsblog/content/FeedItem.js
+++ b/mailnews/extensions/newsblog/content/FeedItem.js
@@ -424,19 +424,25 @@ function FeedEnclosure(aURL, aContentTyp
   // Store a reasonable mimetype if content-type is not present.
   this.mContentType = aContentType || "application/unknown";
   this.mLength = aLength;
   this.mTitle = aTitle;
 
   // Generate a fileName from the URL.
   if (this.mURL) {
     try {
-      this.mFileName = Services.io.newURI(this.mURL).
-                                   QueryInterface(Ci.nsIURL).
-                                   fileName;
+      let uri = Services.io.newURI(this.mURL).QueryInterface(Ci.nsIURL);
+      this.mFileName = uri.fileName;
+      // Determine mimetype from extension if content-type is not present.
+      if (!aContentType) {
+        let contentType = Cc["@mozilla.org/mime;1"]
+                            .getService(Ci.nsIMIMEService)
+                            .getTypeFromExtension(uri.fileExtension);
+        this.mContentType = contentType;
+      }
     } catch (ex) {
       this.mFileName = this.mURL;
     }
   }
 }
 
 FeedEnclosure.prototype = {
   mURL: "",