michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * This component enables the JavaScript API for downloads at startup. This michael@0: * will eventually be removed when nsIDownloadManager will not be available michael@0: * anymore (bug 851471). michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Globals michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: const Cr = Components.results; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: /** michael@0: * CID and Contract ID of our implementation of nsIDownloadManagerUI. michael@0: */ michael@0: const kDownloadsUICid = Components.ID("{4d99321e-d156-455b-81f7-e7aa2308134f}"); michael@0: const kDownloadsUIContractId = "@mozilla.org/download-manager-ui;1"; michael@0: michael@0: /** michael@0: * CID and Contract ID of the JavaScript implementation of nsITransfer. michael@0: */ michael@0: const kTransferCid = Components.ID("{1b4c85df-cbdd-4bb6-b04e-613caece083c}"); michael@0: const kTransferContractId = "@mozilla.org/transfer;1"; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// DownloadsStartup michael@0: michael@0: function DownloadsStartup() { } michael@0: michael@0: DownloadsStartup.prototype = { michael@0: classID: Components.ID("{49507fe5-2cee-4824-b6a3-e999150ce9b8}"), michael@0: michael@0: _xpcom_factory: XPCOMUtils.generateSingletonFactory(DownloadsStartup), michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsISupports michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsIObserver michael@0: michael@0: observe: function DS_observe(aSubject, aTopic, aData) michael@0: { michael@0: if (aTopic != "profile-after-change") { michael@0: Cu.reportError("Unexpected observer notification."); michael@0: return; michael@0: } michael@0: michael@0: // Override Toolkit's nsIDownloadManagerUI implementation with our own. michael@0: // This must be done at application startup and not in the manifest to michael@0: // ensure that our implementation overrides the original one. michael@0: Components.manager.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .registerFactory(kDownloadsUICid, "", michael@0: kDownloadsUIContractId, null); michael@0: michael@0: // Override Toolkit's nsITransfer implementation with the one from the michael@0: // JavaScript API for downloads. michael@0: Components.manager.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .registerFactory(kTransferCid, "", michael@0: kTransferContractId, null); michael@0: }, michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Module michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadsStartup]);