Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix unloading
  • Loading branch information
gavinsharp committed Jan 15, 2013
1 parent 4bd66f6 commit 4576221
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion bootstrap.js
Expand Up @@ -2,18 +2,69 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */


var Cu = Components.utils; let Cu = Components.utils;
let Ci = Components.interfaces;


Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");


function startup(aData, aReason) { function startup(aData, aReason) {
// Monkeypatch all browser windows, current and future // Monkeypatch all browser windows, current and future
watchWindows(function (window) { watchWindows(function (window) {
// Stash the default version of the function
window._saveAsFilename_getDefaultFileName = window.getDefaultFileName;
window.getDefaultFileName = function (aDefaultFileName, aURI, aDocument, aContentDisposition) {
// Copy the bits from getDefaultFileName that attempt to retrieve the
// filename (either from the content disposition header, or from the URL
// itself). This essentially undoes the fix for bug 254139.
if (aContentDisposition) {
const mhpContractID = "@mozilla.org/network/mime-hdrparam;1";
const mhpIID = Components.interfaces.nsIMIMEHeaderParam;
const mhp = Components.classes[mhpContractID].getService(mhpIID);
var dummy = { value: null }; // Need an out param...
var charset = window.getCharsetforSave(aDocument);
var fileName = null;
try {
fileName = mhp.getParameter(aContentDisposition, "filename", charset,
true, dummy);
}
catch (e) {
try {
fileName = mhp.getParameter(aContentDisposition, "name", charset, true,
dummy);
}
catch (e) {
}
}
if (fileName)
return fileName;
}

try {
let url = aURI.QueryInterface(Ci.nsIURL);
if (url.fileName != "") {
var textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
.getService(Components.interfaces.nsITextToSubURI);
return window.validateFileName(textToSubURI.unEscapeURIForUI(url.originCharset || "UTF-8", url.fileName));
}
} catch (e) {
// This is something like a data: and so forth URI... no filename here.
}

// Delegate to the default version
return window._saveAsFilename_getDefaultFileName.apply(window, arguments);
}.bind(window);
}); });
} }


function shutdown(aData, aReason) { function shutdown(aData, aReason) {
if (aReason != APP_SHUTDOWN) { if (aReason != APP_SHUTDOWN) {
let enumerator = wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
let win = enumerator.getNext();
if (win._saveAsFilename_getDefaultFileName)
win.getDefaultFileName = win._saveAsFilename_getDefaultFileName;
}

unloaders.forEach(function (f) { unloaders.forEach(function (f) {
try { try {
f(); f();
Expand Down

0 comments on commit 4576221

Please sign in to comment.