Bug 1466379 - fall back to currentURI in case images are blocked, r?bz,dao draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 07 Jun 2018 16:20:29 +0100
changeset 805236 b21941aad1d5cc13ece7ed84ca1344f0b09803ce
parent 804634 cec4a3cecc29ff97860198969b6fdff24b9e93bb
push id112608
push userbmo:gijskruitbosch+bugs@gmail.com
push dateThu, 07 Jun 2018 15:21:20 +0000
reviewersbz, dao
bugs1466379
milestone62.0a1
Bug 1466379 - fall back to currentURI in case images are blocked, r?bz,dao MozReview-Commit-ID: FW2f18pF4t5
browser/modules/ContextMenu.jsm
dom/browser-element/BrowserElementChildPreload.js
mobile/android/chrome/content/browser.js
--- a/browser/modules/ContextMenu.jsm
+++ b/browser/modules/ContextMenu.jsm
@@ -800,17 +800,17 @@ class ContextMenu {
     if (context.target.nodeType != context.target.ELEMENT_NODE) {
       return;
     }
 
     // See if the user clicked on an image. This check mirrors
     // nsDocumentViewer::GetInImage. Make sure to update both if this is
     // changed.
     if (context.target instanceof Ci.nsIImageLoadingContent &&
-        context.target.currentRequestFinalURI) {
+        (context.target.currentRequestFinalURI || context.target.currentURI)) {
       context.onImage = true;
 
       context.imageInfo = {
         currentSrc: context.target.currentSrc,
         width: context.target.width,
         height: context.target.height,
         imageText: context.target.title || context.target.alt
       };
@@ -824,18 +824,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;
+      // deciding on the filename, if it is present. It might not be present
+      // if images are blocked.
+      context.mediaURL = (context.target.currentRequestFinalURI || context.target.currentURI).spec;
 
       const descURL = context.target.getAttribute("longdesc");
 
       if (descURL) {
         context.imageDescURL = this._makeURLAbsolute(context.target.ownerDocument.body.baseURI,
                                                     descURL);
       }
     } else if (context.target instanceof this.content.HTMLCanvasElement) {
--- a/dom/browser-element/BrowserElementChildPreload.js
+++ b/dom/browser-element/BrowserElementChildPreload.js
@@ -858,18 +858,20 @@ BrowserElementChild.prototype = {
       docShell.QueryInterface(Ci.nsIWebNavigation).currentURI.spec;
 
     if ((ChromeUtils.getClassName(elem) === "HTMLAnchorElement" && elem.href) ||
         (ChromeUtils.getClassName(elem) === "HTMLAreaElement" && elem.href)) {
       return {uri: elem.href,
               documentURI: documentURI,
               text: elem.textContent.substring(0, kLongestReturnedString)};
     }
-    if (elem instanceof Ci.nsIImageLoadingContent && elem.currentRequestFinalURI) {
-      return {uri: elem.currentRequestFinalURI.spec, documentURI: documentURI};
+    if (elem instanceof Ci.nsIImageLoadingContent &&
+        (elem.currentRequestFinalURI || elem.currentURI)) {
+      let uri = elem.currentRequestFinalURI || elem.currentURI;
+      return {uri: uri.spec, documentURI: documentURI};
     }
     if (ChromeUtils.getClassName(elem) === "HTMLImageElement") {
       return {uri: elem.src, documentURI: documentURI};
     }
     if (ChromeUtils.getClassName(elem) === "HTMLVideoElement" ||
         ChromeUtils.getClassName(elem) === "HTMLAudioElement") {
       let hasVideo = !(elem.readyState >= elem.HAVE_METADATA &&
                        (elem.videoWidth == 0 || elem.videoHeight == 0));
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -892,17 +892,18 @@ var BrowserApp = {
           type: "Mma:web_save_image",
         });
 
         RuntimePermissions.waitForPermissions(RuntimePermissions.WRITE_EXTERNAL_STORAGE).then(function(permissionGranted) {
             if (!permissionGranted) {
                 return;
             }
 
-            ContentAreaUtils.saveImageURL(aTarget.currentRequestFinalURI.spec, null, "SaveImageTitle",
+            let uri = aTarget.currentRequestFinalURI || aTarget.currentURI;
+            ContentAreaUtils.saveImageURL(uri.spec, null, "SaveImageTitle",
                                           false, true, aTarget.ownerDocument.documentURIObject,
                                           aTarget.ownerDocument);
         });
       });
 
     NativeWindow.contextmenus.add(stringGetter("contextmenu.setImageAs"),
       NativeWindow.contextmenus._disableRestricted("SET_IMAGE", NativeWindow.contextmenus.imageSaveableContext),
       function(aTarget) {