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
Родитель 3843609c91
Коммит 8a810c34fc
2 изменённых файлов: 24 добавлений и 2 удалений

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

@ -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() {

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

@ -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");