browser/components/downloads/src/DownloadsStartup.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8  * This component enables the JavaScript API for downloads at startup.  This
     9  * will eventually be removed when nsIDownloadManager will not be available
    10  * anymore (bug 851471).
    11  */
    13 "use strict";
    15 ////////////////////////////////////////////////////////////////////////////////
    16 //// Globals
    18 const Cc = Components.classes;
    19 const Ci = Components.interfaces;
    20 const Cu = Components.utils;
    21 const Cr = Components.results;
    23 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    25 /**
    26  * CID and Contract ID of our implementation of nsIDownloadManagerUI.
    27  */
    28 const kDownloadsUICid = Components.ID("{4d99321e-d156-455b-81f7-e7aa2308134f}");
    29 const kDownloadsUIContractId = "@mozilla.org/download-manager-ui;1";
    31 /**
    32  * CID and Contract ID of the JavaScript implementation of nsITransfer.
    33  */
    34 const kTransferCid = Components.ID("{1b4c85df-cbdd-4bb6-b04e-613caece083c}");
    35 const kTransferContractId = "@mozilla.org/transfer;1";
    37 ////////////////////////////////////////////////////////////////////////////////
    38 //// DownloadsStartup
    40 function DownloadsStartup() { }
    42 DownloadsStartup.prototype = {
    43   classID: Components.ID("{49507fe5-2cee-4824-b6a3-e999150ce9b8}"),
    45   _xpcom_factory: XPCOMUtils.generateSingletonFactory(DownloadsStartup),
    47   //////////////////////////////////////////////////////////////////////////////
    48   //// nsISupports
    50   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    52   //////////////////////////////////////////////////////////////////////////////
    53   //// nsIObserver
    55   observe: function DS_observe(aSubject, aTopic, aData)
    56   {
    57     if (aTopic != "profile-after-change") {
    58       Cu.reportError("Unexpected observer notification.");
    59       return;
    60     }
    62     // Override Toolkit's nsIDownloadManagerUI implementation with our own.
    63     // This must be done at application startup and not in the manifest to
    64     // ensure that our implementation overrides the original one.
    65     Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
    66                       .registerFactory(kDownloadsUICid, "",
    67                                        kDownloadsUIContractId, null);
    69     // Override Toolkit's nsITransfer implementation with the one from the
    70     // JavaScript API for downloads.
    71     Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
    72                       .registerFactory(kTransferCid, "",
    73                                        kTransferContractId, null);
    74   },
    75 };
    77 ////////////////////////////////////////////////////////////////////////////////
    78 //// Module
    80 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadsStartup]);

mercurial