Bug 1518442 - Part 3: Add dom.formdata.event.enabled preference for Event-based form participation; r=smaug,edgar

Differential Revision: https://phabricator.services.mozilla.com/D43987

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Dai 2019-09-09 13:53:34 +00:00
parent d2154fae15
commit 5e255f0239
12 changed files with 40 additions and 18 deletions

View File

@ -306,7 +306,9 @@ already_AddRefed<FormData> FormData::Constructor(
// Step 9. Return a shallow clone of entry list.
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
formData = formData->Clone();
if (StaticPrefs::dom_formdata_event_enabled()) {
formData = formData->Clone();
}
}
return formData.forget();

View File

@ -3808,7 +3808,11 @@ nsIContentPolicy* nsContentUtils::GetContentPolicy() {
// static
bool nsContentUtils::IsEventAttributeName(nsAtom* aName, int32_t aType) {
const char16_t* name = aName->GetUTF16String();
if (name[0] != 'o' || name[1] != 'n') return false;
if (name[0] != 'o' || name[1] != 'n' ||
(aName == nsGkAtoms::onformdata &&
!mozilla::StaticPrefs::dom_formdata_event_enabled())) {
return false;
}
EventNameMapping mapping;
return (sAtomEventTable->Get(aName, &mapping) && mapping.mType & aType);

View File

@ -477,7 +477,8 @@ function test() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv(
{"set": [["dom.w3c_touch_events.legacy_apis.enabled", true]]},
{"set": [["dom.w3c_touch_events.legacy_apis.enabled", true],
["dom.formdata.event.enabled", true]]},
function() {
test();
SimpleTest.finish();

View File

@ -560,7 +560,8 @@ nsresult HTMLFormElement::DoSubmit(WidgetEvent* aEvent) {
nsresult rv = BuildSubmission(getter_Transfers(submission), aEvent);
// Don't raise an error if form cannot navigate.
if (rv == NS_ERROR_NOT_AVAILABLE) {
if (StaticPrefs::dom_formdata_event_enabled() &&
rv == NS_ERROR_NOT_AVAILABLE) {
mIsSubmitting = false;
return NS_OK;
}
@ -628,7 +629,7 @@ nsresult HTMLFormElement::BuildSubmission(HTMLFormSubmission** aFormSubmission,
// Step 9. If form cannot navigate, then return.
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm
if (!GetComposedDoc()) {
if (StaticPrefs::dom_formdata_event_enabled() && !GetComposedDoc()) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -885,7 +886,8 @@ nsresult HTMLFormElement::NotifySubmitObservers(nsIURI* aActionURL,
nsresult HTMLFormElement::ConstructEntryList(FormData* aFormData) {
MOZ_ASSERT(aFormData, "Must have FormData!");
if (mIsConstructingEntryList) {
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;
}
@ -908,16 +910,18 @@ nsresult HTMLFormElement::ConstructEntryList(FormData* aFormData) {
sortedControls[i]->SubmitNamesValues(aFormData);
}
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);
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);
EventDispatcher::DispatchDOMEvent(ToSupports(this), nullptr, event, nullptr,
nullptr);
}
return NS_OK;
}

View File

@ -384,7 +384,7 @@ var interfaceNamesInGlobalScope = [
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "FormData", insecureContext: true },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "FormDataEvent", insecureContext: true },
{ name: "FormDataEvent", insecureContext: true, nightly: true },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "FontFace", insecureContext: true },
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -50,6 +50,7 @@ interface mixin GlobalEventHandlers {
attribute EventHandler ondurationchange;
attribute EventHandler onemptied;
attribute EventHandler onended;
[Pref="dom.formdata.event.enabled"]
attribute EventHandler onformdata;
attribute EventHandler oninput;
attribute EventHandler oninvalid;

View File

@ -8,7 +8,8 @@
*/
[Exposed=Window,
Constructor(DOMString type, optional FormDataEventInit eventInitDict = {})]
Constructor(DOMString type, optional FormDataEventInit eventInitDict = {}),
Pref="dom.formdata.event.enabled"]
interface FormDataEvent : Event {
// C++ can't deal with a method called FormData() in the generated code
[BinaryName="GetFormData"]

View File

@ -1459,6 +1459,12 @@
value: false
mirror: always
# Whether or not formData event is enabled.
- name: dom.formdata.event.enabled
type: bool
value: @IS_NIGHTLY_BUILD@
mirror: always
# Support @autocomplete values for form autofill feature.
- name: dom.forms.autocomplete.formautofill
type: bool

View File

@ -1,2 +1,3 @@
lsan-allowed: [Alloc, Malloc, NewPage, PLDHashTable::Add, Realloc, SetPropertyAsInterface, mozilla::WeakPtr, mozilla::extensions::ChannelWrapper::ChannelWrapper, mozilla::net::nsUDPSocket::SendWithAddress, nsNodeSupportsWeakRefTearoff::GetWeakReference]
leak-threshold: [default:51200]
prefs: [dom.formdata.event.enabled:true]

View File

@ -0,0 +1 @@
prefs: [dom.formdata.event.enabled:true]

View File

@ -0,0 +1 @@
prefs: [dom.formdata.event.enabled:true]

View File

@ -1 +1 @@
prefs: [javascript.options.streams:true, dom.xhr.standard_content_type_normalization:true]
prefs: [javascript.options.streams:true, dom.xhr.standard_content_type_normalization:true, dom.formdata.event.enabled:true]