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-06 20:50:52 +00:00
Родитель 6635020ec7
Коммит a128680dbf
12 изменённых файлов: 40 добавлений и 18 удалений

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

@ -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();

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

@ -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);

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

@ -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();

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

@ -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;
}

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

@ -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!

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

@ -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;

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

@ -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"]

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

@ -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

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

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

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

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

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

@ -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]

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

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