(OKToPrompt) && wallet_OKToCapture(strippedURLNameUTF8, window)) {
(OKToPrompt) && wallet_OKToCapture(strippedURLName, window)) {
WLLT_OnSubmit(nsIContent* currentForm, nsIDOMWindowInternal* window) {  nsCOMPtr<nsIDOMHTMLFormElement> currentFormNode(do_QueryInterface(currentForm));  /* get url name as ascii string */  char *URLName = nsnull;  nsAutoString strippedURLNameUCS2;  nsCOMPtr<nsIDocument> doc;  currentForm->GetDocument(*getter_AddRefs(doc));  if (!doc) {    return;  }  nsCOMPtr<nsIURI> docURL;  doc->GetDocumentURL(getter_AddRefs(docURL));  if (!docURL || wallet_IsFromCartman(docURL)) {    return;  }  (void)docURL->GetSpec(&URLName);  wallet_GetHostFile(docURL, strippedURLNameUCS2);  nsCAutoString strippedURLNameUTF8 = NS_ConvertUCS2toUTF8(strippedURLNameUCS2);  /* get to the form elements */  nsCOMPtr<nsIDOMHTMLDocument> htmldoc(do_QueryInterface(doc));  if (htmldoc == nsnull) {    nsCRT::free(URLName);    return;  }  nsCOMPtr<nsIDOMHTMLCollection> forms;  nsresult rv = htmldoc->GetForms(getter_AddRefs(forms));  if (NS_FAILED(rv) || (forms == nsnull)) {    nsCRT::free(URLName);    return;  }  PRUint32 numForms;  forms->GetLength(&numForms);  for (PRUint32 formX = 0; formX < numForms; formX++) {    nsCOMPtr<nsIDOMNode> formNode;    forms->Item(formX, getter_AddRefs(formNode));    if (nsnull != formNode) {#ifndef AutoCapture      PRInt32 fieldcount = 0;#endif      nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(formNode));      if ((nsnull != formElement)) {        nsCOMPtr<nsIDOMHTMLCollection> elements;        rv = formElement->GetElements(getter_AddRefs(elements));        if ((NS_SUCCEEDED(rv)) && (nsnull != elements)) {          /* got to the form elements at long last */           nsVoidArray * signonData = new nsVoidArray();          si_SignonDataStruct * data;          PRUint32 numElements;          elements->GetLength(&numElements);#ifdef AutoCapture          PRBool OKToPrompt = PR_FALSE;          PRInt32 passwordcount = 0;          PRInt32 hits = 0;          wallet_Initialize(PR_FALSE);          wallet_InitializeCurrentURL(doc);          wallet_InitializeStateTesting();          PRBool newValueFound = PR_FALSE;#endif          for (PRUint32 elementX = 0; elementX < numElements; elementX++) {            nsCOMPtr<nsIDOMNode> elementNode;            elements->Item(elementX, getter_AddRefs(elementNode));            if (nsnull != elementNode) {              nsCOMPtr<nsIDOMHTMLSelectElement> selectElement(do_QueryInterface(elementNode));              if ((NS_SUCCEEDED(rv)) && (nsnull != selectElement)) {                if (passwordcount == 0 && !newValueFound && !OKToPrompt) {                  nsAutoString valueOnForm;                  rv = selectElement->GetValue(valueOnForm);                  if (NS_SUCCEEDED(rv) && wallet_IsNewValue (elementNode, valueOnForm)) {                    newValueFound = PR_TRUE;                    if (hits > 1) {                      OKToPrompt = PR_TRUE;                    }                  }                }              }              nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(elementNode));              if ((NS_SUCCEEDED(rv)) && (nsnull != inputElement)) {                nsAutoString type;                rv = inputElement->GetType(type);                if (NS_SUCCEEDED(rv)) {                  PRBool isText = (type.IsEmpty() || (Compare(type, NS_LITERAL_STRING("text"), nsCaseInsensitiveStringComparator())==0));                  PRBool isPassword = (Compare(type, NS_LITERAL_STRING("password"), nsCaseInsensitiveStringComparator())==0);                  // don't save password if field was left blank                  if (isPassword) {                    nsAutoString val;                    (void) inputElement->GetValue(val);                    if (val.IsEmpty()) {                      isPassword = PR_FALSE;                    }                  }#define WALLET_DONT_CACHE_ALL_PASSWORDS#ifdef WALLET_DONT_CACHE_ALL_PASSWORDS                  if (isPassword) {                    nsAutoString val;                    (void) inputElement->GetAttribute(NS_LITERAL_STRING("autocomplete"), val);                    if (val.EqualsIgnoreCase("off")) {                      isPassword = PR_FALSE;                    } else {                      (void) formElement->GetAttribute(NS_LITERAL_STRING("autocomplete"), val);                      if (val.EqualsIgnoreCase("off")) {                        isPassword = PR_FALSE;                      }                    }                  }#endif#ifdef AutoCapture                  if (isPassword) {                    passwordcount++;                    OKToPrompt = PR_FALSE;                  }                  if (isText) {                    if (passwordcount == 0 && !newValueFound && !OKToPrompt) {                      nsAutoString valueOnForm;                      rv = inputElement->GetValue(valueOnForm);                      if (NS_SUCCEEDED(rv) && wallet_IsNewValue (elementNode, valueOnForm)) {                        newValueFound = PR_TRUE;                        if (hits > 1) {                          OKToPrompt = PR_TRUE;                        }                      }                    }                  }#else                  if (isText) {                    fieldcount++;                  }#endif                  if (isText || isPassword) {                    nsAutoString value;                    rv = inputElement->GetValue(value);                    if (NS_SUCCEEDED(rv)) {                      nsAutoString field;                      rv = inputElement->GetName(field);                      if (NS_SUCCEEDED(rv)) {                        data = new si_SignonDataStruct;                        data->value = value;                        if (field.Length() && field.CharAt(0) == '\\') {                          /*                           * Note that data saved for browser-generated logins (e.g. http                           * authentication) use artificial field names starting with                           * \= (see USERNAMEFIELD and PASSWORDFIELD in singsign.cpp).  To                           * avoid mistakes whereby saved logins for http authentication is                           * then prefilled into a field on the html form at the same URL,                           * we will prevent html field names from starting with \=.  We                           * do that by doubling up a backslash if it appears in the first                           * character position                           */                          data->name = nsAutoString('\\');                          data->name.Append(field);                        } else {                          data->name = field;                        }                        data->isPassword = isPassword;                        signonData->AppendElement(data);#ifdef AutoCapture                        if (passwordcount == 0 && !OKToPrompt) {                          /* get schema from field */                          nsCAutoString schema;                          nsVoidArray* dummy;                          nsCAutoString stripField;                          /* try to get schema from displayable text */                          if (schema.IsEmpty()) {                            wallet_GetSchemaFromDisplayableText(inputElement, schema, PR_FALSE);                          }#ifndef IgnoreFieldNames                          /* no schema found, so try to get it from field name */                          if (schema.IsEmpty()) {                            Strip(field, stripField);                            wallet_ReadFromList                              (stripField, schema,                                dummy, wallet_FieldToSchema_list, PR_FALSE);                          }#endif                          /* if schema found, see if it is in distinguished schema list */                          if (!schema.IsEmpty()) {                            /* see if schema is in distinguished list */                            wallet_MapElement * mapElementPtr;                            PRInt32 count = LIST_COUNT(wallet_DistinguishedSchema_list);                            /* test for at least two distinguished schemas and no passwords */                            for (PRInt32 i=0; i<count; i++) {                              mapElementPtr = NS_STATIC_CAST                                (wallet_MapElement*, wallet_DistinguishedSchema_list->ElementAt(i));                                  if (schema.Equals(mapElementPtr->item1, nsCaseInsensitiveCStringComparator()) && value.Length() > 0) {                                hits++;                                if (hits > 1 && newValueFound) {                                  OKToPrompt = PR_TRUE;                                  break;                                }                              }                            }                          }                        }#endif                      }                    }                  }                }              }            }          }          /* save login if appropriate */          if (currentFormNode == formNode) {            nsCOMPtr<nsIPrompt> dialog;            nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));            if (wwatch)              wwatch->GetNewPrompter(0, getter_AddRefs(dialog));            if (dialog) {              SINGSIGN_RememberSignonData(dialog, URLName, signonData, window);            }          }          PRInt32 count2 = signonData->Count();          for (PRInt32 i=count2-1; i>=0; i--) {            data = NS_STATIC_CAST(si_SignonDataStruct*, signonData->ElementAt(i));            delete data;          }          delete signonData;#ifndef AutoCapture          /* give notification if this is first significant form submitted */          if ((fieldcount>=3) && !wallet_GetWalletNotificationPref()) {            /* conditions all met, now give notification */            PRUnichar * notification = Wallet_Localize("WalletNotification");            wallet_SetWalletNotificationPref(PR_TRUE);            wallet_Alert(notification, window);            WALLET_FREE(notification);          }#else          /* save form if it meets all necessary conditions */          if (wallet_GetFormsCapturingPref() &&              (OKToPrompt) && wallet_OKToCapture(strippedURLNameUTF8, window)) {            /* give caveat if this is the first time data is being captured */            Wallet_GiveCaveat(window, nsnull);              /* conditions all met, now save it */            for (PRUint32 elementY = 0; elementY < numElements; elementY++) {              nsIDOMNode* elementNode = nsnull;              elements->Item(elementY, &elementNode);              if (nsnull != elementNode) {                wallet_CaptureInputElement(elementNode, doc);                wallet_CaptureSelectElement(elementNode, doc);              }            }          }#endif        }      }    }  }  nsCRT::free(URLName);}