char * contentTypeChars = nsnull; rv = MIMEService->GetTypeFromFile(file, &contentTypeChars);
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;  }  //  // For type=reset, and type=button, we just never submit, period.  //  if (mType == NS_FORM_INPUT_RESET || mType == NS_FORM_INPUT_BUTTON) {    return rv;  }  //  // For type=image and type=button, we only submit if we were the button  // pressed  //  if ((mType == NS_FORM_INPUT_SUBMIT || mType == NS_FORM_INPUT_IMAGE)      && aSubmitElement != this) {    return rv;  }  //  // For type=radio and type=checkbox, we only submit if checked=true  //  if (mType == NS_FORM_INPUT_RADIO || mType == 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 (mType == 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);    nsIImageControlFrame* imageControlFrame = nsnull;    if (formControlFrame) {      CallQueryInterface(formControlFrame, &imageControlFrame);    }        nsAutoString xVal;    nsAutoString yVal;        if (imageControlFrame) {      imageControlFrame->GetClickedX(&clickedX);      imageControlFrame->GetClickedY(&clickedY);      // Convert the values to strings for submission      xVal.AppendInt(clickedX);      yVal.AppendInt(clickedY);    }        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 (mType == NS_FORM_INPUT_FILE) {    //    // Open the file    //    nsCOMPtr<nsIFile> file;     if (StringBeginsWith(value, NS_LITERAL_STRING("file:"),                         nsCaseInsensitiveStringComparator())) {      // Converts the URL string into the corresponding nsIFile if possible.      // A local file will be created if the URL string begins with file://.      rv = NS_GetFileFromURLSpec(NS_ConvertUCS2toUTF8(value),                                 getter_AddRefs(file));    }    if (!file) {      // this is no "file://", try as local file      nsCOMPtr<nsILocalFile> localFile;      rv = NS_NewLocalFile(value, PR_FALSE, getter_AddRefs(localFile));      file = localFile;    }    if (NS_SUCCEEDED(rv)) {      //      // Get the leaf path name (to be submitted as the value)      //      nsAutoString filename;      rv = file->GetLeafName(filename);      if (NS_SUCCEEDED(rv) && !filename.IsEmpty()) {        PRBool acceptsFiles = aFormSubmission->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;      } else {        // Ignore error returns from GetLeafName.  See bug 199053        rv = NS_OK;      }    }        //    // 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 (mType != NS_FORM_INPUT_IMAGE || !value.IsEmpty()) {    rv = aFormSubmission->AddNameValuePair(this, name, value);  }  return rv;}