OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #ifndef FormDataList_h | 21 #ifndef FormDataList_h |
22 #define FormDataList_h | 22 #define FormDataList_h |
23 | 23 |
24 #include "core/fileapi/Blob.h" | 24 #include "core/fileapi/Blob.h" |
| 25 #include "core/fileapi/File.h" |
25 #include "platform/heap/Handle.h" | 26 #include "platform/heap/Handle.h" |
26 #include "platform/network/FormData.h" | 27 #include "platform/network/FormData.h" |
27 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
28 #include "wtf/text/CString.h" | 29 #include "wtf/text/CString.h" |
29 #include "wtf/text/TextEncoding.h" | 30 #include "wtf/text/TextEncoding.h" |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 class FormDataList { | 34 class FormDataList { |
34 public: | 35 public: |
| 36 class Entry FINAL { |
| 37 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 38 public: |
| 39 enum Type { None, StringType, FileType }; |
| 40 |
| 41 Entry() : m_type(None) { } |
| 42 Entry(const String& name, const String& value) : m_type(StringType), m_n
ame(name), m_string(value) { } |
| 43 Entry(const String& name, PassRefPtrWillBeRawPtr<File> value) : m_type(F
ileType), m_name(name), m_file(value) { } |
| 44 |
| 45 bool isNone() const { return m_type == None; } |
| 46 bool isString() const { return m_type == StringType; } |
| 47 bool isFile() const { return m_type == FileType; } |
| 48 |
| 49 const String& name() const { ASSERT(m_type != None); return m_name; } |
| 50 const String& string() const { ASSERT(m_type == StringType); return m_st
ring; } |
| 51 PassRefPtrWillBeRawPtr<File> file() const { ASSERT(m_type == FileType);
return m_file; } |
| 52 |
| 53 void trace(Visitor*); |
| 54 |
| 55 private: |
| 56 const Type m_type; |
| 57 const String m_name; |
| 58 const String m_string; |
| 59 const RefPtrWillBeMember<File> m_file; |
| 60 }; |
| 61 |
35 class Item { | 62 class Item { |
36 ALLOW_ONLY_INLINE_ALLOCATION(); | 63 ALLOW_ONLY_INLINE_ALLOCATION(); |
37 public: | 64 public: |
38 Item() { } | 65 Item() { } |
39 Item(const WTF::CString& data) : m_data(data) { } | 66 Item(const WTF::CString& data) : m_data(data) { } |
40 Item(PassRefPtrWillBeRawPtr<Blob> blob, const String& filename) : m_blob
(blob), m_filename(filename) { } | 67 Item(PassRefPtrWillBeRawPtr<Blob> blob, const String& filename) : m_blob
(blob), m_filename(filename) { } |
41 | 68 |
42 const WTF::CString& data() const { return m_data; } | 69 const WTF::CString& data() const { return m_data; } |
43 Blob* blob() const { return m_blob.get(); } | 70 Blob* blob() const { return m_blob.get(); } |
44 const String& filename() const { return m_filename; } | 71 const String& filename() const { return m_filename; } |
(...skipping 22 matching lines...) Expand all Loading... |
67 { | 94 { |
68 appendString(key); | 95 appendString(key); |
69 appendString(String::number(value)); | 96 appendString(String::number(value)); |
70 } | 97 } |
71 void appendBlob(const String& key, PassRefPtrWillBeRawPtr<Blob> blob, const
String& filename = String()) | 98 void appendBlob(const String& key, PassRefPtrWillBeRawPtr<Blob> blob, const
String& filename = String()) |
72 { | 99 { |
73 appendString(key); | 100 appendString(key); |
74 appendBlob(blob, filename); | 101 appendBlob(blob, filename); |
75 } | 102 } |
76 | 103 |
| 104 void deleteEntry(const String& key); |
| 105 Entry getEntry(const String& key) const; |
| 106 Entry getEntry(size_t index) const; |
| 107 WillBeHeapVector<Entry> getAll(const String& key) const; |
| 108 bool hasEntry(const String& key) const; |
| 109 void setBlob(const String& key, PassRefPtrWillBeRawPtr<Blob>, const String&
filename); |
| 110 void setData(const String& key, const String& value); |
| 111 size_t size() const { return m_items.size() / 2; } |
| 112 |
77 const WillBeHeapVector<Item>& items() const { return m_items; } | 113 const WillBeHeapVector<Item>& items() const { return m_items; } |
78 const WTF::TextEncoding& encoding() const { return m_encoding; } | 114 const WTF::TextEncoding& encoding() const { return m_encoding; } |
79 | 115 |
80 PassRefPtr<FormData> createFormData(FormData::EncodingType = FormData::FormU
RLEncoded); | 116 PassRefPtr<FormData> createFormData(FormData::EncodingType = FormData::FormU
RLEncoded); |
81 PassRefPtr<FormData> createMultiPartFormData(); | 117 PassRefPtr<FormData> createMultiPartFormData(); |
82 | 118 |
83 void trace(Visitor*); | 119 void trace(Visitor*); |
84 | 120 |
85 private: | 121 private: |
86 void appendKeyValuePairItemsTo(FormData*, const WTF::TextEncoding&, bool isM
ultiPartForm, FormData::EncodingType = FormData::FormURLEncoded); | 122 void appendKeyValuePairItemsTo(FormData*, const WTF::TextEncoding&, bool isM
ultiPartForm, FormData::EncodingType = FormData::FormURLEncoded); |
87 | 123 |
88 void appendString(const CString&); | 124 void appendString(const CString&); |
89 void appendString(const String&); | 125 void appendString(const String&); |
90 void appendBlob(PassRefPtrWillBeRawPtr<Blob>, const String& filename); | 126 void appendBlob(PassRefPtrWillBeRawPtr<Blob>, const String& filename); |
| 127 void setEntry(const String& key, const Item&); |
| 128 Entry itemsToEntry(const Item& key, const Item& value) const; |
| 129 CString encodeAndNormalize(const String& key) const; |
91 | 130 |
92 WTF::TextEncoding m_encoding; | 131 WTF::TextEncoding m_encoding; |
93 WillBeHeapVector<Item> m_items; | 132 WillBeHeapVector<Item> m_items; |
94 }; | 133 }; |
95 | 134 |
96 } // namespace blink | 135 } // namespace blink |
97 | 136 |
98 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item); | 137 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item); |
99 | 138 |
100 #endif // FormDataList_h | 139 #endif // FormDataList_h |
OLD | NEW |