Bug 1460509 - part 51: Make HTMLEditRules::WillInsertBreak() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: 2oTOmT4HSv7
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -1768,16 +1768,19 @@ HTMLEditRules::WillInsertBreak(bool* aCa
*aCancel = false;
*aHandled = false;
// If the selection isn't collapsed, delete it.
if (!SelectionRef().IsCollapsed()) {
nsresult rv =
HTMLEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
nsIEditor::eStrip);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
WillInsert(aCancel);
// Initialize out param. We want to ignore result of WillInsert().
@@ -1921,16 +1924,19 @@ HTMLEditRules::WillInsertBreak(bool* aCa
// make block have a line. Then code further below will put in a second br.)
if (IsEmptyBlockElement(*blockParent, IgnoreSingleBR::eNo)) {
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
EditorRawDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(blockParent);
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
endOfBlockParent);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
}
nsCOMPtr<Element> listItem = IsInListItem(blockParent);
if (listItem && listItem != host) {
nsresult rv =
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -153,16 +153,25 @@ protected:
void WillInsert(bool* aCancel);
nsresult WillInsertText(EditAction aAction,
bool* aCancel,
bool* aHandled,
const nsAString* inString,
nsAString* outString,
int32_t aMaxLength);
nsresult WillLoadHTML(bool* aCancel);
+
+ /**
+ * WillInsertBreak() is called when insertParagraph command is executed
+ * or something equivalent. This method actually tries to insert new
+ * paragraph or <br> element, etc.
+ *
+ * @param aCancel Returns true if target node is not editable.
+ * @param aHandled Returns true if actually insert new break.
+ */
nsresult WillInsertBreak(bool* aCancel, bool* aHandled);
void DeleteNodeIfCollapsedText(nsINode& aNode);
/**
* InsertBRElement() inserts a <br> element into aInsertToBreak.
*
* @param aInsertToBreak The point where new <br> element will be