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
Родитель 7413f29aec
Коммит 84df3ed32e
1 изменённых файлов: 14 добавлений и 7 удалений

Просмотреть файл

@ -1140,8 +1140,6 @@ var NativeWindow = {
_contextId: 0, // id to assign to new context menu items if they are added _contextId: 0, // id to assign to new context menu items if they are added
init: function() { init: function() {
this.imageContext = this.SelectorContext("img");
Services.obs.addObserver(this, "Gesture:LongPress", false); Services.obs.addObserver(this, "Gesture:LongPress", false);
// TODO: These should eventually move into more appropriate classes // TODO: These should eventually move into more appropriate classes
@ -1186,18 +1184,17 @@ var NativeWindow = {
}); });
this.add(Strings.browser.GetStringFromName("contextmenu.saveImage"), this.add(Strings.browser.GetStringFromName("contextmenu.saveImage"),
this.imageContext, this.imageSaveableContext,
function(aTarget) { function(aTarget) {
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache); let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet); let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet);
var contentDisposition = ""; let contentDisposition = "";
var type = ""; let type = "";
try { try {
String(props.get("content-disposition", Ci.nsISupportsCString)); String(props.get("content-disposition", Ci.nsISupportsCString));
String(props.get("type", Ci.nsISupportsCString)); String(props.get("type", Ci.nsISupportsCString));
} catch(ex) { } } catch(ex) { }
var browser = BrowserApp.getBrowserForDocument(aTarget.ownerDocument); ContentAreaUtils.internalSave(aTarget.currentURI.spec, null, null, contentDisposition, type, false, "SaveImageTitle", null, aTarget.ownerDocument.documentURIObject, true, null);
ContentAreaUtils.internalSave(aTarget.currentURI.spec, null, null, contentDisposition, type, false, "SaveImageTitle", null, browser.documentURI, 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) { _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 // 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); let rootElement = ElementTouchHelper.elementFromPoint(BrowserApp.selectedBrowser.contentWindow, aX, aY);