From 12c596dbeeefd70a7e5aa3f681e703ae5b1fb9da Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Fri, 30 Nov 2007 22:49:07 -0800 Subject: [PATCH] Bug 393303 - "Create a blocked string for dirty downloads (virus scan failed)." [p=comrade693+bmo@gmail.com (Shawn Wilsher [sdwilsh]) r=gavin a=blocking-firefox3+] --- .../downloads/public/nsIDownloadManager.idl | 1 + .../downloads/src/nsDownloadManager.cpp | 20 +++++++--- .../downloads/src/nsDownloadScanner.cpp | 2 +- .../mozapps/downloads/downloads.properties | 1 + .../content/DownloadProgressListener.js | 1 + .../mozapps/downloads/content/download.xml | 39 +++++++++++++------ .../mozapps/downloads/content/downloads.css | 4 ++ .../mozapps/downloads/content/downloads.js | 12 +++++- 8 files changed, 60 insertions(+), 20 deletions(-) diff --git a/toolkit/components/downloads/public/nsIDownloadManager.idl b/toolkit/components/downloads/public/nsIDownloadManager.idl index a6d73fcfa90..e5e05e582fa 100644 --- a/toolkit/components/downloads/public/nsIDownloadManager.idl +++ b/toolkit/components/downloads/public/nsIDownloadManager.idl @@ -62,6 +62,7 @@ interface nsIDownloadManager : nsISupports { const short DOWNLOAD_QUEUED = 5; const short DOWNLOAD_BLOCKED = 6; const short DOWNLOAD_SCANNING = 7; + const short DOWNLOAD_DIRTY = 8; const short DOWNLOAD_TYPE_DOWNLOAD = 0; diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index d9062cdfc1c..467291c054a 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -1372,6 +1372,7 @@ nsDownloadManager::RetryDownload(PRUint32 aID) // if our download is not canceled or failed, we should fail if (dl->mDownloadState != nsIDownloadManager::DOWNLOAD_FAILED && dl->mDownloadState != nsIDownloadManager::DOWNLOAD_BLOCKED && + dl->mDownloadState != nsIDownloadManager::DOWNLOAD_DIRTY && dl->mDownloadState != nsIDownloadManager::DOWNLOAD_CANCELED) return NS_ERROR_FAILURE; @@ -1445,7 +1446,8 @@ nsDownloadManager::CleanUp() DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED, nsIDownloadManager::DOWNLOAD_FAILED, nsIDownloadManager::DOWNLOAD_CANCELED, - nsIDownloadManager::DOWNLOAD_BLOCKED }; + nsIDownloadManager::DOWNLOAD_BLOCKED, + nsIDownloadManager::DOWNLOAD_DIRTY }; nsCOMPtr stmt; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( @@ -1453,9 +1455,10 @@ nsDownloadManager::CleanUp() "WHERE state = ?1 " "OR state = ?2 " "OR state = ?3 " - "OR state = ?4"), getter_AddRefs(stmt)); + "OR state = ?4 " + "OR state = ?5"), getter_AddRefs(stmt)); NS_ENSURE_SUCCESS(rv, rv); - for (PRUint32 i = 0; i < 4; ++i) { + for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(states); ++i) { rv = stmt->BindInt32Parameter(i, states[i]); NS_ENSURE_SUCCESS(rv, rv); } @@ -1477,7 +1480,8 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult) DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED, nsIDownloadManager::DOWNLOAD_FAILED, nsIDownloadManager::DOWNLOAD_CANCELED, - nsIDownloadManager::DOWNLOAD_BLOCKED }; + nsIDownloadManager::DOWNLOAD_BLOCKED, + nsIDownloadManager::DOWNLOAD_DIRTY }; nsCOMPtr stmt; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( @@ -1486,9 +1490,10 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult) "WHERE state = ?1 " "OR state = ?2 " "OR state = ?3 " - "OR state = ?4"), getter_AddRefs(stmt)); + "OR state = ?4 " + "OR state = ?5"), getter_AddRefs(stmt)); NS_ENSURE_SUCCESS(rv, rv); - for (PRUint32 i = 0; i < 4; ++i) { + for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(states); ++i) { rv = stmt->BindInt32Parameter(i, states[i]); NS_ENSURE_SUCCESS(rv, rv); } @@ -1752,6 +1757,7 @@ nsDownload::SetState(DownloadState aState) // dispatch to the observers as well. switch (aState) { case nsIDownloadManager::DOWNLOAD_BLOCKED: + case nsIDownloadManager::DOWNLOAD_DIRTY: case nsIDownloadManager::DOWNLOAD_CANCELED: case nsIDownloadManager::DOWNLOAD_FAILED: // Transfers are finished, so break the reference cycle @@ -1883,6 +1889,8 @@ nsDownload::SetState(DownloadState aState) case nsIDownloadManager::DOWNLOAD_BLOCKED: mDownloadManager->SendEvent(this, "dl-blocked"); break; + case nsIDownloadManager::DOWNLOAD_DIRTY: + mDownloadManager->SendEvent(this, "dl-dirty"); default: break; } diff --git a/toolkit/components/downloads/src/nsDownloadScanner.cpp b/toolkit/components/downloads/src/nsDownloadScanner.cpp index 87726d20083..4c196d9eaab 100644 --- a/toolkit/components/downloads/src/nsDownloadScanner.cpp +++ b/toolkit/components/downloads/src/nsDownloadScanner.cpp @@ -225,7 +225,7 @@ nsDownloadScanner::Scan::Run() DownloadState downloadState = 0; switch (mStatus) { case AVSCAN_BAD: - downloadState = nsIDownloadManager::DOWNLOAD_BLOCKED; + downloadState = nsIDownloadManager::DOWNLOAD_DIRTY; break; default: case AVSCAN_FAILED: diff --git a/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties b/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties index 96596071847..1cb662dbab4 100644 --- a/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties +++ b/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties @@ -66,6 +66,7 @@ stateFailed=Failed stateCanceled=Canceled # LOCALIZATION NOTE (stateBlocked): 'Parental Controls' should be capitalized stateBlocked=Blocked by Parental Controls +stateDirty=Blocked: Download may contain a virus or spyware fileDoesNotExistOpenTitle=Cannot Open %S fileDoesNotExistShowTitle=Cannot Show %S diff --git a/toolkit/mozapps/downloads/content/DownloadProgressListener.js b/toolkit/mozapps/downloads/content/DownloadProgressListener.js index 0f392f4275f..a79ed9aef26 100644 --- a/toolkit/mozapps/downloads/content/DownloadProgressListener.js +++ b/toolkit/mozapps/downloads/content/DownloadProgressListener.js @@ -70,6 +70,7 @@ DownloadProgressListener.prototype = { case nsIDM.DOWNLOAD_FAILED: case nsIDM.DOWNLOAD_CANCELED: case nsIDM.DOWNLOAD_BLOCKED: + case nsIDM.DOWNLOAD_DIRTY: case nsIDM.DOWNLOAD_FINISHED: downloadCompleted(aDownload); if (state == nsIDM.DOWNLOAD_FINISHED) diff --git a/toolkit/mozapps/downloads/content/download.xml b/toolkit/mozapps/downloads/content/download.xml index b618450c72b..17bc3742ef5 100644 --- a/toolkit/mozapps/downloads/content/download.xml +++ b/toolkit/mozapps/downloads/content/download.xml @@ -89,17 +89,7 @@ return state == dl.DOWNLOAD_FINISHED || state == dl.DOWNLOAD_CANCELED || state == dl.DOWNLOAD_BLOCKED || - state == dl.DOWNLOAD_FAILED; - ]]> - - - - - @@ -319,4 +309,31 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/toolkit/mozapps/downloads/content/downloads.css b/toolkit/mozapps/downloads/content/downloads.css index f70d46dd35e..0723ae638ed 100644 --- a/toolkit/mozapps/downloads/content/downloads.css +++ b/toolkit/mozapps/downloads/content/downloads.css @@ -31,6 +31,10 @@ richlistitem[type="download"][state="7"] { -moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-scanning'); } +richlistitem[type="download"][state="8"] { + -moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-dirty'); +} + /* Only focus buttons in the selected item*/ richlistitem[type="download"]:not([selected="true"]) button { -moz-user-focus: none; diff --git a/toolkit/mozapps/downloads/content/downloads.js b/toolkit/mozapps/downloads/content/downloads.js index 5f1bd907254..870dcc4bd6a 100644 --- a/toolkit/mozapps/downloads/content/downloads.js +++ b/toolkit/mozapps/downloads/content/downloads.js @@ -91,6 +91,7 @@ let gStr = { stateFailed: "stateFailed", stateCanceled: "stateCanceled", stateBlocked: "stateBlocked", + stateDirty: "stateDirty", units: ["bytes", "kilobyte", "megabyte", "gigabyte"], @@ -304,6 +305,7 @@ function onDownloadDblClick(aEvent) break; case nsIDM.DOWNLOAD_CANCELED: case nsIDM.DOWNLOAD_BLOCKED: + case nsIDM.DOWNLOAD_DIRTY: case nsIDM.DOWNLOAD_FAILED: gDownloadViewController.doCommand("cmd_retry"); break; @@ -538,7 +540,10 @@ var gContextMenus = [ ["menuitem_retry", "menuitem_removeFromList", "menuitem_clearList", "menuseparator_copy_location", "menuitem_copyLocation"], // DOWNLOAD_SCANNING - ["menuitem_copyLocation"] + ["menuitem_copyLocation"], + // DOWNLOAD_DIRTY + ["menuitem_retry", "menuitem_removeFromList", "menuitem_clearList", + "menuseparator_copy_location", "menuitem_copyLocation"] ]; function buildContextMenu(aEvent) @@ -831,6 +836,7 @@ function updateStatus(aItem, aDownload) { case nsIDM.DOWNLOAD_FAILED: case nsIDM.DOWNLOAD_CANCELED: case nsIDM.DOWNLOAD_BLOCKED: + case nsIDM.DOWNLOAD_DIRTY: let (stateSize = {}) { stateSize[nsIDM.DOWNLOAD_FINISHED] = function() { // Display the file size, but show "Unknown" for negative sizes @@ -846,6 +852,7 @@ function updateStatus(aItem, aDownload) { stateSize[nsIDM.DOWNLOAD_FAILED] = function() gStr.stateFailed; stateSize[nsIDM.DOWNLOAD_CANCELED] = function() gStr.stateCanceled; stateSize[nsIDM.DOWNLOAD_BLOCKED] = function() gStr.stateBlocked; + stateSize[nsIDM.DOWNLOAD_DIRTY] = function() gStr.stateDirty; // Insert 1 is the download size or download state status = replaceInsert(gStr.doneStatus, 1, stateSize[state]()); @@ -1075,7 +1082,7 @@ function buildDownloadListWithTime(aTime) var stmt = gDownloadListWithTimeQuery; if (!stmt) { stmt = db.createStatement(replaceInsert(gBaseQuery, 1, "startTime >= ?1 " + - "AND (state = ?2 OR state = ?3 OR state = ?4 OR state = ?5)")); + "AND (state = ?2 OR state = ?3 OR state = ?4 OR state = ?5 OR state = ?6)")); gDownloadListWithTimeQuery = stmt; } @@ -1085,6 +1092,7 @@ function buildDownloadListWithTime(aTime) stmt.bindInt32Parameter(2, nsIDM.DOWNLOAD_FAILED); stmt.bindInt32Parameter(3, nsIDM.DOWNLOAD_CANCELED); stmt.bindInt32Parameter(4, nsIDM.DOWNLOAD_BLOCKED); + stmt.bindInt32Parameter(5, nsIDM.DOWNLOAD_DIRTY); buildDownloadList(stmt, gDownloadsDoneArea); } finally { stmt.reset();