Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix unloading

  • Loading branch information...
commit 45762216b0de97071c68ab98f1192b8a7d760071 1 parent 4bd66f6
Gavin Sharp authored

Showing 1 changed file with 52 additions and 1 deletion. Show diff stats Hide diff stats

  1. +52 1 bootstrap.js
53 bootstrap.js
@@ -2,18 +2,69 @@
2 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5   -var Cu = Components.utils;
  5 +let Cu = Components.utils;
  6 +let Ci = Components.interfaces;
6 7
7 8 Cu.import("resource://gre/modules/Services.jsm");
8 9
9 10 function startup(aData, aReason) {
10 11 // Monkeypatch all browser windows, current and future
11 12 watchWindows(function (window) {
  13 + // Stash the default version of the function
  14 + window._saveAsFilename_getDefaultFileName = window.getDefaultFileName;
  15 + window.getDefaultFileName = function (aDefaultFileName, aURI, aDocument, aContentDisposition) {
  16 + // Copy the bits from getDefaultFileName that attempt to retrieve the
  17 + // filename (either from the content disposition header, or from the URL
  18 + // itself). This essentially undoes the fix for bug 254139.
  19 + if (aContentDisposition) {
  20 + const mhpContractID = "@mozilla.org/network/mime-hdrparam;1";
  21 + const mhpIID = Components.interfaces.nsIMIMEHeaderParam;
  22 + const mhp = Components.classes[mhpContractID].getService(mhpIID);
  23 + var dummy = { value: null }; // Need an out param...
  24 + var charset = window.getCharsetforSave(aDocument);
  25 + var fileName = null;
  26 + try {
  27 + fileName = mhp.getParameter(aContentDisposition, "filename", charset,
  28 + true, dummy);
  29 + }
  30 + catch (e) {
  31 + try {
  32 + fileName = mhp.getParameter(aContentDisposition, "name", charset, true,
  33 + dummy);
  34 + }
  35 + catch (e) {
  36 + }
  37 + }
  38 + if (fileName)
  39 + return fileName;
  40 + }
  41 +
  42 + try {
  43 + let url = aURI.QueryInterface(Ci.nsIURL);
  44 + if (url.fileName != "") {
  45 + var textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
  46 + .getService(Components.interfaces.nsITextToSubURI);
  47 + return window.validateFileName(textToSubURI.unEscapeURIForUI(url.originCharset || "UTF-8", url.fileName));
  48 + }
  49 + } catch (e) {
  50 + // This is something like a data: and so forth URI... no filename here.
  51 + }
  52 +
  53 + // Delegate to the default version
  54 + return window._saveAsFilename_getDefaultFileName.apply(window, arguments);
  55 + }.bind(window);
12 56 });
13 57 }
14 58
15 59 function shutdown(aData, aReason) {
16 60 if (aReason != APP_SHUTDOWN) {
  61 + let enumerator = wm.getEnumerator("navigator:browser");
  62 + while (enumerator.hasMoreElements()) {
  63 + let win = enumerator.getNext();
  64 + if (win._saveAsFilename_getDefaultFileName)
  65 + win.getDefaultFileName = win._saveAsFilename_getDefaultFileName;
  66 + }
  67 +
17 68 unloaders.forEach(function (f) {
18 69 try {
19 70 f();

0 comments on commit 4576221

Please sign in to comment.
Something went wrong with that request. Please try again.