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

Unified Diff: Source/core/html/DOMFormData.cpp

Issue 564963002: New FormData methods: get, getAll, has, set, delete and iterable (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: webexposed/global-interface-listing updates 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/DOMFormData.h ('k') | Source/core/html/FormData.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/DOMFormData.cpp
diff --git a/Source/core/html/DOMFormData.cpp b/Source/core/html/DOMFormData.cpp
index 9379f8cc520a2d0bc7fc233515ef6b550811c903..1abdd46ed4d252a212d446c83c2e91e73ec56701 100644
--- a/Source/core/html/DOMFormData.cpp
+++ b/Source/core/html/DOMFormData.cpp
@@ -32,12 +32,48 @@
#include "core/html/DOMFormData.h"
#include "core/fileapi/Blob.h"
+#include "core/fileapi/File.h"
#include "core/html/HTMLFormElement.h"
#include "wtf/text/TextEncoding.h"
#include "wtf/text/WTFString.h"
namespace blink {
+namespace {
+
+class DOMFormDataIterationSource final : public PairIterable<String, FormDataEntryValue>::IterationSource {
+public:
+ DOMFormDataIterationSource(DOMFormData* formData) : m_formData(formData), m_current(0) { }
+
+ bool next(ScriptState* scriptState, String& key, FormDataEntryValue& value, ExceptionState& exceptionState) override
+ {
+ if (m_current >= m_formData->size())
+ return false;
+
+ const FormDataList::Entry entry = m_formData->getEntry(m_current++);
+ key = entry.name();
+ if (entry.isString())
+ value.setUSVString(entry.string());
+ else if (entry.isFile())
+ value.setFile(entry.file());
+ else
+ ASSERT_NOT_REACHED();
+ return true;
+ }
+
+ void trace(Visitor* visitor) override
+ {
+ visitor->trace(m_formData);
+ PairIterable<String, FormDataEntryValue>::IterationSource::trace(visitor);
+ }
+
+private:
+ const RefPtrWillBeMember<DOMFormData> m_formData;
+ size_t m_current;
+};
+
+} // namespace
+
DOMFormData::DOMFormData(const WTF::TextEncoding& encoding)
: FormDataList(encoding)
{
@@ -66,4 +102,50 @@ void DOMFormData::append(const String& name, Blob* blob, const String& filename)
appendBlob(name, blob, filename);
}
+void DOMFormData::get(const String& name, FormDataEntryValue& result)
+{
+ Entry entry = getEntry(name);
+ if (entry.isString())
+ result.setUSVString(entry.string());
+ else if (entry.isFile())
+ result.setFile(entry.file());
+ else
+ ASSERT(entry.isNone());
+}
+
+Vector<FormDataEntryValue> DOMFormData::getAll(const String& name)
+{
+ Vector<FormDataEntryValue> results;
+ WillBeHeapVector<FormDataList::Entry> entries = FormDataList::getAll(name);
+ for (size_t i = 0; i < entries.size(); ++i) {
+ const FormDataList::Entry& entry = entries[i];
+ ASSERT(entry.name() == name);
+ FormDataEntryValue value;
+ if (entry.isString())
+ value.setUSVString(entry.string());
+ else if (entry.isFile())
+ value.setFile(entry.file());
+ else
+ ASSERT_NOT_REACHED();
+ results.append(value);
+ }
+ ASSERT(results.size() == entries.size());
+ return results;
+}
+
+void DOMFormData::set(const String& name, const String& value)
+{
+ setData(name, value);
+}
+
+void DOMFormData::set(const String& name, Blob* blob, const String& filename)
+{
+ setBlob(name, blob, filename);
+}
+
+PairIterable<String, FormDataEntryValue>::IterationSource* DOMFormData::startIteration(ScriptState*, ExceptionState&)
+{
+ return new DOMFormDataIterationSource(this);
+}
+
} // namespace blink
« no previous file with comments | « Source/core/html/DOMFormData.h ('k') | Source/core/html/FormData.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698