Home | History | Annotate | Download | only in network
      1 /*
      2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  *
     19  */
     20 
     21 #ifndef FormDataBuilder_h
     22 #define FormDataBuilder_h
     23 
     24 #include "PlatformString.h"
     25 #include <wtf/Noncopyable.h>
     26 
     27 namespace WebCore {
     28 
     29 class CString;
     30 class Document;
     31 class TextEncoding;
     32 
     33 class FormDataBuilder : public Noncopyable {
     34 public:
     35     FormDataBuilder();
     36     ~FormDataBuilder();
     37 
     38     bool isPostMethod() const { return m_isPostMethod; }
     39     void setIsPostMethod(bool value) { m_isPostMethod = value; }
     40 
     41     bool isMultiPartForm() const { return m_isMultiPartForm; }
     42     void setIsMultiPartForm(bool value) { m_isMultiPartForm = value; }
     43 
     44     String encodingType() const { return m_encodingType; }
     45     void setEncodingType(const String& value) { m_encodingType = value; }
     46 
     47     String acceptCharset() const { return m_acceptCharset; }
     48     void setAcceptCharset(const String& value) { m_acceptCharset = value; }
     49 
     50     void parseEncodingType(const String&);
     51     void parseMethodType(const String&);
     52 
     53     TextEncoding dataEncoding(Document*) const;
     54 
     55     // Helper functions used by HTMLFormElement/WMLGoElement for multi-part form data
     56     static Vector<char> generateUniqueBoundaryString();
     57     static void beginMultiPartHeader(Vector<char>&, const CString& boundary, const CString& name);
     58     static void addBoundaryToMultiPartHeader(Vector<char>&, const CString& boundary, bool isLastBoundary = false);
     59     static void addFilenameToMultiPartHeader(Vector<char>&, const TextEncoding&, const String& filename);
     60     static void addContentTypeToMultiPartHeader(Vector<char>&, const CString& mimeType);
     61     static void finishMultiPartHeader(Vector<char>&);
     62 
     63     // Helper functions used by HTMLFormElement/WMLGoElement for non multi-part form data
     64     static void addKeyValuePairAsFormData(Vector<char>&, const CString& key, const CString& value);
     65     static void encodeStringAsFormData(Vector<char>&, const CString&);
     66 
     67 private:
     68     bool m_isPostMethod;
     69     bool m_isMultiPartForm;
     70 
     71     String m_encodingType;
     72     String m_acceptCharset;
     73 };
     74 
     75 }
     76 
     77 #endif
     78