Bug 638523 - Save Image saves htm, not the image [r=mbrubeck]
authorVivien Nicolas <21@vingtetun.org>
Fri, 04 Mar 2011 12:55:07 +0100
changeset 67467 5f90d630749b654ba5df9e7e3202bc03f99e2b29
parent 67466 cba6aba978cb021d67d08ad84afe47108fe331ed
child 67468 fa30dde17d49b6b6b35f376c4932898aa287af20
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs638523
Bug 638523 - Save Image saves htm, not the image [r=mbrubeck]
mobile/chrome/content/ContextCommands.js
mobile/chrome/content/content.js
--- a/mobile/chrome/content/ContextCommands.js
+++ b/mobile/chrome/content/ContextCommands.js
@@ -47,18 +47,26 @@ var ContextCommands = {
   },
 
   saveLink: function cc_saveLink() {
     let browser = ContextHelper.popupState.target;
     ContentAreaUtils.saveURL(ContextHelper.popupState.linkURL, null, "SaveLinkTitle", false, true, browser.documentURI);
   },
 
   saveImage: function cc_saveImage() {
-    let browser = ContextHelper.popupState.target;
-    ContentAreaUtils.saveImageURL(ContextHelper.popupState.mediaURL, null, "SaveImageTitle", false, true, browser.documentURI);
+    let popupState = ContextHelper.popupState;
+    let browser = popupState.target;
+
+    // Bug 638523
+    // Using directly SaveImageURL fails here since checking the cache for a
+    // remote page seems to not work (could it be nsICacheSession prohibition)?
+    ContentAreaUtils.internalSave(popupState.mediaURL, null, null,
+                                  popupState.contentDisposition,
+                                  popupState.contentType, false, "SaveImageTitle",
+                                  null, browser.documentURI, false, null);
   },
 
   shareLink: function cc_shareLink() {
     let state = ContextHelper.popupState;
     SharingUI.show(state.linkURL, state.linkTitle);
   },
 
   shareMedia: function cc_shareMedia() {
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -799,16 +799,30 @@ var ContextHandler = {
     let popupNode = this.popupNode = aEvent.originalTarget;
 
     // Do checks for nodes that never have children.
     if (popupNode.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) {
       // See if the user clicked on an image.
       if (popupNode instanceof Ci.nsIImageLoadingContent && popupNode.currentURI) {
         state.types.push("image");
         state.label = state.mediaURL = popupNode.currentURI.spec;
+
+        // Retrieve the type of image from the cache since the url can fail to
+        // provide valuable informations
+        try {
+          let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
+          let props = imageCache.findEntryProperties(popupNode.currentURI, content.document.characterSet);
+          if (props) {
+            state.contentType = String(props.get("type", Ci.nsISupportsCString));
+            state.contentDisposition = String(props.get("content-disposition", Ci.nsISupportsCString));
+          }
+        } catch (e) {
+          // Failure to get type and content-disposition off the image is non-fatal
+        }
+
       } else if (popupNode instanceof Ci.nsIDOMHTMLMediaElement) {
         state.label = state.mediaURL = (popupNode.currentSrc || popupNode.src);
         state.types.push((popupNode.paused || popupNode.ended) ? "media-paused" : "media-playing");
         if (popupNode instanceof Ci.nsIDOMHTMLVideoElement)
           state.types.push("video");
       }
     }