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

Side by Side Diff: Source/core/platform/network/FormData.cpp

Issue 23992003: blob hacking webcore style (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 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
« no previous file with comments | « Source/core/platform/network/FormData.h ('k') | Source/core/xml/XMLHttpRequest.cpp » ('j') | 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) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 for (size_t i = 0; i < n; ++i) { 107 for (size_t i = 0; i < n; ++i) {
108 const FormDataElement& e = m_elements[i]; 108 const FormDataElement& e = m_elements[i];
109 switch (e.m_type) { 109 switch (e.m_type) {
110 case FormDataElement::data: 110 case FormDataElement::data:
111 formData->m_elements.uncheckedAppend(FormDataElement(e.m_data)); 111 formData->m_elements.uncheckedAppend(FormDataElement(e.m_data));
112 break; 112 break;
113 case FormDataElement::encodedFile: 113 case FormDataElement::encodedFile:
114 formData->m_elements.uncheckedAppend(FormDataElement(e.m_filename, e .m_fileStart, e.m_fileLength, e.m_expectedFileModificationTime)); 114 formData->m_elements.uncheckedAppend(FormDataElement(e.m_filename, e .m_fileStart, e.m_fileLength, e.m_expectedFileModificationTime));
115 break; 115 break;
116 case FormDataElement::encodedBlob: 116 case FormDataElement::encodedBlob:
117 formData->m_elements.uncheckedAppend(FormDataElement(e.m_url)); 117 formData->m_elements.uncheckedAppend(FormDataElement(e.m_blobUUID, e .m_optionalBlobDataHandle));
118 break; 118 break;
119 case FormDataElement::encodedURL: 119 case FormDataElement::encodedFileSystemURL:
120 formData->m_elements.uncheckedAppend(FormDataElement(e.m_url, e.m_fi leStart, e.m_fileLength, e.m_expectedFileModificationTime)); 120 formData->m_elements.uncheckedAppend(FormDataElement(e.m_fileSystemU RL, e.m_fileStart, e.m_fileLength, e.m_expectedFileModificationTime));
121 break; 121 break;
122 } 122 }
123 } 123 }
124 return formData.release(); 124 return formData.release();
125 } 125 }
126 126
127 void FormData::appendData(const void* data, size_t size) 127 void FormData::appendData(const void* data, size_t size)
128 { 128 {
129 if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::dat a) 129 if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::dat a)
130 m_elements.append(FormDataElement()); 130 m_elements.append(FormDataElement());
131 FormDataElement& e = m_elements.last(); 131 FormDataElement& e = m_elements.last();
132 size_t oldSize = e.m_data.size(); 132 size_t oldSize = e.m_data.size();
133 e.m_data.grow(oldSize + size); 133 e.m_data.grow(oldSize + size);
134 memcpy(e.m_data.data() + oldSize, data, size); 134 memcpy(e.m_data.data() + oldSize, data, size);
135 } 135 }
136 136
137 void FormData::appendFile(const String& filename) 137 void FormData::appendFile(const String& filename)
138 { 138 {
139 m_elements.append(FormDataElement(filename, 0, BlobDataItem::toEndOfFile, in validFileTime())); 139 m_elements.append(FormDataElement(filename, 0, BlobDataItem::toEndOfFile, in validFileTime()));
140 } 140 }
141 141
142 void FormData::appendFileRange(const String& filename, long long start, long lon g length, double expectedModificationTime) 142 void FormData::appendFileRange(const String& filename, long long start, long lon g length, double expectedModificationTime)
143 { 143 {
144 m_elements.append(FormDataElement(filename, start, length, expectedModificat ionTime)); 144 m_elements.append(FormDataElement(filename, start, length, expectedModificat ionTime));
145 } 145 }
146 146
147 void FormData::appendBlob(const KURL& blobURL) 147 void FormData::appendBlob(const String& uuid, PassRefPtr<BlobDataHandle> optiona lHandle)
148 { 148 {
149 m_elements.append(FormDataElement(blobURL)); 149 m_elements.append(FormDataElement(uuid, optionalHandle));
150 } 150 }
151 151
152 void FormData::appendURL(const KURL& url) 152 void FormData::appendFileSystemURL(const KURL& url)
153 { 153 {
154 m_elements.append(FormDataElement(url, 0, BlobDataItem::toEndOfFile, invalid FileTime())); 154 m_elements.append(FormDataElement(url, 0, BlobDataItem::toEndOfFile, invalid FileTime()));
155 } 155 }
156 156
157 void FormData::appendURLRange(const KURL& url, long long start, long long length , double expectedModificationTime) 157 void FormData::appendFileSystemURLRange(const KURL& url, long long start, long l ong length, double expectedModificationTime)
158 { 158 {
159 m_elements.append(FormDataElement(url, start, length, expectedModificationTi me)); 159 m_elements.append(FormDataElement(url, start, length, expectedModificationTi me));
160 } 160 }
161 161
162 void FormData::appendKeyValuePairItems(const FormDataList& list, const WTF::Text Encoding& encoding, bool isMultiPartForm, EncodingType encodingType) 162 void FormData::appendKeyValuePairItems(const FormDataList& list, const WTF::Text Encoding& encoding, bool isMultiPartForm, EncodingType encodingType)
163 { 163 {
164 if (isMultiPartForm) 164 if (isMultiPartForm)
165 m_boundary = FormDataBuilder::generateUniqueBoundaryString(); 165 m_boundary = FormDataBuilder::generateUniqueBoundaryString();
166 166
167 Vector<char> encodedData; 167 Vector<char> encodedData;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 // Append body 212 // Append body
213 appendData(header.data(), header.size()); 213 appendData(header.data(), header.size());
214 if (value.blob()) { 214 if (value.blob()) {
215 if (value.blob()->isFile()) { 215 if (value.blob()->isFile()) {
216 File* file = toFile(value.blob()); 216 File* file = toFile(value.blob());
217 // Do not add the file if the path is empty. 217 // Do not add the file if the path is empty.
218 if (!file->path().isEmpty()) 218 if (!file->path().isEmpty())
219 appendFile(file->path()); 219 appendFile(file->path());
220 if (!file->fileSystemURL().isEmpty()) 220 if (!file->fileSystemURL().isEmpty())
221 appendURL(file->fileSystemURL()); 221 appendFileSystemURL(file->fileSystemURL());
222 } else {
223 appendBlob(value.blob()->uuid(), value.blob()->blobDataHandl e());
222 } 224 }
223 else
224 appendBlob(value.blob()->url());
225 } else 225 } else
226 appendData(value.data().data(), value.data().length()); 226 appendData(value.data().data(), value.data().length());
227 appendData("\r\n", 2); 227 appendData("\r\n", 2);
228 } else { 228 } else {
229 // Omit the name "isindex" if it's the first form data element. 229 // Omit the name "isindex" if it's the first form data element.
230 // FIXME: Why is this a good rule? Is this obsolete now? 230 // FIXME: Why is this a good rule? Is this obsolete now?
231 if (encodedData.isEmpty() && key.data() == "isindex") 231 if (encodedData.isEmpty() && key.data() == "isindex")
232 FormDataBuilder::encodeStringAsFormData(encodedData, value.data( )); 232 FormDataBuilder::encodeStringAsFormData(encodedData, value.data( ));
233 else 233 else
234 FormDataBuilder::addKeyValuePairAsFormData(encodedData, key.data (), value.data(), encodingType); 234 FormDataBuilder::addKeyValuePairAsFormData(encodedData, key.data (), value.data(), encodingType);
(...skipping 19 matching lines...) Expand all
254 } 254 }
255 255
256 String FormData::flattenToString() const 256 String FormData::flattenToString() const
257 { 257 {
258 Vector<char> bytes; 258 Vector<char> bytes;
259 flatten(bytes); 259 flatten(bytes);
260 return Latin1Encoding().decode(reinterpret_cast<const char*>(bytes.data()), bytes.size()); 260 return Latin1Encoding().decode(reinterpret_cast<const char*>(bytes.data()), bytes.size());
261 } 261 }
262 262
263 } // namespace WebCore 263 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/network/FormData.h ('k') | Source/core/xml/XMLHttpRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698