Diff
Modified: trunk/LayoutTests/ChangeLog (97273 => 97274)
--- trunk/LayoutTests/ChangeLog 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/LayoutTests/ChangeLog 2011-10-12 17:45:19 UTC (rev 97274)
@@ -1,3 +1,19 @@
+2011-10-12 Jian Li <[email protected]>
+
+ Support passing optional filename when FormData.append() is used to
+ append a blob
+ https://bugs.webkit.org/show_bug.cgi?id=69885
+
+ Reviewed by David Levin.
+
+ * http/tests/local/formdata/resources/send-form-data-common.js:
+ (dumpResponse):
+ (sendFormData):
+ (testSendingFormData):
+ * http/tests/local/formdata/script-tests/send-form-data-with-sliced-file.js:
+ (runTest):
+ * http/tests/local/formdata/send-form-data-with-sliced-file-expected.txt:
+
2011-10-12 Dimitri Glazkov <[email protected]>
[Chromium] Mark implicit-submission test as slow for all Debug builds.
Modified: trunk/LayoutTests/http/tests/local/formdata/resources/send-form-data-common.js (97273 => 97274)
--- trunk/LayoutTests/http/tests/local/formdata/resources/send-form-data-common.js 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/LayoutTests/http/tests/local/formdata/resources/send-form-data-common.js 2011-10-12 17:45:19 UTC (rev 97274)
@@ -21,21 +21,18 @@
function dumpResponse(xhr, fileSliced)
{
- var responseText = xhr.responseText;
-
- // If we're sending a sliced file among the FormData, a uniquely generated name prefixed with "Blob" is used.
- // We need to remove the random part in the filename so that we get consistent result.
- if (fileSliced)
- responseText = responseText.replace(/Blob\w{32}/g, "Blob");
-
- debug(responseText);
+ debug(xhr.responseText);
}
function sendFormData(formDataList, fileSliced, sendAsAsync, addEventHandlers)
{
var formData = new FormData();
- for (var i = 0; i < formDataList.length; i++)
- formData.append(formDataList[i]['name'], formDataList[i]['value']);
+ for (var i = 0; i < formDataList.length; i++) {
+ if (formDataList[i]['filename'] != undefined)
+ formData.append(formDataList[i]['name'], formDataList[i]['value'], formDataList[i]['filename']);
+ else
+ formData.append(formDataList[i]['name'], formDataList[i]['value']);
+ }
var xhr = new XMLHttpRequest();
if (addEventHandlers)
@@ -75,7 +72,7 @@
fileSliced = true;
file = file.webkitSlice(dataList[i]['start'], dataList[i]['start'] + dataList[i]['length']);
}
- formDataList.push({'name': dataList[i]['name'], 'value': file});
+ formDataList.push({'name': dataList[i]['name'], 'value': file, 'filename': dataList[i]['filename']});
break;
}
}
Modified: trunk/LayoutTests/http/tests/local/formdata/script-tests/send-form-data-with-sliced-file.js (97273 => 97274)
--- trunk/LayoutTests/http/tests/local/formdata/script-tests/send-form-data-with-sliced-file.js 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/LayoutTests/http/tests/local/formdata/script-tests/send-form-data-with-sliced-file.js 2011-10-12 17:45:19 UTC (rev 97274)
@@ -9,21 +9,36 @@
debug("Sending FormData containing one sliced file:");
testSendingFormData([
- { 'type': 'file', 'name': 'file', 'value': '../resources/file-for-drag-to-send.txt', 'start' : 1, 'length' : 5 }
+ { 'type': 'file', 'name': 'file', 'value': '../resources/file-for-drag-to-send.txt', 'start': 1, 'length': 5 }
]);
+ debug("Sending FormData containing one sliced file with optional null filename:");
+ testSendingFormData([
+ { 'type': 'file', 'name': 'file', 'value': '../resources/file-for-drag-to-send.txt', 'start': 1, 'length': 5, 'filename': null }
+ ]);
+
+ debug("Sending FormData containing one sliced file with optional non-null filename:");
+ testSendingFormData([
+ { 'type': 'file', 'name': 'file', 'value': '../resources/file-for-drag-to-send.txt', 'start': 1, 'length': 5, 'filename': 'filename' }
+ ]);
+
+ debug("Sending FormData containing one complete file with optional non-null filename:");
+ testSendingFormData([
+ { 'type': 'file', 'name': 'file', 'value': '../resources/file-for-drag-to-send.txt', 'filename': 'filename' },
+ ]);
+
debug("Sending FormData containing one string and one sliced file:");
testSendingFormData([
{ 'type': 'string', 'name': 'string1', 'value': 'foo' },
- { 'type': 'file', 'name': 'file1', 'value': '../resources/file-for-drag-to-send.txt', 'start' : 1, 'length' : 5 }
+ { 'type': 'file', 'name': 'file1', 'value': '../resources/file-for-drag-to-send.txt', 'start': 1, 'length': 5 }
]);
debug("Sending FormData containing two strings and two sliced files:");
testSendingFormData([
{ 'type': 'string', 'name': 'string1', 'value': 'foo' },
- { 'type': 'file', 'name': 'file1', 'value': '../resources/file-for-drag-to-send.txt', 'start' : 1, 'length' : 5 },
+ { 'type': 'file', 'name': 'file1', 'value': '../resources/file-for-drag-to-send.txt', 'start': 1, 'length': 5 },
{ 'type': 'string', 'name': 'string2', 'value': 'bar' },
- { 'type': 'file', 'name': 'file2', 'value': '../resources/file-for-drag-to-send.txt', 'start' : 3, 'length' : 2 }
+ { 'type': 'file', 'name': 'file2', 'value': '../resources/file-for-drag-to-send.txt', 'start': 3, 'length': 2, 'filename': 'filename2' }
]);
}
Modified: trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-sliced-file-expected.txt (97273 => 97274)
--- trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-sliced-file-expected.txt 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/LayoutTests/http/tests/local/formdata/send-form-data-with-sliced-file-expected.txt 2011-10-12 17:45:19 UTC (rev 97274)
@@ -6,11 +6,17 @@
Sending FormData containing one sliced file with empty name:
Sending FormData containing one sliced file:
-file=Blob:application/octet-stream:23456
+file=blob:application/octet-stream:23456
+Sending FormData containing one sliced file with optional null filename:
+file=blob:application/octet-stream:23456
+Sending FormData containing one sliced file with optional non-null filename:
+file=filename:application/octet-stream:23456
+Sending FormData containing one complete file with optional non-null filename:
+file=file-for-drag-to-send.txt:text/plain:1234567890
Sending FormData containing one string and one sliced file:
-string1=foo&file1=Blob:application/octet-stream:23456
+string1=foo&file1=blob:application/octet-stream:23456
Sending FormData containing two strings and two sliced files:
-string1=foo&string2=bar&file1=Blob:application/octet-stream:23456&file2=Blob:application/octet-stream:45
+string1=foo&string2=bar&file1=blob:application/octet-stream:23456&file2=filename2:application/octet-stream:45
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/Source/WebCore/ChangeLog (97273 => 97274)
--- trunk/Source/WebCore/ChangeLog 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/ChangeLog 2011-10-12 17:45:19 UTC (rev 97274)
@@ -1,3 +1,31 @@
+2011-10-12 Jian Li <[email protected]>
+
+ Support passing optional filename when FormData.append() is used to
+ append a blob
+ https://bugs.webkit.org/show_bug.cgi?id=69885
+
+ Reviewed by David Levin.
+
+ Covered by existing test with new test case added:
+ http/tests/local/formdata/send-form-data-with-sliced-file.html
+
+ * bindings/js/JSDOMFormDataCustom.cpp:
+ (WebCore::JSDOMFormData::append):
+ * bindings/v8/custom/V8DOMFormDataCustom.cpp:
+ (WebCore::V8DOMFormData::appendCallback):
+ * html/DOMFormData.cpp:
+ (WebCore::DOMFormData::append):
+ * html/DOMFormData.h:
+ * html/DOMFormData.idl:
+ * html/FormDataList.cpp:
+ (WebCore::FormDataList::appendBlob):
+ * html/FormDataList.h:
+ (WebCore::FormDataList::Item::Item):
+ (WebCore::FormDataList::Item::filename):
+ (WebCore::FormDataList::appendBlob):
+ * platform/network/FormData.cpp:
+ (WebCore::FormData::appendKeyValuePairItems):
+
2011-10-12 Sergey Glazunov <[email protected]>
ScriptController::executeIfJavaScriptURL gets confused by synchronous frame loads
Modified: trunk/Source/WebCore/bindings/js/JSDOMFormDataCustom.cpp (97273 => 97274)
--- trunk/Source/WebCore/bindings/js/JSDOMFormDataCustom.cpp 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/bindings/js/JSDOMFormDataCustom.cpp 2011-10-12 17:45:19 UTC (rev 97274)
@@ -62,9 +62,12 @@
if (exec->argumentCount() >= 2) {
String name = ustringToString(exec->argument(0).toString(exec));
JSValue value = exec->argument(1);
- if (value.inherits(&JSBlob::s_info))
- impl()->append(name, toBlob(value));
- else
+ if (value.inherits(&JSBlob::s_info)) {
+ String filename;
+ if (exec->argumentCount() >= 3 && !exec->argument(2).isUndefinedOrNull())
+ filename = ustringToString(exec->argument(2).toString(exec));
+ impl()->append(name, toBlob(value), filename);
+ } else
impl()->append(name, ustringToString(value.toString(exec)));
}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp (97273 => 97274)
--- trunk/Source/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp 2011-10-12 17:45:19 UTC (rev 97274)
@@ -72,7 +72,12 @@
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
Blob* blob = V8Blob::toNative(object);
ASSERT(blob);
- domFormData->append(name, blob);
+
+ String filename;
+ if (args.Length() >= 3 && !args[2]->IsUndefined())
+ filename = toWebCoreStringWithNullCheck(args[2]);
+
+ domFormData->append(name, blob, filename);
} else
domFormData->append(name, toWebCoreStringWithNullCheck(arg));
Modified: trunk/Source/WebCore/html/DOMFormData.cpp (97273 => 97274)
--- trunk/Source/WebCore/html/DOMFormData.cpp 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/html/DOMFormData.cpp 2011-10-12 17:45:19 UTC (rev 97274)
@@ -63,10 +63,10 @@
appendData(name, value);
}
-void DOMFormData::append(const String& name, Blob* blob)
+void DOMFormData::append(const String& name, Blob* blob, const String& filename)
{
if (!name.isEmpty())
- appendBlob(name, blob);
+ appendBlob(name, blob, filename);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/html/DOMFormData.h (97273 => 97274)
--- trunk/Source/WebCore/html/DOMFormData.h 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/html/DOMFormData.h 2011-10-12 17:45:19 UTC (rev 97274)
@@ -48,7 +48,7 @@
static PassRefPtr<DOMFormData> create(const TextEncoding& encoding) { return adoptRef(new DOMFormData(encoding)); }
void append(const String& name, const String& value);
- void append(const String& name, Blob*);
+ void append(const String& name, Blob*, const String& filename = String());
private:
explicit DOMFormData(const TextEncoding&);
Modified: trunk/Source/WebCore/html/DOMFormData.idl (97273 => 97274)
--- trunk/Source/WebCore/html/DOMFormData.idl 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/html/DOMFormData.idl 2011-10-12 17:45:19 UTC (rev 97274)
@@ -36,9 +36,11 @@
GenerateNativeConverter,
GenerateToJS
] DOMFormData {
- // void append(DOMString name, Blob value);
+ // void append(DOMString name, DOMString value);
+ // void append(DOMString name, Blob value, optional DOMString filename);
[Custom] void append(in [Optional=CallWithDefaultValue] DOMString name,
- in [Optional=CallWithDefaultValue] DOMString value);
+ in [Optional=CallWithDefaultValue] DOMString value,
+ in [Optional=CallWithDefaultValue] DOMString filename);
};
}
Modified: trunk/Source/WebCore/html/FormDataList.cpp (97273 => 97274)
--- trunk/Source/WebCore/html/FormDataList.cpp 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/html/FormDataList.cpp 2011-10-12 17:45:19 UTC (rev 97274)
@@ -41,9 +41,9 @@
m_items.append(s);
}
-void FormDataList::appendBlob(PassRefPtr<Blob> blob)
+void FormDataList::appendBlob(PassRefPtr<Blob> blob, const String& filename)
{
- m_items.append(blob);
+ m_items.append(Item(blob, filename));
}
} // namespace
Modified: trunk/Source/WebCore/html/FormDataList.h (97273 => 97274)
--- trunk/Source/WebCore/html/FormDataList.h 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/html/FormDataList.h 2011-10-12 17:45:19 UTC (rev 97274)
@@ -34,14 +34,16 @@
public:
Item() { }
Item(const WTF::CString& data) : m_data(data) { }
- Item(PassRefPtr<Blob> blob) : m_blob(blob) { }
+ Item(PassRefPtr<Blob> blob, const String& filename) : m_blob(blob), m_filename(filename) { }
const WTF::CString& data() const { return m_data; }
Blob* blob() const { return m_blob.get(); }
+ const String& filename() const { return m_filename; }
private:
WTF::CString m_data;
RefPtr<Blob> m_blob;
+ String m_filename;
};
FormDataList(const TextEncoding&);
@@ -61,10 +63,10 @@
appendString(key);
appendString(String::number(value));
}
- void appendBlob(const String& key, PassRefPtr<Blob> blob)
+ void appendBlob(const String& key, PassRefPtr<Blob> blob, const String& filename = String())
{
appendString(key);
- appendBlob(blob);
+ appendBlob(blob, filename);
}
const Vector<Item>& items() const { return m_items; }
@@ -73,7 +75,7 @@
private:
void appendString(const CString&);
void appendString(const String&);
- void appendBlob(PassRefPtr<Blob>);
+ void appendBlob(PassRefPtr<Blob>, const String& filename);
TextEncoding m_encoding;
Vector<Item> m_items;
Modified: trunk/Source/WebCore/platform/network/FormData.cpp (97273 => 97274)
--- trunk/Source/WebCore/platform/network/FormData.cpp 2011-10-12 17:41:41 UTC (rev 97273)
+++ trunk/Source/WebCore/platform/network/FormData.cpp 2011-10-12 17:45:19 UTC (rev 97274)
@@ -221,9 +221,11 @@
}
}
} else {
- // For non-file blob, use the identifier part of the URL as the name.
- name = "Blob" + BlobURL::getIdentifier(value.blob()->url());
- name = name.replace("-", ""); // For safety, remove '-' from the filename since some servers may not like it.
+ // For non-file blob, use the filename if it is passed in FormData.append().
+ if (!value.filename().isEmpty())
+ name = value.filename();
+ else
+ name = "blob";
}
// We have to include the filename=".." part in the header, even if the filename is empty