Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: Source/core/html/FormDataList.h

Issue 564963002: New FormData methods: get, getAll, has, set, delete and iterable (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove stray comma Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 : public RefCountedWillBeGarbageCollected<FormDataList> { 34 class FormDataList : public RefCountedWillBeGarbageCollected<FormDataList> {
34 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(FormDataList); 35 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(FormDataList);
35 public: 36 public:
37 class Entry final {
38 ALLOW_ONLY_INLINE_ALLOCATION();
39 public:
40 enum Type { None, StringType, FileType };
41
42 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, File* value) : m_type(FileType), m_name(name), m_file(value) { }
45
46 bool isNone() const { return m_type == None; }
47 bool isString() const { return m_type == StringType; }
48 bool isFile() const { return m_type == FileType; }
49
50 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 File* file() const { ASSERT(m_type == FileType); return m_file; }
53
54 void trace(Visitor*);
55
56 private:
57 const Type m_type;
58 const String m_name;
59 const String m_string;
60 const Member<File> m_file;
61 };
62
36 class Item { 63 class Item {
37 ALLOW_ONLY_INLINE_ALLOCATION(); 64 ALLOW_ONLY_INLINE_ALLOCATION();
38 public: 65 public:
39 Item() { } 66 Item() { }
40 Item(const WTF::CString& data) : m_data(data) { } 67 Item(const WTF::CString& data) : m_data(data) { }
41 Item(Blob* blob, const String& filename) : m_blob(blob), m_filename(file name) { } 68 Item(Blob* blob, const String& filename) : m_blob(blob), m_filename(file name) { }
42 69
43 const WTF::CString& data() const { return m_data; } 70 const WTF::CString& data() const { return m_data; }
44 Blob* blob() const { return m_blob.get(); } 71 Blob* blob() const { return m_blob.get(); }
45 const String& filename() const { return m_filename; } 72 const String& filename() const { return m_filename; }
(...skipping 27 matching lines...) Expand all
73 { 100 {
74 appendString(key); 101 appendString(key);
75 appendString(String::number(value)); 102 appendString(String::number(value));
76 } 103 }
77 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())
78 { 105 {
79 appendString(key); 106 appendString(key);
80 appendBlob(blob, filename); 107 appendBlob(blob, filename);
81 } 108 }
82 109
110 void deleteEntry(const String& key);
111 Entry getEntry(const String& key) const;
112 Entry getEntry(size_t index) const;
113 WillBeHeapVector<Entry> getAll(const String& key) const;
114 bool hasEntry(const String& key) const;
115 void setBlob(const String& key, Blob*, const String& filename);
116 void setData(const String& key, const String& value);
117 size_t size() const { return m_items.size() / 2; }
118
83 const FormDataListItems& items() const { return m_items; } 119 const FormDataListItems& items() const { return m_items; }
84 const WTF::TextEncoding& encoding() const { return m_encoding; } 120 const WTF::TextEncoding& encoding() const { return m_encoding; }
85 121
86 PassRefPtr<FormData> createFormData(FormData::EncodingType = FormData::FormU RLEncoded); 122 PassRefPtr<FormData> createFormData(FormData::EncodingType = FormData::FormU RLEncoded);
87 PassRefPtr<FormData> createMultiPartFormData(); 123 PassRefPtr<FormData> createMultiPartFormData();
88 124
89 virtual void trace(Visitor*); 125 virtual void trace(Visitor*);
90 126
91 protected: 127 protected:
92 explicit FormDataList(const WTF::TextEncoding&); 128 explicit FormDataList(const WTF::TextEncoding&);
93 129
94 private: 130 private:
95 void appendKeyValuePairItemsTo(FormData*, const WTF::TextEncoding&, bool isM ultiPartForm, FormData::EncodingType = FormData::FormURLEncoded); 131 void appendKeyValuePairItemsTo(FormData*, const WTF::TextEncoding&, bool isM ultiPartForm, FormData::EncodingType = FormData::FormURLEncoded);
96 132
97 void appendString(const CString&); 133 void appendString(const CString&);
98 void appendString(const String&); 134 void appendString(const String&);
99 void appendBlob(Blob*, const String& filename); 135 void appendBlob(Blob*, const String& filename);
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;
100 139
101 WTF::TextEncoding m_encoding; 140 WTF::TextEncoding m_encoding;
102 FormDataListItems m_items; 141 FormDataListItems m_items;
103 }; 142 };
104 143
105 } // namespace blink 144 } // namespace blink
106 145
107 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item); 146 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::FormDataList::Item);
sof 2015/01/22 07:33:40 As Entry is used in a heap vector, the same trait
jsbell 2015/01/22 19:05:39 Done.
108 147
109 #endif // FormDataList_h 148 #endif // FormDataList_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698