/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
already_AddRefed<File> GetOrCreateFileCalledBlob(Blob& aBlob,
ErrorResult& aRv) { // If this is file, we can just use it
RefPtr<File> file = aBlob.ToFile(); if (file) { return file.forget();
}
// Forcing 'blob' as filename
file = aBlob.ToFile(u"blob"_ns, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr;
}
return file.forget();
}
already_AddRefed<File> GetBlobForFormDataStorage(
Blob& aBlob, const Optional<nsAString>& aFilename, ErrorResult& aRv) { // Forcing a filename if (aFilename.WasPassed()) {
RefPtr<File> file = aBlob.ToFile(aFilename.Value(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr;
}
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
ImplCycleCollectionTraverse(cb, tmp->mFormData[i].value, "mFormData[i].GetAsBlob()", 0);
}
nsAutoString usvName(aName); if (!NormalizeUSVString(usvName)) { return NS_ERROR_OUT_OF_MEMORY;
}
FormDataTuple* data = mFormData.AppendElement();
SetNameDirectoryPair(data, usvName, aDirectory); return NS_OK;
}
FormData::FormDataTuple* FormData::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);
}
// https://xhr.spec.whatwg.org/#dom-formdata /* static */
already_AddRefed<FormData> FormData::Constructor( const GlobalObject& aGlobal, const Optional<NonNull<HTMLFormElement> >& aFormElement,
nsGenericHTMLElement* aSubmitter, ErrorResult& aRv) {
RefPtr<FormData> formData; // 1. If form is given, then: if (aFormElement.WasPassed()) { // 1.1. If submitter is non-null, then: if (aSubmitter) { const nsIFormControl* fc = nsIFormControl::FromNode(aSubmitter);
// 1.1.1. If submitter is not a submit button, then throw a TypeError. if (!fc || !fc->IsSubmitControl()) {
aRv.ThrowTypeError("The submitter is not a submit button."); return nullptr;
}
// 1.1.2. If submitter's form owner is not this form element, then throw a // "NotFoundError" DOMException. if (fc->GetForm() != &aFormElement.Value()) {
aRv.ThrowNotFoundError("The submitter is not owned by this form."); return nullptr;
}
}
// 1.2. Let list be the result of constructing the entry list for form and // submitter.
formData = new FormData(aGlobal.GetAsSupports(), UTF_8_ENCODING, aSubmitter);
aRv = aFormElement.Value().ConstructEntryList(formData); if (NS_WARN_IF(aRv.Failed())) { return nullptr;
}
// contentTypeWithCharset can be set to the contentType or // contentType+charset based on what the spec says. // See: https://fetch.spec.whatwg.org/#concept-bodyinit-extract
nsresult FormData::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
nsACString& aContentTypeWithCharset,
nsACString& aCharset) const {
FSMultipartFormData fs(nullptr, u""_ns, UTF_8_ENCODING, nullptr);
nsresult rv = CopySubmissionDataTo(&fs);
NS_ENSURE_SUCCESS(rv, rv);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.