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

Side by Side Diff: Source/core/html/FormDataList.cpp

Issue 1334513002: Fold FormDataList::getEntry(index) into DOMFormData. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/FormDataList.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 30 matching lines...) Expand all
41 FormDataList::Entry FormDataList::getEntry(const String& key) const 41 FormDataList::Entry FormDataList::getEntry(const String& key) const
42 { 42 {
43 const CString keyData = encodeAndNormalize(key); 43 const CString keyData = encodeAndNormalize(key);
44 for (const Item& item : items()) { 44 for (const Item& item : items()) {
45 if (item.key() == keyData) 45 if (item.key() == keyData)
46 return itemsToEntry(item); 46 return itemsToEntry(item);
47 } 47 }
48 return Entry(); 48 return Entry();
49 } 49 }
50 50
51 FormDataList::Entry FormDataList::getEntry(size_t index) const
52 {
53 const FormDataListItems& items = this->items();
54 if (index >= items.size())
55 return Entry();
56 return itemsToEntry(items[index]);
57 }
58
59 HeapVector<FormDataList::Entry> FormDataList::getAll(const String& key) const 51 HeapVector<FormDataList::Entry> FormDataList::getAll(const String& key) const
60 { 52 {
61 HeapVector<FormDataList::Entry> matches; 53 HeapVector<FormDataList::Entry> matches;
62 54
63 const CString keyData = encodeAndNormalize(key); 55 const CString keyData = encodeAndNormalize(key);
64 for (const Item& item : items()) { 56 for (const Item& item : items()) {
65 if (item.key() == keyData) 57 if (item.key() == keyData)
66 matches.append(itemsToEntry(item)); 58 matches.append(itemsToEntry(item));
67 } 59 }
68 60
69 return matches; 61 return matches;
70 } 62 }
71 63
72 FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& item) c onst 64 FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& item) c onst
73 { 65 {
74 const CString nameData = item.key(); 66 const CString nameData = item.key();
75 const String name = m_encoding.decode(nameData.data(), nameData.length()); 67 const String name = m_encoding.decode(nameData.data(), nameData.length());
76 68
77 if (!item.blob()) { 69 if (!item.blob()) {
78 const CString valueData = item.data(); 70 const CString valueData = item.data();
79 return Entry(name, m_encoding.decode(valueData.data(), valueData.length( ))); 71 return Entry(name, m_encoding.decode(valueData.data(), valueData.length( )));
80 } 72 }
73 return Entry(name, item.file());
74 }
81 75
76 File* FormDataList::Item::file() const
77 {
78 ASSERT(blob());
82 // The spec uses the passed filename when inserting entries into the list. 79 // The spec uses the passed filename when inserting entries into the list.
83 // Here, we apply the filename (if present) as an override when extracting 80 // Here, we apply the filename (if present) as an override when extracting
84 // items. 81 // items.
85 // FIXME: Consider applying the name during insertion. 82 // FIXME: Consider applying the name during insertion.
86 83
87 if (item.blob()->isFile()) { 84 if (blob()->isFile()) {
88 File* file = toFile(item.blob()); 85 File* file = toFile(blob());
89 if (item.filename().isNull()) 86 if (filename().isNull())
90 return Entry(name, file); 87 return file;
91 return Entry(name, file->clone(item.filename())); 88 return file->clone(filename());
92 } 89 }
93 90
94 String filename = item.filename(); 91 String filename = m_filename;
95 if (filename.isNull()) 92 if (filename.isNull())
96 filename = "blob"; 93 filename = "blob";
97 return Entry(name, File::create(filename, currentTimeMS(), item.blob()->blob DataHandle())); 94 return File::create(filename, currentTimeMS(), blob()->blobDataHandle());
98 } 95 }
99 96
100 PassRefPtr<FormData> FormDataList::createFormData(FormData::EncodingType encodin gType) 97 PassRefPtr<FormData> FormDataList::createFormData(FormData::EncodingType encodin gType)
101 { 98 {
102 RefPtr<FormData> result = FormData::create(); 99 RefPtr<FormData> result = FormData::create();
103 appendKeyValuePairItemsTo(result.get(), m_encoding, false, encodingType); 100 appendKeyValuePairItemsTo(result.get(), m_encoding, false, encodingType);
104 return result.release(); 101 return result.release();
105 } 102 }
106 103
107 PassRefPtr<FormData> FormDataList::createMultiPartFormData() 104 PassRefPtr<FormData> FormDataList::createMultiPartFormData()
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 { 197 {
201 visitor->trace(m_file); 198 visitor->trace(m_file);
202 } 199 }
203 200
204 DEFINE_TRACE(FormDataList::Item) 201 DEFINE_TRACE(FormDataList::Item)
205 { 202 {
206 visitor->trace(m_blob); 203 visitor->trace(m_blob);
207 } 204 }
208 205
209 } // namespace blink 206 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/FormDataList.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698