if (Wallet_KeySet()) { char * message = Wallet_Localize("noPrefills"); Wallet_Alert(message); PR_FREEIF(message); }
WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) {  /* create list of elements that can be prefilled */  XP_List *wallet_PrefillElement_list=XP_ListNew();  if (!wallet_PrefillElement_list) {    return NS_ERROR_FAILURE;  }  /* starting with the present shell, get each form element and put them on a list */  nsresult result;  if (nsnull != shell) {    nsIDocument* doc = nsnull;    result = shell->GetDocument(&doc);    if (NS_SUCCEEDED(result)) {      wallet_Initialize();      wallet_InitializeCurrentURL(doc);      nsIDOMHTMLDocument* htmldoc = nsnull;      nsresult result = doc->QueryInterface(kIDOMHTMLDocumentIID, (void**)&htmldoc);      if ((NS_SUCCEEDED(result)) && (nsnull != htmldoc)) {        nsIDOMHTMLCollection* forms = nsnull;        htmldoc->GetForms(&forms);        if (nsnull != forms) {          PRUint32 numForms;          forms->GetLength(&numForms);          for (PRUint32 formX = 0; formX < numForms; formX++) {            nsIDOMNode* formNode = nsnull;            forms->Item(formX, &formNode);            if (nsnull != formNode) {              nsIDOMHTMLFormElement* formElement = nsnull;              result = formNode->QueryInterface(kIDOMHTMLFormElementIID, (void**)&formElement);              if ((NS_SUCCEEDED(result)) && (nsnull != formElement)) {                nsIDOMHTMLCollection* elements = nsnull;                result = formElement->GetElements(&elements);                if ((NS_SUCCEEDED(result)) && (nsnull != elements)) {                  /* got to the form elements at long last */                  PRUint32 numElements;                  elements->GetLength(&numElements);                  for (PRUint32 elementX = 0; elementX < numElements; elementX++) {                    nsIDOMNode* elementNode = nsnull;                    elements->Item(elementX, &elementNode);                    if (nsnull != elementNode) {                      wallet_PrefillElement * prefillElement;                      XP_List * resume = nsnull;                      wallet_PrefillElement * firstElement = nsnull;                      PRUint32 numberOfElements = 0;                      for (;;) {                        /* loop to allow for multiple values */                        /* first element in multiple-value group will have its count                         * field set to the number of elements in group.  All other                         * elements in group will have count field set to 0                         */                        prefillElement = XP_NEW(wallet_PrefillElement);                        if (wallet_GetPrefills                            (elementNode,                            prefillElement->inputElement,                            prefillElement->selectElement,                            prefillElement->schema,                            prefillElement->value,                            prefillElement->selectIndex,                            resume) != -1) {                          /* another value found */                          prefillElement->resume = resume;                          if (nsnull == firstElement) {                            firstElement = prefillElement;                          }                          numberOfElements++;                          prefillElement->count = 0;                          XP_ListAddObjectToEnd(wallet_PrefillElement_list, prefillElement);                          if (nsnull == resume) {                            /* value was found from concat rules, can't resume from here */                            break;                          }                        } else {                          /* value not found, stop looking for more values */                          delete prefillElement;                          break;                        }                      }                      if (numberOfElements>0) {                        firstElement->count = numberOfElements;                      }                      NS_RELEASE(elementNode);                    }                  }                  NS_RELEASE(elements);                }                NS_RELEASE(formElement);              }              NS_RELEASE(formNode);            }          }          NS_RELEASE(forms);        }        NS_RELEASE(htmldoc);      }      NS_RELEASE(doc);    }    NS_RELEASE(shell);  }  /* return if no elements were put into the list */  if (!wallet_PrefillElement_list || !XP_ListCount(wallet_PrefillElement_list)) {    return NS_ERROR_FAILURE; // indicates to caller not to display preview screen  }  /* prefill each element using the list */  /* determine if url is on list of urls that should not be previewed */  PRBool noPreview = PR_FALSE;  if (!quick) {    wallet_InitializeURLList();    XP_List* URL_list = wallet_URL_list;    XP_List* dummy;    nsAutoString * value = new nsAutoString("nn");    nsAutoString * urlPtr = new nsAutoString(url);    if (!value || !urlPtr) {      wallet_ReadFromList(*urlPtr, *value, dummy, URL_list);      noPreview = (value->CharAt(NO_PREVIEW) == 'y');      delete value;      delete urlPtr;    }  }  /* determine if preview is necessary */  if (noPreview || quick) {    /* prefill each element without any preview for user verification */    XP_List * list_ptr = wallet_PrefillElement_list;    wallet_PrefillElement * ptr;    while((ptr = (wallet_PrefillElement *) XP_ListNextObject(list_ptr))!=0) {      if (ptr->count) {        if (ptr->inputElement) {          ptr->inputElement->SetValue(*(ptr->value));        } else {          ptr->selectElement->SetSelectedIndex(ptr->selectIndex);        }      }    }    /* go thru list just generated and release everything */    wallet_ReleasePrefillElementList(wallet_PrefillElement_list);    return NS_ERROR_FAILURE; // indicates to caller not to display preview screen  } else {    /* let user preview and verify the prefills first */    wallet_list = wallet_PrefillElement_list;    wallet_url = url;#ifdef DEBUGwallet_DumpStopwatch();wallet_ClearStopwatch();//wallet_DumpTiming();//wallet_ClearTiming();#endif    return NS_OK; // indicates that caller is to display preview screen  }}