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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/html/DOMFormData.h" | 32 #include "core/html/DOMFormData.h" |
33 | 33 |
34 #include "core/fileapi/Blob.h" | 34 #include "core/fileapi/Blob.h" |
| 35 #include "core/fileapi/File.h" |
35 #include "core/html/HTMLFormElement.h" | 36 #include "core/html/HTMLFormElement.h" |
36 #include "wtf/text/TextEncoding.h" | 37 #include "wtf/text/TextEncoding.h" |
37 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
| 42 namespace { |
| 43 |
| 44 class DOMFormDataIterationSource final : public PairIterable<String, FormDataEnt
ryValue>::IterationSource { |
| 45 public: |
| 46 DOMFormDataIterationSource(DOMFormData* formData) : m_formData(formData), m_
current(0) { } |
| 47 |
| 48 bool next(ScriptState* scriptState, String& key, FormDataEntryValue& value,
ExceptionState& exceptionState) override |
| 49 { |
| 50 if (m_current >= m_formData->size()) |
| 51 return false; |
| 52 |
| 53 const FormDataList::Entry entry = m_formData->getEntry(m_current++); |
| 54 key = entry.name(); |
| 55 if (entry.isString()) |
| 56 value.setUSVString(entry.string()); |
| 57 else if (entry.isFile()) |
| 58 value.setFile(entry.file()); |
| 59 else |
| 60 ASSERT_NOT_REACHED(); |
| 61 return true; |
| 62 } |
| 63 |
| 64 void trace(Visitor* visitor) override |
| 65 { |
| 66 visitor->trace(m_formData); |
| 67 PairIterable<String, FormDataEntryValue>::IterationSource::trace(visitor
); |
| 68 } |
| 69 |
| 70 private: |
| 71 const RefPtrWillBeMember<DOMFormData> m_formData; |
| 72 size_t m_current; |
| 73 }; |
| 74 |
| 75 } // namespace |
| 76 |
41 DOMFormData::DOMFormData(const WTF::TextEncoding& encoding) | 77 DOMFormData::DOMFormData(const WTF::TextEncoding& encoding) |
42 : FormDataList(encoding) | 78 : FormDataList(encoding) |
43 { | 79 { |
44 } | 80 } |
45 | 81 |
46 DOMFormData::DOMFormData(HTMLFormElement* form) | 82 DOMFormData::DOMFormData(HTMLFormElement* form) |
47 : FormDataList(UTF8Encoding()) | 83 : FormDataList(UTF8Encoding()) |
48 { | 84 { |
49 if (!form) | 85 if (!form) |
50 return; | 86 return; |
51 | 87 |
52 for (unsigned i = 0; i < form->associatedElements().size(); ++i) { | 88 for (unsigned i = 0; i < form->associatedElements().size(); ++i) { |
53 FormAssociatedElement* element = form->associatedElements()[i]; | 89 FormAssociatedElement* element = form->associatedElements()[i]; |
54 if (!toHTMLElement(element)->isDisabledFormControl()) | 90 if (!toHTMLElement(element)->isDisabledFormControl()) |
55 element->appendFormData(*this, true); | 91 element->appendFormData(*this, true); |
56 } | 92 } |
57 } | 93 } |
58 | 94 |
59 void DOMFormData::append(const String& name, const String& value) | 95 void DOMFormData::append(const String& name, const String& value) |
60 { | 96 { |
61 appendData(name, value); | 97 appendData(name, value); |
62 } | 98 } |
63 | 99 |
64 void DOMFormData::append(const String& name, Blob* blob, const String& filename) | 100 void DOMFormData::append(const String& name, Blob* blob, const String& filename) |
65 { | 101 { |
66 appendBlob(name, blob, filename); | 102 appendBlob(name, blob, filename); |
67 } | 103 } |
68 | 104 |
| 105 void DOMFormData::get(const String& name, FormDataEntryValue& result) |
| 106 { |
| 107 Entry entry = getEntry(name); |
| 108 if (entry.isString()) |
| 109 result.setUSVString(entry.string()); |
| 110 else if (entry.isFile()) |
| 111 result.setFile(entry.file()); |
| 112 else |
| 113 ASSERT(entry.isNone()); |
| 114 } |
| 115 |
| 116 Vector<FormDataEntryValue> DOMFormData::getAll(const String& name) |
| 117 { |
| 118 Vector<FormDataEntryValue> results; |
| 119 WillBeHeapVector<FormDataList::Entry> entries = FormDataList::getAll(name); |
| 120 for (size_t i = 0; i < entries.size(); ++i) { |
| 121 const FormDataList::Entry& entry = entries[i]; |
| 122 ASSERT(entry.name() == name); |
| 123 FormDataEntryValue value; |
| 124 if (entry.isString()) |
| 125 value.setUSVString(entry.string()); |
| 126 else if (entry.isFile()) |
| 127 value.setFile(entry.file()); |
| 128 else |
| 129 ASSERT_NOT_REACHED(); |
| 130 results.append(value); |
| 131 } |
| 132 ASSERT(results.size() == entries.size()); |
| 133 return results; |
| 134 } |
| 135 |
| 136 void DOMFormData::set(const String& name, const String& value) |
| 137 { |
| 138 setData(name, value); |
| 139 } |
| 140 |
| 141 void DOMFormData::set(const String& name, Blob* blob, const String& filename) |
| 142 { |
| 143 setBlob(name, blob, filename); |
| 144 } |
| 145 |
| 146 PairIterable<String, FormDataEntryValue>::IterationSource* DOMFormData::startIte
ration(ScriptState*, ExceptionState&) |
| 147 { |
| 148 return new DOMFormDataIterationSource(this); |
| 149 } |
| 150 |
69 } // namespace blink | 151 } // namespace blink |
OLD | NEW |