From 84df3ed32ee201ba970619ca12c5e33d5e48839f Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Tue, 1 May 2012 20:20:46 -0400 Subject: [PATCH] Bug 750243 - Make sure target.currentURI is not null before saving an image r=wesj a=android-only --- mobile/android/chrome/content/browser.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index d6a854d9aaf..8b2f987cdc9 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -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);