Bug 1660969 - Enable unblock UI for mixed-content-blocked Downloads r=Gijs,ckerschb

Differential Revision: https://phabricator.services.mozilla.com/D88721
This commit is contained in:
Sebastian Streich 2020-11-04 13:21:36 +00:00
Родитель efbe927197
Коммит b3da012bd5
6 изменённых файлов: 48 добавлений и 6 удалений

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

@ -1383,6 +1383,7 @@ DownloadsIndicatorDataCtor.prototype = {
switch (download.error.reputationCheckVerdict) {
case Downloads.Error.BLOCK_VERDICT_UNCOMMON: // fall-through
case Downloads.Error.BLOCK_VERDICT_POTENTIALLY_UNWANTED:
case Downloads.Error.BLOCK_VERDICT_INSECURE:
// Existing higher level attention indication trumps ATTENTION_WARNING.
if (this._attention != DownloadsCommon.ATTENTION_SEVERE) {
this.attention = DownloadsCommon.ATTENTION_WARNING;

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

@ -628,7 +628,7 @@ DownloadsViewUI.DownloadElementShell.prototype = {
case Downloads.Error.BLOCK_VERDICT_UNCOMMON:
return [s.blockedUncommon2, [s.unblockTypeUncommon2, s.unblockTip2]];
case Downloads.Error.BLOCK_VERDICT_INSECURE:
return [s.blockedInsecure, [s.blockedInsecure, s.unblockTip2]];
return [s.blockedPotentiallyInsecure, [s.unblockInsecure, s.unblockTip2]];
case Downloads.Error.BLOCK_VERDICT_POTENTIALLY_UNWANTED:
return [
s.blockedPotentiallyUnwanted,

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

@ -32,7 +32,7 @@ stateBlockedParentalControls=Blocked by Parental Controls
# be longer than the other existing status strings.
blockedMalware=This file contains a virus or malware.
blockedPotentiallyUnwanted=This file may harm your computer.
blockedInsecure = This file could not be downloaded securely.
blockedPotentiallyInsecure=File not downloaded: Potential security risk.
blockedUncommon2=This file is not commonly downloaded.
# LOCALIZATION NOTE (fileMovedOrMissing):
@ -42,7 +42,7 @@ fileMovedOrMissing=File moved or missing
# LOCALIZATION NOTE (unblockHeaderUnblock, unblockHeaderOpen,
# unblockTypeMalware, unblockTypePotentiallyUnwanted2,
# unblockTypeUncommon2, unblockTip2, unblockButtonOpen,
# unblockButtonUnblock, unblockButtonConfirmBlock):
# unblockButtonUnblock, unblockButtonConfirmBlock, unblockInsecure):
# These strings are displayed in the dialog shown when the user asks a blocked
# download to be unblocked. The severity of the threat is expressed in
# descending order by the unblockType strings, it is higher for files detected
@ -52,6 +52,7 @@ unblockHeaderOpen=Are you sure you want to open this file?
unblockTypeMalware=This file contains a virus or other malware that will harm your computer.
unblockTypePotentiallyUnwanted2=This file is disguised as a helpful download, but it can make unexpected changes to your programs and settings.
unblockTypeUncommon2=This file is not commonly downloaded and may not be safe to open. It may contain a virus or make unexpected changes to your programs and settings.
unblockInsecure=The file uses an insecure connection. It may be corrupted or tampered with during the download process.
unblockTip2=You can search for an alternate download source or try again later.
unblockButtonOpen=Open
unblockButtonUnblock=Allow download

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

@ -67,8 +67,9 @@ async function resetDownloads() {
async function shouldNotifyDownloadUI() {
// Waits until a Blocked download was added to the Download List
// -> returns the blocked Download
let list = await Downloads.getList(Downloads.ALL);
await new Promise(res => {
return new Promise(res => {
const view = {
onDownloadAdded: aDownload => {
let { error } = aDownload;
@ -76,7 +77,7 @@ async function shouldNotifyDownloadUI() {
error.becauseBlockedByReputationCheck &&
error.reputationCheckVerdict == Downloads.Error.BLOCK_VERDICT_INSECURE
) {
res(true);
res(aDownload);
list.removeView(view);
}
},
@ -112,7 +113,7 @@ async function runTest(url, link, checkFunction, decscription) {
await SpecialPowers.popPrefEnv();
}
// Test Blocking
add_task(async function() {
await runTest(
INSECURE_BASE_URL,
@ -139,3 +140,17 @@ add_task(async function() {
"Secure -> Secure should Download"
);
});
// Test Manual Unblocking
add_task(async function() {
await runTest(
SECURE_BASE_URL,
"insecure",
async () => {
let download = await shouldNotifyDownloadUI();
await download.unblock();
ok(download.error == null, "There should be no error after unblocking");
},
"A Blocked Download Should succeeded to Download after a Manual unblock"
);
});

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

@ -643,6 +643,23 @@ Download.prototype = {
);
}
if (
this.error?.reputationCheckVerdict == DownloadError.BLOCK_VERDICT_INSECURE
) {
// In this Error case, the download was actually canceled before it was
// passed to the Download UI. So we need to start the download here.
this.error = null;
this.succeeded = false;
this.hasBlockedData = false;
this.start().catch(e => {
this.error = e;
this._notifyChange();
});
this._notifyChange();
this._promiseUnblock = DownloadIntegration.downloadDone(this);
return this._promiseUnblock;
}
if (!this.hasBlockedData) {
return Promise.reject(
new Error("unblock may only be called on Downloads with blocked data.")

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

@ -389,6 +389,14 @@ DownloadLegacyTransfer.prototype = {
becauseBlockedByReputationCheck: true,
reputationCheckVerdict: DownloadError.BLOCK_VERDICT_INSECURE,
};
// hasBlockedData needs to be true
// because the unblock UI is hidden if there is
// no data to be unblocked.
serialisedDownload.hasBlockedData = true;
// We cannot use the legacy saver here, as the original channel
// is already closed. A copy saver would create a new channel once
// start() is called.
serialisedDownload.saver = "copy";
}
Downloads.createDownload(serialisedDownload)