Bug 1623918 - part 2: Mark nsINode::GetSelectionRootContent() and its root callers as MOZ_CAN_RUN_SCRIPT as far as possible r=smaug

This patch tries to mark root callers of `nsINode::GetSelectionRootContent()`
which calls `nsINode::GetAnonymousRootElementOfTextEditor()` as far as possible
(and reasonable).

It's used by `ContentEventHandler` so that a lot of methods of
`EventStateManager`, `ContentEventHandler`, `IMEContentObserver` which are main
users of it are also marked as `MOZ_CAN_RUN_SCRIPT`.  I think that this is
reasonable.

On the other hand, it might not be reasonable to mark `IMEStateManager` methods
as `MOZ_CAN_RUN_SCRIPT` for initializing `IMEContentObserver` because
`IMEStateManager` may be able to initialize `IMEContentObserver` asynchronously
and its root callers are in XUL layout code.  Therefore, this patch uses
`MOZ_CAN_RUN_SCRIPT_BOUNDARY` for `IMEStateManager` at least for now.

Differential Revision: https://phabricator.services.mozilla.com/D92730
This commit is contained in:
Masayuki Nakano
2020-10-08 03:56:51 +00:00
parent 4a80f1e088
commit 66cbb9c6c6
26 changed files with 171 additions and 128 deletions

View File

@@ -111,8 +111,8 @@ TextControlElement::GetTextControlElementFromEditingHost(nsIContent* aHost) {
using ValueChangeKind = TextControlElement::ValueChangeKind;
inline nsresult SetEditorFlagsIfNecessary(EditorBase& aEditorBase,
uint32_t aFlags) {
MOZ_CAN_RUN_SCRIPT inline nsresult SetEditorFlagsIfNecessary(
EditorBase& aEditorBase, uint32_t aFlags) {
if (aEditorBase.Flags() == aFlags) {
return NS_OK;
}
@@ -200,7 +200,7 @@ class RestoreSelectionState : public Runnable {
class MOZ_RAII AutoRestoreEditorState final {
public:
explicit AutoRestoreEditorState(TextEditor* aTextEditor)
MOZ_CAN_RUN_SCRIPT explicit AutoRestoreEditorState(TextEditor* aTextEditor)
: mTextEditor(aTextEditor),
mSavedFlags(mTextEditor->Flags()),
mSavedMaxLength(mTextEditor->MaxTextLength()) {
@@ -214,14 +214,18 @@ class MOZ_RAII AutoRestoreEditorState final {
flags &= ~(nsIEditor::eEditorReadonlyMask);
flags |= nsIEditor::eEditorDontEchoPassword;
if (mSavedFlags != flags) {
mTextEditor->SetFlags(flags);
// It's aTextEditor and whose lifetime must be guaranteed by the caller.
MOZ_KnownLive(mTextEditor)->SetFlags(flags);
}
mTextEditor->SetMaxTextLength(-1);
}
~AutoRestoreEditorState() {
MOZ_CAN_RUN_SCRIPT ~AutoRestoreEditorState() {
mTextEditor->SetMaxTextLength(mSavedMaxLength);
SetEditorFlagsIfNecessary(*mTextEditor, mSavedFlags);
// mTextEditor's lifetime must be guaranteed by owner of the instance
// since the constructor is marked as `MOZ_CAN_RUN_SCRIPT` and this is
// a stack only class.
SetEditorFlagsIfNecessary(MOZ_KnownLive(*mTextEditor), mSavedFlags);
}
private: