Files
tubestation/toolkit/mozapps/extensions/content/xpinstallConfirm.js
Jim Blandy 39dc0c6097 Bug 914753: Make Emacs file variable header lines correct, or at least consistent. DONTBUILD r=ehsan
The -*- file variable lines -*- establish per-file settings that Emacs will
pick up. This patch makes the following changes to those lines (and touches
nothing else):

 - Never set the buffer's mode.

   Years ago, Emacs did not have a good JavaScript mode, so it made sense
   to use Java or C++ mode in .js files. However, Emacs has had js-mode for
   years now; it's perfectly serviceable, and is available and enabled by
   default in all major Emacs packagings.

   Selecting a mode in the -*- file variable line -*- is almost always the
   wrong thing to do anyway. It overrides Emacs's default choice, which is
   (now) reasonable; and even worse, it overrides settings the user might
   have made in their '.emacs' file for that file extension. It's only
   useful when there's something specific about that particular file that
   makes a particular mode appropriate.

 - Correctly propagate settings that establish the correct indentation
   level for this file: c-basic-offset and js2-basic-offset should be
   js-indent-level. Whatever value they're given should be preserved;
   different parts of our tree use different indentation styles.

 - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil.
   Remove tab-width: settings, at least in files that don't contain tab
   characters.

 - Remove js2-mode settings that belong in the user's .emacs file, like
   js2-skip-preprocessor-directives.
2014-06-24 22:12:07 -07:00

171 lines
5.4 KiB
JavaScript

// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var XPInstallConfirm = {};
XPInstallConfirm.init = function XPInstallConfirm_init()
{
var _installCountdown;
var _installCountdownInterval;
var _focused;
var _timeout;
// Default to cancelling the install when the window unloads
XPInstallConfirm._installOK = false;
var bundle = document.getElementById("xpinstallConfirmStrings");
let args = window.arguments[0].wrappedJSObject;
var _installCountdownLength = 5;
try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var delay_in_milliseconds = prefs.getIntPref("security.dialog_enable_delay");
_installCountdownLength = Math.round(delay_in_milliseconds / 500);
} catch (ex) { }
var itemList = document.getElementById("itemList");
var numItemsToInstall = args.installs.length;
for (let install of args.installs) {
var installItem = document.createElement("installitem");
itemList.appendChild(installItem);
installItem.name = install.addon.name;
installItem.url = install.sourceURI.spec;
var icon = install.iconURL;
if (icon)
installItem.icon = icon;
var type = install.type;
if (type)
installItem.type = type;
if (install.certName) {
installItem.cert = bundle.getFormattedString("signed", [install.certName]);
}
else {
installItem.cert = bundle.getString("unverified");
}
installItem.signed = install.certName ? "true" : "false";
}
var introString = bundle.getString("itemWarnIntroSingle");
if (numItemsToInstall > 4)
introString = bundle.getFormattedString("itemWarnIntroMultiple", [numItemsToInstall]);
var textNode = document.createTextNode(introString);
var introNode = document.getElementById("itemWarningIntro");
while (introNode.hasChildNodes())
introNode.removeChild(introNode.firstChild);
introNode.appendChild(textNode);
var okButton = document.documentElement.getButton("accept");
okButton.focus();
function okButtonCountdown() {
_installCountdown -= 1;
if (_installCountdown < 1) {
okButton.label = bundle.getString("installButtonLabel");
okButton.disabled = false;
clearInterval(_installCountdownInterval);
}
else
okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
}
function myfocus() {
// Clear the timeout if it exists so only the last one will be used.
if (_timeout)
clearTimeout(_timeout);
// Use setTimeout since the last focus or blur event to fire is the one we
// want
_timeout = setTimeout(setWidgetsAfterFocus, 0);
}
function setWidgetsAfterFocus() {
if (_focused)
return;
_installCountdown = _installCountdownLength;
_installCountdownInterval = setInterval(okButtonCountdown, 500);
okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
_focused = true;
}
function myblur() {
// Clear the timeout if it exists so only the last one will be used.
if (_timeout)
clearTimeout(_timeout);
// Use setTimeout since the last focus or blur event to fire is the one we
// want
_timeout = setTimeout(setWidgetsAfterBlur, 0);
}
function setWidgetsAfterBlur() {
if (!_focused)
return;
// Set _installCountdown to the inital value set in setWidgetsAfterFocus
// plus 1 so when the window is focused there is immediate ui feedback.
_installCountdown = _installCountdownLength + 1;
okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
okButton.disabled = true;
clearInterval(_installCountdownInterval);
_focused = false;
}
function myUnload() {
if (_installCountdownLength > 0) {
document.removeEventListener("focus", myfocus, true);
document.removeEventListener("blur", myblur, true);
}
window.removeEventListener("unload", myUnload, false);
// Now perform the desired action - either install the
// addons or cancel the installations
if (XPInstallConfirm._installOK) {
for (let install of args.installs)
install.install();
}
else {
for (let install of args.installs)
install.cancel();
}
}
window.addEventListener("unload", myUnload, false);
if (_installCountdownLength > 0) {
document.addEventListener("focus", myfocus, true);
document.addEventListener("blur", myblur, true);
okButton.disabled = true;
setWidgetsAfterFocus();
}
else
okButton.label = bundle.getString("installButtonLabel");
}
XPInstallConfirm.onOK = function XPInstallConfirm_onOk()
{
Components.classes["@mozilla.org/base/telemetry;1"].
getService(Components.interfaces.nsITelemetry).
getHistogramById("SECURITY_UI").
add(Components.interfaces.nsISecurityUITelemetry.WARNING_CONFIRM_ADDON_INSTALL_CLICK_THROUGH);
// Perform the install or cancel after the window has unloaded
XPInstallConfirm._installOK = true;
return true;
}
XPInstallConfirm.onCancel = function XPInstallConfirm_onCancel()
{
// Perform the install or cancel after the window has unloaded
XPInstallConfirm._installOK = false;
return true;
}