Bug 1452819 - Use the right URI when getting data from the image cache for the "Save Image As..." context menu options. r=dao, a=jcristau
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 11 Apr 2018 10:27:01 -0400
changeset 802261 094590abbf52caa2634bdf09c882b05fc87b5f5c
parent 802260 a5ab68f0fdf09446f9af2c87854018edea00b916
child 802262 91ef127d6086546d9db3bac3343e328005718f6d
push id111850
push userbmo:tom@mozilla.com
push dateThu, 31 May 2018 16:41:37 +0000
reviewersdao, jcristau
bugs1452819
milestone60.0.2
Bug 1452819 - Use the right URI when getting data from the image cache for the "Save Image As..." context menu options. r=dao, a=jcristau MozReview-Commit-ID: zZggyJ6y7n
browser/modules/ContextMenu.jsm
--- a/browser/modules/ContextMenu.jsm
+++ b/browser/modules/ContextMenu.jsm
@@ -535,23 +535,25 @@ class ContextMenu {
 
     let disableSetDesktopBg = null;
 
     // Media related cache info parent needs for saving
     let contentType = null;
     let contentDisposition = null;
     if (aEvent.target.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
         aEvent.target instanceof Ci.nsIImageLoadingContent &&
-        aEvent.target.currentRequestFinalURI) {
+        aEvent.target.currentURI) {
       disableSetDesktopBg = this._disableSetDesktopBackground(aEvent.target);
 
       try {
         let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
                                                          .getImgCacheForDocument(doc);
-        let props = imageCache.findEntryProperties(aEvent.target.currentRequestFinalURI, doc);
+        // The image cache's notion of where this image is located is
+        // the currentURI of the image loading content.
+        let props = imageCache.findEntryProperties(aEvent.target.currentURI, doc);
 
         try {
           contentType = props.get("type", Ci.nsISupportsCString).data;
         } catch (e) {}
 
         try {
           contentDisposition = props.get("content-disposition", Ci.nsISupportsCString).data;
         } catch (e) {}
@@ -826,16 +828,19 @@ class ContextMenu {
       }
 
       if (request &&
           (request.imageStatus & request.STATUS_LOAD_COMPLETE) &&
           !(request.imageStatus & request.STATUS_ERROR)) {
         context.onCompletedImage = true;
       }
 
+      // The actual URL the image was loaded from (after redirects) is the
+      // currentRequestFinalURI.  We should use that as the URL for purposes of
+      // deciding on the filename.
       context.mediaURL = context.target.currentRequestFinalURI.spec;
 
       const descURL = context.target.getAttribute("longdesc");
 
       if (descURL) {
         context.imageDescURL = this._makeURLAbsolute(context.target.ownerDocument.body.baseURI,
                                                     descURL);
       }