browser/components/downloads/src/DownloadsStartup.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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

mercurial