if (!leafNameChars.IsEmpty()) { NS_ConvertUTF8toUCS2 filename(leafNameChars);
if (!filename.IsEmpty()) {
nsHTMLInputElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,                                      nsIContent* aSubmitElement){  nsresult rv = NS_OK;  //  // Disabled elements don't submit  //  PRBool disabled;  rv = GetDisabled(&disabled);  if (NS_FAILED(rv) || disabled) {    return rv;  }  //  // Get the type (many ops depend on the type)  //  PRInt32 type;  rv = GetType(&type);  if (NS_FAILED(rv)) {    return rv;  }  //  // For type=reset, and type=button, we just never submit, period.  //  if (type == NS_FORM_INPUT_RESET || type == NS_FORM_INPUT_BUTTON) {    return rv;  }  //  // For type=image and type=button, we only submit if we were the button  // pressed  //  if ((type == NS_FORM_INPUT_SUBMIT || type == NS_FORM_INPUT_IMAGE)      && aSubmitElement != this) {    return rv;  }  //  // For type=radio and type=checkbox, we only submit if checked=true  //  if (type == NS_FORM_INPUT_RADIO || type == NS_FORM_INPUT_CHECKBOX) {    PRBool checked;    rv = GetChecked(&checked);    if (NS_FAILED(rv) || !checked) {      return rv;    }  }  //  // Get the name  //  nsAutoString name;  rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, name);  if (NS_FAILED(rv)) {    return rv;  }  PRBool nameThere = (rv != NS_CONTENT_ATTR_NOT_THERE);  //  // Submit .x, .y for input type=image  //  if (type == NS_FORM_INPUT_IMAGE) {    // Go to the frame to find out where it was clicked.  This is the only    // case where I can actually see using the frame, because you're talking    // about a value--mouse click--that is rightfully the domain of the frame.    //    // If the frame isn't there or isn't an ImageControlFrame, then we're not    // submitting these values no matter *how* nicely you ask.    PRInt32 clickedX;    PRInt32 clickedY;    nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);    nsCOMPtr<nsIImageControlFrame> imageControlFrame(        do_QueryInterface(formControlFrame));    if (imageControlFrame) {      imageControlFrame->GetClickedX(&clickedX);      imageControlFrame->GetClickedY(&clickedY);      // Convert the values to strings for submission      char buf[20];      sprintf(&buf[0], "%d", clickedX);      nsAutoString xVal = NS_ConvertASCIItoUCS2(buf);      sprintf(&buf[0], "%d", clickedY);      nsAutoString yVal = NS_ConvertASCIItoUCS2(buf);      if (!name.IsEmpty()) {        aFormSubmission->AddNameValuePair(this,                                          name + NS_LITERAL_STRING(".x"), xVal);        aFormSubmission->AddNameValuePair(this,                                          name + NS_LITERAL_STRING(".y"), yVal);      } else {        // If the Image Element has no name, simply return x and y        // to Nav and IE compatability.        aFormSubmission->AddNameValuePair(this, NS_LITERAL_STRING("x"), xVal);        aFormSubmission->AddNameValuePair(this, NS_LITERAL_STRING("y"), yVal);      }    }  }  //  // Submit name=value  //  // If name not there, don't submit  if (!nameThere) {    return rv;  }  // Get the value  nsAutoString value;  rv = GetValue(value);  if (NS_FAILED(rv)) {    return rv;  }  //  // Submit file if it's input type=file and this encoding method accepts files  //  if (type == NS_FORM_INPUT_FILE) {    //    // Open the file    //    nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID,                                                  &rv));    NS_ENSURE_SUCCESS(rv, rv);    rv = file->InitWithPath(NS_ConvertUCS2toUTF8(value));    if (NS_SUCCEEDED(rv)) {      //      // Get the leaf path name (to be submitted as the value)      //      nsCAutoString leafNameChars;      rv = file->GetLeafName(leafNameChars);      NS_ENSURE_SUCCESS(rv, rv);      if (!leafNameChars.IsEmpty()) {        NS_ConvertUTF8toUCS2 filename(leafNameChars);        PRBool acceptsFiles = PR_FALSE;        aFormSubmission->AcceptsFiles(&acceptsFiles);        if (acceptsFiles) {          //          // Get content type          //          nsCOMPtr<nsIMIMEService> MIMEService =            do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);          NS_ENSURE_SUCCESS(rv, rv);          char * contentTypeChars = nsnull;          rv = MIMEService->GetTypeFromFile(file, &contentTypeChars);          nsCAutoString contentType;          if (contentTypeChars) {            contentType.Adopt(contentTypeChars);          } else {            contentType = NS_LITERAL_CSTRING("application/octet-stream");          }          //          // Get input stream          //          nsCOMPtr<nsIInputStream> fileStream;          rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream),                                          file, -1, -1,                                          nsIFileInputStream::CLOSE_ON_EOF |                                          nsIFileInputStream::REOPEN_ON_REWIND);          if (fileStream) {            //            // Create buffered stream (for efficiency)            //            nsCOMPtr<nsIInputStream> bufferedStream;            rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),                                           fileStream, 8192);            NS_ENSURE_SUCCESS(rv, rv);            if (bufferedStream) {              //              // Submit              //              aFormSubmission->AddNameFilePair(this, name, filename,                                               bufferedStream, contentType,                                               PR_FALSE);              return rv;            }          }        }        //        // If we don't submit as a file, at least submit the truncated filename.        //        aFormSubmission->AddNameFilePair(this, name, filename,            nsnull, NS_LITERAL_CSTRING("application/octet-stream"),            PR_FALSE);        return rv;      }    }        //    // If we can't even make a truncated filename, submit empty string    // rather than sending everything    //    aFormSubmission->AddNameFilePair(this, name, value,        nsnull, NS_LITERAL_CSTRING("application/octet-stream"),        PR_FALSE);    return rv;  }  // Submit  // (for type=image, only submit if value is non-null)  if (type != NS_FORM_INPUT_IMAGE || !value.IsEmpty()) {    rv = aFormSubmission->AddNameValuePair(this, name, value);  }  return rv;}