Backed out 5 changesets (bug 1518442) as requested by jdai. CLOSED TREE

Backed out changeset 9143aef9bd5e (bug 1518442)
Backed out changeset b1b08f66996c (bug 1518442)
Backed out changeset 1f3d36108982 (bug 1518442)
Backed out changeset 1ac7b20bb1d8 (bug 1518442)
Backed out changeset f280db1076a4 (bug 1518442)
This commit is contained in:
Narcis Beleuzu
2019-09-07 01:07:50 +03:00
parent e63bab20bf
commit 106c0002c0
31 changed files with 203 additions and 254 deletions

View File

@@ -39,7 +39,6 @@
// form submission
#include "HTMLFormSubmissionConstants.h"
#include "mozilla/dom/FormData.h"
#include "mozilla/dom/FormDataEvent.h"
#include "mozilla/Telemetry.h"
#include "nsIFormSubmitObserver.h"
#include "nsIObserverService.h"
@@ -118,8 +117,7 @@ HTMLFormElement::HTMLFormElement(
mDeferSubmission(false),
mNotifiedObservers(false),
mNotifiedObserversResult(false),
mEverTriedInvalidSubmit(false),
mIsConstructingEntryList(false) {
mEverTriedInvalidSubmit(false) {
// We start out valid.
AddStatesSilently(NS_EVENT_STATE_VALID);
}
@@ -506,8 +504,7 @@ nsresult HTMLFormElement::DoSubmitOrReset(WidgetEvent* aEvent,
if (eFormSubmit == aMessage) {
// Don't submit if we're not in a document or if we're in
// a sandboxed frame and form submit is disabled.
if (mIsConstructingEntryList || !doc ||
(doc->GetSandboxFlags() & SANDBOXED_FORMS)) {
if (!doc || (doc->GetSandboxFlags() & SANDBOXED_FORMS)) {
return NS_OK;
}
return DoSubmit(aEvent);
@@ -558,14 +555,6 @@ nsresult HTMLFormElement::DoSubmit(WidgetEvent* aEvent) {
// prepare the submission object
//
nsresult rv = BuildSubmission(getter_Transfers(submission), aEvent);
// Don't raise an error if form cannot navigate.
if (StaticPrefs::dom_formdata_event_enabled() &&
rv == NS_ERROR_NOT_AVAILABLE) {
mIsSubmitting = false;
return NS_OK;
}
if (NS_FAILED(rv)) {
mIsSubmitting = false;
return rv;
@@ -617,33 +606,17 @@ nsresult HTMLFormElement::BuildSubmission(HTMLFormSubmission** aFormSubmission,
nsresult rv;
//
// Walk over the form elements and call SubmitNamesValues() on them to get
// their data.
//
auto encoding = GetSubmitEncoding()->OutputEncoding();
RefPtr<FormData> formData =
new FormData(GetOwnerGlobal(), encoding, originatingElement);
rv = ConstructEntryList(formData);
NS_ENSURE_SUBMIT_SUCCESS(rv);
// Step 9. If form cannot navigate, then return.
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm
if (StaticPrefs::dom_formdata_event_enabled() && !GetComposedDoc()) {
return NS_ERROR_NOT_AVAILABLE;
}
//
// Get the submission object
//
rv = HTMLFormSubmission::GetFromForm(this, originatingElement, encoding,
rv = HTMLFormSubmission::GetFromForm(this, originatingElement,
aFormSubmission);
NS_ENSURE_SUBMIT_SUCCESS(rv);
//
// Dump the data into the submission object
//
rv = formData->CopySubmissionDataTo(*aFormSubmission);
rv = WalkFormElements(*aFormSubmission);
NS_ENSURE_SUBMIT_SUCCESS(rv);
return NS_OK;
@@ -884,16 +857,8 @@ nsresult HTMLFormElement::NotifySubmitObservers(nsIURI* aActionURL,
return rv;
}
nsresult HTMLFormElement::ConstructEntryList(FormData* aFormData) {
MOZ_ASSERT(aFormData, "Must have FormData!");
bool isFormDataEventEnabled = StaticPrefs::dom_formdata_event_enabled();
if (isFormDataEventEnabled && mIsConstructingEntryList) {
// Step 2.2 of https://xhr.spec.whatwg.org/#dom-formdata.
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
AutoRestore<bool> resetConstructingEntryList(mIsConstructingEntryList);
mIsConstructingEntryList = true;
nsresult HTMLFormElement::WalkFormElements(
HTMLFormSubmission* aFormSubmission) {
// This shouldn't be called recursively, so use a rather large value
// for the preallocated buffer.
AutoTArray<RefPtr<nsGenericHTMLFormElement>, 100> sortedControls;
@@ -907,58 +872,12 @@ nsresult HTMLFormElement::ConstructEntryList(FormData* aFormData) {
//
for (uint32_t i = 0; i < len; ++i) {
// Tell the control to submit its name/value pairs to the submission
sortedControls[i]->SubmitNamesValues(aFormData);
}
if (isFormDataEventEnabled) {
FormDataEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mFormData = aFormData;
RefPtr<FormDataEvent> event =
FormDataEvent::Constructor(this, NS_LITERAL_STRING("formdata"), init);
event->SetTrusted(true);
EventDispatcher::DispatchDOMEvent(ToSupports(this), nullptr, event, nullptr,
nullptr);
sortedControls[i]->SubmitNamesValues(aFormSubmission);
}
return NS_OK;
}
NotNull<const Encoding*> HTMLFormElement::GetSubmitEncoding() {
nsAutoString acceptCharsetValue;
GetAttr(kNameSpaceID_None, nsGkAtoms::acceptcharset, acceptCharsetValue);
int32_t charsetLen = acceptCharsetValue.Length();
if (charsetLen > 0) {
int32_t offset = 0;
int32_t spPos = 0;
// get charset from charsets one by one
do {
spPos = acceptCharsetValue.FindChar(char16_t(' '), offset);
int32_t cnt = ((-1 == spPos) ? (charsetLen - offset) : (spPos - offset));
if (cnt > 0) {
nsAutoString uCharset;
acceptCharsetValue.Mid(uCharset, offset, cnt);
auto encoding = Encoding::ForLabelNoReplacement(uCharset);
if (encoding) {
return WrapNotNull(encoding);
}
}
offset = spPos + 1;
} while (spPos != -1);
}
// if there are no accept-charset or all the charset are not supported
// Get the charset from document
Document* doc = GetComposedDoc();
if (doc) {
return doc->GetDocumentCharacterSet();
}
return UTF_8_ENCODING;
}
// nsIForm
NS_IMETHODIMP_(uint32_t)