Upstream version 9.38.198.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 {
34 public:
35     class Item {
36         ALLOW_ONLY_INLINE_ALLOCATION();
37     public:
38         Item() { }
39         Item(const WTF::CString& data) : m_data(data) { }
40         Item(PassRefPtrWillBeRawPtr<Blob> blob, const String& filename) : m_blob(blob), m_filename(filename) { }
41
42         const WTF::CString& data() const { return m_data; }
43         Blob* blob() const { return m_blob.get(); }
44         const String& filename() const { return m_filename; }
45
46         void trace(Visitor*);
47
48     private:
49         WTF::CString m_data;
50         RefPtrWillBeMember<Blob> m_blob;
51         String m_filename;
52     };
53
54     FormDataList(const WTF::TextEncoding&);
55
56     void appendData(const String& key, const String& value)
57     {
58         appendString(key);
59         appendString(value);
60     }
61     void appendData(const String& key, const CString& value)
62     {
63         appendString(key);
64         appendString(value);
65     }
66     void appendData(const String& key, int value)
67     {
68         appendString(key);
69         appendString(String::number(value));
70     }
71     void appendBlob(const String& key, PassRefPtrWillBeRawPtr<Blob> blob, const String& filename = String())
72     {
73         appendString(key);
74         appendBlob(blob, filename);
75     }
76
77     const WillBeHeapVector<Item>& items() const { return m_items; }
78     const WTF::TextEncoding& encoding() const { return m_encoding; }
79
80     PassRefPtr<FormData> createFormData(FormData::EncodingType = FormData::FormURLEncoded);
81     PassRefPtr<FormData> createMultiPartFormData();
82
83     void trace(Visitor*);
84
85 private:
86     void appendKeyValuePairItemsTo(FormData*, const WTF::TextEncoding&, bool isMultiPartForm, FormData::EncodingType = FormData::FormURLEncoded);
87
88     void appendString(const CString&);
89     void appendString(const String&);
90     void appendBlob(PassRefPtrWillBeRawPtr<Blob>, const String& filename);
91
92     WTF::TextEncoding m_encoding;
93     WillBeHeapVector<Item> m_items;
94 };
95
96 } // namespace blink
97
98 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item);
99
100 #endif // FormDataList_h