Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
nsFSTextPlain Class Reference
Inheritance diagram for nsFSTextPlain:
Inheritance graph
[legend]
Collaboration diagram for nsFSTextPlain:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsFSTextPlain (const nsACString &aCharset, nsISaveAsCharset *aEncoder, nsIFormProcessor *aFormProcessor, PRInt32 aBidiOptions)
virtual ~nsFSTextPlain ()
virtual
NS_DECL_ISUPPORTS_INHERITED
nsresult 
AddNameValuePair (nsIDOMHTMLElement *aSource, const nsAString &aName, const nsAString &aValue)
 Submit a name/value pair.
virtual nsresult AddNameFilePair (nsIDOMHTMLElement *aSource, const nsAString &aName, const nsAString &aFilename, nsIInputStream *aStream, const nsACString &aContentType, PRBool aMoreFilesToCome)
 Submit a name/file pair.
NS_IMETHOD Init ()
 Called to initialize the submission.
virtual NS_DECL_ISUPPORTS nsresult SubmitTo (nsIURI *aActionURI, const nsAString &aTarget, nsIContent *aSource, nsPresContext *aPresContext, nsIDocShell **aDocShell, nsIRequest **aRequest)
 Call to perform the submission.

Static Public Member Functions

static void GetSubmitCharset (nsGenericHTMLElement *aForm, PRUint8 aCtrlsModAtSubmit, nsACString &aCharset)
 Get the submit charset for a form (suitable to pass in to the constructor).
static nsresult GetEncoder (nsGenericHTMLElement *aForm, nsPresContext *aPresContext, const nsACString &aCharset, nsISaveAsCharset **aEncoder)
 Get the encoder for a form (suitable to pass in to the constructor).
static void GetEnumAttr (nsGenericHTMLElement *aForm, nsIAtom *aAtom, PRInt32 *aValue)
 Get an attribute of a form as int, provided that it is an enumerated value.

Protected Member Functions

NS_IMETHOD GetEncodedSubmission (nsIURI *aURI, nsIInputStream **aPostDataStream)
 Given a URI and the current submission, create the final URI and data stream that will be submitted.
virtual PRBool AcceptsFiles () const
 Find out whether or not this form submission accepts files.
nsresult ProcessValue (nsIDOMHTMLElement *aSource, const nsAString &aName, const nsAString &aValue, nsAString &aResult)
 Call to have the form processor listen in when a name/value pair is found to be submitted.
nsresult EncodeVal (const nsAString &aStr, nsACString &aResult)
 Encode a Unicode string to bytes using the encoder (or just copy the input if there is no encoder).
nsresult UnicodeToNewBytes (const nsAString &aStr, nsISaveAsCharset *aEncoder, nsACString &aOut)
 Encode a Unicode string to bytes using an encoder.

Protected Attributes

nsCString mCharset
 The name of the encoder charset.
nsCOMPtr< nsISaveAsCharsetmEncoder
 The encoder that will encode Unicode names and values into bytes to be sent over the wire (usually a charset transformation)
nsCOMPtr< nsIFormProcessormFormProcessor
 A form processor who can listen to values.
PRInt32 mBidiOptions
 The BIDI options flags for the current pres context.

Private Attributes

nsString mBody

Detailed Description

Definition at line 926 of file nsFormSubmission.cpp.


Constructor & Destructor Documentation

nsFSTextPlain::nsFSTextPlain ( const nsACString &  aCharset,
nsISaveAsCharset aEncoder,
nsIFormProcessor aFormProcessor,
PRInt32  aBidiOptions 
) [inline]

Definition at line 929 of file nsFormSubmission.cpp.

    : nsFormSubmission(aCharset, aEncoder, aFormProcessor, aBidiOptions)
  {
  }
virtual nsFSTextPlain::~nsFSTextPlain ( ) [inline, virtual]

Definition at line 936 of file nsFormSubmission.cpp.

  {
  }

Member Function Documentation

virtual PRBool nsFSTextPlain::AcceptsFiles ( ) const [inline, protected, virtual]

Find out whether or not this form submission accepts files.

Parameters:
aAcceptsFilesthe boolean output

Implements nsIFormSubmission.

