Bug 1539356 - Mark EditorBase::InsertNodeTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato

This patch marks `EditorBase::InsertNodeTransaction()` **and** its callers as `MOZ_CAN_RUN_SCRIPT`.

Unfortunately, this patch tells us that some `GetSomething()` methods may destroy the editor since `HTMLEditRules::GetNodesForOperation()`, `HTMLEditRules::GetNodesFromPoint()` and `HTMLEditRules::GetNodesFromSelection()` may change the DOM tree.  Additionally, initialization methods may destroy the editor since it may insert a bogus `<br>` node.

Note that this patch also removes some unused methods. I.e., they are not result of some cleaning up the code. This patch just avoids marking unused methods as `MOZ_CAN_RUN_SCRIPT`.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-03-29 10:55:31 +00:00
Родитель 624de11cb1
Коммит 81b30d7143
33 изменённых файлов: 572 добавлений и 357 удалений

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

@ -58,23 +58,6 @@ bool nsDocShellEditorData::GetEditable() {
return mMakeEditable || (mHTMLEditor != nullptr); return mMakeEditable || (mHTMLEditor != nullptr);
} }
nsresult nsDocShellEditorData::CreateEditor() {
nsCOMPtr<nsIEditingSession> editingSession;
nsresult rv = GetEditingSession(getter_AddRefs(editingSession));
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsPIDOMWindowOuter> domWindow =
mDocShell ? mDocShell->GetWindow() : nullptr;
rv = editingSession->SetupEditorOnWindow(domWindow);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
nsresult nsDocShellEditorData::GetEditingSession(nsIEditingSession** aResult) { nsresult nsDocShellEditorData::GetEditingSession(nsIEditingSession** aResult) {
EnsureEditingSession(); EnsureEditingSession();

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

@ -24,7 +24,6 @@ class nsDocShellEditorData {
nsresult MakeEditable(bool aWaitForUriLoad); nsresult MakeEditable(bool aWaitForUriLoad);
bool GetEditable(); bool GetEditable();
nsresult CreateEditor();
nsresult GetEditingSession(nsIEditingSession** aResult); nsresult GetEditingSession(nsIEditingSession** aResult);
mozilla::HTMLEditor* GetHTMLEditor() const { return mHTMLEditor; } mozilla::HTMLEditor* GetHTMLEditor() const { return mHTMLEditor; }
nsresult SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor); nsresult SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor);

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

@ -1345,8 +1345,10 @@ nsresult nsTextEditorState::PrepareEditor(const nsAString* aValue) {
// already does the relevant security checks. // already does the relevant security checks.
AutoNoJSAPI nojsapi; AutoNoJSAPI nojsapi;
rv = newTextEditor->Init(*doc, GetRootNode(), mSelCon, editorFlags, RefPtr<Element> rootElement = GetRootNode();
defaultValue); RefPtr<nsTextInputSelectionImpl> selectionController = mSelCon;
rv = newTextEditor->Init(*doc, rootElement, selectionController,
editorFlags, defaultValue);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }

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

@ -72,6 +72,7 @@ class nsEditingSession final : public nsIEditingSession,
// progress load stuff // progress load stuff
nsresult StartDocumentLoad(nsIWebProgress* aWebProgress, nsresult StartDocumentLoad(nsIWebProgress* aWebProgress,
bool isToBeMadeEditable); bool isToBeMadeEditable);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
nsresult EndDocumentLoad(nsIWebProgress* aWebProgress, nsIChannel* aChannel, nsresult EndDocumentLoad(nsIWebProgress* aWebProgress, nsIChannel* aChannel,
nsresult aStatus, bool isToBeMadeEditable); nsresult aStatus, bool isToBeMadeEditable);
nsresult StartPageLoad(nsIChannel* aChannel); nsresult StartPageLoad(nsIChannel* aChannel);

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

@ -47,6 +47,7 @@ interface nsIEditingSession : nsISupports
* (or part of it) editable. * (or part of it) editable.
* @param aInteractive if PR_FALSE turn off scripting and plugins * @param aInteractive if PR_FALSE turn off scripting and plugins
*/ */
[can_run_script]
void makeWindowEditable(in mozIDOMWindowProxy window, void makeWindowEditable(in mozIDOMWindowProxy window,
in string aEditorType, in string aEditorType,
in boolean doAfterUriLoad, in boolean doAfterUriLoad,
@ -70,6 +71,7 @@ interface nsIEditingSession : nsISupports
/** /**
* Setup editor and related support objects * Setup editor and related support objects
*/ */
[can_run_script]
void setupEditorOnWindow(in mozIDOMWindowProxy window); void setupEditorOnWindow(in mozIDOMWindowProxy window);
/** /**

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

@ -495,11 +495,10 @@ already_AddRefed<nsComputedDOMStyle> CSSEditUtils::GetComputedStyle(
// whole node if it is a span and if its only attribute is _moz_dirty // whole node if it is a span and if its only attribute is _moz_dirty
nsresult CSSEditUtils::RemoveCSSInlineStyle(nsINode& aNode, nsAtom* aProperty, nsresult CSSEditUtils::RemoveCSSInlineStyle(nsINode& aNode, nsAtom* aProperty,
const nsAString& aPropertyValue) { const nsAString& aPropertyValue) {
RefPtr<Element> element = aNode.AsElement(); OwningNonNull<Element> element(*aNode.AsElement());
NS_ENSURE_STATE(element);
// remove the property from the style attribute // remove the property from the style attribute
nsresult rv = RemoveCSSProperty(*element, *aProperty, aPropertyValue); nsresult rv = RemoveCSSProperty(element, *aProperty, aPropertyValue);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (!element->IsHTMLElement(nsGkAtoms::span) || if (!element->IsHTMLElement(nsGkAtoms::span) ||
@ -507,7 +506,8 @@ nsresult CSSEditUtils::RemoveCSSInlineStyle(nsINode& aNode, nsAtom* aProperty,
return NS_OK; return NS_OK;
} }
return mHTMLEditor->RemoveContainerWithTransaction(*element); OwningNonNull<HTMLEditor> htmlEditor(*mHTMLEditor);
return htmlEditor->RemoveContainerWithTransaction(element);
} }
// Answers true if the property can be removed by setting a "none" CSS value // Answers true if the property can be removed by setting a "none" CSS value
@ -847,8 +847,9 @@ nsresult CSSEditUtils::RemoveCSSEquivalentToHTMLStyle(
// remove the individual CSS inline styles // remove the individual CSS inline styles
int32_t count = cssPropertyArray.Length(); int32_t count = cssPropertyArray.Length();
for (int32_t index = 0; index < count; index++) { for (int32_t index = 0; index < count; index++) {
nsresult rv = RemoveCSSProperty(*aElement, *cssPropertyArray[index], nsresult rv =
cssValueArray[index], aSuppressTransaction); RemoveCSSProperty(*aElement, MOZ_KnownLive(*cssPropertyArray[index]),
cssValueArray[index], aSuppressTransaction);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
return NS_OK; return NS_OK;

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

@ -100,6 +100,7 @@ class CSSEditUtils final {
const nsAString& aValue, bool aSuppressTxn = false); const nsAString& aValue, bool aSuppressTxn = false);
nsresult SetCSSPropertyPixels(dom::Element& aElement, nsAtom& aProperty, nsresult SetCSSPropertyPixels(dom::Element& aElement, nsAtom& aProperty,
int32_t aIntValue); int32_t aIntValue);
MOZ_CAN_RUN_SCRIPT
nsresult RemoveCSSProperty(dom::Element& aElement, nsAtom& aProperty, nsresult RemoveCSSProperty(dom::Element& aElement, nsAtom& aProperty,
const nsAString& aPropertyValue, const nsAString& aPropertyValue,
bool aSuppressTxn = false); bool aSuppressTxn = false);
@ -127,6 +128,7 @@ class CSSEditUtils final {
* @param aPropertyValue [IN] The value of the property we have to remove * @param aPropertyValue [IN] The value of the property we have to remove
* if the property accepts more than one value. * if the property accepts more than one value.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RemoveCSSInlineStyle(nsINode& aNode, nsAtom* aProperty, nsresult RemoveCSSInlineStyle(nsINode& aNode, nsAtom* aProperty,
const nsAString& aPropertyValue); const nsAString& aPropertyValue);
@ -258,6 +260,7 @@ class CSSEditUtils final {
* @param aSuppressTransaction [IN] A boolean indicating, when true, * @param aSuppressTransaction [IN] A boolean indicating, when true,
* that no transaction should be recorded. * that no transaction should be recorded.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RemoveCSSEquivalentToHTMLStyle(dom::Element* aElement, nsresult RemoveCSSEquivalentToHTMLStyle(dom::Element* aElement,
nsAtom* aHTMLProperty, nsAtom* aHTMLProperty,
nsAtom* aAttribute, nsAtom* aAttribute,

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

@ -2372,13 +2372,15 @@ void EditorBase::CloneAttributesWithTransaction(Element& aDestElement,
nsAutoString value; nsAutoString value;
attr->GetValue(value); attr->GetValue(value);
if (isDestElementInBody) { if (isDestElementInBody) {
SetAttributeOrEquivalent(destElement, attr->NodeInfo()->NameAtom(), value, SetAttributeOrEquivalent(destElement,
false); MOZ_KnownLive(attr->NodeInfo()->NameAtom()),
value, false);
} else { } else {
// The element is not inserted in the document yet, we don't want to put // The element is not inserted in the document yet, we don't want to put
// a transaction on the UndoStack // a transaction on the UndoStack
SetAttributeOrEquivalent(destElement, attr->NodeInfo()->NameAtom(), value, SetAttributeOrEquivalent(destElement,
true); MOZ_KnownLive(attr->NodeInfo()->NameAtom()),
value, true);
} }
} }
} }

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

@ -171,6 +171,7 @@ class EditorBase : public nsIEditor,
* @param aFlags A bitmask of flags for specifying the behavior * @param aFlags A bitmask of flags for specifying the behavior
* of the editor. * of the editor.
*/ */
MOZ_CAN_RUN_SCRIPT
virtual nsresult Init(Document& doc, Element* aRoot, virtual nsresult Init(Document& doc, Element* aRoot,
nsISelectionController* aSelCon, uint32_t aFlags, nsISelectionController* aSelCon, uint32_t aFlags,
const nsAString& aInitialValue); const nsAString& aInitialValue);
@ -885,6 +886,7 @@ class EditorBase : public nsIEditor,
* does nothing during composition, returns NS_OK. * does nothing during composition, returns NS_OK.
* Otherwise, an error code. * Otherwise, an error code.
*/ */
MOZ_CAN_RUN_SCRIPT
virtual nsresult InsertTextWithTransaction( virtual nsresult InsertTextWithTransaction(
Document& aDocument, const nsAString& aStringToInsert, Document& aDocument, const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert, const EditorRawDOMPoint& aPointToInsert,
@ -926,9 +928,9 @@ class EditorBase : public nsIEditor,
* before child node referred by this. * before child node referred by this.
*/ */
template <typename PT, typename CT> template <typename PT, typename CT>
nsresult InsertNodeWithTransaction( MOZ_CAN_RUN_SCRIPT nsresult
nsIContent& aContentToInsert, InsertNodeWithTransaction(nsIContent& aContentToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert); const EditorDOMPointBase<PT, CT>& aPointToInsert);
/** /**
* ReplaceContainerWithTransaction() creates new element whose name is * ReplaceContainerWithTransaction() creates new element whose name is
@ -939,6 +941,7 @@ class EditorBase : public nsIEditor,
* with new element. * with new element.
* @param aTagName The name of new element node. * @param aTagName The name of new element node.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> ReplaceContainerWithTransaction( already_AddRefed<Element> ReplaceContainerWithTransaction(
Element& aOldContainer, nsAtom& aTagName) { Element& aOldContainer, nsAtom& aTagName) {
return ReplaceContainerWithTransactionInternal( return ReplaceContainerWithTransactionInternal(
@ -955,6 +958,7 @@ class EditorBase : public nsIEditor,
* with new element. * with new element.
* @param aTagName The name of new element node. * @param aTagName The name of new element node.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> ReplaceContainerAndCloneAttributesWithTransaction( already_AddRefed<Element> ReplaceContainerAndCloneAttributesWithTransaction(
Element& aOldContainer, nsAtom& aTagName) { Element& aOldContainer, nsAtom& aTagName) {
return ReplaceContainerWithTransactionInternal( return ReplaceContainerWithTransactionInternal(
@ -973,6 +977,7 @@ class EditorBase : public nsIEditor,
* @param aAttribute Attribute name to be set to the new element. * @param aAttribute Attribute name to be set to the new element.
* @param aAttributeValue Attribute value to be set to aAttribute. * @param aAttributeValue Attribute value to be set to aAttribute.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> ReplaceContainerWithTransaction( already_AddRefed<Element> ReplaceContainerWithTransaction(
Element& aOldContainer, nsAtom& aTagName, nsAtom& aAttribute, Element& aOldContainer, nsAtom& aTagName, nsAtom& aAttribute,
const nsAString& aAttributeValue) { const nsAString& aAttributeValue) {
@ -985,6 +990,7 @@ class EditorBase : public nsIEditor,
* aSourceElement to aDestElement after removing all attributes in * aSourceElement to aDestElement after removing all attributes in
* aDestElement. * aDestElement.
*/ */
MOZ_CAN_RUN_SCRIPT
void CloneAttributesWithTransaction(Element& aDestElement, void CloneAttributesWithTransaction(Element& aDestElement,
Element& aSourceElement); Element& aSourceElement);
@ -994,6 +1000,7 @@ class EditorBase : public nsIEditor,
* *
* @param aElement The element to be removed. * @param aElement The element to be removed.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RemoveContainerWithTransaction(Element& aElement); nsresult RemoveContainerWithTransaction(Element& aElement);
/** /**
@ -1010,6 +1017,7 @@ class EditorBase : public nsIEditor,
* was. * was.
* @return The new element. * @return The new element.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> InsertContainerWithTransaction(nsIContent& aContent, already_AddRefed<Element> InsertContainerWithTransaction(nsIContent& aContent,
nsAtom& aTagName) { nsAtom& aTagName) {
return InsertContainerWithTransactionInternal( return InsertContainerWithTransactionInternal(
@ -1033,6 +1041,7 @@ class EditorBase : public nsIEditor,
* @param aAttributeValue Value to be set to aAttribute. * @param aAttributeValue Value to be set to aAttribute.
* @return The new element. * @return The new element.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> InsertContainerWithTransaction( already_AddRefed<Element> InsertContainerWithTransaction(
nsIContent& aContent, nsAtom& aTagName, nsAtom& aAttribute, nsIContent& aContent, nsAtom& aTagName, nsAtom& aAttribute,
const nsAString& aAttributeValue) { const nsAString& aAttributeValue) {
@ -1075,7 +1084,7 @@ class EditorBase : public nsIEditor,
* @param aContent The node to be moved. * @param aContent The node to be moved.
*/ */
template <typename PT, typename CT> template <typename PT, typename CT>
nsresult MoveNodeWithTransaction( MOZ_CAN_RUN_SCRIPT nsresult MoveNodeWithTransaction(
nsIContent& aContent, const EditorDOMPointBase<PT, CT>& aPointToInsert); nsIContent& aContent, const EditorDOMPointBase<PT, CT>& aPointToInsert);
/** /**
@ -1085,6 +1094,7 @@ class EditorBase : public nsIEditor,
* @param aNewContainer The new container which will contain aContent as * @param aNewContainer The new container which will contain aContent as
* its last child. * its last child.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult MoveNodeToEndWithTransaction(nsIContent& aContent, nsresult MoveNodeToEndWithTransaction(nsIContent& aContent,
nsINode& aNewContainer) { nsINode& aNewContainer) {
EditorRawDOMPoint pointToInsert; EditorRawDOMPoint pointToInsert;
@ -1171,6 +1181,7 @@ class EditorBase : public nsIEditor,
nsresult RemoveAttributeWithTransaction(Element& aElement, nsresult RemoveAttributeWithTransaction(Element& aElement,
nsAtom& aAttribute); nsAtom& aAttribute);
MOZ_CAN_RUN_SCRIPT
virtual nsresult RemoveAttributeOrEquivalent(Element* aElement, virtual nsresult RemoveAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute, nsAtom* aAttribute,
bool aSuppressTransaction) = 0; bool aSuppressTransaction) = 0;
@ -1185,6 +1196,7 @@ class EditorBase : public nsIEditor,
nsresult SetAttributeWithTransaction(Element& aElement, nsAtom& aAttribute, nsresult SetAttributeWithTransaction(Element& aElement, nsAtom& aAttribute,
const nsAString& aValue); const nsAString& aValue);
MOZ_CAN_RUN_SCRIPT
virtual nsresult SetAttributeOrEquivalent(Element* aElement, virtual nsresult SetAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,
@ -1281,6 +1293,7 @@ class EditorBase : public nsIEditor,
* @param aCloneAllAttributes If true, all attributes of aOldContainer will * @param aCloneAllAttributes If true, all attributes of aOldContainer will
* be copied to the new element. * be copied to the new element.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> ReplaceContainerWithTransactionInternal( already_AddRefed<Element> ReplaceContainerWithTransactionInternal(
Element& aElement, nsAtom& aTagName, nsAtom& aAttribute, Element& aElement, nsAtom& aTagName, nsAtom& aAttribute,
const nsAString& aAttributeValue, bool aCloneAllAttributes); const nsAString& aAttributeValue, bool aCloneAllAttributes);
@ -1303,6 +1316,7 @@ class EditorBase : public nsIEditor,
* @param aAttributeValue Value to be set to aAttribute. * @param aAttributeValue Value to be set to aAttribute.
* @return The new element. * @return The new element.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> InsertContainerWithTransactionInternal( already_AddRefed<Element> InsertContainerWithTransactionInternal(
nsIContent& aContent, nsAtom& aTagName, nsAtom& aAttribute, nsIContent& aContent, nsAtom& aTagName, nsAtom& aAttribute,
const nsAString& aAttributeValue); const nsAString& aAttributeValue);
@ -1739,6 +1753,7 @@ class EditorBase : public nsIEditor,
* OnEndHandlingTopLevelEditSubAction() is called after * OnEndHandlingTopLevelEditSubAction() is called after
* SetTopLevelEditSubAction() is handled. * SetTopLevelEditSubAction() is handled.
*/ */
MOZ_CAN_RUN_SCRIPT
virtual void OnEndHandlingTopLevelEditSubAction(); virtual void OnEndHandlingTopLevelEditSubAction();
/** /**
@ -2116,9 +2131,10 @@ class EditorBase : public nsIEditor,
} }
} }
MOZ_CAN_RUN_SCRIPT_BOUNDARY
~AutoTopLevelEditSubActionNotifier() { ~AutoTopLevelEditSubActionNotifier() {
if (!mDoNothing) { if (!mDoNothing) {
mEditorBase.OnEndHandlingTopLevelEditSubAction(); MOZ_KnownLive(mEditorBase).OnEndHandlingTopLevelEditSubAction();
} }
} }

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

@ -74,6 +74,7 @@ class EditorEventListener : public nsIDOMEventListener {
void HandleEndComposition(WidgetCompositionEvent* aCompositionEvent); void HandleEndComposition(WidgetCompositionEvent* aCompositionEvent);
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent); virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent);
MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) { return NS_OK; } virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) { return NS_OK; }
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent); virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent);

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

@ -1343,8 +1343,9 @@ nsresult HTMLEditRules::WillInsertText(EditSubAction aEditSubAction,
} }
if (inString->IsEmpty()) { if (inString->IsEmpty()) {
rv = HTMLEditorRef().InsertTextWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*doc, *inString, EditorRawDOMPoint(pointToInsert)); .InsertTextWithTransaction(*doc, *inString,
EditorRawDOMPoint(pointToInsert));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -1444,9 +1445,10 @@ nsresult HTMLEditRules::WillInsertText(EditSubAction aEditSubAction,
"by mutation observer"); "by mutation observer");
} else { } else {
EditorRawDOMPoint pointAfterInsertedString; EditorRawDOMPoint pointAfterInsertedString;
rv = HTMLEditorRef().InsertTextWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*doc, subStr, EditorRawDOMPoint(currentPoint), .InsertTextWithTransaction(*doc, subStr,
&pointAfterInsertedString); EditorRawDOMPoint(currentPoint),
&pointAfterInsertedString);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -1731,8 +1733,8 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
// MakeBasicBlock() creates AutoSelectionRestorer. // MakeBasicBlock() creates AutoSelectionRestorer.
// Therefore, even if it returns NS_OK, editor might have been destroyed // Therefore, even if it returns NS_OK, editor might have been destroyed
// at restoring Selection. // at restoring Selection.
OwningNonNull<nsAtom> separatorTag = ParagraphSeparatorElement(separator); nsresult rv =
nsresult rv = MakeBasicBlock(separatorTag); MakeBasicBlock(MOZ_KnownLive(ParagraphSeparatorElement(separator)));
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED) || if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED) ||
NS_WARN_IF(!CanHandleEditAction())) { NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED); return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
@ -1796,9 +1798,9 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
nsCOMPtr<Element> listItem = IsInListItem(blockParent); nsCOMPtr<Element> listItem = IsInListItem(blockParent);
if (listItem && listItem != host) { if (listItem && listItem != host) {
nsresult rv = nsresult rv = ReturnInListItem(
ReturnInListItem(*listItem, *atStartOfSelection.GetContainer(), *listItem, MOZ_KnownLive(*atStartOfSelection.GetContainer()),
atStartOfSelection.Offset()); atStartOfSelection.Offset());
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) { if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED); return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
} }
@ -1965,8 +1967,10 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
// the style from the line above. // the style from the line above.
EditorDOMPoint atSecondBRElement(maybeSecondBRNode); EditorDOMPoint atSecondBRElement(maybeSecondBRNode);
if (brElement->GetNextSibling() != maybeSecondBRNode) { if (brElement->GetNextSibling() != maybeSecondBRNode) {
nsresult rv = HTMLEditorRef().MoveNodeWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*maybeSecondBRNode->AsContent(), afterBRElement); .MoveNodeWithTransaction(
MOZ_KnownLive(*maybeSecondBRNode->AsContent()),
afterBRElement);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -2588,7 +2592,7 @@ nsresult HTMLEditRules::WillDeleteSelection(
startPoint.GetContainerAsText() && sibling->GetAsText()) { startPoint.GetContainerAsText() && sibling->GetAsText()) {
EditorDOMPoint pt; EditorDOMPoint pt;
nsresult rv = JoinNearestEditableNodesWithTransaction( nsresult rv = JoinNearestEditableNodesWithTransaction(
*sibling, *startPoint.GetContainerAsContent(), &pt); *sibling, MOZ_KnownLive(*startPoint.GetContainerAsContent()), &pt);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -2700,7 +2704,8 @@ nsresult HTMLEditRules::WillDeleteSelection(
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
EditActionResult ret = TryToJoinBlocksWithTransaction( EditActionResult ret = TryToJoinBlocksWithTransaction(
*leftNode->AsContent(), *rightNode->AsContent()); MOZ_KnownLive(*leftNode->AsContent()),
MOZ_KnownLive(*rightNode->AsContent()));
*aHandled |= ret.Handled(); *aHandled |= ret.Handled();
*aCancel |= ret.Canceled(); *aCancel |= ret.Canceled();
if (NS_WARN_IF(ret.Failed())) { if (NS_WARN_IF(ret.Failed())) {
@ -2780,7 +2785,8 @@ nsresult HTMLEditRules::WillDeleteSelection(
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
EditActionResult ret = TryToJoinBlocksWithTransaction( EditActionResult ret = TryToJoinBlocksWithTransaction(
*leftNode->AsContent(), *rightNode->AsContent()); MOZ_KnownLive(*leftNode->AsContent()),
MOZ_KnownLive(*rightNode->AsContent()));
// This should claim that trying to join the block means that // This should claim that trying to join the block means that
// this handles the action because the caller shouldn't do anything // this handles the action because the caller shouldn't do anything
// anymore in this case. // anymore in this case.
@ -3458,8 +3464,8 @@ EditActionResult HTMLEditRules::TryToJoinBlocksWithTransaction(
return EditActionIgnored(NS_ERROR_NULL_POINTER); return EditActionIgnored(NS_ERROR_NULL_POINTER);
} }
ret |= MoveBlock(*previousContent.GetContainerAsElement(), *rightBlock, ret |= MoveBlock(MOZ_KnownLive(*previousContent.GetContainerAsElement()),
previousContent.Offset(), 0); *rightBlock, previousContent.Offset(), 0);
if (NS_WARN_IF(ret.Failed())) { if (NS_WARN_IF(ret.Failed())) {
return ret; return ret;
} }
@ -3509,8 +3515,8 @@ EditActionResult HTMLEditRules::TryToJoinBlocksWithTransaction(
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED); return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
} }
if (pt.IsSet() && mergeLists) { if (pt.IsSet() && mergeLists) {
CreateElementResult convertListTypeResult = CreateElementResult convertListTypeResult = ConvertListType(
ConvertListType(*rightBlock, *existingList, *nsGkAtoms::li); *rightBlock, MOZ_KnownLive(*existingList), *nsGkAtoms::li);
if (NS_WARN_IF(convertListTypeResult.Rv() == NS_ERROR_EDITOR_DESTROYED)) { if (NS_WARN_IF(convertListTypeResult.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED); return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
} }
@ -3559,8 +3565,8 @@ EditActionResult HTMLEditRules::MoveBlock(Element& aLeftBlock,
// get the node to act on // get the node to act on
if (IsBlockNode(arrayOfNodes[i])) { if (IsBlockNode(arrayOfNodes[i])) {
// For block nodes, move their contents only, then delete block. // For block nodes, move their contents only, then delete block.
ret |= ret |= MoveContents(MOZ_KnownLive(*arrayOfNodes[i]->AsElement()),
MoveContents(*arrayOfNodes[i]->AsElement(), aLeftBlock, &aLeftOffset); aLeftBlock, &aLeftOffset);
if (NS_WARN_IF(ret.Failed())) { if (NS_WARN_IF(ret.Failed())) {
return ret; return ret;
} }
@ -3572,8 +3578,8 @@ EditActionResult HTMLEditRules::MoveBlock(Element& aLeftBlock,
ret.MarkAsHandled(); ret.MarkAsHandled();
} else { } else {
// Otherwise move the content as is, checking against the DTD. // Otherwise move the content as is, checking against the DTD.
ret |= MoveNodeSmart(*arrayOfNodes[i]->AsContent(), aLeftBlock, ret |= MoveNodeSmart(MOZ_KnownLive(*arrayOfNodes[i]->AsContent()),
&aLeftOffset); aLeftBlock, &aLeftOffset);
if (NS_WARN_IF(ret.Rv() == NS_ERROR_EDITOR_DESTROYED)) { if (NS_WARN_IF(ret.Rv() == NS_ERROR_EDITOR_DESTROYED)) {
return ret; return ret;
} }
@ -3600,8 +3606,8 @@ EditActionResult HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
if (HTMLEditorRef().CanContain(aDestElement, aNode)) { if (HTMLEditorRef().CanContain(aDestElement, aNode)) {
// If it can, move it there. // If it can, move it there.
if (*aInOutDestOffset == -1) { if (*aInOutDestOffset == -1) {
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().MoveNodeToEndWithTransaction(aNode, aDestElement); .MoveNodeToEndWithTransaction(aNode, aDestElement);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED); return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
} }
@ -3610,8 +3616,8 @@ EditActionResult HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
} }
} else { } else {
EditorRawDOMPoint pointToInsert(&aDestElement, *aInOutDestOffset); EditorRawDOMPoint pointToInsert(&aDestElement, *aInOutDestOffset);
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().MoveNodeWithTransaction(aNode, pointToInsert); .MoveNodeWithTransaction(aNode, pointToInsert);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED); return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
} }
@ -3629,7 +3635,8 @@ EditActionResult HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
// If it can't, move its children (if any), and then delete it. // If it can't, move its children (if any), and then delete it.
EditActionResult ret(NS_OK); EditActionResult ret(NS_OK);
if (aNode.IsElement()) { if (aNode.IsElement()) {
ret = MoveContents(*aNode.AsElement(), aDestElement, aInOutDestOffset); ret = MoveContents(MOZ_KnownLive(*aNode.AsElement()), aDestElement,
aInOutDestOffset);
if (NS_WARN_IF(ret.Failed())) { if (NS_WARN_IF(ret.Failed())) {
return ret; return ret;
} }
@ -3656,7 +3663,7 @@ EditActionResult HTMLEditRules::MoveContents(Element& aElement,
EditActionResult ret(NS_OK); EditActionResult ret(NS_OK);
while (aElement.GetFirstChild()) { while (aElement.GetFirstChild()) {
ret |= MoveNodeSmart(*aElement.GetFirstChild(), aDestElement, ret |= MoveNodeSmart(MOZ_KnownLive(*aElement.GetFirstChild()), aDestElement,
aInOutDestOffset); aInOutDestOffset);
if (NS_WARN_IF(ret.Failed())) { if (NS_WARN_IF(ret.Failed())) {
return ret; return ret;
@ -3964,20 +3971,22 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
// whole list and then RemoveContainerWithTransaction() on the list. // whole list and then RemoveContainerWithTransaction() on the list.
// ConvertListType first: that routine handles converting the list // ConvertListType first: that routine handles converting the list
// item types, if needed. // item types, if needed.
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode, *curList); rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeToEndWithTransaction(*curNode, *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
CreateElementResult convertListTypeResult = CreateElementResult convertListTypeResult = ConvertListType(
ConvertListType(*curNode->AsElement(), aListType, aItemType); MOZ_KnownLive(*curNode->AsElement()), aListType, aItemType);
if (NS_WARN_IF(convertListTypeResult.Failed())) { if (NS_WARN_IF(convertListTypeResult.Failed())) {
return convertListTypeResult.Rv(); return convertListTypeResult.Rv();
} }
rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*convertListTypeResult.GetNewNode()); .RemoveBlockContainerWithTransaction(
MOZ_KnownLive(*convertListTypeResult.GetNewNode()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -3987,8 +3996,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
newBlock = convertListTypeResult.forget(); newBlock = convertListTypeResult.forget();
} else { } else {
// replace list with new list type // replace list with new list type
CreateElementResult convertListTypeResult = CreateElementResult convertListTypeResult = ConvertListType(
ConvertListType(*curNode->AsElement(), aListType, aItemType); MOZ_KnownLive(*curNode->AsElement()), aListType, aItemType);
if (NS_WARN_IF(convertListTypeResult.Failed())) { if (NS_WARN_IF(convertListTypeResult.Failed())) {
return convertListTypeResult.Rv(); return convertListTypeResult.Rv();
} }
@ -4033,7 +4042,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
} }
} }
// move list item to new list // move list item to new list
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode, *curList); rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeToEndWithTransaction(*curNode, *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4042,8 +4052,9 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
} }
// convert list item type if needed // convert list item type if needed
if (!curNode->IsHTMLElement(&aItemType)) { if (!curNode->IsHTMLElement(&aItemType)) {
newBlock = HTMLEditorRef().ReplaceContainerWithTransaction( newBlock = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement(), aItemType); .ReplaceContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()), aItemType);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4058,7 +4069,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
curList = atCurNode.GetContainerAsElement(); curList = atCurNode.GetContainerAsElement();
} else if (atCurNode.GetContainer() != curList) { } else if (atCurNode.GetContainer() != curList) {
// move list item to new list // move list item to new list
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode, *curList); rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeToEndWithTransaction(*curNode, *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4067,8 +4079,9 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
} }
} }
if (!curNode->IsHTMLElement(&aItemType)) { if (!curNode->IsHTMLElement(&aItemType)) {
newBlock = HTMLEditorRef().ReplaceContainerWithTransaction( newBlock = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement(), aItemType); .ReplaceContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()), aItemType);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4109,8 +4122,9 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
prevListItem = nullptr; prevListItem = nullptr;
int32_t j = i + 1; int32_t j = i + 1;
GetInnerContent(*curNode, arrayOfNodes, &j); GetInnerContent(*curNode, arrayOfNodes, &j);
rv = rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().RemoveContainerWithTransaction(*curNode->AsElement()); .RemoveContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4152,8 +4166,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
if (IsInlineNode(curNode) && prevListItem) { if (IsInlineNode(curNode) && prevListItem) {
// this is a continuation of some inline nodes that belong together in // this is a continuation of some inline nodes that belong together in
// the same list item. use prevListItem // the same list item. use prevListItem
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode, rv = MOZ_KnownLive(HTMLEditorRef())
*prevListItem); .MoveNodeToEndWithTransaction(*curNode, *prevListItem);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4163,8 +4177,9 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
} else { } else {
// don't wrap li around a paragraph. instead replace paragraph with li // don't wrap li around a paragraph. instead replace paragraph with li
if (curNode->IsHTMLElement(nsGkAtoms::p)) { if (curNode->IsHTMLElement(nsGkAtoms::p)) {
listItem = HTMLEditorRef().ReplaceContainerWithTransaction( listItem = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement(), aItemType); .ReplaceContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()), aItemType);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4172,8 +4187,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} else { } else {
listItem = HTMLEditorRef().InsertContainerWithTransaction(*curNode, listItem = MOZ_KnownLive(HTMLEditorRef())
aItemType); .InsertContainerWithTransaction(*curNode, aItemType);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4194,7 +4209,8 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
if (listItem) { if (listItem) {
// if we made a new list item, deal with it: tuck the listItem into the // if we made a new list item, deal with it: tuck the listItem into the
// end of the active list // end of the active list
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*listItem, *curList); rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeToEndWithTransaction(*listItem, *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4249,7 +4265,7 @@ nsresult HTMLEditRules::WillRemoveList(bool* aCancel, bool* aHandled) {
// unlist this listitem // unlist this listitem
bool bOutOfList; bool bOutOfList;
do { do {
rv = PopListItem(*curNode->AsContent(), &bOutOfList); rv = PopListItem(MOZ_KnownLive(*curNode->AsContent()), &bOutOfList);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -4257,7 +4273,7 @@ nsresult HTMLEditRules::WillRemoveList(bool* aCancel, bool* aHandled) {
!bOutOfList); // keep popping it out until it's not in a list anymore !bOutOfList); // keep popping it out until it's not in a list anymore
} else if (HTMLEditUtils::IsList(curNode)) { } else if (HTMLEditUtils::IsList(curNode)) {
// node is a list, move list items out // node is a list, move list items out
rv = RemoveListStructure(*curNode->AsElement()); rv = RemoveListStructure(MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -4683,8 +4699,10 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
sibling->NodeInfo()->NameAtom() && sibling->NodeInfo()->NameAtom() &&
atCurNode.GetContainer()->NodeInfo()->NamespaceID() == atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) { sibling->NodeInfo()->NamespaceID()) {
nsresult rv = HTMLEditorRef().MoveNodeWithTransaction( nsresult rv =
*curNode->AsContent(), EditorRawDOMPoint(sibling, 0)); MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
EditorRawDOMPoint(sibling, 0));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4703,8 +4721,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
sibling->NodeInfo()->NameAtom() && sibling->NodeInfo()->NameAtom() &&
atCurNode.GetContainer()->NodeInfo()->NamespaceID() == atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) { sibling->NodeInfo()->NamespaceID()) {
nsresult rv = HTMLEditorRef().MoveNodeToEndWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), *sibling); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *sibling);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4744,8 +4763,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
mNewBlock = curList; mNewBlock = curList;
} }
// tuck the node into the end of the active list // tuck the node into the end of the active list
nsresult rv = HTMLEditorRef().MoveNodeToEndWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), *curList); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4758,7 +4778,8 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
// Not a list item. // Not a list item.
if (IsBlockNode(*curNode)) { if (IsBlockNode(*curNode)) {
nsresult rv = IncreaseMarginToIndent(*curNode->AsElement()); nsresult rv =
IncreaseMarginToIndent(MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) { if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4799,8 +4820,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
} }
// tuck the node into the end of the active blockquote // tuck the node into the end of the active blockquote
nsresult rv = HTMLEditorRef().MoveNodeToEndWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), *curQuote); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curQuote);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4950,8 +4972,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
sibling->NodeInfo()->NameAtom() && sibling->NodeInfo()->NameAtom() &&
atCurNode.GetContainer()->NodeInfo()->NamespaceID() == atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) { sibling->NodeInfo()->NamespaceID()) {
rv = HTMLEditorRef().MoveNodeWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), EditorRawDOMPoint(sibling, 0)); .MoveNodeWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
EditorRawDOMPoint(sibling, 0));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -4970,8 +4993,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
sibling->NodeInfo()->NameAtom() && sibling->NodeInfo()->NameAtom() &&
atCurNode.GetContainer()->NodeInfo()->NamespaceID() == atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) { sibling->NodeInfo()->NamespaceID()) {
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(), rv = MOZ_KnownLive(HTMLEditorRef())
*sibling); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *sibling);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5011,8 +5035,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
mNewBlock = curList; mNewBlock = curList;
} }
// tuck the node into the end of the active list // tuck the node into the end of the active list
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(), rv = MOZ_KnownLive(HTMLEditorRef())
*curList); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5069,7 +5094,8 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
} }
} }
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*listItem, *curList); rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeToEndWithTransaction(*listItem, *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5118,8 +5144,9 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
} }
// tuck the node into the end of the active blockquote // tuck the node into the end of the active blockquote
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(), rv = MOZ_KnownLive(HTMLEditorRef())
*curQuote); .MoveNodeToEndWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
*curQuote);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5275,8 +5302,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
lastBQChild = nullptr; lastBQChild = nullptr;
curBlockQuoteIsIndentedWithCSS = false; curBlockQuoteIsIndentedWithCSS = false;
} }
rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement()); .RemoveBlockContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5298,7 +5326,8 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
RefPtr<nsAtom> unit; RefPtr<nsAtom> unit;
CSSEditUtils::ParseLength(value, &f, getter_AddRefs(unit)); CSSEditUtils::ParseLength(value, &f, getter_AddRefs(unit));
if (f > 0) { if (f > 0) {
nsresult rv = DecreaseMarginToOutdent(*curNode->AsElement()); nsresult rv =
DecreaseMarginToOutdent(MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) { if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5328,7 +5357,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
lastBQChild = nullptr; lastBQChild = nullptr;
curBlockQuoteIsIndentedWithCSS = false; curBlockQuoteIsIndentedWithCSS = false;
} }
rv = PopListItem(*curNode->AsContent()); rv = PopListItem(MOZ_KnownLive(*curNode->AsContent()));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return SplitRangeOffFromNodeResult(rv); return SplitRangeOffFromNodeResult(rv);
} }
@ -5415,8 +5444,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
// Move node out of list // Move node out of list
if (HTMLEditUtils::IsList(curNode)) { if (HTMLEditUtils::IsList(curNode)) {
// Just unwrap this sublist // Just unwrap this sublist
rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement()); .RemoveBlockContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5441,8 +5471,8 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
// list. Be sure to put it after the parent list because this // list. Be sure to put it after the parent list because this
// loop iterates backwards through the parent's list of children. // loop iterates backwards through the parent's list of children.
EditorRawDOMPoint afterCurrentList(curParent, offset + 1); EditorRawDOMPoint afterCurrentList(curParent, offset + 1);
rv = rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().MoveNodeWithTransaction(*child, afterCurrentList); .MoveNodeWithTransaction(*child, afterCurrentList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5462,8 +5492,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
child = curNode->GetLastChild(); child = curNode->GetLastChild();
} }
// Delete the now-empty list // Delete the now-empty list
rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement()); .RemoveBlockContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5522,8 +5553,8 @@ HTMLEditRules::SplitRangeOffFromBlockAndRemoveMiddleContainer(
} }
NS_WARNING_ASSERTION(splitResult.Succeeded(), NS_WARNING_ASSERTION(splitResult.Succeeded(),
"Failed to split the range off from the block element"); "Failed to split the range off from the block element");
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().RemoveBlockContainerWithTransaction(aBlockElement); .RemoveBlockContainerWithTransaction(aBlockElement);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5587,8 +5618,9 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
} }
if (!aIsBlockIndentedWithCSS) { if (!aIsBlockIndentedWithCSS) {
nsresult rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*splitResult.GetMiddleContentAsElement()); .RemoveBlockContainerWithTransaction(MOZ_KnownLive(
*splitResult.GetMiddleContentAsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED); return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5600,8 +5632,8 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentPartOfBlock(
} }
if (splitResult.GetMiddleContentAsElement()) { if (splitResult.GetMiddleContentAsElement()) {
nsresult rv = nsresult rv = DecreaseMarginToOutdent(
DecreaseMarginToOutdent(*splitResult.GetMiddleContentAsElement()); MOZ_KnownLive(*splitResult.GetMiddleContentAsElement()));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return SplitRangeOffFromNodeResult(rv); return SplitRangeOffFromNodeResult(rv);
} }
@ -5622,8 +5654,9 @@ CreateElementResult HTMLEditRules::ConvertListType(Element& aListElement,
Element* element = child->AsElement(); Element* element = child->AsElement();
if (HTMLEditUtils::IsListItem(element) && if (HTMLEditUtils::IsListItem(element) &&
!element->IsHTMLElement(&aNewListItemTag)) { !element->IsHTMLElement(&aNewListItemTag)) {
child = HTMLEditorRef().ReplaceContainerWithTransaction( child = MOZ_KnownLive(HTMLEditorRef())
*element, aNewListItemTag); .ReplaceContainerWithTransaction(MOZ_KnownLive(*element),
aNewListItemTag);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return CreateElementResult(NS_ERROR_EDITOR_DESTROYED); return CreateElementResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5634,8 +5667,8 @@ CreateElementResult HTMLEditRules::ConvertListType(Element& aListElement,
!element->IsHTMLElement(&aNewListTag)) { !element->IsHTMLElement(&aNewListTag)) {
// XXX List elements shouldn't have other list elements as their // XXX List elements shouldn't have other list elements as their
// child. Why do we handle such invalid tree? // child. Why do we handle such invalid tree?
CreateElementResult convertListTypeResult = CreateElementResult convertListTypeResult = ConvertListType(
ConvertListType(*child->AsElement(), aNewListTag, aNewListItemTag); MOZ_KnownLive(*child->AsElement()), aNewListTag, aNewListItemTag);
if (NS_WARN_IF(convertListTypeResult.Failed())) { if (NS_WARN_IF(convertListTypeResult.Failed())) {
return convertListTypeResult; return convertListTypeResult;
} }
@ -5649,8 +5682,9 @@ CreateElementResult HTMLEditRules::ConvertListType(Element& aListElement,
return CreateElementResult(&aListElement); return CreateElementResult(&aListElement);
} }
RefPtr<Element> listElement = HTMLEditorRef().ReplaceContainerWithTransaction( RefPtr<Element> listElement =
aListElement, aNewListTag); MOZ_KnownLive(HTMLEditorRef())
.ReplaceContainerWithTransaction(aListElement, aNewListTag);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return CreateElementResult(NS_ERROR_EDITOR_DESTROYED); return CreateElementResult(NS_ERROR_EDITOR_DESTROYED);
} }
@ -5685,8 +5719,10 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
while (item && node != rootElement) { while (item && node != rootElement) {
// XXX If we redesign ClearStyle(), we can use EditorDOMPoint in this // XXX If we redesign ClearStyle(), we can use EditorDOMPoint in this
// method. // method.
nsresult rv = HTMLEditorRef().ClearStyle(address_of(node), &offset, nsresult rv =
item->tag, item->attr); MOZ_KnownLive(HTMLEditorRef())
.ClearStyle(address_of(node), &offset, MOZ_KnownLive(item->tag),
MOZ_KnownLive(item->attr));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5726,8 +5762,9 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
} }
OwningNonNull<Text> newNode = OwningNonNull<Text> newNode =
EditorBase::CreateTextNode(aDocument, EmptyString()); EditorBase::CreateTextNode(aDocument, EmptyString());
nsresult rv = HTMLEditorRef().InsertNodeWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*newNode, EditorRawDOMPoint(node, offset)); .InsertNodeWithTransaction(
*newNode, EditorRawDOMPoint(node, offset));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5743,7 +5780,8 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
HTMLEditor::FontSize dir = relFontSize > 0 ? HTMLEditor::FontSize::incr HTMLEditor::FontSize dir = relFontSize > 0 ? HTMLEditor::FontSize::incr
: HTMLEditor::FontSize::decr; : HTMLEditor::FontSize::decr;
for (int32_t j = 0; j < DeprecatedAbs(relFontSize); j++) { for (int32_t j = 0; j < DeprecatedAbs(relFontSize); j++) {
rv = HTMLEditorRef().RelativeFontChangeOnTextNode(dir, newNode, 0, -1); rv = MOZ_KnownLive(HTMLEditorRef())
.RelativeFontChangeOnTextNode(dir, newNode, 0, -1);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5754,8 +5792,10 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
} }
while (item) { while (item) {
rv = HTMLEditorRef().SetInlinePropertyOnNode( rv = MOZ_KnownLive(HTMLEditorRef())
*node->AsContent(), *item->tag, item->attr, item->value); .SetInlinePropertyOnNode(MOZ_KnownLive(*node->AsContent()),
MOZ_KnownLive(*item->tag),
MOZ_KnownLive(item->attr), item->value);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -5854,7 +5894,7 @@ nsresult HTMLEditRules::AlignContentsAtSelection(const nsAString& aAlignType) {
// header; in HTML 4, it can directly carry the ALIGN attribute and we // header; in HTML 4, it can directly carry the ALIGN attribute and we
// don't need to make a div! If we are in CSS mode, all the work is done // don't need to make a div! If we are in CSS mode, all the work is done
// in AlignBlock // in AlignBlock
rv = AlignBlock(*node->AsElement(), aAlignType, rv = AlignBlock(MOZ_KnownLive(*node->AsElement()), aAlignType,
ResetAlignOf::OnlyDescendants); ResetAlignOf::OnlyDescendants);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
@ -5993,7 +6033,7 @@ nsresult HTMLEditRules::AlignContentsAtSelection(const nsAString& aAlignType) {
// don't need to nest it, just set the alignment. In CSS, assign the // don't need to nest it, just set the alignment. In CSS, assign the
// corresponding CSS styles in AlignBlock // corresponding CSS styles in AlignBlock
if (HTMLEditUtils::SupportsAlignAttr(*curNode)) { if (HTMLEditUtils::SupportsAlignAttr(*curNode)) {
rv = AlignBlock(*curNode->AsElement(), aAlignType, rv = AlignBlock(MOZ_KnownLive(*curNode->AsElement()), aAlignType,
ResetAlignOf::ElementAndDescendants); ResetAlignOf::ElementAndDescendants);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
@ -6090,8 +6130,9 @@ nsresult HTMLEditRules::AlignContentsAtSelection(const nsAString& aAlignType) {
} }
// Tuck the node into the end of the active div // Tuck the node into the end of the active div
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(), rv = MOZ_KnownLive(HTMLEditorRef())
*curDiv); .MoveNodeToEndWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
*curDiv);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -6139,8 +6180,10 @@ nsresult HTMLEditRules::AlignBlockContents(nsINode& aNode,
if (firstChild == lastChild && firstChild->IsHTMLElement(nsGkAtoms::div)) { if (firstChild == lastChild && firstChild->IsHTMLElement(nsGkAtoms::div)) {
// the cell already has a div containing all of its content: just // the cell already has a div containing all of its content: just
// act on this div. // act on this div.
nsresult rv = HTMLEditorRef().SetAttributeOrEquivalent( nsresult rv =
firstChild->AsElement(), nsGkAtoms::align, aAlignType, false); MOZ_KnownLive(HTMLEditorRef())
.SetAttributeOrEquivalent(MOZ_KnownLive(firstChild->AsElement()),
nsGkAtoms::align, aAlignType, false);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -6162,8 +6205,9 @@ nsresult HTMLEditRules::AlignBlockContents(nsINode& aNode,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// set up the alignment on the div // set up the alignment on the div
nsresult rv = HTMLEditorRef().SetAttributeOrEquivalent( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
divElem, nsGkAtoms::align, aAlignType, false); .SetAttributeOrEquivalent(divElem, nsGkAtoms::align,
aAlignType, false);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -6172,8 +6216,9 @@ nsresult HTMLEditRules::AlignBlockContents(nsINode& aNode,
} }
// tuck the children into the end of the active div // tuck the children into the end of the active div
while (lastChild && (lastChild != divElem)) { while (lastChild && (lastChild != divElem)) {
nsresult rv = HTMLEditorRef().MoveNodeWithTransaction( nsresult rv =
*lastChild, EditorRawDOMPoint(divElem, 0)); MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(*lastChild, EditorRawDOMPoint(divElem, 0));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -7172,7 +7217,8 @@ nsresult HTMLEditRules::GetNodesForOperation(
if (aTouchContent == TouchContent::yes && IsInlineNode(node) && if (aTouchContent == TouchContent::yes && IsInlineNode(node) &&
HTMLEditorRef().IsContainer(node) && !EditorBase::IsTextNode(node)) { HTMLEditorRef().IsContainer(node) && !EditorBase::IsTextNode(node)) {
nsTArray<OwningNonNull<nsINode>> arrayOfInlines; nsTArray<OwningNonNull<nsINode>> arrayOfInlines;
nsresult rv = BustUpInlinesAtBRs(*node->AsContent(), arrayOfInlines); nsresult rv = BustUpInlinesAtBRs(MOZ_KnownLive(*node->AsContent()),
arrayOfInlines);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -7460,8 +7506,9 @@ nsresult HTMLEditRules::BustUpInlinesAtBRs(
// Move break outside of container and also put in node list // Move break outside of container and also put in node list
EditorRawDOMPoint atNextNode(splitNodeResult.GetNextNode()); EditorRawDOMPoint atNextNode(splitNodeResult.GetNextNode());
nsresult rv = HTMLEditorRef().MoveNodeWithTransaction(*brNode->AsContent(), nsresult rv = MOZ_KnownLive(HTMLEditorRef())
atNextNode); .MoveNodeWithTransaction(
MOZ_KnownLive(*brNode->AsContent()), atNextNode);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8069,8 +8116,9 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
"Failed to advance offset after the right list node"); "Failed to advance offset after the right list node");
if (HTMLEditUtils::IsList(atNextSiblingOfLeftList.GetContainer())) { if (HTMLEditUtils::IsList(atNextSiblingOfLeftList.GetContainer())) {
// If so, move item out of this list and into the grandparent list // If so, move item out of this list and into the grandparent list
nsresult rv = HTMLEditorRef().MoveNodeWithTransaction( nsresult rv =
aListItem, atNextSiblingOfLeftList); MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(aListItem, atNextSiblingOfLeftList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8222,9 +8270,10 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
} }
RefPtr<Element> brElement; RefPtr<Element> brElement;
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().CopyLastEditableChildStylesWithTransaction( .CopyLastEditableChildStylesWithTransaction(
*prevItem->AsElement(), aListItem, address_of(brElement)); MOZ_KnownLive(*prevItem->AsElement()), aListItem,
address_of(brElement));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8361,8 +8410,9 @@ nsresult HTMLEditRules::MakeBlockquote(
// note: doesn't matter if we set mNewBlock multiple times. // note: doesn't matter if we set mNewBlock multiple times.
} }
nsresult rv = HTMLEditorRef().MoveNodeToEndWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), *curBlock); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curBlock);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8399,8 +8449,9 @@ nsresult HTMLEditRules::RemoveBlockStyle(
continue; continue;
} }
// Remove current block // Remove current block
nsresult rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsElement()); .RemoveBlockContainerWithTransaction(
MOZ_KnownLive(*curNode->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8524,9 +8575,9 @@ nsresult HTMLEditRules::ApplyBlockStyle(
HTMLEditUtils::IsFormatNode(curNode)) { HTMLEditUtils::IsFormatNode(curNode)) {
// Forget any previous block used for previous inline nodes // Forget any previous block used for previous inline nodes
curBlock = nullptr; curBlock = nullptr;
newBlock = newBlock = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().ReplaceContainerAndCloneAttributesWithTransaction( .ReplaceContainerAndCloneAttributesWithTransaction(
*curNode->AsElement(), aBlockTag); MOZ_KnownLive(*curNode->AsElement()), aBlockTag);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8606,8 +8657,9 @@ nsresult HTMLEditRules::ApplyBlockStyle(
// Remember our new block for postprocessing // Remember our new block for postprocessing
mNewBlock = curBlock; mNewBlock = curBlock;
// Note: doesn't matter if we set mNewBlock multiple times. // Note: doesn't matter if we set mNewBlock multiple times.
nsresult rv = HTMLEditorRef().MoveNodeToEndWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), *curBlock); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curBlock);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8662,8 +8714,9 @@ nsresult HTMLEditRules::ApplyBlockStyle(
// This is a continuation of some inline nodes that belong together in // This is a continuation of some inline nodes that belong together in
// the same block item. Use curBlock. // the same block item. Use curBlock.
nsresult rv = HTMLEditorRef().MoveNodeToEndWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
*curNode->AsContent(), *curBlock); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curBlock);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -8751,8 +8804,9 @@ nsresult HTMLEditRules::JoinNearestEditableNodesWithTransaction(
// left one // left one
if (parent != rightParent) { if (parent != rightParent) {
int32_t parOffset = parent->ComputeIndexOf(&aNodeLeft); int32_t parOffset = parent->ComputeIndexOf(&aNodeLeft);
nsresult rv = HTMLEditorRef().MoveNodeWithTransaction( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
aNodeRight, EditorRawDOMPoint(parent, parOffset)); .MoveNodeWithTransaction(
aNodeRight, EditorRawDOMPoint(parent, parOffset));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -9684,8 +9738,8 @@ nsresult HTMLEditRules::PopListItem(nsIContent& aListItem, bool* aOutOfList) {
"Failed to advance offset to right list node"); "Failed to advance offset to right list node");
} }
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().MoveNodeWithTransaction(*listItem, pointToInsertListItem); .MoveNodeWithTransaction(*listItem, pointToInsertListItem);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -9703,8 +9757,9 @@ nsresult HTMLEditRules::PopListItem(nsIContent& aListItem, bool* aOutOfList) {
// current parent is <dl>, there is same issue. // current parent is <dl>, there is same issue.
if (!HTMLEditUtils::IsList(pointToInsertListItem.GetContainer()) && if (!HTMLEditUtils::IsList(pointToInsertListItem.GetContainer()) &&
HTMLEditUtils::IsListItem(listItem)) { HTMLEditUtils::IsListItem(listItem)) {
rv = HTMLEditorRef().RemoveBlockContainerWithTransaction( rv = MOZ_KnownLive(HTMLEditorRef())
*listItem->AsElement()); .RemoveBlockContainerWithTransaction(
MOZ_KnownLive(*listItem->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -9747,7 +9802,7 @@ nsresult HTMLEditRules::RemoveListStructure(Element& aListElement) {
} }
if (HTMLEditUtils::IsList(child)) { if (HTMLEditUtils::IsList(child)) {
nsresult rv = RemoveListStructure(*child->AsElement()); nsresult rv = RemoveListStructure(MOZ_KnownLive(*child->AsElement()));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -9768,8 +9823,8 @@ nsresult HTMLEditRules::RemoveListStructure(Element& aListElement) {
} }
// Delete the now-empty list // Delete the now-empty list
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().RemoveBlockContainerWithTransaction(aListElement); .RemoveBlockContainerWithTransaction(aListElement);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10155,7 +10210,9 @@ nsresult HTMLEditRules::RemoveAlignment(nsINode& aNode,
} }
// now remove the CENTER container // now remove the CENTER container
rv = HTMLEditorRef().RemoveContainerWithTransaction(*child->AsElement()); rv = MOZ_KnownLive(HTMLEditorRef())
.RemoveContainerWithTransaction(
MOZ_KnownLive(*child->AsElement()));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10177,8 +10234,10 @@ nsresult HTMLEditRules::RemoveAlignment(nsINode& aNode,
} }
if (useCSS) { if (useCSS) {
if (child->IsAnyOfHTMLElements(nsGkAtoms::table, nsGkAtoms::hr)) { if (child->IsAnyOfHTMLElements(nsGkAtoms::table, nsGkAtoms::hr)) {
nsresult rv = HTMLEditorRef().SetAttributeOrEquivalent( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
child->AsElement(), nsGkAtoms::align, aAlignType, false); .SetAttributeOrEquivalent(
MOZ_KnownLive(child->AsElement()),
nsGkAtoms::align, aAlignType, false);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10291,8 +10350,9 @@ nsresult HTMLEditRules::AlignBlock(Element& aElement,
if (HTMLEditorRef().IsCSSEnabled()) { if (HTMLEditorRef().IsCSSEnabled()) {
// Let's use CSS alignment; we use margin-left and margin-right for tables // Let's use CSS alignment; we use margin-left and margin-right for tables
// and text-align for other block-level elements // and text-align for other block-level elements
nsresult rv = HTMLEditorRef().SetAttributeOrEquivalent( nsresult rv = MOZ_KnownLive(HTMLEditorRef())
&aElement, nsGkAtoms::align, aAlignType, false); .SetAttributeOrEquivalent(&aElement, nsGkAtoms::align,
aAlignType, false);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10309,8 +10369,9 @@ nsresult HTMLEditRules::AlignBlock(Element& aElement,
return NS_OK; return NS_OK;
} }
rv = HTMLEditorRef().SetAttributeOrEquivalent(&aElement, nsGkAtoms::align, rv = MOZ_KnownLive(HTMLEditorRef())
aAlignType, false); .SetAttributeOrEquivalent(&aElement, nsGkAtoms::align, aAlignType,
false);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10370,8 +10431,8 @@ nsresult HTMLEditRules::ChangeMarginStart(Element& aElement, bool aIncrease) {
return NS_OK; return NS_OK;
} }
HTMLEditorRef().mCSSEditUtils->RemoveCSSProperty(aElement, marginProperty, HTMLEditorRef().mCSSEditUtils->RemoveCSSProperty(
value); aElement, MOZ_KnownLive(marginProperty), value);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10384,7 +10445,8 @@ nsresult HTMLEditRules::ChangeMarginStart(Element& aElement, bool aIncrease) {
return NS_OK; return NS_OK;
} }
nsresult rv = HTMLEditorRef().RemoveContainerWithTransaction(aElement); nsresult rv =
MOZ_KnownLive(HTMLEditorRef()).RemoveContainerWithTransaction(aElement);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10575,8 +10637,9 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
// new block for postprocessing. // new block for postprocessing.
} }
// Tuck the node into the end of the active list // Tuck the node into the end of the active list
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(), rv = MOZ_KnownLive(HTMLEditorRef())
*curList); .MoveNodeToEndWithTransaction(
MOZ_KnownLive(*curNode->AsContent()), *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10641,7 +10704,8 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*listItem, *curList); rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeToEndWithTransaction(*listItem, *curList);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10681,8 +10745,9 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
} }
// Tuck the node into the end of the active blockquote // Tuck the node into the end of the active blockquote
rv = HTMLEditorRef().MoveNodeToEndWithTransaction(*curNode->AsContent(), rv = MOZ_KnownLive(HTMLEditorRef())
*curPositionedDiv); .MoveNodeToEndWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
*curPositionedDiv);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10701,7 +10766,9 @@ nsresult HTMLEditRules::DidAbsolutePosition() {
if (!mNewBlock) { if (!mNewBlock) {
return NS_OK; return NS_OK;
} }
nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*mNewBlock, true); OwningNonNull<Element> newBlock(*mNewBlock);
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.SetPositionToAbsoluteOrStatic(*newBlock, true);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -10738,8 +10805,8 @@ nsresult HTMLEditRules::WillRemoveAbsolutePosition(bool* aCancel,
{ {
AutoSelectionRestorer restoreSelectionLater(HTMLEditorRef()); AutoSelectionRestorer restoreSelectionLater(HTMLEditorRef());
nsresult rv = nsresult rv = MOZ_KnownLive(HTMLEditorRef())
HTMLEditorRef().SetPositionToAbsoluteOrStatic(*element, false); .SetPositionToAbsoluteOrStatic(*element, false);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }

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

@ -78,15 +78,23 @@ class HTMLEditRules : public TextEditRules {
HTMLEditRules(); HTMLEditRules();
// TextEditRules methods // TextEditRules methods
MOZ_CAN_RUN_SCRIPT
virtual nsresult Init(TextEditor* aTextEditor) override; virtual nsresult Init(TextEditor* aTextEditor) override;
virtual nsresult DetachEditor() override; virtual nsresult DetachEditor() override;
virtual nsresult BeforeEdit(EditSubAction aEditSubAction, virtual nsresult BeforeEdit(EditSubAction aEditSubAction,
nsIEditor::EDirection aDirection) override; nsIEditor::EDirection aDirection) override;
MOZ_CAN_RUN_SCRIPT
virtual nsresult AfterEdit(EditSubAction aEditSubAction, virtual nsresult AfterEdit(EditSubAction aEditSubAction,
nsIEditor::EDirection aDirection) override; nsIEditor::EDirection aDirection) override;
// NOTE: Don't mark WillDoAction() nor DidDoAction() as MOZ_CAN_RUN_SCRIPT
// because they are too generic and doing it makes a lot of public
// editor methods marked as MOZ_CAN_RUN_SCRIPT too, but some of them
// may not causes running script. So, ideal fix must be that we make
// each method callsed by this method public.
MOZ_CAN_RUN_SCRIPT_BOUNDARY MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual nsresult WillDoAction(EditSubActionInfo& aInfo, bool* aCancel, virtual nsresult WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
bool* aHandled) override; bool* aHandled) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual nsresult DidDoAction(EditSubActionInfo& aInfo, virtual nsresult DidDoAction(EditSubActionInfo& aInfo,
nsresult aResult) override; nsresult aResult) override;
virtual bool DocumentIsEmpty() override; virtual bool DocumentIsEmpty() override;
@ -96,9 +104,13 @@ class HTMLEditRules : public TextEditRules {
*/ */
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult DocumentModified(); MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult DocumentModified();
MOZ_CAN_RUN_SCRIPT
nsresult GetListState(bool* aMixed, bool* aOL, bool* aUL, bool* aDL); nsresult GetListState(bool* aMixed, bool* aOL, bool* aUL, bool* aDL);
MOZ_CAN_RUN_SCRIPT
nsresult GetListItemState(bool* aMixed, bool* aLI, bool* aDT, bool* aDD); nsresult GetListItemState(bool* aMixed, bool* aLI, bool* aDT, bool* aDD);
MOZ_CAN_RUN_SCRIPT
nsresult GetAlignment(bool* aMixed, nsIHTMLEditor::EAlignment* aAlign); nsresult GetAlignment(bool* aMixed, nsIHTMLEditor::EAlignment* aAlign);
MOZ_CAN_RUN_SCRIPT
nsresult GetParagraphState(bool* aMixed, nsAString& outFormat); nsresult GetParagraphState(bool* aMixed, nsAString& outFormat);
/** /**
@ -174,6 +186,7 @@ class HTMLEditRules : public TextEditRules {
* @param aMaxLength The maximum string length which the editor * @param aMaxLength The maximum string length which the editor
* allows to set. * allows to set.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult WillInsertText(EditSubAction aEditSubAction, MOZ_MUST_USE nsresult WillInsertText(EditSubAction aEditSubAction,
bool* aCancel, bool* aHandled, bool* aCancel, bool* aHandled,
const nsAString* inString, const nsAString* inString,
@ -210,6 +223,7 @@ class HTMLEditRules : public TextEditRules {
* @param aInsertToBreak The point where new <br> element will be * @param aInsertToBreak The point where new <br> element will be
* inserted before. * inserted before.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult InsertBRElement(const EditorDOMPoint& aInsertToBreak); MOZ_MUST_USE nsresult InsertBRElement(const EditorDOMPoint& aInsertToBreak);
/** /**
@ -315,6 +329,7 @@ class HTMLEditRules : public TextEditRules {
* be joined or it's impossible to join them but it's not * be joined or it's impossible to join them but it's not
* unexpected case, this returns true with this. * unexpected case, this returns true with this.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE EditActionResult MOZ_MUST_USE EditActionResult
TryToJoinBlocksWithTransaction(nsIContent& aLeftNode, nsIContent& aRightNode); TryToJoinBlocksWithTransaction(nsIContent& aLeftNode, nsIContent& aRightNode);
@ -327,6 +342,7 @@ class HTMLEditRules : public TextEditRules {
* @return Sets handled to true if this actually joins the nodes. * @return Sets handled to true if this actually joins the nodes.
* canceled is always false. * canceled is always false.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE EditActionResult MoveBlock(Element& aLeftBlock, MOZ_MUST_USE EditActionResult MoveBlock(Element& aLeftBlock,
Element& aRightBlock, Element& aRightBlock,
int32_t aLeftOffset, int32_t aLeftOffset,
@ -341,6 +357,7 @@ class HTMLEditRules : public TextEditRules {
* the nodes. * the nodes.
* canceled is always false. * canceled is always false.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE EditActionResult MoveNodeSmart(nsIContent& aNode, MOZ_MUST_USE EditActionResult MoveNodeSmart(nsIContent& aNode,
Element& aDestElement, Element& aDestElement,
int32_t* aInOutDestOffset); int32_t* aInOutDestOffset);
@ -354,6 +371,7 @@ class HTMLEditRules : public TextEditRules {
* the nodes. * the nodes.
* canceled is always false. * canceled is always false.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE EditActionResult MoveContents(Element& aElement, MOZ_MUST_USE EditActionResult MoveContents(Element& aElement,
Element& aDestElement, Element& aDestElement,
int32_t* aInOutDestOffset); int32_t* aInOutDestOffset);
@ -455,6 +473,7 @@ class HTMLEditRules : public TextEditRules {
* @param aCancel Returns true if the operation is canceled. * @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled. * @param aHandled Returns true if the edit action is handled.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult WillRemoveAbsolutePosition(bool* aCancel, MOZ_MUST_USE nsresult WillRemoveAbsolutePosition(bool* aCancel,
bool* aHandled); bool* aHandled);
@ -544,6 +563,7 @@ class HTMLEditRules : public TextEditRules {
* @param aTargetElement Returns target element which should be * @param aTargetElement Returns target element which should be
* changed to absolute positioned. * changed to absolute positioned.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult PrepareToMakeElementAbsolutePosition( MOZ_MUST_USE nsresult PrepareToMakeElementAbsolutePosition(
bool* aHandled, RefPtr<Element>* aTargetElement); bool* aHandled, RefPtr<Element>* aTargetElement);
@ -554,6 +574,7 @@ class HTMLEditRules : public TextEditRules {
* WillAbsolutePosition() to absolute positioned. * WillAbsolutePosition() to absolute positioned.
* Therefore, this might cause destroying the HTML editor. * Therefore, this might cause destroying the HTML editor.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult DidAbsolutePosition(); MOZ_MUST_USE nsresult DidAbsolutePosition();
/** /**
@ -564,6 +585,7 @@ class HTMLEditRules : public TextEditRules {
* to aAlignType. * to aAlignType.
* @param aAlignType New value of align attribute of <div>. * @param aAlignType New value of align attribute of <div>.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult AlignInnerBlocks(nsINode& aNode, MOZ_MUST_USE nsresult AlignInnerBlocks(nsINode& aNode,
const nsAString& aAlignType); const nsAString& aAlignType);
@ -578,6 +600,7 @@ class HTMLEditRules : public TextEditRules {
* @param aAlignType New value of align attribute of <div> which * @param aAlignType New value of align attribute of <div> which
* is only child of aNode. * is only child of aNode.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult AlignBlockContents(nsINode& aNode, MOZ_MUST_USE nsresult AlignBlockContents(nsINode& aNode,
const nsAString& aAlignType); const nsAString& aAlignType);
@ -592,6 +615,7 @@ class HTMLEditRules : public TextEditRules {
* @param aAlignType New align attribute value where the contents * @param aAlignType New align attribute value where the contents
* should be aligned to. * should be aligned to.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult AlignContentsAtSelection(const nsAString& aAlignType); MOZ_MUST_USE nsresult AlignContentsAtSelection(const nsAString& aAlignType);
nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray, nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
@ -677,6 +701,7 @@ class HTMLEditRules : public TextEditRules {
* @param aOffset Typically, Selection start offset in the * @param aOffset Typically, Selection start offset in the
* start container, where to insert a break. * start container, where to insert a break.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult ReturnInListItem(Element& aListItem, nsINode& aNode, MOZ_MUST_USE nsresult ReturnInListItem(Element& aListItem, nsINode& aNode,
int32_t aOffset); int32_t aOffset);
@ -684,6 +709,7 @@ class HTMLEditRules : public TextEditRules {
* Called after handling edit action. This may adjust Selection, remove * Called after handling edit action. This may adjust Selection, remove
* unnecessary empty nodes, create <br> elements if needed, etc. * unnecessary empty nodes, create <br> elements if needed, etc.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult AfterEditInner(EditSubAction aEditSubAction, MOZ_MUST_USE nsresult AfterEditInner(EditSubAction aEditSubAction,
nsIEditor::EDirection aDirection); nsIEditor::EDirection aDirection);
@ -693,6 +719,7 @@ class HTMLEditRules : public TextEditRules {
* need to check if the editor is still available even if this returns * need to check if the editor is still available even if this returns
* NS_OK. * NS_OK.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult IndentAroundSelectionWithCSS(); MOZ_MUST_USE nsresult IndentAroundSelectionWithCSS();
/** /**
@ -701,6 +728,7 @@ class HTMLEditRules : public TextEditRules {
* need to check if the editor is still available even if this returns * need to check if the editor is still available even if this returns
* NS_OK. * NS_OK.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult IndentAroundSelectionWithHTML(); MOZ_MUST_USE nsresult IndentAroundSelectionWithHTML();
/** /**
@ -716,6 +744,7 @@ class HTMLEditRules : public TextEditRules {
* The middle content is middle content of last * The middle content is middle content of last
* outdented element. * outdented element.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE SplitRangeOffFromNodeResult OutdentAroundSelection(); MOZ_MUST_USE SplitRangeOffFromNodeResult OutdentAroundSelection();
/** /**
@ -735,6 +764,7 @@ class HTMLEditRules : public TextEditRules {
* The middle content is nullptr since * The middle content is nullptr since
* removing it is the job of this method. * removing it is the job of this method.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE SplitRangeOffFromNodeResult MOZ_MUST_USE SplitRangeOffFromNodeResult
SplitRangeOffFromBlockAndRemoveMiddleContainer(Element& aBlockElement, SplitRangeOffFromBlockAndRemoveMiddleContainer(Element& aBlockElement,
nsIContent& aStartOfRange, nsIContent& aStartOfRange,
@ -776,6 +806,7 @@ class HTMLEditRules : public TextEditRules {
* if aIsBlockIndentedWithCSS is true. * if aIsBlockIndentedWithCSS is true.
* Otherwise, nullptr. * Otherwise, nullptr.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE SplitRangeOffFromNodeResult MOZ_MUST_USE SplitRangeOffFromNodeResult
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent, OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
nsIContent& aEndOutdent, bool aIsBlockIndentedWithCSS); nsIContent& aEndOutdent, bool aIsBlockIndentedWithCSS);
@ -786,6 +817,7 @@ class HTMLEditRules : public TextEditRules {
* need to check if the editor is still available even if this returns * need to check if the editor is still available even if this returns
* NS_OK. * NS_OK.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MakeList(nsAtom& aListType, bool aEntireList, MOZ_MUST_USE nsresult MakeList(nsAtom& aListType, bool aEntireList,
const nsAString* aBulletType, bool* aCancel, const nsAString* aBulletType, bool* aCancel,
nsAtom& aItemType); nsAtom& aItemType);
@ -804,6 +836,7 @@ class HTMLEditRules : public TextEditRules {
* New list element may be aListElement if its * New list element may be aListElement if its
* tag name is same as aNewListTag. * tag name is same as aNewListTag.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE CreateElementResult ConvertListType(Element& aListElement, MOZ_MUST_USE CreateElementResult ConvertListType(Element& aListElement,
nsAtom& aListType, nsAtom& aListType,
nsAtom& aItemType); nsAtom& aItemType);
@ -814,6 +847,7 @@ class HTMLEditRules : public TextEditRules {
* *
* @param aDocument The document of the editor. * @param aDocument The document of the editor.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult CreateStyleForInsertText(dom::Document& aDocument); MOZ_MUST_USE nsresult CreateStyleForInsertText(dom::Document& aDocument);
/** /**
@ -901,6 +935,7 @@ class HTMLEditRules : public TextEditRules {
* transaction. We should rename this to making clearer what this does. * transaction. We should rename this to making clearer what this does.
*/ */
enum class TouchContent { no, yes }; enum class TouchContent { no, yes };
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult GetNodesForOperation( MOZ_MUST_USE nsresult GetNodesForOperation(
nsTArray<RefPtr<nsRange>>& aArrayOfRanges, nsTArray<RefPtr<nsRange>>& aArrayOfRanges,
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes, nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
@ -913,6 +948,7 @@ class HTMLEditRules : public TextEditRules {
* GetNodesFromPoint() constructs a list of nodes from a point that will be * GetNodesFromPoint() constructs a list of nodes from a point that will be
* operated on. * operated on.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MOZ_MUST_USE nsresult
GetNodesFromPoint(const EditorDOMPoint& aPoint, EditSubAction aEditSubAction, GetNodesFromPoint(const EditorDOMPoint& aPoint, EditSubAction aEditSubAction,
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes, nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
@ -922,16 +958,19 @@ class HTMLEditRules : public TextEditRules {
* GetNodesFromSelection() constructs a list of nodes from the selection that * GetNodesFromSelection() constructs a list of nodes from the selection that
* will be operated on. * will be operated on.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MOZ_MUST_USE nsresult
GetNodesFromSelection(EditSubAction aEditSubAction, GetNodesFromSelection(EditSubAction aEditSubAction,
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes, nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
TouchContent aTouchContent); TouchContent aTouchContent);
enum class EntireList { no, yes }; enum class EntireList { no, yes };
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MOZ_MUST_USE nsresult
GetListActionNodes(nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes, GetListActionNodes(nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
EntireList aEntireList, TouchContent aTouchContent); EntireList aEntireList, TouchContent aTouchContent);
void GetDefinitionListItemTypes(Element* aElement, bool* aDT, bool* aDD); void GetDefinitionListItemTypes(Element* aElement, bool* aDT, bool* aDD);
MOZ_CAN_RUN_SCRIPT
nsresult GetParagraphFormatNodes( nsresult GetParagraphFormatNodes(
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes); nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes);
void LookInsideDivBQandList(nsTArray<OwningNonNull<nsINode>>& aNodeArray); void LookInsideDivBQandList(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
@ -959,6 +998,7 @@ class HTMLEditRules : public TextEditRules {
* be set if <br> is at start edge of aNode) and * be set if <br> is at start edge of aNode) and
* aNode itself. * aNode itself.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult BustUpInlinesAtBRs( MOZ_MUST_USE nsresult BustUpInlinesAtBRs(
nsIContent& aNode, nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes); nsIContent& aNode, nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes);
@ -985,6 +1025,7 @@ class HTMLEditRules : public TextEditRules {
* If aNodeArray has a table related element, <li>, <blockquote> or <div>, * If aNodeArray has a table related element, <li>, <blockquote> or <div>,
* it will removed and its contents will be moved to where it was. * it will removed and its contents will be moved to where it was.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray); nsresult RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
/** /**
@ -1003,6 +1044,7 @@ class HTMLEditRules : public TextEditRules {
* @param aNodeArray Must be descendants of a node. * @param aNodeArray Must be descendants of a node.
* @param aBlockTag The element name of new block elements. * @param aBlockTag The element name of new block elements.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult ApplyBlockStyle( MOZ_MUST_USE nsresult ApplyBlockStyle(
nsTArray<OwningNonNull<nsINode>>& aNodeArray, nsAtom& aBlockTag); nsTArray<OwningNonNull<nsINode>>& aNodeArray, nsAtom& aBlockTag);
@ -1015,6 +1057,7 @@ class HTMLEditRules : public TextEditRules {
* @param aNodeArray Nodes which will be moved into created * @param aNodeArray Nodes which will be moved into created
* <blockquote> elements. * <blockquote> elements.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult MOZ_MUST_USE nsresult
MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray); MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
@ -1060,6 +1103,7 @@ class HTMLEditRules : public TextEditRules {
* @param aNewFirstChildOfRightNode * @param aNewFirstChildOfRightNode
* The point at the first child of aRightNode. * The point at the first child of aRightNode.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult JoinNearestEditableNodesWithTransaction( MOZ_MUST_USE nsresult JoinNearestEditableNodesWithTransaction(
nsIContent& aLeftNode, nsIContent& aRightNode, nsIContent& aLeftNode, nsIContent& aRightNode,
EditorDOMPoint* aNewFirstChildOfRightNode); EditorDOMPoint* aNewFirstChildOfRightNode);
@ -1081,6 +1125,7 @@ class HTMLEditRules : public TextEditRules {
* removed (i.e., unwrapped contents of * removed (i.e., unwrapped contents of
* aListItem). Otherwise, false. * aListItem). Otherwise, false.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult PopListItem(nsIContent& aListItem, MOZ_MUST_USE nsresult PopListItem(nsIContent& aListItem,
bool* aOutOfList = nullptr); bool* aOutOfList = nullptr);
@ -1096,6 +1141,7 @@ class HTMLEditRules : public TextEditRules {
* *
* @param aListElement A <ul>, <ol> or <dl> element. * @param aListElement A <ul>, <ol> or <dl> element.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult RemoveListStructure(Element& aListElement); MOZ_MUST_USE nsresult RemoveListStructure(Element& aListElement);
/** /**
@ -1216,6 +1262,7 @@ class HTMLEditRules : public TextEditRules {
* @param aDescendantsOnly true if align information of aNode itself * @param aDescendantsOnly true if align information of aNode itself
* shouldn't be removed. Otherwise, false. * shouldn't be removed. Otherwise, false.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult RemoveAlignment(nsINode& aNode, MOZ_MUST_USE nsresult RemoveAlignment(nsINode& aNode,
const nsAString& aAlignType, const nsAString& aAlignType,
bool aDescendantsOnly); bool aDescendantsOnly);
@ -1245,6 +1292,7 @@ class HTMLEditRules : public TextEditRules {
* descendants or only descendants. * descendants or only descendants.
*/ */
enum class ResetAlignOf { ElementAndDescendants, OnlyDescendants }; enum class ResetAlignOf { ElementAndDescendants, OnlyDescendants };
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult AlignBlock(Element& aElement, MOZ_MUST_USE nsresult AlignBlock(Element& aElement,
const nsAString& aAlignType, const nsAString& aAlignType,
ResetAlignOf aResetAlignOf); ResetAlignOf aResetAlignOf);
@ -1256,6 +1304,7 @@ class HTMLEditRules : public TextEditRules {
* *
* @param aElement The element to be indented. * @param aElement The element to be indented.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult IncreaseMarginToIndent(Element& aElement) { MOZ_MUST_USE nsresult IncreaseMarginToIndent(Element& aElement) {
return ChangeMarginStart(aElement, true); return ChangeMarginStart(aElement, true);
} }
@ -1267,6 +1316,7 @@ class HTMLEditRules : public TextEditRules {
* *
* @param aElement The element to be outdented. * @param aElement The element to be outdented.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult DecreaseMarginToOutdent(Element& aElement) { MOZ_MUST_USE nsresult DecreaseMarginToOutdent(Element& aElement) {
return ChangeMarginStart(aElement, false); return ChangeMarginStart(aElement, false);
} }
@ -1281,6 +1331,7 @@ class HTMLEditRules : public TextEditRules {
* @param aElement The element to be indented or outdented. * @param aElement The element to be indented or outdented.
* @param aIncrease true for indent, false for outdent. * @param aIncrease true for indent, false for outdent.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult ChangeMarginStart(Element& aElement, bool aIncrease); MOZ_MUST_USE nsresult ChangeMarginStart(Element& aElement, bool aIncrease);
/** /**

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

@ -500,7 +500,8 @@ nsresult HTMLEditor::InitRules() {
// instantiate the rules for the html editor // instantiate the rules for the html editor
mRules = new HTMLEditRules(); mRules = new HTMLEditRules();
} }
return mRules->Init(this); RefPtr<TextEditRules> rules(mRules);
return rules->Init(this);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1484,7 +1485,8 @@ HTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString) {
NS_ENSURE_TRUE(child && child->IsElement(), NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(child && child->IsElement(), NS_ERROR_NULL_POINTER);
// Copy all attributes from the div child to current body element // Copy all attributes from the div child to current body element
CloneAttributesWithTransaction(*rootElement, *child->AsElement()); CloneAttributesWithTransaction(*rootElement,
MOZ_KnownLive(*child->AsElement()));
// place selection at first editable content // place selection at first editable content
return MaybeCollapseSelectionAtFirstEditableNode(false); return MaybeCollapseSelectionAtFirstEditableNode(false);
@ -2945,7 +2947,7 @@ HTMLEditor::InsertLinkAroundSelection(Element* aAnchorElement) {
attribute->GetValue(value); attribute->GetValue(value);
rv = SetInlinePropertyInternal(*nsGkAtoms::a, name, value); rv = SetInlinePropertyInternal(*nsGkAtoms::a, MOZ_KnownLive(name), value);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -4572,8 +4574,8 @@ nsresult HTMLEditor::CopyLastEditableChildStylesWithTransaction(
} }
// Otherwise, inserts new parent inline container to the previous inserted // Otherwise, inserts new parent inline container to the previous inserted
// inline container. // inline container.
lastClonedElement = lastClonedElement = InsertContainerWithTransaction(*lastClonedElement,
InsertContainerWithTransaction(*lastClonedElement, *tagName); MOZ_KnownLive(*tagName));
if (NS_WARN_IF(!lastClonedElement)) { if (NS_WARN_IF(!lastClonedElement)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

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

@ -126,6 +126,7 @@ class HTMLEditor final : public TextEditor,
bool GetReturnInParagraphCreatesNewParagraph(); bool GetReturnInParagraphCreatesNewParagraph();
// TextEditor overrides // TextEditor overrides
MOZ_CAN_RUN_SCRIPT
virtual nsresult Init(Document& aDoc, Element* aRoot, virtual nsresult Init(Document& aDoc, Element* aRoot,
nsISelectionController* aSelCon, uint32_t aFlags, nsISelectionController* aSelCon, uint32_t aFlags,
const nsAString& aValue) override; const nsAString& aValue) override;
@ -200,6 +201,7 @@ class HTMLEditor final : public TextEditor,
* this creates an <a> element. * this creates an <a> element.
* @return Newly created element. * @return Newly created element.
*/ */
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Element> CreateElementWithDefaults(const nsAtom& aTagName); already_AddRefed<Element> CreateElementWithDefaults(const nsAtom& aTagName);
/** /**
@ -224,6 +226,7 @@ class HTMLEditor final : public TextEditor,
* @param aY [IN] vertical position of the pointer * @param aY [IN] vertical position of the pointer
* @param aTarget [IN] the element triggering the event * @param aTarget [IN] the element triggering the event
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult OnMouseUp(int32_t aX, int32_t aY, Element* aTarget); nsresult OnMouseUp(int32_t aX, int32_t aY, Element* aTarget);
/** /**
@ -345,6 +348,7 @@ class HTMLEditor final : public TextEditor,
* This automatically removes exclusive style, however, treats all changes * This automatically removes exclusive style, however, treats all changes
* as a transaction. * as a transaction.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult SetInlinePropertyAsAction(nsAtom& aProperty, nsAtom* aAttribute, nsresult SetInlinePropertyAsAction(nsAtom& aProperty, nsAtom* aAttribute,
const nsAString& aValue); const nsAString& aValue);
@ -371,6 +375,7 @@ class HTMLEditor final : public TextEditor,
* nsGkAtoms::bgcolor. Otherwise, set nullptr. * nsGkAtoms::bgcolor. Otherwise, set nullptr.
* Must not use nsGkAtoms::_empty here. * Must not use nsGkAtoms::_empty here.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RemoveInlinePropertyAsAction(nsAtom& aProperty, nsAtom* aAttribute); nsresult RemoveInlinePropertyAsAction(nsAtom& aProperty, nsAtom* aAttribute);
/** /**
@ -455,16 +460,6 @@ class HTMLEditor final : public TextEditor,
*/ */
Element* GetActiveEditingHost() const; Element* GetActiveEditingHost() const;
/** Insert a string as quoted text
* (whose representation is dependant on the editor type),
* replacing the selected text (if any).
*
* @param aQuotedText The actual text to be quoted
* @parem aNodeInserted Return the node which was inserted.
*/
nsresult InsertAsQuotation(const nsAString& aQuotedText,
nsINode** aNodeInserted);
/** /**
* Inserts a plaintext string at the current location, * Inserts a plaintext string at the current location,
* with special processing for lines beginning with ">", * with special processing for lines beginning with ">",
@ -522,6 +517,7 @@ class HTMLEditor final : public TextEditor,
/** /**
* InsertTextWithTransaction() inserts aStringToInsert at aPointToInsert. * InsertTextWithTransaction() inserts aStringToInsert at aPointToInsert.
*/ */
MOZ_CAN_RUN_SCRIPT
virtual nsresult InsertTextWithTransaction( virtual nsresult InsertTextWithTransaction(
Document& aDocument, const nsAString& aStringToInsert, Document& aDocument, const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert, const EditorRawDOMPoint& aPointToInsert,
@ -539,6 +535,7 @@ class HTMLEditor final : public TextEditor,
* placeholder, this is set to the new <br> * placeholder, this is set to the new <br>
* element. * element.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult CopyLastEditableChildStylesWithTransaction( nsresult CopyLastEditableChildStylesWithTransaction(
Element& aPreviousBlock, Element& aNewBlock, Element& aPreviousBlock, Element& aNewBlock,
RefPtr<Element>* aNewBrElement); RefPtr<Element>* aNewBrElement);
@ -551,13 +548,16 @@ class HTMLEditor final : public TextEditor,
* *
* @param aElement Block element to be removed. * @param aElement Block element to be removed.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RemoveBlockContainerWithTransaction(Element& aElement); nsresult RemoveBlockContainerWithTransaction(Element& aElement);
virtual Element* GetEditorRoot() const override; virtual Element* GetEditorRoot() const override;
using EditorBase::IsEditable; using EditorBase::IsEditable;
MOZ_CAN_RUN_SCRIPT
virtual nsresult RemoveAttributeOrEquivalent( virtual nsresult RemoveAttributeOrEquivalent(
Element* aElement, nsAtom* aAttribute, Element* aElement, nsAtom* aAttribute,
bool aSuppressTransaction) override; bool aSuppressTransaction) override;
MOZ_CAN_RUN_SCRIPT
virtual nsresult SetAttributeOrEquivalent(Element* aElement, virtual nsresult SetAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,
@ -667,6 +667,7 @@ class HTMLEditor final : public TextEditor,
* @param aEnabled [IN] true to absolutely position the element, * @param aEnabled [IN] true to absolutely position the element,
* false to put it back in the normal flow * false to put it back in the normal flow
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult SetPositionToAbsoluteOrStatic(Element& aElement, bool aEnabled); nsresult SetPositionToAbsoluteOrStatic(Element& aElement, bool aEnabled);
/** /**
@ -764,10 +765,12 @@ class HTMLEditor final : public TextEditor,
* Helper routines for font size changing. * Helper routines for font size changing.
*/ */
enum class FontSize { incr, decr }; enum class FontSize { incr, decr };
MOZ_CAN_RUN_SCRIPT
nsresult RelativeFontChangeOnTextNode(FontSize aDir, Text& aTextNode, nsresult RelativeFontChangeOnTextNode(FontSize aDir, Text& aTextNode,
int32_t aStartOffset, int32_t aStartOffset,
int32_t aEndOffset); int32_t aEndOffset);
MOZ_CAN_RUN_SCRIPT
nsresult SetInlinePropertyOnNode(nsIContent& aNode, nsAtom& aProperty, nsresult SetInlinePropertyOnNode(nsIContent& aNode, nsAtom& aProperty,
nsAtom* aAttribute, const nsAString& aValue); nsAtom* aAttribute, const nsAString& aValue);
@ -930,10 +933,12 @@ class HTMLEditor final : public TextEditor,
const nsAString* aValue, bool* aFirst, const nsAString* aValue, bool* aFirst,
bool* aAny, bool* aAll, nsAString* outValue); bool* aAny, bool* aAll, nsAString* outValue);
MOZ_CAN_RUN_SCRIPT
nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset, nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
nsAtom* aProperty, nsAtom* aAttribute); nsAtom* aProperty, nsAtom* aAttribute);
nsresult SetPositionToAbsolute(Element& aElement); nsresult SetPositionToAbsolute(Element& aElement);
MOZ_CAN_RUN_SCRIPT
nsresult SetPositionToStatic(Element& aElement); nsresult SetPositionToStatic(Element& aElement);
/** /**
@ -947,6 +952,7 @@ class HTMLEditor final : public TextEditor,
protected: // Called by helper classes. protected: // Called by helper classes.
virtual void OnStartToHandleTopLevelEditSubAction( virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override; EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
MOZ_CAN_RUN_SCRIPT
virtual void OnEndHandlingTopLevelEditSubAction() override; virtual void OnEndHandlingTopLevelEditSubAction() override;
protected: // Shouldn't be used by friend classes protected: // Shouldn't be used by friend classes
@ -1435,6 +1441,7 @@ class HTMLEditor final : public TextEditor,
* text. * text.
* @param aNodeInserted [OUT] The new <blockquote> element. * @param aNodeInserted [OUT] The new <blockquote> element.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult InsertAsCitedQuotationInternal(const nsAString& aQuotedText, nsresult InsertAsCitedQuotationInternal(const nsAString& aQuotedText,
const nsAString& aCitation, const nsAString& aCitation,
bool aInsertHTML, bool aInsertHTML,
@ -1458,7 +1465,7 @@ class HTMLEditor final : public TextEditor,
* Otherwise, the result is not set. * Otherwise, the result is not set.
*/ */
template <typename PT, typename CT> template <typename PT, typename CT>
EditorDOMPoint InsertNodeIntoProperAncestorWithTransaction( MOZ_CAN_RUN_SCRIPT EditorDOMPoint InsertNodeIntoProperAncestorWithTransaction(
nsIContent& aNode, const EditorDOMPointBase<PT, CT>& aPointToInsert, nsIContent& aNode, const EditorDOMPointBase<PT, CT>& aPointToInsert,
SplitAtEdges aSplitAtEdges); SplitAtEdges aSplitAtEdges);
@ -1489,10 +1496,13 @@ class HTMLEditor final : public TextEditor,
*/ */
nsresult IndentOrOutdentAsSubAction(EditSubAction aEditSubAction); nsresult IndentOrOutdentAsSubAction(EditSubAction aEditSubAction);
MOZ_CAN_RUN_SCRIPT
nsresult LoadHTML(const nsAString& aInputString); nsresult LoadHTML(const nsAString& aInputString);
MOZ_CAN_RUN_SCRIPT
nsresult SetInlinePropertyInternal(nsAtom& aProperty, nsAtom* aAttribute, nsresult SetInlinePropertyInternal(nsAtom& aProperty, nsAtom* aAttribute,
const nsAString& aValue); const nsAString& aValue);
MOZ_CAN_RUN_SCRIPT
nsresult RemoveInlinePropertyInternal(nsAtom* aProperty, nsAtom* aAttribute); nsresult RemoveInlinePropertyInternal(nsAtom* aProperty, nsAtom* aAttribute);
/** /**
@ -1502,6 +1512,7 @@ class HTMLEditor final : public TextEditor,
* @param aSourceToInsert HTML source fragment to replace the children * @param aSourceToInsert HTML source fragment to replace the children
* of <head> element. * of <head> element.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult ReplaceHeadContentsWithSourceWithTransaction( nsresult ReplaceHeadContentsWithSourceWithTransaction(
const nsAString& aSourceToInsert); const nsAString& aSourceToInsert);
@ -1630,6 +1641,7 @@ class HTMLEditor final : public TextEditor,
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BlobReader) NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BlobReader)
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(BlobReader) NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(BlobReader)
MOZ_CAN_RUN_SCRIPT
nsresult OnResult(const nsACString& aResult); nsresult OnResult(const nsACString& aResult);
nsresult OnError(const nsAString& aErrorName); nsresult OnError(const nsAString& aErrorName);
@ -1645,6 +1657,7 @@ class HTMLEditor final : public TextEditor,
bool mDoDeleteSelection; bool mDoDeleteSelection;
}; };
MOZ_CAN_RUN_SCRIPT
virtual nsresult InitRules() override; virtual nsresult InitRules() override;
virtual void CreateEventListeners() override; virtual void CreateEventListeners() override;
@ -1743,6 +1756,7 @@ class HTMLEditor final : public TextEditor,
* of course) * of course)
* This doesn't change or use the current selection. * This doesn't change or use the current selection.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult InsertCell(Element* aCell, int32_t aRowSpan, int32_t aColSpan, nsresult InsertCell(Element* aCell, int32_t aRowSpan, int32_t aColSpan,
bool aAfter, bool aIsHeader, Element** aNewCell); bool aAfter, bool aIsHeader, Element** aNewCell);
@ -1845,6 +1859,7 @@ class HTMLEditor final : public TextEditor,
/** /**
* Move all contents from aCellToMerge into aTargetCell (append at end). * Move all contents from aCellToMerge into aTargetCell (append at end).
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult MergeCells(RefPtr<Element> aTargetCell, RefPtr<Element> aCellToMerge, nsresult MergeCells(RefPtr<Element> aTargetCell, RefPtr<Element> aCellToMerge,
bool aDeleteCellToMerge); bool aDeleteCellToMerge);
@ -1902,10 +1917,12 @@ class HTMLEditor final : public TextEditor,
nsresult GetCellSpansAt(Element* aTable, int32_t aRowIndex, int32_t aColIndex, nsresult GetCellSpansAt(Element* aTable, int32_t aRowIndex, int32_t aColIndex,
int32_t& aActualRowSpan, int32_t& aActualColSpan); int32_t& aActualRowSpan, int32_t& aActualColSpan);
MOZ_CAN_RUN_SCRIPT
nsresult SplitCellIntoColumns(Element* aTable, int32_t aRowIndex, nsresult SplitCellIntoColumns(Element* aTable, int32_t aRowIndex,
int32_t aColIndex, int32_t aColSpanLeft, int32_t aColIndex, int32_t aColSpanLeft,
int32_t aColSpanRight, Element** aNewCell); int32_t aColSpanRight, Element** aNewCell);
MOZ_CAN_RUN_SCRIPT
nsresult SplitCellIntoRows(Element* aTable, int32_t aRowIndex, nsresult SplitCellIntoRows(Element* aTable, int32_t aRowIndex,
int32_t aColIndex, int32_t aRowSpanAbove, int32_t aColIndex, int32_t aRowSpanAbove,
int32_t aRowSpanBelow, Element** aNewCell); int32_t aRowSpanBelow, Element** aNewCell);
@ -1930,6 +1947,7 @@ class HTMLEditor final : public TextEditor,
* or <table> element itself. Otherwise, * or <table> element itself. Otherwise,
* this returns NS_OK but does nothing. * this returns NS_OK but does nothing.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult NormalizeTableInternal(Element& aTableOrElementInTable); nsresult NormalizeTableInternal(Element& aTableOrElementInTable);
/** /**
@ -2053,14 +2071,18 @@ class HTMLEditor final : public TextEditor,
/** /**
* Increase/decrease the font size of selection. * Increase/decrease the font size of selection.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult RelativeFontChange(FontSize aDir); nsresult RelativeFontChange(FontSize aDir);
MOZ_CAN_RUN_SCRIPT
nsresult RelativeFontChangeOnNode(int32_t aSizeChange, nsIContent* aNode); nsresult RelativeFontChangeOnNode(int32_t aSizeChange, nsIContent* aNode);
MOZ_CAN_RUN_SCRIPT
nsresult RelativeFontChangeHelper(int32_t aSizeChange, nsINode* aNode); nsresult RelativeFontChangeHelper(int32_t aSizeChange, nsINode* aNode);
/** /**
* Helper routines for inline style. * Helper routines for inline style.
*/ */
MOZ_CAN_RUN_SCRIPT
nsresult SetInlinePropertyOnTextNode(Text& aData, int32_t aStartOffset, nsresult SetInlinePropertyOnTextNode(Text& aData, int32_t aStartOffset,
int32_t aEndOffset, nsAtom& aProperty, int32_t aEndOffset, nsAtom& aProperty,
nsAtom* aAttribute, nsAtom* aAttribute,
@ -2070,6 +2092,7 @@ class HTMLEditor final : public TextEditor,
nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange); nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange);
nsresult SplitStyleAboveRange(nsRange* aRange, nsAtom* aProperty, nsresult SplitStyleAboveRange(nsRange* aRange, nsAtom* aProperty,
nsAtom* aAttribute); nsAtom* aAttribute);
MOZ_CAN_RUN_SCRIPT
nsresult RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty, nsresult RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty,
nsAtom* aAttribute, nsAtom* aAttribute,
const bool aChildrenOnly = false); const bool aChildrenOnly = false);
@ -2080,6 +2103,7 @@ class HTMLEditor final : public TextEditor,
bool IsOnlyAttribute(const Element* aElement, nsAtom* aAttribute); bool IsOnlyAttribute(const Element* aElement, nsAtom* aAttribute);
bool HasStyleOrIdOrClass(Element* aElement); bool HasStyleOrIdOrClass(Element* aElement);
MOZ_CAN_RUN_SCRIPT
nsresult RemoveElementIfNoStyleOrIdOrClass(Element& aElement); nsresult RemoveElementIfNoStyleOrIdOrClass(Element& aElement);
/** /**
@ -2099,7 +2123,7 @@ class HTMLEditor final : public TextEditor,
* aClearStyle should be set to false if you want the paste to be affected by * aClearStyle should be set to false if you want the paste to be affected by
* local style (e.g., for the insertHTML command). * local style (e.g., for the insertHTML command).
*/ */
MOZ_CAN_RUN_SCRIPT_BOUNDARY MOZ_CAN_RUN_SCRIPT
nsresult DoInsertHTMLWithContext( nsresult DoInsertHTMLWithContext(
const nsAString& aInputString, const nsAString& aContextStr, const nsAString& aInputString, const nsAString& aContextStr,
const nsAString& aInfoStr, const nsAString& aFlavor, Document* aSourceDoc, const nsAString& aInfoStr, const nsAString& aFlavor, Document* aSourceDoc,
@ -2226,6 +2250,7 @@ class HTMLEditor final : public TextEditor,
int32_t GetNewResizingWidth(int32_t aX, int32_t aY); int32_t GetNewResizingWidth(int32_t aX, int32_t aY);
int32_t GetNewResizingHeight(int32_t aX, int32_t aY); int32_t GetNewResizingHeight(int32_t aX, int32_t aY);
void HideShadowAndInfo(); void HideShadowAndInfo();
MOZ_CAN_RUN_SCRIPT
void SetFinalSize(int32_t aX, int32_t aY); void SetFinalSize(int32_t aX, int32_t aY);
void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH, void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH,
bool aPreserveRatio); bool aPreserveRatio);
@ -2318,6 +2343,7 @@ class HTMLEditor final : public TextEditor,
bool IsSimpleModifiableNode(nsIContent* aContent, nsAtom* aProperty, bool IsSimpleModifiableNode(nsIContent* aContent, nsAtom* aProperty,
nsAtom* aAttribute, const nsAString* aValue); nsAtom* aAttribute, const nsAString* aValue);
MOZ_CAN_RUN_SCRIPT
nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode, nsAtom& aProperty, nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode, nsAtom& aProperty,
nsAtom* aAttribute, nsAtom* aAttribute,
const nsAString& aValue); const nsAString& aValue);

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

@ -34,8 +34,9 @@ namespace mozilla {
using dom::Element; using dom::Element;
// prototype // prototype
static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsAString& aLocalName); static nsresult
GetListState(HTMLEditor* aHTMLEditor, bool* aMixed, nsAString& aLocalName);
// defines // defines
#define STATE_ENABLED "state_enabled" #define STATE_ENABLED "state_enabled"
@ -84,7 +85,7 @@ StateUpdatingCommandBase::DoCommand(const char* aCommandName,
if (NS_WARN_IF(!htmlEditor)) { if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return ToggleState(htmlEditor); return ToggleState(MOZ_KnownLive(htmlEditor));
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -245,15 +246,16 @@ nsresult StyleUpdatingCommand::ToggleState(HTMLEditor* aHTMLEditor) {
} }
} }
nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*mTagName, nullptr); nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(
MOZ_KnownLive(*mTagName), nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
return NS_OK; return NS_OK;
} }
nsresult rv = nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(MOZ_KnownLive(*mTagName),
aHTMLEditor->SetInlinePropertyAsAction(*mTagName, nullptr, EmptyString()); nullptr, EmptyString());
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -400,7 +402,7 @@ RemoveListCommand::IsCommandEnabled(const char* aCommandName,
bool bMixed; bool bMixed;
nsAutoString localName; nsAutoString localName;
nsresult rv = GetListState(htmlEditor, &bMixed, localName); nsresult rv = GetListState(MOZ_KnownLive(htmlEditor), &bMixed, localName);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
*outCmdEnabled = bMixed || !localName.IsEmpty(); *outCmdEnabled = bMixed || !localName.IsEmpty();
@ -589,7 +591,7 @@ MultiStateCommandBase::DoCommandParams(const char* aCommandName,
params->GetString(STATE_ATTRIBUTE, attribute); params->GetString(STATE_ATTRIBUTE, attribute);
} }
} }
return SetState(htmlEditor, attribute); return SetState(MOZ_KnownLive(htmlEditor), attribute);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -604,7 +606,7 @@ MultiStateCommandBase::GetCommandStateParams(const char* aCommandName,
if (NS_WARN_IF(!htmlEditor)) { if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return GetCurrentState(htmlEditor, aParams); return GetCurrentState(MOZ_KnownLive(htmlEditor), aParams);
} }
ParagraphStateCommand::ParagraphStateCommand() : MultiStateCommandBase() {} ParagraphStateCommand::ParagraphStateCommand() : MultiStateCommandBase() {}
@ -1155,7 +1157,7 @@ RemoveStylesCommand::DoCommand(const char* aCommandName, nsISupports* refCon) {
if (!htmlEditor) { if (!htmlEditor) {
return NS_OK; return NS_OK;
} }
return htmlEditor->RemoveAllInlineProperties(); return MOZ_KnownLive(htmlEditor)->RemoveAllInlineProperties();
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1201,7 +1203,7 @@ IncreaseFontSizeCommand::DoCommand(const char* aCommandName,
if (!htmlEditor) { if (!htmlEditor) {
return NS_OK; return NS_OK;
} }
return htmlEditor->IncreaseFontSize(); return MOZ_KnownLive(htmlEditor)->IncreaseFontSize();
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1247,7 +1249,7 @@ DecreaseFontSizeCommand::DoCommand(const char* aCommandName,
if (!htmlEditor) { if (!htmlEditor) {
return NS_OK; return NS_OK;
} }
return htmlEditor->DecreaseFontSize(); return MOZ_KnownLive(htmlEditor)->DecreaseFontSize();
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1297,7 +1299,7 @@ InsertHTMLCommand::DoCommand(const char* aCommandName, nsISupports* refCon) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsAutoString html; nsAutoString html;
return htmlEditor->InsertHTML(html); return MOZ_KnownLive(htmlEditor)->InsertHTML(html);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1322,7 +1324,7 @@ InsertHTMLCommand::DoCommandParams(const char* aCommandName,
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
return htmlEditor->InsertHTML(html); return MOZ_KnownLive(htmlEditor)->InsertHTML(html);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1373,11 +1375,14 @@ InsertTagCommand::DoCommand(const char* aCmdName, nsISupports* refCon) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
RefPtr<Element> newElement = htmlEditor->CreateElementWithDefaults(*mTagName); RefPtr<Element> newElement =
MOZ_KnownLive(htmlEditor)
->CreateElementWithDefaults(MOZ_KnownLive(*mTagName));
if (NS_WARN_IF(!newElement)) { if (NS_WARN_IF(!newElement)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsresult rv = htmlEditor->InsertElementAtSelection(newElement, true); nsresult rv =
MOZ_KnownLive(htmlEditor)->InsertElementAtSelection(newElement, true);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -1428,7 +1433,9 @@ InsertTagCommand::DoCommandParams(const char* aCommandName,
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
RefPtr<Element> newElement = htmlEditor->CreateElementWithDefaults(*mTagName); RefPtr<Element> newElement =
MOZ_KnownLive(htmlEditor)
->CreateElementWithDefaults(MOZ_KnownLive(*mTagName));
if (NS_WARN_IF(!newElement)) { if (NS_WARN_IF(!newElement)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1441,14 +1448,14 @@ InsertTagCommand::DoCommandParams(const char* aCommandName,
// do actual insertion // do actual insertion
if (mTagName == nsGkAtoms::a) { if (mTagName == nsGkAtoms::a) {
rv = htmlEditor->InsertLinkAroundSelection(newElement); rv = MOZ_KnownLive(htmlEditor)->InsertLinkAroundSelection(newElement);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
return NS_OK; return NS_OK;
} }
rv = htmlEditor->InsertElementAtSelection(newElement, true); rv = MOZ_KnownLive(htmlEditor)->InsertElementAtSelection(newElement, true);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -1472,7 +1479,8 @@ InsertTagCommand::GetCommandStateParams(const char* aCommandName,
/****************************/ /****************************/
static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed, static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed,
nsAString& aLocalName) { nsAString& aLocalName)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
MOZ_ASSERT(aHTMLEditor); MOZ_ASSERT(aHTMLEditor);
MOZ_ASSERT(aMixed); MOZ_ASSERT(aMixed);

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

@ -58,10 +58,12 @@ class StateUpdatingCommandBase : public HTMLEditorCommandBase {
virtual ~StateUpdatingCommandBase(); virtual ~StateUpdatingCommandBase();
// get the current state (on or off) for this style or block format // get the current state (on or off) for this style or block format
virtual nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) = 0; virtual nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) = 0;
// add/remove the style // add/remove the style
MOZ_CAN_RUN_SCRIPT
virtual nsresult ToggleState(HTMLEditor* aHTMLEditor) = 0; virtual nsresult ToggleState(HTMLEditor* aHTMLEditor) = 0;
protected: protected:
@ -76,10 +78,12 @@ class StyleUpdatingCommand final : public StateUpdatingCommandBase {
protected: protected:
// get the current state (on or off) for this style or block format // get the current state (on or off) for this style or block format
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
// add/remove the style // add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(HTMLEditor* aHTMLEditor) final; nsresult ToggleState(HTMLEditor* aHTMLEditor) final;
}; };
@ -103,10 +107,12 @@ class ListCommand final : public StateUpdatingCommandBase {
protected: protected:
// get the current state (on or off) for this style or block format // get the current state (on or off) for this style or block format
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
// add/remove the style // add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(HTMLEditor* aHTMLEditor) final; nsresult ToggleState(HTMLEditor* aHTMLEditor) final;
}; };
@ -116,10 +122,12 @@ class ListItemCommand final : public StateUpdatingCommandBase {
protected: protected:
// get the current state (on or off) for this style or block format // get the current state (on or off) for this style or block format
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
// add/remove the style // add/remove the style
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(HTMLEditor* aHTMLEditor) final; nsresult ToggleState(HTMLEditor* aHTMLEditor) final;
}; };
@ -135,8 +143,10 @@ class MultiStateCommandBase : public HTMLEditorCommandBase {
protected: protected:
virtual ~MultiStateCommandBase(); virtual ~MultiStateCommandBase();
virtual nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) = 0; virtual nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) = 0;
MOZ_CAN_RUN_SCRIPT
virtual nsresult SetState(HTMLEditor* aHTMLEditor, virtual nsresult SetState(HTMLEditor* aHTMLEditor,
const nsString& newState) = 0; const nsString& newState) = 0;
}; };
@ -146,8 +156,10 @@ class ParagraphStateCommand final : public MultiStateCommandBase {
ParagraphStateCommand(); ParagraphStateCommand();
protected: protected:
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -156,8 +168,10 @@ class FontFaceStateCommand final : public MultiStateCommandBase {
FontFaceStateCommand(); FontFaceStateCommand();
protected: protected:
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -166,8 +180,10 @@ class FontSizeStateCommand final : public MultiStateCommandBase {
FontSizeStateCommand(); FontSizeStateCommand();
protected: protected:
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -178,8 +194,10 @@ class HighlightColorStateCommand final : public MultiStateCommandBase {
protected: protected:
NS_IMETHOD IsCommandEnabled(const char* aCommandName, NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon, bool* _retval) final; nsISupports* aCommandRefCon, bool* _retval) final;
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -188,8 +206,10 @@ class FontColorStateCommand final : public MultiStateCommandBase {
FontColorStateCommand(); FontColorStateCommand();
protected: protected:
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -198,8 +218,10 @@ class AlignCommand final : public MultiStateCommandBase {
AlignCommand(); AlignCommand();
protected: protected:
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -208,8 +230,10 @@ class BackgroundColorStateCommand final : public MultiStateCommandBase {
BackgroundColorStateCommand(); BackgroundColorStateCommand();
protected: protected:
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final; nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
}; };
@ -220,8 +244,10 @@ class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
protected: protected:
NS_IMETHOD IsCommandEnabled(const char* aCommandName, NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon, bool* _retval) final; nsISupports* aCommandRefCon, bool* _retval) final;
nsresult GetCurrentState(HTMLEditor* aHTMLEditor, MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
nsICommandParams* aParams) final; nsresult
GetCurrentState(HTMLEditor* aHTMLEditor, nsICommandParams* aParams) final;
MOZ_CAN_RUN_SCRIPT
nsresult ToggleState(HTMLEditor* aHTMLEditor) final; nsresult ToggleState(HTMLEditor* aHTMLEditor) final;
}; };

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

@ -523,7 +523,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
// Try to insert. // Try to insert.
EditorDOMPoint insertedPoint = EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestorWithTransaction( InsertNodeIntoProperAncestorWithTransaction(
*curNode->AsContent(), pointToInsert, MOZ_KnownLive(*curNode->AsContent()), pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer); SplitAtEdges::eDoNotCreateEmptyContainer);
if (insertedPoint.IsSet()) { if (insertedPoint.IsSet()) {
lastInsertNode = curNode->AsContent(); lastInsertNode = curNode->AsContent();
@ -542,7 +542,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
} }
nsCOMPtr<nsINode> oldParent = content->GetParentNode(); nsCOMPtr<nsINode> oldParent = content->GetParentNode();
insertedPoint = InsertNodeIntoProperAncestorWithTransaction( insertedPoint = InsertNodeIntoProperAncestorWithTransaction(
*content->GetParent(), pointToInsert, MOZ_KnownLive(*content->GetParent()), pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer); SplitAtEdges::eDoNotCreateEmptyContainer);
if (insertedPoint.IsSet()) { if (insertedPoint.IsSet()) {
insertedContextParent = oldParent; insertedContextParent = oldParent;
@ -982,9 +982,13 @@ nsresult HTMLEditor::BlobReader::OnResult(const nsACString& aResult) {
} }
AutoPlaceholderBatch treatAsOneTransaction(*mHTMLEditor); AutoPlaceholderBatch treatAsOneTransaction(*mHTMLEditor);
rv = mHTMLEditor->DoInsertHTMLWithContext( RefPtr<Document> sourceDocument(mSourceDoc);
stuffToPaste, EmptyString(), EmptyString(), NS_LITERAL_STRING(kFileMime), EditorDOMPoint pointToInsert(mPointToInsert);
mSourceDoc, mPointToInsert, mDoDeleteSelection, mIsSafe, false); rv = MOZ_KnownLive(mHTMLEditor)
->DoInsertHTMLWithContext(stuffToPaste, EmptyString(), EmptyString(),
NS_LITERAL_STRING(kFileMime),
sourceDocument, pointToInsert,
mDoDeleteSelection, mIsSafe, false);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv); return EditorBase::ToGenericNSResult(rv);
} }
@ -1009,6 +1013,7 @@ class SlurpBlobEventListener final : public nsIDOMEventListener {
explicit SlurpBlobEventListener(HTMLEditor::BlobReader* aListener) explicit SlurpBlobEventListener(HTMLEditor::BlobReader* aListener)
: mListener(aListener) {} : mListener(aListener) {}
MOZ_CAN_RUN_SCRIPT
NS_IMETHOD HandleEvent(Event* aEvent) override; NS_IMETHOD HandleEvent(Event* aEvent) override;
private: private:
@ -1041,16 +1046,17 @@ SlurpBlobEventListener::HandleEvent(Event* aEvent) {
EventMessage message = aEvent->WidgetEventPtr()->mMessage; EventMessage message = aEvent->WidgetEventPtr()->mMessage;
RefPtr<HTMLEditor::BlobReader> listener(mListener);
if (message == eLoad) { if (message == eLoad) {
MOZ_ASSERT(reader->DataFormat() == FileReader::FILE_AS_BINARY); MOZ_ASSERT(reader->DataFormat() == FileReader::FILE_AS_BINARY);
// The original data has been converted from Latin1 to UTF-16, this just // The original data has been converted from Latin1 to UTF-16, this just
// undoes that conversion. // undoes that conversion.
mListener->OnResult(NS_LossyConvertUTF16toASCII(reader->Result())); listener->OnResult(NS_LossyConvertUTF16toASCII(reader->Result()));
} else if (message == eLoadError) { } else if (message == eLoadError) {
nsAutoString errorMessage; nsAutoString errorMessage;
reader->GetError()->GetErrorMessage(errorMessage); reader->GetError()->GetErrorMessage(errorMessage);
mListener->OnError(errorMessage); listener->OnError(errorMessage);
} }
return NS_OK; return NS_OK;
@ -1916,39 +1922,6 @@ nsresult HTMLEditor::InsertTextWithQuotationsInternal(
return rv; return rv;
} }
nsresult HTMLEditor::InsertAsQuotation(const nsAString& aQuotedText,
nsINode** aNodeInserted) {
if (IsPlaintextEditor()) {
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertText);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return NS_ERROR_NOT_INITIALIZED;
}
MOZ_ASSERT(!aQuotedText.IsVoid());
editActionData.SetData(aQuotedText);
AutoPlaceholderBatch treatAsOneTransaction(*this);
nsresult rv = InsertAsPlaintextQuotation(aQuotedText, true, aNodeInserted);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv);
}
return NS_OK;
}
AutoEditActionDataSetter editActionData(*this,
EditAction::eInsertBlockquoteElement);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return NS_ERROR_NOT_INITIALIZED;
}
AutoPlaceholderBatch treatAsOneTransaction(*this);
nsAutoString citation;
nsresult rv = InsertAsCitedQuotationInternal(aQuotedText, citation, false,
aNodeInserted);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv);
}
return NS_OK;
}
// Insert plaintext as a quotation, with cite marks (e.g. "> "). // Insert plaintext as a quotation, with cite marks (e.g. "> ").
// This differs from its corresponding method in TextEditor // This differs from its corresponding method in TextEditor
// in that here, quoted material is enclosed in a <pre> tag // in that here, quoted material is enclosed in a <pre> tag

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

@ -228,7 +228,7 @@ nsresult HTMLEditorEventListener::MouseUp(MouseEvent* aMouseEvent) {
// FYI: We need to notify HTML editor of mouseup even if it's consumed // FYI: We need to notify HTML editor of mouseup even if it's consumed
// because HTML editor always needs to release grabbing resizer. // because HTML editor always needs to release grabbing resizer.
HTMLEditor* htmlEditor = mEditorBase->AsHTMLEditor(); RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
MOZ_ASSERT(htmlEditor); MOZ_ASSERT(htmlEditor);
RefPtr<EventTarget> target = aMouseEvent->GetTarget(); RefPtr<EventTarget> target = aMouseEvent->GetTarget();

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

@ -74,6 +74,7 @@ class HTMLEditorEventListener final : public EditorEventListener {
protected: protected:
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent) override; virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent) override;
MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) override; virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) override;
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent) override; virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent) override;

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

