Commit fd0384db authored by tkent@chromium.org's avatar tkent@chromium.org

Move FormDataList::deleteEntry() and hasEntry() to DOMFormData.

- Move FormDataList::deleteEntry() to DOMFormData
- Fold FormDataList::hasEntry() into DOMFormData::has().

This CL has no behavior changes.

BUG=528840

Review URL: https://codereview.chromium.org/1308183006

git-svn-id: svn://svn.chromium.org/blink/trunk@201951 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent febb09a0
...@@ -120,6 +120,19 @@ void DOMFormData::append(ExecutionContext* context, const String& name, Blob* bl ...@@ -120,6 +120,19 @@ void DOMFormData::append(ExecutionContext* context, const String& name, Blob* bl
appendBlob(name, blob, filename); appendBlob(name, blob, filename);
} }
void DOMFormData::deleteEntry(const String& name)
{
const CString keyData = encodeAndNormalize(name);
size_t i = 0;
while (i < m_items.size()) {
if (m_items[i].key() == keyData) {
m_items.remove(i);
} else {
++i;
}
}
}
void DOMFormData::get(const String& name, FormDataEntryValue& result) void DOMFormData::get(const String& name, FormDataEntryValue& result)
{ {
if (m_opaque) if (m_opaque)
...@@ -160,7 +173,12 @@ bool DOMFormData::has(const String& name) ...@@ -160,7 +173,12 @@ bool DOMFormData::has(const String& name)
{ {
if (m_opaque) if (m_opaque)
return false; return false;
return hasEntry(name); const CString keyData = encodeAndNormalize(name);
for (const Item& item : items()) {
if (item.key() == keyData)
return true;
}
return false;
} }
void DOMFormData::set(const String& name, const String& value) void DOMFormData::set(const String& name, const String& value)
......
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
// FormData interface. // FormData interface.
void append(const String& name, const String& value); void append(const String& name, const String& value);
void append(ExecutionContext*, const String& name, Blob*, const String& filename = String()); void append(ExecutionContext*, const String& name, Blob*, const String& filename = String());
void deleteEntry(const String& name);
void get(const String& name, FormDataEntryValue& result); void get(const String& name, FormDataEntryValue& result);
HeapVector<FormDataEntryValue> getAll(const String& name); HeapVector<FormDataEntryValue> getAll(const String& name);
bool has(const String& name); bool has(const String& name);
......
...@@ -63,15 +63,15 @@ TEST(DOMFormDataTest, opacityHas) ...@@ -63,15 +63,15 @@ TEST(DOMFormDataTest, opacityHas)
fd->append("name1", "value1"); fd->append("name1", "value1");
EXPECT_TRUE(fd->has("name1")); EXPECT_TRUE(fd->has("name1"));
EXPECT_TRUE(fd->hasEntry("name1")); EXPECT_EQ(1u, fd->size());
fd->makeOpaque(); fd->makeOpaque();
// Web-exposed interface should be opaque. // Web-exposed interface should be opaque.
EXPECT_FALSE(fd->has("name1")); EXPECT_FALSE(fd->has("name1"));
// Internal interface should be uneffected. // Internal collection should be uneffected.
EXPECT_TRUE(fd->hasEntry("name1")); EXPECT_EQ(1u, fd->size());
} }
} // namespace blink } // namespace blink
...@@ -38,20 +38,6 @@ void FormDataList::appendItem(const FormDataList::Item& item) ...@@ -38,20 +38,6 @@ void FormDataList::appendItem(const FormDataList::Item& item)
m_items.append(item); m_items.append(item);
} }
void FormDataList::deleteEntry(const String& key)
{
const CString keyData = encodeAndNormalize(key);
size_t i = 0;
while (i < m_items.size()) {
if (m_items[i].key() == keyData) {
m_items.remove(i);
} else {
++i;
}
}
return;
}
FormDataList::Entry FormDataList::getEntry(const String& key) const FormDataList::Entry FormDataList::getEntry(const String& key) const
{ {
const CString keyData = encodeAndNormalize(key); const CString keyData = encodeAndNormalize(key);
...@@ -111,16 +97,6 @@ FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& item) c ...@@ -111,16 +97,6 @@ FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& item) c
return Entry(name, File::create(filename, currentTimeMS(), item.blob()->blobDataHandle())); return Entry(name, File::create(filename, currentTimeMS(), item.blob()->blobDataHandle()));
} }
bool FormDataList::hasEntry(const String& key) const
{
const CString keyData = encodeAndNormalize(key);
for (const Item& item : items()) {
if (item.key() == keyData)
return true;
}
return false;
}
PassRefPtr<FormData> FormDataList::createFormData(FormData::EncodingType encodingType) PassRefPtr<FormData> FormDataList::createFormData(FormData::EncodingType encodingType)
{ {
RefPtr<FormData> result = FormData::create(); RefPtr<FormData> result = FormData::create();
......
...@@ -102,11 +102,9 @@ public: ...@@ -102,11 +102,9 @@ public:
appendItem(Item(encodeAndNormalize(key), blob, filename)); appendItem(Item(encodeAndNormalize(key), blob, filename));
} }
void deleteEntry(const String& key);
Entry getEntry(const String& key) const; Entry getEntry(const String& key) const;
Entry getEntry(size_t index) const; Entry getEntry(size_t index) const;
HeapVector<Entry> getAll(const String& key) const; HeapVector<Entry> getAll(const String& key) const;
bool hasEntry(const String& key) const;
size_t size() const { return m_items.size(); } size_t size() const { return m_items.size(); }
const FormDataListItems& items() const { return m_items; } const FormDataListItems& items() const { return m_items; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment