browser/components/downloads/src/DownloadsStartup.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/downloads/src/DownloadsStartup.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/**
    1.11 + * This component enables the JavaScript API for downloads at startup.  This
    1.12 + * will eventually be removed when nsIDownloadManager will not be available
    1.13 + * anymore (bug 851471).
    1.14 + */
    1.15 +
    1.16 +"use strict";
    1.17 +
    1.18 +////////////////////////////////////////////////////////////////////////////////
    1.19 +//// Globals
    1.20 +
    1.21 +const Cc = Components.classes;
    1.22 +const Ci = Components.interfaces;
    1.23 +const Cu = Components.utils;
    1.24 +const Cr = Components.results;
    1.25 +
    1.26 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.27 +
    1.28 +/**
    1.29 + * CID and Contract ID of our implementation of nsIDownloadManagerUI.
    1.30 + */
    1.31 +const kDownloadsUICid = Components.ID("{4d99321e-d156-455b-81f7-e7aa2308134f}");
    1.32 +const kDownloadsUIContractId = "@mozilla.org/download-manager-ui;1";
    1.33 +
    1.34 +/**
    1.35 + * CID and Contract ID of the JavaScript implementation of nsITransfer.
    1.36 + */
    1.37 +const kTransferCid = Components.ID("{1b4c85df-cbdd-4bb6-b04e-613caece083c}");
    1.38 +const kTransferContractId = "@mozilla.org/transfer;1";
    1.39 +
    1.40 +////////////////////////////////////////////////////////////////////////////////
    1.41 +//// DownloadsStartup
    1.42 +
    1.43 +function DownloadsStartup() { }
    1.44 +
    1.45 +DownloadsStartup.prototype = {
    1.46 +  classID: Components.ID("{49507fe5-2cee-4824-b6a3-e999150ce9b8}"),
    1.47 +
    1.48 +  _xpcom_factory: XPCOMUtils.generateSingletonFactory(DownloadsStartup),
    1.49 +
    1.50 +  //////////////////////////////////////////////////////////////////////////////
    1.51 +  //// nsISupports
    1.52 +
    1.53 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    1.54 +
    1.55 +  //////////////////////////////////////////////////////////////////////////////
    1.56 +  //// nsIObserver
    1.57 +
    1.58 +  observe: function DS_observe(aSubject, aTopic, aData)
    1.59 +  {
    1.60 +    if (aTopic != "profile-after-change") {
    1.61 +      Cu.reportError("Unexpected observer notification.");
    1.62 +      return;
    1.63 +    }
    1.64 +
    1.65 +    // Override Toolkit's nsIDownloadManagerUI implementation with our own.
    1.66 +    // This must be done at application startup and not in the manifest to
    1.67 +    // ensure that our implementation overrides the original one.
    1.68 +    Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
    1.69 +                      .registerFactory(kDownloadsUICid, "",
    1.70 +                                       kDownloadsUIContractId, null);
    1.71 +
    1.72 +    // Override Toolkit's nsITransfer implementation with the one from the
    1.73 +    // JavaScript API for downloads.
    1.74 +    Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
    1.75 +                      .registerFactory(kTransferCid, "",
    1.76 +                                       kTransferContractId, null);
    1.77 +  },
    1.78 +};
    1.79 +
    1.80 +////////////////////////////////////////////////////////////////////////////////
    1.81 +//// Module
    1.82 +
    1.83 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadsStartup]);

mercurial