OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 void set(const String& name, const String& value); | 73 void set(const String& name, const String& value); |
74 void set(const String& name, Blob*, const String& filename = String()); | 74 void set(const String& name, Blob*, const String& filename = String()); |
75 | 75 |
76 // Internal functions. | 76 // Internal functions. |
77 | 77 |
78 void makeOpaque() { m_opaque = true; } | 78 void makeOpaque() { m_opaque = true; } |
79 bool opaque() const { return m_opaque; } | 79 bool opaque() const { return m_opaque; } |
80 | 80 |
81 const WTF::TextEncoding& encoding() const { return m_encoding; } | 81 const WTF::TextEncoding& encoding() const { return m_encoding; } |
82 class Entry; | 82 class Entry; |
83 const HeapVector<Entry>& entries() const { return m_entries; } | 83 const HeapVector<Member<const Entry>>& entries() const { return m_entries; } |
84 size_t size() const { return m_entries.size(); } | 84 size_t size() const { return m_entries.size(); } |
85 // TODO(tkent): Rename appendFoo functions to |append| for consistency with | 85 // TODO(tkent): Rename appendFoo functions to |append| for consistency with |
86 // public function. | 86 // public function. |
87 void appendData(const String& key, const String& value); | 87 void appendData(const String& key, const String& value); |
88 void appendData(const String& key, int value); | 88 void appendData(const String& key, int value); |
89 void appendBlob(const String& key, Blob*, const String& filename = String())
; | 89 void appendBlob(const String& key, Blob*, const String& filename = String())
; |
90 String decode(const CString& data) const; | 90 String decode(const CString& data) const; |
91 | 91 |
92 PassRefPtr<EncodedFormData> encodeFormData(EncodedFormData::EncodingType = E
ncodedFormData::FormURLEncoded); | 92 PassRefPtr<EncodedFormData> encodeFormData(EncodedFormData::EncodingType = E
ncodedFormData::FormURLEncoded); |
93 PassRefPtr<EncodedFormData> encodeMultiPartFormData(); | 93 PassRefPtr<EncodedFormData> encodeMultiPartFormData(); |
94 | 94 |
95 private: | 95 private: |
96 explicit FormData(const WTF::TextEncoding&); | 96 explicit FormData(const WTF::TextEncoding&); |
97 explicit FormData(HTMLFormElement*); | 97 explicit FormData(HTMLFormElement*); |
98 void setEntry(const Entry&); | 98 void setEntry(const Entry*); |
99 CString encodeAndNormalize(const String& key) const; | 99 CString encodeAndNormalize(const String& key) const; |
100 IterationSource* startIteration(ScriptState*, ExceptionState&) override; | 100 IterationSource* startIteration(ScriptState*, ExceptionState&) override; |
101 | 101 |
102 WTF::TextEncoding m_encoding; | 102 WTF::TextEncoding m_encoding; |
103 HeapVector<Entry> m_entries; | 103 // Entry pointers in m_entries never be nullptr. |
| 104 HeapVector<Member<const Entry>> m_entries; |
104 bool m_opaque; | 105 bool m_opaque; |
105 }; | 106 }; |
106 | 107 |
107 // Represents entry, which is a pair of a name and a value. | 108 // Represents entry, which is a pair of a name and a value. |
108 // https://xhr.spec.whatwg.org/#concept-formdata-entry | 109 // https://xhr.spec.whatwg.org/#concept-formdata-entry |
109 class FormData::Entry { | 110 // Entry objects are immutable. |
110 ALLOW_ONLY_INLINE_ALLOCATION(); | 111 class FormData::Entry : public GarbageCollectedFinalized<FormData::Entry> { |
111 public: | 112 public: |
112 Entry(const CString& key, const CString& data) : m_key(key), m_data(data) {
} | 113 Entry(const CString& key, const CString& data) : m_key(key), m_data(data) {
} |
113 Entry(const CString& key, Blob* blob, const String& filename) : m_key(key),
m_blob(blob), m_filename(filename) { } | 114 Entry(const CString& key, Blob* blob, const String& filename) : m_key(key),
m_blob(blob), m_filename(filename) { } |
114 DECLARE_TRACE(); | 115 DECLARE_TRACE(); |
115 | 116 |
116 bool isString() const { return !m_blob; } | 117 bool isString() const { return !m_blob; } |
117 bool isFile() const { return m_blob; } | 118 bool isFile() const { return m_blob; } |
118 const CString& key() const { return m_key; } | 119 const CString& key() const { return m_key; } |
119 const CString& data() const { return m_data; } | 120 const CString& data() const { return m_data; } |
120 Blob* blob() const { return m_blob.get(); } | 121 Blob* blob() const { return m_blob.get(); } |
121 File* file() const; | 122 File* file() const; |
122 const String& filename() const { return m_filename; } | 123 const String& filename() const { return m_filename; } |
123 | 124 |
124 private: | 125 private: |
125 CString m_key; | 126 const CString m_key; |
126 CString m_data; | 127 const CString m_data; |
127 Member<Blob> m_blob; | 128 const Member<Blob> m_blob; |
128 String m_filename; | 129 const String m_filename; |
129 }; | 130 }; |
130 | 131 |
131 } // namespace blink | 132 } // namespace blink |
132 | 133 |
133 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::FormData::Entry); | |
134 | |
135 #endif // FormData_h | 134 #endif // FormData_h |
OLD | NEW |