diff --git a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js index 4e0ae6bb7fd..d2efc36100d 100644 --- a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js +++ b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js @@ -551,27 +551,30 @@ nsHeaderSniffer.prototype = { get suggestedFileName() { - var filename = ""; - var name = this.mContentDisposition; - if (name) { - const filenamePrefix = "filename="; - var ix = name.indexOf(filenamePrefix); - if (ix >= 0) { - // Adjust ix to point to start of actual name - ix += filenamePrefix.length; - filename = name.substr(ix, name.length); - if (filename != "") { - ix = filename.lastIndexOf(";"); - if (ix > 0) - filename = filename.substr(0, ix); - - filename = filename.replace(/^"|"$/g, ""); + var fileName = ""; + + if (this.mContentDisposition) { + const mhpContractID = "@mozilla.org/network/mime-hdrparam;1" + const mhpIID = Components.interfaces.nsIMIMEHeaderParam; + const mhp = Components.classes[mhpContractID].getService(mhpIID); + var dummy = { value: null }; // To make JS engine happy. + var charset = getCharsetforSave(null); + + try { + fileName = mhp.getParameter(this.mContentDisposition, "filename", charset, true, dummy); + } + catch (e) { + try { + fileName = mhp.getParameter(this.mContentDisposition, "name", charset, true, dummy); + } + catch (e) { } } } - return filename; - } + fileName = fileName.replace(/^"|"$/g, ""); + return fileName; + } }; // We have no DOM, and can only save the URL as is. @@ -768,13 +771,7 @@ function getDefaultFileName(aDefaultFileName, aNameFromHeaders, aDocumentURI, aD // try unescape again with a characterSet var textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"] .getService(Components.interfaces.nsITextToSubURI); - var charset; - if (aDocument) - charset = aDocument.characterSet; - else if (document.commandDispatcher.focusedWindow) - charset = document.commandDispatcher.focusedWindow.document.characterSet; - else - charset = window._content.document.characterSet; + var charset = getCharsetforSave(aDocument); return textToSubURI.unEscapeURIForUI(charset, url.fileName); } catch (e) { // This is something like a wyciwyg:, data:, and so forth @@ -907,3 +904,14 @@ function GetSaveModeForContentType(aContentType) return saveMode; } + +function getCharsetforSave(aDocument) +{ + if (aDocument) + return aDocument.characterSet; + + if (document.commandDispatcher.focusedWindow) + return document.commandDispatcher.focusedWindow.document.characterSet; + + return window._content.document.characterSet; +}