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