Loading editor/libeditor/EditorBase.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -2175,6 +2175,11 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT_IF(IsTextEditor(), !aContent.IsText()); // Do nothing if the node is read-only. if (IsHTMLEditor() && NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(aContent))) { return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; } IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eDeleteNode, nsIEditor::ePrevious, ignoredError); Loading Loading @@ -2218,7 +2223,7 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) { } } return rv; return NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : rv; } NS_IMETHODIMP EditorBase::NotifySelectionChanged(Document* aDocument, Loading Loading @@ -3079,7 +3084,14 @@ nsresult EditorBase::InsertTextIntoTextNodeWithTransaction( if (IsHTMLEditor() && isIMETransaction && mComposition) { RefPtr<Text> textNode = mComposition->GetContainerTextNode(); if (textNode && !textNode->Length()) { DeleteNodeWithTransaction(*textNode); nsresult rv = DeleteNodeWithTransaction(*textNode); if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) { NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::DeleteNodeWithTransaction() failed, but ignored"); mComposition->OnTextNodeRemoved(); static_cast<CompositionTransaction*>(transaction.get())->MarkFixed(); } Loading editor/libeditor/EditorBase.h +1 −1 Original line number Diff line number Diff line Loading @@ -1705,7 +1705,7 @@ class EditorBase : public nsIEditor, * * @param aContent The node which will be removed form the DOM tree. */ virtual MOZ_CAN_RUN_SCRIPT nsresult [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult DeleteNodeWithTransaction(nsIContent& aContent); /** Loading editor/libeditor/HTMLEditSubActionHandler.cpp +27 −96 Original line number Diff line number Diff line Loading @@ -678,15 +678,9 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() { if (mostDistantEmptyInlineAncestor) { nsresult rv = DeleteNodeWithTransaction(*mostDistantEmptyInlineAncestor); if (Destroyed()) { NS_WARNING( "HTMLEditor::DeleteNodeWithTransaction() caused destroying the " "editor at deleting empty inline ancestors"); return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING( "HTMLEditor::DeleteNodeWithTransaction() failed at deleting " "EditorBase::DeleteNodeWithTransaction() failed at deleting " "empty inline ancestors"); return rv; } Loading Loading @@ -958,11 +952,8 @@ nsresult HTMLEditor::EnsureNoPaddingBRElementForEmptyEditor() { RefPtr<HTMLBRElement> paddingBRElement( std::move(mPaddingBRElementForEmptyEditor)); nsresult rv = DeleteNodeWithTransaction(*paddingBRElement); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DeleteNodeWithTransaction() failed"); "EditorBase::DeleteNodeWithTransaction() failed"); return rv; } Loading Loading @@ -2428,11 +2419,8 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement( // MOZ_KnownLive(leftCiteElement) because it's grabbed by // splitCiteElementResult. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*leftCiteElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } } Loading @@ -2441,11 +2429,8 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement( // MOZ_KnownLive(rightCiteElement) because it's grabbed by // splitCiteElementResult. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*rightCiteElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } } Loading Loading @@ -3162,11 +3147,8 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return EditActionResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return EditActionResult(rv); } } Loading Loading @@ -3293,11 +3275,8 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( (content->IsHTMLElement(nsGkAtoms::br) || HTMLEditUtils::IsEmptyInlineContent(content))) { nsresult rv = DeleteNodeWithTransaction(*content); if (NS_WARN_IF(Destroyed())) { return EditActionResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return EditActionResult(rv); } if (content->IsHTMLElement(nsGkAtoms::br)) { Loading Loading @@ -3885,12 +3864,9 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { editingHost)) { if (brContent && brContent->IsHTMLElement(nsGkAtoms::br)) { AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock); rv = DeleteNodeWithTransaction(*brContent); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(*brContent); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -3930,12 +3906,9 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { editingHost)) { if (maybeBRContent->IsHTMLElement(nsGkAtoms::br)) { AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock); rv = DeleteNodeWithTransaction(*maybeBRContent); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(*maybeBRContent); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } // We don't need to act on this node any more Loading Loading @@ -3970,12 +3943,9 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { OwningNonNull<nsIContent>& content = arrayOfContents[0]; // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } arrayOfContents.RemoveElementAt(0); Loading Loading @@ -4396,11 +4366,8 @@ nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() { // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } arrayOfContents.RemoveElementAt(0); Loading Loading @@ -4618,11 +4585,8 @@ nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() { // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -5272,11 +5236,8 @@ SplitRangeOffFromNodeResult HTMLEditor::HandleOutdentAtSelectionInternal() { // Delete any non-list items for now // XXX Chrome moves it from the list element. We should follow it. nsresult rv = DeleteNodeWithTransaction(*lastChildContent); if (NS_WARN_IF(Destroyed())) { return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return SplitRangeOffFromNodeResult(rv); } } Loading Loading @@ -7538,11 +7499,8 @@ HTMLEditor::HandleInsertParagraphInHeadingElement( // MOZ_KnownLive(rightHeadingElement) because it's grabbed by // splitHeadingResult. rv = DeleteNodeWithTransaction(MOZ_KnownLive(*rightHeadingElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } Loading Loading @@ -7921,11 +7879,8 @@ nsresult HTMLEditor::SplitParagraph(Element& aParentDivOrP, // prevent an empty p). if (aNextBRNode && HTMLEditUtils::IsVisibleBRElement(*aNextBRNode)) { nsresult rv = DeleteNodeWithTransaction(*aNextBRNode); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -8055,11 +8010,8 @@ HTMLEditor::HandleInsertParagraphInListItemElement( // Otherwise, replace the empty aListItemElement with a new paragraph. nsresult rv = DeleteNodeWithTransaction(aListItemElement); if (MOZ_UNLIKELY(NS_WARN_IF(Destroyed()))) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } nsStaticAtom& newParagraphTagName = Loading Loading @@ -8224,11 +8176,8 @@ HTMLEditor::HandleInsertParagraphInListItemElement( // MOZ_KnownLive(rightListItemElement) because it's grabbed by // splitListItemResult. rv = DeleteNodeWithTransaction(MOZ_KnownLive(rightListItemElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } return EditorDOMPoint(newListItemElement, 0u); Loading Loading @@ -8652,11 +8601,8 @@ nsresult HTMLEditor::CreateOrChangeBlockContainerElement( // MOZ_KnownLive because 'aArrayOfContents' is guaranteed to keep it // alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } continue; Loading Loading @@ -8905,11 +8851,8 @@ HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction( if (!HTMLEditUtils::IsBlockElement(*nextEditableSibling)) { AutoEditorDOMPointChildInvalidator lockOffset(splitPoint); nsresult rv = DeleteNodeWithTransaction(*maybeBRContent); if (NS_WARN_IF(Destroyed())) { return CreateElementResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return CreateElementResult(rv); } } Loading Loading @@ -9742,12 +9685,9 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) { if (HTMLEditUtils::IsSimplyEditableNode(emptyContent)) { // MOZ_KnownLive because 'arrayOfEmptyContents' is guaranteed to keep it // alive. rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyContent)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyContent)); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -9777,12 +9717,9 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) { MOZ_ASSERT(insertBRElementResult.GetNewNode()); } // MOZ_KnownLive because 'arrayOfEmptyCites' is guaranteed to keep it alive. rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyCite)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyCite)); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -9985,11 +9922,8 @@ nsresult HTMLEditor::DestroyListStructureRecursively(Element& aListElement) { // <script> and <template> and <dl> element to have <div> to group // some <dt> and <dd> elements. So, this may break valid children. nsresult rv = DeleteNodeWithTransaction(*child); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -10704,11 +10638,8 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( for (OwningNonNull<nsIContent>& curNode : arrayOfContents) { // MOZ_KnownLive because 'arrayOfContents' is guaranteed to keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*curNode)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading editor/libeditor/HTMLEditor.cpp +6 −31 Original line number Diff line number Diff line Loading @@ -1531,7 +1531,7 @@ nsresult HTMLEditor::ReplaceHeadContentsWithSourceWithTransaction( while (nsCOMPtr<nsIContent> child = primaryHeadElement->GetFirstChild()) { nsresult rv = DeleteNodeWithTransaction(*child); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -3464,20 +3464,6 @@ nsresult HTMLEditor::RemoveEmptyInclusiveAncestorInlineElements( } nsresult rv = DeleteNodeWithTransaction(content); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DeleteNodeWithTransaction() failed"); return rv; } nsresult HTMLEditor::DeleteNodeWithTransaction(nsIContent& aContent) { // Do nothing if the node is read-only. if (NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(aContent))) { return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; } nsresult rv = EditorBase::DeleteNodeWithTransaction(aContent); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DeleteNodeWithTransaction() failed"); return rv; Loading @@ -3500,7 +3486,7 @@ nsresult HTMLEditor::DeleteAllChildrenWithTransaction(Element& aElement) { while (nsCOMPtr<nsIContent> child = aElement.GetLastChild()) { nsresult rv = DeleteNodeWithTransaction(*child); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading @@ -3522,7 +3508,7 @@ NS_IMETHODIMP HTMLEditor::DeleteNode(nsINode* aNode) { rv = DeleteNodeWithTransaction(MOZ_KnownLive(*aNode->AsContent())); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DeleteNodeWithTransaction() failed"); "EditorBase::DeleteNodeWithTransaction() failed"); return rv; } Loading Loading @@ -3823,7 +3809,7 @@ already_AddRefed<Element> HTMLEditor::InsertContainerWithTransactionInternal( // XXX Perhaps, we should not remove the container if it's not editable. nsresult rv = DeleteNodeWithTransaction(aContent); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return nullptr; } Loading Loading @@ -3929,13 +3915,8 @@ CreateElementResult HTMLEditor::ReplaceContainerWithTransactionInternal( // Delete aOldContainer from the DOM tree to make it not referred by // InsertNodeTransaction. nsresult rv = DeleteNodeWithTransaction(aOldContainer); if (MOZ_UNLIKELY(Destroyed())) { NS_WARNING( "HTMLEditor::DeleteNodeWithTransaction() caused destroying the editor"); return CreateElementResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return CreateElementResult(rv); } Loading Loading @@ -4035,9 +4016,6 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::RemoveContainerWithTransaction( : GetNextSiblingOf(arrayOfChildren, *parentNode); nsresult rv = DeleteNodeWithTransaction(aElement); if (MOZ_UNLIKELY(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeTransaction() failed"); return Err(rv); Loading Loading @@ -5895,11 +5873,8 @@ HTMLEditor::CopyLastEditableChildStylesWithTransaction(Element& aPreviousBlock, for (const OwningNonNull<nsIContent>& child : newBlockChildren) { // MOZ_KNownLive(child) because of bug 1622253 nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(child)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } } Loading editor/libeditor/HTMLEditor.h +1 −10 Original line number Diff line number Diff line Loading @@ -720,15 +720,6 @@ class HTMLEditor final : public EditorBase, WithTransaction aWithTransaction, const EditorDOMPoint& aPointToInsert, EDirection aSelect = eNone); /** * DeleteNodeWithTransaction() removes aContent from the DOM tree if it's * modifiable. * * @param aContent The node to be removed from the DOM tree. */ MOZ_CAN_RUN_SCRIPT nsresult DeleteNodeWithTransaction(nsIContent& aContent) final; /** * DeleteTextWithTransaction() removes text in the range from aTextNode if * it's modifiable. Note that this not an override of same method of Loading Loading @@ -4680,7 +4671,7 @@ class HTMLEditor final : public EditorBase, // JoinNearestEditableNodesWithTransaction, // MoveChildrenWithTransaction, // MoveOneHardLineContentsWithTransaction, // MoveToEndOfCOntainer, // MoveToEndOfContainer, // SplitAncestorStyledInlineElementsAt, // TreatEmptyTextNodes }; Loading Loading
editor/libeditor/EditorBase.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -2175,6 +2175,11 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT_IF(IsTextEditor(), !aContent.IsText()); // Do nothing if the node is read-only. if (IsHTMLEditor() && NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(aContent))) { return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; } IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eDeleteNode, nsIEditor::ePrevious, ignoredError); Loading Loading @@ -2218,7 +2223,7 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) { } } return rv; return NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : rv; } NS_IMETHODIMP EditorBase::NotifySelectionChanged(Document* aDocument, Loading Loading @@ -3079,7 +3084,14 @@ nsresult EditorBase::InsertTextIntoTextNodeWithTransaction( if (IsHTMLEditor() && isIMETransaction && mComposition) { RefPtr<Text> textNode = mComposition->GetContainerTextNode(); if (textNode && !textNode->Length()) { DeleteNodeWithTransaction(*textNode); nsresult rv = DeleteNodeWithTransaction(*textNode); if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) { NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::DeleteNodeWithTransaction() failed, but ignored"); mComposition->OnTextNodeRemoved(); static_cast<CompositionTransaction*>(transaction.get())->MarkFixed(); } Loading
editor/libeditor/EditorBase.h +1 −1 Original line number Diff line number Diff line Loading @@ -1705,7 +1705,7 @@ class EditorBase : public nsIEditor, * * @param aContent The node which will be removed form the DOM tree. */ virtual MOZ_CAN_RUN_SCRIPT nsresult [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult DeleteNodeWithTransaction(nsIContent& aContent); /** Loading
editor/libeditor/HTMLEditSubActionHandler.cpp +27 −96 Original line number Diff line number Diff line Loading @@ -678,15 +678,9 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() { if (mostDistantEmptyInlineAncestor) { nsresult rv = DeleteNodeWithTransaction(*mostDistantEmptyInlineAncestor); if (Destroyed()) { NS_WARNING( "HTMLEditor::DeleteNodeWithTransaction() caused destroying the " "editor at deleting empty inline ancestors"); return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING( "HTMLEditor::DeleteNodeWithTransaction() failed at deleting " "EditorBase::DeleteNodeWithTransaction() failed at deleting " "empty inline ancestors"); return rv; } Loading Loading @@ -958,11 +952,8 @@ nsresult HTMLEditor::EnsureNoPaddingBRElementForEmptyEditor() { RefPtr<HTMLBRElement> paddingBRElement( std::move(mPaddingBRElementForEmptyEditor)); nsresult rv = DeleteNodeWithTransaction(*paddingBRElement); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DeleteNodeWithTransaction() failed"); "EditorBase::DeleteNodeWithTransaction() failed"); return rv; } Loading Loading @@ -2428,11 +2419,8 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement( // MOZ_KnownLive(leftCiteElement) because it's grabbed by // splitCiteElementResult. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*leftCiteElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } } Loading @@ -2441,11 +2429,8 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement( // MOZ_KnownLive(rightCiteElement) because it's grabbed by // splitCiteElementResult. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*rightCiteElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } } Loading Loading @@ -3162,11 +3147,8 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return EditActionResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return EditActionResult(rv); } } Loading Loading @@ -3293,11 +3275,8 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList( (content->IsHTMLElement(nsGkAtoms::br) || HTMLEditUtils::IsEmptyInlineContent(content))) { nsresult rv = DeleteNodeWithTransaction(*content); if (NS_WARN_IF(Destroyed())) { return EditActionResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return EditActionResult(rv); } if (content->IsHTMLElement(nsGkAtoms::br)) { Loading Loading @@ -3885,12 +3864,9 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { editingHost)) { if (brContent && brContent->IsHTMLElement(nsGkAtoms::br)) { AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock); rv = DeleteNodeWithTransaction(*brContent); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(*brContent); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -3930,12 +3906,9 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { editingHost)) { if (maybeBRContent->IsHTMLElement(nsGkAtoms::br)) { AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock); rv = DeleteNodeWithTransaction(*maybeBRContent); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(*maybeBRContent); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } // We don't need to act on this node any more Loading Loading @@ -3970,12 +3943,9 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) { OwningNonNull<nsIContent>& content = arrayOfContents[0]; // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } arrayOfContents.RemoveElementAt(0); Loading Loading @@ -4396,11 +4366,8 @@ nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() { // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } arrayOfContents.RemoveElementAt(0); Loading Loading @@ -4618,11 +4585,8 @@ nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() { // MOZ_KnownLive because 'arrayOfContents' is guaranteed to // keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -5272,11 +5236,8 @@ SplitRangeOffFromNodeResult HTMLEditor::HandleOutdentAtSelectionInternal() { // Delete any non-list items for now // XXX Chrome moves it from the list element. We should follow it. nsresult rv = DeleteNodeWithTransaction(*lastChildContent); if (NS_WARN_IF(Destroyed())) { return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return SplitRangeOffFromNodeResult(rv); } } Loading Loading @@ -7538,11 +7499,8 @@ HTMLEditor::HandleInsertParagraphInHeadingElement( // MOZ_KnownLive(rightHeadingElement) because it's grabbed by // splitHeadingResult. rv = DeleteNodeWithTransaction(MOZ_KnownLive(*rightHeadingElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } Loading Loading @@ -7921,11 +7879,8 @@ nsresult HTMLEditor::SplitParagraph(Element& aParentDivOrP, // prevent an empty p). if (aNextBRNode && HTMLEditUtils::IsVisibleBRElement(*aNextBRNode)) { nsresult rv = DeleteNodeWithTransaction(*aNextBRNode); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -8055,11 +8010,8 @@ HTMLEditor::HandleInsertParagraphInListItemElement( // Otherwise, replace the empty aListItemElement with a new paragraph. nsresult rv = DeleteNodeWithTransaction(aListItemElement); if (MOZ_UNLIKELY(NS_WARN_IF(Destroyed()))) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } nsStaticAtom& newParagraphTagName = Loading Loading @@ -8224,11 +8176,8 @@ HTMLEditor::HandleInsertParagraphInListItemElement( // MOZ_KnownLive(rightListItemElement) because it's grabbed by // splitListItemResult. rv = DeleteNodeWithTransaction(MOZ_KnownLive(rightListItemElement)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } return EditorDOMPoint(newListItemElement, 0u); Loading Loading @@ -8652,11 +8601,8 @@ nsresult HTMLEditor::CreateOrChangeBlockContainerElement( // MOZ_KnownLive because 'aArrayOfContents' is guaranteed to keep it // alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*content)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } continue; Loading Loading @@ -8905,11 +8851,8 @@ HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction( if (!HTMLEditUtils::IsBlockElement(*nextEditableSibling)) { AutoEditorDOMPointChildInvalidator lockOffset(splitPoint); nsresult rv = DeleteNodeWithTransaction(*maybeBRContent); if (NS_WARN_IF(Destroyed())) { return CreateElementResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return CreateElementResult(rv); } } Loading Loading @@ -9742,12 +9685,9 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) { if (HTMLEditUtils::IsSimplyEditableNode(emptyContent)) { // MOZ_KnownLive because 'arrayOfEmptyContents' is guaranteed to keep it // alive. rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyContent)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyContent)); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -9777,12 +9717,9 @@ nsresult HTMLEditor::RemoveEmptyNodesIn(nsRange& aRange) { MOZ_ASSERT(insertBRElementResult.GetNewNode()); } // MOZ_KnownLive because 'arrayOfEmptyCites' is guaranteed to keep it alive. rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyCite)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(emptyCite)); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -9985,11 +9922,8 @@ nsresult HTMLEditor::DestroyListStructureRecursively(Element& aListElement) { // <script> and <template> and <dl> element to have <div> to group // some <dt> and <dd> elements. So, this may break valid children. nsresult rv = DeleteNodeWithTransaction(*child); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -10704,11 +10638,8 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( for (OwningNonNull<nsIContent>& curNode : arrayOfContents) { // MOZ_KnownLive because 'arrayOfContents' is guaranteed to keep it alive. nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(*curNode)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading
editor/libeditor/HTMLEditor.cpp +6 −31 Original line number Diff line number Diff line Loading @@ -1531,7 +1531,7 @@ nsresult HTMLEditor::ReplaceHeadContentsWithSourceWithTransaction( while (nsCOMPtr<nsIContent> child = primaryHeadElement->GetFirstChild()) { nsresult rv = DeleteNodeWithTransaction(*child); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading Loading @@ -3464,20 +3464,6 @@ nsresult HTMLEditor::RemoveEmptyInclusiveAncestorInlineElements( } nsresult rv = DeleteNodeWithTransaction(content); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DeleteNodeWithTransaction() failed"); return rv; } nsresult HTMLEditor::DeleteNodeWithTransaction(nsIContent& aContent) { // Do nothing if the node is read-only. if (NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(aContent))) { return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; } nsresult rv = EditorBase::DeleteNodeWithTransaction(aContent); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DeleteNodeWithTransaction() failed"); return rv; Loading @@ -3500,7 +3486,7 @@ nsresult HTMLEditor::DeleteAllChildrenWithTransaction(Element& aElement) { while (nsCOMPtr<nsIContent> child = aElement.GetLastChild()) { nsresult rv = DeleteNodeWithTransaction(*child); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } Loading @@ -3522,7 +3508,7 @@ NS_IMETHODIMP HTMLEditor::DeleteNode(nsINode* aNode) { rv = DeleteNodeWithTransaction(MOZ_KnownLive(*aNode->AsContent())); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::DeleteNodeWithTransaction() failed"); "EditorBase::DeleteNodeWithTransaction() failed"); return rv; } Loading Loading @@ -3823,7 +3809,7 @@ already_AddRefed<Element> HTMLEditor::InsertContainerWithTransactionInternal( // XXX Perhaps, we should not remove the container if it's not editable. nsresult rv = DeleteNodeWithTransaction(aContent); if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return nullptr; } Loading Loading @@ -3929,13 +3915,8 @@ CreateElementResult HTMLEditor::ReplaceContainerWithTransactionInternal( // Delete aOldContainer from the DOM tree to make it not referred by // InsertNodeTransaction. nsresult rv = DeleteNodeWithTransaction(aOldContainer); if (MOZ_UNLIKELY(Destroyed())) { NS_WARNING( "HTMLEditor::DeleteNodeWithTransaction() caused destroying the editor"); return CreateElementResult(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return CreateElementResult(rv); } Loading Loading @@ -4035,9 +4016,6 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::RemoveContainerWithTransaction( : GetNextSiblingOf(arrayOfChildren, *parentNode); nsresult rv = DeleteNodeWithTransaction(aElement); if (MOZ_UNLIKELY(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeTransaction() failed"); return Err(rv); Loading Loading @@ -5895,11 +5873,8 @@ HTMLEditor::CopyLastEditableChildStylesWithTransaction(Element& aPreviousBlock, for (const OwningNonNull<nsIContent>& child : newBlockChildren) { // MOZ_KNownLive(child) because of bug 1622253 nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(child)); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed"); NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return Err(rv); } } Loading
editor/libeditor/HTMLEditor.h +1 −10 Original line number Diff line number Diff line Loading @@ -720,15 +720,6 @@ class HTMLEditor final : public EditorBase, WithTransaction aWithTransaction, const EditorDOMPoint& aPointToInsert, EDirection aSelect = eNone); /** * DeleteNodeWithTransaction() removes aContent from the DOM tree if it's * modifiable. * * @param aContent The node to be removed from the DOM tree. */ MOZ_CAN_RUN_SCRIPT nsresult DeleteNodeWithTransaction(nsIContent& aContent) final; /** * DeleteTextWithTransaction() removes text in the range from aTextNode if * it's modifiable. Note that this not an override of same method of Loading Loading @@ -4680,7 +4671,7 @@ class HTMLEditor final : public EditorBase, // JoinNearestEditableNodesWithTransaction, // MoveChildrenWithTransaction, // MoveOneHardLineContentsWithTransaction, // MoveToEndOfCOntainer, // MoveToEndOfContainer, // SplitAncestorStyledInlineElementsAt, // TreatEmptyTextNodes }; Loading