*doPrefillMessage = !gEncryptionFailure;
if (!gEncryptionFailure) { PRUnichar * message = Wallet_Localize("noPrefills"); wallet_Alert(message, win); Recycle(message); }
WLLT_Prefill(nsIPresShell* shell, PRBool quick, PRBool* doPrefillMessage){  nsAutoString urlName;  *doPrefillMessage = PR_FALSE;  /* create list of elements that can be prefilled */  nsVoidArray *wallet_PrefillElement_list=new nsVoidArray();  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)  {    nsCOMPtr<nsIDocument> doc;    shell->GetDocument(getter_AddRefs(doc));    if (doc)    {      nsCOMPtr<nsIURI> url = getter_AddRefs(doc->GetDocumentURL());      if (url) {        wallet_GetHostFile(url, urlName);      }      wallet_Initialize(PR_TRUE);      gEncryptionFailure = PR_FALSE;      wallet_InitializeCurrentURL(doc);            nsCOMPtr<nsIDOMHTMLDocument> htmldoc = do_QueryInterface(doc);      if (htmldoc)      {        nsCOMPtr<nsIDOMHTMLCollection> forms;        htmldoc->GetForms(getter_AddRefs(forms));        if (forms)        {          PRUint32 numForms;          forms->GetLength(&numForms);          for (PRUint32 formX = 0; (formX < numForms) && !gEncryptionFailure; formX++)          {            nsCOMPtr<nsIDOMNode> formNode;            forms->Item(formX, getter_AddRefs(formNode));            if (formNode)            {              nsCOMPtr<nsIDOMHTMLFormElement> formElement = do_QueryInterface(formNode);              if (formElement)              {                nsCOMPtr<nsIDOMHTMLCollection> elements;                result = formElement->GetElements(getter_AddRefs(elements));                if (elements)                {                  /* got to the form elements at long last */                  PRUint32 numElements;                  elements->GetLength(&numElements);                  for (PRUint32 elementX = 0; (elementX < numElements) && !gEncryptionFailure; elementX++)                  {                    nsCOMPtr<nsIDOMNode> elementNode;                    elements->Item(elementX, getter_AddRefs(elementNode));                    if (elementNode)                    {                      wallet_PrefillElement * prefillElement;                      PRInt32 index = 0;                      wallet_PrefillElement * firstElement = nsnull;                      PRUint32 numberOfElements = 0;                      for (; !gEncryptionFailure;) {                        /* 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 = PR_NEW(wallet_PrefillElement);                        if (wallet_GetPrefills                            (elementNode,                            prefillElement->inputElement,                            prefillElement->selectElement,                            prefillElement->schema,                            prefillElement->value,                            prefillElement->selectIndex,                            index) != -1) {                          /* another value found */                          if (nsnull == firstElement) {                            firstElement = prefillElement;                          }                          numberOfElements++;                          prefillElement->count = 0;                          wallet_PrefillElement_list->AppendElement(prefillElement);                        } else {                          /* value not found, stop looking for more values */                          delete prefillElement;                          break;                        }                      } // for                                            if (numberOfElements>0) {                        firstElement->count = numberOfElements;                      }                    }                                      } // for                                  }              }            }          }        }      }    }  }  /* return if no elements were put into the list */  if (LIST_COUNT(wallet_PrefillElement_list) == 0) {    *doPrefillMessage = !gEncryptionFailure;    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();    nsVoidArray* dummy;    nsAutoString value; value.AssignWithConversion("nn");    if (urlName.Length() != 0) {      wallet_ReadFromList(urlName, value, dummy, wallet_URL_list, PR_FALSE);      noPreview = (value.CharAt(NO_PREVIEW) == 'y');    }  }  /* determine if preview is necessary */  if (noPreview || quick) {    /* prefill each element without any preview for user verification */    wallet_PrefillElement * ptr;    PRInt32 count = LIST_COUNT(wallet_PrefillElement_list);    for (PRInt32 i=0; i<count; i++) {      ptr = NS_STATIC_CAST(wallet_PrefillElement*, wallet_PrefillElement_list->ElementAt(i));      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 = urlName;#ifdef DEBUG////wallet_DumpStopwatch();////wallet_ClearStopwatch();//wallet_DumpTiming();//wallet_ClearTiming();#endif    return NS_OK; // indicates that caller is to display preview screen  }}