home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 December
/
PCWorld_2006-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-1-2.exe
/
chrome
/
browser.jar
/
content
/
browser
/
passcardUtils.js
< prev
next >
Wrap
Text File
|
2006-01-06
|
32KB
|
1,082 lines
/*
PasscardUtils
Initial refactoring of code from browser.js: JMckenty
*/
var kDefaultPasscard = "DefaultPasscard";
var kScreenNameService = "ScreenNameService";
var gPasscardMgr = null;
function passcardUtilsInit()
{
gPasscardMgr = Components.classes["@mozilla.org/passwordmanager;1"]
.getService(Components.interfaces.nsIPasswordManager);
}
function passcardDebug(aStr)
{
if (gPrefService.getPrefType("passcard.debug") &&
gPrefService.getBoolPref("passcard.debug"))
{
dump('PASSCARD: '+aStr+'\n');
}
}
function PasscardBlacklistSite()
{
gPasscardMgr.addReject(gBrowser.currentURI.host);
}
function PasscardIsSiteBlacklisted(aURI)
{
if (!aURI) return false;
if (!(aURI.scheme == 'http' || aURI.scheme == 'https'))
return false;
var dotTestHost = '.'+aURI.host.toLowerCase();
var enumerator = gPasscardMgr.rejectEnumerator;
while (enumerator.hasMoreElements()) {
var nextReject = enumerator.getNext();
nextReject.QueryInterface(Components.interfaces.nsIPassword);
var dotRejectHost = '.'+nextReject.host.toLowerCase();
var idx = dotTestHost.indexOf(dotRejectHost);
if (idx == -1) continue;
var tmp = dotTestHost.substring(idx);
if (tmp == dotRejectHost) return true;
}
return false;
}
function SetAsPasscardDefault(menulist)
{
passcardDebug('passcard uniqueID: ' + menulist.selectedItem.value);
var realm = new Object();
gPasscardMgr.getDomain(gBrowser.currentURI, realm);
passcardDebug('SetAsPasscardDefault(): realm: ' + realm.value);
gPasscardMgr.setAsLastUsedSignon(realm.value, menulist.selectedItem.value);
// update the passcard button label on the toolbar
SetPasscard();
/* used for testing
dump('***Passcard URI: ' + gBrowser.currentURI.host + '\n');
var enumerator = passwordManager.enumerator;
while (enumerator.hasMoreElements()) {
var nextPassword = enumerator.getNext();
nextPassword = nextPassword.QueryInterface(Components.interfaces.nsIPassword);
dump("***Passcard -- passcard: " + nextPassword.passcard +
" uniqueID: " + nextPassword.uniqueID + " lastUsed: " + nextPassword.lastUsed + "\n");
}
*/
}
// MERC - JCH: Fix for BLT#161274. If notification bar "Don't Show Again" checkbox
// is checked, hide the notification bar whenever passcard detects the site.
function SetDoNotShowPasscardMessageBar(list,checkbox)
{
if (gPasscardMgr == null)
return;
const DONT_SHOW_NOTIFICATION_BAR = 3;
const SHOW_NOTIFICATION_BAR = 0;
var currentURI = getWebNavigation().currentURI;
// realm is the base domain
var realm = new Object();
gPasscardMgr.getDomain(currentURI, realm);
var passcard = GetPasscard(realm.value, list.label);
var newval;
if (checkbox.checked) {
newval = DONT_SHOW_NOTIFICATION_BAR;
} else {
newval = SHOW_NOTIFICATION_BAR;
}
// Update passcard data.
gPasscardMgr.updateSignon(passcard.host, passcard.passcard, passcard.user, passcard.password,
newval, passcard.protect, passcard.lastUsed, passcard.uniqueID,
passcard.advancedFields, passcard.fraudProtected, passcard.snsEnabled);
}
function isPasscardHighlight()
{
if (passcardPreferences('Highlight') != "0")
return true;
return false;
}
function openSelectedPasscard(menulist) {
//var menulist = document.getElementById('messagePasscardList');
var passcardName = menulist.selectedItem.getAttribute('label');
gPrefService.setCharPref('browser.passcard.selectedcard', passcardName);
openPasscardPrefs();
}
// MERC - JCH : need to select the proper tab when pref dialog opens
function openPasscardPrefs() {
gPrefService.setCharPref('browser.preferences.formfillORpasscard', 'passcardtab');
openPrefs(PREF_AUTOFILL);
}
// MERC JVL
// Save the current fields on the form as a passcard
function savePasscard() {
var hpDoc = getTridentDocument();
if (hpDoc) {
// fire Trident side
passcardDebug('********* SavePasscard via Trident **********');
hpDoc.savePasscard();
}
else
{
// fire Gecko side
passcardDebug('********* SavePasscard via Gecko **********');
gPasscardMgr.savePasscard(gBrowser.contentDocument);
}
}
// delete the old passcard menu items
function clearPasscardMenu() {
var menu = document.getElementById('combinedFormFillPopup');
if (!menu) return;
var pcSep = document.getElementById('combinedFormFillPasscardSep');
pcSep.setAttribute('hidden', 'true');
var child = menu.lastChild;
while (child) {
nextChild = child.previousSibling;
if (child.hasAttribute('passcard')) {
menu.removeChild(child);
}
child = nextChild;
}
}
function GetWebmailPasscard(domain, key)
{
if (!domain || domain == '') return null;
passcardDebug('GetWebmailPasscard('+domain+', '+key+')');
var enumerator = gPasscardMgr.enumerator;
while (enumerator.hasMoreElements()) {
var nextPasscard = enumerator.getNext();
nextPasscard = nextPasscard.QueryInterface(Components.interfaces.nsIPassword);
if ((domain == nextPasscard.host) && (nextPasscard.passcard == key)) {
return nextPasscard;
}
}
return null;
}
function GetDefaultPasscard()
{
return GetPasscard('DefaultPasscard', 'DefaultPasscard');
}
function GetPasscard(domain, key)
{
if (!domain || domain == '') return null;
passcardDebug('GetPasscard('+domain+', '+key+')');
var enumerator = gPasscardMgr.enumerator;
while (enumerator.hasMoreElements()) {
var nextPasscard = enumerator.getNext();
nextPasscard = nextPasscard.QueryInterface(Components.interfaces.nsIPassword);
if ((domain == nextPasscard.host) && (nextPasscard.passcard == key)) {
return nextPasscard;
}
}
return null;
}
function GetFirstPasscardForSite(domain)
{
if (!domain || domain == '') return null;
passcardDebug('GetPasscard('+domain+')');
var enumerator = gPasscardMgr.enumerator;
while (enumerator.hasMoreElements()) {
var nextPasscard = enumerator.getNext();
nextPasscard = nextPasscard.QueryInterface(Components.interfaces.nsIPassword);
if ((domain == nextPasscard.host)) {
return nextPasscard;
}
}
return null;
}
// MERC (DP): get a list of passcards for URL
// MERC - JCH: Changing menu ids for new combined datacard-passcard button.
function updatePasscardMenu(menu) {
// keep track of number of passcards found for the specific realm
var passcardCount = 0;
var foundSitePasscards = false;
var addDefaultPasscard = false;
var defaultName = "";
var defaultUniqueID = -1;
var currentURI = getWebNavigation().currentURI;
try {
// realm is the base domain
var realm = new Object();
gPasscardMgr.getDomain(currentURI, realm);
passcardDebug('***Passcard -- realm: ' + realm.value);
var enumerator = gPasscardMgr.enumerator;
while (enumerator.hasMoreElements()) {
var nextPasscard = enumerator.getNext();
nextPasscard = nextPasscard.QueryInterface(Components.interfaces.nsIPassword);
var host = nextPasscard.host;
passcardDebug("***Passcard -- host: " + host);
if (realm.value && realm.value == host) {
var uniqueID = nextPasscard.uniqueID;
var passcard = nextPasscard.passcard;
var lastUsed = nextPasscard.lastUsed;
passcardDebug("***Passcard -- passcard: " + passcard +
" uniqueID: " + uniqueID + " lastUsed: " + lastUsed);
/* // if this is the first passcard menu item, put a menu separator before
var menuitem;
if (passcardCount == 0) {
menuitem = document.createElement("menuseparator");
menu.appendChild(menuitem);
} */
// create a new menuitem to add to the dropdown list
menuitem = document.createElement("menuitem");
menuitem.setAttribute('label', passcard);
menuitem.setAttribute('host', host);
menuitem.setAttribute('uniqueID', uniqueID);
menuitem.setAttribute('lastUsed', lastUsed);
menuitem.setAttribute('type', 'checkbox');
menuitem.setAttribute('passcard', 'true');
//menuitem.setAttribute('tooltiptext', 'UserID: ' + user);
menuitem.setAttribute('oncommand', 'setPasscardDefault(this);');
// find the default passcard for site
if (eval(lastUsed)) {
menuitem.setAttribute('checked', 'true');
} else {
menuitem.setAttribute('checked', 'false');
}
menu.appendChild(menuitem);
passcardCount++;
foundSitePasscards = true;
}
else if (kDefaultPasscard == host) {
defaultName = nextPasscard.passcard;
defaultUniqueID = nextPasscard.uniqueID;
// if it is protected, we will assume that the user has a valid Default Passcard
addDefaultPasscard = IsProtectedAndPopulatedPasscard(nextPasscard);
}
} // while
} catch(e) {}
// Toggle visibility of menu separator, depending on whether
// passcards were listed
var pcSep = document.getElementById('combinedFormFillPasscardSep');
if (pcSep && foundSitePasscards) {
pcSep.removeAttribute('hidden');
} else {
pcSep.setAttribute('hidden', 'true');
}
if (addDefaultPasscard && !foundSitePasscards &&
defaultName.length > 0 && defaultUniqueID != -1)
{
dump("***Default Passcard -- passcard: " + defaultName + " uniqueID: " + defaultUniqueID + "\n");
// add a menu separator before
//menu.appendChild(document.createElement("menuseparator"));
pcSep.removeAttribute('hidden');
// create a new menuitem to add to the dropdown list
var menuitem = document.createElement("menuitem");
menuitem.setAttribute('label', defaultName);
menuitem.setAttribute('host', kDefaultPasscard);
menuitem.setAttribute('uniqueID', defaultUniqueID);
menuitem.setAttribute('lastUsed', '1');
menuitem.setAttribute('type', 'checkbox');
//menuitem.setAttribute('tooltiptext', 'UserID: ' + user);
menuitem.setAttribute('oncommand', 'setPasscardDefault(this);');
menuitem.setAttribute('checked', 'true');
menuitem.setAttribute('passcard', 'true');
menu.appendChild(menuitem);
passcardCount++;
}
// if there are no passcards found, disable fill menu item
var fillItem = document.getElementById('combinedFillFormMenuItem');
var fillSubmitItem = document.getElementById('combinedFillAndSubmitMenuItem');
if (passcardCount > 0) {
fillItem.removeAttribute('disabled');
fillSubmitItem.removeAttribute('disabled');
} else {
fillItem.setAttribute('disabled', 'true');
fillSubmitItem.setAttribute('disabled', 'true');
}
// MERC JVL
// if there are no password fields (HTML INPUT type fields)
// on the form, disable the Save Passcard menu item
// var savePasscardMenuItem = document.getElementById('savePasscardMenuItem');
var savePasscardMenuItem = document.getElementById('combinedSaveMenuItem');
if (CheckIsPasscardable(false) && !PasscardIsSiteBlacklisted(currentURI))
{
passcardDebug(' - enabling save');
savePasscardMenuItem.removeAttribute('disabled');
}
else
{
passcardDebug(' - disabling save');
savePasscardMenuItem.setAttribute('disabled', 'true');
}
}
// MERC JVL
// helper function to check of a passcard is protected and has a username/password
function IsProtectedAndPopulatedPasscard(passcard)
{
// if it is protected, we will assume that the user has a populated Passcard
if (passcard.protect == 0 &&
(passcard.user.length < 1 || passcard.password.length < 1))
{
return false;
}
return true;
}
// MERC JVL
// helper function to check if a passcard can be
// applied to the form, regardless of engine
function CheckIsPasscardable(bIgnoreValue)
{
var bIsPasscardable = false;
var hpDoc = getTridentDocument();
if (hpDoc)
{
// fire Trident side
bIsPasscardable = hpDoc.isPasscardable(bIgnoreValue);
}
else
{
// fire Gecko side
bIsPasscardable = IsPasscardable(gBrowser.contentDocument, bIgnoreValue);
}
return bIsPasscardable;
}
// TODO JVL : Would be useful in XPCom - move functionality to XPCom when there's a chance to do so
// MERC JVL
// Checks current document and its 'frame' ('iframe' and 'object' as well) for a
// potential Passcard (looks for documents with only one password field and not two)
// RECURSIVE!!!
const NO_PASSWORD_FIELD = 0;
const FOUND_A_PASSCARD = 1;
const NOT_A_PASSCARD = 2;
function IsPasscardable(doc, bIgnoreValue)
{
if (!doc)
return false;
var inputTextElement = null;
var isPasscard = NO_PASSWORD_FIELD;
var idx = 0;
var inputElements = doc.getElementsByTagName('input');
while (isPasscard != NOT_A_PASSCARD && idx < inputElements.length)
{
var inputElement = inputElements.item(idx);
if (inputElement != null)
{
var elementType = inputElement.getAttribute('type');
if (elementType == 'text' || elementType == null)
{
// found a text field, may be the username field,
// store reference to object for later use
inputTextElement = inputElement;
}
else if (elementType == 'password')
{
// if we encountered a second password field,
// this form is probably not passcardable, bail
if (isPasscard == FOUND_A_PASSCARD)
{
// MERC CCOTE bug fix blt 202309
var previousIdx= idx-1;
var previousInputElement = inputElements.item(previousIdx);
var previousElementType = previousInputElement.getAttribute('type');
if(previousElementType == 'password') isPasscard = NOT_A_PASSCARD;
}
else if (isPasscard == NO_PASSWORD_FIELD)
{
// look for a set of username/password fields
if (inputElement.value != "" || bIgnoreValue)
{
if (inputTextElement != null)
{
if (inputTextElement.value != "" || bIgnoreValue)
{
// found a set of username/password fields
isPasscard = FOUND_A_PASSCARD;
}
}
// TODO JVL - Added to handle static username input text field case
else
{
isPasscard = FOUND_A_PASSCARD;
}
}
}
}
}
idx++;
}
// haven't found a password field in this frame, check child frames
if (isPasscard == NO_PASSWORD_FIELD)
{
isPasscard = IsPasscardInFrames(doc, 'iframe', bIgnoreValue);
if (isPasscard == NO_PASSWORD_FIELD)
isPasscard = IsPasscardInFrames(doc, 'frame', bIgnoreValue);
if (isPasscard == NO_PASSWORD_FIELD)
isPasscard = IsPasscardInFrames(doc, 'object', bIgnoreValue);
}
return isPasscard == FOUND_A_PASSCARD;
}
// MERC JVL
// Checks for a passcard in a 'frame' document ('iframe' and 'object' as well)
// RECURSIVE!!!
function IsPasscardInFrames(doc, elementName, bIgnoreValue)
{
var isPasscard = NO_PASSWORD_FIELD;
var iframeElements = doc.getElementsByTagName(elementName);
var idx = 0; // JMC: Bad strict, should not redeclare
while (isPasscard == NO_PASSWORD_FIELD && idx < iframeElements.length)
{
var iframeElement = iframeElements.item(idx);
if (iframeElement)
{
if (IsPasscardable(iframeElement.contentDocument, bIgnoreValue))
isPasscard = FOUND_A_PASSCARD;
}
idx++;
}
return isPasscard;
}
function passcardAllowHost(aHost)
{
// showStack();
passcardDebug(" is " + aHost + " an allowed passcard host?");
var enumerator = gPasscardMgr.rejectEnumerator;
while (enumerator.hasMoreElements())
{
var nextReject = enumerator.getNext();
nextReject = nextReject.QueryInterface(Components.interfaces.nsIPassword);
if (nextReject.host == aHost)
{
passcardDebug("It's a reject");
return false;
}
}
if (gOptout.isInList(aHost))
{
passcardDebug("It's an Optout");
return false;
}
return true;
}
// MERC - JCH: Check if the page has a password field.
// If so, alert the user with notification bar.
function CheckForPasscardField()
{
// realm is the base domain
var realm = new Object();
if (gBrowser.currentURI && (gBrowser.currentURI.schemeIs("http") ||
gBrowser.currentURI.schemeIs("https")) )
{
var passcardMgrInternal = Components.classes["@mozilla.org/passwordmanager;1"]
.getService(Components.interfaces.nsIPasswordManagerInternal);
if (!passcardMgrInternal)
return false;
passcardDebug('uri (as a spec): ' + gBrowser.currentURI.spec);
passcardMgrInternal.ParseRealm(gBrowser.currentURI, realm, true, false);
passcardDebug('realm: ' + realm.value);
if (realm.value == null)
return false;
} else {
return false;
}
if (!passcardAllowHost(realm.value))
{
return false;
}
var bFoundPasscard = false;
var bShowNotification = false;
try {
// now check if the passcard is set to prompt
enumerator = gPasscardMgr.enumerator;
while (!bFoundPasscard && enumerator.hasMoreElements())
{
var nextPasscard = enumerator.getNext();
nextPasscard = nextPasscard.QueryInterface(Components.interfaces.nsIPassword);
if (isValidPasscardHost(nextPasscard.host,nextPasscard.lastUsed, realm.value)||
isValidSnsPasscardHost(nextPasscard.host, realm.value))
{
bFoundPasscard = true;
bShowNotification = nextPasscard.autologin == 0 && // display prompt
IsProtectedAndPopulatedPasscard(nextPasscard);
}
}
} catch (ex) { }
if (!bFoundPasscard)
{
bShowNotification = IsDisplayBrowserBarForDefaultPasscard();
passcardDebug('Checking if DefaultPasscard exists: ' + bShowNotification);
}
var bPasswordFieldExists = CheckIsPasscardable(true);
passcardDebug('Is Passcardable?: ' + bPasswordFieldExists);
passcardDebug('***** Notification bar state: '+gCurrentNotificationBar);
// If password field exists and passcard is set to show a prompt,
// then show the notification bar.
if (bShowNotification && bPasswordFieldExists)
{
ShowPasscardBar();
}
else
{
HidePasscardBar();
}
// if there is a password field, we don't want to display the datacard notification bar even if
// the passcard notification bar is not displayed
return bPasswordFieldExists;
}
function ShowPasscardBar()
{
displayNotificationBar("passcard");
/* var message;
var bundle_browser = document.getElementById("bundle_browser");
message = bundle_browser.getString("passcardMsg");
gBrowser.showMessage(gBrowser.selectedBrowser, "chrome://browser/skin/icons/passwordsm_h.png",
message, "", null, null, null, "top", true, 1); */
}
function HidePasscardBar()
{
if (gCurrentNotificationBar == 'passcard') {
var tabbrowser = getBrowser();
tabbrowser.hideMessage(tabbrowser.selectedBrowser, "top");
}
}
function IsDisplayBrowserBarForDefaultPasscard()
{
// search for default passcard
var enumerator = gPasscardMgr.enumerator;
while (enumerator.hasMoreElements())
{
try
{
var nextPasscard = enumerator.getNext();
// get all info for the passcard
nextPasscard = nextPasscard.QueryInterface(Components.interfaces.nsIPassword);
if (nextPasscard.host == kDefaultPasscard)
{
return nextPasscard.autologin == 0 && IsProtectedAndPopulatedPasscard(nextPasscard);
}
}
catch (ex) {}
}
return false;
}
function setPasscardDefault(menuitem) {
if(eval(menuitem.getAttribute('lastUsed')))
return;
// if the menuitem is NOT the default passcard...
var enumerator = gPasscardMgr.enumerator;
// realm is the base domain
var realm = new Object();
gPasscardMgr.getDomain(getWebNavigation().currentURI, realm);
if (realm.value == null)
return; // currentURI was probably null
// set select passcard as lastUsed
// NOTE: This operation does not reset the checked state for the selected menuitem
gPasscardMgr.setAsLastUsedSignon(menuitem.getAttribute('host'),
menuitem.getAttribute('uniqueID'));
// update the browser message bar if it is shown
UpdatePasscardMessageBar(menuitem.getAttribute('label'));
// update the passcard button label on the toolbar
SetPasscard();
passcardDebug('***default -- passcard: ' + menuitem.getAttribute('label'));
fillUsernamePassword(menuitem, false);
}
// update the browser message bar (if it is shown) with the current passcard
function UpdatePasscardMessageBar(menuLabel)
{
if (gCurrentNotificationBar != "passcard")
return;
if (menuLabel == null || menuLabel.length < 1)
return;
var theMenulist = document.getAnonymousElementByAttribute(gBrowser.mCurrentBrowser.previousSibling, 'anonid', 'messagePasscardList');
if (theMenulist == null)
return;
var theMenupopup = theMenulist.childNodes[0];
if (!theMenupopup || theMenupopup.localName != 'menupopup')
return;
var i;
for (i = 0; i < theMenupopup.childNodes.length; i++)
{
var child = theMenupopup.childNodes[i];
//passcardDebug('*** menuitem: child: ' + child.getAttribute('label') + ', menuitem: ' + menuLabel);
if (child.getAttribute('label') == menuLabel)
{
theMenulist.selectedIndex = i;
break;
}
}
}
//MERC: Durga
//Display default passcard on toolbar in text mode
function SetPasscard()
{
passcardDebug('SetPasscard()');
var enumerator = gPasscardMgr.enumerator;
var realm = new Object();
var host;
var password;
var passcard;
var nextPassword;
var numFound = 0;
var lastUsed;
var lastUsedName;
/* var filler1 = new Object();
var filler2 = new Object();
var filler3 = new Object();
var filler4 = new Object();
var filler5 = new Object();
var filler6 = new Object();
*/
// If passcard button is not present, no need to update it
// MERC - JCH: Use the combined datacard/passcard button ID
var button = document.getElementById("combined-autofill-button");
if (!button) return;
// Update button to generic setting
// MERC - JCH: Changing button name from 'passcard' to 'autofill'.
button.setAttribute("label", "Autofill");
button.removeAttribute("match");
// Check for realm
gPasscardMgr.getDomain(getWebNavigation().currentURI, realm);
if (realm.value == null)
return; // currentURI was probably null
passcardDebug("***Passcard -- realm: " + realm.value);
// search for default passcard
while (enumerator.hasMoreElements()) {
try {
nextPassword = enumerator.getNext();
// get all info for the passcard
nextPassword = nextPassword.QueryInterface(Components.interfaces.nsIPassword);
host = nextPassword.host;
lastUsed = nextPassword.lastUsed;
passcard = nextPassword.passcard;
if (realm.value == host) {
// This passcard matches the site
passcardDebug("***Passcard -- lastUsed: " + lastUsed);
passcardDebug("***Passcard -- passcard: " + passcard);
numFound++;
if (lastUsed == 1) {
// Set button label
dump("\n**Setting label to passcard: " + passcard + "**\n");
// BC: BLT #176383:
/* Expected Result:
* The Autofill button shouldn't be renamed, Clear History button and Netscape
* logo should visible on the screen.
* BC: Not sure why someone tried to add this, but the autofill label
* should NOT be changed.
*/
//button.setAttribute("label", passcard);
button.setAttribute("match", "true");
}
if (lastUsed == 1 || !lastUsedName) {
lastUsedName = passcard;
}
}
}
catch(e)
{
passcardDebug ("caught exception: " + e);
}
}
if (numFound > 1) {
button.setAttribute("label", lastUsedName + '+'+numFound);
button.setAttribute("match", "true");
}
} // end function
// MERC - JCH: This function is called from browser.xml: "browsermessage" binding.
// When submitFlag is false we don't submit the passcard info, when it's true we do.
function ParameterizedDoPasscard(submitFlag)
{
var theMenulist = document.getAnonymousElementByAttribute(gBrowser.mCurrentBrowser.previousSibling, 'anonid', 'messagePasscardList');
if (theMenulist)
{
passcardDebug("Currently selected Passcard in Browser Message Bar: " + theMenulist.label);
if (theMenulist.label.length > 0)
gPasscardMgr.useSpecialPasscard = theMenulist.label;
}
var hpDoc = getTridentDocument();
if (hpDoc)
{
// fire Trident side
if (submitFlag)
{
passcardDebug('********* DoFillFormAndSubmit via Trident **********');
hpDoc.doPasscardFillFormAndSubmit();
}
else
{
passcardDebug('********* DoFillForm via Trident **********');
hpDoc.doPasscardFillForm();
}
}
else
{
// fire Gecko side
passcardDebug('********* DoPasscardOneTime via Gecko **********');
var enumerator = gPasscardMgr.enumerator;
var realm = new Object();
var host;
var password;
var uniqueID;
var nextPassword;
var lastUsed;
var passcardFound = false;
var filler1 = new Object();
var filler2 = new Object();
var filler3 = new Object();
var filler4 = new Object();
var filler5 = new Object();
var filler6 = new Object();
var filler7 = new Object();
var filler8 = new Object();
var filler9 = new Object();
var filler10 = new Object();
var bUseSpecialPasscard = false;
var specialPasscard = gPasscardMgr.useSpecialPasscard;
if (specialPasscard.length > 0)
{
if (specialPasscard == kDefaultPasscard ||
specialPasscard == kScreenNameService)
bUseSpecialPasscard = true;
}
if (!bUseSpecialPasscard && enumerator.hasMoreElements())
{
gPasscardMgr.getDomain(getWebNavigation().currentURI, realm);
//passcardDebug('REALM: ' + realm + ' VALUE: ' + realm.value);
if (realm.value != null)
{
passcardDebug("***Passcard -- realm: " + realm.value);
// search for default passcard
while (enumerator.hasMoreElements() && !passcardFound) {
try {
nextPassword = enumerator.getNext();
// get all info for the passcard
nextPassword = nextPassword.QueryInterface(Components.interfaces.nsIPassword);
host = nextPassword.host;
lastUsed = nextPassword.lastUsed;
uniqueID = nextPassword.uniqueID;
if (realm.value == host && lastUsed==1)
{
passcardDebug("***Passcard -- lastUsed: " + lastUsed);
passcardFound = true;
passcardDebug('********* DoPasscardOneTime via Gecko, found passcard! **********');
gPasscardMgr.passcardFillRootDoc(gBrowser.contentDocument, host, uniqueID, submitFlag, false);
}
} catch(e) {}
}
}
}
if (!passcardFound) {
// use default user/password
passcardDebug('********* ParameterizedDoPasscard via Gecko, use default! **********');
gPasscardMgr.passcardDefaultRootDoc(gBrowser.contentDocument, submitFlag, true);
}
}
if (theMenulist)
gPasscardMgr.useSpecialPasscard = "";
} // end function
function passcardPreferences(prefName) {
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 prefDefaultUser = new Object();
var prefDefaultPassword = new Object();
var prefProtect = new Object();
var prefPrompt = new Object();
var prefExpire = new Object();
var prefVersion = new Object();
gPasscardMgr.getPreferences(prefAutologin, prefAutologinPrompt, prefAutosave,
prefAutosavePrompt, prefHighlight, prefFillAndSubmit,
prefDefaultPrompt, prefDefaultUser, prefDefaultPassword,
prefProtect, prefPrompt, prefExpire, prefVersion);
return eval('pref' + prefName + '.value'); //JMC: Cheap Hack
}
//MERC: Durga
//Retrieve passcard for specific url when toolbar button is clicked
function DoPasscardOneTime()
{
var hpDoc = getTridentDocument();
if (hpDoc)
{
// fire Trident side
passcardDebug('********* DoPasscardOneTime via Trident **********');
hpDoc.doPasscardOneTime(); // if Fill & Submit preference set, doPasscardOneTime() will call submit (see Trident CPasscards::OnToolbarButton())
}
else
{
// fire Gecko side
passcardDebug('********* DoPasscardOneTime via Gecko **********');
var enumerator = gPasscardMgr.enumerator;
var realm = new Object();
var host;
var password;
var uniqueID;
var nextPassword;
var lastUsed;
var passcardFound = false;
var filler1 = new Object();
var filler2 = new Object();
var filler3 = new Object();
var filler4 = new Object();
var filler5 = new Object();
var filler6 = new Object();
var filler7 = new Object();
var filler8 = new Object();
var filler9 = new Object();
var filler10 = new Object();
var bSubmitForm = isPasscardFillAndSubmit();
if (enumerator.hasMoreElements())
{
gPasscardMgr.getDomain(getWebNavigation().currentURI, realm);
//passcardDebug('REALM: ' + realm + ' VALUE: ' + realm.value);
if (realm.value != null)
{
passcardDebug("***Passcard -- realm: " + realm.value);
// search for default passcard
while (enumerator.hasMoreElements() && !passcardFound) {
try {
nextPassword = enumerator.getNext();
// get all info for the passcard
nextPassword = nextPassword.QueryInterface(Components.interfaces.nsIPassword);
host = nextPassword.host;
lastUsed = nextPassword.lastUsed;
uniqueID = nextPassword.uniqueID;
if(realm.value == host && lastUsed==1)
{
passcardDebug("***Passcard -- lastUsed: " + lastUsed);
passcardFound = true;
passcardDebug('********* DoPasscardOneTime via Gecko, found passcard! **********');
gPasscardMgr.passcardFillRootDoc(gBrowser.contentDocument, host, uniqueID, bSubmitForm, false);
}
} catch(e) {}
}
}
}
if (!passcardFound) {
// use default user/password
passcardDebug('********* DoPasscardOneTime via Gecko, use default! **********');
gPasscardMgr.passcardDefaultRootDoc(gBrowser.contentDocument, bSubmitForm, false);
}
}
} // end function
function isPasscardFillAndSubmit()
{
// TODO JVL : Need to revisit when passcard preferences are stored in browser prefs, but for now, this will do
if (gPasscardMgr == null)
return false;
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 prefProtect = new Object();
var prefPrompt = new Object();
var prefExpire = new Object();
var prefVersion = new Object();
gPasscardMgr.getPreferences(prefAutologin, prefAutologinPrompt, prefAutosave,
prefAutosavePrompt, prefHighlight, prefFillAndSubmit,
prefDefaultPrompt, prefUserID, prefPassword,
prefProtect, prefPrompt, prefExpire, prefVersion);
if (prefFillAndSubmit.value != "0")
return true;
return false;
}
function fillUsernamePassword(menuitem, bSubmitForm) {
var hpDoc = getTridentDocument();
if (hpDoc)
{
// fire Trident side
if (bSubmitForm)
{
passcardDebug('********* DoFillFormAndSubmit via Trident **********');
hpDoc.doPasscardFillFormAndSubmit();
}
else
{
passcardDebug('********* DoFillForm via Trident **********');
hpDoc.doPasscardFillForm();
}
}
else
{
var bFound = false;
var myHost = menuitem.getAttribute('host');
var myUniqueID = menuitem.getAttribute('uniqueID');
if (myHost.length > 0 && myUniqueID.length > 0)
{
bFound = true;
}
else
{
var nextItem = menuitem.nextSibling;
while (!bFound && nextItem != null)
{
if (nextItem.getAttribute('lastUsed') == "1")
{
myHost = nextItem.getAttribute('host');
myUniqueID = nextItem.getAttribute('uniqueID');
bFound = true;
}
else
{
nextItem = nextItem.nextSibling;
}
}
}
if (bFound)
{
passcardDebug('*********** fillUsernamePassword() ********************');
passcardDebug('host: ' + myHost + ' ID: ' + myUniqueID + ' submitForm: ' + bSubmitForm);
gPasscardMgr.passcardFillRootDoc(gBrowser.contentDocument, myHost, myUniqueID, bSubmitForm, false);
}
}
}
//MERC CCOTE BLT fix 196092
// Return true or false if the current host is a match for this passcard
function isValidPasscardHost(aPasscardHost,aPasscardLastUsed, aHost){
if(aPasscardHost == aHost && aPasscardLastUsed == 1) return true;
return false
}
//MERC CCOTE BLT fix 196092
// Return true or false if the current host is a match for the SNS passcard
function isValidSnsPasscardHost(aPasscardHost, aHost){
if(aPasscardHost == 'ScreenNameService' && isSNSSite(aHost)) return true;
return false
}