Bug 750243 - Make sure target.currentURI is not null before saving an image r=wesj a=android-only

This commit is contained in:
Mark Finkle 2012-05-01 20:20:46 -04:00
parent 2e4f40583c
commit 9093a7fc0c

View File

@ -1140,8 +1140,6 @@ var NativeWindow = {
_contextId: 0, // id to assign to new context menu items if they are added
init: function() {
this.imageContext = this.SelectorContext("img");
Services.obs.addObserver(this, "Gesture:LongPress", false);
// TODO: These should eventually move into more appropriate classes
@ -1186,18 +1184,17 @@ var NativeWindow = {
});
this.add(Strings.browser.GetStringFromName("contextmenu.saveImage"),
this.imageContext,
this.imageSaveableContext,
function(aTarget) {
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet);
var contentDisposition = "";
var type = "";
let contentDisposition = "";
let type = "";
try {
String(props.get("content-disposition", Ci.nsISupportsCString));
String(props.get("type", Ci.nsISupportsCString));
} catch(ex) { }
var browser = BrowserApp.getBrowserForDocument(aTarget.ownerDocument);
ContentAreaUtils.internalSave(aTarget.currentURI.spec, null, null, contentDisposition, type, false, "SaveImageTitle", null, browser.documentURI, true, null);
ContentAreaUtils.internalSave(aTarget.currentURI.spec, null, null, contentDisposition, type, false, "SaveImageTitle", null, aTarget.ownerDocument.documentURIObject, true, null);
});
},
@ -1285,6 +1282,16 @@ var NativeWindow = {
}
},
imageSaveableContext: {
matches: function imageSaveableContextMatches(aElement) {
if (aElement instanceof Ci.nsIImageLoadingContent && aElement.currentURI) {
// The image must be loaded to allow saving
let request = aElement.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
return (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE));
}
}
},
_sendToContent: function(aX, aY) {
// initially we look for nearby clickable elements. If we don't find one we fall back to using whatever this click was on
let rootElement = ElementTouchHelper.elementFromPoint(BrowserApp.selectedBrowser.contentWindow, aX, aY);