Bug 1198181 - Part 5 - Change the unblock dialog actions based on the verdict. r=past
MozReview-Commit-ID: 3NkvpI9EqpB
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -530,32 +530,36 @@ this.DownloadsCommon = {
*
* @return True to unblock the file, false to keep the user safe and
* cancel the operation.
*/
confirmUnblockDownload: Task.async(function* (aVerdict, aOwnerWindow) {
let s = DownloadsCommon.strings;
let title = s.unblockHeader;
let buttonFlags = (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
- (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1) +
- Ci.nsIPrompt.BUTTON_POS_1_DEFAULT;
+ (Ci.nsIPrompt.BUTTON_TITLE_CANCEL * Ci.nsIPrompt.BUTTON_POS_1);
let type = "";
let message = s.unblockTip;
- let okButton = s.unblockButtonContinue;
- let cancelButton = s.unblockButtonCancel;
+ let unblockButton = s.unblockButtonContinue;
+ let confirmBlockButton = s.unblockButtonCancel;
switch (aVerdict) {
case Downloads.Error.BLOCK_VERDICT_UNCOMMON:
type = s.unblockTypeUncommon;
+ buttonFlags += (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_2) +
+ Ci.nsIPrompt.BUTTON_POS_0_DEFAULT;
break;
case Downloads.Error.BLOCK_VERDICT_POTENTIALLY_UNWANTED:
type = s.unblockTypePotentiallyUnwanted;
+ buttonFlags += (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_2) +
+ Ci.nsIPrompt.BUTTON_POS_2_DEFAULT;
break;
default: // Assume Downloads.Error.BLOCK_VERDICT_MALWARE
type = s.unblockTypeMalware;
+ buttonFlags += Ci.nsIPrompt.BUTTON_POS_1_DEFAULT;
break;
}
if (type) {
message = type + "\n\n" + message;
}
Services.ww.registerNotification(function onOpen(subj, topic) {
@@ -575,18 +579,19 @@ this.DownloadsCommon = {
}
});
}
});
// The ordering of the ok/cancel buttons is used this way to allow "cancel"
// to have the same result as hitting the ESC or Close button (see bug 345067).
let rv = Services.prompt.confirmEx(aOwnerWindow, title, message, buttonFlags,
- okButton, cancelButton, null, null, {});
- return (rv == 0);
+ unblockButton, null, confirmBlockButton,
+ null, {});
+ return ["unblock", "cancel", "confirmBlock"][rv];
}),
};
XPCOMUtils.defineLazyGetter(this.DownloadsCommon, "log", () => {
return DownloadsLogger.log.bind(DownloadsLogger);
});
XPCOMUtils.defineLazyGetter(this.DownloadsCommon, "error", () => {
return DownloadsLogger.error.bind(DownloadsLogger);
--- a/browser/components/downloads/DownloadsViewUI.jsm
+++ b/browser/components/downloads/DownloadsViewUI.jsm
@@ -260,16 +260,35 @@ this.DownloadsViewUI.DownloadElementShel
text = s.statusSeparator(firstPart, displayDate);
tip = s.statusSeparator(fullHost, fullDate);
}
return { text, tip: tip || text };
},
/**
+ * Shows the appropriate unblock dialog based on the verdict, and executes the
+ * action selected by the user in the dialog, which may involve unblocking,
+ * opening or removing the file.
+ *
+ * @param window
+ * The window to which the dialog should be anchored.
+ */
+ confirmUnblock(window) {
+ let verdict = this.download.error.reputationCheckVerdict;
+ DownloadsCommon.confirmUnblockDownload(verdict, window).then(action => {
+ if (action == "unblock") {
+ return this.download.unblock();
+ } else if (action == "confirmBlock") {
+ return this.download.confirmBlock();
+ }
+ }).catch(Cu.reportError);
+ },
+
+ /**
* Returns the name of the default command to use for the current state of the
* download, when there is a double click or another default interaction. If
* there is no default command for the current state, returns an empty string.
* The commands are implemented as functions on this object or derived ones.
*/
get currentDefaultCommandName() {
switch (DownloadsCommon.stateOfDownload(this.download)) {
case Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED:
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -372,22 +372,17 @@ HistoryDownloadElementShell.prototype =
}
if (this._historyDownload) {
let uri = NetUtil.newURI(this.download.source.url);
PlacesUtils.bhistory.removePage(uri);
}
},
downloadsCmd_unblock() {
- let verdict = this.download.error.reputationCheckVerdict;
- DownloadsCommon.confirmUnblockDownload(verdict, window).then(confirmed => {
- if (confirmed) {
- return this.download.unblock();
- }
- }).catch(Cu.reportError);
+ this.confirmUnblock(window);
},
// Returns whether or not the download handled by this shell should
// show up in the search results for the given term. Both the display
// name for the download and the url are searched.
matchesSearchTerm(aTerm) {
if (!aTerm) {
return true;
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -1087,22 +1087,17 @@ DownloadsViewItem.prototype = {
cmd_delete() {
DownloadsCommon.removeAndFinalizeDownload(this.download);
PlacesUtils.bhistory.removePage(
NetUtil.newURI(this.download.source.url));
},
downloadsCmd_unblock() {
DownloadsPanel.hidePanel();
- let verdict = this.download.error.reputationCheckVerdict;
- DownloadsCommon.confirmUnblockDownload(verdict, window).then(confirmed => {
- if (confirmed) {
- return this.download.unblock();
- }
- }).catch(Cu.reportError);
+ this.confirmUnblock(window);
},
downloadsCmd_open() {
this.download.launch().catch(Cu.reportError);
// We explicitly close the panel here to give the user the feedback that
// their click has been received, and we're handling the action.
// Otherwise, we'd have to wait for the file-type handler to execute
--- a/browser/components/downloads/test/browser/browser_confirm_unblock_download.js
+++ b/browser/components/downloads/test/browser/browser_confirm_unblock_download.js
@@ -30,17 +30,17 @@ function addDialogOpenObserver(buttonAct
}
});
}
add_task(function* test_confirm_unblock_dialog_unblock() {
addDialogOpenObserver("accept");
let result = yield DownloadsCommon.confirmUnblockDownload(Downloads.Error.BLOCK_VERDICT_MALWARE,
window);
- ok(result, "Should return true when the user clicks on `Unblock` button.");
+ is(result, "unblock");
});
add_task(function* test_confirm_unblock_dialog_keep_safe() {
addDialogOpenObserver("cancel");
let result = yield DownloadsCommon.confirmUnblockDownload(Downloads.Error.BLOCK_VERDICT_MALWARE,
window);
- ok(!result, "Should return false when the user clicks on `Keep me safe` button.");
+ is(result, "cancel");
});