Definition at line 959 of file nsFormSubmission.cpp.

  {
    return PR_FALSE;
  }
nsresult nsFSTextPlain::AddNameFilePair ( nsIDOMHTMLElement aSource,
const nsAString &  aName,
const nsAString &  aFilename,
nsIInputStream aStream,
const nsACString &  aContentType,
PRBool  aMoreFilesToCome 
) [virtual]

Submit a name/file pair.

Parameters:
aSourcethe control sending the parameter
aNamethe name of the parameter
aFilenamethe name of the file (pass null to provide no name)
aStreamthe stream containing the file data to be sent
aContentTypethe content-type of the file data being sent
aMoreFilesToCometrue if another name/file pair with the same name will be sent soon

Implements nsIFormSubmission.

Definition at line 999 of file nsFormSubmission.cpp.

{
  AddNameValuePair(aSource,aName,aFilename);
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsFSTextPlain::AddNameValuePair ( nsIDOMHTMLElement aSource,
const nsAString &  aName,
const nsAString &  aValue 
) [virtual]

Submit a name/value pair.

Parameters:
aSourcethe control sending the parameter
aNamethe name of the parameter
aValuethe value of the parameter

Implements nsIFormSubmission.

Definition at line 973 of file nsFormSubmission.cpp.

{
  //
  // Let external code process (and possibly change) value
  //
  nsString processedValue;
  nsresult rv = ProcessValue(aSource, aName, aValue, processedValue);

  // XXX This won't work well with a name like "a=b" or "a\nb" but I suppose
  // text/plain doesn't care about that.  Parsers aren't built for escaped
  // values so we'll have to live with it.
  if (NS_SUCCEEDED(rv)) {
    mBody.Append(aName + NS_LITERAL_STRING("=") + processedValue +
                 NS_LITERAL_STRING(CRLF));

  } else {
    mBody.Append(aName + NS_LITERAL_STRING("=") + aValue +
                 NS_LITERAL_STRING(CRLF));
  }

  return NS_OK;
}

Here is the caller graph for this function:

nsresult nsFormSubmission::EncodeVal ( const nsAString &  aStr,
nsACString &  aResult 
) [protected, inherited]

Encode a Unicode string to bytes using the encoder (or just copy the input if there is no encoder).

Parameters:
aStrthe string to encode
aResultthe encoded string [OUT]
Exceptions:
anerror if UnicodeToNewBytes fails

Definition at line 1423 of file nsFormSubmission.cpp.

{
  NS_ASSERTION(mEncoder, "Encoder not available. Losing data !");
  if (mEncoder)
    return UnicodeToNewBytes(aStr, mEncoder, aOut);

  // fall back to UTF-8
  CopyUTF16toUTF8(aStr, aOut);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsFSTextPlain::GetEncodedSubmission ( nsIURI aURI,
nsIInputStream **  aPostDataStream 
) [protected, virtual]

Given a URI and the current submission, create the final URI and data stream that will be submitted.

Subclasses must implement this.

Parameters:
aURIthe URI being submitted to [INOUT]
aPostDataStreama data stream for POST data [OUT]

Implements nsFormSubmission.

Definition at line 1021 of file nsFormSubmission.cpp.

{
  nsresult rv = NS_OK;

  // XXX HACK We are using the standard URL mechanism to give the body to the
  // mailer instead of passing the post data stream to it, since that sounds
  // hard.
  PRBool isMailto = PR_FALSE;
  aURI->SchemeIs("mailto", &isMailto);
  if (isMailto) {
    nsCAutoString path;
    rv = aURI->GetPath(path);
    NS_ENSURE_SUCCESS(rv, rv);

    HandleMailtoSubject(path);

    // Append the body to and force-plain-text args to the mailto line
    char* escapedBuf = nsEscape(NS_ConvertUTF16toUTF8(mBody).get(),
                                url_XAlphas);
    NS_ENSURE_TRUE(escapedBuf, NS_ERROR_OUT_OF_MEMORY);
    nsCString escapedBody;
    escapedBody.Adopt(escapedBuf);

    path += NS_LITERAL_CSTRING("&force-plain-text=Y&body=") + escapedBody;

    rv = aURI->SetPath(path);

  } else {

    // Create data stream
    nsCOMPtr<nsIInputStream> bodyStream;
    rv = NS_NewStringInputStream(getter_AddRefs(bodyStream),
                                          mBody);
    if (!bodyStream) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    // Create mime stream with headers and such
    nsCOMPtr<nsIMIMEInputStream> mimeStream
        = do_CreateInstance("@mozilla.org/network/mime-input-stream;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    mimeStream->AddHeader("Content-Type", "text/plain");
    mimeStream->SetAddContentLength(PR_TRUE);
    mimeStream->SetData(bodyStream);
    CallQueryInterface(mimeStream, aPostDataStream);
    NS_ADDREF(*aPostDataStream);
  }

  return rv;
}

Here is the call graph for this function:

nsresult nsFormSubmission::GetEncoder ( nsGenericHTMLElement aForm,
nsPresContext aPresContext,
const nsACString &  aCharset,
nsISaveAsCharset **  aEncoder 
) [static, inherited]

Get the encoder for a form (suitable to pass in to the constructor).

Parameters:
aFormthe form in question
aPresContextthe pres context in which we are submitting
aCharsetthe charset of the form
aEncoderthe returned encoder [OUT]

Definition at line 1309 of file nsFormSubmission.cpp.

{
  *aEncoder = nsnull;
  nsresult rv = NS_OK;

  nsCAutoString charset(aCharset);
  // canonical name is passed so that we just have to check against
  // *our* canonical names listed in charsetaliases.properties
  if (charset.EqualsLiteral("ISO-8859-1")) {
    charset.AssignLiteral("windows-1252");
  }

  // use UTF-8 for UTF-16* and UTF-32* (per WHATWG and existing practice of
  // MS IE/Opera). 
  if (StringBeginsWith(charset, NS_LITERAL_CSTRING("UTF-16")) || 
      StringBeginsWith(charset, NS_LITERAL_CSTRING("UTF-32"))) {
    charset.AssignLiteral("UTF-8");
  }

  rv = CallCreateInstance( NS_SAVEASCHARSET_CONTRACTID, aEncoder);
  NS_ASSERTION(NS_SUCCEEDED(rv), "create nsISaveAsCharset failed");
  NS_ENSURE_SUCCESS(rv, rv);

  rv = (*aEncoder)->Init(charset.get(),
                         (nsISaveAsCharset::attr_EntityAfterCharsetConv + 
                          nsISaveAsCharset::attr_FallbackDecimalNCR),
                         0);
  NS_ASSERTION(NS_SUCCEEDED(rv), "initialize nsISaveAsCharset failed");
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFormSubmission::GetEnumAttr ( nsGenericHTMLElement aForm,
nsIAtom aAtom,
PRInt32 aValue 
) [static, inherited]

Get an attribute of a form as int, provided that it is an enumerated value.

Parameters:
aFormthe form in question
aAtomthe attribute (for example, nsHTMLAtoms::enctype) to get
aValuethe result (will not be set at all if the attribute does not exist on the form, so make sure you provide a default value.) [OUT]

Definition at line 1413 of file nsFormSubmission.cpp.

{
  const nsAttrValue* value = aContent->GetParsedAttr(atom);
  if (value && value->Type() == nsAttrValue::eEnum) {
    *aValue = value->GetEnumValue();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFormSubmission::GetSubmitCharset ( nsGenericHTMLElement aForm,
PRUint8  aCtrlsModAtSubmit,
nsACString &  aCharset 
) [static, inherited]

Get the submit charset for a form (suitable to pass in to the constructor).

Parameters:
aFormthe form in question
aCtrlsModAtSubmitBIDI controls text mode. Unused in non-BIDI builds.
aCharsetthe returned charset [OUT]

Definition at line 1238 of file nsFormSubmission.cpp.

{
  oCharset.AssignLiteral("UTF-8"); // default to utf-8

  nsresult rv = NS_OK;
  nsAutoString acceptCharsetValue;
  aForm->GetAttr(kNameSpaceID_None, nsHTMLAtoms::acceptcharset,
                 acceptCharsetValue);

  PRInt32 charsetLen = acceptCharsetValue.Length();
  if (charsetLen > 0) {
    PRInt32 offset=0;
    PRInt32 spPos=0;
    // get charset from charsets one by one
    nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &rv));
    if (NS_FAILED(rv)) {
      return;
    }
    if (calias) {
      do {
        spPos = acceptCharsetValue.FindChar(PRUnichar(' '), offset);
        PRInt32 cnt = ((-1==spPos)?(charsetLen-offset):(spPos-offset));
        if (cnt > 0) {
          nsAutoString uCharset;
          acceptCharsetValue.Mid(uCharset, offset, cnt);

          if (NS_SUCCEEDED(calias->
                           GetPreferred(NS_LossyConvertUTF16toASCII(uCharset),
                                        oCharset)))
            return;
        }
        offset = spPos + 1;
      } while (spPos != -1);
    }
  }
  // if there are no accept-charset or all the charset are not supported
  // Get the charset from document
  nsIDocument* doc = aForm->GetDocument();
  if (doc) {
    oCharset = doc->GetDocumentCharacterSet();
  }

  if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_VISUAL
     && oCharset.Equals(NS_LITERAL_CSTRING("windows-1256"),
                        nsCaseInsensitiveCStringComparator())) {
//Mohamed
    oCharset.AssignLiteral("IBM864");
  }
  else if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_LOGICAL
          && oCharset.Equals(NS_LITERAL_CSTRING("IBM864"),
                             nsCaseInsensitiveCStringComparator())) {
    oCharset.AssignLiteral("IBM864i");
  }
  else if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_VISUAL
          && oCharset.Equals(NS_LITERAL_CSTRING("ISO-8859-6"),
                             nsCaseInsensitiveCStringComparator())) {
    oCharset.AssignLiteral("IBM864");
  }
  else if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_VISUAL
          && oCharset.Equals(NS_LITERAL_CSTRING("UTF-8"),
                             nsCaseInsensitiveCStringComparator())) {
    oCharset.AssignLiteral("IBM864");
  }

}

