Bug 1607131 - Make beforeinput event for MozEditableElement.setUserInput() not cancelable by default r=smaug

Blink and WebKit do not fire `beforeinput` event when user uses build-in
password manager and autocomplete.  But the `inputType` value for this case,
`"insertReplacementText"` is defined as cancelable in the spec, and it's
actually cancelable when it's fired for correcting a word with built-in
spellchecker of them.

For making only our users' autocomplete and password manager not blocked by
web apps, we should make them not cancelable by default, but I think that we
should keep dispatching such non-cancelable `beforeinput` for conforming to
the standard unless we'd get a web-compat report for this.

Differential Revision: https://phabricator.services.mozilla.com/D93206
This commit is contained in:
Masayuki Nakano
2020-10-20 00:13:43 +00:00
parent 2defe3eb1a
commit 161f5d6fe9
21 changed files with 230 additions and 66 deletions

View File

@@ -2761,7 +2761,11 @@ bool TextControlState::SetValueWithTextEditor(
// nsIPrincipal means that that may be user's input. So, let's
// do it.
nsresult rv = textEditor->ReplaceTextAsAction(
aHandlingSetValue.GetSettingValue(), nullptr, nullptr);
aHandlingSetValue.GetSettingValue(), nullptr,
StaticPrefs::dom_input_event_allow_to_cancel_set_user_input()
? TextEditor::AllowBeforeInputEventCancelable::Yes
: TextEditor::AllowBeforeInputEventCancelable::No,
nullptr);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditor::ReplaceTextAsAction() failed");
return rv != NS_ERROR_OUT_OF_MEMORY;
@@ -2837,8 +2841,13 @@ bool TextControlState::SetValueWithTextEditor(
// In this case, we makes the editor stop dispatching "input"
// event so that passing nullptr as nsIPrincipal is safe for now.
nsresult rv =
textEditor->SetTextAsAction(aHandlingSetValue.GetSettingValue(), nullptr);
nsresult rv = textEditor->SetTextAsAction(
aHandlingSetValue.GetSettingValue(),
(aHandlingSetValue.GetSetValueFlags() & eSetValue_BySetUserInput) &&
!StaticPrefs::dom_input_event_allow_to_cancel_set_user_input()
? TextEditor::AllowBeforeInputEventCancelable::No
: TextEditor::AllowBeforeInputEventCancelable::Yes,
nullptr);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditor::SetTextAsAction() failed");
@@ -2897,7 +2906,12 @@ bool TextControlState::SetValueWithoutTextEditor(
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(
MOZ_KnownLive(aHandlingSetValue.GetTextControlElement()),
eEditorBeforeInput, EditorInputType::eInsertReplacementText, nullptr,
InputEventOptions(inputEventData), &status);
InputEventOptions(
inputEventData,
StaticPrefs::dom_input_event_allow_to_cancel_set_user_input()
? InputEventOptions::NeverCancelable::No
: InputEventOptions::NeverCancelable::Yes),
&status);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"Failed to dispatch beforeinput event");
if (status == nsEventStatus_eConsumeNoDefault) {
@@ -2983,7 +2997,8 @@ bool TextControlState::SetValueWithoutTextEditor(
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(
MOZ_KnownLive(aHandlingSetValue.GetTextControlElement()),
eEditorInput, EditorInputType::eInsertReplacementText, nullptr,
InputEventOptions(inputEventData));
InputEventOptions(inputEventData,
InputEventOptions::NeverCancelable::No));
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"Failed to dispatch input event");
}