Bug 1466379 - fall back to currentURI in case images are blocked, r?bz,dao
MozReview-Commit-ID: FW2f18pF4t5
--- 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) {