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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "platform/network/EncodedFormData.h" | 28 #include "platform/network/EncodedFormData.h" |
29 #include "wtf/Forward.h" | 29 #include "wtf/Forward.h" |
30 #include "wtf/text/CString.h" | 30 #include "wtf/text/CString.h" |
31 #include "wtf/text/TextEncoding.h" | 31 #include "wtf/text/TextEncoding.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 // TODO(tkent): Merge FormDataList into DOMFormData. | 35 // TODO(tkent): Merge FormDataList into DOMFormData. |
36 class CORE_EXPORT FormDataList : public GarbageCollected<FormDataList> { | 36 class CORE_EXPORT FormDataList : public GarbageCollected<FormDataList> { |
37 public: | 37 public: |
38 // TODO(tkent): Merge Entry and Item. | |
39 class Entry final { | |
40 ALLOW_ONLY_INLINE_ALLOCATION(); | |
41 public: | |
42 enum Type { None, StringType, FileType }; | |
43 | |
44 Entry() : m_type(None) { } | |
45 Entry(const String& name, const String& value) : m_type(StringType), m_n
ame(name), m_string(value) { } | |
46 Entry(const String& name, File* value) : m_type(FileType), m_name(name),
m_file(value) { } | |
47 | |
48 bool isNone() const { return m_type == None; } | |
49 bool isString() const { return m_type == StringType; } | |
50 bool isFile() const { return m_type == FileType; } | |
51 | |
52 const String& name() const { ASSERT(m_type != None); return m_name; } | |
53 const String& string() const { ASSERT(m_type == StringType); return m_st
ring; } | |
54 File* file() const { ASSERT(m_type == FileType); return m_file; } | |
55 | |
56 DECLARE_TRACE(); | |
57 | |
58 private: | |
59 const Type m_type; | |
60 const String m_name; | |
61 const String m_string; | |
62 const Member<File> m_file; | |
63 }; | |
64 | |
65 class Item { | 38 class Item { |
66 ALLOW_ONLY_INLINE_ALLOCATION(); | 39 ALLOW_ONLY_INLINE_ALLOCATION(); |
67 public: | 40 public: |
68 Item(const CString& key) : m_key(key) { } | 41 Item(const CString& key) : m_key(key) { } |
69 Item(const CString& key, const CString& data) : m_key(key), m_data(data)
{ } | 42 Item(const CString& key, const CString& data) : m_key(key), m_data(data)
{ } |
70 Item(const CString& key, Blob* blob, const String& filename) : m_key(key
), m_blob(blob), m_filename(filename) { } | 43 Item(const CString& key, Blob* blob, const String& filename) : m_key(key
), m_blob(blob), m_filename(filename) { } |
71 | 44 |
72 bool isString() const { return !m_blob; } | 45 bool isString() const { return !m_blob; } |
73 bool isFile() const { return m_blob; } | 46 bool isFile() const { return m_blob; } |
74 const CString& key() const { return m_key; } | 47 const CString& key() const { return m_key; } |
(...skipping 23 matching lines...) Expand all Loading... |
98 } | 71 } |
99 void appendData(const String& key, int value) | 72 void appendData(const String& key, int value) |
100 { | 73 { |
101 appendItem(Item(encodeAndNormalize(key), encodeAndNormalize(String::numb
er(value)))); | 74 appendItem(Item(encodeAndNormalize(key), encodeAndNormalize(String::numb
er(value)))); |
102 } | 75 } |
103 void appendBlob(const String& key, Blob* blob, const String& filename = Stri
ng()) | 76 void appendBlob(const String& key, Blob* blob, const String& filename = Stri
ng()) |
104 { | 77 { |
105 appendItem(Item(encodeAndNormalize(key), blob, filename)); | 78 appendItem(Item(encodeAndNormalize(key), blob, filename)); |
106 } | 79 } |
107 | 80 |
108 Entry getEntry(const String& key) const; | |
109 HeapVector<Entry> getAll(const String& key) const; | |
110 size_t size() const { return m_items.size(); } | 81 size_t size() const { return m_items.size(); } |
111 | 82 |
112 const FormDataListItems& items() const { return m_items; } | 83 const FormDataListItems& items() const { return m_items; } |
113 const WTF::TextEncoding& encoding() const { return m_encoding; } | 84 const WTF::TextEncoding& encoding() const { return m_encoding; } |
114 | 85 |
115 PassRefPtr<EncodedFormData> createFormData(EncodedFormData::EncodingType = E
ncodedFormData::FormURLEncoded); | 86 PassRefPtr<EncodedFormData> createFormData(EncodedFormData::EncodingType = E
ncodedFormData::FormURLEncoded); |
116 PassRefPtr<EncodedFormData> createMultiPartFormData(); | 87 PassRefPtr<EncodedFormData> createMultiPartFormData(); |
117 | 88 |
118 DECLARE_VIRTUAL_TRACE(); | 89 DECLARE_VIRTUAL_TRACE(); |
119 | 90 |
120 protected: | 91 protected: |
121 explicit FormDataList(const WTF::TextEncoding&); | 92 explicit FormDataList(const WTF::TextEncoding&); |
122 CString encodeAndNormalize(const String& key) const; | 93 CString encodeAndNormalize(const String& key) const; |
123 | 94 |
124 FormDataListItems m_items; | 95 FormDataListItems m_items; |
125 | 96 |
126 private: | 97 private: |
127 void appendKeyValuePairItemsTo(EncodedFormData*, const WTF::TextEncoding&, b
ool isMultiPartForm, EncodedFormData::EncodingType = EncodedFormData::FormURLEnc
oded); | 98 void appendKeyValuePairItemsTo(EncodedFormData*, const WTF::TextEncoding&, b
ool isMultiPartForm, EncodedFormData::EncodingType = EncodedFormData::FormURLEnc
oded); |
128 | 99 |
129 void appendItem(const Item&); | 100 void appendItem(const Item&); |
130 Entry itemsToEntry(const Item&) const; | |
131 | 101 |
132 WTF::TextEncoding m_encoding; | 102 WTF::TextEncoding m_encoding; |
133 }; | 103 }; |
134 | 104 |
135 } // namespace blink | 105 } // namespace blink |
136 | 106 |
137 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Entry); | |
138 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item); | 107 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item); |
139 | 108 |
140 #endif // FormDataList_h | 109 #endif // FormDataList_h |
OLD | NEW |