nsCRT::free(strippedURLName);
WLLT_OnSubmit(nsIContent* currentForm, nsIDOMWindow* window) {  nsCOMPtr<nsIDOMHTMLFormElement> currentFormNode(do_QueryInterface(currentForm));  /* get url name as ascii string */  char *URLName = nsnull;  nsCOMPtr<nsIURI> docURL;  nsCOMPtr<nsIDocument> doc;  currentForm->GetDocument(*getter_AddRefs(doc));  if (!doc) {    return;  }  docURL = dont_AddRef(doc->GetDocumentURL());  if (!docURL) {    return;  }  (void)docURL->GetSpec(&URLName);  /* 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;#endif          for (PRUint32 elementX = 0; elementX < numElements; elementX++) {            nsCOMPtr<nsIDOMNode> elementNode;            elements->Item(elementX, getter_AddRefs(elementNode));            if (nsnull != elementNode) {              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() || (type.CompareWithConversion("text", PR_TRUE)==0));                  PRBool isPassword = (type.CompareWithConversion("password", PR_TRUE)==0);#ifdef AutoCapture                  if (isPassword) {                    passwordcount++;                    OKToPrompt = PR_FALSE;                  }#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.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) {                          /* get schema from field */                          wallet_Initialize(PR_FALSE, PR_FALSE);                          wallet_InitializeCurrentURL(doc);                          nsAutoString schema;                          nsVoidArray* dummy;                          nsString stripField;                          if (schema.Length() ||                              (wallet_ReadFromList(field, schema, dummy, wallet_specificURLFieldToSchema_list, PR_FALSE)) ||                              (wallet_ReadFromList(Strip(field, stripField), schema, dummy, wallet_FieldToSchema_list, PR_FALSE))) {                          }                          /* see if schema is in distinguished list */                          schema.ToLowerCase();                          wallet_MapElement * ptr;                          PRInt32 count = LIST_COUNT(wallet_DistinguishedSchema_list);                          /* test for at least two distinguished schemas and no passwords */                          for (PRInt32 i=0; i<count; i++) {                            ptr = NS_STATIC_CAST                              (wallet_MapElement*, wallet_DistinguishedSchema_list->ElementAt(i));                            if (ptr->item1 == schema && value.Length() > 0) {                              hits++;                              if (hits > 1) {                                OKToPrompt = PR_TRUE;                                break;                              }                            }                          }                        }#endif                      }                    }                  }                }              }            }          }          /* save login if appropriate */          if (currentFormNode == formNode) {            NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &rv);            if (NS_SUCCEEDED(rv)) {              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);            Recycle(notification);          }#else          /* save form if it meets all necessary conditions */          if (wallet_GetFormsCapturingPref() &&              (OKToPrompt) && wallet_OKToCapture(URLName, 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) {                nsIDOMHTMLInputElement* inputElement;                  rv =                  elementNode->QueryInterface(kIDOMHTMLInputElementIID, (void**)&inputElement);                if ((NS_SUCCEEDED(rv)) && (nsnull != inputElement)) {                  /* it's an input element */                  nsAutoString type;                  rv = inputElement->GetType(type);                  if ((NS_SUCCEEDED(rv)) &&                      (type.IsEmpty() || (type.CompareWithConversion("text", PR_TRUE) == 0))) {                    nsAutoString field;                    rv = inputElement->GetName(field);                    if (NS_SUCCEEDED(rv)) {                      nsAutoString value;                      rv = inputElement->GetValue(value);                      if (NS_SUCCEEDED(rv)) {                        /* get schema name from vcard attribute if it exists */                        nsAutoString vcardValue;                        nsIDOMElement * element;                        rv = elementNode->QueryInterface(kIDOMElementIID, (void**)&element);                        if ((NS_SUCCEEDED(rv)) && (nsnull != element)) {                          nsAutoString vcardName; vcardName.AssignWithConversion("VCARD_NAME");                          rv = element->GetAttribute(vcardName, vcardValue);                          NS_RELEASE(element);                        }                        wallet_Capture(doc, field, value, vcardValue);                      }                    }                  }                }              }            }          }#endif        }      }    }  }  nsCRT::free(URLName);}