Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsSubmissionElement.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla XForms support.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * IBM Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Darin Fisher <darin@meer.net>
00024  *  Merle Sterling <msterlin@us.ibm.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsXFormsSubmissionElement_h_
00041 #define nsXFormsSubmissionElement_h_
00042 
00043 #include "nsXFormsStubElement.h"
00044 #include "nsIRequestObserver.h"
00045 #include "nsIInputStream.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsIModelElementPrivate.h"
00048 #include "nsIXFormsSubmitElement.h"
00049 #include "nsIXFormsSubmissionElement.h"
00050 #include "nsIChannelEventSink.h"
00051 #include "nsIInterfaceRequestor.h"
00052 #include "nsHashSets.h"
00053 #include "nsIDocument.h"
00054 #include "nsIHttpHeaderVisitor.h"
00055 #include "nsIXFormsContextInfo.h"
00056 #include "nsDataHashtable.h"
00057 #include "nsIHttpChannel.h"
00058 
00059 
00060 class nsIMultiplexInputStream;
00061 class nsIDOMElement;
00062 class nsIChannel;
00063 class nsIURI;
00064 class nsIFile;
00065 class nsCString;
00066 class nsString;
00067 
00068 class SubmissionAttachmentArray;
00069 
00075 class nsXFormsSubmissionElement : public nsXFormsStubElement,
00076                                   public nsIRequestObserver,
00077                                   public nsIXFormsSubmissionElement,
00078                                   public nsIChannelEventSink,
00079                                   public nsIInterfaceRequestor,
00080                                   public nsIHttpHeaderVisitor
00081 {
00082 public:
00083   NS_DECL_ISUPPORTS_INHERITED
00084   NS_DECL_NSIREQUESTOBSERVER
00085   NS_DECL_NSIXFORMSSUBMISSIONELEMENT
00086   NS_DECL_NSICHANNELEVENTSINK
00087   NS_DECL_NSIINTERFACEREQUESTOR
00088   NS_DECL_NSIHTTPHEADERVISITOR
00089 
00090   nsXFormsSubmissionElement()
00091     : mElement(nsnull),
00092       mSubmissionActive(PR_FALSE),
00093       mIsReplaceInstance(PR_FALSE),
00094       mIsSOAPRequest(PR_FALSE),
00095       mFormat(0),
00096       mSubmissionBody(nsnull)
00097   {}
00098 
00099   // nsIXTFGenericElement overrides
00100   NS_IMETHOD OnDestroyed();
00101   NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled);
00102   NS_IMETHOD OnCreated(nsIXTFGenericElementWrapper *aWrapper);
00103 
00104   NS_HIDDEN_(already_AddRefed<nsIModelElementPrivate>) GetModel();
00105 
00106   NS_HIDDEN_(nsresult) LoadReplaceInstance(nsIChannel *);
00107   NS_HIDDEN_(nsresult) LoadReplaceAll(nsIChannel *);
00108   NS_HIDDEN_(nsresult) Submit();
00109   NS_HIDDEN_(nsresult) GetSubmissionURI(nsACString& aURI);
00110   NS_HIDDEN_(PRBool)   GetBooleanAttr(const nsAString &attrName,
00111                                       PRBool defaultVal = PR_FALSE);
00112   NS_HIDDEN_(void)     GetDefaultInstanceData(nsIDOMNode **result);
00113   NS_HIDDEN_(nsresult) GetBoundInstanceData(nsIDOMNode **result);
00114   NS_HIDDEN_(nsresult) GetSelectedInstanceElement(const nsAString &aInstance,
00115                                                   nsIModelElementPrivate *aModel,
00116                                                   nsIInstanceElementPrivate **result);
00117   NS_HIDDEN_(nsresult) SerializeData(nsIDOMDocument *data, nsCString &uri,
00118                                      nsIInputStream **, nsCString &contentType);
00119   NS_HIDDEN_(nsresult) SerializeDataXML(nsIDOMDocument *data, nsIInputStream **,
00120                                         nsCString &contentType);
00121   NS_HIDDEN_(nsresult) CreatePurgedDoc(nsIDOMNode *source,
00122                                        nsIDOMDocument **result);
00123   NS_HIDDEN_(nsresult) CopyChildren(nsIModelElementPrivate* model,
00124                                     nsIDOMNode *source, nsIDOMNode *dest,
00125                                     nsIDOMDocument *destDoc,
00126                                     const nsString &cdataElements,
00127                                     PRUint32 depth);
00128   NS_HIDDEN_(nsresult) SerializeDataURLEncoded(nsIDOMDocument *data,
00129                                                nsCString &uri,
00130                                                nsIInputStream **,
00131                                                nsCString &contentType);
00132   NS_HIDDEN_(void)     AppendURLEncodedData(nsIDOMNode *data,
00133                                             const nsCString &sep,
00134                                             nsCString &buf);
00135   NS_HIDDEN_(nsresult) SerializeDataMultipartRelated(nsIDOMDocument *data,
00136                                                      nsIInputStream **,
00137                                                      nsCString &contentType);
00138   NS_HIDDEN_(nsresult) SerializeDataMultipartFormData(nsIDOMDocument *data,
00139                                                       nsIInputStream **,
00140                                                       nsCString &contentType);
00141   NS_HIDDEN_(nsresult) AppendMultipartFormData(nsIDOMNode *data,
00142                                                const nsCString &boundary,
00143                                                nsCString &buf,
00144                                                nsIMultiplexInputStream *);
00145   NS_HIDDEN_(nsresult) AppendPostDataChunk(nsCString &postDataChunk,
00146                                            nsIMultiplexInputStream *multiStream);
00147   NS_HIDDEN_(nsresult) GetElementEncodingType(nsIDOMNode *data,
00148                                               PRUint32 *encType,
00149                                               nsIModelElementPrivate* aModel = nsnull);
00150   NS_HIDDEN_(nsresult) CreateFileStream(const nsString &absURI, nsIFile **file,
00151                                         nsIInputStream **stream);
00152   NS_HIDDEN_(nsresult) SendData(const nsCString &uri, nsIInputStream *stream,
00153                                 const nsCString &contentType);
00154 
00155 private:
00156   nsIDOMElement*                   mElement;
00157   PRPackedBool                     mSubmissionActive;
00158    // Valid when mSubmissionActive == PR_TRUE
00159   PRPackedBool                     mIsReplaceInstance;
00160   PRPackedBool                     mIsSOAPRequest;
00161   // Valid when mSubmissionActive == PR_TRUE
00162   PRUint32                         mFormat;
00163   nsCOMPtr<nsIXFormsSubmitElement> mActivator;
00164 
00165   // input end of pipe, which contains response data.
00166   nsCOMPtr<nsIInputStream>         mPipeIn;
00167 
00168   // Context Info for events.
00169   nsCOMArray<nsIXFormsContextInfo> mContextInfo;
00170   // Document for http header context info.
00171   nsCOMPtr<nsIDOMDocument>         mHttpHeaderDoc;
00172   // Submission body from xforms-submit-serialize.
00173   nsCOMPtr<nsIDOMNode>              mSubmissionBody;
00174   // Type of submit error.
00175   nsString                         mSubmitError;
00176 
00181   PRBool CheckSameOrigin(nsIDocument *aBaseDocument, nsIURI *aTestURI);
00182   nsresult AddNameSpaces(nsIDOMElement* aTarget, nsIDOMNode* aSource,
00183                          nsStringHashSet* aPrefixHash);
00184   nsresult GetIncludeNSPrefixesAttr(nsStringHashSet** aHash);
00185 
00192   void EndSubmit(PRBool aSucceeded);
00193 
00204   nsresult CreateSubmissionDoc(nsIDOMNode *aRoot,
00205                                nsIDOMDocument** aReturnDoc);
00206 
00215   nsresult CreateAttachments(nsIModelElementPrivate *aModel, nsIDOMNode *aDoc,
00216                              SubmissionAttachmentArray *aAttachments);
00217 
00221   nsresult SetContextInfo();
00222 
00229   nsresult SetHttpContextInfo(PRUint32 aResponse, const nsAString &aResponseText);
00230 
00231   nsresult ParseErrorResponse(nsIChannel *aChannel);
00232   nsresult OverrideRequestHeaders(nsIHttpChannel *aHttpChannel);
00233   nsresult ProcessHeaderElement(nsIDOMNode *aHeaderNode,
00234                                 nsIHttpChannel *aHttpChannel);
00235 };
00236 
00237 NS_HIDDEN_(nsresult)
00238 NS_NewXFormsSubmissionElement(nsIXTFElement **aResult);
00239 
00240 #endif