Bug 1820403 - Skip parts of form submission when the method is dialog. r=dom-core,sefeng

https://github.com/whatwg/html/pull/8943 moved dialog submission in the form submission algorithm from step 24 to step 11.

Differential Revision: https://phabricator.services.mozilla.com/D183168
This commit is contained in:
Vincent Hilla 2023-07-18 13:00:27 +00:00
Родитель 9f044bb607
Коммит 683c902afb
4 изменённых файлов: 30 добавлений и 39 удалений

Просмотреть файл

@ -854,7 +854,7 @@ nsresult HTMLFormElement::SubmitSubmission(
return rv;
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submit-dialog
// https://html.spec.whatwg.org/#concept-form-submit step 11
nsresult HTMLFormElement::SubmitDialog(DialogFormSubmission* aFormSubmission) {
// Close the dialog subject. If there is a result, let that be the return
// value.

Просмотреть файл

@ -778,6 +778,32 @@ nsresult HTMLFormSubmission::GetFromForm(HTMLFormElement* aForm,
nsresult rv;
// Get method (default: GET)
int32_t method = NS_FORM_METHOD_GET;
if (aSubmitter && aSubmitter->HasAttr(nsGkAtoms::formmethod)) {
GetEnumAttr(aSubmitter, nsGkAtoms::formmethod, &method);
} else {
GetEnumAttr(aForm, nsGkAtoms::method, &method);
}
if (method == NS_FORM_METHOD_DIALOG) {
HTMLDialogElement* dialog = aForm->FirstAncestorOfType<HTMLDialogElement>();
// If there isn't one, do nothing.
if (!dialog) {
return NS_ERROR_FAILURE;
}
nsAutoString result;
if (aSubmitter) {
aSubmitter->ResultForDialogSubmit(result);
}
*aFormSubmission = new DialogFormSubmission(result, aEncoding, dialog);
return NS_OK;
}
MOZ_ASSERT(method != NS_FORM_METHOD_DIALOG);
// Get action
nsCOMPtr<nsIURI> actionURL;
rv = aForm->GetActionURL(getter_AddRefs(actionURL), aSubmitter);
@ -823,34 +849,6 @@ nsresult HTMLFormSubmission::GetFromForm(HTMLFormElement* aForm,
GetEnumAttr(aForm, nsGkAtoms::enctype, &enctype);
}
// Get method (default: GET)
int32_t method = NS_FORM_METHOD_GET;
if (aSubmitter && aSubmitter->HasAttr(nsGkAtoms::formmethod)) {
GetEnumAttr(aSubmitter, nsGkAtoms::formmethod, &method);
} else {
GetEnumAttr(aForm, nsGkAtoms::method, &method);
}
if (method == NS_FORM_METHOD_DIALOG) {
HTMLDialogElement* dialog = aForm->FirstAncestorOfType<HTMLDialogElement>();
// If there isn't one, or if it does not have an open attribute, do
// nothing.
if (!dialog || !dialog->Open()) {
return NS_ERROR_FAILURE;
}
nsAutoString result;
if (aSubmitter) {
aSubmitter->ResultForDialogSubmit(result);
}
*aFormSubmission =
new DialogFormSubmission(result, actionURL, target, aEncoding, dialog);
return NS_OK;
}
MOZ_ASSERT(method != NS_FORM_METHOD_DIALOG);
// Choose encoder
if (method == NS_FORM_METHOD_POST && enctype == NS_FORM_ENCTYPE_MULTIPART) {
*aFormSubmission =

Просмотреть файл

@ -39,6 +39,7 @@ class HTMLFormSubmission {
*
* @param aForm the form to get a submission object based on
* @param aSubmitter the submitter element (can be null)
* @param aEncoding the submiter element's encoding
* @param aFormSubmission the form submission object (out param)
*/
static nsresult GetFromForm(HTMLFormElement* aForm,
@ -168,11 +169,9 @@ class EncodingFormSubmission : public HTMLFormSubmission {
class DialogFormSubmission final : public HTMLFormSubmission {
public:
DialogFormSubmission(nsAString& aResult, nsIURI* aActionURL,
const nsAString& aTarget,
NotNull<const Encoding*> aEncoding,
DialogFormSubmission(nsAString& aResult, NotNull<const Encoding*> aEncoding,
HTMLDialogElement* aDialogElement)
: HTMLFormSubmission(aActionURL, aTarget, aEncoding),
: HTMLFormSubmission(nullptr, u""_ns, aEncoding),
mDialogElement(aDialogElement),
mReturnValue(aResult) {}
nsresult AddNameValuePair(const nsAString& aName,

Просмотреть файл

@ -1,6 +0,0 @@
[dialog-form-submission-unusual.html]
[A form's action and rel=noopener are ignored during submission]
expected: FAIL
[A form's action and rel=noopener are ignored during submission, part 2]
expected: FAIL