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