bug 162020 option to delay enabling confirmation buttons r=mkaply,sr=sspitzer

This commit is contained in:
dveditz%cruzio.com 2004-06-05 09:26:01 +00:00
Родитель f1fc36c541
Коммит 1f3e1038f3
8 изменённых файлов: 49 добавлений и 131 удалений

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

@ -2141,6 +2141,7 @@ nsScriptSecurityManager::CheckConfirmDialog(JSContext* cx, nsIPrincipal* aPrinci
PRInt32 buttonPressed = 1; // If the user exits by clicking the close box, assume No (button 1)
rv = prompter->ConfirmEx(title.get(), message.get(),
(nsIPrompt::BUTTON_DELAY_ENABLE) +
(nsIPrompt::BUTTON_POS_1_DEFAULT) +
(nsIPrompt::BUTTON_TITLE_YES * nsIPrompt::BUTTON_POS_0) +
(nsIPrompt::BUTTON_TITLE_NO * nsIPrompt::BUTTON_POS_1),

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

@ -133,7 +133,10 @@ interface nsIPromptService : nsISupports
const unsigned long BUTTON_POS_0_DEFAULT = 0 << 24;
const unsigned long BUTTON_POS_1_DEFAULT = 1 << 24;
const unsigned long BUTTON_POS_2_DEFAULT = 2 << 24;
const unsigned long BUTTON_POS_2_DEFAULT = 2 << 24;
/* used for security dialogs, buttons are initially disabled */
const unsigned long BUTTON_DELAY_ENABLE = 1 << 26;
const unsigned long STD_OK_CANCEL_BUTTONS = (BUTTON_TITLE_OK * BUTTON_POS_0) +
(BUTTON_TITLE_CANCEL * BUTTON_POS_1);

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

@ -52,7 +52,8 @@ interface nsPIPromptService : nsISupports
eButton0Text=8, eButton1Text=9, eButton2Text=10, eButton3Text=11,
eDialogTitle=12};
enum {eButtonPressed=0, eCheckboxState=1, eNumberButtons=2,
eNumberEditfields=3, eEditField1Password=4, eDefaultButton=5};
eNumberEditfields=3, eEditField1Password=4, eDefaultButton=5,
eDelayButtonEnable=6};
%}
void doDialog(in nsIDOMWindow aParent, in nsIDialogParamBlock aParamBlock, in string aChromeURL);

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

