| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 bool next(ScriptState* scriptState, String& name, FormDataEntryValue& value,
ExceptionState& exceptionState) override | 49 bool next(ScriptState* scriptState, String& name, FormDataEntryValue& value,
ExceptionState& exceptionState) override |
| 50 { | 50 { |
| 51 if (m_current >= m_formData->size()) | 51 if (m_current >= m_formData->size()) |
| 52 return false; | 52 return false; |
| 53 | 53 |
| 54 const FormData::Entry& entry = *m_formData->entries()[m_current++]; | 54 const FormData::Entry& entry = *m_formData->entries()[m_current++]; |
| 55 name = m_formData->decode(entry.name()); | 55 name = m_formData->decode(entry.name()); |
| 56 if (entry.isString()) { | 56 if (entry.isString()) { |
| 57 value.setUSVString(m_formData->decode(entry.value())); | 57 value.setUSVString(m_formData->decode(entry.value())); |
| 58 } else { | 58 } else { |
| 59 ASSERT(entry.isFile()); | 59 DCHECK(entry.isFile()); |
| 60 value.setFile(entry.file()); | 60 value.setFile(entry.file()); |
| 61 } | 61 } |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 DEFINE_INLINE_VIRTUAL_TRACE() | 65 DEFINE_INLINE_VIRTUAL_TRACE() |
| 66 { | 66 { |
| 67 visitor->trace(m_formData); | 67 visitor->trace(m_formData); |
| 68 PairIterable<String, FormDataEntryValue>::IterationSource::trace(visitor
); | 68 PairIterable<String, FormDataEntryValue>::IterationSource::trace(visitor
); |
| 69 } | 69 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 | 138 |
| 139 void FormData::get(const String& name, FormDataEntryValue& result) | 139 void FormData::get(const String& name, FormDataEntryValue& result) |
| 140 { | 140 { |
| 141 const CString encodedName = encodeAndNormalize(name); | 141 const CString encodedName = encodeAndNormalize(name); |
| 142 for (const auto& entry : entries()) { | 142 for (const auto& entry : entries()) { |
| 143 if (entry->name() == encodedName) { | 143 if (entry->name() == encodedName) { |
| 144 if (entry->isString()) { | 144 if (entry->isString()) { |
| 145 result.setUSVString(decode(entry->value())); | 145 result.setUSVString(decode(entry->value())); |
| 146 } else { | 146 } else { |
| 147 ASSERT(entry->isFile()); | 147 DCHECK(entry->isFile()); |
| 148 result.setFile(entry->file()); | 148 result.setFile(entry->file()); |
| 149 } | 149 } |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 HeapVector<FormDataEntryValue> FormData::getAll(const String& name) | 155 HeapVector<FormDataEntryValue> FormData::getAll(const String& name) |
| 156 { | 156 { |
| 157 HeapVector<FormDataEntryValue> results; | 157 HeapVector<FormDataEntryValue> results; |
| 158 | 158 |
| 159 const CString encodedName = encodeAndNormalize(name); | 159 const CString encodedName = encodeAndNormalize(name); |
| 160 for (const auto& entry : entries()) { | 160 for (const auto& entry : entries()) { |
| 161 if (entry->name() != encodedName) | 161 if (entry->name() != encodedName) |
| 162 continue; | 162 continue; |
| 163 FormDataEntryValue value; | 163 FormDataEntryValue value; |
| 164 if (entry->isString()) { | 164 if (entry->isString()) { |
| 165 value.setUSVString(decode(entry->value())); | 165 value.setUSVString(decode(entry->value())); |
| 166 } else { | 166 } else { |
| 167 ASSERT(entry->isFile()); | 167 DCHECK(entry->isFile()); |
| 168 value.setFile(entry->file()); | 168 value.setFile(entry->file()); |
| 169 } | 169 } |
| 170 results.append(value); | 170 results.append(value); |
| 171 } | 171 } |
| 172 return results; | 172 return results; |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool FormData::has(const String& name) | 175 bool FormData::has(const String& name) |
| 176 { | 176 { |
| 177 const CString encodedName = encodeAndNormalize(name); | 177 const CString encodedName = encodeAndNormalize(name); |
| 178 for (const auto& entry : entries()) { | 178 for (const auto& entry : entries()) { |
| 179 if (entry->name() == encodedName) | 179 if (entry->name() == encodedName) |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void FormData::set(const String& name, const String& value) | 185 void FormData::set(const String& name, const String& value) |
| 186 { | 186 { |
| 187 setEntry(new Entry(encodeAndNormalize(name), encodeAndNormalize(value))); | 187 setEntry(new Entry(encodeAndNormalize(name), encodeAndNormalize(value))); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void FormData::set(const String& name, Blob* blob, const String& filename) | 190 void FormData::set(const String& name, Blob* blob, const String& filename) |
| 191 { | 191 { |
| 192 setEntry(new Entry(encodeAndNormalize(name), blob, filename)); | 192 setEntry(new Entry(encodeAndNormalize(name), blob, filename)); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void FormData::setEntry(const Entry* entry) | 195 void FormData::setEntry(const Entry* entry) |
| 196 { | 196 { |
| 197 ASSERT(entry); | 197 DCHECK(entry); |
| 198 const CString encodedName = entry->name(); | 198 const CString encodedName = entry->name(); |
| 199 bool found = false; | 199 bool found = false; |
| 200 size_t i = 0; | 200 size_t i = 0; |
| 201 while (i < m_entries.size()) { | 201 while (i < m_entries.size()) { |
| 202 if (m_entries[i]->name() != encodedName) { | 202 if (m_entries[i]->name() != encodedName) { |
| 203 ++i; | 203 ++i; |
| 204 } else if (found) { | 204 } else if (found) { |
| 205 m_entries.remove(i); | 205 m_entries.remove(i); |
| 206 } else { | 206 } else { |
| 207 found = true; | 207 found = true; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 322 |
| 323 // ---------------------------------------------------------------- | 323 // ---------------------------------------------------------------- |
| 324 | 324 |
| 325 DEFINE_TRACE(FormData::Entry) | 325 DEFINE_TRACE(FormData::Entry) |
| 326 { | 326 { |
| 327 visitor->trace(m_blob); | 327 visitor->trace(m_blob); |
| 328 } | 328 } |
| 329 | 329 |
| 330 File* FormData::Entry::file() const | 330 File* FormData::Entry::file() const |
| 331 { | 331 { |
| 332 ASSERT(blob()); | 332 DCHECK(blob()); |
| 333 // The spec uses the passed filename when inserting entries into the list. | 333 // The spec uses the passed filename when inserting entries into the list. |
| 334 // Here, we apply the filename (if present) as an override when extracting | 334 // Here, we apply the filename (if present) as an override when extracting |
| 335 // entries. | 335 // entries. |
| 336 // FIXME: Consider applying the name during insertion. | 336 // FIXME: Consider applying the name during insertion. |
| 337 | 337 |
| 338 if (blob()->isFile()) { | 338 if (blob()->isFile()) { |
| 339 File* file = toFile(blob()); | 339 File* file = toFile(blob()); |
| 340 if (filename().isNull()) | 340 if (filename().isNull()) |
| 341 return file; | 341 return file; |
| 342 return file->clone(filename()); | 342 return file->clone(filename()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 String filename = m_filename; | 345 String filename = m_filename; |
| 346 if (filename.isNull()) | 346 if (filename.isNull()) |
| 347 filename = "blob"; | 347 filename = "blob"; |
| 348 return File::create(filename, currentTimeMS(), blob()->blobDataHandle()); | 348 return File::create(filename, currentTimeMS(), blob()->blobDataHandle()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 } // namespace blink | 351 } // namespace blink |
| OLD | NEW |