@ -970,24 +970,25 @@ void HTMLEditor::SetFinalSize(int32_t aX, int32_t aY) {
// we want one transaction only from a user's point of view // we want one transaction only from a user's point of view
AutoPlaceholderBatch treatAsOneTransaction(*this); AutoPlaceholderBatch treatAsOneTransaction(*this);
RefPtr<Element> resizedObject(mResizedObject);
if (mResizedObjectIsAbsolutelyPositioned) { if (mResizedObjectIsAbsolutelyPositioned) {
if (setHeight) { if (setHeight) {
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::top, y); mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::top, y);
} }
if (setWidth) { if (setWidth) {
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::left, x); mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::left, x);
} }
} }
if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) { if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) {
if (setWidth && if (setWidth &&
mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) { resizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) {
RemoveAttributeWithTransaction(*mResizedObject, *nsGkAtoms::width); RemoveAttributeWithTransaction(*resizedObject, *nsGkAtoms::width);
} }
if (setHeight && if (setHeight &&
mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::height)) { resizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::height)) {
RemoveAttributeWithTransaction(*mResizedObject, *nsGkAtoms::height); RemoveAttributeWithTransaction(*resizedObject, *nsGkAtoms::height);
} }
if (setWidth) { if (setWidth) {
@ -1005,30 +1006,30 @@ void HTMLEditor::SetFinalSize(int32_t aX, int32_t aY) {
// triggering an immediate reflow; otherwise, we have problems // triggering an immediate reflow; otherwise, we have problems
// with asynchronous reflow // with asynchronous reflow
if (setWidth) { if (setWidth) {
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width, mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
width); width);
} }
if (setHeight) { if (setHeight) {
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height, mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
height); height);
} }
if (setWidth) { if (setWidth) {
nsAutoString w; nsAutoString w;
w.AppendInt(width); w.AppendInt(width);
SetAttributeWithTransaction(*mResizedObject, *nsGkAtoms::width, w); SetAttributeWithTransaction(*resizedObject, *nsGkAtoms::width, w);
} }
if (setHeight) { if (setHeight) {
nsAutoString h; nsAutoString h;
h.AppendInt(height); h.AppendInt(height);
SetAttributeWithTransaction(*mResizedObject, *nsGkAtoms::height, h); SetAttributeWithTransaction(*resizedObject, *nsGkAtoms::height, h);
} }
if (setWidth) { if (setWidth) {
mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::width, mCSSEditUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::width,
EmptyString()); EmptyString());
} }
if (setHeight) { if (setHeight) {
mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::height, mCSSEditUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::height,
EmptyString()); EmptyString());
} }
} }

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

