зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1281186 - Remove uses of nsIDownloadManager from DownloadsCommon.jsm, DownloadsViewUI.jsm, and allDownloadsViewOverlay.js. r=mak
MozReview-Commit-ID: 28nc8aTea5v --HG-- extra : rebase_source : 0fe2e78104e727488930b07c8c5a64ccc4274614
This commit is contained in:
Родитель
d0ac8577e3
Коммит
5c2404b2f6
|
@ -71,8 +71,6 @@ XPCOMUtils.defineLazyGetter(this, "DownloadsLogger", () => {
|
|||
return new ConsoleAPI(consoleOptions);
|
||||
});
|
||||
|
||||
const nsIDM = Ci.nsIDownloadManager;
|
||||
|
||||
const kDownloadsStringBundleUrl =
|
||||
"chrome://browser/locale/downloads/downloads.properties";
|
||||
|
||||
|
@ -139,6 +137,19 @@ PrefObserver.register({
|
|||
* and provides shared methods for all the instances of the user interface.
|
||||
*/
|
||||
this.DownloadsCommon = {
|
||||
// The following legacy constants are still returned by stateOfDownload, but
|
||||
// individual properties of the Download object should normally be used.
|
||||
DOWNLOAD_NOTSTARTED: -1,
|
||||
DOWNLOAD_DOWNLOADING: 0,
|
||||
DOWNLOAD_FINISHED: 1,
|
||||
DOWNLOAD_FAILED: 2,
|
||||
DOWNLOAD_CANCELED: 3,
|
||||
DOWNLOAD_PAUSED: 4,
|
||||
DOWNLOAD_BLOCKED_PARENTAL: 6,
|
||||
DOWNLOAD_DIRTY: 8,
|
||||
DOWNLOAD_BLOCKED_POLICY: 9,
|
||||
|
||||
// The following are the possible values of the "attention" property.
|
||||
ATTENTION_NONE: "",
|
||||
ATTENTION_SUCCESS: "success",
|
||||
ATTENTION_WARNING: "warning",
|
||||
|
@ -297,27 +308,27 @@ this.DownloadsCommon = {
|
|||
stateOfDownload(download) {
|
||||
// Collapse state using the correct priority.
|
||||
if (!download.stopped) {
|
||||
return nsIDM.DOWNLOAD_DOWNLOADING;
|
||||
return DownloadsCommon.DOWNLOAD_DOWNLOADING;
|
||||
}
|
||||
if (download.succeeded) {
|
||||
return nsIDM.DOWNLOAD_FINISHED;
|
||||
return DownloadsCommon.DOWNLOAD_FINISHED;
|
||||
}
|
||||
if (download.error) {
|
||||
if (download.error.becauseBlockedByParentalControls) {
|
||||
return nsIDM.DOWNLOAD_BLOCKED_PARENTAL;
|
||||
return DownloadsCommon.DOWNLOAD_BLOCKED_PARENTAL;
|
||||
}
|
||||
if (download.error.becauseBlockedByReputationCheck) {
|
||||
return nsIDM.DOWNLOAD_DIRTY;
|
||||
return DownloadsCommon.DOWNLOAD_DIRTY;
|
||||
}
|
||||
return nsIDM.DOWNLOAD_FAILED;
|
||||
return DownloadsCommon.DOWNLOAD_FAILED;
|
||||
}
|
||||
if (download.canceled) {
|
||||
if (download.hasPartialData) {
|
||||
return nsIDM.DOWNLOAD_PAUSED;
|
||||
return DownloadsCommon.DOWNLOAD_PAUSED;
|
||||
}
|
||||
return nsIDM.DOWNLOAD_CANCELED;
|
||||
return DownloadsCommon.DOWNLOAD_CANCELED;
|
||||
}
|
||||
return nsIDM.DOWNLOAD_NOTSTARTED;
|
||||
return DownloadsCommon.DOWNLOAD_NOTSTARTED;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -325,18 +325,18 @@ this.DownloadsViewUI.DownloadElementShell.prototype = {
|
|||
*/
|
||||
get currentDefaultCommandName() {
|
||||
switch (DownloadsCommon.stateOfDownload(this.download)) {
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED:
|
||||
case DownloadsCommon.DOWNLOAD_NOTSTARTED:
|
||||
return "downloadsCmd_cancel";
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_FAILED:
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_CANCELED:
|
||||
case DownloadsCommon.DOWNLOAD_FAILED:
|
||||
case DownloadsCommon.DOWNLOAD_CANCELED:
|
||||
return "downloadsCmd_retry";
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_PAUSED:
|
||||
case DownloadsCommon.DOWNLOAD_PAUSED:
|
||||
return "downloadsCmd_pauseResume";
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_FINISHED:
|
||||
case DownloadsCommon.DOWNLOAD_FINISHED:
|
||||
return "downloadsCmd_open";
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL:
|
||||
case DownloadsCommon.DOWNLOAD_BLOCKED_PARENTAL:
|
||||
return "downloadsCmd_openReferrer";
|
||||
case Ci.nsIDownloadManager.DOWNLOAD_DIRTY:
|
||||
case DownloadsCommon.DOWNLOAD_DIRTY:
|
||||
return "downloadsCmd_showBlockedInfo";
|
||||
}
|
||||
return "";
|
||||
|
|
|
@ -30,8 +30,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
const nsIDM = Ci.nsIDownloadManager;
|
||||
|
||||
const DESTINATION_FILE_URI_ANNO = "downloads/destinationFileURI";
|
||||
const DOWNLOAD_META_DATA_ANNO = "downloads/metaData";
|
||||
|
||||
|
@ -72,17 +70,17 @@ HistoryDownload.prototype = {
|
|||
}
|
||||
|
||||
if ("state" in metaData) {
|
||||
this.succeeded = metaData.state == nsIDM.DOWNLOAD_FINISHED;
|
||||
this.canceled = metaData.state == nsIDM.DOWNLOAD_CANCELED ||
|
||||
metaData.state == nsIDM.DOWNLOAD_PAUSED;
|
||||
this.succeeded = metaData.state == DownloadsCommon.DOWNLOAD_FINISHED;
|
||||
this.canceled = metaData.state == DownloadsCommon.DOWNLOAD_CANCELED ||
|
||||
metaData.state == DownloadsCommon.DOWNLOAD_PAUSED;
|
||||
this.endTime = metaData.endTime;
|
||||
|
||||
// Recreate partial error information from the state saved in history.
|
||||
if (metaData.state == nsIDM.DOWNLOAD_FAILED) {
|
||||
if (metaData.state == DownloadsCommon.DOWNLOAD_FAILED) {
|
||||
this.error = { message: "History download failed." };
|
||||
} else if (metaData.state == nsIDM.DOWNLOAD_BLOCKED_PARENTAL) {
|
||||
} else if (metaData.state == DownloadsCommon.DOWNLOAD_BLOCKED_PARENTAL) {
|
||||
this.error = { becauseBlockedByParentalControls: true };
|
||||
} else if (metaData.state == nsIDM.DOWNLOAD_DIRTY) {
|
||||
} else if (metaData.state == DownloadsCommon.DOWNLOAD_DIRTY) {
|
||||
this.error = {
|
||||
becauseBlockedByReputationCheck: true,
|
||||
reputationCheckVerdict: metaData.reputationCheckVerdict || "",
|
||||
|
|
|
@ -14,11 +14,11 @@ registerCleanupFunction(function*() {
|
|||
add_task(function* test_basic_functionality() {
|
||||
// Display one of each download state.
|
||||
const DownloadData = [
|
||||
{ state: nsIDM.DOWNLOAD_NOTSTARTED },
|
||||
{ state: nsIDM.DOWNLOAD_PAUSED },
|
||||
{ state: nsIDM.DOWNLOAD_FINISHED },
|
||||
{ state: nsIDM.DOWNLOAD_FAILED },
|
||||
{ state: nsIDM.DOWNLOAD_CANCELED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_NOTSTARTED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_PAUSED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FINISHED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FAILED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_CANCELED },
|
||||
];
|
||||
|
||||
// Wait for focus first
|
||||
|
|
|
@ -139,7 +139,7 @@ function promisePanelHidden() {
|
|||
|
||||
function makeDownload(verdict) {
|
||||
return {
|
||||
state: nsIDM.DOWNLOAD_DIRTY,
|
||||
state: DownloadsCommon.DOWNLOAD_DIRTY,
|
||||
hasBlockedData: true,
|
||||
errorObj: {
|
||||
result: Components.results.NS_ERROR_FAILURE,
|
||||
|
|
|
@ -34,26 +34,26 @@ add_task(function* test_openDownloadsFolder() {
|
|||
add_task(function* test_clearList() {
|
||||
const kTestCases = [{
|
||||
downloads: [
|
||||
{ state: nsIDM.DOWNLOAD_NOTSTARTED },
|
||||
{ state: nsIDM.DOWNLOAD_FINISHED },
|
||||
{ state: nsIDM.DOWNLOAD_FAILED },
|
||||
{ state: nsIDM.DOWNLOAD_CANCELED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_NOTSTARTED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FINISHED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FAILED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_CANCELED },
|
||||
],
|
||||
expectClearListShown: true,
|
||||
expectedItemNumber: 0,
|
||||
}, {
|
||||
downloads: [
|
||||
{ state: nsIDM.DOWNLOAD_NOTSTARTED },
|
||||
{ state: nsIDM.DOWNLOAD_FINISHED },
|
||||
{ state: nsIDM.DOWNLOAD_FAILED },
|
||||
{ state: nsIDM.DOWNLOAD_PAUSED },
|
||||
{ state: nsIDM.DOWNLOAD_CANCELED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_NOTSTARTED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FINISHED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FAILED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_PAUSED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_CANCELED },
|
||||
],
|
||||
expectClearListShown: true,
|
||||
expectedItemNumber: 1,
|
||||
}, {
|
||||
downloads: [
|
||||
{ state: nsIDM.DOWNLOAD_PAUSED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_PAUSED },
|
||||
],
|
||||
expectClearListShown: false,
|
||||
expectedItemNumber: 1,
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
add_task(function* test_height_reduced_after_removal() {
|
||||
yield task_addDownloads([
|
||||
{ state: nsIDM.DOWNLOAD_FINISHED },
|
||||
{ state: DownloadsCommon.DOWNLOAD_FINISHED },
|
||||
]);
|
||||
|
||||
yield task_openPanel();
|
||||
|
|
|
@ -24,8 +24,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "HttpServer",
|
||||
"resource://testing-common/httpd.js");
|
||||
|
||||
const nsIDM = Ci.nsIDownloadManager;
|
||||
|
||||
var gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
|
||||
gTestTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
|
||||
|
||||
|
@ -163,11 +161,12 @@ function* task_addDownloads(aItems) {
|
|||
target: {
|
||||
path: gTestTargetFile.path,
|
||||
},
|
||||
succeeded: item.state == nsIDM.DOWNLOAD_FINISHED,
|
||||
canceled: item.state == nsIDM.DOWNLOAD_CANCELED ||
|
||||
item.state == nsIDM.DOWNLOAD_PAUSED,
|
||||
error: item.state == nsIDM.DOWNLOAD_FAILED ? new Error("Failed.") : null,
|
||||
hasPartialData: item.state == nsIDM.DOWNLOAD_PAUSED,
|
||||
succeeded: item.state == DownloadsCommon.DOWNLOAD_FINISHED,
|
||||
canceled: item.state == DownloadsCommon.DOWNLOAD_CANCELED ||
|
||||
item.state == DownloadsCommon.DOWNLOAD_PAUSED,
|
||||
error: item.state == DownloadsCommon.DOWNLOAD_FAILED ?
|
||||
new Error("Failed.") : null,
|
||||
hasPartialData: item.state == DownloadsCommon.DOWNLOAD_PAUSED,
|
||||
hasBlockedData: item.hasBlockedData || false,
|
||||
startTime: new Date(startTimeMs++),
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче