Bug 416683 - binary downloads are deleted on completion when "Launch applications and unsafe files" is disabled. p=jmathies, r=Mardak, r=robarnold, sr=bsmedberg, a1.9b5=beltzner, b-ff3=beltzner

This commit is contained in:
edward.lee@engineering.uiuc.edu 2008-03-21 17:23:45 -07:00
Родитель cc1584f460
Коммит 711e95aa2b
13 изменённых файлов: 221 добавлений и 39 удалений

Просмотреть файл

@ -49,10 +49,13 @@ interface nsIMIMEInfo;
* Represents a download object.
*
* @note This object is no longer updated once it enters a completed state.
* Completed states are the following:
* nsIDownloadManager::DOWNLOAD_FINISHED
* nsIDownloadManager::DOWNLOAD_FAILED
* nsIDownloadManager::DOWNLOAD_CANCELED
* Completed states are the following:
* nsIDownloadManager::DOWNLOAD_FINISHED
* nsIDownloadManager::DOWNLOAD_FAILED
* nsIDownloadManager::DOWNLOAD_CANCELED
* nsIDownloadManager::DOWNLOAD_BLOCKED_PARENTAL
* nsIDownloadManager::DOWNLOAD_DIRTY
* nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY
*/
[scriptable, uuid(c891111e-92a6-47b8-bc46-874ebb61ac9d)]
interface nsIDownload : nsITransfer {

Просмотреть файл

@ -50,21 +50,71 @@ interface nsIDownloadProgressListener;
interface nsISimpleEnumerator;
interface mozIStorageConnection;
[scriptable, uuid(05ed1d45-0aff-4ba0-9e2c-a9ef20383048)]
[scriptable, uuid(88a2df08-47f7-4268-bb16-81bab231f1bf)]
interface nsIDownloadManager : nsISupports {
// Download States
const short DOWNLOAD_NOTSTARTED = -1;
const short DOWNLOAD_DOWNLOADING = 0;
const short DOWNLOAD_FINISHED = 1;
const short DOWNLOAD_FAILED = 2;
const short DOWNLOAD_CANCELED = 3;
const short DOWNLOAD_PAUSED = 4;
const short DOWNLOAD_QUEUED = 5;
const short DOWNLOAD_BLOCKED = 6;
const short DOWNLOAD_SCANNING = 7;
const short DOWNLOAD_DIRTY = 8;
/**
* Download type for generic file download.
*/
const short DOWNLOAD_TYPE_DOWNLOAD = 0;
/**
* Download state for uninitialized download object.
*/
const short DOWNLOAD_NOTSTARTED = -1;
/**
* Download is currently transferring data.
*/
const short DOWNLOAD_DOWNLOADING = 0;
/**
* Download completed including any processing of the target
* file. (completed)
*/
const short DOWNLOAD_FINISHED = 1;
/**
* Transfer failed due to error. (completed)
*/
const short DOWNLOAD_FAILED = 2;
/**
* Download was canceled by the user. (completed)
*/
const short DOWNLOAD_CANCELED = 3;
/**
* Transfer was paused by the user.
*/
const short DOWNLOAD_PAUSED = 4;
/**
* Download is active but data has not yet been received.
*/
const short DOWNLOAD_QUEUED = 5;
/**
* Transfer request was blocked by parental controls proxies. (completed)
*/
const short DOWNLOAD_BLOCKED_PARENTAL = 6;
/**
* Transferred download is being scanned by virus scanners.
*/
const short DOWNLOAD_SCANNING = 7;
/**
* A virus was detected in the download. The target will most likely
* no longer exist. (completed)
*/
const short DOWNLOAD_DIRTY = 8;
/**
* Win specific: Request was blocked by zone policy settings.
* (see bug #416683) (completed)
*/
const short DOWNLOAD_BLOCKED_POLICY = 9;
const short DOWNLOAD_TYPE_DOWNLOAD = 0;
/**
* Creates an nsIDownload and adds it to be managed by the download manager.

Просмотреть файл

@ -1372,6 +1372,19 @@ nsDownloadManager::AddDownload(DownloadType aDownloadType,
(void)aMIMEInfo->GetPreferredAction(&action);
}
DownloadState startState = nsIDownloadManager::DOWNLOAD_QUEUED;
#if defined(XP_WIN) && !defined(__MINGW32__) && !defined(WINCE)
if (mScanner) {
AVCheckPolicyState res = mScanner->CheckPolicy(source, target);
if (res == AVPOLICY_BLOCKED) {
// This download will get deleted during a call to IAE's Save,
// so go ahead and mark it as blocked and avoid the download.
(void)dl->Cancel();
startState = nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY;
}
}
#endif
PRInt64 id = AddDownloadToDB(dl->mDisplayName, source, target, tempPath,
dl->mStartTime, dl->mLastUpdate,
nsIDownloadManager::DOWNLOAD_NOTSTARTED,
@ -1380,7 +1393,7 @@ nsDownloadManager::AddDownload(DownloadType aDownloadType,
dl->mID = id;
rv = AddToCurrentDownloads(dl);
(void)dl->SetState(nsIDownloadManager::DOWNLOAD_QUEUED);
(void)dl->SetState(startState);
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(*aDownload = dl);
@ -1467,7 +1480,8 @@ 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_BLOCKED_PARENTAL &&
dl->mDownloadState != nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY &&
dl->mDownloadState != nsIDownloadManager::DOWNLOAD_DIRTY &&
dl->mDownloadState != nsIDownloadManager::DOWNLOAD_CANCELED)
return NS_ERROR_FAILURE;
@ -1542,7 +1556,8 @@ nsDownloadManager::CleanUp()
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED,
nsIDownloadManager::DOWNLOAD_FAILED,
nsIDownloadManager::DOWNLOAD_CANCELED,
nsIDownloadManager::DOWNLOAD_BLOCKED,
nsIDownloadManager::DOWNLOAD_BLOCKED_PARENTAL,
nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY,
nsIDownloadManager::DOWNLOAD_DIRTY };
nsCOMPtr<mozIStorageStatement> stmt;
@ -1552,7 +1567,8 @@ nsDownloadManager::CleanUp()
"OR state = ?2 "
"OR state = ?3 "
"OR state = ?4 "
"OR state = ?5"), getter_AddRefs(stmt));
"OR state = ?5 "
"OR state = ?6"), getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(states); ++i) {
rv = stmt->BindInt32Parameter(i, states[i]);
@ -1589,7 +1605,8 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult)
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED,
nsIDownloadManager::DOWNLOAD_FAILED,
nsIDownloadManager::DOWNLOAD_CANCELED,
nsIDownloadManager::DOWNLOAD_BLOCKED,
nsIDownloadManager::DOWNLOAD_BLOCKED_PARENTAL,
nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY,
nsIDownloadManager::DOWNLOAD_DIRTY };
nsCOMPtr<mozIStorageStatement> stmt;
@ -1600,7 +1617,8 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult)
"OR state = ?2 "
"OR state = ?3 "
"OR state = ?4 "
"OR state = ?5"), getter_AddRefs(stmt));
"OR state = ?5 "
"OR state = ?6"), getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(states); ++i) {
rv = stmt->BindInt32Parameter(i, states[i]);
@ -1894,7 +1912,8 @@ nsDownload::SetState(DownloadState aState)
// the database *before* notifying listeners. At this point, you can safely
// dispatch to the observers as well.
switch (aState) {
case nsIDownloadManager::DOWNLOAD_BLOCKED:
case nsIDownloadManager::DOWNLOAD_BLOCKED_PARENTAL:
case nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY:
case nsIDownloadManager::DOWNLOAD_DIRTY:
case nsIDownloadManager::DOWNLOAD_CANCELED:
case nsIDownloadManager::DOWNLOAD_FAILED:
@ -2024,7 +2043,8 @@ nsDownload::SetState(DownloadState aState)
case nsIDownloadManager::DOWNLOAD_FINISHED:
mDownloadManager->SendEvent(this, "dl-done");
break;
case nsIDownloadManager::DOWNLOAD_BLOCKED:
case nsIDownloadManager::DOWNLOAD_BLOCKED_PARENTAL:
case nsIDownloadManager::DOWNLOAD_BLOCKED_POLICY:
mDownloadManager->SendEvent(this, "dl-blocked");
break;
case nsIDownloadManager::DOWNLOAD_DIRTY:
@ -2182,8 +2202,8 @@ nsDownload::OnStateChange(nsIWebProgress *aWebProgress,
// Cancel using the provided object
(void)Cancel();
// Fail the download - DOWNLOAD_BLOCKED
(void)SetState(nsIDownloadManager::DOWNLOAD_BLOCKED);
// Fail the download
(void)SetState(nsIDownloadManager::DOWNLOAD_BLOCKED_PARENTAL);
}
}
} else if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_NETWORK) &&

Просмотреть файл

@ -81,7 +81,7 @@ public:
PRBool showDM = PR_TRUE;
if (branch)
branch->GetBoolPref(PREF_BDM_SHOWWHENSTARTING , &showDM);
branch->GetBoolPref(PREF_BDM_SHOWWHENSTARTING, &showDM);
PRBool useWindow = PR_TRUE;
if (branch)

Просмотреть файл

@ -259,6 +259,42 @@ nsDownloadScanner::ListCLSID()
return 0;
}
// If IAttachementExecute is available, use the CheckPolicy call to find out
// if this download should be prevented due to Internet Zone Policy settings.
AVCheckPolicyState
nsDownloadScanner::CheckPolicy(const nsACString &aSource, const nsACString &aTarget)
{
if (aSource.IsEmpty())
return AVPOLICY_DOWNLOAD;
if (!mHaveAttachmentExecute)
return AVPOLICY_DOWNLOAD;
nsRefPtr<IAttachmentExecute> ae;
HRESULT hr;
hr = CoCreateInstance(CLSID_AttachmentServices, NULL, CLSCTX_INPROC,
IID_IAttachmentExecute, getter_AddRefs(ae));
if (FAILED(hr))
return AVPOLICY_DOWNLOAD;
(void)ae->SetClientGuid(GUID_MozillaVirusScannerPromptGeneric);
(void)ae->SetSource(NS_ConvertUTF8toUTF16(aSource).get());
if (!aTarget.IsEmpty())
(void)ae->SetLocalPath(NS_ConvertUTF8toUTF16(aTarget).get());
// Any failure means the file download/exec will be blocked by the system.
// S_OK or S_FALSE imply it's ok.
hr = ae->CheckPolicy();
if (hr == S_OK)
return AVPOLICY_DOWNLOAD;
if (hr == S_FALSE)
return AVPOLICY_PROMPT;
return AVPOLICY_BLOCKED;
}
#ifndef THREAD_MODE_BACKGROUND_BEGIN
#define THREAD_MODE_BACKGROUND_BEGIN 0x00010000
#endif

Просмотреть файл

@ -33,6 +33,14 @@ enum AVScanState
AVSCAN_TIMEDOUT
};
enum AVCheckPolicyState
{
AVPOLICY_DOWNLOAD,
AVPOLICY_PROMPT,
AVPOLICY_BLOCKED
};
// See nsDownloadScanner.cpp for declaration and definition
class nsDownloadScannerWatchdog;
@ -43,6 +51,7 @@ public:
~nsDownloadScanner();
nsresult Init();
nsresult ScanDownload(nsDownload *download);
AVCheckPolicyState CheckPolicy(const nsACString &aSource, const nsACString &aTarget);
private:
PRBool mHaveAVScanner;

Просмотреть файл

@ -68,9 +68,14 @@ DownloadProgressListener.prototype = {
case nsIDM.DOWNLOAD_QUEUED:
prependList(aDownload);
break;
case nsIDM.DOWNLOAD_BLOCKED_POLICY:
prependList(aDownload);
// Should fall through, this is a final state but DOWNLOAD_QUEUED
// is skipped. See nsDownloadManager::AddDownload.
case nsIDM.DOWNLOAD_FAILED:
case nsIDM.DOWNLOAD_CANCELED:
case nsIDM.DOWNLOAD_BLOCKED:
case nsIDM.DOWNLOAD_BLOCKED_PARENTAL:
case nsIDM.DOWNLOAD_DIRTY:
case nsIDM.DOWNLOAD_FINISHED:
downloadCompleted(aDownload);

Просмотреть файл

@ -90,7 +90,8 @@
const dl = Components.interfaces.nsIDownloadManager;
return state == dl.DOWNLOAD_FINISHED ||
state == dl.DOWNLOAD_CANCELED ||
state == dl.DOWNLOAD_BLOCKED ||
state == dl.DOWNLOAD_BLOCKED_PARENTAL ||
state == dl.DOWNLOAD_BLOCKED_POLICY ||
state == dl.DOWNLOAD_DIRTY ||
state == dl.DOWNLOAD_FAILED;
]]>
@ -272,7 +273,29 @@
</content>
</binding>
<binding id="download-blocked" extends="chrome://mozapps/content/downloads/download.xml#download-base">
<binding id="download-blocked-parental" extends="chrome://mozapps/content/downloads/download.xml#download-base">
<content>
<xul:hbox flex="1">
<xul:vbox pack="center">
<xul:image class="downloadTypeIcon blockedIcon"/>
</xul:vbox>
<xul:vbox pack="start" flex="1">
<xul:hbox align="center" flex="1">
<xul:label xbl:inherits="value=target,tooltiptext=target"
crop="center" flex="1" class="name"/>
<xul:label xbl:inherits="value=dateTime,tooltiptext=dateTimeTip"
class="dateTime"/>
</xul:hbox>
<xul:hbox align="center" flex="1">
<xul:label xbl:inherits="value=status,tooltiptext=statusTip"
crop="end" flex="1" class="status"/>
</xul:hbox>
</xul:vbox>
</xul:hbox>
</content>
</binding>
<binding id="download-blocked-policy" extends="chrome://mozapps/content/downloads/download.xml#download-base">
<content>
<xul:hbox flex="1">
<xul:vbox pack="center">

Просмотреть файл

@ -24,7 +24,7 @@ richlistitem[type="download"][state="4"] {
}
richlistitem[type="download"][state="6"] {
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-blocked');
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-blocked-parental');
}
richlistitem[type="download"][state="7"] {
@ -35,6 +35,10 @@ richlistitem[type="download"][state="8"] {
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-dirty');
}
richlistitem[type="download"][state="9"] {
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-blocked-policy');
}
/* Only focus buttons in the selected item*/
richlistitem[type="download"]:not([selected="true"]) button {
-moz-user-focus: none;

Просмотреть файл

@ -94,7 +94,8 @@ let gStr = {
doneSizeUnknown: "doneSizeUnknown",
stateFailed: "stateFailed",
stateCanceled: "stateCanceled",
stateBlocked: "stateBlocked",
stateBlockedParentalControls: "stateBlocked",
stateBlockedPolicy: "stateDirty",
stateDirty: "stateDirty",
yesterday: "yesterday",
monthDate: "monthDate",
@ -520,7 +521,7 @@ var gContextMenus = [
, "menuitem_openReferrer"
, "menuitem_copyLocation"
],
// DOWNLOAD_BLOCKED
// DOWNLOAD_BLOCKED_PARENTAL
[
"menuitem_openReferrer"
, "menuitem_copyLocation"
@ -536,6 +537,14 @@ var gContextMenus = [
, "menuitem_copyLocation"
],
// DOWNLOAD_DIRTY
[
"menuitem_openReferrer"
, "menuitem_copyLocation"
, "menuseparator"
, "menuitem_removeFromList"
, "menuitem_clearList"
],
// DOWNLOAD_BLOCKED_POLICY
[
"menuitem_openReferrer"
, "menuitem_copyLocation"
@ -864,7 +873,8 @@ function updateStatus(aItem, aDownload) {
case nsIDM.DOWNLOAD_FINISHED:
case nsIDM.DOWNLOAD_FAILED:
case nsIDM.DOWNLOAD_CANCELED:
case nsIDM.DOWNLOAD_BLOCKED:
case nsIDM.DOWNLOAD_BLOCKED_PARENTAL:
case nsIDM.DOWNLOAD_BLOCKED_POLICY:
case nsIDM.DOWNLOAD_DIRTY:
{
let (stateSize = {}) {
@ -881,7 +891,8 @@ 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_BLOCKED_PARENTAL] = function() gStr.stateBlockedParentalControls;
stateSize[nsIDM.DOWNLOAD_BLOCKED_POLICY] = function() gStr.stateBlockedPolicy;
stateSize[nsIDM.DOWNLOAD_DIRTY] = function() gStr.stateDirty;
// Insert 1 is the download size or download state

Просмотреть файл

@ -106,7 +106,7 @@ const DownloadData = [
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859231,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
@ -114,6 +114,13 @@ const DownloadData = [
startTime: 1180493839859230,
endTime: 1180493839859230,
state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859231,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];

Просмотреть файл

@ -69,7 +69,7 @@ const DownloadData = [
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859232,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
@ -77,6 +77,13 @@ const DownloadData = [
startTime: 1180493839859230,
endTime: 1180493839859230,
state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859231,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];

Просмотреть файл

@ -69,7 +69,7 @@ const DownloadData = [
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859232,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
@ -77,6 +77,13 @@ const DownloadData = [
startTime: 1180493839859230,
endTime: 1180493839859230,
state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859231,
state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];