browser/components/downloads/src/DownloadsStartup.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:9bae59029d6e
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/. */
6
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 */
12
13 "use strict";
14
15 ////////////////////////////////////////////////////////////////////////////////
16 //// Globals
17
18 const Cc = Components.classes;
19 const Ci = Components.interfaces;
20 const Cu = Components.utils;
21 const Cr = Components.results;
22
23 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
24
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";
30
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";
36
37 ////////////////////////////////////////////////////////////////////////////////
38 //// DownloadsStartup
39
40 function DownloadsStartup() { }
41
42 DownloadsStartup.prototype = {
43 classID: Components.ID("{49507fe5-2cee-4824-b6a3-e999150ce9b8}"),
44
45 _xpcom_factory: XPCOMUtils.generateSingletonFactory(DownloadsStartup),
46
47 //////////////////////////////////////////////////////////////////////////////
48 //// nsISupports
49
50 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
51
52 //////////////////////////////////////////////////////////////////////////////
53 //// nsIObserver
54
55 observe: function DS_observe(aSubject, aTopic, aData)
56 {
57 if (aTopic != "profile-after-change") {
58 Cu.reportError("Unexpected observer notification.");
59 return;
60 }
61
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);
68
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 };
76
77 ////////////////////////////////////////////////////////////////////////////////
78 //// Module
79
80 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DownloadsStartup]);

mercurial