home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2005 October
/
Gamestar_77_2005-10_dvd.iso
/
Programy
/
nsb-install-8-0.exe
/
chrome
/
toolkit.jar
/
content
/
mozapps
/
autofill
/
passcard.js
< prev
next >
Wrap
Text File
|
2005-07-29
|
33KB
|
1,247 lines
/*** Passcard Manager **********************************************/
// NOTE: The following array stores Form Fill and Passcards XUL ids
var _elementIDs = [ "FirstName", "LastName", "EmailAddr", "PhoneNum", "shippingAddresses",
"StrAddr", "StrAddr2", "City", "State", "countryList", "ZipCode",
"askEveryTimeHidden", "passwordAskTimes", "passwordTimeout",
"pcAutologin", "pcAutosave", "pcHighlight", "pcFillAndSubmit",
"pcPasswordProtect", "afillRadio",
"dcAutosave", "dcFillAndSubmit", "dcMessageBar", "dcPasswordProtect", "dcPasswordPrompt"];
// no longer needed? "pcAutofill", "pcAutofillPrompt", "pcAutosave", "pcAutosavePrompt", "pcHighlight", "pcFillAndSubmit",
// no longer needed? "pcUserID", "pcPassword", "pcPasswordProtect", "pcPasswordPrompt", "pcPasswordExpire", "afillRadio",
// const variables
var kPasscardPreferences = "passcard.preferences.tab";
var kPasscardDetails = "passcard.details.tab";
var kCheckboxStateChange = "CheckboxStateChange";
var kSelectedTab = "passcard-tabs";
var kSignonsTree = "signonsTree";
var kRejectsTree = "rejectsTree";
var kDefaultPasscard = "DefaultPasscard";
// global variables
var gDebug = false;
var gPrefTabSelectInit = false;
var gSelectedTree = null;
var gSignons = null;
var gTreeMutex = 0;
var gPrefService = null;
var gLastSelectedSignon = null;
function PasscardOnLoad()
{
// password manager startup
pmStartup();
// passcard startup
pcStartup();
if (!IsOpenInDialog())
{
// master password startup
mpStartup();
}
}
/**
* Startup
**/
function pcStartup()
{
debug("Passcard Startup()");
// setup event handlers
if (!IsInitialized())
window.top.hPrefWindow.registerOKCallbackFunc(OnPasscardOK);
if (!IsOpenInDialog())
{
// get the preferences from the file and
// ensure dependent xul are disabled appropriately
pcGetPreferences();
}
// need to setup this event handler after pcGetPreferences()
/* TODO JVL : Remove if no longer necessary
document.getElementById("pcPasswordProtect").addEventListener(kCheckboxStateChange, SetPasswordIfBlank, false);
document.getElementById("pcPasswordPrompt").addEventListener(kCheckboxStateChange, SetPasswordIfBlank, false);
*/
gSelectedTree = document.getElementById('signonsTree');
gPrefTabSelectInit = true;
SetPasscardTab(kPasscardPreferences, "passcard-tabbox");
SetPasscardTab(kPasscardDetails, "detail-tabbox");
// MERC JVL : Removed (4/14/05) SetNoLoginPasscardMsg();
gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (gPrefService.getPrefType('browser.passcard.selectedcard') &&
gPrefService.getCharPref('browser.passcard.selectedcard'))
{
selectTreeByPasscardName(gPrefService.getCharPref('browser.passcard.selectedcard'));
}
else if (signonsTree.view.rowCount > 0 && signonsTree.treeBoxObject.selection.currentIndex < 0)
{
signonsTree.treeBoxObject.selection.select(0);
}
if (signonsTree.view.rowCount > 0 && signonsTree.treeBoxObject.selection.currentIndex < 0)
{
signonsTree.treeBoxObject.selection.select(0);
}
}
function selectTreeByPasscardName(passcardName)
{
var idx = 0;
var signonList = parent.passcardFinalize.signons;
if (signonList == null)
return;
if (signonList.length < 1)
return;
while (idx < signonList.length)
{
if (signonList[idx].passcard == passcardName)
break;
idx++;
}
if (idx >= signonList.length)
idx = 0;
signonsTree.treeBoxObject.selection.select(idx);
}
/**
* Set the passcard tab
**/
function SetPasscardTab(charPref, strTabBox)
{
var prefs = GetPreferencesInterface();
if (prefs == null)
return;
var selectedTabId = prefs.getCharPref(charPref);
debug("The selected passcard tab is", selectedTabId);
var theTabBox = document.getElementById(strTabBox);
// only allow this tab selection if in the Forms Option panel
if (theTabBox != null || !IsOpenInDialog())
{
var theTab = document.getElementById(selectedTabId);
theTabBox.selectedTab = theTab;
}
}
/**
* Get the passcard (general) preferences
**/
function pcGetPreferences()
{
// TODO JVL : Should store in browser prefs
// only get the preferences if we're opening the Options
// dialog and not just switching tabs within the dialog
if (IsInitialized())
return;
var pm = GetPMInterface();
if (pm == null)
return;
debug("GetPreferences()");
var prefAutologin = new Object();
var prefAutologinPrompt = new Object();
var prefAutosave = new Object();
var prefAutosavePrompt = new Object();
var prefHighlight = new Object();
var prefFillAndSubmit = new Object();
var prefDefaultPrompt = new Object();
var prefUserID = new Object();
var prefPassword = new Object();
var prefPasswordProtect = new Object();
var prefPasswordPrompt = new Object();
var prefExpire = new Object();
pm.getPreferences(prefAutologin, prefAutologinPrompt, prefAutosave, prefAutosavePrompt, prefHighlight, prefFillAndSubmit,
prefDefaultPrompt, prefUserID, prefPassword, prefPasswordProtect, prefPasswordPrompt, prefExpire);
prefDump(prefAutologin, prefAutologinPrompt, prefAutosave, prefAutosavePrompt, prefHighlight, prefFillAndSubmit,
prefDefaultPrompt, prefUserID, prefPassword, prefPasswordProtect, prefPasswordPrompt, prefExpire);
document.getElementById("pcAutologin").selectedIndex = AsInteger(prefAutologin.value);
document.getElementById("pcAutosave").selectedIndex = AsInteger(prefAutosave.value);
document.getElementById("pcHighlight").checked = AsBoolean(prefHighlight.value);
document.getElementById("pcFillAndSubmit").checked = AsBoolean(prefFillAndSubmit.value);
document.getElementById("pcDefaultPrompt").checked = AsBoolean(prefDefaultPrompt.value);
// document.getElementById("pcUserID").value = prefUserID.value;
// document.getElementById("pcPassword").value = prefPassword.value;
document.getElementById("pcPasswordProtect").checked = AsBoolean(prefPasswordProtect.value);
// document.getElementById("pcPasswordPrompt").checked = AsBoolean(prefPasswordPrompt.value);
// document.getElementById("pcPasswordExpire").value = IsValidExpireValue(prefExpire.value);
}
/**
* Select the tree, activate/deactivate buttons and update details
**/
function SelectTree(thisTree)
{
// respect mutex
if (gTreeMutex != 0)
return;
// establish mutex
gTreeMutex++;
CommitLastSelectedSignon();
// update tree selection
gSelectedTree = thisTree;
var treeID = gSelectedTree.id;
// clear all selections in the other tree
document.getElementById(gSelectedTree.id == kRejectsTree ? kSignonsTree : kRejectsTree).
view.selection.clearSelection();
// show/hide the additional message about Password protected Passcards (hide for blacklisted sites)
// MERC JVL : Removed (4/14/05) SetNoLoginPasscardMsg();
// show/hide the data fields using a deck depending which list we are viewing
document.getElementById("detail-deck").selectedIndex = gSelectedTree.id == kRejectsTree ? 0 : 1;
// enable/disable the Remove/RemoveAll buttons
var selections = GetTreeSelections(gSelectedTree);
if (selections != null && selections.length > 0) // MERC JVL: why is 'selections.length' == 1 in this instance?
{
if (!IsDefaultPasscard())
document.getElementById("removeSignon").removeAttribute("disabled");
else
document.getElementById("removeSignon").setAttribute("disabled", "true");
document.getElementById("removeAllSignons").removeAttribute("disabled");
}
else
{
document.getElementById("removeSignon").setAttribute("disabled", "true");
document.getElementById("removeAllSignons").setAttribute("disabled", "true");
}
// update the fields
var signon = GetSelectedSignon();
if (signon)
{
document.getElementById("passcard-site-description").value = signon.host;
document.getElementById("passcard-userID-edit").value = signon.user;
document.getElementById("passcard-password-edit").value = signon.password;
document.getElementById("passcard-autologin-menulist").selectedIndex = AutologinAsInt(signon.autologin);
document.getElementById("passcard-protect-checkbox").checked = signon.protect == 0 ? false : true;
document.getElementById("passcard-setAsDefault-button").disabled = signon.lastUsed == 0 ? null : true;
//dump('********** SelectTree():Advanced Fields: ' + signon.advancedFields + '\n');
FillAdvancedFields(signon.advancedFields);
EnableProtect();
gLastSelectedSignon = signon;
}
// release mutex
gTreeMutex--;
}
/**
* Delete the item from the selected list
**/
function DeleteItem()
{
// sanity check
if (IsDefaultPasscard())
return;
if (gSelectedTree == signonsTree)
{
// check if the lastUsed signon is being deleted
var bLastUsed = false;
var host;
var signon = GetSelectedSignon();
if (signon)
{
bLastUsed = (signon.lastUsed != 0);
host = signon.host;
}
// delete the selected item
DeleteSelectedItemFromTree(signonsTree, signonsTreeView, gSignons,
parent.passcardFinalize.deletedSignons,
"removeSignon", "removeAllSignons");
// if the lastUsed signon was deleted, set the zeroth signon as the lastUsed
if (bLastUsed && gSignons.length > 0)
{
var i = 0;
var maxlen = gSignons.length;
while (i < maxlen)
{
if (host == gSignons[i].host)
{
gSignons[i].lastUsed = 1;
i = maxlen;
}
i++;
}
}
// hide the data fields if the tree is empty
if (gSignons.length < 1)
document.getElementById("detail-deck").selectedIndex = 0;
}
else if (gSelectedTree == rejectsTree)
{
DeleteSelectedItemFromTree(rejectsTree, rejectsTreeView,
parent.passcardFinalize.rejects,
parent.passcardFinalize.deletedRejects,
"removeSignon", "removeAllSignons");
}
}
/**
* Delete all items from the selected list
**/
function DeleteAllItems()
{
if (gSelectedTree == signonsTree)
{
DeleteAllFromTree(signonsTree, signonsTreeView, gSignons,
parent.passcardFinalize.deletedSignons,
"removeSignon", "removeAllSignons");
// hide the data fields if the tree is empty
if (gSignons.length < 1)
document.getElementById("detail-deck").selectedIndex = 0;
}
else if (gSelectedTree == rejectsTree)
{
DeleteAllFromTree(rejectsTree, rejectsTreeView,
parent.passcardFinalize.rejects,
parent.passcardFinalize.deletedRejects,
"removeSignon", "removeAllSignons");
}
}
/**
* Return the autologin string as a number
**/
function AutologinAsInt(str)
{
var val = str;
try
{
val = parseInt(str);
}
catch(e)
{
val = 1;
}
// four options in autologin dropdown menulist
return (val > -1 && val < 4) ? val : 0;
}
/**
* Change the userID for the selected passcard
**/
function SetUserID(obj)
{
var signon = GetSelectedSignon();
if (signon && obj)
signon.user = obj.value;
}
/**
* Change the password for the selected passcard
**/
function SetPassword(obj)
{
var signon = GetSelectedSignon();
if (signon && obj)
signon.password = obj.value;
}
/**
* Set the autologin preference for the selected passcard
**/
function SetAutologin(obj)
{
var signon = GetSelectedSignon();
if (signon && obj)
signon.autologin = obj.selectedIndex;
}
/**
* Set the protection preference for the selected passcard
**/
function SetProtect(obj)
{
var signon = GetSelectedSignon();
if (signon && obj)
{
if (obj.checked && !IsMasterPasswordSet())
{
if (!OnChangePassword())
{
obj.checked = !obj.checked;
}
}
signon.protect = obj.checked ? 1 : 0;
}
}
/**
* Set the currently selected passcard as the default passcard for this site
**/
function SetAsDefault(obj)
{
// get the current signon from the list
var signon = GetSelectedSignon();
if (signon && obj)
{
// reset lastUsed for each signon
for (var i = 0; i < gSignons.length; i++)
{
if (signon.host == gSignons[i].host)
gSignons[i].lastUsed = 0;
}
// set lastUsed for the current signon and disable the button
signon.lastUsed = 1;
obj.disabled = true;
}
}
/**
* Get the currently selected passcard from the signon list
**/
function GetSelectedSignon()
{
if (gSelectedTree == signonsTree)
{
if (!gSignons)
gSignons = parent.passcardFinalize.signons;
if (gSignons)
{
var idx = signonsTree.treeBoxObject.selection.currentIndex;
if (idx > -1 && idx < gSignons.length)
return gSignons[idx];
}
else
{
// should never get here
alert('Could not retrieve the passcard database');
}
}
return null;
}
/**
* Handle Ok event
**/
function OnPasscardOK()
{
var pcFinalize = parent.passcardFinalize;
if (!pcFinalize)
return;
if (!pcFinalize.IsOpenInDialog2())
{
// save passcard preferences
pcFinalize.pcSetPreferences();
}
if (pcFinalize.IsOpenFormFillPanel())
CommitLastSelectedSignon();
// serialize the passcard changes
pcFinalize.Serialize();
}
/**
* Enable the protect checkbox if both username and password fields are not blank
**/
function EnableProtect()
{
if (document.getElementById("passcard-userID-edit").value.length > 0 &&
document.getElementById("passcard-password-edit").value.length > 0)
{
document.getElementById("passcard-protect-checkbox").removeAttribute('disabled');
}
else
{
document.getElementById("passcard-protect-checkbox").setAttribute('disabled', 'true');
}
}
/* TODO JVL: Remove if no longer necessary
/ **
* Ensure expire time is valid
** /
function OnExpireTextChange()
{
document.getElementById("pcPasswordExpire").value
= IsValidExpireValue(document.getElementById("pcPasswordExpire").value);
}
*/
/**
* Select and save the passcard tab state for the next time it is open
**/
function OnSelectPasscardTab(theTabs)
{
var theTab = theTabs.selectedItem;
if (!theTab)
return;
// HACK: don't save the preference until the page has been fully initialized
// because OnSelectPasscardTab() will be called before Startup()
if (gPrefTabSelectInit)
{
// set as the last visted tab
var prefs = GetPreferencesInterface();
if (prefs)
prefs.setCharPref(theTabs.id == kSelectedTab ? kPasscardPreferences : kPasscardDetails, theTab.id);
}
}
/**
* Check if the dialog has already been initialized
**/
function IsInitialized()
{
var prefWindow = window.top.hPrefWindow;
if (prefWindow)
{
var pageData = prefWindow.wsm.dataManager.getPageData('chrome://mozapps/content/autofill/autofill.xul');
if (pageData && ('initialized' in pageData))
return true;
}
if (IsOpenInDialog())
return true;
return false;
}
/**
* Check if the Default Passcard has been selected in the list
**/
function IsDefaultPasscard()
{
var bIsDefault = false;
if (gSelectedTree.id == kSignonsTree)
{
var signon = GetSelectedSignon();
bIsDefault = (signon && signon.host == kDefaultPasscard);
}
return bIsDefault;
}
/** MERC JVL : Removed (4/14/05)
* Set the no login passcard message
function SetNoLoginPasscardMsg()
{
if (IsMasterPasswordSet() || gSelectedTree.id == kRejectsTree)
{
document.getElementById('noLoginPasscardMsg').setAttribute('hidden', 'true');
}
else
{
document.getElementById('noLoginPasscardMsg').removeAttribute('hidden');
}
}
**/
/**
* Prompt user to enter a Master Password if password protecting
* a Passcard and no Master Password has been set yet.
**/
function CheckForMasterPassword(event)
{
if (!IsMasterPasswordSet())
{
OnChangePassword();
}
}
/**
* Unprotect all Passcards
**/
function UnprotectAllPasscards()
{
for (var i = 0; i < gSignons.length; i++)
{
gSignons[i].protect = 0;
}
// also ensure that the currently selected passcard's protect checkbox is unchecked
document.getElementById("passcard-protect-checkbox").checked = false;
}
// check if we're viewing from a dialog in the Privacy Options panel
// instead of the Forms Option panel
function IsOpenInDialog()
{
return document.getElementById('pref-passcards') != null;
}
/**
* Fill the advanced view with the signon's advanced fields
**/
function FillAdvancedFields(advancedFields)
{
if (advancedFields == null)
{
document.getElementById('advancedFieldsDeck').selectedIndex = 0;
return;
}
//dump('passcard.js: FillAdvancedFields('+advancedFields+')\n');
// Clear the tree
var treeChildren = document.getElementById('advancedFieldsTreeChildren');
while (treeChildren.childNodes.length)
{
treeChildren.removeChild(treeChildren.childNodes[treeChildren.childNodes.length-1]);
}
if (advancedFields.length > 0)
{
document.getElementById('advancedFieldsDeck').selectedIndex = 1;
var pairs = advancedFields.split('|');
for (var i = 0; i < pairs.length; i++)
{
var delim = pairs[i].indexOf('=');
var fieldName = pairs[i].substring(0,delim);
var value = pairs[i].substring(delim+1);
var keyCell = document.createElement('treecell');
keyCell.setAttribute('label', fieldName);
var valCell = document.createElement('treecell');
valCell.setAttribute('label', value);
var row = document.createElement('treerow');
row.appendChild(keyCell);
row.appendChild(valCell);
var item = document.createElement('treeitem');
item.appendChild(row);
treeChildren.appendChild(item);
}
}
else
{
document.getElementById('advancedFieldsDeck').selectedIndex = 0;
}
}
/**
* Extract the current advanced fields to store them in the signon
**/
function ExtractAdvancedFields()
{
var treeChildren = document.getElementById('advancedFieldsTreeChildren');
if (treeChildren == null)
return "";
var pairs = new Array();
for (var i = 0; i < treeChildren.childNodes.length; i++)
{
var row = treeChildren.childNodes[i].firstChild;
var fieldName = row.firstChild.getAttribute('label');
var value = row.lastChild.getAttribute('label');
pairs[pairs.length] = fieldName + '=' + value;
}
var str = pairs.join('|');
//dump('passcard.js: ExtractAdvancedFields():\n ['+str+']\n');
return str;
}
function CommitLastSelectedSignon()
{
if (gLastSelectedSignon)
{
/* TODO JVL: an attempt to fix the bug where you make a change and select a different passcard before the change is committed
var advTree = document.getElementById("advancedFieldsTree");
var txtBox = document.getAnonymousElementByAttribute(advTree, "ileattr", "text");
// txtBox.blur();
// txtBox._assignValueToCell(txtBox.value, true);
*/
gLastSelectedSignon.advancedFields = ExtractAdvancedFields();
gLastSelectedSignon = null;
}
}
/* TODO JVL - remove if no longer used
/ **
* Edit selected passcard in list
** /
function EditPasscard()
{
var signon = GetSelectedSignon();
if (signon == null)
return;
// check to see if the passcard is password protected or not
if (!CanEditPasscard(signon.protect))
return;
passcardDump(signon);
var newPass = new Object();
newPass.passcard = signon;
newPass.result = "";
window.openDialog("chrome://mozapps/content/autofill/EditPasscardDialog.xul",
"_blank", "chrome,dialog,modal", newPass);
if (newPass.result != "" && passwordmanager != null)
{
var pm = GetPMInterface();
if (pm != null)
{
var newPasscard = newPass.passcard;
pm.updateSignon(newPasscard.host, newPasscard.uniqueID, newPasscard.passcard, newPasscard.user,
newPasscard.password, newPasscard.autologin, newPasscard.protect);
}
}
}
/ **
* Check if the passcard is password protected (non-zero)
** /
function CanEditPasscard(protect)
{
if (protect == 0 || !HasMasterPassword())
return true;
var dialogTitle = GetStringLocale("masterPasswordTitle");
var dialogPrompt = GetStringLocale("masterPasswordPrompt");
var proceed = new Object();
proceed.errorMessage = "";
proceed.result = "PROMPT";
while (proceed.result == "PROMPT")
{
window.openDialog("chrome://mozapps/content/autofill/SimplePasswordPrompt.xul",
"_blank", "chrome,dialog,modal", dialogTitle, dialogPrompt, proceed);
}
return proceed.result == "OK";
}
/ **
* Checkbox event handler
** /
function SetPasswordIfBlank(event)
{
var pm = GetPMInterface();
if (pm == null)
return;
var prefProtect = new Object();
var prefPagePassword = new Object();
pm.getPreferencePassword(prefProtect, prefPagePassword);
if (prefPagePassword.value.length <= 0 &&
(document.getElementById("pcPasswordProtect").checked ||
document.getElementById("pcPasswordPrompt").checked))
{
OnConfirmPassword();
}
}
/ **
* Display confirm password dialog
** /
function OnConfirmPassword()
{
var pm = GetPMInterface();
if (pm == null)
return;
var prefProtect = new Object();
var prefPagePassword = new Object();
pm.getPreferencePassword(prefProtect, prefPagePassword);
var proceed = new Object();
proceed.password = prefPagePassword.value;
proceed.errorMessage = "";
proceed.result = "PROMPT";
debug ("The old password assigned is", proceed.password);
while (proceed.result == "PROMPT")
{
window.openDialog("chrome://mozapps/content/autofill/ConfirmPassword.xul",
"_blank", "chrome,dialog,modal", proceed);
}
if (proceed.result == "OK")
{
debug ("The new password assigned is", proceed.password);
pm.setPreferencePassword(prefProtect, proceed.password);
}
// uncheck the appropriate checkboxes if the user doesn't save a password
if (proceed.password.length < 1)
{
BypassCheckboxEventListener("pcPasswordProtect", false);
BypassCheckboxEventListener("pcPasswordPrompt", false);
}
}
/ **
* Check if user can access the passcard panel (password protected)
* Returns true if user enters a matching password
** /
function SelectPasscardPanel(currentTab)
{
// sanity check
if (!currentTab || currentTab.id != "passcardtab")
return false;
ShowPasscardManagerContents(0);
var pm = GetPMInterface();
if (pm == null)
return false;
var prefProtect = new Object();
var prefPagePassword = new Object();
pm.getPreferencePassword(prefProtect, prefPagePassword);
// only need to continue checking if...
// this is the first time viewing the passcard manager for this session and
// the panel is password protected and
// the password is not blank,
// otherwise just return true now
if (!parent.passcardFinalize.gbPasscardManagerEntered &&
prefProtect && parseInt(prefProtect.value) != 0 &&
prefPagePassword && prefPagePassword.value.length > 0)
{
var dialogTitle = GetStringLocale("passcardManagerTitle");
var passwordLabel = GetStringLocale("passcardManagerPrompt");
var proceed = new Object();
proceed.password = prefPagePassword.value;
proceed.errorMessage = "";
proceed.result = "PROMPT";
debug ("The old password assigned is", proceed.password);
while (proceed.result == "PROMPT")
{
window.openDialog("chrome://mozapps/content/autofill/SimplePasswordPrompt.xul",
"_blank", "chrome,dialog,modal", dialogTitle, passwordLabel, proceed);
}
debug ("The new password assigned is", proceed.password);
// only reset the tab to passcard if user correctly enters password for passcard manager
if (proceed.result != "OK")
return false;
}
ShowPasscardManagerContents(1);
parent.passcardFinalize.gbPasscardManagerEntered = true;
return true;
}
/ **
* Get the localized string
** /
function GetStringLocale(val)
{
if (val.length > 0)
{
var bundle = document.getElementById("formfillpasscardBundle");
if (bundle)
return bundle.getString(val);
}
return "";
}
/ **
* Shows the Passcard Manager contents
** /
function ShowPasscardManagerContents(nVal)
{
if (nVal >= 0 && nVal <= 1)
document.getElementById("passcard-deck").selectedIndex = nVal;
}
/ **
* Bypass the checkbox event listener so that the checkbox can change state without firing
** /
function BypassCheckboxEventListener(checkboxID, state)
{
document.getElementById(checkboxID).removeEventListener(kCheckboxStateChange, SetPasswordIfBlank, false);
document.getElementById(checkboxID).checked = state;
document.getElementById(checkboxID).addEventListener(kCheckboxStateChange, SetPasswordIfBlank, false);
}
/ **
* Autosave checkbox event handler
** /
function DisableAutosave(event)
{
DisableCheckbox(event, "pcAutosave", "pcAutosavePrompt");
}
/ **
* Generic checkbox event handler
** /
function DisableCheckbox(event, dependee, dependent)
{
var dependentObj = document.getElementById(dependent);
// ensure dependent checkbox is disabled appropriately
if (document.getElementById(dependee).checked)
{
dependentObj.disabled = null;
}
else
{
// ensure dependent checkbox is unchecked when disabled
dependentObj.checked = false;
dependentObj.disabled = true;
}
}
*/
/*** Interface functions *******************************************/
/**
* Get the password manager internal interface
**/
function GetPMInterface()
{
return Components.classes["@mozilla.org/passwordmanager;1"].getService(Components.interfaces.nsIPasswordManager);
}
/**
* Get the preferences interface
**/
function GetPreferencesInterface()
{
return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
}
/*** Helper functions **********************************************/
/**
* Only allow a value between 0-999
**/
/* TODO JVL: Remove
function IsValidExpireValue(str)
{
var val = parseInt(str);
if (!val || !(val >= 0 && val < parent.passcardFinalize.kMaxExpireMinutes))
return 0;
return val;
}
*/
/**
* Return the string as a boolean value
**/
function AsBoolean(str)
{
var val = parseInt(str);
if (!val || val == 0)
return false;
return true;
}
/**
* Return the string as an integer value
**/
function AsInteger(str)
{
if (str == null || str == "")
str = 0;
var val = str;
try
{
val = parseInt(str);
}
catch(e)
{
val = 0;
}
return (val < 0) ? 0 : val;
}
/*** Test and debugging functions **********************************/
/**
* File specific debug messages
**/
function debug(val)
{
debug(val, "");
}
/**
* File specific debug messages
**/
function debug(fld, val)
{
if (!gDebug)
return;
var msg = "***** Passcard: " + fld;
if (val != null && val != "")
msg += ": " + val;
msg += "\n";
dump(msg);
}
/**
* Test function to see the passcards being saved.
**/
function passcardDump(pass)
{
if (!gDebug)
return;
var msg = "******************** Signons Dump BEGIN\n";
msg += "Host: " + pass.host + "\n";
msg += "Passcard: " + pass.passcard + "\n";
msg += "User: " + pass.user + "\n";
msg += "Password: " + pass.password + "\n";
msg += "AutoLogin: " + pass.autologin + "\n";
msg += "Protect: " + pass.protect + "\n";
msg += "LastUsed: " + pass.lastUsed + "\n";
msg += "UniqueID: " + pass.uniqueID + "\n";
msg += "******************** Signons Dump END\n";
dump(msg);
}
/**
* Test function to see the preferences being saved.
**/
function prefDump(prefAutologin, prefAutologinPrompt, prefAutosave, prefAutosavePrompt, prefHighlight,
prefFillAndSubmit, prefDefaultPrompt, prefUserID, prefPassword, prefProtect, prefPrompt, prefExpire)
{
if (!gDebug)
return;
var msg = "******************** Preferences Dump BEGIN\n";
msg += "Auto login: " + prefAutologin.value + "\n";
msg += "Auto login prompt: " + prefAutologinPrompt.value + "\n";
msg += "Auto save: " + prefAutosave.value + "\n";
msg += "Auto save prompt: " + prefAutosavePrompt.value + "\n";
msg += "Highlight: " + prefHighlight.value + "\n";
msg += "Fill and Submit: " + prefFillAndSubmit.value + "\n";
msg += "Default Prompt: " + prefDefaultPrompt.value + "\n";
msg += "UserID: " + prefUserID.value + "\n";
msg += "Password: " + prefPassword.value + "\n";
msg += "Password protect: " + prefProtect.value + "\n";
msg += "Password prompt: " + prefPrompt.value + "\n";
msg += "Password expire: " + prefExpire.value + "\n";
msg += "******************** Preferences Dump END\n";
dump(msg);
}
/**
* Test function to see the passcards being saved.
**/
function pcDump(view, val)
{
if (!gDebug)
return;
if (val != "")
alert(val);
for (i = 0; i < passcards.length; i++)
{
var msg = view.getCellText(i, "passcardCol");
msg += "\n";
msg += view.getCellText(i, "siteCol");
msg += "\n";
msg += view.getCellText(i, "userCol");
alert(msg);
}
}
/* TODO JVL - TEST CODE - REMOVE WHEN PASSCARD DEVELOPMENT FINISHED */
// viewSignons is copied from pref-privacy.js
function viewSignons()
{
window.openDialog("chrome://passwordmgr/content/passwordManager.xul",
"_blank", "chrome,resizable=yes", "8");
}
// This class is referenced (at a higher level) in pref.xul so that
// we don't go out of scope when the user clicks the OK button
if (!parent.passcardFinalize) parent.passcardFinalize =
{
kPageTag : "chrome://mozapps/content/autofill/autofill.xul",
kMaxExpireMinutes : 1000,
gbPasscardManagerEntered : false,
signons : new Array(),
rejects : new Array(),
deletedSignons : new Array(),
deletedRejects : new Array(),
/**
* Serialize the passcard changes
**/
Serialize : function()
{
var pm = this.GetInterface();
if (pm)
{
// save the changes made to the signons
var changes = this.signons;
for (var i = 0; i < changes.length; i++)
{
pm.updateSignon(changes[i].host, changes[i].passcard, changes[i].user,
changes[i].password, changes[i].autologin, changes[i].protect,
changes[i].lastUsed, changes[i].uniqueID, changes[i].advancedFields);
}
// permanently remove the deleted signons
var pass = this.deletedSignons;
for (var s = 0; s < pass.length; s++)
pm.removeUser(pass[s].host, pass[s].rawuser);
pass.length = 0;
// permanently remove the deleted rejects
var sites = this.deletedRejects;
for (var r = 0; r < sites.length; r++)
pm.removeReject(sites[r].host);
sites.length = 0;
}
},
// copy from IsOpenInDialog() defined above
IsOpenInDialog2 : function()
{
return document.getElementById('pref-passcards') != null;
},
// check if we're viewing from the Form Fill Option panel
IsOpenFormFillPanel : function()
{
return document.getElementById('autofillManager') != null;
},
/**
* Set the passcard (general) preferences
**/
pcSetPreferences : function()
{
var pm = this.GetInterface();
if (pm == null)
return;
dump("***** Passcard: SetPreferences()\n");
var prefAutologin = this.MenuAsString("pcAutologin");
var prefAutologinPrompt = "0";
var prefAutosave = this.MenuAsString("pcAutosave");
var prefAutosavePrompt = "0";
var prefHighlight = this.CheckedAsString("pcHighlight");
var prefFillAndSubmit = this.CheckedAsString("pcFillAndSubmit");
var prefDefaultPrompt = this.CheckedAsString("pcDefaultPrompt");
var prefUserID = ""; //this.ValueAsString("pcUserID");
var prefPassword = ""; //this.ValueAsString("pcPassword");
var prefProtect = this.CheckedAsString("pcPasswordProtect");
var prefPrompt = ""; //this.CheckedAsString("pcPasswordPrompt");
var prefExpire = 0; //parseInt(this.ValueAsString("pcPasswordExpire"));
/* TODO JVL: Remove if no longer necessary
if (!prefExpire || !(prefExpire >= 0 && prefExpire < this.kMaxExpireMinutes))
prefExpire = 0;
*/
pm.setPreferences(prefAutologin, prefAutologinPrompt, prefAutosave, prefAutosavePrompt, prefHighlight, prefFillAndSubmit,
prefDefaultPrompt, prefUserID, prefPassword, prefProtect, prefPrompt, prefExpire);
},
/**
* Get the password manager internal interface
**/
GetInterface : function()
{
return Components.classes["@mozilla.org/passwordmanager;1"].getService(Components.interfaces.nsIPasswordManager);
},
/**
* Return the boolean as a string value ("1" or "0")
**/
CheckedAsString : function(str)
{
var thePage = document.getElementById("autofilltabbox");
if (thePage)
{
return document.getElementById(str).checked ? "1" : "0";
}
else
{
dump("***** Passcard: Retrieving from WSM Data Manager\n");
var pageData = parent.wsm.dataManager.getPageData(this.kPageTag);
if (pageData && "initialized" in pageData && pageData.initialized && "elementIDs" in pageData)
{
var itemObject = pageData.elementIDs[str];
if (itemObject)
return itemObject.checked ? "1" : "0";
}
return "0";
}
},
/**
* Return the Value as a string value
**/
ValueAsString : function(str)
{
var thePage = document.getElementById("autofilltabbox");
if (thePage)
{
return document.getElementById(str).value;
}
else
{
dump("***** Passcard: Retrieving from WSM Data Manager\n");
var pageData = parent.wsm.dataManager.getPageData(this.kPageTag);
if (pageData && "initialized" in pageData && pageData.initialized && "elementIDs" in pageData)
{
var itemObject = pageData.elementIDs[str];
if (itemObject)
return itemObject.value;
}
return "";
}
},
/**
* Return the menu as a string value
**/
MenuAsString : function(str)
{
var thePage = document.getElementById("autofilltabbox");
if (thePage)
{
return document.getElementById(str).selectedIndex;
}
else
{
dump("***** Passcard: Retrieving from WSM Data Manager\n");
var pageData = parent.wsm.dataManager.getPageData(this.kPageTag);
if (pageData && "initialized" in pageData && pageData.initialized && "elementIDs" in pageData)
{
var itemObject = pageData.elementIDs[str];
if (itemObject)
return itemObject.selectedIndex;
}
return "0";
}
}
}