Index: Source/core/html/FormDataList.cpp |
diff --git a/Source/core/html/FormDataList.cpp b/Source/core/html/FormDataList.cpp |
index f0d1e1c06229a945f3bcde178935940653043583..2c62b3daf5b239f95f8bf11a2bac8b1480ef8113 100644 |
--- a/Source/core/html/FormDataList.cpp |
+++ b/Source/core/html/FormDataList.cpp |
@@ -24,6 +24,7 @@ |
#include "core/fileapi/File.h" |
#include "platform/network/FormDataBuilder.h" |
#include "platform/text/LineEnding.h" |
+#include "wtf/CurrentTime.h" |
namespace blink { |
@@ -34,8 +35,7 @@ FormDataList::FormDataList(const WTF::TextEncoding& c) |
void FormDataList::appendString(const String& string) |
{ |
- CString encodedString = m_encoding.encode(string, WTF::EntitiesForUnencodables); |
- m_items.append(normalizeLineEndingsToCRLF(encodedString)); |
+ m_items.append(encodeAndNormalize(string)); |
} |
void FormDataList::appendString(const CString& string) |
@@ -48,6 +48,124 @@ void FormDataList::appendBlob(PassRefPtrWillBeRawPtr<Blob> blob, const String& f |
m_items.append(Item(blob, filename)); |
} |
+void FormDataList::deleteItem(const String& key) |
+{ |
+ const CString keyData = encodeAndNormalize(key); |
+ ASSERT(!(m_items.size() % 2)); |
+ size_t i = 0; |
+ while (i < m_items.size()) { |
+ if (m_items[i].data() == keyData) { |
+ m_items.remove(i, 2); |
+ } else { |
+ i += 2; |
+ } |
+ } |
+ ASSERT(!(m_items.size() % 2)); |
+ return; |
+} |
+ |
+FormDataList::EntryValue FormDataList::getItem(const String& key) const |
+{ |
+ const CString keyData = encodeAndNormalize(key); |
+ const WillBeHeapVector<Item>& items = this->items(); |
+ size_t formDataListSize = items.size(); |
+ ASSERT(!(formDataListSize % 2)); |
+ for (size_t i = 0; i < formDataListSize; i += 2) { |
+ const FormDataList::Item& key = items[i]; |
+ if (key.data() != keyData) |
+ continue; |
+ const FormDataList::Item& value = items[i + 1]; |
+ return itemToEntryValue(value); |
+ } |
+ return EntryValue(); |
+} |
+ |
+Vector<FormDataList::EntryValue> FormDataList::getAll(const String& key) const |
+{ |
+ Vector<FormDataList::EntryValue> matches; |
sof
2014/09/12 15:21:26
Vector => WillBeHeapVector
jsbell
2014/09/12 16:30:09
Done.
|
+ |
+ const CString keyData = encodeAndNormalize(key); |
+ const WillBeHeapVector<Item>& items = this->items(); |
+ size_t formDataListSize = items.size(); |
+ ASSERT(!(formDataListSize % 2)); |
+ for (size_t i = 0; i < formDataListSize; i += 2) { |
+ const FormDataList::Item& key = items[i]; |
+ if (key.data() != keyData) |
+ continue; |
+ const FormDataList::Item& value = items[i + 1]; |
+ matches.append(itemToEntryValue(value)); |
+ } |
+ |
+ return matches; |
+} |
+ |
+FormDataList::EntryValue FormDataList::itemToEntryValue(const FormDataList::Item& value) const |
+{ |
+ if (!value.blob()) { |
+ const CString data = value.data(); |
+ return EntryValue(m_encoding.decode(data.data(), data.length())); |
+ } |
+ |
+ if (value.blob()->isFile()) { |
+ // FIXME: Overwrite file's name with value.filename(). |
+ return EntryValue(toFile(value.blob())); |
+ } |
+ |
+ String filename = value.filename(); |
+ if (filename.isNull()) |
+ filename = "blob"; |
+ return EntryValue(File::create(filename, currentTimeMS(), value.blob()->blobDataHandle())); |
tyoshino (SeeGerritForStatus)
2014/09/12 07:29:32
this looks equivalent to what's specified in the s
jsbell
2014/09/12 16:30:09
Thanks!
|
+} |
+ |
+bool FormDataList::hasItem(const String& key) const |
+{ |
+ const CString keyData = encodeAndNormalize(key); |
+ const WillBeHeapVector<Item>& items = this->items(); |
+ size_t formDataListSize = items.size(); |
+ ASSERT(!(formDataListSize % 2)); |
+ for (size_t i = 0; i < formDataListSize; i += 2) { |
+ const FormDataList::Item& key = items[i]; |
+ if (key.data() == keyData) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+void FormDataList::setBlob(const String& key, PassRefPtrWillBeRawPtr<Blob> blob, const String& filename) |
+{ |
+ setItem(key, Item(blob, filename)); |
+} |
+ |
+void FormDataList::setData(const String& key, const String& value) |
+{ |
+ setItem(key, encodeAndNormalize(value)); |
+} |
+ |
+void FormDataList::setItem(const String& key, const Item& item) |
+{ |
+ const CString keyData = encodeAndNormalize(key); |
+ ASSERT(!(m_items.size() % 2)); |
+ bool found = false; |
+ size_t i = 0; |
+ while (i < m_items.size()) { |
+ if (m_items[i].data() != keyData) { |
+ i += 2; |
+ } else if (found) { |
+ m_items.remove(i, 2); |
+ } else { |
+ found = true; |
+ m_items[i + 1] = item; |
+ i += 2; |
+ } |
+ } |
+ if (!found) { |
+ m_items.append(keyData); |
+ m_items.append(item); |
+ } |
+ ASSERT(!(m_items.size() % 2)); |
+ return; |
+} |
+ |
PassRefPtr<FormData> FormDataList::createFormData(FormData::EncodingType encodingType) |
{ |
RefPtr<FormData> result = FormData::create(); |
@@ -140,6 +258,12 @@ void FormDataList::appendKeyValuePairItemsTo(FormData* formData, const WTF::Text |
formData->appendData(encodedData.data(), encodedData.size()); |
} |
+CString FormDataList::encodeAndNormalize(const String& string) const |
+{ |
+ CString encodedString = m_encoding.encode(string, WTF::EntitiesForUnencodables); |
+ return normalizeLineEndingsToCRLF(encodedString); |
+} |
+ |
void FormDataList::trace(Visitor* visitor) |
{ |
visitor->trace(m_items); |