Bug 638523 - Save Image saves htm, not the image [r=mbrubeck]

This commit is contained in:
Vivien Nicolas 2011-03-04 12:55:07 +01:00
parent c55869127e
commit f996480c18
2 changed files with 24 additions and 2 deletions

View File

@ -52,8 +52,16 @@ var ContextCommands = {
},
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() {

View File

@ -804,6 +804,20 @@ var ContextHandler = {
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");