2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-02-24 21:58:18 -08:00
|
|
|
|
|
|
|
#include "nsFormData.h"
|
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsIInputStream.h"
|
2014-10-08 09:15:23 -07:00
|
|
|
#include "mozilla/dom/File.h"
|
2013-06-19 07:24:37 -07:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2015-02-21 11:54:44 -08:00
|
|
|
|
2015-05-12 05:11:03 -07:00
|
|
|
#include "MultipartBlobImpl.h"
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsFormData::nsFormData(nsISupports* aOwner)
|
2012-07-30 07:20:58 -07:00
|
|
|
: nsFormSubmission(NS_LITERAL_CSTRING("UTF-8"), nullptr)
|
2012-12-11 10:09:56 -08:00
|
|
|
, mOwner(aOwner)
|
2010-02-24 21:58:18 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
namespace {
|
2015-05-12 05:09:51 -07:00
|
|
|
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
// Implements steps 3 and 4 of the "create an entry" algorithm of FormData.
|
2015-05-12 05:09:51 -07:00
|
|
|
already_AddRefed<File>
|
|
|
|
CreateNewFileInstance(Blob& aBlob, const Optional<nsAString>& aFilename)
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
{
|
|
|
|
// Step 3 "If value is a Blob object and not a File object, set value to
|
|
|
|
// a new File object, representing the same bytes, whose name attribute value
|
|
|
|
// is "blob"."
|
|
|
|
// Step 4 "If value is a File object and filename is given, set value to
|
|
|
|
// a new File object, representing the same bytes, whose name attribute
|
|
|
|
// value is filename."
|
|
|
|
nsAutoString filename;
|
|
|
|
if (aFilename.WasPassed()) {
|
|
|
|
filename = aFilename.Value();
|
2015-05-12 05:09:51 -07:00
|
|
|
} else {
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
// If value is already a File and filename is not passed, the spec says not
|
|
|
|
// to create a new instance.
|
2015-05-12 05:09:51 -07:00
|
|
|
nsRefPtr<File> file = aBlob.ToFile();
|
|
|
|
if (file) {
|
|
|
|
return file.forget();
|
|
|
|
}
|
|
|
|
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
filename = NS_LITERAL_STRING("blob");
|
|
|
|
}
|
|
|
|
|
2015-05-12 05:09:51 -07:00
|
|
|
return aBlob.ToFile(filename);
|
2015-05-11 14:54:02 -07:00
|
|
|
}
|
2015-05-12 05:09:51 -07:00
|
|
|
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// nsISupports
|
|
|
|
|
2014-10-08 09:15:22 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFormData)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFormData)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
|
|
|
|
|
|
|
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
|
|
|
|
ImplCycleCollectionUnlink(tmp->mFormData[i].fileValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFormData)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
|
|
|
|
|
|
|
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
|
|
|
|
ImplCycleCollectionTraverse(cb,tmp->mFormData[i].fileValue,
|
|
|
|
"mFormData[i].fileValue", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsFormData)
|
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormData)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormData)
|
2014-10-08 09:15:22 -07:00
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormData)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2010-02-24 21:58:18 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMFormData)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXHRSendable)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFormData)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// nsFormSubmission
|
|
|
|
nsresult
|
|
|
|
nsFormData::GetEncodedSubmission(nsIURI* aURI,
|
|
|
|
nsIInputStream** aPostDataStream)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Shouldn't call nsFormData::GetEncodedSubmission");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
void
|
|
|
|
nsFormData::Append(const nsAString& aName, const nsAString& aValue)
|
2010-02-24 21:58:18 -08:00
|
|
|
{
|
2013-03-03 10:30:13 -08:00
|
|
|
AddNameValuePair(aName, aValue);
|
2010-02-24 21:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
void
|
2015-05-12 05:09:51 -07:00
|
|
|
nsFormData::Append(const nsAString& aName, Blob& aBlob,
|
2013-03-03 10:30:13 -08:00
|
|
|
const Optional<nsAString>& aFilename)
|
2010-02-24 21:58:18 -08:00
|
|
|
{
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
nsRefPtr<File> file = CreateNewFileInstance(aBlob, aFilename);
|
|
|
|
AddNameFilePair(aName, file);
|
2015-01-28 17:04:28 -08:00
|
|
|
}
|
|
|
|
|
2015-01-28 17:04:28 -08:00
|
|
|
void
|
|
|
|
nsFormData::Delete(const nsAString& aName)
|
|
|
|
{
|
|
|
|
// We have to use this slightly awkward for loop since uint32_t >= 0 is an
|
|
|
|
// error for being always true.
|
|
|
|
for (uint32_t i = mFormData.Length(); i-- > 0; ) {
|
|
|
|
if (aName.Equals(mFormData[i].name)) {
|
|
|
|
mFormData.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormData::ExtractValue(const FormDataTuple& aTuple,
|
|
|
|
OwningFileOrUSVString* aOutValue)
|
|
|
|
{
|
|
|
|
if (aTuple.valueIsFile) {
|
|
|
|
aOutValue->SetAsFile() = aTuple.fileValue;
|
|
|
|
} else {
|
|
|
|
aOutValue->SetAsUSVString() = aTuple.stringValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormData::Get(const nsAString& aName,
|
|
|
|
Nullable<OwningFileOrUSVString>& aOutValue)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mFormData.Length(); ++i) {
|
|
|
|
if (aName.Equals(mFormData[i].name)) {
|
|
|
|
ExtractValue(mFormData[i], &aOutValue.SetValue());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aOutValue.SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormData::GetAll(const nsAString& aName,
|
|
|
|
nsTArray<OwningFileOrUSVString>& aValues)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mFormData.Length(); ++i) {
|
|
|
|
if (aName.Equals(mFormData[i].name)) {
|
|
|
|
OwningFileOrUSVString* element = aValues.AppendElement();
|
|
|
|
ExtractValue(mFormData[i], element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsFormData::Has(const nsAString& aName)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mFormData.Length(); ++i) {
|
|
|
|
if (aName.Equals(mFormData[i].name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-12 05:09:51 -07:00
|
|
|
nsresult
|
|
|
|
nsFormData::AddNameFilePair(const nsAString& aName, File* aFile)
|
|
|
|
{
|
|
|
|
FormDataTuple* data = mFormData.AppendElement();
|
|
|
|
SetNameFilePair(data, aName, aFile);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:04:28 -08:00
|
|
|
nsFormData::FormDataTuple*
|
|
|
|
nsFormData::RemoveAllOthersAndGetFirstFormDataTuple(const nsAString& aName)
|
|
|
|
{
|
|
|
|
FormDataTuple* lastFoundTuple = nullptr;
|
|
|
|
uint32_t lastFoundIndex = mFormData.Length();
|
|
|
|
// We have to use this slightly awkward for loop since uint32_t >= 0 is an
|
|
|
|
// error for being always true.
|
|
|
|
for (uint32_t i = mFormData.Length(); i-- > 0; ) {
|
|
|
|
if (aName.Equals(mFormData[i].name)) {
|
|
|
|
if (lastFoundTuple) {
|
|
|
|
// The one we found earlier was not the first one, we can remove it.
|
|
|
|
mFormData.RemoveElementAt(lastFoundIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastFoundTuple = &mFormData[i];
|
|
|
|
lastFoundIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastFoundTuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-12 05:09:51 -07:00
|
|
|
nsFormData::Set(const nsAString& aName, Blob& aBlob,
|
2015-01-28 17:04:28 -08:00
|
|
|
const Optional<nsAString>& aFilename)
|
|
|
|
{
|
|
|
|
FormDataTuple* tuple = RemoveAllOthersAndGetFirstFormDataTuple(aName);
|
|
|
|
if (tuple) {
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
nsRefPtr<File> file = CreateNewFileInstance(aBlob, aFilename);
|
|
|
|
SetNameFilePair(tuple, aName, file);
|
2015-01-28 17:04:28 -08:00
|
|
|
} else {
|
|
|
|
Append(aName, aBlob, aFilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormData::Set(const nsAString& aName, const nsAString& aValue)
|
|
|
|
{
|
|
|
|
FormDataTuple* tuple = RemoveAllOthersAndGetFirstFormDataTuple(aName);
|
|
|
|
if (tuple) {
|
|
|
|
SetNameValuePair(tuple, aName, aValue);
|
|
|
|
} else {
|
|
|
|
Append(aName, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// nsIDOMFormData
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t dataType;
|
2010-02-24 21:58:18 -08:00
|
|
|
nsresult rv = aValue->GetDataType(&dataType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (dataType == nsIDataType::VTYPE_INTERFACE ||
|
|
|
|
dataType == nsIDataType::VTYPE_INTERFACE_IS) {
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
nsID *iid;
|
|
|
|
rv = aValue->GetAsInterface(&iid, getter_AddRefs(supports));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-03-26 17:01:12 -07:00
|
|
|
free(iid);
|
2010-02-24 21:58:18 -08:00
|
|
|
|
2010-10-13 16:25:33 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports);
|
2015-05-12 05:09:51 -07:00
|
|
|
nsRefPtr<Blob> blob = static_cast<Blob*>(domBlob.get());
|
2010-10-13 16:25:33 -07:00
|
|
|
if (domBlob) {
|
2013-03-03 12:34:47 -08:00
|
|
|
Optional<nsAString> temp;
|
2014-10-08 09:15:22 -07:00
|
|
|
Append(aName, *blob, temp);
|
2012-12-11 10:09:56 -08:00
|
|
|
return NS_OK;
|
2010-02-24 21:58:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t* stringData = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t stringLen = 0;
|
2010-02-24 21:58:18 -08:00
|
|
|
rv = aValue->GetAsWStringWithSize(&stringLen, &stringData);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsString valAsString;
|
|
|
|
valAsString.Adopt(stringData, stringLen);
|
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
Append(aName, valAsString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
nsFormData::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-11 10:09:56 -08:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return FormDataBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-11 10:09:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<nsFormData>
|
2012-12-03 08:07:49 -08:00
|
|
|
nsFormData::Constructor(const GlobalObject& aGlobal,
|
2013-06-19 07:24:37 -07:00
|
|
|
const Optional<NonNull<HTMLFormElement> >& aFormElement,
|
2012-12-11 10:09:56 -08:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsRefPtr<nsFormData> formData = new nsFormData(aGlobal.GetAsSupports());
|
2012-12-11 10:09:56 -08:00
|
|
|
if (aFormElement.WasPassed()) {
|
2013-06-19 11:48:43 -07:00
|
|
|
aRv = aFormElement.Value().WalkFormElements(formData);
|
2012-12-11 10:09:56 -08:00
|
|
|
}
|
|
|
|
return formData.forget();
|
2010-02-24 21:58:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2010-09-15 15:52:02 -07:00
|
|
|
// nsIXHRSendable
|
2010-02-24 21:58:18 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-19 15:15:32 -07:00
|
|
|
nsFormData::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
|
|
|
|
nsACString& aContentType, nsACString& aCharset)
|
2010-02-24 21:58:18 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsFSMultipartFormData fs(NS_LITERAL_CSTRING("UTF-8"), nullptr);
|
2013-03-03 10:30:13 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mFormData.Length(); ++i) {
|
2010-02-24 21:58:18 -08:00
|
|
|
if (mFormData[i].valueIsFile) {
|
Bug 1127150 - Use File's name instead of explicit file name in form submission related classes. r=baku
Our nsFormSubmission and subclasses accepted a third filename argument to
explicitly specify the filename. Since switching from nsIDOMBlob to File in Bug
1085283, we can read out the filename directly from the File. This simplifies
the code, but introduces a change in the way Firefox submits form data to
servers.
Consider the code:
var fd = new FormData();
fd.append("blob1", new Blob(["hi"]), ""); // explicit empty filename as third arg
fd.append("file1", new File(["hi"], "")); // File's name is empty, no third arg.
xhr.send(fd);
Previously, the request body had filename="" in the first case, and filename="blob" in the second.
This patch will change it to both cases result in filename=""
This behaviour isn't exactly specced anywhere, nor in the HTML spec [1], nor in
RFC 2388. In addition Blink (at least Chromium v40) has the same behaviour
introduced by this patch. So shipping it seems ok to me.
[1]: http://www.w3.org/html/wg/drafts/html/master/semantics.html#multipart/form-data-encoding-algorithm
2015-02-21 11:54:44 -08:00
|
|
|
fs.AddNameFilePair(mFormData[i].name, mFormData[i].fileValue);
|
2010-02-24 21:58:18 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fs.AddNameValuePair(mFormData[i].name, mFormData[i].stringValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.GetContentType(aContentType);
|
|
|
|
aCharset.Truncate();
|
2012-09-19 15:15:32 -07:00
|
|
|
*aContentLength = 0;
|
|
|
|
NS_ADDREF(*aBody = fs.GetSubmissionBody(aContentLength));
|
2010-02-24 21:58:18 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|