Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / FormDataList.h
1 /*
2  * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
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 FormDataList_h
22 #define FormDataList_h
23
24 #include "core/fileapi/Blob.h"
25 #include "platform/heap/Handle.h"
26 #include "platform/network/FormData.h"
27 #include "wtf/Forward.h"
28 #include "wtf/text/CString.h"
29 #include "wtf/text/TextEncoding.h"
30
31 namespace blink {
32
33 class FormDataList : public RefCountedWillBeGarbageCollected<FormDataList> {
34     DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(FormDataList);
35 public:
36     class Item {
37         ALLOW_ONLY_INLINE_ALLOCATION();
38     public:
39         Item() { }
40         Item(const WTF::CString& data) : m_data(data) { }
41         Item(Blob* blob, const String& filename) : m_blob(blob), m_filename(filename) { }
42
43         const WTF::CString& data() const { return m_data; }
44         Blob* blob() const { return m_blob.get(); }
45         const String& filename() const { return m_filename; }
46
47         void trace(Visitor*);
48
49     private:
50         WTF::CString m_data;
51         Member<Blob> m_blob;
52         String m_filename;
53     };
54
55     static PassRefPtrWillBeRawPtr<FormDataList> create(const WTF::TextEncoding& encoding)
56     {
57         return adoptRefWillBeNoop(new FormDataList(encoding));
58     }
59
60     typedef PersistentHeapVectorWillBeHeapVector<FormDataList::Item> FormDataListItems;
61
62     void appendData(const String& key, const String& value)
63     {
64         appendString(key);
65         appendString(value);
66     }
67     void appendData(const String& key, const CString& value)
68     {
69         appendString(key);
70         appendString(value);
71     }
72     void appendData(const String& key, int value)
73     {
74         appendString(key);
75         appendString(String::number(value));
76     }
77     void appendBlob(const String& key, Blob* blob, const String& filename = String())
78     {
79         appendString(key);
80         appendBlob(blob, filename);
81     }
82
83     const FormDataListItems& items() const { return m_items; }
84     const WTF::TextEncoding& encoding() const { return m_encoding; }
85
86     PassRefPtr<FormData> createFormData(FormData::EncodingType = FormData::FormURLEncoded);
87     PassRefPtr<FormData> createMultiPartFormData();
88
89     virtual void trace(Visitor*);
90
91 protected:
92     explicit FormDataList(const WTF::TextEncoding&);
93
94 private:
95     void appendKeyValuePairItemsTo(FormData*, const WTF::TextEncoding&, bool isMultiPartForm, FormData::EncodingType = FormData::FormURLEncoded);
96
97     void appendString(const CString&);
98     void appendString(const String&);
99     void appendBlob(Blob*, const String& filename);
100
101     WTF::TextEncoding m_encoding;
102     FormDataListItems m_items;
103 };
104
105 } // namespace blink
106
107 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item);
108
109 #endif // FormDataList_h