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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 "bindings/core/v8/V8Binding.h" | |
35 #include "bindings/core/v8/V8File.h" | |
36 #include "core/dom/Iterator.h" | |
Jens Widell
2015/01/15 07:35:06
You don't need to include this now, I think?
jsbell
2015/01/15 18:57:13
Done.
| |
34 #include "core/fileapi/Blob.h" | 37 #include "core/fileapi/Blob.h" |
38 #include "core/fileapi/File.h" | |
35 #include "core/html/HTMLFormElement.h" | 39 #include "core/html/HTMLFormElement.h" |
36 #include "wtf/text/TextEncoding.h" | 40 #include "wtf/text/TextEncoding.h" |
37 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
38 | 42 |
39 namespace blink { | 43 namespace blink { |
40 | 44 |
45 namespace { | |
46 | |
47 ScriptValue entryValueToScriptValue(ScriptState* scriptState, const FormDataList ::Entry& entry) | |
48 { | |
49 if (entry.isString()) | |
50 return ScriptValue(scriptState, v8String(scriptState->isolate(), entry.s tring())); | |
51 if (entry.isFile()) | |
52 return ScriptValue(scriptState, toV8(entry.file(), scriptState->context( )->Global(), scriptState->isolate())); | |
53 ASSERT(entry.isNone()); | |
54 return ScriptValue(scriptState, v8::Null(scriptState->isolate())); | |
55 } | |
56 | |
57 class DOMFormDataIterationSource final : public PairIterable<String, ScriptValue >::IterationSource { | |
58 public: | |
59 DOMFormDataIterationSource(DOMFormData* formData) : m_formData(formData), m_ current(0) { } | |
60 | |
61 virtual bool next(ScriptState* scriptState, String& key, ScriptValue& value, ExceptionState& exceptionState) override | |
62 { | |
63 if (m_current >= m_formData->size()) | |
64 return false; | |
65 | |
66 const FormDataList::Entry entry = m_formData->getEntry(m_current++); | |
67 ASSERT(!entry.isNone()); | |
68 key = entry.name(); | |
69 value = entryValueToScriptValue(scriptState, entry); | |
70 return true; | |
71 } | |
72 | |
73 virtual void trace(Visitor* visitor) | |
74 { | |
75 PairIterable<String, ScriptValue>::IterationSource::trace(visitor); | |
Jens Widell
2015/01/15 07:35:06
The convention is to make this a tail call, said h
jsbell
2015/01/15 18:57:13
Done.
| |
76 visitor->trace(m_formData); | |
77 } | |
78 | |
79 private: | |
80 const RefPtrWillBeMember<DOMFormData> m_formData; | |
81 size_t m_current; | |
82 }; | |
83 | |
84 } // namespace | |
85 | |
41 DOMFormData::DOMFormData(const WTF::TextEncoding& encoding) | 86 DOMFormData::DOMFormData(const WTF::TextEncoding& encoding) |
42 : FormDataList(encoding) | 87 : FormDataList(encoding) |
43 { | 88 { |
44 } | 89 } |
45 | 90 |
46 DOMFormData::DOMFormData(HTMLFormElement* form) | 91 DOMFormData::DOMFormData(HTMLFormElement* form) |
47 : FormDataList(UTF8Encoding()) | 92 : FormDataList(UTF8Encoding()) |
48 { | 93 { |
49 if (!form) | 94 if (!form) |
50 return; | 95 return; |
51 | 96 |
52 for (unsigned i = 0; i < form->associatedElements().size(); ++i) { | 97 for (unsigned i = 0; i < form->associatedElements().size(); ++i) { |
53 FormAssociatedElement* element = form->associatedElements()[i]; | 98 FormAssociatedElement* element = form->associatedElements()[i]; |
54 if (!toHTMLElement(element)->isDisabledFormControl()) | 99 if (!toHTMLElement(element)->isDisabledFormControl()) |
55 element->appendFormData(*this, true); | 100 element->appendFormData(*this, true); |
56 } | 101 } |
57 } | 102 } |
58 | 103 |
59 void DOMFormData::append(const String& name, const String& value) | 104 void DOMFormData::append(const String& name, const String& value) |
60 { | 105 { |
61 appendData(name, value); | 106 appendData(name, value); |
62 } | 107 } |
63 | 108 |
64 void DOMFormData::append(const String& name, Blob* blob, const String& filename) | 109 void DOMFormData::append(const String& name, Blob* blob, const String& filename) |
65 { | 110 { |
66 appendBlob(name, blob, filename); | 111 appendBlob(name, blob, filename); |
67 } | 112 } |
68 | 113 |
114 ScriptValue DOMFormData::get(ScriptState* scriptState, const String& name) | |
115 { | |
116 return entryValueToScriptValue(scriptState, getEntry(name)); | |
117 } | |
118 | |
119 Vector<ScriptValue> DOMFormData::getAll(ScriptState* scriptState, const String& name) | |
120 { | |
121 Vector<ScriptValue> results; | |
122 WillBeHeapVector<FormDataList::Entry> entries = FormDataList::getAll(name); | |
123 for (size_t i = 0; i < entries.size(); ++i) { | |
124 const FormDataList::Entry& entry = entries[i]; | |
125 ASSERT(!entry.isNone()); | |
126 ASSERT(entry.name() == name); | |
127 results.append(entryValueToScriptValue(scriptState, entry)); | |
128 } | |
129 ASSERT(results.size() == entries.size()); | |
130 return results; | |
131 } | |
132 | |
133 void DOMFormData::set(const String& name, const String& value) | |
134 { | |
135 setData(name, value); | |
136 } | |
137 | |
138 void DOMFormData::set(const String& name, Blob* blob, const String& filename) | |
139 { | |
140 setBlob(name, blob, filename); | |
141 } | |
142 | |
143 PairIterable<String, ScriptValue>::IterationSource* DOMFormData::startIteration( ScriptState*, ExceptionState&) | |
144 { | |
145 return new DOMFormDataIterationSource(this); | |
146 } | |
147 | |
69 } // namespace blink | 148 } // namespace blink |
OLD | NEW |