@ -291,6 +291,8 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent,
#define BUTTON_DEFAULT_MASK 0x03000000
block->SetInt(eDefaultButton, (buttonFlags & BUTTON_DEFAULT_MASK) >> 24);
block->SetInt(eDelayButtonEnable, buttonFlags & BUTTON_DELAY_ENABLE);
PRInt32 numberButtons = 0;
for (int i = 0; i < 3; i++) {

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

@ -645,6 +645,8 @@ pref("security.directory", "");
pref("signed.applets.codebase_principal_support", false);
pref("security.checkloaduri", true);
pref("security.xpconnect.plugin.unrestricted", true);
// security-sensitive dialogs should delay focus. In milliseconds.
pref("security.dialog_enable_delay", 2000);
// Modifier key prefs: default to Windows settings,
// menu access key = alt, accelerator key = control.

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

@ -87,8 +87,11 @@ interface nsIPrompt : nsISupports
const unsigned long BUTTON_POS_0_DEFAULT = 0 << 24;
const unsigned long BUTTON_POS_1_DEFAULT = 1 << 24;
const unsigned long BUTTON_POS_2_DEFAULT = 2 << 24;
const unsigned long BUTTON_POS_2_DEFAULT = 2 << 24;
/* used for security dialogs, buttons are initially disabled */
const unsigned long BUTTON_DELAY_ENABLE = 1 << 26;
const unsigned long STD_OK_CANCEL_BUTTONS = (BUTTON_TITLE_OK * BUTTON_POS_0) +
(BUTTON_TITLE_CANCEL * BUTTON_POS_1);

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

@ -163,27 +163,56 @@ function commonDialogOnLoad()
if (gCommonDialogParam.GetInt(3) == 0) // If no text fields
{
var dButton;
var defaultButton = gCommonDialogParam.GetInt(5);
switch (defaultButton) {
case 3:
document.documentElement.getButton("extra2").focus();
dButton = document.documentElement.getButton("extra2");
break;
case 2:
document.documentElement.getButton("extra1").focus();
dButton = document.documentElement.getButton("extra1");
break;
case 1:
document.documentElement.getButton("cancel").focus();
dButton = document.documentElement.getButton("cancel");
break;
default:
case 0:
document.documentElement.getButton("accept").focus();
dButton = document.documentElement.getButton("accept");
break;
}
// move the default attribute and focus from the accept button
// to the one specified in the dialog params
document.documentElement.getButton("accept").setAttribute("default",false);
dButton.setAttribute("default", true);
dButton.focus();
}
if (gCommonDialogParam.GetInt(6) != 0) // delay button enable
{
var delayInterval = 2000;
try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
delayInterval = prefs.getIntPref("security.dialog_enable_delay");
} catch (e) {}
document.documentElement.getButton("accept").disabled = true;
document.documentElement.getButton("extra1").disabled = true;
document.documentElement.getButton("extra2").disabled = true;
setTimeout(commonDialogReenableButtons, delayInterval);
}
getAttention();
}
function commonDialogReenableButtons()
{
document.documentElement.getButton("accept").disabled = false;
document.documentElement.getButton("extra1").disabled = false;
document.documentElement.getButton("extra2").disabled = false;
}
function initTextbox(aName, aLabelIndex, aValueIndex, aAlwaysLabel)
{
unHideElementById(aName+"Container");

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

@ -1,123 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// dialog param block
var gParam;
var gBundle;
function addTreeItem(num, aName, aUrl, aCertName)
{
// first column is the package name
var item = document.createElement("description");
item.setAttribute("value", aName);
item.setAttribute("tooltiptext", aName);
item.setAttribute("class", "confirmName");
item.setAttribute("crop", "center");
// second column is for the cert name
var certName = document.createElement("description");
var certNameValue = aCertName ? aCertName : gBundle.getString("Unsigned");
certName.setAttribute("value", certNameValue);
certName.setAttribute("tooltiptext", certNameValue);
certName.setAttribute("crop", "center");
// third column is the host serving the file
var urltext = aUrl.replace(/^([^:]*:\/*[^\/]+).*/, "$1");
var url = document.createElement("description");
url.setAttribute("value", aUrl);
url.setAttribute("tooltiptext", aUrl);
url.setAttribute("class", "confirmURL");
url.setAttribute("crop", "center");
// create row and add it to the grid
var row = document.createElement("row");
row.appendChild(item);
row.appendChild(certName);
row.appendChild(url);
document.getElementById("xpirows").appendChild(row);
}
function onLoad()
{
var row = 0;
var moduleName, URL, IconURL, certName, numberOfDialogTreeElements;
gBundle = document.getElementById("xpinstallBundle");
gParam = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
gParam.SetInt(0, 1); // Set the default return to Cancel
numberOfDialogTreeElements = gParam.GetInt(1);
for (var i=0; i < numberOfDialogTreeElements; i++)
{
moduleName = gParam.GetString(i);
URL = gParam.GetString(++i);
IconURL = gParam.GetString(++i); // Advance the enumeration, parameter is unused just now.
certName = gParam.GetString(++i);
addTreeItem(row++, moduleName, URL, certName);
}
// Move default+focus from |accept| to |cancel| button.
var aButton = document.documentElement.getButton("accept");
aButton.setAttribute("default", false);
aButton = document.documentElement.getButton("cancel");
aButton.focus();
aButton.setAttribute("default", true);
}
function onAccept()
{
// set the accept button in the param block
if (gParam)
gParam.SetInt(0, 0);
return true;
}
function onCancel()
{
// set the cancel button in the param block
if (gParam)
gParam.SetInt(0, 1);
return true;
}