@ -186,8 +186,8 @@ nsresult HTMLEditor::SetInlinePropertyInternal(nsAtom& aProperty,
nsCOMPtr<nsINode> endNode = range->GetEndContainer(); nsCOMPtr<nsINode> endNode = range->GetEndContainer();
if (startNode && startNode == endNode && startNode->GetAsText()) { if (startNode && startNode == endNode && startNode->GetAsText()) {
rv = SetInlinePropertyOnTextNode( rv = SetInlinePropertyOnTextNode(
*startNode->GetAsText(), range->StartOffset(), range->EndOffset(), MOZ_KnownLive(*startNode->GetAsText()), range->StartOffset(),
aProperty, aAttribute, aValue); range->EndOffset(), aProperty, aAttribute, aValue);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -227,8 +227,8 @@ nsresult HTMLEditor::SetInlinePropertyInternal(nsAtom& aProperty,
// subtree iterator works - it will not have reported it). // subtree iterator works - it will not have reported it).
if (startNode && startNode->GetAsText() && IsEditable(startNode)) { if (startNode && startNode->GetAsText() && IsEditable(startNode)) {
rv = SetInlinePropertyOnTextNode( rv = SetInlinePropertyOnTextNode(
*startNode->GetAsText(), range->StartOffset(), startNode->Length(), MOZ_KnownLive(*startNode->GetAsText()), range->StartOffset(),
aProperty, aAttribute, aValue); startNode->Length(), aProperty, aAttribute, aValue);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -246,8 +246,8 @@ nsresult HTMLEditor::SetInlinePropertyInternal(nsAtom& aProperty,
// separately handled (it does if it's a text node, due to how the // separately handled (it does if it's a text node, due to how the
// subtree iterator works - it will not have reported it). // subtree iterator works - it will not have reported it).
if (endNode && endNode->GetAsText() && IsEditable(endNode)) { if (endNode && endNode->GetAsText() && IsEditable(endNode)) {
rv = SetInlinePropertyOnTextNode(*endNode->GetAsText(), 0, rv = SetInlinePropertyOnTextNode(MOZ_KnownLive(*endNode->GetAsText()),
range->EndOffset(), aProperty, 0, range->EndOffset(), aProperty,
aAttribute, aValue); aAttribute, aValue);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
@ -388,7 +388,7 @@ nsresult HTMLEditor::SetInlinePropertyOnTextNode(
if (aAttribute) { if (aAttribute) {
// Look for siblings that are correct type of node // Look for siblings that are correct type of node
nsIContent* sibling = GetPriorHTMLSibling(textNodeForTheRange); nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(textNodeForTheRange);
if (IsSimpleModifiableNode(sibling, &aProperty, aAttribute, &aValue)) { if (IsSimpleModifiableNode(sibling, &aProperty, aAttribute, &aValue)) {
// Previous sib is already right kind of inline node; slide this over // Previous sib is already right kind of inline node; slide this over
return MoveNodeToEndWithTransaction(*textNodeForTheRange, *sibling); return MoveNodeToEndWithTransaction(*textNodeForTheRange, *sibling);
@ -817,7 +817,8 @@ nsresult HTMLEditor::RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty,
return rv; return rv;
} }
} }
nsresult rv = RemoveContainerWithTransaction(*aNode.AsElement()); nsresult rv =
RemoveContainerWithTransaction(MOZ_KnownLive(*aNode.AsElement()));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} else if (aNode.IsElement()) { } else if (aNode.IsElement()) {
// otherwise we just want to eliminate the attribute // otherwise we just want to eliminate the attribute
@ -825,7 +826,8 @@ nsresult HTMLEditor::RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty,
// if this matching attribute is the ONLY one on the node, // if this matching attribute is the ONLY one on the node,
// then remove the whole node. Otherwise just nix the attribute. // then remove the whole node. Otherwise just nix the attribute.
if (IsOnlyAttribute(aNode.AsElement(), aAttribute)) { if (IsOnlyAttribute(aNode.AsElement(), aAttribute)) {
nsresult rv = RemoveContainerWithTransaction(*aNode.AsElement()); nsresult rv =
RemoveContainerWithTransaction(MOZ_KnownLive(*aNode.AsElement()));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -853,10 +855,11 @@ nsresult HTMLEditor::RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty,
// attribute // attribute
// let's remove them // let's remove them
mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle( mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
aNode.AsElement(), aProperty, aAttribute, nullptr, false); MOZ_KnownLive(aNode.AsElement()), aProperty, aAttribute, nullptr,
false);
// remove the node if it is a span or font, if its style attribute is // remove the node if it is a span or font, if its style attribute is
// empty or absent, and if it does not have a class nor an id // empty or absent, and if it does not have a class nor an id
RemoveElementIfNoStyleOrIdOrClass(*aNode.AsElement()); RemoveElementIfNoStyleOrIdOrClass(MOZ_KnownLive(*aNode.AsElement()));
} }
} }
} }
@ -870,7 +873,7 @@ nsresult HTMLEditor::RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty,
aNode.IsHTMLElement(nsGkAtoms::small)) && aNode.IsHTMLElement(nsGkAtoms::small)) &&
aAttribute == nsGkAtoms::size) { aAttribute == nsGkAtoms::size) {
// if we are setting font size, remove any nested bigs and smalls // if we are setting font size, remove any nested bigs and smalls
return RemoveContainerWithTransaction(*aNode.AsElement()); return RemoveContainerWithTransaction(MOZ_KnownLive(*aNode.AsElement()));
} }
return NS_OK; return NS_OK;
} }
@ -1403,7 +1406,7 @@ nsresult HTMLEditor::RemoveInlinePropertyInternal(nsAtom* aProperty,
if (CSSEditUtils::IsCSSInvertible(*aProperty, aAttribute)) { if (CSSEditUtils::IsCSSInvertible(*aProperty, aAttribute)) {
NS_NAMED_LITERAL_STRING(value, "-moz-editor-invert-value"); NS_NAMED_LITERAL_STRING(value, "-moz-editor-invert-value");
SetInlinePropertyOnTextNode( SetInlinePropertyOnTextNode(
*startNode->GetAsText(), range->StartOffset(), MOZ_KnownLive(*startNode->GetAsText()), range->StartOffset(),
range->EndOffset(), *aProperty, aAttribute, value); range->EndOffset(), *aProperty, aAttribute, value);
} }
} }
@ -1550,9 +1553,9 @@ nsresult HTMLEditor::RelativeFontChange(FontSize aDir) {
nsCOMPtr<nsINode> startNode = range->GetStartContainer(); nsCOMPtr<nsINode> startNode = range->GetStartContainer();
nsCOMPtr<nsINode> endNode = range->GetEndContainer(); nsCOMPtr<nsINode> endNode = range->GetEndContainer();
if (startNode == endNode && IsTextNode(startNode)) { if (startNode == endNode && IsTextNode(startNode)) {
rv = RelativeFontChangeOnTextNode(aDir, *startNode->GetAsText(), rv = RelativeFontChangeOnTextNode(
range->StartOffset(), aDir, MOZ_KnownLive(*startNode->GetAsText()), range->StartOffset(),
range->EndOffset()); range->EndOffset());
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -1597,16 +1600,16 @@ nsresult HTMLEditor::RelativeFontChange(FontSize aDir) {
// to be separately handled (they do if they are text nodes, due to how // to be separately handled (they do if they are text nodes, due to how
// the subtree iterator works - it will not have reported them). // the subtree iterator works - it will not have reported them).
if (IsTextNode(startNode) && IsEditable(startNode)) { if (IsTextNode(startNode) && IsEditable(startNode)) {
rv = RelativeFontChangeOnTextNode(aDir, *startNode->GetAsText(), rv = RelativeFontChangeOnTextNode(
range->StartOffset(), aDir, MOZ_KnownLive(*startNode->GetAsText()), range->StartOffset(),
startNode->Length()); startNode->Length());
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
} }
if (IsTextNode(endNode) && IsEditable(endNode)) { if (IsTextNode(endNode) && IsEditable(endNode)) {
rv = RelativeFontChangeOnTextNode(aDir, *endNode->GetAsText(), 0, rv = RelativeFontChangeOnTextNode(
range->EndOffset()); aDir, MOZ_KnownLive(*endNode->GetAsText()), 0, range->EndOffset());
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -1685,8 +1688,8 @@ nsresult HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
} }
// Else reparent the node inside font node with appropriate relative size // Else reparent the node inside font node with appropriate relative size
RefPtr<Element> newElement = RefPtr<Element> newElement = InsertContainerWithTransaction(
InsertContainerWithTransaction(*textNodeForTheRange, *nodeType); *textNodeForTheRange, MOZ_KnownLive(*nodeType));
if (NS_WARN_IF(!newElement)) { if (NS_WARN_IF(!newElement)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1765,7 +1768,7 @@ nsresult HTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange,
nsresult rv = RelativeFontChangeHelper(aSizeChange, aNode); nsresult rv = RelativeFontChangeHelper(aSizeChange, aNode);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// in that case, just remove this node and pull up the children // in that case, just remove this node and pull up the children
return RemoveContainerWithTransaction(*aNode->AsElement()); return RemoveContainerWithTransaction(MOZ_KnownLive(*aNode->AsElement()));
} }
// can it be put inside a "big" or "small"? // can it be put inside a "big" or "small"?
@ -1777,7 +1780,7 @@ nsresult HTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange,
// ok, chuck it in. // ok, chuck it in.
// first look at siblings of aNode for matching bigs or smalls. // first look at siblings of aNode for matching bigs or smalls.
// if we find one, move aNode into it. // if we find one, move aNode into it.
nsIContent* sibling = GetPriorHTMLSibling(aNode); nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(aNode);
if (sibling && sibling->IsHTMLElement(atom)) { if (sibling && sibling->IsHTMLElement(atom)) {
// previous sib is already right kind of inline node; slide this over into // previous sib is already right kind of inline node; slide this over into
// it // it
@ -1792,7 +1795,8 @@ nsresult HTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange,
} }
// else insert it above aNode // else insert it above aNode
RefPtr<Element> newElement = InsertContainerWithTransaction(*aNode, *atom); RefPtr<Element> newElement =
InsertContainerWithTransaction(*aNode, MOZ_KnownLive(*atom));
if (NS_WARN_IF(!newElement)) { if (NS_WARN_IF(!newElement)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

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

@ -2203,8 +2203,8 @@ nsresult HTMLEditor::SplitCellIntoColumns(Element* aTable, int32_t aRowIndex,
// Insert new cell after using the remaining span // Insert new cell after using the remaining span
// and always get the new cell so we can copy the background color; // and always get the new cell so we can copy the background color;
RefPtr<Element> newCellElement; RefPtr<Element> newCellElement;
rv = InsertCell(cellData.mElement, cellData.mEffectiveRowSpan, aColSpanRight, rv = InsertCell(MOZ_KnownLive(cellData.mElement), cellData.mEffectiveRowSpan,
true, false, getter_AddRefs(newCellElement)); aColSpanRight, true, false, getter_AddRefs(newCellElement));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -2374,7 +2374,7 @@ HTMLEditor::SwitchTableCellHeaderType(Element* aSourceCell,
// This creates new node, moves children, copies attributes (true) // This creates new node, moves children, copies attributes (true)
// and manages the selection! // and manages the selection!
RefPtr<Element> newCell = ReplaceContainerAndCloneAttributesWithTransaction( RefPtr<Element> newCell = ReplaceContainerAndCloneAttributesWithTransaction(
*aSourceCell, *newCellName); *aSourceCell, MOZ_KnownLive(*newCellName));
if (NS_WARN_IF(!newCell)) { if (NS_WARN_IF(!newCell)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

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

@ -469,9 +469,10 @@ EditActionResult TextEditRules::WillInsertLineBreak(int32_t aMaxLength) {
// Insert a linefeed character. // Insert a linefeed character.
EditorRawDOMPoint pointAfterInsertedLineBreak; EditorRawDOMPoint pointAfterInsertedLineBreak;
rv = TextEditorRef().InsertTextWithTransaction(*doc, NS_LITERAL_STRING("\n"), rv = MOZ_KnownLive(TextEditorRef())
pointToInsert, .InsertTextWithTransaction(*doc, NS_LITERAL_STRING("\n"),
&pointAfterInsertedLineBreak); pointToInsert,
&pointAfterInsertedLineBreak);
if (NS_WARN_IF(!pointAfterInsertedLineBreak.IsSet())) { if (NS_WARN_IF(!pointAfterInsertedLineBreak.IsSet())) {
return EditActionIgnored(NS_ERROR_FAILURE); return EditActionIgnored(NS_ERROR_FAILURE);
} }
@ -839,8 +840,8 @@ nsresult TextEditRules::WillInsertText(EditSubAction aEditSubAction,
betterInsertionPoint.Set(betterInsertionPoint.GetContainer(), betterInsertionPoint.Set(betterInsertionPoint.GetContainer(),
IMESelectionOffset); IMESelectionOffset);
} }
rv = TextEditorRef().InsertTextWithTransaction(*doc, *outString, rv = MOZ_KnownLive(TextEditorRef())
betterInsertionPoint); .InsertTextWithTransaction(*doc, *outString, betterInsertionPoint);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -854,8 +855,9 @@ nsresult TextEditRules::WillInsertText(EditSubAction aEditSubAction,
AutoTransactionsConserveSelection dontChangeMySelection(TextEditorRef()); AutoTransactionsConserveSelection dontChangeMySelection(TextEditorRef());
EditorRawDOMPoint pointAfterStringInserted; EditorRawDOMPoint pointAfterStringInserted;
rv = TextEditorRef().InsertTextWithTransaction( rv = MOZ_KnownLive(TextEditorRef())
*doc, *outString, atStartOfSelection, &pointAfterStringInserted); .InsertTextWithTransaction(*doc, *outString, atStartOfSelection,
&pointAfterStringInserted);
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -954,8 +956,9 @@ nsresult TextEditRules::WillSetText(bool* aCancel, bool* aHandled,
if (NS_WARN_IF(!newNode)) { if (NS_WARN_IF(!newNode)) {
return NS_OK; return NS_OK;
} }
nsresult rv = TextEditorRef().InsertNodeWithTransaction( nsresult rv = MOZ_KnownLive(TextEditorRef())
*newNode, EditorRawDOMPoint(rootElement, 0)); .InsertNodeWithTransaction(
*newNode, EditorRawDOMPoint(rootElement, 0));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
@ -1515,10 +1518,14 @@ nsresult TextEditRules::CreateBogusNodeIfNeeded() {
// Give it a special attribute. // Give it a special attribute.
newBrElement->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, newBrElement->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
kMOZEditorBogusNodeValue, false); kMOZEditorBogusNodeValue, false);
if (NS_WARN_IF(mBogusNode != newBrElement)) {
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
// Put the node in the document. // Put the node in the document.
nsresult rv = TextEditorRef().InsertNodeWithTransaction( nsresult rv = MOZ_KnownLive(TextEditorRef())
*mBogusNode, EditorRawDOMPoint(rootElement, 0)); .InsertNodeWithTransaction(
*newBrElement, EditorRawDOMPoint(rootElement, 0));
if (NS_WARN_IF(!CanHandleEditAction())) { if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }

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

@ -80,16 +80,24 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
HTMLEditRules* AsHTMLEditRules(); HTMLEditRules* AsHTMLEditRules();
const HTMLEditRules* AsHTMLEditRules() const; const HTMLEditRules* AsHTMLEditRules() const;
MOZ_CAN_RUN_SCRIPT
virtual nsresult Init(TextEditor* aTextEditor); virtual nsresult Init(TextEditor* aTextEditor);
virtual nsresult SetInitialValue(const nsAString& aValue); virtual nsresult SetInitialValue(const nsAString& aValue);
virtual nsresult DetachEditor(); virtual nsresult DetachEditor();
virtual nsresult BeforeEdit(EditSubAction aEditSubAction, virtual nsresult BeforeEdit(EditSubAction aEditSubAction,
nsIEditor::EDirection aDirection); nsIEditor::EDirection aDirection);
MOZ_CAN_RUN_SCRIPT
virtual nsresult AfterEdit(EditSubAction aEditSubAction, virtual nsresult AfterEdit(EditSubAction aEditSubAction,
nsIEditor::EDirection aDirection); nsIEditor::EDirection aDirection);
// NOTE: Don't mark WillDoAction() nor DidDoAction() as MOZ_CAN_RUN_SCRIPT
// because they are too generic and doing it makes a lot of public
// editor methods marked as MOZ_CAN_RUN_SCRIPT too, but some of them
// may not causes running script. So, ideal fix must be that we make
// each method callsed by this method public.
MOZ_CAN_RUN_SCRIPT_BOUNDARY MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual nsresult WillDoAction(EditSubActionInfo& aInfo, bool* aCancel, virtual nsresult WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
bool* aHandled); bool* aHandled);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual nsresult DidDoAction(EditSubActionInfo& aInfo, nsresult aResult); virtual nsresult DidDoAction(EditSubActionInfo& aInfo, nsresult aResult);
/** /**
@ -196,6 +204,7 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* @param aMaxLength The maximum string length which the text editor * @param aMaxLength The maximum string length which the text editor
* allows to set. * allows to set.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult WillSetText(bool* aCancel, bool* aHandled, MOZ_MUST_USE nsresult WillSetText(bool* aCancel, bool* aHandled,
const nsAString* inString, const nsAString* inString,
int32_t aMaxLength); int32_t aMaxLength);
@ -280,6 +289,7 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
/** /**
* Creates a bogus <br> node if the root element has no editable content. * Creates a bogus <br> node if the root element has no editable content.
*/ */
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded(); MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
/** /**

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

@ -76,7 +76,7 @@ AutoEditInitRulesTrigger::AutoEditInitRulesTrigger(TextEditor* aTextEditor,
AutoEditInitRulesTrigger::~AutoEditInitRulesTrigger() { AutoEditInitRulesTrigger::~AutoEditInitRulesTrigger() {
if (mTextEditor) { if (mTextEditor) {
mResult = mTextEditor->EndEditorInit(); mResult = MOZ_KnownLive(mTextEditor)->EndEditorInit();
} }
} }

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

@ -29,11 +29,12 @@ class TextEditUtils final {
*/ */
class AutoEditInitRulesTrigger final { class AutoEditInitRulesTrigger final {
private: private:
TextEditor* mTextEditor; RefPtr<TextEditor> mTextEditor;
nsresult& mResult; nsresult& mResult;
public: public:
AutoEditInitRulesTrigger(TextEditor* aTextEditor, nsresult& aResult); AutoEditInitRulesTrigger(TextEditor* aTextEditor, nsresult& aResult);
MOZ_CAN_RUN_SCRIPT
~AutoEditInitRulesTrigger(); ~AutoEditInitRulesTrigger();
}; };

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

@ -321,7 +321,8 @@ nsresult TextEditor::InitRules() {
// instantiate the rules for this text editor // instantiate the rules for this text editor
mRules = new TextEditRules(); mRules = new TextEditRules();
} }
return mRules->Init(this); RefPtr<TextEditRules> textEditRules(mRules);
return textEditRules->Init(this);
} }
nsresult TextEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) { nsresult TextEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {

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

@ -87,6 +87,7 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
virtual bool CanPasteTransferable(nsITransferable* aTransferable); virtual bool CanPasteTransferable(nsITransferable* aTransferable);
// Overrides of EditorBase // Overrides of EditorBase
MOZ_CAN_RUN_SCRIPT
virtual nsresult Init(Document& aDoc, Element* aRoot, virtual nsresult Init(Document& aDoc, Element* aRoot,
nsISelectionController* aSelCon, uint32_t aFlags, nsISelectionController* aSelCon, uint32_t aFlags,
const nsAString& aValue) override; const nsAString& aValue) override;
@ -266,9 +267,11 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
****************************************************************************/ ****************************************************************************/
// Overrides of EditorBase // Overrides of EditorBase
MOZ_CAN_RUN_SCRIPT
virtual nsresult RemoveAttributeOrEquivalent( virtual nsresult RemoveAttributeOrEquivalent(
Element* aElement, nsAtom* aAttribute, Element* aElement, nsAtom* aAttribute,
bool aSuppressTransaction) override; bool aSuppressTransaction) override;
MOZ_CAN_RUN_SCRIPT
virtual nsresult SetAttributeOrEquivalent(Element* aElement, virtual nsresult SetAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,
@ -363,9 +366,11 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
protected: // Called by helper classes. protected: // Called by helper classes.
virtual void OnStartToHandleTopLevelEditSubAction( virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override; EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
MOZ_CAN_RUN_SCRIPT
virtual void OnEndHandlingTopLevelEditSubAction() override; virtual void OnEndHandlingTopLevelEditSubAction() override;
void BeginEditorInit(); void BeginEditorInit();
MOZ_CAN_RUN_SCRIPT
nsresult EndEditorInit(); nsresult EndEditorInit();
protected: // Shouldn't be used by friend classes protected: // Shouldn't be used by friend classes
@ -437,6 +442,7 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
*/ */
bool IsSafeToInsertData(Document* aSourceDoc); bool IsSafeToInsertData(Document* aSourceDoc);
MOZ_CAN_RUN_SCRIPT
virtual nsresult InitRules(); virtual nsresult InitRules();
/** /**

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

@ -252,7 +252,8 @@ template <typename PT, typename CT>
nsresult WSRunObject::InsertText( nsresult WSRunObject::InsertText(
Document& aDocument, const nsAString& aStringToInsert, Document& aDocument, const nsAString& aStringToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert, const EditorDOMPointBase<PT, CT>& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString) { EditorRawDOMPoint* aPointAfterInsertedString)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
// MOOSE: for now, we always assume non-PRE formatting. Fix this later. // MOOSE: for now, we always assume non-PRE formatting. Fix this later.
// meanwhile, the pre case is handled in WillInsertText in // meanwhile, the pre case is handled in WillInsertText in
// HTMLEditRules.cpp // HTMLEditRules.cpp
@ -381,8 +382,10 @@ nsresult WSRunObject::InsertText(
} }
// Ready, aim, fire! // Ready, aim, fire!
nsresult rv = mHTMLEditor->InsertTextWithTransaction( nsresult rv =
aDocument, theString, pointToInsert, aPointAfterInsertedString); MOZ_KnownLive(mHTMLEditor)
->InsertTextWithTransaction(aDocument, theString, pointToInsert,
aPointAfterInsertedString);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_OK; return NS_OK;
} }

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

@ -236,10 +236,10 @@ class MOZ_STACK_CLASS WSRunObject final {
* Otherwise, an error code. * Otherwise, an error code.
*/ */
template <typename PT, typename CT> template <typename PT, typename CT>
nsresult InsertText(dom::Document& aDocument, MOZ_CAN_RUN_SCRIPT nsresult
const nsAString& aStringToInsert, InsertText(dom::Document& aDocument, const nsAString& aStringToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert, const EditorDOMPointBase<PT, CT>& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString = nullptr); EditorRawDOMPoint* aPointAfterInsertedString = nullptr);
// DeleteWSBackward deletes a single visible piece of ws before the ws // DeleteWSBackward deletes a single visible piece of ws before the ws
// point (the point to create the wsRunObject, passed to its constructor). // point (the point to create the wsRunObject, passed to its constructor).

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

@ -52,10 +52,12 @@ interface nsIEditor : nsISupports
readonly attribute Selection selection; readonly attribute Selection selection;
[can_run_script]
void setAttributeOrEquivalent(in Element element, void setAttributeOrEquivalent(in Element element,
in AString sourceAttrName, in AString sourceAttrName,
in AString sourceAttrValue, in AString sourceAttrValue,
in boolean aSuppressTransaction); in boolean aSuppressTransaction);
[can_run_script]
void removeAttributeOrEquivalent(in Element element, void removeAttributeOrEquivalent(in Element element,
in AString sourceAttrName, in AString sourceAttrName,
in boolean aSuppressTransaction); in boolean aSuppressTransaction);
@ -386,6 +388,7 @@ interface nsIEditor : nsISupports
* @param aDestNode the destination element to operate on * @param aDestNode the destination element to operate on
* @param aSourceNode the source element to copy attributes from * @param aSourceNode the source element to copy attributes from
*/ */
[can_run_script]
void cloneAttributes(in Element aDestElement, in Element aSourceElement); void cloneAttributes(in Element aDestElement, in Element aSourceElement);
/** /**
@ -398,6 +401,7 @@ interface nsIEditor : nsISupports
* 0=first child, 1=second child, etc. * 0=first child, 1=second child, etc.
* any number > number of current children = last child * any number > number of current children = last child
*/ */
[can_run_script]
void insertNode(in Node node, void insertNode(in Node node,
in Node parent, in Node parent,
in long aPosition); in long aPosition);

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

@ -22,6 +22,7 @@ interface nsIEditorMailSupport : nsISupports
* @param aInsertHTML Insert as html? (vs plaintext) * @param aInsertHTML Insert as html? (vs plaintext)
* @return The node which was inserted * @return The node which was inserted
*/ */
[can_run_script]
Node insertAsCitedQuotation(in AString aQuotedText, Node insertAsCitedQuotation(in AString aQuotedText,
in AString aCitation, in AString aCitation,
in boolean aInsertHTML); in boolean aInsertHTML);

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

@ -42,6 +42,7 @@ interface nsIHTMLEditor : nsISupports
* Example: aProperty="font", aAttribute="color", * Example: aProperty="font", aAttribute="color",
* aValue="0x00FFFF" * aValue="0x00FFFF"
*/ */
[can_run_script]
void setInlineProperty(in AString aProperty, void setInlineProperty(in AString aProperty,
in AString aAttribute, in AString aAttribute,
in AString aValue); in AString aValue);
@ -84,6 +85,7 @@ interface nsIHTMLEditor : nsISupports
* removeAllInlineProperties() deletes all the inline properties from all * removeAllInlineProperties() deletes all the inline properties from all
* text in the current selection. * text in the current selection.
*/ */
[can_run_script]
void removeAllInlineProperties(); void removeAllInlineProperties();
@ -100,6 +102,7 @@ interface nsIHTMLEditor : nsISupports
* @param aAttribute If aProperty is "font", aAttribute should be "face", * @param aAttribute If aProperty is "font", aAttribute should be "face",
* "size", "color" or "bgcolor". * "size", "color" or "bgcolor".
*/ */
[can_run_script]
void removeInlineProperty(in AString aProperty, in AString aAttribute); void removeInlineProperty(in AString aProperty, in AString aAttribute);
/** /**
@ -107,6 +110,7 @@ interface nsIHTMLEditor : nsISupports
* All existing text is scanned for existing <FONT SIZE> attributes * All existing text is scanned for existing <FONT SIZE> attributes
* so they will be incremented instead of inserting new <FONT> tag * so they will be incremented instead of inserting new <FONT> tag
*/ */
[can_run_script]
void increaseFontSize(); void increaseFontSize();
/** /**
@ -114,6 +118,7 @@ interface nsIHTMLEditor : nsISupports
* All existing text is scanned for existing <FONT SIZE> attributes * All existing text is scanned for existing <FONT SIZE> attributes
* so they will be decreased instead of inserting new <FONT> tag * so they will be decreased instead of inserting new <FONT> tag
*/ */
[can_run_script]
void decreaseFontSize(); void decreaseFontSize();
/* ------------ HTML content methods -------------- */ /* ------------ HTML content methods -------------- */
@ -131,6 +136,7 @@ interface nsIHTMLEditor : nsISupports
* *
* @param aInputString the string to be inserted * @param aInputString the string to be inserted
*/ */
[can_run_script]
void insertHTML(in AString aInputString); void insertHTML(in AString aInputString);
@ -162,6 +168,7 @@ interface nsIHTMLEditor : nsISupports
* after the end of the selection for all element except * after the end of the selection for all element except
* Named Anchors, which insert before the selection * Named Anchors, which insert before the selection
*/ */
[can_run_script]
void insertElementAtSelection(in Element aElement, void insertElementAtSelection(in Element aElement,
in boolean aDeleteSelection); in boolean aDeleteSelection);
@ -212,6 +219,7 @@ interface nsIHTMLEditor : nsISupports
* @param aMixed True if there is more than one format * @param aMixed True if there is more than one format
* @return Name of block tag. "" is returned for none. * @return Name of block tag. "" is returned for none.
*/ */
[can_run_script]
AString getParagraphState(out boolean aMixed); AString getParagraphState(out boolean aMixed);
/** /**
@ -245,6 +253,7 @@ interface nsIHTMLEditor : nsISupports
* @param aUL true if an "ul" list is selected. * @param aUL true if an "ul" list is selected.
* @param aDL true if a "dl" list is selected. * @param aDL true if a "dl" list is selected.
*/ */
[can_run_script]
void getListState(out boolean aMixed, out boolean aOL, out boolean aUL, void getListState(out boolean aMixed, out boolean aOL, out boolean aUL,
out boolean aDL); out boolean aDL);
@ -256,6 +265,7 @@ interface nsIHTMLEditor : nsISupports
* @param aDT true if "dt" list items are selected. * @param aDT true if "dt" list items are selected.
* @param aDD true if "dd" list items are selected. * @param aDD true if "dd" list items are selected.
*/ */
[can_run_script]
void getListItemState(out boolean aMixed, out boolean aLI, void getListItemState(out boolean aMixed, out boolean aLI,
out boolean aDT, out boolean aDD); out boolean aDT, out boolean aDD);
@ -266,6 +276,7 @@ interface nsIHTMLEditor : nsISupports
* @param aAlign enum value for first encountered alignment * @param aAlign enum value for first encountered alignment
* (left/center/right) * (left/center/right)
*/ */
[can_run_script]
void getAlignment(out boolean aMixed, out short aAlign); void getAlignment(out boolean aMixed, out short aAlign);
/** /**
@ -356,6 +367,7 @@ interface nsIHTMLEditor : nsISupports
* (an "A" tag with the "name" attribute set) * (an "A" tag with the "name" attribute set)
* @return The new element created. * @return The new element created.
*/ */
[can_run_script]
Element createElementWithDefaults(in AString aTagName); Element createElementWithDefaults(in AString aTagName);
/** /**
@ -363,6 +375,7 @@ interface nsIHTMLEditor : nsISupports
* *
* @param aElement An "A" element with a non-empty "href" attribute * @param aElement An "A" element with a non-empty "href" attribute
*/ */
[can_run_script]
void insertLinkAroundSelection(in Element aAnchorElement); void insertLinkAroundSelection(in Element aAnchorElement);
/** /**