Here is the call graph for this function:

Here is the caller graph for this function:

Called to initialize the submission.

Perform any initialization that may fail here. Subclasses must implement this.

Implements nsFormSubmission.

Definition at line 1014 of file nsFormSubmission.cpp.

{
  mBody.Truncate();
  return NS_OK;
}
nsresult nsFormSubmission::ProcessValue ( nsIDOMHTMLElement aSource,
const nsAString &  aName,
const nsAString &  aValue,
nsAString &  aResult 
) [protected, inherited]

Call to have the form processor listen in when a name/value pair is found to be submitted.

Parameters:
aSourcethe HTML element the name/value is associated with
aNamethe name that will be submitted
aValuethe value that will be submitted
theprocessed value that will be sent to the server. [OUT]

Definition at line 1435 of file nsFormSubmission.cpp.

{
  // Hijack _charset_ (hidden inputs only) for internationalization (bug 18643)
  if (aName.EqualsLiteral("_charset_")) {
    nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aSource);
    if (formControl && formControl->GetType() == NS_FORM_INPUT_HIDDEN) {
        CopyASCIItoUTF16(mCharset, aResult);
        return NS_OK;
    }
  }

  nsresult rv = NS_OK;
  aResult = aValue;
  if (mFormProcessor) {
    rv = mFormProcessor->ProcessValue(aSource, aName, aResult);
    NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to Notify form process observer");
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFormSubmission::SubmitTo ( nsIURI aActionURL,
const nsAString &  aTarget,
nsIContent aSource,
nsPresContext aPresContext,
nsIDocShell **  aDocShell,
nsIRequest **  aRequest 
) [virtual, inherited]

Call to perform the submission.

Parameters:
aActionURLthe URL to submit to (may be modified with GET contents)
aTargetthe target window
aSourcethe element responsible for the submission (for web shell)
aPresContextthe presentation context
aDocShell(out param) the DocShell in which the submission was loaded
aRequest(out param) the Request for the submission

Implements nsIFormSubmission.

Definition at line 1209 of file nsFormSubmission.cpp.

{
  nsresult rv;

  //
  // Finish encoding (get post data stream and URI)
  //
  nsCOMPtr<nsIInputStream> postDataStream;
  rv = GetEncodedSubmission(aActionURI, getter_AddRefs(postDataStream));
  NS_ENSURE_SUCCESS(rv, rv);

  //
  // Actually submit the data
  //
  nsILinkHandler *handler = aPresContext->GetLinkHandler();
  NS_ENSURE_TRUE(handler, NS_ERROR_FAILURE);

  return handler->OnLinkClickSync(aSource, eLinkVerb_Replace,
                                  aActionURI,
                                  PromiseFlatString(aTarget).get(),
                                  postDataStream, nsnull,
                                  aDocShell, aRequest);
}

Here is the call graph for this function:

nsresult nsFormSubmission::UnicodeToNewBytes ( const nsAString &  aStr,
nsISaveAsCharset aEncoder,
nsACString &  aOut 
) [protected, inherited]

Encode a Unicode string to bytes using an encoder.

(Used by EncodeVal)

Parameters:
aStrthe string to encode
aEncoderthe encoder to encode the bytes with (cannot be null)
aOutthe encoded string [OUT]
Exceptions:
anerror if the encoder fails

Definition at line 1347 of file nsFormSubmission.cpp.

{
  PRUint8 ctrlsModAtSubmit = GET_BIDI_OPTION_CONTROLSTEXTMODE(mBidiOptions);
  PRUint8 textDirAtSubmit = GET_BIDI_OPTION_DIRECTION(mBidiOptions);
  //ahmed 15-1
  nsAutoString newBuffer;
  //This condition handle the RTL,LTR for a logical file
  if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL
     && mCharset.Equals(NS_LITERAL_CSTRING("windows-1256"),
                        nsCaseInsensitiveCStringComparator())) {
    Conv_06_FE_WithReverse(nsString(aStr),
                           newBuffer,
                           textDirAtSubmit);
  }
  else if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_LOGICAL
          && mCharset.Equals(NS_LITERAL_CSTRING("IBM864"),
                             nsCaseInsensitiveCStringComparator())) {
    //For 864 file, When it is logical, if LTR then only convert
    //If RTL will mak a reverse for the buffer
    Conv_FE_06(nsString(aStr), newBuffer);
    if (textDirAtSubmit == 2) { //RTL
    //Now we need to reverse the Buffer, it is by searching the buffer
      PRInt32 len = newBuffer.Length();
      PRUint32 z = 0;
      nsAutoString temp;
      temp.SetLength(len);
      while (--len >= 0)
        temp.SetCharAt(newBuffer.CharAt(len), z++);
      newBuffer = temp;
    }
  }
  else if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL
          && mCharset.Equals(NS_LITERAL_CSTRING("IBM864"),
                             nsCaseInsensitiveCStringComparator())
                  && textDirAtSubmit == IBMBIDI_TEXTDIRECTION_RTL) {

    Conv_FE_06(nsString(aStr), newBuffer);
    //Now we need to reverse the Buffer, it is by searching the buffer
    PRInt32 len = newBuffer.Length();
    PRUint32 z = 0;
    nsAutoString temp;
    temp.SetLength(len);
    while (--len >= 0)
      temp.SetCharAt(newBuffer.CharAt(len), z++);
    newBuffer = temp;
  }
  else {
    newBuffer = aStr;
  }

  nsXPIDLCString res;
  if (!newBuffer.IsEmpty()) {
    aOut.Truncate();
    nsresult rv = aEncoder->Convert(newBuffer.get(), getter_Copies(res));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  aOut = res;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

PRInt32 nsFormSubmission::mBidiOptions [protected, inherited]

The BIDI options flags for the current pres context.

Definition at line 176 of file nsFormSubmission.cpp.

Definition at line 965 of file nsFormSubmission.cpp.

nsCString nsFormSubmission::mCharset [protected, inherited]

The name of the encoder charset.

Definition at line 168 of file nsFormSubmission.cpp.

The encoder that will encode Unicode names and values into bytes to be sent over the wire (usually a charset transformation)

Definition at line 172 of file nsFormSubmission.cpp.

A form processor who can listen to values.

Definition at line 174 of file nsFormSubmission.cpp.


The documentation for this class was generated from the following file: