Permalink
Browse files

fix unloading

  • Loading branch information...
1 parent 4bd66f6 commit 45762216b0de97071c68ab98f1192b8a7d760071 @gavinsharp committed Jan 15, 2013
Showing with 52 additions and 1 deletion.
  1. +52 −1 bootstrap.js
View
@@ -2,18 +2,69 @@
* 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/. */
-var Cu = Components.utils;
+let Cu = Components.utils;
+let Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
function startup(aData, aReason) {
// Monkeypatch all browser windows, current and future
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) {
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) {
try {
f();

0 comments on commit 4576221

Please sign in to comment.