Bug 1549264 - Mark EditorBase::SplitNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D30039

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-05-07 22:34:28 +00:00
Родитель 0925cb9a70
Коммит f440ac739a
13 изменённых файлов: 169 добавлений и 121 удалений

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

@ -1072,7 +1072,7 @@ class EditorBase : public nsIEditor,
* error.
*/
template <typename PT, typename CT>
already_AddRefed<nsIContent> SplitNodeWithTransaction(
MOZ_CAN_RUN_SCRIPT already_AddRefed<nsIContent> SplitNodeWithTransaction(
const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
ErrorResult& aResult);
@ -1386,7 +1386,7 @@ class EditorBase : public nsIEditor,
* caller want to do it.
*/
template <typename PT, typename CT>
SplitNodeResult SplitNodeDeepWithTransaction(
MOZ_CAN_RUN_SCRIPT SplitNodeResult SplitNodeDeepWithTransaction(
nsIContent& aMostAncestorToSplit,
const EditorDOMPointBase<PT, CT>& aDeepestStartOfRightNode,
SplitAtEdges aSplitAtEdges);

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

@ -1462,9 +1462,9 @@ nsresult HTMLEditRules::WillInsertText(EditSubAction aEditSubAction,
// is it a return?
if (subStr.Equals(newlineStr)) {
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(currentPoint,
nsIEditor::eNone);
RefPtr<Element> brElement = MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(
currentPoint, nsIEditor::eNone);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -1834,7 +1834,8 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
EditorRawDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(blockParent);
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(endOfBlockParent);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(endOfBlockParent);
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
}
@ -1921,7 +1922,8 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
// First, insert a <br> element.
RefPtr<Element> brElement;
if (IsPlaintextEditor()) {
brElement = HTMLEditorRef().InsertBrElementWithTransaction(aPointToBreak);
brElement = MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(aPointToBreak);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -1946,9 +1948,10 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
HTMLEditor::GetLinkElement(pointToBreak.GetContainer());
if (linkNode) {
SplitNodeResult splitLinkNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*linkNode, pointToBreak,
SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*linkNode, pointToBreak,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -2094,8 +2097,10 @@ EditActionResult HTMLEditRules::SplitMailCites() {
}
SplitNodeResult splitCiteNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*citeNode, pointToSplit, SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*citeNode, pointToSplit,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
}
@ -2124,8 +2129,8 @@ EditActionResult HTMLEditRules::SplitMailCites() {
EditorRawDOMPoint endOfPreviousNodeOfSplitPoint;
endOfPreviousNodeOfSplitPoint.SetToEndOf(previousNodeOfSplitPoint);
RefPtr<Element> invisibleBrElement =
HTMLEditorRef().InsertBrElementWithTransaction(
endOfPreviousNodeOfSplitPoint);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(endOfPreviousNodeOfSplitPoint);
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
}
@ -2139,7 +2144,8 @@ EditActionResult HTMLEditRules::SplitMailCites() {
// cite node, <br> should be inserted before the current cite.
EditorRawDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(pointToInsertBrNode);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToInsertBrNode);
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
}
@ -2189,8 +2195,8 @@ EditActionResult HTMLEditRules::SplitMailCites() {
wsType == WSType::special ||
// In case we're at the very end.
wsType == WSType::thisBlock) {
brElement = HTMLEditorRef().InsertBrElementWithTransaction(
pointToCreateNewBrNode);
brElement = MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToCreateNewBrNode);
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
}
@ -3177,8 +3183,9 @@ nsresult HTMLEditRules::InsertBRIfNeeded() {
if (HTMLEditorRef().CanContainTag(*atStartOfSelection.GetContainer(),
*nsGkAtoms::br)) {
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(atStartOfSelection,
nsIEditor::ePrevious);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(atStartOfSelection,
nsIEditor::ePrevious);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -3498,9 +3505,11 @@ EditActionResult HTMLEditRules::TryToJoinBlocksWithTransaction(
nsCOMPtr<nsINode> previousContentParent =
previousContent.GetContainer();
int32_t previousContentOffset = previousContent.Offset();
rv = HTMLEditorRef().SplitStyleAbovePoint(
address_of(previousContentParent), &previousContentOffset, nullptr,
nullptr, nullptr, getter_AddRefs(splittedPreviousContent));
rv = MOZ_KnownLive(HTMLEditorRef())
.SplitStyleAbovePoint(address_of(previousContentParent),
&previousContentOffset, nullptr, nullptr,
nullptr,
getter_AddRefs(splittedPreviousContent));
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
}
@ -3797,7 +3806,8 @@ nsresult HTMLEditRules::DidDeleteSelection() {
}
if (atCiteNode.IsSet() && seenBR) {
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(atCiteNode);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(atCiteNode);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -4081,7 +4091,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
}
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
HTMLEditorRef().SplitNodeWithTransaction(atCurNode, error);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeWithTransaction(atCurNode, error);
if (NS_WARN_IF(!CanHandleEditAction())) {
error.SuppressException();
return NS_ERROR_EDITOR_DESTROYED;
@ -4442,9 +4453,10 @@ nsresult HTMLEditRules::MakeBasicBlock(nsAtom& blockType) {
}
// Do the splits!
SplitNodeResult splitNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*curBlock, pointToInsertBlock,
SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*curBlock, pointToInsertBlock,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -4453,8 +4465,8 @@ nsresult HTMLEditRules::MakeBasicBlock(nsAtom& blockType) {
}
EditorRawDOMPoint pointToInsertBrNode(splitNodeResult.SplitPoint());
// Put a <br> element at the split point
brContent =
HTMLEditorRef().InsertBrElementWithTransaction(pointToInsertBrNode);
brContent = MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToInsertBrNode);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -4572,7 +4584,8 @@ nsresult HTMLEditRules::DidMakeBasicBlock() {
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
nsresult rv = InsertMozBRIfNeeded(*atStartOfSelection.Container());
nsresult rv =
InsertMozBRIfNeeded(MOZ_KnownLive(*atStartOfSelection.Container()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4805,8 +4818,8 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(*containerName,
atCurNode);
MaybeSplitAncestorsForInsertWithTransaction(
MOZ_KnownLive(*containerName), atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -5077,8 +5090,8 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(*containerName,
atCurNode);
MaybeSplitAncestorsForInsertWithTransaction(
MOZ_KnownLive(*containerName), atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -5139,8 +5152,8 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
atListItem.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(*containerName,
atListItem);
MaybeSplitAncestorsForInsertWithTransaction(
MOZ_KnownLive(*containerName), atListItem);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -5637,9 +5650,10 @@ SplitRangeOffFromNodeResult HTMLEditRules::SplitRangeOffFromBlock(
// Split at the start.
SplitNodeResult splitAtStartResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
aBlockElement, EditorRawDOMPoint(&aStartOfMiddleElement),
SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aBlockElement, EditorRawDOMPoint(&aStartOfMiddleElement),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
}
@ -5651,8 +5665,10 @@ SplitRangeOffFromNodeResult HTMLEditRules::SplitRangeOffFromBlock(
DebugOnly<bool> advanced = atAfterEnd.AdvanceOffset();
NS_WARNING_ASSERTION(advanced, "Failed to advance offset after the end node");
SplitNodeResult splitAtEndResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
aBlockElement, atAfterEnd, SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aBlockElement, atAfterEnd,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
}
@ -5804,9 +5820,10 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
if (RefPtr<Text> text = node->GetAsText()) {
// if we are in a text node, split it
SplitNodeResult splitTextNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*text, EditorRawDOMPoint(text, offset),
SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*text, EditorRawDOMPoint(text, offset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -6349,7 +6366,8 @@ nsresult HTMLEditRules::MaybeDeleteTopMostEmptyAncestor(
// AfterEdit().
if (!HTMLEditUtils::IsList(atBlockParent.GetContainer())) {
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(atBlockParent);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(atBlockParent);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7115,7 +7133,8 @@ nsresult HTMLEditRules::GetNodesForOperation(
// Split the text node.
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
HTMLEditorRef().SplitNodeWithTransaction(atEnd, error);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeWithTransaction(atEnd, error);
if (NS_WARN_IF(!CanHandleEditAction())) {
error.SuppressException();
return NS_ERROR_EDITOR_DESTROYED;
@ -7445,10 +7464,12 @@ nsresult HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& aRangeItem) {
// GetHighestInlineParent(), isn't it?
if (endInline && !isCollapsed) {
SplitNodeResult splitEndInlineResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*endInline,
EditorRawDOMPoint(aRangeItem.mEndContainer, aRangeItem.mEndOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*endInline,
EditorRawDOMPoint(aRangeItem.mEndContainer,
aRangeItem.mEndOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7468,11 +7489,12 @@ nsresult HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& aRangeItem) {
if (startInline) {
SplitNodeResult splitStartInlineResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*startInline,
EditorRawDOMPoint(aRangeItem.mStartContainer,
aRangeItem.mStartOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*startInline,
EditorRawDOMPoint(aRangeItem.mStartContainer,
aRangeItem.mStartOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7517,8 +7539,10 @@ nsresult HTMLEditRules::BustUpInlinesAtBRs(
return NS_ERROR_FAILURE;
}
SplitNodeResult splitNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*nextNode, atBrNode, SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*nextNode, atBrNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7711,9 +7735,10 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
// Split the header
SplitNodeResult splitHeaderResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
aHeader, EditorRawDOMPoint(node, aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aHeader, EditorRawDOMPoint(node, aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7772,8 +7797,8 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
// Append a <br> to it
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(
EditorRawDOMPoint(pNode, 0));
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(EditorRawDOMPoint(pNode, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7942,8 +7967,8 @@ EditActionResult HTMLEditRules::ReturnInParagraph(Element& aParentDivOrP) {
if (doesCRCreateNewP) {
ErrorResult error;
nsCOMPtr<nsIContent> newLeftDivOrP =
HTMLEditorRef().SplitNodeWithTransaction(pointToSplitParentDivOrP,
error);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeWithTransaction(pointToSplitParentDivOrP, error);
if (NS_WARN_IF(!CanHandleEditAction())) {
error.SuppressException();
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
@ -7987,7 +8012,8 @@ EditActionResult HTMLEditRules::ReturnInParagraph(Element& aParentDivOrP) {
return EditActionResult(NS_OK);
}
brContent = HTMLEditorRef().InsertBrElementWithTransaction(pointToInsertBR);
brContent = MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToInsertBR);
if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
}
@ -8033,9 +8059,10 @@ nsresult HTMLEditRules::SplitParagraph(
// Split the paragraph.
SplitNodeResult splitDivOrPResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
aParentDivOrP, EditorRawDOMPoint(selNode, selOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aParentDivOrP, EditorRawDOMPoint(selNode, selOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -8074,11 +8101,11 @@ nsresult HTMLEditRules::SplitParagraph(
// moz-<br> will be exposed as <br> with Element.innerHTML. Therefore,
// we can use normal <br> elements for placeholder in this case.
// Note that Chromium also behaves so.
rv = InsertBRIfNeeded(*splitDivOrPResult.GetPreviousNode());
rv = InsertBRIfNeeded(MOZ_KnownLive(*splitDivOrPResult.GetPreviousNode()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = InsertBRIfNeeded(*splitDivOrPResult.GetNextNode());
rv = InsertBRIfNeeded(MOZ_KnownLive(*splitDivOrPResult.GetNextNode()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -8128,8 +8155,8 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
// We need to split the list!
EditorRawDOMPoint atListItem(&aListItem);
ErrorResult error;
leftListNode =
HTMLEditorRef().SplitNodeWithTransaction(atListItem, error);
leftListNode = MOZ_KnownLive(HTMLEditorRef())
.SplitNodeWithTransaction(atListItem, error);
if (NS_WARN_IF(!CanHandleEditAction())) {
error.SuppressException();
return NS_ERROR_EDITOR_DESTROYED;
@ -8190,8 +8217,8 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
// Append a <br> to it
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(
EditorRawDOMPoint(pNode, 0));
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(EditorRawDOMPoint(pNode, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -8230,9 +8257,10 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
// Now split the list item.
SplitNodeResult splitListItemResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
aListItem, EditorRawDOMPoint(selNode, aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aListItem, EditorRawDOMPoint(selNode, aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -8784,7 +8812,7 @@ SplitNodeResult HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction(
}
// Look for a node that can legally contain the tag.
EditorRawDOMPoint pointToInsert(aStartOfDeepestRightNode);
EditorDOMPoint pointToInsert(aStartOfDeepestRightNode);
for (; pointToInsert.IsSet();
pointToInsert.Set(pointToInsert.GetContainer())) {
// We cannot split active editing host and its ancestor. So, there is
@ -8809,9 +8837,11 @@ SplitNodeResult HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction(
}
SplitNodeResult splitNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*pointToInsert.GetChild(), aStartOfDeepestRightNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
MOZ_KnownLive(*pointToInsert.GetChild()),
aStartOfDeepestRightNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitNodeResult(NS_ERROR_EDITOR_DESTROYED);
}
@ -9592,8 +9622,8 @@ nsresult HTMLEditRules::RemoveEmptyNodesInChangedRange() {
// We are deleting a cite that has just a br. We want to delete cite,
// but preserve br.
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(
EditorRawDOMPoint(delNode));
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(EditorRawDOMPoint(delNode));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -9724,7 +9754,8 @@ nsresult HTMLEditRules::PopListItem(nsIContent& aListItem, bool* aOutOfList) {
}
MOZ_ASSERT(atListItem.IsSetAndValid());
ErrorResult error;
leftListNode = HTMLEditorRef().SplitNodeWithTransaction(atListItem, error);
leftListNode = MOZ_KnownLive(HTMLEditorRef())
.SplitNodeWithTransaction(atListItem, error);
if (NS_WARN_IF(!CanHandleEditAction())) {
error.SuppressException();
return NS_ERROR_EDITOR_DESTROYED;
@ -10314,7 +10345,8 @@ nsresult HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
pointToInsert.Set(&aNode, 0);
}
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(pointToInsert);
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToInsert);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -10620,8 +10652,8 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(*containerName,
atCurNode);
MaybeSplitAncestorsForInsertWithTransaction(
MOZ_KnownLive(*containerName), atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -10689,8 +10721,8 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
atListItem.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(*containerName,
atListItem);
MaybeSplitAncestorsForInsertWithTransaction(
MOZ_KnownLive(*containerName), atListItem);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}

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

@ -122,6 +122,7 @@ class HTMLEditRules : public TextEditRules {
*
* @param aNode The node which may be inserted <br> elements.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MakeSureElemStartsAndEndsOnCR(nsINode& aNode);
void DidCreateNode(Element& aNewElement);
@ -262,7 +263,7 @@ class HTMLEditRules : public TextEditRules {
* not be spastic. If so, it inserts one. Callers responsibility to only
* call with collapsed selection.
*/
MOZ_MUST_USE nsresult InsertBRIfNeeded();
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertBRIfNeeded();
/**
* CanContainParagraph() returns true if aElement can have a <p> element as
@ -274,7 +275,7 @@ class HTMLEditRules : public TextEditRules {
* Insert normal <br> element into aNode when aNode is a block and it has
* no children.
*/
MOZ_MUST_USE nsresult InsertBRIfNeeded(nsINode& aNode) {
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertBRIfNeeded(nsINode& aNode) {
return InsertBRIfNeededInternal(aNode, false);
}
@ -282,7 +283,7 @@ class HTMLEditRules : public TextEditRules {
* Insert moz-<br> element (<br type="_moz">) into aNode when aNode is a
* block and it has no children.
*/
MOZ_MUST_USE nsresult InsertMozBRIfNeeded(nsINode& aNode) {
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertMozBRIfNeeded(nsINode& aNode) {
return InsertBRIfNeededInternal(aNode, true);
}
@ -296,6 +297,7 @@ class HTMLEditRules : public TextEditRules {
* Otherwise, i.e., this should insert a normal <br>
* element, false.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult InsertBRIfNeededInternal(nsINode& aNode,
bool aInsertMozBR);
@ -540,7 +542,7 @@ class HTMLEditRules : public TextEditRules {
* contents. This method inserts moz-<br> element if start container of
* Selection needs it.
*/
MOZ_MUST_USE nsresult DidMakeBasicBlock();
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidMakeBasicBlock();
/**
* Called before changing an element to absolute positioned.
@ -783,6 +785,7 @@ class HTMLEditRules : public TextEditRules {
* @param aStartOfMiddleElement Start node of middle block element.
* @param aEndOfMiddleElement End node of middle block element.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE SplitRangeOffFromNodeResult SplitRangeOffFromBlock(
Element& aBlockElement, nsIContent& aStartOfMiddleElement,
nsIContent& aEndOfMiddleElement);
@ -990,6 +993,7 @@ class HTMLEditRules : public TextEditRules {
* Will be modified to split point if they're
* split.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult BustUpInlinesAtRangeEndpoints(RangeItem& aRangeItem);
/**
@ -1084,7 +1088,8 @@ class HTMLEditRules : public TextEditRules {
* the point to insert the element.
*/
template <typename PT, typename CT>
MOZ_MUST_USE SplitNodeResult MaybeSplitAncestorsForInsertWithTransaction(
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE SplitNodeResult
MaybeSplitAncestorsForInsertWithTransaction(
nsAtom& aTag, const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode);
/**
@ -1169,7 +1174,7 @@ class HTMLEditRules : public TextEditRules {
* InsertBRElementToEmptyListItemsAndTableCellsInChangedRange() inserts
* <br> element into empty list item or table cell elements.
*/
MOZ_MUST_USE nsresult
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
InsertBRElementToEmptyListItemsAndTableCellsInChangedRange();
/**
@ -1187,7 +1192,8 @@ class HTMLEditRules : public TextEditRules {
*
* @param aAction Maybe used to look for a good point to put caret.
*/
MOZ_MUST_USE nsresult AdjustSelection(nsIEditor::EDirection aAction);
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
AdjustSelection(nsIEditor::EDirection aAction);
/**
* FindNearEditableNode() tries to find an editable node near aPoint.
@ -1278,6 +1284,7 @@ class HTMLEditRules : public TextEditRules {
* @param aStarts true for trying to insert <br> to the start.
* false for trying to insert <br> to the end.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
bool aStarts);

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

@ -1692,8 +1692,9 @@ EditorDOMPoint HTMLEditor::InsertNodeIntoProperAncestorWithTransaction(
if (pointToInsert != aPointToInsert) {
// We need to split some levels above the original selection parent.
MOZ_ASSERT(pointToInsert.GetChild());
SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
*pointToInsert.GetChild(), aPointToInsert, aSplitAtEdges);
SplitNodeResult splitNodeResult =
SplitNodeDeepWithTransaction(MOZ_KnownLive(*pointToInsert.GetChild()),
aPointToInsert, aSplitAtEdges);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return EditorDOMPoint();
}
@ -2139,7 +2140,7 @@ HTMLEditor::MakeOrChangeList(const nsAString& aListType, bool entireList,
if (pointToInsertList.GetContainer() != atStartOfSelection.GetContainer()) {
// We need to split up to the child of parent.
SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
*pointToInsertList.GetChild(), atStartOfSelection,
MOZ_KnownLive(*pointToInsertList.GetChild()), atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
@ -2316,7 +2317,7 @@ nsresult HTMLEditor::InsertBasicBlockWithTransaction(nsAtom& aTagName) {
atStartOfSelection.GetContainer()) {
// We need to split up to the child of the point to insert a block.
SplitNodeResult splitBlockResult = SplitNodeDeepWithTransaction(
*pointToInsertBlock.GetChild(), atStartOfSelection,
MOZ_KnownLive(*pointToInsertBlock.GetChild()), atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitBlockResult.Failed())) {
return splitBlockResult.Rv();
@ -2457,8 +2458,8 @@ nsresult HTMLEditor::IndentOrOutdentAsSubAction(
atStartOfSelection.GetContainer()) {
// We need to split up to the child of parent.
SplitNodeResult splitBlockquoteResult = SplitNodeDeepWithTransaction(
*pointToInsertBlockquote.GetChild(), atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(*pointToInsertBlockquote.GetChild()),
atStartOfSelection, SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitBlockquoteResult.Failed())) {
return splitBlockquoteResult.Rv();
}

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

@ -208,8 +208,8 @@ class HTMLEditor final : public TextEditor,
/**
* Indent or outdent content around Selection.
*/
nsresult IndentAsAction();
nsresult OutdentAsAction();
MOZ_CAN_RUN_SCRIPT nsresult IndentAsAction();
MOZ_CAN_RUN_SCRIPT nsresult OutdentAsAction();
/**
* event callback when a mouse button is pressed
@ -788,6 +788,7 @@ class HTMLEditor final : public TextEditor,
nsresult SetInlinePropertyOnNode(nsIContent& aNode, nsAtom& aProperty,
nsAtom* aAttribute, const nsAString& aValue);
MOZ_CAN_RUN_SCRIPT
nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
nsAtom* aProperty, nsAtom* aAttribute,
nsIContent** aOutLeftNode = nullptr,
@ -951,9 +952,8 @@ class HTMLEditor final : public TextEditor,
nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
nsAtom* aProperty, nsAtom* aAttribute);
nsresult SetPositionToAbsolute(Element& aElement);
MOZ_CAN_RUN_SCRIPT
nsresult SetPositionToStatic(Element& aElement);
MOZ_CAN_RUN_SCRIPT nsresult SetPositionToAbsolute(Element& aElement);
MOZ_CAN_RUN_SCRIPT nsresult SetPositionToStatic(Element& aElement);
/**
* OnModifyDocument() is called when the editor is changed. This should
@ -1510,6 +1510,7 @@ class HTMLEditor final : public TextEditor,
* @param aEditSubAction Must be EditSubAction::eIndent or
* EditSubAction::eOutdent.
*/
MOZ_CAN_RUN_SCRIPT
nsresult IndentOrOutdentAsSubAction(EditSubAction aEditSubAction);
MOZ_CAN_RUN_SCRIPT
@ -2085,6 +2086,7 @@ class HTMLEditor final : public TextEditor,
* @param aTagName A block level element name. Must NOT be
* nsGkAtoms::dt nor nsGkAtoms::dd.
*/
MOZ_CAN_RUN_SCRIPT
nsresult InsertBasicBlockWithTransaction(nsAtom& aTagName);
/**
@ -2109,6 +2111,7 @@ class HTMLEditor final : public TextEditor,
nsresult PromoteInlineRange(nsRange& aRange);
nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange);
MOZ_CAN_RUN_SCRIPT
nsresult SplitStyleAboveRange(nsRange* aRange, nsAtom* aProperty,
nsAtom* aAttribute);
MOZ_CAN_RUN_SCRIPT

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

@ -439,7 +439,7 @@ nsresult IndentCommand::DoCommand(Command aCommand,
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
nsresult rv = htmlEditor->IndentAsAction();
nsresult rv = MOZ_KnownLive(htmlEditor)->IndentAsAction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -483,7 +483,7 @@ nsresult OutdentCommand::DoCommand(Command aCommand,
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
nsresult rv = htmlEditor->OutdentAsAction();
nsresult rv = MOZ_KnownLive(htmlEditor)->OutdentAsAction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -350,7 +350,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
// Are we in a text node? If so, split it.
if (pointToInsert.IsInTextNode()) {
SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
*pointToInsert.GetContainerAsContent(), pointToInsert,
MOZ_KnownLive(*pointToInsert.GetContainerAsContent()), pointToInsert,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();

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

@ -1780,7 +1780,8 @@ CreateElementResult TextEditRules::CreateBRInternal(
}
RefPtr<Element> brElement =
TextEditorRef().InsertBrElementWithTransaction(aPointToInsert);
MOZ_KnownLive(TextEditorRef())
.InsertBrElementWithTransaction(aPointToInsert);
if (NS_WARN_IF(!CanHandleEditAction())) {
return CreateElementResult(NS_ERROR_EDITOR_DESTROYED);
}

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

@ -284,13 +284,12 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
/**
* Creates a trailing break in the text doc if there is not one already.
*/
MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
/**
* Creates a bogus <br> node if the root element has no editable content.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
/**
* Returns a truncated insertion string if insertion would place us over
@ -314,8 +313,8 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* if couldn't create new <br> element.
*/
template <typename PT, typename CT>
CreateElementResult CreateBR(
const EditorDOMPointBase<PT, CT>& aPointToInsert) {
MOZ_CAN_RUN_SCRIPT CreateElementResult
CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert) {
CreateElementResult ret = CreateBRInternal(aPointToInsert, false);
#ifdef DEBUG
// If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
@ -335,8 +334,8 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* if couldn't create new <br> element.
*/
template <typename PT, typename CT>
CreateElementResult CreateMozBR(
const EditorDOMPointBase<PT, CT>& aPointToInsert) {
MOZ_CAN_RUN_SCRIPT CreateElementResult
CreateMozBR(const EditorDOMPointBase<PT, CT>& aPointToInsert) {
CreateElementResult ret = CreateBRInternal(aPointToInsert, true);
#ifdef DEBUG
// If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
@ -393,7 +392,7 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* If it succeeded, never returns nullptr.
*/
template <typename PT, typename CT>
CreateElementResult CreateBRInternal(
MOZ_CAN_RUN_SCRIPT CreateElementResult CreateBRInternal(
const EditorDOMPointBase<PT, CT>& aPointToInsert, bool aCreateMozBR);
protected:

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

@ -354,7 +354,7 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
* <br> node, returns nullptr.
*/
template <typename PT, typename CT>
already_AddRefed<Element> InsertBrElementWithTransaction(
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> InsertBrElementWithTransaction(
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect = eNone);

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

@ -240,7 +240,8 @@ already_AddRefed<Element> WSRunObject::InsertBreak(
}
RefPtr<Element> newBrElement =
mHTMLEditor->InsertBrElementWithTransaction(pointToInsert, aSelect);
MOZ_KnownLive(mHTMLEditor)
->InsertBrElementWithTransaction(pointToInsert, aSelect);
if (NS_WARN_IF(!newBrElement)) {
return nullptr;
}

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

@ -419,6 +419,7 @@ interface nsIEditor : nsISupports
* @param aNewLeftNode [OUT] the new node resulting from the split,
* becomes aExistingRightNode's previous sibling.
*/
[can_run_script]
void splitNode(in Node existingRightNode,
in long offset,
out Node newLeftNode);

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

@ -211,6 +211,7 @@ interface nsIHTMLEditor : nsISupports
* SetParagraphFormat Insert a block paragraph tag around selection
* @param aParagraphFormat "p", "h1" to "h6", "address", "pre", or "blockquote"
*/
[can_run_script]
void setParagraphFormat(in AString aParagraphFormat);
/**
@ -283,6 +284,7 @@ interface nsIHTMLEditor : nsISupports
* Document me!
*
*/
[can_run_script]
void makeOrChangeList(in AString aListType, in boolean entireList,
in AString aBulletType);
@ -298,6 +300,7 @@ interface nsIHTMLEditor : nsISupports
* Document me!
*
*/
[can_run_script]
void indent(in AString aIndent);
/**