Bug 1460509 - part 9: Make TextEditRules::WillSetText() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: 9ksPugTVVqh
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -901,16 +901,19 @@ TextEditRules::WillSetText(bool* aCancel
}
RefPtr<nsTextNode> newNode = EditorBase::CreateTextNode(*doc, tString);
if (NS_WARN_IF(!newNode)) {
return NS_OK;
}
nsresult rv =
TextEditorRef().InsertNodeWithTransaction(
*newNode, EditorRawDOMPoint(rootElement, 0));
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
*aHandled = true;
ASSERT_PASSWORD_LENGTHS_EQUAL();
return NS_OK;
@@ -920,16 +923,19 @@ TextEditRules::WillSetText(bool* aCancel
if (NS_WARN_IF(!EditorBase::IsTextNode(curNode))) {
return NS_OK;
}
// Even if empty text, we don't remove text node and set empty text
// for performance
nsresult rv = TextEditorRef().SetTextImpl(SelectionRef(), tString,
*curNode->GetAsText());
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
*aHandled = true;
ASSERT_PASSWORD_LENGTHS_EQUAL();
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -134,20 +134,30 @@ protected:
bool* aCancel,
bool* aHandled,
const nsAString* inString,
nsAString* outString,
int32_t aMaxLength);
nsresult WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
- nsresult WillSetText(bool* aCancel,
- bool* aHandled,
- const nsAString* inString,
- int32_t aMaxLength);
+ /**
+ * Called before setting text to the text editor.
+ * This method may actually set text to it. Therefore, this might cause
+ * destroying the text editor.
+ *
+ * @param aCancel Returns true if the operation is canceled.
+ * @param aHandled Returns true if the edit action is handled.
+ * @param inString String to be set.
+ * @param aMaxLength The maximum string length which the text editor
+ * allows to set.
+ */
+ MOZ_MUST_USE nsresult
+ WillSetText(bool* aCancel, bool* aHandled,
+ const nsAString* inString, int32_t aMaxLength);
void WillInsert(bool* aCancel);
/**
* Called before deleting selected content.
* This method may actually remove the selected content with
* DeleteSelectionWithTransaction(). So, this might cause destroying the
* editor.