Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Customizing the download progress bar

This example illustrates how to customize the progress bar displayed for a given download in the Downloads window.

First you need to overlay the Downloads window so that you can add a new stylesheet. In your jar.mn file, add the following (replacing "myextension" with the name of your extension's chrome package):

% overlay chrome://mozapps/content/downloads/downloads.xul  chrome://myextension/content/downloads-overlay.xul

In downloads-overlay.xul, reference the new stylesheet:

<?xml version="1.0"?>

<?xml-stylesheet href="chrome://myextension/skin/myextension.css" type="text/css"?>

<overlay id="myDownloadOverlay" xmlns="https://www.mozilla.org/keymaster/gat...re.is.only.xul">
 </overlay>

In jar.mn, make sure that there is an asterisk in front of the entry for myextension.css so that it will be preprocessed. This is required since it contains platform-specific directives, as we will see.

The myextension.css file will look something like this:

richlistitem progressmeter {
%ifdef XP_WIN
  min-height: 17px !important;
%else
%ifdef XP_MACOSX
  -moz-appearance: none !important;
  background-image: url(chrome://myextension/skin/progress_bg_osx.png) !important;
%endif
%endif
}

richlistitem .progress-bar {
%ifdef XP_WIN
  -moz-appearance: none !important;
  background-image: url(chrome://myextension/skin/progress_fd_win.png) !important;
%else
%ifdef XP_MACOSX
  background-image: url(chrome://myextension/skin/progress_fd_osx.gif) !important;
%endif
%endif
}

Note: This file only supports Windows and Mac, but it would be straightforward to add support for Linux.

This is the product of some tweaking and experimentation, so perhaps there is a different and/or better way to achieve the same thing. We are specifying the height of the progress meter on Windows and a background image on Mac. The background image (the first one in the file) should be a segment of whatever you want the unfilled portion of the progress bar to look like. An image of 7 pixels wide and 12 pixels high seems to work well. The other two images are for the filled in progress bar on Windows and Mac respectively. Once again, a height of 12 pixels or so and a few pixels wide seems about right, though you might have to experiment with this a bit.

Changing the progress bar for specific downloads

This is all you need to change the progress bar appearance for all downloads. If you want to change it for certain specific downloads only, things get a bit trickier. In your overlay file, add a JavaScript file between the <overlay> and </overlay> tags:

    <script type="application/javascript" src="chrome://myextension/content/downloads-overlay.js" />

The JavaScript file will look something like this:

var MyDownloadManager = {
  defaultCreateDownloadItem : null,

  init : function fdm_init() {
    MyDownloadManager.defaultCreateDownloadItem = window.createDownloadItem;
    window.createDownloadItem = function(aAttrs) {
      var dl = MyDownloadManager.defaultCreateDownloadItem(aAttrs);
      if (dl) {
             if (...whatever condition you use to decide whether to change this download...) {
               dl.setAttribute("myspecialdownload", "true");
        }
      }
      return dl;
    }
  }
};


window.addEventListener("load", function(e) { MyDownloadManager.init(); }, false);

In your CSS file, change richdownloaditem (both occurrences) to richdownloaditem[myspecialdownload="true"]. Now your new progress bar image will only be used for the downloads with your special attribute.

Document Tags and Contributors

 Contributors to this page: wbamberg, Sheppy, Plasticmillion
 Last updated by: wbamberg,