Commit 8fb3a4ae authored by tkent's avatar tkent Committed by Commit bot

Editing: Remove unreasonable ASSERT_NO_EDITING_ABORT instances.

This CL has no tests.  We're not sure if this CL makes user-visible behavior
changes.  The purpose of this CL is to reduce ClusterFuzz crashes in the future.

This CL also updates comments in EditingState.h.  We can't remove
NoEditingAbortChecker and ASSERT_NO_EDITING_ABORT.

BUG=586846

Review URL: https://codereview.chromium.org/1703903002

Cr-Commit-Position: refs/heads/master@{#376067}
parent 0273a935
......@@ -1154,7 +1154,9 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
element->removeAttribute(HTMLNames::idAttr);
if (isHTMLAnchorElement(element))
element->removeAttribute(HTMLNames::nameAttr);
surroundNodeRangeWithElement(child, child, wrapper, ASSERT_NO_EDITING_ABORT);
surroundNodeRangeWithElement(child, child, wrapper, editingState);
if (editingState->isAborted())
return;
}
}
......
......@@ -65,9 +65,7 @@ private:
} while (true)
#if ENABLE(ASSERT)
// TODO(yosin): Once all commands aware |EditingState|, we get rid of
// |NoEditingAbortChecker| class
// This class is inspired by |NoExceptionStateAssertionChecke|.
// This class is inspired by |NoExceptionStateAssertionChecker|.
class NoEditingAbortChecker final {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(NoEditingAbortChecker);
......@@ -83,9 +81,11 @@ private:
int const m_line;
};
// A macro for default parameter of |EditingState*| parameter.
// TODO(yosin): Once all commands aware |EditingState|, we get rid of
// |ASSERT_NO_EDITING_ABORT| macro.
// If a function with EditingState* argument should not be aborted,
// ASSERT_NO_EDITING_ABORT should be specified.
// fooFunc(...., ASSERT_NO_EDITING_ABORT);
// It causes an assertion failure If ENABLE(ASSERT) and the function was aborted
// unexpectedly.
#define ASSERT_NO_EDITING_ABORT (NoEditingAbortChecker(__FILE__, __LINE__).editingState())
#else
#define ASSERT_NO_EDITING_ABORT (IgnorableEditingAbortState().editingState())
......
......@@ -193,7 +193,9 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState)
// Adjust the insertion position after the delete
const Position originalInsertionPosition = insertionPosition;
const Element* enclosingAnchor = enclosingAnchorElement(originalInsertionPosition);
insertionPosition = positionAvoidingSpecialElementBoundary(insertionPosition, ASSERT_NO_EDITING_ABORT);
insertionPosition = positionAvoidingSpecialElementBoundary(insertionPosition, editingState);
if (editingState->isAborted())
return;
if (listChild == enclosingAnchor) {
// |positionAvoidingSpecialElementBoundary()| creates new A element and
// move to another place.
......@@ -329,7 +331,10 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState)
// Recreate the same structure in the new paragraph.
WillBeHeapVector<RefPtrWillBeMember<Element>> ancestors;
getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionOutsideTabSpan(insertionPosition), ASSERT_NO_EDITING_ABORT).anchorNode(), startBlock.get(), ancestors);
insertionPosition = positionAvoidingSpecialElementBoundary(positionOutsideTabSpan(insertionPosition), editingState);
if (editingState->isAborted())
return;
getAncestorsInsideBlock(insertionPosition.anchorNode(), startBlock.get(), ancestors);
RefPtrWillBeRawPtr<Element> placeholder = cloneHierarchyUnderNewBlock(ancestors, blockToInsert, editingState);
if (editingState->isAborted())
......
......@@ -38,7 +38,7 @@ SimplifyMarkupCommand::SimplifyMarkupCommand(Document& document, Node* firstNode
{
}
void SimplifyMarkupCommand::doApply(EditingState*)
void SimplifyMarkupCommand::doApply(EditingState* editingState)
{
ContainerNode* rootNode = m_firstNode->parentNode();
WillBeHeapVector<RefPtrWillBeMember<ContainerNode>> nodesToRemove;
......@@ -88,15 +88,19 @@ void SimplifyMarkupCommand::doApply(EditingState*)
// we perform all the DOM mutations at once.
for (size_t i = 0; i < nodesToRemove.size(); ++i) {
// FIXME: We can do better by directly moving children from nodesToRemove[i].
int numPrunedAncestors = pruneSubsequentAncestorsToRemove(nodesToRemove, i);
int numPrunedAncestors = pruneSubsequentAncestorsToRemove(nodesToRemove, i, editingState);
if (editingState->isAborted())
return;
if (numPrunedAncestors < 0)
continue;
removeNodePreservingChildren(nodesToRemove[i], ASSERT_NO_EDITING_ABORT, AssumeContentIsAlwaysEditable);
removeNodePreservingChildren(nodesToRemove[i], editingState, AssumeContentIsAlwaysEditable);
if (editingState->isAborted())
return;
i += numPrunedAncestors;
}
}
int SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove(WillBeHeapVector<RefPtrWillBeMember<ContainerNode>>& nodesToRemove, size_t startNodeIndex)
int SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove(WillBeHeapVector<RefPtrWillBeMember<ContainerNode>>& nodesToRemove, size_t startNodeIndex, EditingState* editingState)
{
size_t pastLastNodeToRemove = startNodeIndex + 1;
for (; pastLastNodeToRemove < nodesToRemove.size(); ++pastLastNodeToRemove) {
......@@ -113,9 +117,15 @@ int SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove(WillBeHeapVector<Ref
if (pastLastNodeToRemove == startNodeIndex + 1)
return 0;
removeNode(nodesToRemove[startNodeIndex], ASSERT_NO_EDITING_ABORT, AssumeContentIsAlwaysEditable);
insertNodeBefore(nodesToRemove[startNodeIndex], highestAncestorToRemove, ASSERT_NO_EDITING_ABORT, AssumeContentIsAlwaysEditable);
removeNode(highestAncestorToRemove, ASSERT_NO_EDITING_ABORT, AssumeContentIsAlwaysEditable);
removeNode(nodesToRemove[startNodeIndex], editingState, AssumeContentIsAlwaysEditable);
if (editingState->isAborted())
return -1;
insertNodeBefore(nodesToRemove[startNodeIndex], highestAncestorToRemove, editingState, AssumeContentIsAlwaysEditable);
if (editingState->isAborted())
return -1;
removeNode(highestAncestorToRemove, editingState, AssumeContentIsAlwaysEditable);
if (editingState->isAborted())
return -1;
return pastLastNodeToRemove - startNodeIndex - 1;
}
......
......@@ -43,7 +43,7 @@ private:
SimplifyMarkupCommand(Document&, Node* firstNode, Node* nodeAfterLast);
void doApply(EditingState*) override;
int pruneSubsequentAncestorsToRemove(WillBeHeapVector<RefPtrWillBeMember<ContainerNode>>& nodesToRemove, size_t startNodeIndex);
int pruneSubsequentAncestorsToRemove(WillBeHeapVector<RefPtrWillBeMember<ContainerNode>>& nodesToRemove, size_t startNodeIndex, EditingState*);
RefPtrWillBeMember<Node> m_firstNode;
RefPtrWillBeMember<Node> m_nodeAfterLast;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment