Bug 1494215 - Show notification to allow add-on installation after xpinstallConfirm removal in bug 1473933. r=jorgk

This commit is contained in:
Geoff Lankow 2018-10-06 11:54:57 +13:00
Родитель 4ce414addd
Коммит f4c4cbcb15
3 изменённых файлов: 74 добавлений и 31 удалений

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

@ -1356,20 +1356,18 @@ var specialTabs = {
Services.obs.addObserver(this.xpInstallObserver, "addon-install-disabled");
Services.obs.addObserver(this.xpInstallObserver, "addon-install-blocked");
Services.obs.addObserver(this.xpInstallObserver, "addon-install-failed");
Services.obs.addObserver(this.xpInstallObserver, "addon-install-confirmation");
Services.obs.addObserver(this.xpInstallObserver, "addon-install-complete");
},
onunload: function () {
window.removeEventListener("unload", specialTabs.onunload);
Services.obs.removeObserver(specialTabs.xpInstallObserver,
"addon-install-disabled");
Services.obs.removeObserver(specialTabs.xpInstallObserver,
"addon-install-blocked");
Services.obs.removeObserver(specialTabs.xpInstallObserver,
"addon-install-failed");
Services.obs.removeObserver(specialTabs.xpInstallObserver,
"addon-install-complete");
Services.obs.removeObserver(specialTabs.xpInstallObserver, "addon-install-disabled");
Services.obs.removeObserver(specialTabs.xpInstallObserver, "addon-install-blocked");
Services.obs.removeObserver(specialTabs.xpInstallObserver, "addon-install-failed");
Services.obs.removeObserver(specialTabs.xpInstallObserver, "addon-install-confirmation");
Services.obs.removeObserver(specialTabs.xpInstallObserver, "addon-install-complete");
},
xpInstallObserver: {
@ -1468,6 +1466,48 @@ var specialTabs = {
}
}
break;
case "addon-install-confirmation":
let acceptInstallation = () => {
for (let install of installInfo.installs)
install.install();
installInfo = null;
};
let cancelInstallation = () => {
if (installInfo) {
for (let install of installInfo.installs) {
// The notification may have been closed because the add-ons got
// cancelled elsewhere, only try to cancel those that are still
// pending install.
if (install.state != AddonManager.STATE_CANCELLED)
install.cancel();
}
}
};
messageString = messengerBundle.getString("addonConfirmInstall.message");
messageString = PluralForm.get(installInfo.installs.length, messageString);
messageString = messageString.replace("#1", brandShortName);
messageString = messageString.replace("#2", installInfo.installs.length);
messageString += " " + installInfo.installs.map(ii => ii.name).join(", ");
buttons = [{
label: messengerBundle.getString("addonConfirmInstall.installButton.label"),
accessKey: messengerBundle.getString("addonConfirmInstall.installButton.accesskey"),
callback: acceptInstallation,
}, {
label: messengerBundle.getString("addonConfirmInstall.cancelButton.label"),
accessKey: messengerBundle.getString("addonConfirmInstall.cancelButton.accesskey"),
callback: cancelInstallation,
}];
if (notificationBox)
notificationBox.appendNotification(messageString,
notificationID,
iconURL,
notificationBox.PRIORITY_WARNING_MEDIUM,
buttons);
break;
case "addon-install-complete":
let needsRestart = installInfo.installs.some(function(i) {
return i.addon.pendingOperations != AddonManager.PENDING_NONE;
@ -1483,8 +1523,10 @@ var specialTabs = {
BrowserUtils.restartApplication();
}
}];
}
else {
} else if (browser.currentURI.spec == "about:addons") {
messageString = messengerBundle.getString("addonsInstalled");
buttons = [];
} else {
messageString = messengerBundle.getString("addonsInstalled");
buttons = [{
label: messengerBundle.getString("addonInstallManage"),

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

@ -679,6 +679,17 @@ addonInstallRestartButton.accesskey=R
addonInstallManage=Open Add-ons Manager
addonInstallManage.accesskey=O
# LOCALIZATION NOTE (addonConfirmInstallMessage):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is brandShortName
# #2 is the number of add-ons being installed
addonConfirmInstall.message=Allow the installation of the following add-on in #1:;Allow the installation of the following #2 add-ons in #1:
addonConfirmInstall.cancelButton.label=Cancel
addonConfirmInstall.cancelButton.accesskey=C
addonConfirmInstall.installButton.label=Install
addonConfirmInstall.installButton.accesskey=I
# LOCALIZATION NOTE (addonError-1, addonError-2, addonError-3, addonError-4):
# #1 is the add-on name, #2 is the host name, #3 is the application name
# #4 is the application version

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

@ -56,17 +56,6 @@ var setupModule = function (module) {
cth.installInto(module);
};
function close_xpinstall_dialog(xpidlg) {
xpidlg.window.document.documentElement.cancelDialog();
}
function accept_xpinstall_dialog(xpidlg) {
// The install dialog has a count down that we must wait for before
// proceeding.
mc.sleep(5500);
xpidlg.window.document.documentElement.getButton('accept').doCommand();
}
function click_notification_box_action_in_current_tab() {
let actionButton = gNotificationBox.currentNotification.querySelector("button");
mc.click(new elib.Elem(actionButton));
@ -117,14 +106,14 @@ function test_install_corrupt_xpi() {
close_notification_box();
}
test_install_xpi_offer.__force_skip__ = true; // disabled, see bug 1494215
function test_install_xpi_offer() {
click_install_link_and_wait_for_alert("installlink");
// which we want to click on!
plan_for_modal_dialog("Addons:Install", close_xpinstall_dialog);
// This brings up a second notification, which we ignore.
AlertWatcher.planForAlert(mc);
click_notification_box_action_in_current_tab();
wait_for_modal_dialog("Addons:Install", 50000);
AlertWatcher.waitForAlert(mc);
close_notification_box();
// After closing the dialog we need to give just a little extra time
// before we do things.
@ -142,18 +131,19 @@ function test_xpinstall_disabled() {
click_notification_box_action_in_current_tab();
}
test_xpinstall_actually_install.__force_skip__ = true; // disabled, see bug 1494215
function test_xpinstall_actually_install() {
click_install_link_and_wait_for_alert("installlink");
// which we want to click on!
plan_for_modal_dialog("Addons:Install", accept_xpinstall_dialog);
// and this time we get an alert as well.
// This brings up a second notification, which we click on.
AlertWatcher.planForAlert(mc);
click_notification_box_action_in_current_tab();
wait_for_modal_dialog("Addons:Install", 50000);
AlertWatcher.waitForAlert(mc);
// This brings up a third notification, which we ignore.
AlertWatcher.planForAlert(mc);
click_notification_box_action_in_current_tab();
AlertWatcher.waitForAlert(mc);
close_notification_box();
close_tab(gNewTab);
}