Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
nsFormSubmission Class Reference

Helper superclass implementation of nsIFormSubmission, providing common methods that most of the specific implementations need and use. More...

Inheritance diagram for nsFormSubmission:
Inheritance graph
[legend]
Collaboration diagram for nsFormSubmission:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsFormSubmission (const nsACString &aCharset, nsISaveAsCharset *aEncoder, nsIFormProcessor *aFormProcessor, PRInt32 aBidiOptions)
virtual ~nsFormSubmission ()
virtual NS_DECL_ISUPPORTS nsresult SubmitTo (nsIURI *aActionURI, const nsAString &aTarget, nsIContent *aSource, nsPresContext *aPresContext, nsIDocShell **aDocShell, nsIRequest **aRequest)
 Call to perform the submission.
NS_IMETHOD Init ()=0
 Called to initialize the submission.
virtual PRBool AcceptsFiles () const =0
 Find out whether or not this form submission accepts files.
virtual nsresult AddNameValuePair (nsIDOMHTMLElement *aSource, const nsAString &aName, const nsAString &aValue)=0
 Submit a name/value pair.
virtual nsresult AddNameFilePair (nsIDOMHTMLElement *aSource, const nsAString &aName, const nsAString &aFilename, nsIInputStream *aStream, const nsACString &aContentType, PRBool aMoreFilesToCome)=0
 Submit a name/file pair.

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)=0
 Given a URI and the current submission, create the final URI and data stream that will be submitted.
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.

Detailed Description

Helper superclass implementation of nsIFormSubmission, providing common methods that most of the specific implementations need and use.

Definition at line 83 of file nsFormSubmission.cpp.


Constructor & Destructor Documentation

nsFormSubmission::nsFormSubmission ( const nsACString &  aCharset,
nsISaveAsCharset aEncoder,
nsIFormProcessor aFormProcessor,
PRInt32  aBidiOptions 
) [inline]
Parameters:
aCharsetthe charset of the form as a string
aEncoderan encoder that will encode Unicode names and values into bytes to be sent over the wire (usually a charset transformation)
aFormProcessora form processor who can listen to
aBidiOptionsthe BIDI options flags for the current pres context

Definition at line 94 of file nsFormSubmission.cpp.

    : mCharset(aCharset),
      mEncoder(aEncoder),
      mFormProcessor(aFormProcessor),
      mBidiOptions(aBidiOptions)
  {
  };
virtual nsFormSubmission::~nsFormSubmission ( ) [inline, virtual]

Definition at line 104 of file nsFormSubmission.cpp.

  {
  };

Member Function Documentation

virtual PRBool nsIFormSubmission::AcceptsFiles ( ) const [pure virtual, inherited]

Find out whether or not this form submission accepts files.

Parameters:
aAcceptsFilesthe boolean output

Implemented in nsFSTextPlain, nsFSMultipartFormData, and nsFSURLEncoded.

Here is the caller graph for this function:

virtual nsresult nsIFormSubmission::AddNameFilePair ( nsIDOMHTMLElement aSource,
const nsAString &  aName,
const nsAString &  aFilename,
nsIInputStream aStream,
const nsACString &  aContentType,
PRBool  aMoreFilesToCome 
) [pure virtual, inherited]

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

Implemented in nsFSTextPlain, nsFSMultipartFormData, and nsFSURLEncoded.

Here is the caller graph for this function:

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

Submit a name/value pair.

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

Implemented in nsFSTextPlain, nsFSMultipartFormData, and nsFSURLEncoded.

Here is the caller graph for this function:

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

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_IMETHOD nsFormSubmission::GetEncodedSubmission ( nsIURI aURI,
nsIInputStream **  aPostDataStream 
) [protected, pure 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]

Implemented in nsFSTextPlain, nsFSMultipartFormData, and nsFSURLEncoded.

Here is the caller graph for this function:

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

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]

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]

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:

NS_IMETHOD nsFormSubmission::Init ( ) [pure virtual]

Called to initialize the submission.

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

Implemented in nsFSTextPlain, nsFSMultipartFormData, and nsFSURLEncoded.

nsresult nsFormSubmission::ProcessValue ( nsIDOMHTMLElement aSource,
const nsAString &  aName,
const nsAString &  aValue,
nsAString &  aResult 
) [protected]

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]

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]

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

The BIDI options flags for the current pres context.

Definition at line 176 of file nsFormSubmission.cpp.

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: