Bug 1018486 - Part 2: Changes in editor/, r=masayuki
authorMichael Layzell <michael@thelayzells.com>
Mon, 18 Jul 2016 12:36:19 -0400
changeset 313041 9a9dbfdcdb15c3b530f5b92ff43b1bd1b102d8e9
parent 313040 5399738f71c074589c8d6d52f4a62c1e87cfe8dc
child 313042 b4d1a0890f4048ded5479b157b75f05138a34ade
push id30669
push userkwierso@gmail.com
push dateThu, 08 Sep 2016 00:56:12 +0000
treeherdermozilla-central@77940cbf0c2a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1018486
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1018486 - Part 2: Changes in editor/, r=masayuki MozReview-Commit-ID: JA7UCVXEd8j
editor/libeditor/EditorEventListener.cpp
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/HTMLStyleEditor.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/TextEditor.cpp
editor/txmgr/nsTransactionItem.cpp
editor/txtsvc/nsTextServicesDocument.cpp
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -349,16 +349,17 @@ EditorEventListener::EditorHasFocus()
 NS_IMPL_ISUPPORTS(EditorEventListener, nsIDOMEventListener)
 
 NS_IMETHODIMP
 EditorEventListener::HandleEvent(nsIDOMEvent* aEvent)
 {
   NS_ENSURE_TRUE(mEditorBase, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIEditor> kungFuDeathGrip = mEditorBase;
+  Unused << kungFuDeathGrip; // mEditorBase is not referred to in this function
 
   WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
 
   // Let's handle each event with the message of the internal event of the
   // coming event.  If the DOM event was created with improper interface,
   // e.g., keydown event is created with |new MouseEvent("keydown", {});|,
   // its message is always 0.  Therefore, we can ban such strange event easy.
   // However, we need to handle strange "focus" and "blur" event.  See the
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -65,22 +65,22 @@ HTMLEditor::AbsolutePositionSelection(bo
   // Find out if the selection is collapsed:
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(aEnabled ? EditAction::setAbsolutePosition :
                                     EditAction::removeAbsolutePosition);
   bool cancel, handled;
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (NS_FAILED(res) || cancel)
     return res;
 
-  return mRules->DidDoAction(selection, &ruleInfo, res);
+  return rules->DidDoAction(selection, &ruleInfo, res);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement** _retval)
 {
   nsAutoString positionStr;
   nsCOMPtr<nsINode> node = GetSelectionContainer();
   nsCOMPtr<nsIDOMNode> resultNode;
@@ -171,22 +171,22 @@ HTMLEditor::RelativeChangeZIndex(int32_t
   // brade: can we get rid of this comment?
   // Find out if the selection is collapsed:
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(aChange < 0 ? EditAction::decreaseZIndex :
                                        EditAction::increaseZIndex);
   bool cancel, handled;
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(res))
     return res;
 
-  return mRules->DidDoAction(selection, &ruleInfo, res);
+  return rules->DidDoAction(selection, &ruleInfo, res);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetElementZIndex(nsIDOMElement* aElement,
                              int32_t* aZindex)
 {
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_STATE(element || !aElement);
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -292,45 +292,45 @@ NS_IMETHODIMP
 HTMLEditRules::BeforeEdit(EditAction action,
                           nsIEditor::EDirection aDirection)
 {
   if (mLockRulesSniffing) {
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   AutoLockRulesSniffing lockIt(this);
   mDidExplicitlySetInterline = false;
 
   if (!mActionNesting) {
     mActionNesting++;
 
     // Clear our flag about if just deleted a range
     mDidRangedDelete = false;
 
     // Remember where our selection was before edit action took place:
 
     // Get selection
-    RefPtr<Selection> selection = mHTMLEditor->GetSelection();
+    RefPtr<Selection> selection = htmlEditor->GetSelection();
 
     // Get the selection location
     if (!selection->RangeCount()) {
       return NS_ERROR_UNEXPECTED;
     }
     mRangeItem->startNode = selection->GetRangeAt(0)->GetStartParent();
     mRangeItem->startOffset = selection->GetRangeAt(0)->StartOffset();
     mRangeItem->endNode = selection->GetRangeAt(0)->GetEndParent();
     mRangeItem->endOffset = selection->GetRangeAt(0)->EndOffset();
     nsCOMPtr<nsINode> selStartNode = mRangeItem->startNode;
     nsCOMPtr<nsINode> selEndNode = mRangeItem->endNode;
 
     // Register with range updater to track this as we perturb the doc
-    (mHTMLEditor->mRangeUpdater).RegisterRangeItem(mRangeItem);
+    htmlEditor->mRangeUpdater.RegisterRangeItem(mRangeItem);
 
     // Clear deletion state bool
     mDidDeleteSelection = false;
 
     // Clear out mDocChangeRange and mUtilRange
     if (mDocChangeRange) {
       // Clear out our accounting of what changed
       mDocChangeRange->Reset();
@@ -347,17 +347,17 @@ HTMLEditRules::BeforeEdit(EditAction act
         IsStyleCachePreservingAction(action)) {
       nsCOMPtr<nsINode> selNode =
         aDirection == nsIEditor::eNext ? selEndNode : selStartNode;
       nsresult rv = CacheInlineStyles(GetAsDOMNode(selNode));
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // Stabilize the document against contenteditable count changes
-    nsCOMPtr<nsIDOMDocument> doc = mHTMLEditor->GetDOMDocument();
+    nsCOMPtr<nsIDOMDocument> doc = htmlEditor->GetDOMDocument();
     NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
     nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
     NS_ENSURE_TRUE(htmlDoc, NS_ERROR_FAILURE);
     if (htmlDoc->GetEditingState() == nsIHTMLDocument::eContentEditable) {
       htmlDoc->ChangeContentEditableCount(nullptr, +1);
       mRestoreContentEditableCount = true;
     }
 
@@ -374,33 +374,33 @@ NS_IMETHODIMP
 HTMLEditRules::AfterEdit(EditAction action,
                          nsIEditor::EDirection aDirection)
 {
   if (mLockRulesSniffing) {
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   AutoLockRulesSniffing lockIt(this);
 
   MOZ_ASSERT(mActionNesting > 0);
   nsresult rv = NS_OK;
   mActionNesting--;
   if (!mActionNesting) {
     // Do all the tricky stuff
     rv = AfterEditInner(action, aDirection);
 
     // Free up selectionState range item
-    (mHTMLEditor->mRangeUpdater).DropRangeItem(mRangeItem);
+    htmlEditor->mRangeUpdater.DropRangeItem(mRangeItem);
 
     // Reset the contenteditable count to its previous value
     if (mRestoreContentEditableCount) {
-      nsCOMPtr<nsIDOMDocument> doc = mHTMLEditor->GetDOMDocument();
+      nsCOMPtr<nsIDOMDocument> doc = htmlEditor->GetDOMDocument();
       NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
       nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
       NS_ENSURE_TRUE(htmlDoc, NS_ERROR_FAILURE);
       if (htmlDoc->GetEditingState() == nsIHTMLDocument::eContentEditable) {
         htmlDoc->ChangeContentEditableCount(nullptr, -1);
       }
       mRestoreContentEditableCount = false;
     }
@@ -784,37 +784,37 @@ HTMLEditRules::GetListItemState(bool* aM
 
 nsresult
 HTMLEditRules::GetAlignment(bool* aMixed,
                             nsIHTMLEditor::EAlignment* aAlign)
 {
   MOZ_ASSERT(aMixed && aAlign);
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // For now, just return first alignment.  We'll lie about if it's mixed.
   // This is for efficiency given that our current ui doesn't care if it's
   // mixed.
   // cmanske: NOT TRUE! We would like to pay attention to mixed state in Format
   // | Align submenu!
 
   // This routine assumes that alignment is done ONLY via divs
 
   // Default alignment is left
   *aMixed = false;
   *aAlign = nsIHTMLEditor::eLeft;
 
   // Get selection
-  NS_ENSURE_STATE(mHTMLEditor->GetSelection());
-  OwningNonNull<Selection> selection = *mHTMLEditor->GetSelection();
+  NS_ENSURE_STATE(htmlEditor->GetSelection());
+  OwningNonNull<Selection> selection = *htmlEditor->GetSelection();
 
   // Get selection location
-  NS_ENSURE_TRUE(mHTMLEditor->GetRoot(), NS_ERROR_FAILURE);
-  OwningNonNull<Element> root = *mHTMLEditor->GetRoot();
+  NS_ENSURE_TRUE(htmlEditor->GetRoot(), NS_ERROR_FAILURE);
+  OwningNonNull<Element> root = *htmlEditor->GetRoot();
 
   int32_t rootOffset = root->GetParentNode() ?
                        root->GetParentNode()->IndexOf(root) : -1;
 
   NS_ENSURE_STATE(selection->GetRangeAt(0) &&
                   selection->GetRangeAt(0)->GetStartParent());
   OwningNonNull<nsINode> parent = *selection->GetRangeAt(0)->GetStartParent();
   int32_t offset = selection->GetRangeAt(0)->StartOffset();
@@ -823,43 +823,43 @@ HTMLEditRules::GetAlignment(bool* aMixed
   nsCOMPtr<nsINode> nodeToExamine;
   if (selection->Collapsed() || parent->GetAsText()) {
     // If selection is collapsed, we want to look at 'parent' and its ancestors
     // for divs with alignment on them.  If we are in a text node, then that is
     // the node of interest.
     nodeToExamine = parent;
   } else if (parent->IsHTMLElement(nsGkAtoms::html) && offset == rootOffset) {
     // If we have selected the body, let's look at the first editable node
-    nodeToExamine = mHTMLEditor->GetNextNode(parent, offset, true);
+    nodeToExamine = htmlEditor->GetNextNode(parent, offset, true);
   } else {
     nsTArray<RefPtr<nsRange>> arrayOfRanges;
     GetPromotedRanges(selection, arrayOfRanges, EditAction::align);
 
     // Use these ranges to construct a list of nodes to act on.
     nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
     nsresult rv = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
                                        EditAction::align, TouchContent::no);
     NS_ENSURE_SUCCESS(rv, rv);
     nodeToExamine = arrayOfNodes.SafeElementAt(0);
   }
 
   NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
 
   NS_NAMED_LITERAL_STRING(typeAttrName, "align");
-  nsCOMPtr<Element> blockParent = mHTMLEditor->GetBlock(*nodeToExamine);
+  nsCOMPtr<Element> blockParent = htmlEditor->GetBlock(*nodeToExamine);
 
   NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
 
-  if (mHTMLEditor->IsCSSEnabled() &&
-      mHTMLEditor->mCSSEditUtils->IsCSSEditableProperty(blockParent, nullptr,
+  if (htmlEditor->IsCSSEnabled() &&
+      htmlEditor->mCSSEditUtils->IsCSSEditableProperty(blockParent, nullptr,
                                                         &typeAttrName)) {
     // We are in CSS mode and we know how to align this element with CSS
     nsAutoString value;
     // Let's get the value(s) of text-align or margin-left/margin-right
-    mHTMLEditor->mCSSEditUtils->GetCSSEquivalentToHTMLInlineStyleSet(
+    htmlEditor->mCSSEditUtils->GetCSSEquivalentToHTMLInlineStyleSet(
         blockParent, nullptr, &typeAttrName, value, CSSEditUtils::eComputed);
     if (value.EqualsLiteral("center") ||
         value.EqualsLiteral("-moz-center") ||
         value.EqualsLiteral("auto auto")) {
       *aAlign = nsIHTMLEditor::eCenter;
       return NS_OK;
     }
     if (value.EqualsLiteral("right") ||
@@ -1167,17 +1167,17 @@ void
 HTMLEditRules::WillInsert(Selection& aSelection,
                           bool* aCancel)
 {
   MOZ_ASSERT(aCancel);
 
   TextEditRules::WillInsert(aSelection, aCancel);
 
   NS_ENSURE_TRUE_VOID(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Adjust selection to prevent insertion after a moz-BR.  This next only
   // works for collapsed selections right now, because selection is a pain to
   // work with when not collapsed.  (no good way to extend start or end of
   // selection), so we ignore those types of selections.
   if (!aSelection.Collapsed()) {
     return;
   }
@@ -1185,21 +1185,21 @@ HTMLEditRules::WillInsert(Selection& aSe
   // If we are after a mozBR in the same block, then move selection to be
   // before it
   NS_ENSURE_TRUE_VOID(aSelection.GetRangeAt(0) &&
                       aSelection.GetRangeAt(0)->GetStartParent());
   OwningNonNull<nsINode> selNode = *aSelection.GetRangeAt(0)->GetStartParent();
   int32_t selOffset = aSelection.GetRangeAt(0)->StartOffset();
 
   // Get prior node
-  nsCOMPtr<nsIContent> priorNode = mHTMLEditor->GetPriorHTMLNode(selNode,
-                                                                 selOffset);
+  nsCOMPtr<nsIContent> priorNode = htmlEditor->GetPriorHTMLNode(selNode,
+                                                                selOffset);
   if (priorNode && TextEditUtils::IsMozBR(priorNode)) {
-    nsCOMPtr<Element> block1 = mHTMLEditor->GetBlock(selNode);
-    nsCOMPtr<Element> block2 = mHTMLEditor->GetBlockNodeParent(priorNode);
+    nsCOMPtr<Element> block1 = htmlEditor->GetBlock(selNode);
+    nsCOMPtr<Element> block2 = htmlEditor->GetBlockNodeParent(priorNode);
 
     if (block1 && block1 == block2) {
       // If we are here then the selection is right after a mozBR that is in
       // the same block as the selection.  We need to move the selection start
       // to be before the mozBR.
       selNode = priorNode->GetParentNode();
       selOffset = selNode->IndexOf(priorNode);
       nsresult res = aSelection.Collapse(selNode, selOffset);
@@ -1476,22 +1476,22 @@ HTMLEditRules::WillInsertBreak(Selection
                                bool* aCancel,
                                bool* aHandled)
 {
   MOZ_ASSERT(aCancel && aHandled);
   *aCancel = false;
   *aHandled = false;
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // If the selection isn't collapsed, delete it.
   nsresult res;
   if (!aSelection.Collapsed()) {
-    res = mHTMLEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
+    res = htmlEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   WillInsert(aSelection, aCancel);
 
   // Initialize out param.  We want to ignore result of WillInsert().
   *aCancel = false;
 
@@ -1508,44 +1508,44 @@ HTMLEditRules::WillInsertBreak(Selection
   // Smart splitting rules
   NS_ENSURE_TRUE(aSelection.GetRangeAt(0) &&
                  aSelection.GetRangeAt(0)->GetStartParent(),
                  NS_ERROR_FAILURE);
   OwningNonNull<nsINode> node = *aSelection.GetRangeAt(0)->GetStartParent();
   int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
   // Do nothing if the node is read-only
-  if (!mHTMLEditor->IsModifiableNode(node)) {
+  if (!htmlEditor->IsModifiableNode(node)) {
     *aCancel = true;
     return NS_OK;
   }
 
   // Identify the block
-  nsCOMPtr<Element> blockParent = mHTMLEditor->GetBlock(node);
+  nsCOMPtr<Element> blockParent = htmlEditor->GetBlock(node);
   NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
 
   // If the active editing host is an inline element, or if the active editing
   // host is the block parent itself, just append a br.
-  nsCOMPtr<Element> host = mHTMLEditor->GetActiveEditingHost();
+  nsCOMPtr<Element> host = htmlEditor->GetActiveEditingHost();
   if (!EditorUtils::IsDescendantOf(blockParent, host)) {
     res = StandardBreakImpl(node, offset, aSelection);
     NS_ENSURE_SUCCESS(res, res);
     *aHandled = true;
     return NS_OK;
   }
 
   // If block is empty, populate with br.  (For example, imagine a div that
   // contains the word "text".  The user selects "text" and types return.
   // "Text" is deleted leaving an empty block.  We want to put in one br to
   // make block have a line.  Then code further below will put in a second br.)
   bool isEmpty;
   IsEmptyBlock(*blockParent, &isEmpty);
   if (isEmpty) {
-    nsCOMPtr<Element> br = mHTMLEditor->CreateBR(blockParent,
-                                                 blockParent->Length());
+    nsCOMPtr<Element> br = htmlEditor->CreateBR(blockParent,
+                                                blockParent->Length());
     NS_ENSURE_STATE(br);
   }
 
   nsCOMPtr<Element> listItem = IsInListItem(blockParent);
   if (listItem && listItem != host) {
     ReturnInListItem(aSelection, *listItem, node, offset);
     *aHandled = true;
     return NS_OK;
@@ -1571,51 +1571,51 @@ HTMLEditRules::WillInsertBreak(Selection
 }
 
 nsresult
 HTMLEditRules::StandardBreakImpl(nsINode& aNode,
                                  int32_t aOffset,
                                  Selection& aSelection)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   nsCOMPtr<Element> brNode;
   bool bAfterBlock = false;
   bool bBeforeBlock = false;
   nsCOMPtr<nsINode> node = &aNode;
   nsresult res;
 
   if (IsPlaintextEditor()) {
-    brNode = mHTMLEditor->CreateBR(node, aOffset);
+    brNode = htmlEditor->CreateBR(node, aOffset);
     NS_ENSURE_STATE(brNode);
   } else {
-    WSRunObject wsObj(mHTMLEditor, node, aOffset);
+    WSRunObject wsObj(htmlEditor, node, aOffset);
     int32_t visOffset = 0;
     WSType wsType;
     nsCOMPtr<nsINode> visNode;
     wsObj.PriorVisibleNode(node, aOffset, address_of(visNode),
                            &visOffset, &wsType);
     if (wsType & WSType::block) {
       bAfterBlock = true;
     }
     wsObj.NextVisibleNode(node, aOffset, address_of(visNode),
                           &visOffset, &wsType);
     if (wsType & WSType::block) {
       bBeforeBlock = true;
     }
     nsCOMPtr<nsIDOMNode> linkDOMNode;
-    if (mHTMLEditor->IsInLink(GetAsDOMNode(node), address_of(linkDOMNode))) {
+    if (htmlEditor->IsInLink(GetAsDOMNode(node), address_of(linkDOMNode))) {
       // Split the link
       nsCOMPtr<Element> linkNode = do_QueryInterface(linkDOMNode);
       NS_ENSURE_STATE(linkNode || !linkDOMNode);
       nsCOMPtr<nsINode> linkParent = linkNode->GetParentNode();
-      aOffset = mHTMLEditor->SplitNodeDeep(*linkNode, *node->AsContent(),
-                                           aOffset,
-                                           HTMLEditor::EmptyContainers::no);
+      aOffset = htmlEditor->SplitNodeDeep(*linkNode, *node->AsContent(),
+                                          aOffset,
+                                          HTMLEditor::EmptyContainers::no);
       NS_ENSURE_STATE(aOffset != -1);
       node = linkParent;
     }
     brNode = wsObj.InsertBreak(address_of(node), &aOffset, nsIEditor::eNone);
     NS_ENSURE_TRUE(brNode, NS_ERROR_FAILURE);
   }
   node = brNode->GetParentNode();
   NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
@@ -1623,33 +1623,33 @@ HTMLEditRules::StandardBreakImpl(nsINode
   if (bAfterBlock && bBeforeBlock) {
     // We just placed a br between block boundaries.  This is the one case
     // where we want the selection to be before the br we just placed, as the
     // br will be on a new line, rather than at end of prior line.
     aSelection.SetInterlinePosition(true);
     res = aSelection.Collapse(node, offset);
     NS_ENSURE_SUCCESS(res, res);
   } else {
-    WSRunObject wsObj(mHTMLEditor, node, offset + 1);
+    WSRunObject wsObj(htmlEditor, node, offset + 1);
     nsCOMPtr<nsINode> secondBR;
     int32_t visOffset = 0;
     WSType wsType;
     wsObj.NextVisibleNode(node, offset + 1, address_of(secondBR),
                           &visOffset, &wsType);
     if (wsType == WSType::br) {
       // The next thing after the break we inserted is another break.  Move the
       // second break to be the first break's sibling.  This will prevent them
       // from being in different inline nodes, which would break
       // SetInterlinePosition().  It will also assure that if the user clicks
       // away and then clicks back on their new blank line, they will still get
       // the style from the line above.
       nsCOMPtr<nsINode> brParent = secondBR->GetParentNode();
       int32_t brOffset = brParent ? brParent->IndexOf(secondBR) : -1;
       if (brParent != node || brOffset != offset + 1) {
-        res = mHTMLEditor->MoveNode(secondBR->AsContent(), node, offset + 1);
+        res = htmlEditor->MoveNode(secondBR->AsContent(), node, offset + 1);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
     // SetInterlinePosition(true) means we want the caret to stick to the
     // content on the "right".  We want the caret to stick to whatever is past
     // the break.  This is because the break is on the same line we were on,
     // but the next content will be on the following line.
 
@@ -2528,39 +2528,39 @@ HTMLEditRules::GetGoodSelPointForNode(ns
 nsresult
 HTMLEditRules::JoinBlocks(nsIContent& aLeftNode,
                           nsIContent& aRightNode,
                           bool* aCanceled)
 {
   MOZ_ASSERT(aCanceled);
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
-
-  nsCOMPtr<Element> leftBlock = mHTMLEditor->GetBlock(aLeftNode);
-  nsCOMPtr<Element> rightBlock = mHTMLEditor->GetBlock(aRightNode);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+
+  nsCOMPtr<Element> leftBlock = htmlEditor->GetBlock(aLeftNode);
+  nsCOMPtr<Element> rightBlock = htmlEditor->GetBlock(aRightNode);
 
   // Sanity checks
   NS_ENSURE_TRUE(leftBlock && rightBlock, NS_ERROR_NULL_POINTER);
   NS_ENSURE_STATE(leftBlock != rightBlock);
 
   if (HTMLEditUtils::IsTableElement(leftBlock) ||
       HTMLEditUtils::IsTableElement(rightBlock)) {
     // Do not try to merge table elements
     *aCanceled = true;
     return NS_OK;
   }
 
   // Make sure we don't try to move things into HR's, which look like blocks
   // but aren't containers
   if (leftBlock->IsHTMLElement(nsGkAtoms::hr)) {
-    leftBlock = mHTMLEditor->GetBlockNodeParent(leftBlock);
+    leftBlock = htmlEditor->GetBlockNodeParent(leftBlock);
   }
   if (rightBlock->IsHTMLElement(nsGkAtoms::hr)) {
-    rightBlock = mHTMLEditor->GetBlockNodeParent(rightBlock);
+    rightBlock = htmlEditor->GetBlockNodeParent(rightBlock);
   }
   NS_ENSURE_STATE(leftBlock && rightBlock);
 
   // Bail if both blocks the same
   if (leftBlock == rightBlock) {
     *aCanceled = true;
     return NS_OK;
   }
@@ -2591,39 +2591,39 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
       // sublists in our implementation.
       leftBlock = leftList;
       rightBlock = rightList;
       mergeLists = true;
       existingList = leftList->NodeInfo()->NameAtom();
     }
   }
 
-  AutoTransactionsConserveSelection dontSpazMySelection(mHTMLEditor);
+  AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
 
   nsresult res = NS_OK;
   int32_t rightOffset = 0;
   int32_t leftOffset = -1;
 
   // offset below is where you find yourself in rightBlock when you traverse
   // upwards from leftBlock
   if (EditorUtils::IsDescendantOf(leftBlock, rightBlock, &rightOffset)) {
     // Tricky case.  Left block is inside right block.  Do ws adjustment.  This
     // just destroys non-visible ws at boundaries we will be joining.
     rightOffset++;
-    res = WSRunObject::ScrubBlockBoundary(mHTMLEditor,
+    res = WSRunObject::ScrubBlockBoundary(htmlEditor,
                                           WSRunObject::kBlockEnd,
                                           leftBlock);
     NS_ENSURE_SUCCESS(res, res);
 
     {
       // We can't just track rightBlock because it's an Element.
       nsCOMPtr<nsINode> trackingRightBlock(rightBlock);
-      AutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater,
+      AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater,
                                 address_of(trackingRightBlock), &rightOffset);
-      res = WSRunObject::ScrubBlockBoundary(mHTMLEditor,
+      res = WSRunObject::ScrubBlockBoundary(htmlEditor,
                                             WSRunObject::kAfterBlock,
                                             rightBlock, rightOffset);
       NS_ENSURE_SUCCESS(res, res);
       if (trackingRightBlock->IsElement()) {
         rightBlock = trackingRightBlock->AsElement();
       } else {
         NS_ENSURE_STATE(trackingRightBlock->GetParentElement());
         rightBlock = trackingRightBlock->GetParentElement();
@@ -2632,41 +2632,41 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
     // Do br adjustment.
     nsCOMPtr<Element> brNode =
       CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
     if (mergeLists) {
       // The idea here is to take all children in rightList that are past
       // offset, and pull them into leftlist.
       for (nsCOMPtr<nsIContent> child = rightList->GetChildAt(offset);
            child; child = rightList->GetChildAt(rightOffset)) {
-        res = mHTMLEditor->MoveNode(child, leftList, -1);
+        res = htmlEditor->MoveNode(child, leftList, -1);
         NS_ENSURE_SUCCESS(res, res);
       }
     } else {
       res = MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
     }
     if (brNode) {
-      mHTMLEditor->DeleteNode(brNode);
+      htmlEditor->DeleteNode(brNode);
     }
   // Offset below is where you find yourself in leftBlock when you traverse
   // upwards from rightBlock
   } else if (EditorUtils::IsDescendantOf(rightBlock, leftBlock, &leftOffset)) {
     // Tricky case.  Right block is inside left block.  Do ws adjustment.  This
     // just destroys non-visible ws at boundaries we will be joining.
-    res = WSRunObject::ScrubBlockBoundary(mHTMLEditor,
+    res = WSRunObject::ScrubBlockBoundary(htmlEditor,
                                           WSRunObject::kBlockStart,
                                           rightBlock);
     NS_ENSURE_SUCCESS(res, res);
     {
       // We can't just track leftBlock because it's an Element, so track
       // something else.
       nsCOMPtr<nsINode> trackingLeftBlock(leftBlock);
-      AutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater,
+      AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater,
                                 address_of(trackingLeftBlock), &leftOffset);
-      res = WSRunObject::ScrubBlockBoundary(mHTMLEditor,
+      res = WSRunObject::ScrubBlockBoundary(htmlEditor,
                                             WSRunObject::kBeforeBlock,
                                             leftBlock, leftOffset);
       NS_ENSURE_SUCCESS(res, res);
       if (trackingLeftBlock->IsElement()) {
         leftBlock = trackingLeftBlock->AsElement();
       } else {
         NS_ENSURE_STATE(trackingLeftBlock->GetParentElement());
         leftBlock = trackingLeftBlock->GetParentElement();
@@ -2708,49 +2708,49 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
 
         // We want to move our content just after the previous visible node.
         previousContentOffset++;
       }
 
       // Because we don't want the moving content to receive the style of the
       // previous content, we split the previous content's style.
 
-      nsCOMPtr<Element> editorRoot = mHTMLEditor->GetEditorRoot();
+      nsCOMPtr<Element> editorRoot = htmlEditor->GetEditorRoot();
       if (!editorRoot || &aLeftNode != editorRoot) {
         nsCOMPtr<nsIContent> splittedPreviousContent;
-        res = mHTMLEditor->SplitStyleAbovePoint(address_of(previousContentParent),
-                                                &previousContentOffset,
-                                                nullptr, nullptr, nullptr,
-                                                getter_AddRefs(splittedPreviousContent));
+        res = htmlEditor->SplitStyleAbovePoint(address_of(previousContentParent),
+                                               &previousContentOffset,
+                                               nullptr, nullptr, nullptr,
+                                               getter_AddRefs(splittedPreviousContent));
         NS_ENSURE_SUCCESS(res, res);
 
         if (splittedPreviousContent) {
           previousContentParent = splittedPreviousContent->GetParentNode();
           previousContentOffset = previousContentParent ?
             previousContentParent->IndexOf(splittedPreviousContent) : -1;
         }
       }
 
       NS_ENSURE_TRUE(previousContentParent, NS_ERROR_NULL_POINTER);
 
       res = MoveBlock(*previousContentParent->AsElement(), *rightBlock,
           previousContentOffset, rightOffset);
       NS_ENSURE_SUCCESS(res, res);
     }
     if (brNode) {
-      mHTMLEditor->DeleteNode(brNode);
+      htmlEditor->DeleteNode(brNode);
     }
   } else {
     // Normal case.  Blocks are siblings, or at least close enough.  An example
     // of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>.  The
     // first li and the p are not true siblings, but we still want to join them
     // if you backspace from li into p.
 
     // Adjust whitespace at block boundaries
-    res = WSRunObject::PrepareToJoinBlocks(mHTMLEditor, leftBlock, rightBlock);
+    res = WSRunObject::PrepareToJoinBlocks(htmlEditor, leftBlock, rightBlock);
     NS_ENSURE_SUCCESS(res, res);
     // Do br adjustment.
     nsCOMPtr<Element> brNode =
       CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
     if (mergeLists || leftBlock->NodeInfo()->NameAtom() ==
                       rightBlock->NodeInfo()->NameAtom()) {
       // Nodes are same type.  merge them.
       EditorDOMPoint pt = JoinNodesSmart(*leftBlock, *rightBlock);
@@ -2760,17 +2760,17 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
                               existingList, nsGkAtoms::li);
       }
     } else {
       // Nodes are dissimilar types.
       res = MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
       NS_ENSURE_SUCCESS(res, res);
     }
     if (brNode) {
-      res = mHTMLEditor->DeleteNode(brNode);
+      res = htmlEditor->DeleteNode(brNode);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   return NS_OK;
 }
 
 
 /**
@@ -2820,35 +2820,35 @@ HTMLEditRules::MoveBlock(Element& aLeftB
 nsresult
 HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
                              Element& aDestElement,
                              int32_t* aInOutDestOffset)
 {
   MOZ_ASSERT(aInOutDestOffset);
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
   nsresult res;
 
   // Check if this node can go into the destination node
-  if (mHTMLEditor->CanContain(aDestElement, aNode)) {
+  if (htmlEditor->CanContain(aDestElement, aNode)) {
     // If it can, move it there
-    res = mHTMLEditor->MoveNode(&aNode, &aDestElement, *aInOutDestOffset);
+    res = htmlEditor->MoveNode(&aNode, &aDestElement, *aInOutDestOffset);
     NS_ENSURE_SUCCESS(res, res);
     if (*aInOutDestOffset != -1) {
       (*aInOutDestOffset)++;
     }
   } else {
     // If it can't, move its children (if any), and then delete it.
     if (aNode.IsElement()) {
       res = MoveContents(*aNode.AsElement(), aDestElement, aInOutDestOffset);
       NS_ENSURE_SUCCESS(res, res);
     }
 
-    res = mHTMLEditor->DeleteNode(&aNode);
+    res = htmlEditor->DeleteNode(&aNode);
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
 }
 
 /**
  * Moves the _contents_ of aElement to (aDestElement, aInOutDestOffset).  DTD
  * containment rules are followed throughout.  aInOutDestOffset is updated to
@@ -3317,106 +3317,106 @@ nsresult
 HTMLEditRules::WillMakeBasicBlock(Selection& aSelection,
                                   const nsAString& aBlockType,
                                   bool* aCancel,
                                   bool* aHandled)
 {
   MOZ_ASSERT(aCancel && aHandled);
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   OwningNonNull<nsIAtom> blockType = NS_Atomize(aBlockType);
 
   WillInsert(aSelection, aCancel);
   // We want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = false;
 
   nsresult res = NormalizeSelection(&aSelection);
   NS_ENSURE_SUCCESS(res, res);
-  AutoSelectionRestorer selectionRestorer(&aSelection, mHTMLEditor);
-  AutoTransactionsConserveSelection dontSpazMySelection(mHTMLEditor);
+  AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
+  AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
   *aHandled = true;
 
   // Contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
   res = GetNodesFromSelection(aSelection, EditAction::makeBasicBlock,
                               arrayOfNodes);
   NS_ENSURE_SUCCESS(res, res);
 
   // Remove all non-editable nodes.  Leave them be.
   for (int32_t i = arrayOfNodes.Length() - 1; i >= 0; i--) {
-    if (!mHTMLEditor->IsEditable(arrayOfNodes[i])) {
+    if (!htmlEditor->IsEditable(arrayOfNodes[i])) {
       arrayOfNodes.RemoveElementAt(i);
     }
   }
 
   // If nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // Get selection location
     NS_ENSURE_STATE(aSelection.GetRangeAt(0) &&
                     aSelection.GetRangeAt(0)->GetStartParent());
     OwningNonNull<nsINode> parent =
       *aSelection.GetRangeAt(0)->GetStartParent();
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
     if (blockType == nsGkAtoms::normal ||
         blockType == nsGkAtoms::_empty) {
       // We are removing blocks (going to "body text")
-      NS_ENSURE_TRUE(mHTMLEditor->GetBlock(parent), NS_ERROR_NULL_POINTER);
-      OwningNonNull<Element> curBlock = *mHTMLEditor->GetBlock(parent);
+      NS_ENSURE_TRUE(htmlEditor->GetBlock(parent), NS_ERROR_NULL_POINTER);
+      OwningNonNull<Element> curBlock = *htmlEditor->GetBlock(parent);
       if (HTMLEditUtils::IsFormatNode(curBlock)) {
         // If the first editable node after selection is a br, consume it.
         // Otherwise it gets pushed into a following block after the split,
         // which is visually bad.
         nsCOMPtr<nsIContent> brNode =
-          mHTMLEditor->GetNextHTMLNode(parent, offset);
+          htmlEditor->GetNextHTMLNode(parent, offset);
         if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
-          res = mHTMLEditor->DeleteNode(brNode);
+          res = htmlEditor->DeleteNode(brNode);
           NS_ENSURE_SUCCESS(res, res);
         }
         // Do the splits!
-        offset = mHTMLEditor->SplitNodeDeep(curBlock, *parent->AsContent(),
+        offset = htmlEditor->SplitNodeDeep(curBlock, *parent->AsContent(),
                                             offset,
                                             HTMLEditor::EmptyContainers::no);
         NS_ENSURE_STATE(offset != -1);
         // Put a br at the split point
-        brNode = mHTMLEditor->CreateBR(curBlock->GetParentNode(), offset);
+        brNode = htmlEditor->CreateBR(curBlock->GetParentNode(), offset);
         NS_ENSURE_STATE(brNode);
         // Put selection at the split point
         res = aSelection.Collapse(curBlock->GetParentNode(), offset);
         // Don't restore the selection
         selectionRestorer.Abort();
         *aHandled = true;
         NS_ENSURE_SUCCESS(res, res);
       }
       // Else nothing to do!
     } else {
       // We are making a block.  Consume a br, if needed.
       nsCOMPtr<nsIContent> brNode =
-        mHTMLEditor->GetNextHTMLNode(parent, offset, true);
+        htmlEditor->GetNextHTMLNode(parent, offset, true);
       if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
-        res = mHTMLEditor->DeleteNode(brNode);
+        res = htmlEditor->DeleteNode(brNode);
         NS_ENSURE_SUCCESS(res, res);
         // We don't need to act on this node any more
         arrayOfNodes.RemoveElement(brNode);
       }
       // Make sure we can put a block here
       res = SplitAsNeeded(blockType, parent, offset);
       NS_ENSURE_SUCCESS(res, res);
       nsCOMPtr<Element> block =
-        mHTMLEditor->CreateNode(blockType, parent, offset);
+        htmlEditor->CreateNode(blockType, parent, offset);
       NS_ENSURE_STATE(block);
       // Remember our new block for postprocessing
       mNewBlock = block;
       // Delete anything that was in the list of nodes
       while (!arrayOfNodes.IsEmpty()) {
         OwningNonNull<nsINode> curNode = arrayOfNodes[0];
-        res = mHTMLEditor->DeleteNode(curNode);
+        res = htmlEditor->DeleteNode(curNode);
         NS_ENSURE_SUCCESS(res, res);
         arrayOfNodes.RemoveElementAt(0);
       }
       // Put selection in new block
       res = aSelection.Collapse(block, 0);
       // Don't restore the selection
       selectionRestorer.Abort();
       *aHandled = true;
@@ -3917,25 +3917,25 @@ HTMLEditRules::WillOutdent(Selection& aS
                            bool* aCancel,
                            bool* aHandled)
 {
   MOZ_ASSERT(aCancel && aHandled);
   *aCancel = false;
   *aHandled = true;
   nsCOMPtr<nsIContent> rememberedLeftBQ, rememberedRightBQ;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
-  bool useCSS = mHTMLEditor->IsCSSEnabled();
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+  bool useCSS = htmlEditor->IsCSSEnabled();
 
   nsresult res = NormalizeSelection(&aSelection);
   NS_ENSURE_SUCCESS(res, res);
 
   // Some scoping for selection resetting - we may need to tweak it
   {
-    AutoSelectionRestorer selectionRestorer(&aSelection, mHTMLEditor);
+    AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
 
     // Convert the selection ranges into "promoted" selection ranges: this
     // basically just expands the range to include the immediate block parent,
     // and then further expands to include any ancestors whose children are all
     // in the range
     nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
     res = GetNodesFromSelection(aSelection, EditAction::outdent,
                                 arrayOfNodes);
@@ -3967,33 +3967,33 @@ HTMLEditRules::WillOutdent(Selection& aS
                                    getter_AddRefs(rememberedLeftBQ),
                                    getter_AddRefs(rememberedRightBQ));
           NS_ENSURE_SUCCESS(res, res);
           curBlockQuote = nullptr;
           firstBQChild = nullptr;
           lastBQChild = nullptr;
           curBlockQuoteIsIndentedWithCSS = false;
         }
-        res = mHTMLEditor->RemoveBlockContainer(curNode);
+        res = htmlEditor->RemoveBlockContainer(curNode);
         NS_ENSURE_SUCCESS(res, res);
         continue;
       }
       // Is it a block with a 'margin' property?
       if (useCSS && IsBlockNode(curNode)) {
         nsIAtom& marginProperty =
-          MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, curNode);
+          MarginPropertyAtomForIndent(*htmlEditor->mCSSEditUtils, curNode);
         nsAutoString value;
-        mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(curNode,
+        htmlEditor->mCSSEditUtils->GetSpecifiedProperty(curNode,
                                                          marginProperty,
                                                          value);
         float f;
         nsCOMPtr<nsIAtom> unit;
-        NS_ENSURE_STATE(mHTMLEditor);
-        mHTMLEditor->mCSSEditUtils->ParseLength(value, &f,
-                                                getter_AddRefs(unit));
+        NS_ENSURE_STATE(htmlEditor);
+        htmlEditor->mCSSEditUtils->ParseLength(value, &f,
+                                               getter_AddRefs(unit));
         if (f > 0) {
           ChangeIndentation(*curNode->AsElement(), Change::minus);
           continue;
         }
       }
       // Is it a list item?
       if (HTMLEditUtils::IsListItem(curNode)) {
         // If it is a list item, that means we are not outdenting whole list.
@@ -4041,38 +4041,38 @@ HTMLEditRules::WillOutdent(Selection& aS
       }
 
       // Are we inside a blockquote?
       OwningNonNull<nsINode> n = curNode;
       curBlockQuoteIsIndentedWithCSS = false;
       // Keep looking up the hierarchy as long as we don't hit the body or the
       // active editing host or a table element (other than an entire table)
       while (!n->IsHTMLElement(nsGkAtoms::body) && 
-             mHTMLEditor->IsDescendantOfEditorRoot(n) &&
+             htmlEditor->IsDescendantOfEditorRoot(n) &&
              (n->IsHTMLElement(nsGkAtoms::table) ||
               !HTMLEditUtils::IsTableElement(n))) {
         if (!n->GetParentNode()) {
           break;
         }
         n = *n->GetParentNode();
         if (n->IsHTMLElement(nsGkAtoms::blockquote)) {
           // If so, remember it and the first node we are taking out of it.
           curBlockQuote = n->AsElement();
           firstBQChild = curNode;
           lastBQChild = curNode;
           break;
         } else if (useCSS) {
           nsIAtom& marginProperty =
-            MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, curNode);
+            MarginPropertyAtomForIndent(*htmlEditor->mCSSEditUtils, curNode);
           nsAutoString value;
-          mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(*n, marginProperty,
+          htmlEditor->mCSSEditUtils->GetSpecifiedProperty(*n, marginProperty,
                                                            value);
           float f;
           nsCOMPtr<nsIAtom> unit;
-          mHTMLEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
+          htmlEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
           if (f > 0 && !(HTMLEditUtils::IsList(curParent) &&
                          HTMLEditUtils::IsList(curNode))) {
             curBlockQuote = n->AsElement();
             firstBQChild = curNode;
             lastBQChild = curNode;
             curBlockQuoteIsIndentedWithCSS = true;
             break;
           }
@@ -4080,48 +4080,47 @@ HTMLEditRules::WillOutdent(Selection& aS
       }
 
       if (!curBlockQuote) {
         // Couldn't find enclosing blockquote.  Handle list cases.
         if (HTMLEditUtils::IsList(curParent)) {
           // Move node out of list
           if (HTMLEditUtils::IsList(curNode)) {
             // Just unwrap this sublist
-            res = mHTMLEditor->RemoveBlockContainer(curNode);
+            res = htmlEditor->RemoveBlockContainer(curNode);
             NS_ENSURE_SUCCESS(res, res);
           }
           // handled list item case above
         } else if (HTMLEditUtils::IsList(curNode)) {
           // node is a list, but parent is non-list: move list items out
           nsCOMPtr<nsIContent> child = curNode->GetLastChild();
           while (child) {
             if (HTMLEditUtils::IsListItem(child)) {
               bool unused;
               res = PopListItem(GetAsDOMNode(child), &unused);
               NS_ENSURE_SUCCESS(res, res);
             } else if (HTMLEditUtils::IsList(child)) {
               // We have an embedded list, so move it out from under the parent
               // list. Be sure to put it after the parent list because this
               // loop iterates backwards through the parent's list of children.
 
-              res = mHTMLEditor->MoveNode(child, curParent, offset + 1);
+              res = htmlEditor->MoveNode(child, curParent, offset + 1);
               NS_ENSURE_SUCCESS(res, res);
             } else {
               // Delete any non-list items for now
-              res = mHTMLEditor->DeleteNode(child);
+              res = htmlEditor->DeleteNode(child);
               NS_ENSURE_SUCCESS(res, res);
             }
             child = curNode->GetLastChild();
           }
           // Delete the now-empty list
-          res = mHTMLEditor->RemoveBlockContainer(curNode);
+          res = htmlEditor->RemoveBlockContainer(curNode);
           NS_ENSURE_SUCCESS(res, res);
         } else if (useCSS) {
           nsCOMPtr<Element> element;
-          nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(curNode);
           if (curNode->GetAsText()) {
             // We want to outdent the parent of text nodes
             element = curNode->GetParentElement();
           } else if (curNode->IsElement()) {
             element = curNode->AsElement();
           }
           if (element) {
             ChangeIndentation(*element, Change::minus);
@@ -4198,38 +4197,38 @@ HTMLEditRules::SplitBlock(Element& aBloc
                           nsIContent** aOutLeftNode,
                           nsIContent** aOutRightNode,
                           nsIContent** aOutMiddleNode)
 {
   // aStartChild and aEndChild must be exclusive descendants of aBlock
   MOZ_ASSERT(EditorUtils::IsDescendantOf(&aStartChild, &aBlock) &&
              EditorUtils::IsDescendantOf(&aEndChild, &aBlock));
   NS_ENSURE_TRUE_VOID(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Get split point location
   OwningNonNull<nsIContent> startParent = *aStartChild.GetParent();
   int32_t startOffset = startParent->IndexOf(&aStartChild);
 
   // Do the splits!
   nsCOMPtr<nsIContent> newMiddleNode1;
-  mHTMLEditor->SplitNodeDeep(aBlock, startParent, startOffset,
-                             HTMLEditor::EmptyContainers::no,
-                             aOutLeftNode, getter_AddRefs(newMiddleNode1));
+  htmlEditor->SplitNodeDeep(aBlock, startParent, startOffset,
+                            HTMLEditor::EmptyContainers::no,
+                            aOutLeftNode, getter_AddRefs(newMiddleNode1));
 
   // Get split point location
   OwningNonNull<nsIContent> endParent = *aEndChild.GetParent();
   // +1 because we want to be after the child
   int32_t endOffset = 1 + endParent->IndexOf(&aEndChild);
 
   // Do the splits!
   nsCOMPtr<nsIContent> newMiddleNode2;
-  mHTMLEditor->SplitNodeDeep(aBlock, endParent, endOffset,
-                             HTMLEditor::EmptyContainers::no,
-                             getter_AddRefs(newMiddleNode2), aOutRightNode);
+  htmlEditor->SplitNodeDeep(aBlock, endParent, endOffset,
+                            HTMLEditor::EmptyContainers::no,
+                            getter_AddRefs(newMiddleNode2), aOutRightNode);
 
   if (aOutMiddleNode) {
     if (newMiddleNode2) {
       newMiddleNode2.forget(aOutMiddleNode);
     } else {
       newMiddleNode1.forget(aOutMiddleNode);
     }
   }
@@ -4452,27 +4451,27 @@ nsresult
 HTMLEditRules::WillAlign(Selection& aSelection,
                          const nsAString& aAlignType,
                          bool* aCancel,
                          bool* aHandled)
 {
   MOZ_ASSERT(aCancel && aHandled);
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   WillInsert(aSelection, aCancel);
 
   // Initialize out param.  We want to ignore result of WillInsert().
   *aCancel = false;
   *aHandled = false;
 
   nsresult rv = NormalizeSelection(&aSelection);
   NS_ENSURE_SUCCESS(rv, rv);
-  AutoSelectionRestorer selectionRestorer(&aSelection, mHTMLEditor);
+  AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
 
   // Convert the selection ranges into "promoted" selection ranges: This
   // basically just expands the range to include the immediate block parent,
   // and then further expands to include any ancestors whose children are all
   // in the range
   *aHandled = true;
   nsTArray<OwningNonNull<nsINode>> nodeArray;
   rv = GetNodesFromSelection(aSelection, EditAction::align, nodeArray);
@@ -4524,30 +4523,30 @@ HTMLEditRules::WillAlign(Selection& aSel
     NS_ENSURE_STATE(parent);
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
     rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
     NS_ENSURE_SUCCESS(rv, rv);
     // Consume a trailing br, if any.  This is to keep an alignment from
     // creating extra lines, if possible.
     nsCOMPtr<nsIContent> brContent =
-      mHTMLEditor->GetNextHTMLNode(parent, offset);
+      htmlEditor->GetNextHTMLNode(parent, offset);
     if (brContent && TextEditUtils::IsBreak(brContent)) {
       // Making use of html structure... if next node after where we are
       // putting our div is not a block, then the br we found is in same block
       // we are, so it's safe to consume it.
-      nsCOMPtr<nsIContent> sibling = mHTMLEditor->GetNextHTMLSibling(parent,
-                                                                     offset);
+      nsCOMPtr<nsIContent> sibling = htmlEditor->GetNextHTMLSibling(parent,
+                                                                    offset);
       if (sibling && !IsBlockNode(*sibling)) {
-        rv = mHTMLEditor->DeleteNode(brContent);
+        rv = htmlEditor->DeleteNode(brContent);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
-    nsCOMPtr<Element> div = mHTMLEditor->CreateNode(nsGkAtoms::div, parent,
-                                                    offset);
+    nsCOMPtr<Element> div = htmlEditor->CreateNode(nsGkAtoms::div, parent,
+                                                   offset);
     NS_ENSURE_STATE(div);
     // Remember our new block for postprocessing
     mNewBlock = div;
     // Set up the alignment on the div, using HTML or CSS
     rv = AlignBlock(*div, aAlignType, ContentsOnly::yes);
     NS_ENSURE_SUCCESS(rv, rv);
     *aHandled = true;
     // Put in a moz-br so that it won't get deleted
@@ -4565,23 +4564,23 @@ HTMLEditRules::WillAlign(Selection& aSel
 
   nsTArray<bool> transitionList;
   MakeTransitionList(nodeArray, transitionList);
 
   // Okay, now go through all the nodes and give them an align attrib or put
   // them in a div, or whatever is appropriate.  Woohoo!
 
   nsCOMPtr<Element> curDiv;
-  bool useCSS = mHTMLEditor->IsCSSEnabled();
+  bool useCSS = htmlEditor->IsCSSEnabled();
   for (size_t i = 0; i < nodeArray.Length(); i++) {
     auto& curNode = nodeArray[i];
     // Here's where we actually figure out what to do
 
     // Ignore all non-editable nodes.  Leave them be.
-    if (!mHTMLEditor->IsEditable(curNode)) {
+    if (!htmlEditor->IsEditable(curNode)) {
       continue;
     }
 
     // The node is a table element, an hr, a paragraph, a div or a section
     // header; in HTML 4, it can directly carry the ALIGN attribute and we
     // don't need to nest it, just set the alignment.  In CSS, assign the
     // corresponding CSS styles in AlignBlock
     if (HTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(curNode))) {
@@ -4597,29 +4596,29 @@ HTMLEditRules::WillAlign(Selection& aSel
 
     // Skip insignificant formatting text nodes to prevent unnecessary
     // structure splitting!
     bool isEmptyTextNode = false;
     if (curNode->GetAsText() &&
         ((HTMLEditUtils::IsTableElement(curParent) &&
           !HTMLEditUtils::IsTableCellOrCaption(*curParent)) ||
          HTMLEditUtils::IsList(curParent) ||
-         (NS_SUCCEEDED(mHTMLEditor->IsEmptyNode(curNode, &isEmptyTextNode)) &&
+         (NS_SUCCEEDED(htmlEditor->IsEmptyNode(curNode, &isEmptyTextNode)) &&
           isEmptyTextNode))) {
       continue;
     }
 
     // If it's a list item, or a list inside a list, forget any "current" div,
     // and instead put divs inside the appropriate block (td, li, etc.)
     if (HTMLEditUtils::IsListItem(curNode) ||
         HTMLEditUtils::IsList(curNode)) {
       rv = RemoveAlignment(GetAsDOMNode(curNode), aAlignType, true);
       NS_ENSURE_SUCCESS(rv, rv);
       if (useCSS) {
-        mHTMLEditor->mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
+        htmlEditor->mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
             curNode->AsElement(), nullptr, &NS_LITERAL_STRING("align"),
             &aAlignType, false);
         curDiv = nullptr;
         continue;
       } else if (HTMLEditUtils::IsList(curParent)) {
         // If we don't use CSS, add a contraint to list element: they have to
         // be inside another list, i.e., >= second level of nesting
         rv = AlignInnerBlocks(*curNode, &aAlignType);
@@ -4636,28 +4635,28 @@ HTMLEditRules::WillAlign(Selection& aSel
       // First, check that our element can contain a div.
       if (!mTextEditor->CanContainTag(*curParent, *nsGkAtoms::div)) {
         // Cancelled
         return NS_OK;
       }
 
       rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
       NS_ENSURE_SUCCESS(rv, rv);
-      curDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent, offset);
+      curDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParent, offset);
       NS_ENSURE_STATE(curDiv);
       // Remember our new block for postprocessing
       mNewBlock = curDiv;
       // Set up the alignment on the div
       rv = AlignBlock(*curDiv, aAlignType, ContentsOnly::yes);
     }
 
     NS_ENSURE_STATE(curNode->IsContent());
 
     // Tuck the node into the end of the active div
-    rv = mHTMLEditor->MoveNode(curNode->AsContent(), curDiv, -1);
+    rv = htmlEditor->MoveNode(curNode->AsContent(), curDiv, -1);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 
 /**
@@ -4764,100 +4763,100 @@ HTMLEditRules::CheckForEmptyBlock(nsINod
                                   nsIEditor::EDirection aAction,
                                   bool* aHandled)
 {
   // If the editing host is an inline element, bail out early.
   if (aBodyNode && IsInlineNode(*aBodyNode)) {
     return NS_OK;
   }
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // If we are inside an empty block, delete it.  Note: do NOT delete table
   // elements this way.
-  nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*aStartNode);
+  nsCOMPtr<Element> block = htmlEditor->GetBlock(*aStartNode);
   bool bIsEmptyNode;
   nsCOMPtr<Element> emptyBlock;
   nsresult res;
   if (block && block != aBodyNode) {
     // Efficiency hack, avoiding IsEmptyNode() call when in body
-    res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
+    res = htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
     NS_ENSURE_SUCCESS(res, res);
     while (block && bIsEmptyNode && !HTMLEditUtils::IsTableElement(block) &&
            block != aBodyNode) {
       emptyBlock = block;
-      block = mHTMLEditor->GetBlockNodeParent(emptyBlock);
+      block = htmlEditor->GetBlockNodeParent(emptyBlock);
       if (block) {
-        res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
+        res = htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
   }
 
   if (emptyBlock && emptyBlock->IsEditable()) {
     nsCOMPtr<nsINode> blockParent = emptyBlock->GetParentNode();
     NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
     int32_t offset = blockParent->IndexOf(emptyBlock);
 
     if (HTMLEditUtils::IsListItem(emptyBlock)) {
       // Are we the first list item in the list?
       bool bIsFirst;
-      NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->IsFirstEditableChild(GetAsDOMNode(emptyBlock),
-                                              &bIsFirst);
+      NS_ENSURE_STATE(htmlEditor);
+      res = htmlEditor->IsFirstEditableChild(GetAsDOMNode(emptyBlock),
+                                             &bIsFirst);
       NS_ENSURE_SUCCESS(res, res);
       if (bIsFirst) {
         nsCOMPtr<nsINode> listParent = blockParent->GetParentNode();
         NS_ENSURE_TRUE(listParent, NS_ERROR_FAILURE);
         int32_t listOffset = listParent->IndexOf(blockParent);
         // If we are a sublist, skip the br creation
         if (!HTMLEditUtils::IsList(listParent)) {
           // Create a br before list
-          NS_ENSURE_STATE(mHTMLEditor);
+          NS_ENSURE_STATE(htmlEditor);
           nsCOMPtr<Element> br =
-            mHTMLEditor->CreateBR(listParent, listOffset);
+            htmlEditor->CreateBR(listParent, listOffset);
           NS_ENSURE_STATE(br);
           // Adjust selection to be right before it
           res = aSelection->Collapse(listParent, listOffset);
           NS_ENSURE_SUCCESS(res, res);
         }
         // Else just let selection percolate up.  We'll adjust it in
         // AfterEdit()
       }
     } else {
       if (aAction == nsIEditor::eNext) {
         // Move to the start of the next node, if any
-        nsCOMPtr<nsIContent> nextNode = mHTMLEditor->GetNextNode(blockParent,
-                                                                 offset + 1, true);
+        nsCOMPtr<nsIContent> nextNode = htmlEditor->GetNextNode(blockParent,
+                                                                offset + 1, true);
         if (nextNode) {
           EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
           res = aSelection->Collapse(pt.node, pt.offset);
           NS_ENSURE_SUCCESS(res, res);
         } else {
           // Adjust selection to be right after it.
           res = aSelection->Collapse(blockParent, offset + 1);
           NS_ENSURE_SUCCESS(res, res);
         }
       } else {
         // Move to the end of the previous node
-        nsCOMPtr<nsIContent> priorNode = mHTMLEditor->GetPriorNode(blockParent,
-                                                                   offset,
-                                                                   true);
+        nsCOMPtr<nsIContent> priorNode = htmlEditor->GetPriorNode(blockParent,
+                                                                  offset,
+                                                                  true);
         if (priorNode) {
           EditorDOMPoint pt = GetGoodSelPointForNode(*priorNode, aAction);
           res = aSelection->Collapse(pt.node, pt.offset);
           NS_ENSURE_SUCCESS(res, res);
         } else {
           res = aSelection->Collapse(blockParent, offset + 1);
           NS_ENSURE_SUCCESS(res, res);
         }
       }
     }
-    NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->DeleteNode(emptyBlock);
+    NS_ENSURE_STATE(htmlEditor);
+    res = htmlEditor->DeleteNode(emptyBlock);
     *aHandled = true;
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
 }
 
 Element*
 HTMLEditRules::CheckForInvisibleBR(Element& aBlock,
@@ -5456,36 +5455,36 @@ HTMLEditRules::GetPromotedRanges(Selecti
  * PromoteRange() expands a range to include any parents for which all editable
  * children are already in range.
  */
 void
 HTMLEditRules::PromoteRange(nsRange& aRange,
                             EditAction aOperationType)
 {
   NS_ENSURE_TRUE(mHTMLEditor, );
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   nsCOMPtr<nsINode> startNode = aRange.GetStartParent();
   nsCOMPtr<nsINode> endNode = aRange.GetEndParent();
   int32_t startOffset = aRange.StartOffset();
   int32_t endOffset = aRange.EndOffset();
 
   // MOOSE major hack:
   // GetPromotedPoint doesn't really do the right thing for collapsed ranges
   // inside block elements that contain nothing but a solo <br>.  It's easier
   // to put a workaround here than to revamp GetPromotedPoint.  :-(
   if (startNode == endNode && startOffset == endOffset) {
-    nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*startNode);
+    nsCOMPtr<Element> block = htmlEditor->GetBlock(*startNode);
     if (block) {
       bool bIsEmptyNode = false;
-      nsCOMPtr<nsIContent> root = mHTMLEditor->GetActiveEditingHost();
+      nsCOMPtr<nsIContent> root = htmlEditor->GetActiveEditingHost();
       // Make sure we don't go higher than our root element in the content tree
       NS_ENSURE_TRUE(root, );
       if (!nsContentUtils::ContentIsDescendantOf(root, block)) {
-        mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
+        htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
       }
       if (bIsEmptyNode) {
         startNode = block;
         endNode = block;
         startOffset = 0;
         endOffset = block->Length();
       }
     }
@@ -5493,27 +5492,26 @@ HTMLEditRules::PromoteRange(nsRange& aRa
 
   // Make a new adjusted range to represent the appropriate block content.
   // This is tricky.  The basic idea is to push out the range endpoints to
   // truly enclose the blocks that we will affect.
 
   nsCOMPtr<nsIDOMNode> opStartNode;
   nsCOMPtr<nsIDOMNode> opEndNode;
   int32_t opStartOffset, opEndOffset;
-  RefPtr<nsRange> opRange;
 
   GetPromotedPoint(kStart, GetAsDOMNode(startNode), startOffset,
                    aOperationType, address_of(opStartNode), &opStartOffset);
   GetPromotedPoint(kEnd, GetAsDOMNode(endNode), endOffset, aOperationType,
                    address_of(opEndNode), &opEndOffset);
 
   // Make sure that the new range ends up to be in the editable section.
-  if (!mHTMLEditor->IsDescendantOfEditorRoot(
+  if (!htmlEditor->IsDescendantOfEditorRoot(
         EditorBase::GetNodeAtRangeOffsetPoint(opStartNode, opStartOffset)) ||
-      !mHTMLEditor->IsDescendantOfEditorRoot(
+      !htmlEditor->IsDescendantOfEditorRoot(
         EditorBase::GetNodeAtRangeOffsetPoint(opEndNode, opEndOffset - 1))) {
     return;
   }
 
   DebugOnly<nsresult> res = aRange.SetStart(opStartNode, opStartOffset);
   MOZ_ASSERT(NS_SUCCEEDED(res));
   res = aRange.SetEnd(opEndNode, opEndOffset);
   MOZ_ASSERT(NS_SUCCEEDED(res));
@@ -5544,42 +5542,42 @@ private:
 nsresult
 HTMLEditRules::GetNodesForOperation(
                  nsTArray<RefPtr<nsRange>>& aArrayOfRanges,
                  nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
                  EditAction aOperationType,
                  TouchContent aTouchContent)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   int32_t rangeCount = aArrayOfRanges.Length();
   nsresult res = NS_OK;
 
   if (aTouchContent == TouchContent::yes) {
     // Split text nodes. This is necessary, since GetPromotedPoint() may return a
     // range ending in a text node in case where part of a pre-formatted
     // elements needs to be moved.
     for (int32_t i = 0; i < rangeCount; i++) {
       RefPtr<nsRange> r = aArrayOfRanges[i];
       nsCOMPtr<nsIContent> endParent = do_QueryInterface(r->GetEndParent());
-      if (!mHTMLEditor->IsTextNode(endParent)) {
+      if (!htmlEditor->IsTextNode(endParent)) {
         continue;
       }
       nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(endParent);
       if (textNode) {
         int32_t offset = r->EndOffset();
         nsAutoString tempString;
         textNode->GetData(tempString);
 
         if (0 < offset && offset < (int32_t)(tempString.Length())) {
           // Split the text node.
           nsCOMPtr<nsIDOMNode> tempNode;
-          res = mHTMLEditor->SplitNode(endParent->AsDOMNode(), offset,
-                                       getter_AddRefs(tempNode));
+          res = htmlEditor->SplitNode(endParent->AsDOMNode(), offset,
+                                      getter_AddRefs(tempNode));
           NS_ENSURE_SUCCESS(res, res);
 
           // Correct the range.
           // The new end parent becomes the parent node of the text.
           nsCOMPtr<nsIContent> newParent = endParent->GetParent();
           r->SetEnd(newParent, newParent->IndexOf(endParent));
         }
       }
@@ -5592,29 +5590,29 @@ HTMLEditRules::GetNodesForOperation(
   if (aTouchContent == TouchContent::yes) {
     nsTArray<OwningNonNull<RangeItem>> rangeItemArray;
     rangeItemArray.AppendElements(rangeCount);
 
     // First register ranges for special editor gravity
     for (int32_t i = 0; i < rangeCount; i++) {
       rangeItemArray[i] = new RangeItem();
       rangeItemArray[i]->StoreRange(aArrayOfRanges[0]);
-      mHTMLEditor->mRangeUpdater.RegisterRangeItem(rangeItemArray[i]);
+      htmlEditor->mRangeUpdater.RegisterRangeItem(rangeItemArray[i]);
       aArrayOfRanges.RemoveElementAt(0);
     }
     // Now bust up inlines.
     for (auto& item : Reversed(rangeItemArray)) {
       res = BustUpInlinesAtRangeEndpoints(*item);
       if (NS_FAILED(res)) {
         break;
       }
     }
     // Then unregister the ranges
     for (auto& item : rangeItemArray) {
-      mHTMLEditor->mRangeUpdater.DropRangeItem(item);
+      htmlEditor->mRangeUpdater.DropRangeItem(item);
       aArrayOfRanges.AppendElement(item->GetRange());
     }
     NS_ENSURE_SUCCESS(res, res);
   }
   // Gather up a list of all the nodes
   for (auto& range : aArrayOfRanges) {
     DOMSubtreeIterator iter;
     res = iter.Init(*range);
@@ -5653,17 +5651,17 @@ HTMLEditRules::GetNodesForOperation(
         int32_t j = i;
         aOutArrayOfNodes.RemoveElementAt(i);
         GetInnerContent(*node, aOutArrayOfNodes, &j);
       }
     }
   }
   // Outdent should look inside of divs.
   if (aOperationType == EditAction::outdent &&
-      !mHTMLEditor->IsCSSEnabled()) {
+      !htmlEditor->IsCSSEnabled()) {
     for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
       OwningNonNull<nsINode> node = aOutArrayOfNodes[i];
       if (node->IsHTMLElement(nsGkAtoms::div)) {
         int32_t j = i;
         aOutArrayOfNodes.RemoveElementAt(i);
         GetInnerContent(*node, aOutArrayOfNodes, &j, Lists::no, Tables::no);
       }
     }
@@ -5676,17 +5674,17 @@ HTMLEditRules::GetNodesForOperation(
       aOperationType == EditAction::makeList ||
       aOperationType == EditAction::align ||
       aOperationType == EditAction::setAbsolutePosition ||
       aOperationType == EditAction::indent ||
       aOperationType == EditAction::outdent) {
     for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
       OwningNonNull<nsINode> node = aOutArrayOfNodes[i];
       if (aTouchContent == TouchContent::yes && IsInlineNode(node) &&
-          mHTMLEditor->IsContainer(node) && !mHTMLEditor->IsTextNode(node)) {
+          htmlEditor->IsContainer(node) && !htmlEditor->IsTextNode(node)) {
         nsTArray<OwningNonNull<nsINode>> arrayOfInlines;
         res = BustUpInlinesAtBRs(*node->AsContent(), arrayOfInlines);
         NS_ENSURE_SUCCESS(res, res);
 
         // Put these nodes in aOutArrayOfNodes, replacing the current node
         aOutArrayOfNodes.RemoveElementAt(i);
         aOutArrayOfNodes.InsertElementsAt(i, arrayOfInlines);
       }
@@ -5708,19 +5706,19 @@ HTMLEditRules::GetChildNodesForOperation
 
 nsresult
 HTMLEditRules::GetListActionNodes(
                  nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
                  EntireList aEntireList,
                  TouchContent aTouchContent)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
-
-  RefPtr<Selection> selection = mHTMLEditor->GetSelection();
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+
+  RefPtr<Selection> selection = htmlEditor->GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   // Added this in so that ui code can ask to change an entire list, even if
   // selection is only in part of it.  used by list item dialog.
   if (aEntireList == EntireList::yes) {
     uint32_t rangeCount = selection->RangeCount();
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
       RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
@@ -5736,30 +5734,30 @@ HTMLEditRules::GetListActionNodes(
     // the selection spans multiple lists but with no common list parent.
     if (aOutArrayOfNodes.Length()) {
       return NS_OK;
     }
   }
 
   {
     // We don't like other people messing with our selection!
-    AutoTransactionsConserveSelection dontSpazMySelection(mHTMLEditor);
+    AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
 
     // contruct a list of nodes to act on.
     nsresult res = GetNodesFromSelection(*selection, EditAction::makeList,
                                          aOutArrayOfNodes, aTouchContent);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   // Pre-process our list of nodes
   for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
     OwningNonNull<nsINode> testNode = aOutArrayOfNodes[i];
 
     // Remove all non-editable nodes.  Leave them be.
-    if (!mHTMLEditor->IsEditable(testNode)) {
+    if (!htmlEditor->IsEditable(testNode)) {
       aOutArrayOfNodes.RemoveElementAt(i);
       continue;
     }
 
     // Scan for table elements and divs.  If we find table elements other than
     // table, replace it with a list of any editable non-table content.
     if (HTMLEditUtils::IsTableElementButNotTable(testNode)) {
       int32_t j = i;
@@ -5775,32 +5773,32 @@ HTMLEditRules::GetListActionNodes(
   return NS_OK;
 }
 
 void
 HTMLEditRules::LookInsideDivBQandList(
                  nsTArray<OwningNonNull<nsINode>>& aNodeArray)
 {
   NS_ENSURE_TRUE(mHTMLEditor, );
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // If there is only one node in the array, and it is a list, div, or
   // blockquote, then look inside of it until we find inner list or content.
   int32_t listCount = aNodeArray.Length();
   if (listCount != 1) {
     return;
   }
 
   OwningNonNull<nsINode> curNode = aNodeArray[0];
 
   while (curNode->IsHTMLElement(nsGkAtoms::div) ||
          HTMLEditUtils::IsList(curNode) ||
          curNode->IsHTMLElement(nsGkAtoms::blockquote)) {
     // Dive as long as there's only one child, and it's a list, div, blockquote
-    uint32_t numChildren = mHTMLEditor->CountEditableChildren(curNode);
+    uint32_t numChildren = htmlEditor->CountEditableChildren(curNode);
     if (numChildren != 1) {
       break;
     }
 
     // Keep diving!  XXX One would expect to dive into the one editable node.
     nsCOMPtr<nsIContent> child = curNode->GetFirstChild();
     if (!child->IsHTMLElement(nsGkAtoms::div) &&
         !HTMLEditUtils::IsList(child) &&
@@ -5848,32 +5846,32 @@ HTMLEditRules::GetDefinitionListItemType
 }
 
 nsresult
 HTMLEditRules::GetParagraphFormatNodes(
                  nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
                  TouchContent aTouchContent)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
-
-  RefPtr<Selection> selection = mHTMLEditor->GetSelection();
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+
+  RefPtr<Selection> selection = htmlEditor->GetSelection();
   NS_ENSURE_STATE(selection);
 
   // Contruct a list of nodes to act on.
   nsresult res = GetNodesFromSelection(*selection, EditAction::makeBasicBlock,
                                        outArrayOfNodes, aTouchContent);
   NS_ENSURE_SUCCESS(res, res);
 
   // Pre-process our list of nodes
   for (int32_t i = outArrayOfNodes.Length() - 1; i >= 0; i--) {
     OwningNonNull<nsINode> testNode = outArrayOfNodes[i];
 
     // Remove all non-editable nodes.  Leave them be.
-    if (!mHTMLEditor->IsEditable(testNode)) {
+    if (!htmlEditor->IsEditable(testNode)) {
       outArrayOfNodes.RemoveElementAt(i);
       continue;
     }
 
     // Scan for table elements.  If we find table elements other than table,
     // replace it with a list of any editable non-table content.  Ditto for
     // list elements.
     if (HTMLEditUtils::IsTableElement(testNode) ||
@@ -5930,17 +5928,17 @@ HTMLEditRules::BustUpInlinesAtRangeEndpo
 }
 
 nsresult
 HTMLEditRules::BustUpInlinesAtBRs(
                  nsIContent& aNode,
                  nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // First build up a list of all the break nodes inside the inline container.
   nsTArray<OwningNonNull<nsINode>> arrayOfBreaks;
   BRNodeFunctor functor;
   DOMIterator iter(aNode);
   iter.AppendList(functor, arrayOfBreaks);
 
   // If there aren't any breaks, just put inNode itself in the array
@@ -5957,32 +5955,32 @@ HTMLEditRules::BustUpInlinesAtBRs(
   for (uint32_t i = 0; i < arrayOfBreaks.Length(); i++) {
     OwningNonNull<Element> breakNode = *arrayOfBreaks[i]->AsElement();
     NS_ENSURE_TRUE(splitDeepNode, NS_ERROR_NULL_POINTER);
     NS_ENSURE_TRUE(breakNode->GetParent(), NS_ERROR_NULL_POINTER);
     OwningNonNull<nsIContent> splitParentNode = *breakNode->GetParent();
     int32_t splitOffset = splitParentNode->IndexOf(breakNode);
 
     int32_t resultOffset =
-      mHTMLEditor->SplitNodeDeep(*splitDeepNode, splitParentNode, splitOffset,
-                                 HTMLEditor::EmptyContainers::yes,
-                                 getter_AddRefs(leftNode),
-                                 getter_AddRefs(rightNode));
+      htmlEditor->SplitNodeDeep(*splitDeepNode, splitParentNode, splitOffset,
+                                HTMLEditor::EmptyContainers::yes,
+                                getter_AddRefs(leftNode),
+                                getter_AddRefs(rightNode));
     NS_ENSURE_STATE(resultOffset != -1);
 
     // Put left node in node list
     if (leftNode) {
       // Might not be a left node.  A break might have been at the very
       // beginning of inline container, in which case SplitNodeDeep would not
       // actually split anything
       aOutArrayOfNodes.AppendElement(*leftNode);
     }
     // Move break outside of container and also put in node list
-    nsresult res = mHTMLEditor->MoveNode(breakNode, inlineParentNode,
-                                         resultOffset);
+    nsresult res = htmlEditor->MoveNode(breakNode, inlineParentNode,
+                                        resultOffset);
     NS_ENSURE_SUCCESS(res, res);
     aOutArrayOfNodes.AppendElement(*breakNode);
 
     // Now rightNode becomes the new node to split
     splitDeepNode = rightNode;
   }
   // Now tack on remaining rightNode, if any, to the list
   if (rightNode) {
@@ -6113,67 +6111,67 @@ HTMLEditRules::IsInListItem(nsINode* aNo
  */
 nsresult
 HTMLEditRules::ReturnInHeader(Selection& aSelection,
                               Element& aHeader,
                               nsINode& aNode,
                               int32_t aOffset)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Remember where the header is
   nsCOMPtr<nsINode> headerParent = aHeader.GetParentNode();
   int32_t offset = headerParent ? headerParent->IndexOf(&aHeader) : -1;
 
   // Get ws code to adjust any ws
   nsCOMPtr<nsINode> node = &aNode;
-  nsresult res = WSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor,
+  nsresult res = WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
                                                          address_of(node),
                                                          &aOffset);
   NS_ENSURE_SUCCESS(res, res);
 
   // Split the header
   NS_ENSURE_STATE(node->IsContent());
-  mHTMLEditor->SplitNodeDeep(aHeader, *node->AsContent(), aOffset);
+  htmlEditor->SplitNodeDeep(aHeader, *node->AsContent(), aOffset);
 
   // If the left-hand heading is empty, put a mozbr in it
-  nsCOMPtr<nsIContent> prevItem = mHTMLEditor->GetPriorHTMLSibling(&aHeader);
+  nsCOMPtr<nsIContent> prevItem = htmlEditor->GetPriorHTMLSibling(&aHeader);
   if (prevItem && HTMLEditUtils::IsHeader(*prevItem)) {
     bool isEmptyNode;
-    res = mHTMLEditor->IsEmptyNode(prevItem, &isEmptyNode);
+    res = htmlEditor->IsEmptyNode(prevItem, &isEmptyNode);
     NS_ENSURE_SUCCESS(res, res);
     if (isEmptyNode) {
       res = CreateMozBR(prevItem->AsDOMNode(), 0);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
   // If the new (righthand) header node is empty, delete it
   bool isEmpty;
   res = IsEmptyBlock(aHeader, &isEmpty, MozBRCounts::no);
   NS_ENSURE_SUCCESS(res, res);
   if (isEmpty) {
-    res = mHTMLEditor->DeleteNode(&aHeader);
+    res = htmlEditor->DeleteNode(&aHeader);
     NS_ENSURE_SUCCESS(res, res);
     // Layout tells the caret to blink in a weird place if we don't place a
     // break after the header.
     nsCOMPtr<nsIContent> sibling =
-      mHTMLEditor->GetNextHTMLSibling(headerParent, offset + 1);
+      htmlEditor->GetNextHTMLSibling(headerParent, offset + 1);
     if (!sibling || !sibling->IsHTMLElement(nsGkAtoms::br)) {
       ClearCachedStyles();
-      mHTMLEditor->mTypeInState->ClearAllProps();
+      htmlEditor->mTypeInState->ClearAllProps();
 
       // Create a paragraph
       nsCOMPtr<Element> pNode =
-        mHTMLEditor->CreateNode(nsGkAtoms::p, headerParent, offset + 1);
+        htmlEditor->CreateNode(nsGkAtoms::p, headerParent, offset + 1);
       NS_ENSURE_STATE(pNode);
 
       // Append a <br> to it
-      nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(pNode, 0);
+      nsCOMPtr<Element> brNode = htmlEditor->CreateBR(pNode, 0);
       NS_ENSURE_STATE(brNode);
 
       // Set selection to before the break
       res = aSelection.Collapse(pNode, 0);
       NS_ENSURE_SUCCESS(res, res);
     } else {
       headerParent = sibling->GetParentNode();
       offset = headerParent ? headerParent->IndexOf(sibling) : -1;
@@ -6383,20 +6381,20 @@ nsresult
 HTMLEditRules::ReturnInListItem(Selection& aSelection,
                                 Element& aListItem,
                                 nsINode& aNode,
                                 int32_t aOffset)
 {
   MOZ_ASSERT(HTMLEditUtils::IsListItem(&aListItem));
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Get the item parent and the active editing host.
-  nsCOMPtr<Element> root = mHTMLEditor->GetActiveEditingHost();
+  nsCOMPtr<Element> root = htmlEditor->GetActiveEditingHost();
 
   nsCOMPtr<Element> list = aListItem.GetParentElement();
   int32_t itemOffset = list ? list->IndexOf(&aListItem) : -1;
 
   // If we are in an empty item, then we want to pop up out of the list, but
   // only if prefs say it's okay and if the parent isn't the active editing
   // host.
   bool isEmpty;
@@ -6404,111 +6402,111 @@ HTMLEditRules::ReturnInListItem(Selectio
   NS_ENSURE_SUCCESS(res, res);
   if (isEmpty && root != list && mReturnInEmptyLIKillsList) {
     // Get the list offset now -- before we might eventually split the list
     nsCOMPtr<nsINode> listParent = list->GetParentNode();
     int32_t offset = listParent ? listParent->IndexOf(list) : -1;
 
     // Are we the last list item in the list?
     bool isLast;
-    res = mHTMLEditor->IsLastEditableChild(aListItem.AsDOMNode(), &isLast);
+    res = htmlEditor->IsLastEditableChild(aListItem.AsDOMNode(), &isLast);
     NS_ENSURE_SUCCESS(res, res);
     if (!isLast) {
       // We need to split the list!
       ErrorResult rv;
-      mHTMLEditor->SplitNode(*list, itemOffset, rv);
+      htmlEditor->SplitNode(*list, itemOffset, rv);
       NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
     }
 
     // Are we in a sublist?
     if (HTMLEditUtils::IsList(listParent)) {
       // If so, move item out of this list and into the grandparent list
-      res = mHTMLEditor->MoveNode(&aListItem, listParent, offset + 1);
+      res = htmlEditor->MoveNode(&aListItem, listParent, offset + 1);
       NS_ENSURE_SUCCESS(res, res);
       res = aSelection.Collapse(&aListItem, 0);
       NS_ENSURE_SUCCESS(res, res);
     } else {
       // Otherwise kill this item
-      res = mHTMLEditor->DeleteNode(&aListItem);
+      res = htmlEditor->DeleteNode(&aListItem);
       NS_ENSURE_SUCCESS(res, res);
 
       // Time to insert a paragraph
       nsCOMPtr<Element> pNode =
-        mHTMLEditor->CreateNode(nsGkAtoms::p, listParent, offset + 1);
+        htmlEditor->CreateNode(nsGkAtoms::p, listParent, offset + 1);
       NS_ENSURE_STATE(pNode);
 
       // Append a <br> to it
-      nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(pNode, 0);
+      nsCOMPtr<Element> brNode = htmlEditor->CreateBR(pNode, 0);
       NS_ENSURE_STATE(brNode);
 
       // Set selection to before the break
       res = aSelection.Collapse(pNode, 0);
       NS_ENSURE_SUCCESS(res, res);
     }
     return NS_OK;
   }
 
   // Else we want a new list item at the same list level.  Get ws code to
   // adjust any ws.
   nsCOMPtr<nsINode> selNode = &aNode;
-  res = WSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor,
+  res = WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
                                                 address_of(selNode),
                                                 &aOffset);
   NS_ENSURE_SUCCESS(res, res);
   // Now split list item
   NS_ENSURE_STATE(selNode->IsContent());
-  mHTMLEditor->SplitNodeDeep(aListItem, *selNode->AsContent(), aOffset);
+  htmlEditor->SplitNodeDeep(aListItem, *selNode->AsContent(), aOffset);
 
   // Hack: until I can change the damaged doc range code back to being
   // extra-inclusive, I have to manually detect certain list items that may be
   // left empty.
-  nsCOMPtr<nsIContent> prevItem = mHTMLEditor->GetPriorHTMLSibling(&aListItem);
+  nsCOMPtr<nsIContent> prevItem = htmlEditor->GetPriorHTMLSibling(&aListItem);
   if (prevItem && HTMLEditUtils::IsListItem(prevItem)) {
     bool isEmptyNode;
-    res = mHTMLEditor->IsEmptyNode(prevItem, &isEmptyNode);
+    res = htmlEditor->IsEmptyNode(prevItem, &isEmptyNode);
     NS_ENSURE_SUCCESS(res, res);
     if (isEmptyNode) {
       res = CreateMozBR(prevItem->AsDOMNode(), 0);
       NS_ENSURE_SUCCESS(res, res);
     } else {
-      res = mHTMLEditor->IsEmptyNode(&aListItem, &isEmptyNode, true);
+      res = htmlEditor->IsEmptyNode(&aListItem, &isEmptyNode, true);
       NS_ENSURE_SUCCESS(res, res);
       if (isEmptyNode) {
         nsCOMPtr<nsIAtom> nodeAtom = aListItem.NodeInfo()->NameAtom();
         if (nodeAtom == nsGkAtoms::dd || nodeAtom == nsGkAtoms::dt) {
           nsCOMPtr<nsINode> list = aListItem.GetParentNode();
           int32_t itemOffset = list ? list->IndexOf(&aListItem) : -1;
 
           nsIAtom* listAtom = nodeAtom == nsGkAtoms::dt ? nsGkAtoms::dd
                                                         : nsGkAtoms::dt;
           nsCOMPtr<Element> newListItem =
-            mHTMLEditor->CreateNode(listAtom, list, itemOffset + 1);
+            htmlEditor->CreateNode(listAtom, list, itemOffset + 1);
           NS_ENSURE_STATE(newListItem);
           res = mTextEditor->DeleteNode(&aListItem);
           NS_ENSURE_SUCCESS(res, res);
           res = aSelection.Collapse(newListItem, 0);
           NS_ENSURE_SUCCESS(res, res);
 
           return NS_OK;
         }
 
         nsCOMPtr<Element> brNode;
-        res = mHTMLEditor->CopyLastEditableChildStyles(GetAsDOMNode(prevItem),
+        res = htmlEditor->CopyLastEditableChildStyles(GetAsDOMNode(prevItem),
           GetAsDOMNode(&aListItem), getter_AddRefs(brNode));
         NS_ENSURE_SUCCESS(res, res);
         if (brNode) {
           nsCOMPtr<nsINode> brParent = brNode->GetParentNode();
           int32_t offset = brParent ? brParent->IndexOf(brNode) : -1;
           res = aSelection.Collapse(brParent, offset);
           NS_ENSURE_SUCCESS(res, res);
 
           return NS_OK;
         }
       } else {
-        WSRunObject wsObj(mHTMLEditor, &aListItem, 0);
+        WSRunObject wsObj(htmlEditor, &aListItem, 0);
         nsCOMPtr<nsINode> visNode;
         int32_t visOffset = 0;
         WSType wsType;
         wsObj.NextVisibleNode(&aListItem, 0, address_of(visNode),
                               &visOffset, &wsType);
         if (wsType == WSType::special || wsType == WSType::br ||
             visNode->IsHTMLElement(nsGkAtoms::hr)) {
           nsCOMPtr<nsINode> parent = visNode->GetParentNode();
@@ -6598,17 +6596,17 @@ HTMLEditRules::MakeBlockquote(nsTArray<O
 
 /**
  * RemoveBlockStyle() makes the nodes have no special block type.
  */
 nsresult
 HTMLEditRules::RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Intent of this routine is to be used for converting to/from headers,
   // paragraphs, pre, and address.  Those blocks that pretty much just contain
   // inline things...
   nsresult res;
 
   nsCOMPtr<Element> curBlock;
   nsCOMPtr<nsIContent> firstNode, lastNode;
@@ -6617,17 +6615,17 @@ HTMLEditRules::RemoveBlockStyle(nsTArray
     if (HTMLEditUtils::IsFormatNode(curNode)) {
       // Process any partial progress saved
       if (curBlock) {
         res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
         NS_ENSURE_SUCCESS(res, res);
         firstNode = lastNode = curBlock = nullptr;
       }
       // Remove current block
-      res = mHTMLEditor->RemoveBlockContainer(*curNode->AsContent());
+      res = htmlEditor->RemoveBlockContainer(*curNode->AsContent());
       NS_ENSURE_SUCCESS(res, res);
     } else if (curNode->IsAnyOfHTMLElements(nsGkAtoms::table,
                                             nsGkAtoms::tr,
                                             nsGkAtoms::tbody,
                                             nsGkAtoms::td,
                                             nsGkAtoms::li,
                                             nsGkAtoms::blockquote,
                                             nsGkAtoms::div) ||
@@ -6655,17 +6653,17 @@ HTMLEditRules::RemoveBlockStyle(nsTArray
           // handle it now.  We need to remove the portion of curBlock that
           // contains [firstNode - lastNode].
           res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
           NS_ENSURE_SUCCESS(res, res);
           firstNode = lastNode = curBlock = nullptr;
           // Fall out and handle curNode
         }
       }
-      curBlock = mHTMLEditor->GetBlockNodeParent(curNode);
+      curBlock = htmlEditor->GetBlockNodeParent(curNode);
       if (curBlock && HTMLEditUtils::IsFormatNode(curBlock)) {
         firstNode = lastNode = curNode->AsContent();
       } else {
         // Not a block kind that we care about.
         curBlock = nullptr;
       }
     } else if (curBlock) {
       // Some node that is already sans block style.  Skip over it and process
@@ -6691,23 +6689,23 @@ HTMLEditRules::RemoveBlockStyle(nsTArray
 nsresult
 HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
                                nsIAtom& aBlockTag)
 {
   // Intent of this routine is to be used for converting to/from headers,
   // paragraphs, pre, and address.  Those blocks that pretty much just contain
   // inline things...
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   nsresult res;
 
   // Remove all non-editable nodes.  Leave them be.
   for (int32_t i = aNodeArray.Length() - 1; i >= 0; i--) {
-    if (!mHTMLEditor->IsEditable(aNodeArray[i])) {
+    if (!htmlEditor->IsEditable(aNodeArray[i])) {
       aNodeArray.RemoveElementAt(i);
     }
   }
 
   nsCOMPtr<Element> newBlock;
 
   nsCOMPtr<Element> curBlock;
   for (auto& curNode : aNodeArray) {
@@ -6724,19 +6722,19 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
 
     // If curNode is a address, p, header, address, or pre, replace it with a
     // new block of correct type.
     // XXX: pre can't hold everything the others can
     if (HTMLEditUtils::IsMozDiv(curNode) ||
         HTMLEditUtils::IsFormatNode(curNode)) {
       // Forget any previous block used for previous inline nodes
       curBlock = nullptr;
-      newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
-                                               &aBlockTag, nullptr, nullptr,
-                                               EditorBase::eCloneAttributes);
+      newBlock = htmlEditor->ReplaceContainer(curNode->AsElement(),
+                                              &aBlockTag, nullptr, nullptr,
+                                              EditorBase::eCloneAttributes);
       NS_ENSURE_STATE(newBlock);
     } else if (HTMLEditUtils::IsTable(curNode) ||
                HTMLEditUtils::IsList(curNode) ||
                curNode->IsAnyOfHTMLElements(nsGkAtoms::tbody,
                                             nsGkAtoms::tr,
                                             nsGkAtoms::td,
                                             nsGkAtoms::li,
                                             nsGkAtoms::blockquote,
@@ -6749,71 +6747,71 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
       if (childArray.Length()) {
         res = ApplyBlockStyle(childArray, aBlockTag);
         NS_ENSURE_SUCCESS(res, res);
       } else {
         // Make sure we can put a block here
         res = SplitAsNeeded(aBlockTag, curParent, offset);
         NS_ENSURE_SUCCESS(res, res);
         nsCOMPtr<Element> theBlock =
-          mHTMLEditor->CreateNode(&aBlockTag, curParent, offset);
+          htmlEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(theBlock);
         // Remember our new block for postprocessing
         mNewBlock = theBlock;
       }
     } else if (curNode->IsHTMLElement(nsGkAtoms::br)) {
       // If the node is a break, we honor it by putting further nodes in a new
       // parent
       if (curBlock) {
         // Forget any previous block used for previous inline nodes
         curBlock = nullptr;
-        res = mHTMLEditor->DeleteNode(curNode);
+        res = htmlEditor->DeleteNode(curNode);
         NS_ENSURE_SUCCESS(res, res);
       } else {
         // The break is the first (or even only) node we encountered.  Create a
         // block for it.
         res = SplitAsNeeded(aBlockTag, curParent, offset);
         NS_ENSURE_SUCCESS(res, res);
-        curBlock = mHTMLEditor->CreateNode(&aBlockTag, curParent, offset);
+        curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
         mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
-        res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
+        res = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
         NS_ENSURE_SUCCESS(res, res);
       }
     } else if (IsInlineNode(curNode)) {
       // If curNode is inline, pull it into curBlock.  Note: it's assumed that
       // consecutive inline nodes in aNodeArray are actually members of the
       // same block parent.  This happens to be true now as a side effect of
       // how aNodeArray is contructed, but some additional logic should be
       // added here if that should change
       //
       // If curNode is a non editable, drop it if we are going to <pre>.
-      if (&aBlockTag == nsGkAtoms::pre && !mHTMLEditor->IsEditable(curNode)) {
+      if (&aBlockTag == nsGkAtoms::pre && !htmlEditor->IsEditable(curNode)) {
         // Do nothing to this block
         continue;
       }
 
       // If no curBlock, make one
       if (!curBlock) {
         res = SplitAsNeeded(aBlockTag, curParent, offset);
         NS_ENSURE_SUCCESS(res, res);
-        curBlock = mHTMLEditor->CreateNode(&aBlockTag, curParent, offset);
+        curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
         mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
       }
 
       // XXX If curNode is a br, replace it with a return if going to <pre>
 
       // This is a continuation of some inline nodes that belong together in
       // the same block item.  Use curBlock.
-      res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
+      res = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   return NS_OK;
 }
 
 /**
  * Given a tag name, split inOutParent up to the point where we can insert the
@@ -7195,43 +7193,43 @@ void
 HTMLEditRules::CheckInterlinePosition(Selection& aSelection)
 {
   // If the selection isn't collapsed, do nothing.
   if (!aSelection.Collapsed()) {
     return;
   }
 
   NS_ENSURE_TRUE_VOID(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Get the (collapsed) selection location
   NS_ENSURE_TRUE_VOID(aSelection.GetRangeAt(0) &&
                       aSelection.GetRangeAt(0)->GetStartParent());
   OwningNonNull<nsINode> selNode = *aSelection.GetRangeAt(0)->GetStartParent();
   int32_t selOffset = aSelection.GetRangeAt(0)->StartOffset();
 
   // First, let's check to see if we are after a <br>.  We take care of this
   // special-case first so that we don't accidentally fall through into one of
   // the other conditionals.
   nsCOMPtr<nsIContent> node =
-    mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, true);
+    htmlEditor->GetPriorHTMLNode(selNode, selOffset, true);
   if (node && node->IsHTMLElement(nsGkAtoms::br)) {
     aSelection.SetInterlinePosition(true);
     return;
   }
 
   // Are we after a block?  If so try set caret to following content
-  node = mHTMLEditor->GetPriorHTMLSibling(selNode, selOffset);
+  node = htmlEditor->GetPriorHTMLSibling(selNode, selOffset);
   if (node && IsBlockNode(*node)) {
     aSelection.SetInterlinePosition(true);
     return;
   }
 
   // Are we before a block?  If so try set caret to prior content
-  node = mHTMLEditor->GetNextHTMLSibling(selNode, selOffset);
+  node = htmlEditor->GetNextHTMLSibling(selNode, selOffset);
   if (node && IsBlockNode(*node)) {
     aSelection.SetInterlinePosition(false);
   }
 }
 
 nsresult
 HTMLEditRules::AdjustSelection(Selection* aSelection,
                                nsIEditor::EDirection aAction)
@@ -7481,17 +7479,17 @@ HTMLEditRules::InDifferentTableElements(
   return aNode1 != aNode2;
 }
 
 
 nsresult
 HTMLEditRules::RemoveEmptyNodes()
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Some general notes on the algorithm used here: the goal is to examine all
   // the nodes in mDocChangeRange, and remove the empty ones.  We do this by
   // using a content iterator to traverse all the nodes in the range, and
   // placing the empty nodes into an array.  After finishing the iteration, we
   // delete the empty nodes in the array.  (They cannot be deleted as we find
   // them because that would invalidate the iterator.)
   //
@@ -7561,18 +7559,18 @@ HTMLEditRules::RemoveEmptyNodes()
             bIsCandidate = true;
           }
         }
       }
 
       if (bIsCandidate) {
         // We delete mailcites even if they have a solo br in them.  Other
         // nodes we require to be empty.
-        res = mHTMLEditor->IsEmptyNode(node->AsDOMNode(), &bIsEmptyNode,
-                                       bIsMailCite, true);
+        res = htmlEditor->IsEmptyNode(node->AsDOMNode(), &bIsEmptyNode,
+                                      bIsMailCite, true);
         NS_ENSURE_SUCCESS(res, res);
         if (bIsEmptyNode) {
           if (bIsMailCite) {
             // mailcites go on a separate list from other empty nodes
             arrayOfEmptyCites.AppendElement(*node);
           } else {
             arrayOfEmptyNodes.AppendElement(*node);
           }
@@ -7585,37 +7583,37 @@ HTMLEditRules::RemoveEmptyNodes()
       }
     }
 
     iter->Next();
   }
 
   // now delete the empty nodes
   for (auto& delNode : arrayOfEmptyNodes) {
-    if (mHTMLEditor->IsModifiableNode(delNode)) {
-      res = mHTMLEditor->DeleteNode(delNode);
+    if (htmlEditor->IsModifiableNode(delNode)) {
+      res = htmlEditor->DeleteNode(delNode);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
   // Now delete the empty mailcites.  This is a separate step because we want
   // to pull out any br's and preserve them.
   for (auto& delNode : arrayOfEmptyCites) {
     bool bIsEmptyNode;
-    res = mHTMLEditor->IsEmptyNode(delNode, &bIsEmptyNode, false, true);
+    res = htmlEditor->IsEmptyNode(delNode, &bIsEmptyNode, false, true);
     NS_ENSURE_SUCCESS(res, res);
     if (!bIsEmptyNode) {
       // We are deleting a cite that has just a br.  We want to delete cite,
       // but preserve br.
       nsCOMPtr<nsINode> parent = delNode->GetParentNode();
       int32_t offset = parent ? parent->IndexOf(delNode) : -1;
-      nsCOMPtr<Element> br = mHTMLEditor->CreateBR(parent, offset);
+      nsCOMPtr<Element> br = htmlEditor->CreateBR(parent, offset);
       NS_ENSURE_STATE(br);
     }
-    res = mHTMLEditor->DeleteNode(delNode);
+    res = htmlEditor->DeleteNode(delNode);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::SelectionEndpointInNode(nsINode* aNode,
@@ -7666,42 +7664,42 @@ HTMLEditRules::SelectionEndpointInNode(n
 
 /**
  * IsEmptyInline: Return true if aNode is an empty inline container
  */
 bool
 HTMLEditRules::IsEmptyInline(nsINode& aNode)
 {
   NS_ENSURE_TRUE(mHTMLEditor, false);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
-
-  if (IsInlineNode(aNode) && mHTMLEditor->IsContainer(&aNode)) {
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+
+  if (IsInlineNode(aNode) && htmlEditor->IsContainer(&aNode)) {
     bool isEmpty = true;
-    mHTMLEditor->IsEmptyNode(&aNode, &isEmpty);
+    htmlEditor->IsEmptyNode(&aNode, &isEmpty);
     return isEmpty;
   }
   return false;
 }
 
 
 bool
 HTMLEditRules::ListIsEmptyLine(nsTArray<OwningNonNull<nsINode>>& aArrayOfNodes)
 {
   // We have a list of nodes which we are candidates for being moved into a new
   // block.  Determine if it's anything more than a blank line.  Look for
   // editable content above and beyond one single BR.
   NS_ENSURE_TRUE(aArrayOfNodes.Length(), true);
 
   NS_ENSURE_TRUE(mHTMLEditor, false);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   int32_t brCount = 0;
 
   for (auto& node : aArrayOfNodes) {
-    if (!mHTMLEditor->IsEditable(node)) {
+    if (!htmlEditor->IsEditable(node)) {
       continue;
     }
     if (TextEditUtils::IsBreak(node)) {
       // First break doesn't count
       if (brCount) {
         return false;
       }
       brCount++;
@@ -7775,17 +7773,17 @@ HTMLEditRules::PopListItem(nsIDOMNode* a
   }
   return res;
 }
 
 nsresult
 HTMLEditRules::RemoveListStructure(Element& aList)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
   nsresult res;
 
   while (aList.GetFirstChild()) {
     OwningNonNull<nsIContent> child = *aList.GetFirstChild();
 
     if (HTMLEditUtils::IsListItem(child)) {
       bool isOutOfList;
       // Keep popping it out until it's not in a list anymore
@@ -7793,23 +7791,23 @@ HTMLEditRules::RemoveListStructure(Eleme
         res = PopListItem(child->AsDOMNode(), &isOutOfList);
         NS_ENSURE_SUCCESS(res, res);
       } while (!isOutOfList);
     } else if (HTMLEditUtils::IsList(child)) {
       res = RemoveListStructure(*child->AsElement());
       NS_ENSURE_SUCCESS(res, res);
     } else {
       // Delete any non-list items for now
-      res = mHTMLEditor->DeleteNode(child);
+      res = htmlEditor->DeleteNode(child);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
   // Delete the now-empty list
-  res = mHTMLEditor->RemoveBlockContainer(aList);
+  res = htmlEditor->RemoveBlockContainer(aList);
   NS_ENSURE_SUCCESS(res, res);
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::ConfirmSelectionInBody()
 {
@@ -8347,60 +8345,60 @@ HTMLEditRules::AlignBlock(Element& aElem
                           ContentsOnly aContentsOnly)
 {
   if (!IsBlockNode(aElement) && !aElement.IsHTMLElement(nsGkAtoms::hr)) {
     // We deal only with blocks; early way out
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   nsresult res = RemoveAlignment(aElement.AsDOMNode(), aAlignType,
                                  aContentsOnly == ContentsOnly::yes);
   NS_ENSURE_SUCCESS(res, res);
   NS_NAMED_LITERAL_STRING(attr, "align");
-  if (mHTMLEditor->IsCSSEnabled()) {
+  if (htmlEditor->IsCSSEnabled()) {
     // Let's use CSS alignment; we use margin-left and margin-right for tables
     // and text-align for other block-level elements
-    res = mHTMLEditor->SetAttributeOrEquivalent(
+    res = htmlEditor->SetAttributeOrEquivalent(
       static_cast<nsIDOMElement*>(aElement.AsDOMNode()), attr, aAlignType,
       false);
     NS_ENSURE_SUCCESS(res, res);
   } else {
     // HTML case; this code is supposed to be called ONLY if the element
     // supports the align attribute but we'll never know...
     if (HTMLEditUtils::SupportsAlignAttr(aElement.AsDOMNode())) {
       res =
-        mHTMLEditor->SetAttribute(static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
-                                  attr, aAlignType);
+        htmlEditor->SetAttribute(static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
+                                 attr, aAlignType);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::ChangeIndentation(Element& aElement,
                                  Change aChange)
 {
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   nsIAtom& marginProperty =
-    MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, aElement);
+    MarginPropertyAtomForIndent(*htmlEditor->mCSSEditUtils, aElement);
   nsAutoString value;
-  mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(aElement, marginProperty,
-                                                   value);
+  htmlEditor->mCSSEditUtils->GetSpecifiedProperty(aElement, marginProperty,
+                                                  value);
   float f;
   nsCOMPtr<nsIAtom> unit;
-  mHTMLEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
+  htmlEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
   if (0 == f) {
     nsAutoString defaultLengthUnit;
-    mHTMLEditor->mCSSEditUtils->GetDefaultLengthUnit(defaultLengthUnit);
+    htmlEditor->mCSSEditUtils->GetDefaultLengthUnit(defaultLengthUnit);
     unit = NS_Atomize(defaultLengthUnit);
   }
   int8_t multiplier = aChange == Change::plus ? +1 : -1;
   if        (nsGkAtoms::in == unit) {
             f += NS_EDITOR_INDENT_INCREMENT_IN * multiplier;
   } else if (nsGkAtoms::cm == unit) {
             f += NS_EDITOR_INDENT_INCREMENT_CM * multiplier;
   } else if (nsGkAtoms::mm == unit) {
@@ -8418,62 +8416,62 @@ HTMLEditRules::ChangeIndentation(Element
   } else if (nsGkAtoms::percentage == unit) {
             f += NS_EDITOR_INDENT_INCREMENT_PERCENT * multiplier;
   }
 
   if (0 < f) {
     nsAutoString newValue;
     newValue.AppendFloat(f);
     newValue.Append(nsDependentAtomString(unit));
-    mHTMLEditor->mCSSEditUtils->SetCSSProperty(aElement, marginProperty,
-                                               newValue);
+    htmlEditor->mCSSEditUtils->SetCSSProperty(aElement, marginProperty,
+                                              newValue);
     return NS_OK;
   }
 
-  mHTMLEditor->mCSSEditUtils->RemoveCSSProperty(aElement, marginProperty,
-                                                value);
+  htmlEditor->mCSSEditUtils->RemoveCSSProperty(aElement, marginProperty,
+                                               value);
 
   // Remove unnecessary divs
   if (!aElement.IsHTMLElement(nsGkAtoms::div) ||
-      &aElement == mHTMLEditor->GetActiveEditingHost() ||
-      !mHTMLEditor->IsDescendantOfEditorRoot(&aElement) ||
+      &aElement == htmlEditor->GetActiveEditingHost() ||
+      !htmlEditor->IsDescendantOfEditorRoot(&aElement) ||
       HTMLEditor::HasAttributes(&aElement)) {
     return NS_OK;
   }
 
-  nsresult res = mHTMLEditor->RemoveContainer(&aElement);
+  nsresult res = htmlEditor->RemoveContainer(&aElement);
   NS_ENSURE_SUCCESS(res, res);
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
                                     bool* aCancel,
                                     bool* aHandled)
 {
   MOZ_ASSERT(aCancel && aHandled);
   NS_ENSURE_STATE(mHTMLEditor);
-  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   WillInsert(aSelection, aCancel);
 
   // We want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
-  nsCOMPtr<Element> focusElement = mHTMLEditor->GetSelectionContainer();
+  nsCOMPtr<Element> focusElement = htmlEditor->GetSelectionContainer();
   if (focusElement && HTMLEditUtils::IsImage(focusElement)) {
     mNewBlock = focusElement;
     return NS_OK;
   }
 
   nsresult res = NormalizeSelection(&aSelection);
   NS_ENSURE_SUCCESS(res, res);
-  AutoSelectionRestorer selectionRestorer(&aSelection, mHTMLEditor);
+  AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
 
   // Convert the selection ranges into "promoted" selection ranges: this
   // basically just expands the range to include the immediate block parent,
   // and then further expands to include any ancestors whose children are all
   // in the range.
 
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
   GetPromotedRanges(aSelection, arrayOfRanges,
@@ -8493,24 +8491,24 @@ HTMLEditRules::WillAbsolutePosition(Sele
     OwningNonNull<nsINode> parent =
       *aSelection.GetRangeAt(0)->GetStartParent();
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
     // Make sure we can put a block here
     res = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
     NS_ENSURE_SUCCESS(res, res);
     nsCOMPtr<Element> positionedDiv =
-      mHTMLEditor->CreateNode(nsGkAtoms::div, parent, offset);
+      htmlEditor->CreateNode(nsGkAtoms::div, parent, offset);
     NS_ENSURE_STATE(positionedDiv);
     // Remember our new block for postprocessing
     mNewBlock = positionedDiv;
     // Delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
-      res = mHTMLEditor->DeleteNode(curNode);
+      res = htmlEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(res, res);
       arrayOfNodes.RemoveElementAt(0);
     }
     // Put selection in new block
     res = aSelection.Collapse(positionedDiv, 0);
     // Don't restore the selection
     selectionRestorer.Abort();
     *aHandled = true;
@@ -8522,54 +8520,54 @@ HTMLEditRules::WillAbsolutePosition(Sele
   // whatever is appropriate.  Woohoo!
   nsCOMPtr<Element> curList, curPositionedDiv, indentedLI;
   for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) {
     // Here's where we actually figure out what to do
     NS_ENSURE_STATE(arrayOfNodes[i]->IsContent());
     OwningNonNull<nsIContent> curNode = *arrayOfNodes[i]->AsContent();
 
     // Ignore all non-editable nodes.  Leave them be.
-    if (!mHTMLEditor->IsEditable(curNode)) {
+    if (!htmlEditor->IsEditable(curNode)) {
       continue;
     }
 
     nsCOMPtr<nsIContent> sibling;
 
     nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
     int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
 
     // Some logic for putting list items into nested lists...
     if (HTMLEditUtils::IsList(curParent)) {
       // Check to see if curList is still appropriate.  Which it is if curNode
       // is still right after it in the same list.
       if (curList) {
-        sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
+        sibling = htmlEditor->GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         // Create a new nested list of correct type
         res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
                             offset);
         NS_ENSURE_SUCCESS(res, res);
         if (!curPositionedDiv) {
           nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
           int32_t parentOffset = curParentParent
             ? curParentParent->IndexOf(curParent) : -1;
-          curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParentParent,
-                                                     parentOffset);
+          curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParentParent,
+                                                    parentOffset);
           mNewBlock = curPositionedDiv;
         }
-        curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                          curPositionedDiv, -1);
+        curList = htmlEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
+                                         curPositionedDiv, -1);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in.  Remember our
         // new block for postprocessing.
       }
       // Tuck the node into the end of the active list
-      res = mHTMLEditor->MoveNode(curNode, curList, -1);
+      res = htmlEditor->MoveNode(curNode, curList, -1);
       NS_ENSURE_SUCCESS(res, res);
     } else {
       // Not a list item, use blockquote?  If we are inside a list item, we
       // don't want to blockquote, we want to sublist the list item.  We may
       // have several nodes listed in the array of nodes to act on, that are in
       // the same list item.  Since we only want to indent that li once, we
       // must keep track of the most recent indented list item, and not indent
       // it if we find another node to act on that is still inside the same li.
@@ -8579,63 +8577,63 @@ HTMLEditRules::WillAbsolutePosition(Sele
           // Already indented this list item
           continue;
         }
         curParent = listItem->GetParentNode();
         offset = curParent ? curParent->IndexOf(listItem) : -1;
         // Check to see if curList is still appropriate.  Which it is if
         // curNode is still right after it in the same list.
         if (curList) {
-          sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
+          sibling = htmlEditor->GetPriorHTMLSibling(curNode);
         }
 
         if (!curList || (sibling && sibling != curList)) {
           // Create a new nested list of correct type
           res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
                               offset);
           NS_ENSURE_SUCCESS(res, res);
           if (!curPositionedDiv) {
             nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
             int32_t parentOffset = curParentParent ?
               curParentParent->IndexOf(curParent) : -1;
-            curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div,
-                                                       curParentParent,
-                                                       parentOffset);
+            curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div,
+                                                      curParentParent,
+                                                      parentOffset);
             mNewBlock = curPositionedDiv;
           }
-          curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
-                                            curPositionedDiv, -1);
+          curList = htmlEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
+                                           curPositionedDiv, -1);
           NS_ENSURE_STATE(curList);
         }
-        res = mHTMLEditor->MoveNode(listItem, curList, -1);
+        res = htmlEditor->MoveNode(listItem, curList, -1);
         NS_ENSURE_SUCCESS(res, res);
         // Remember we indented this li
         indentedLI = listItem;
       } else {
         // Need to make a div to put things in if we haven't already
 
         if (!curPositionedDiv) {
           if (curNode->IsHTMLElement(nsGkAtoms::div)) {
             curPositionedDiv = curNode->AsElement();
             mNewBlock = curPositionedDiv;
             curList = nullptr;
             continue;
           }
           res = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
           NS_ENSURE_SUCCESS(res, res);
-          curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent,
-                                                     offset);
+          curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParent,
+                                                    offset);
           NS_ENSURE_STATE(curPositionedDiv);
           // Remember our new block for postprocessing
           mNewBlock = curPositionedDiv;
           // curPositionedDiv is now the correct thing to put curNode in
         }
 
         // Tuck the node into the end of the active blockquote
-        res = mHTMLEditor->MoveNode(curNode, curPositionedDiv, -1);
+        res = htmlEditor->MoveNode(curNode, curPositionedDiv, -1);
         NS_ENSURE_SUCCESS(res, res);
         // Forget curList, if any
         curList = nullptr;
       }
     }
   }
   return NS_OK;
 }
@@ -8718,18 +8716,18 @@ HTMLEditRules::DocumentModifiedWorker()
 {
   if (!mHTMLEditor) {
     return;
   }
 
   // DeleteNode below may cause a flush, which could destroy the editor
   nsAutoScriptBlockerSuppressNodeRemoved scriptBlocker;
 
-  nsCOMPtr<nsIHTMLEditor> kungFuDeathGrip(mHTMLEditor);
-  RefPtr<Selection> selection = mHTMLEditor->GetSelection();
+  RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
+  RefPtr<Selection> selection = htmlEditor->GetSelection();
   if (!selection) {
     return;
   }
 
   // Delete our bogus node, if we have one, since the document might not be
   // empty any more.
   if (mBogusNode) {
     mTextEditor->DeleteNode(mBogusNode);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1487,17 +1487,17 @@ HTMLEditor::NormalizeEOLInsertPosition(n
   *insertOffset = brOffset + 1;
 }
 
 NS_IMETHODIMP
 HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
                                      bool aDeleteSelection)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   nsresult res = NS_ERROR_NOT_INITIALIZED;
 
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
 
@@ -1510,17 +1510,17 @@ HTMLEditor::InsertElementAtSelection(nsI
   if (!selection) {
     return NS_ERROR_FAILURE;
   }
 
   // hand off to the rules system, see if it has anything to say about this
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::insertElement);
   ruleInfo.insertElement = aElement;
-  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     if (aDeleteSelection)
     {
       if (!IsBlockNode(element)) {
         // E.g., inserting an image.  In this case we don't need to delete any
@@ -1578,17 +1578,17 @@ HTMLEditor::InsertElementAtSelection(nsI
           nsCOMPtr<nsIDOMNode> brNode;
           res = CreateBR(parentSelectedNode, offsetForInsert+1, address_of(brNode));
           NS_ENSURE_SUCCESS(res, res);
           selection->Collapse(parentSelectedNode, offsetForInsert+1);
         }
       }
     }
   }
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 
 /**
  * InsertNodeAtPoint() attempts to insert aNode into the document, at a point
  * specified by {*ioParent,*ioOffset}.  Checks with strict dtd to see if
  * containment is allowed.  If not allowed, will attempt to find a parent in
@@ -1952,32 +1952,32 @@ NS_IMETHODIMP
 HTMLEditor::MakeOrChangeList(const nsAString& aListType,
                              bool entireList,
                              const nsAString& aBulletType)
 {
   nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::makeList, nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(EditAction::makeList);
   ruleInfo.blockType = &aListType;
   ruleInfo.entireList = entireList;
   ruleInfo.bulletType = &aBulletType;
-  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
     bool isCollapsed = selection->Collapsed();
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
@@ -2013,104 +2013,104 @@ HTMLEditor::MakeOrChangeList(const nsASt
       // make a list item
       nsCOMPtr<Element> newItem = CreateNode(nsGkAtoms::li, newList, 0);
       NS_ENSURE_STATE(newItem);
       res = selection->Collapse(newItem,0);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveList(const nsAString& aListType)
 {
   nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::removeList, nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(EditAction::removeList);
   if (aListType.LowerCaseEqualsLiteral("ol"))
     ruleInfo.bOrdered = true;
   else  ruleInfo.bOrdered = false;
-  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   // no default behavior for this yet.  what would it mean?
 
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 nsresult
 HTMLEditor::MakeDefinitionItem(const nsAString& aItemType)
 {
   nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::makeDefListItem,
                                nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(EditAction::makeDefListItem);
   ruleInfo.blockType = &aItemType;
-  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // todo: no default for now.  we count on rules to handle it.
   }
 
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 nsresult
 HTMLEditor::InsertBasicBlock(const nsAString& aBlockType)
 {
   nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::makeBasicBlock,
                                nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(EditAction::makeBasicBlock);
   ruleInfo.blockType = &aBlockType;
-  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
     bool isCollapsed = selection->Collapsed();
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
@@ -2146,44 +2146,44 @@ HTMLEditor::InsertBasicBlock(const nsASt
       NS_ENSURE_STATE(newBlock);
 
       // reposition selection to inside the block
       res = selection->Collapse(newBlock,0);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 NS_IMETHODIMP
 HTMLEditor::Indent(const nsAString& aIndent)
 {
   nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
   EditAction opID = EditAction::indent;
   if (aIndent.LowerCaseEqualsLiteral("outdent"))
   {
     opID = EditAction::outdent;
   }
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(opID);
-  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // Do default - insert a blockquote node if selection collapsed
     bool isCollapsed = selection->Collapsed();
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
@@ -2225,44 +2225,43 @@ HTMLEditor::Indent(const nsAString& aInd
         // reposition selection to before the space character
         NS_ENSURE_STATE(selection->GetRangeAt(0));
         res = selection->Collapse(selection->GetRangeAt(0)->GetStartParent(),
                                   0);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
   }
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 //TODO: IMPLEMENT ALIGNMENT!
 
 NS_IMETHODIMP
 HTMLEditor::Align(const nsAString& aAlignType)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::align, nsIEditor::eNext);
 
-  nsCOMPtr<nsIDOMNode> node;
   bool cancel, handled;
 
   // Find out if the selection is collapsed:
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(EditAction::align);
   ruleInfo.alignType = &aAlignType;
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(res))
     return res;
 
-  res = mRules->DidDoAction(selection, &ruleInfo, res);
+  res = rules->DidDoAction(selection, &ruleInfo, res);
   return res;
 }
 
 already_AddRefed<Element>
 HTMLEditor::GetElementOrParentByTagName(const nsAString& aTagName,
                                         nsINode* aNode)
 {
   MOZ_ASSERT(!aTagName.IsEmpty());
@@ -3247,18 +3246,18 @@ HTMLEditor::DoContentInserted(nsIDocumen
   }
   // We don't need to handle our own modifications
   else if (!mAction && (aContainer ? aContainer->IsEditable() : aDocument->IsEditable())) {
     if (IsMozEditorBogusNode(aChild)) {
       // Ignore insertion of the bogus node
       return;
     }
     // Protect the edit rules object from dying
-    nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-    mRules->DocumentModified();
+    nsCOMPtr<nsIEditRules> rules(mRules);
+    rules->DocumentModified();
 
     // Update spellcheck for only the newly-inserted node (bug 743819)
     if (mInlineSpellChecker) {
       RefPtr<nsRange> range = new nsRange(aChild);
       int32_t endIndex = aIndexInContainer + 1;
       if (aInsertedOrAppended == eAppended) {
         // Count all the appended nodes
         nsIContent* sibling = aChild->GetNextSibling();
@@ -3291,18 +3290,18 @@ HTMLEditor::ContentRemoved(nsIDocument* 
   }
   // We don't need to handle our own modifications
   else if (!mAction && (aContainer ? aContainer->IsEditable() : aDocument->IsEditable())) {
     if (aChild && IsMozEditorBogusNode(aChild)) {
       // Ignore removal of the bogus node
       return;
     }
     // Protect the edit rules object from dying
-    nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-    mRules->DocumentModified();
+    nsCOMPtr<nsIEditRules> rules(mRules);
+    rules->DocumentModified();
   }
 }
 
 NS_IMETHODIMP_(bool)
 HTMLEditor::IsModifiableNode(nsIDOMNode* aNode)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   return IsModifiableNode(node);
@@ -3468,36 +3467,40 @@ HTMLEditor::StyleSheetLoaded(StyleSheetH
  * All editor operations which alter the doc should be prefaced
  * with a call to StartOperation, naming the action and direction.
  */
 NS_IMETHODIMP
 HTMLEditor::StartOperation(EditAction opID,
                            nsIEditor::EDirection aDirection)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   EditorBase::StartOperation(opID, aDirection);  // will set mAction, mDirection
-  if (mRules) return mRules->BeforeEdit(mAction, mDirection);
+  if (rules) {
+    return rules->BeforeEdit(mAction, mDirection);
+  }
   return NS_OK;
 }
 
 /**
  * All editor operations which alter the doc should be followed
  * with a call to EndOperation.
  */
 NS_IMETHODIMP
 HTMLEditor::EndOperation()
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   // post processing
   nsresult res = NS_OK;
-  if (mRules) res = mRules->AfterEdit(mAction, mDirection);
+  if (rules) {
+    res = rules->AfterEdit(mAction, mDirection);
+  }
   EditorBase::EndOperation();  // will clear mAction, mDirection
   return res;
 }
 
 bool
 HTMLEditor::TagCanContainTag(nsIAtom& aParentTag,
                              nsIAtom& aChildTag)
 {
@@ -3544,24 +3547,24 @@ HTMLEditor::IsContainer(nsIDOMNode* aNod
 
 
 nsresult
 HTMLEditor::SelectEntireDocument(Selection* aSelection)
 {
   if (!aSelection || !mRules) { return NS_ERROR_NULL_POINTER; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   // get editor root node
   nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
 
   // is doc empty?
   bool bDocIsEmpty;
-  nsresult res = mRules->DocumentIsEmpty(&bDocIsEmpty);
+  nsresult res = rules->DocumentIsEmpty(&bDocIsEmpty);
   NS_ENSURE_SUCCESS(res, res);
 
   if (bDocIsEmpty)
   {
     // if its empty dont select entire doc - that would select the bogus node
     return aSelection->Collapse(rootElement, 0);
   }
 
@@ -4554,32 +4557,32 @@ HTMLEditor::SetIsCSSEnabled(bool aIsCSSP
 // Set the block background color
 nsresult
 HTMLEditor::SetCSSBackgroundColor(const nsAString& aColor)
 {
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
   ForceCompositionEnd();
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_STATE(selection);
 
   bool isCollapsed = selection->Collapsed();
 
   AutoEditBatch batchIt(this);
   AutoRules beginRulesSniffing(this, EditAction::insertElement,
                                nsIEditor::eNext);
   AutoSelectionRestorer selectionRestorer(selection, this);
   AutoTransactionsConserveSelection dontSpazMySelection(this);
 
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::setTextProperty);
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     NS_NAMED_LITERAL_STRING(bgcolor, "bgcolor");
     for (uint32_t i = 0; i < selection->RangeCount(); i++) {
       RefPtr<nsRange> range = selection->GetRangeAt(i);
       NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
@@ -4686,17 +4689,17 @@ HTMLEditor::SetCSSBackgroundColor(const 
                                                        false);
           }
         }
       }
     }
   }
   if (!cancel) {
     // Post-process
-    res = mRules->DidDoAction(selection, &ruleInfo, res);
+    res = rules->DidDoAction(selection, &ruleInfo, res);
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetBackgroundColor(const nsAString& aColor)
 {
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -114,18 +114,18 @@ HTMLEditor::LoadHTML(const nsAString& aI
 
   // Get selection
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_STATE(selection);
 
   TextRulesInfo ruleInfo(EditAction::loadHTML);
   bool cancel, handled;
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel) {
     return NS_OK; // rules canceled the operation
   }
 
   if (!handled)
   {
     // Delete Selection, but only if it isn't collapsed, see bug #106269
@@ -140,17 +140,17 @@ HTMLEditor::LoadHTML(const nsAString& aI
 
     // create fragment for pasted html
     nsCOMPtr<nsIDOMDocumentFragment> docfrag;
     {
       rv = range->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
       NS_ENSURE_SUCCESS(rv, rv);
     }
     // put the fragment into the document
-    nsCOMPtr<nsIDOMNode> parent, junk;
+    nsCOMPtr<nsIDOMNode> parent;
     rv = range->GetStartContainer(getter_AddRefs(parent));
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
     int32_t childOffset;
     rv = range->GetStartOffset(&childOffset);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIDOMNode> nodeToInsert;
@@ -158,17 +158,17 @@ HTMLEditor::LoadHTML(const nsAString& aI
     while (nodeToInsert)
     {
       rv = InsertNode(nodeToInsert, parent, childOffset++);
       NS_ENSURE_SUCCESS(rv, rv);
       docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
     }
   }
 
-  return mRules->DidDoAction(selection, &ruleInfo, rv);
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 NS_IMETHODIMP
 HTMLEditor::InsertHTML(const nsAString& aInString)
 {
   const nsAFlatString& empty = EmptyString();
 
   return InsertHTMLWithContext(aInString, empty, empty, empty,
@@ -200,17 +200,17 @@ HTMLEditor::DoInsertHTMLWithContext(cons
                                     int32_t aDestOffset,
                                     bool aDeleteSelection,
                                     bool aTrustedInput,
                                     bool aClearStyle)
 {
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // Prevent the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   // force IME commit; set up rules sniffing and batching
   ForceCompositionEnd();
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::htmlPaste, nsIEditor::eNext);
 
   // Get selection
   RefPtr<Selection> selection = GetSelection();
@@ -224,17 +224,17 @@ HTMLEditor::DoInsertHTMLWithContext(cons
                                            address_of(fragmentAsNode),
                                            address_of(streamStartParent),
                                            address_of(streamEndParent),
                                            &streamStartOffset,
                                            &streamEndOffset,
                                            aTrustedInput);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIDOMNode> targetNode, tempNode;
+  nsCOMPtr<nsIDOMNode> targetNode;
   int32_t targetOffset=0;
 
   if (!aDestNode)
   {
     // if caller didn't provide the destination/target node,
     // fetch the paste insertion point from our selection
     rv = GetStartNodeAndOffset(selection, getter_AddRefs(targetNode), &targetOffset);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -362,17 +362,17 @@ HTMLEditor::DoInsertHTMLWithContext(cons
     }
     // collapse selection to beginning of deleted table content
     selection->CollapseToStart();
   }
 
   // give rules a chance to handle or cancel
   TextRulesInfo ruleInfo(EditAction::insertElement);
   bool cancel, handled;
-  rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel) {
     return NS_OK; // rules canceled the operation
   }
 
   if (!handled)
   {
     // The rules code (WillDoAction above) might have changed the selection.
@@ -547,17 +547,17 @@ HTMLEditor::DoInsertHTMLWithContext(cons
             curNode->RemoveChild(child, getter_AddRefs(tmp));
           }
           curNode->GetFirstChild(getter_AddRefs(child));
         }
 
       } else if (parentBlock && HTMLEditUtils::IsPre(parentBlock) &&
                  HTMLEditUtils::IsPre(curNode)) {
         // Check for pre's going into pre's.
-        nsCOMPtr<nsIDOMNode> child, tmp;
+        nsCOMPtr<nsIDOMNode> child;
         curNode->GetFirstChild(getter_AddRefs(child));
         while (child)
         {
           rv = InsertNodeAtPoint(child, address_of(parentNode), &offsetOfNewNode, true);
           if (NS_FAILED(rv))
             break;
 
           bDidInsert = true;
@@ -699,17 +699,17 @@ HTMLEditor::DoInsertHTMLWithContext(cons
         if (leftLink) {
           selNode = GetNodeLocation(GetAsDOMNode(leftLink), &selOffset);
           selection->Collapse(selNode, selOffset+1);
         }
       }
     }
   }
 
-  return mRules->DidDoAction(selection, &ruleInfo, rv);
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 NS_IMETHODIMP
 HTMLEditor::AddInsertionListener(nsIContentFilter* aListener)
 {
   NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   // don't let a listener be added more than once
@@ -1684,18 +1684,18 @@ HTMLEditor::PasteAsCitedQuotation(const 
   // get selection
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // give rules a chance to handle or cancel
   TextRulesInfo ruleInfo(EditAction::insertElement);
   bool cancel, handled;
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel || handled) {
     return NS_OK; // rules canceled the operation
   }
 
   nsCOMPtr<Element> newNode =
     DeleteSelectionAndCreateElement(*nsGkAtoms::blockquote);
   NS_ENSURE_TRUE(newNode, NS_ERROR_NULL_POINTER);
@@ -1875,18 +1875,18 @@ HTMLEditor::InsertAsPlaintextQuotation(c
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::insertQuotation,
                                nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   TextRulesInfo ruleInfo(EditAction::insertElement);
   bool cancel, handled;
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel || handled) {
     return NS_OK; // rules canceled the operation
   }
 
   // Wrap the inserted quote in a <span> so we can distinguish it.
   nsCOMPtr<Element> newNode =
     DeleteSelectionAndCreateElement(*nsGkAtoms::span);
@@ -1965,18 +1965,18 @@ HTMLEditor::InsertAsCitedQuotation(const
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::insertQuotation,
                                nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   TextRulesInfo ruleInfo(EditAction::insertElement);
   bool cancel, handled;
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel || handled) {
     return NS_OK; // rules canceled the operation
   }
 
   nsCOMPtr<Element> newNode =
     DeleteSelectionAndCreateElement(*nsGkAtoms::blockquote);
   NS_ENSURE_TRUE(newNode, NS_ERROR_NULL_POINTER);
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -109,17 +109,17 @@ HTMLEditor::RemoveAllDefaultProperties()
 
 NS_IMETHODIMP
 HTMLEditor::SetInlineProperty(nsIAtom* aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue)
 {
   NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
   ForceCompositionEnd();
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   if (selection->Collapsed()) {
     // Manipulating text attributes on a collapsed selection only sets state
     // for the next text insertion
@@ -131,17 +131,17 @@ HTMLEditor::SetInlineProperty(nsIAtom* a
   AutoRules beginRulesSniffing(this, EditAction::insertElement,
                                nsIEditor::eNext);
   AutoSelectionRestorer selectionRestorer(selection, this);
   AutoTransactionsConserveSelection dontSpazMySelection(this);
 
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::setTextProperty);
   // Protect the edit rules object from dying
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     uint32_t rangeCount = selection->RangeCount();
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; rangeIdx++) {
       RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
 
       // Adjust range to include any ancestors whose children are entirely
@@ -215,17 +215,17 @@ HTMLEditor::SetInlineProperty(nsIAtom* a
                                           range->EndOffset(), *aProperty,
                                           &aAttribute, aValue);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
   }
   if (!cancel) {
     // Post-process
-    return mRules->DidDoAction(selection, &ruleInfo, res);
+    return rules->DidDoAction(selection, &ruleInfo, res);
   }
   return NS_OK;
 }
 
 // Helper function for SetInlinePropertyOn*: is aNode a simple old <b>, <font>,
 // <span style="">, etc. that we can reuse instead of creating a new one?
 bool
 HTMLEditor::IsSimpleModifiableNode(nsIContent* aContent,
@@ -1221,18 +1221,18 @@ HTMLEditor::RemoveInlinePropertyImpl(nsI
   AutoRules beginRulesSniffing(this, EditAction::removeTextProperty,
                                nsIEditor::eNext);
   AutoSelectionRestorer selectionRestorer(selection, this);
   AutoTransactionsConserveSelection dontSpazMySelection(this);
 
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::removeTextProperty);
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsCOMPtr<nsIEditRules> rules(mRules);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     uint32_t rangeCount = selection->RangeCount();
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
       OwningNonNull<nsRange> range = *selection->GetRangeAt(rangeIdx);
       if (aProperty == nsGkAtoms::name) {
         // Promote range if it starts or end in a named anchor and we want to
@@ -1312,17 +1312,17 @@ HTMLEditor::RemoveInlinePropertyImpl(nsI
             SetInlinePropertyOnNode(node, *aProperty, aAttribute, value);
           }
         }
       }
     }
   }
   if (!cancel) {
     // Post-process
-    res = mRules->DidDoAction(selection, &ruleInfo, res);
+    res = rules->DidDoAction(selection, &ruleInfo, res);
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::IncreaseFontSize()
 {
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -515,17 +515,16 @@ HTMLEditor::InsertTableColumn(int32_t aN
   }
   return res;
 }
 
 NS_IMETHODIMP
 HTMLEditor::InsertTableRow(int32_t aNumber,
                            bool aAfter)
 {
-  RefPtr<Selection> selection;
   nsCOMPtr<nsIDOMElement> table;
   nsCOMPtr<nsIDOMElement> curCell;
 
   int32_t startRowIndex, startColIndex;
   nsresult res = GetCellContext(nullptr,
                                 getter_AddRefs(table),
                                 getter_AddRefs(curCell),
                                 nullptr, nullptr,
@@ -1101,17 +1100,16 @@ HTMLEditor::DeleteTableColumn(int32_t aN
 
 NS_IMETHODIMP
 HTMLEditor::DeleteColumn(nsIDOMElement* aTable,
                          int32_t aColIndex)
 {
   NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMElement> cell;
-  nsCOMPtr<nsIDOMElement> cellInDeleteCol;
   int32_t startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   bool    isSelected;
   int32_t rowIndex = 0;
   nsresult res = NS_OK;
 
   do {
     res = GetCellDataAt(aTable, rowIndex, aColIndex, getter_AddRefs(cell),
                         &startRowIndex, &startColIndex, &rowSpan, &colSpan,
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -655,17 +655,17 @@ nsresult
 TextEditor::DeleteSelection(EDirection aAction,
                             EStripWrappers aStripWrappers)
 {
   MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
 
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   nsresult result;
 
   // delete placeholder txns merge.
   AutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
   AutoRules beginRulesSniffing(this, EditAction::deleteSelection, aAction);
 
   // pre-process
@@ -691,38 +691,38 @@ TextEditor::DeleteSelection(EDirection a
       aAction = eNone;
     }
   }
 
   TextRulesInfo ruleInfo(EditAction::deleteSelection);
   ruleInfo.collapsedAction = aAction;
   ruleInfo.stripWrappers = aStripWrappers;
   bool cancel, handled;
-  result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(result, result);
   if (!cancel && !handled)
   {
     result = DeleteSelectionImpl(aAction, aStripWrappers);
   }
   if (!cancel)
   {
     // post-process
-    result = mRules->DidDoAction(selection, &ruleInfo, result);
+    result = rules->DidDoAction(selection, &ruleInfo, result);
   }
 
   return result;
 }
 
 NS_IMETHODIMP
 TextEditor::InsertText(const nsAString& aStringToInsert)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   EditAction opID = EditAction::insertText;
   if (ShouldHandleIMEComposition()) {
     opID = EditAction::insertIMEText;
   }
   AutoPlaceHolderBatch batch(this, nullptr);
   AutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
 
@@ -734,49 +734,49 @@ TextEditor::InsertText(const nsAString& 
   // XXX and ruleInfo not to refer to instring in its dtor?
   //nsAutoString instring(aStringToInsert);
   TextRulesInfo ruleInfo(opID);
   ruleInfo.inString = &aStringToInsert;
   ruleInfo.outString = &resultString;
   ruleInfo.maxLength = mMaxTextLength;
 
   bool cancel, handled;
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled)
   {
     // we rely on rules code for now - no default implementation
   }
   if (!cancel)
   {
     // post-process
-    res = mRules->DidDoAction(selection, &ruleInfo, res);
+    res = rules->DidDoAction(selection, &ruleInfo, res);
   }
   return res;
 }
 
 NS_IMETHODIMP
 TextEditor::InsertLineBreak()
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::insertBreak, nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(EditAction::insertBreak);
   ruleInfo.maxLength = mMaxTextLength;
   bool cancel, handled;
-  nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled)
   {
     // get the (collapsed) selection location
     NS_ENSURE_STATE(selection->GetRangeAt(0));
     nsCOMPtr<nsINode> selNode = selection->GetRangeAt(0)->GetStartParent();
     int32_t selOffset = selection->GetRangeAt(0)->StartOffset();
     NS_ENSURE_STATE(selNode);
@@ -819,33 +819,33 @@ TextEditor::InsertLineBreak()
           selection->SetInterlinePosition(true);
         }
       }
     }
   }
   if (!cancel)
   {
     // post-process, always called if WillInsertBreak didn't return cancel==true
-    res = mRules->DidDoAction(selection, &ruleInfo, res);
+    res = rules->DidDoAction(selection, &ruleInfo, res);
   }
 
   return res;
 }
 
 nsresult
 TextEditor::BeginIMEComposition(WidgetCompositionEvent* aEvent)
 {
   NS_ENSURE_TRUE(!mComposition, NS_OK);
 
   if (IsPasswordEditor()) {
     NS_ENSURE_TRUE(mRules, NS_ERROR_NULL_POINTER);
     // Protect the edit rules object from dying
-    nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+    nsCOMPtr<nsIEditRules> rules(mRules);
 
-    TextEditRules* textEditRules = static_cast<TextEditRules*>(mRules.get());
+    TextEditRules* textEditRules = static_cast<TextEditRules*>(rules.get());
     textEditRules->ResetIMETextPWBuf();
   }
 
   return EditorBase::BeginIMEComposition(aEvent);
 }
 
 nsresult
 TextEditor::UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent)
@@ -916,19 +916,19 @@ TextEditor::GetInputEventTargetContent()
 NS_IMETHODIMP
 TextEditor::GetDocumentIsEmpty(bool* aDocumentIsEmpty)
 {
   NS_ENSURE_TRUE(aDocumentIsEmpty, NS_ERROR_NULL_POINTER);
 
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
-  return mRules->DocumentIsEmpty(aDocumentIsEmpty);
+  return rules->DocumentIsEmpty(aDocumentIsEmpty);
 }
 
 NS_IMETHODIMP
 TextEditor::GetTextLength(int32_t* aCount)
 {
   NS_ASSERTION(aCount, "null pointer");
 
   // initialize out params
@@ -1082,64 +1082,64 @@ TextEditor::SetNewlineHandling(int32_t a
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditor::Undo(uint32_t aCount)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   AutoUpdateViewBatch beginViewBatching(this);
 
   ForceCompositionEnd();
 
   NotifyEditorObservers(eNotifyEditorObserversOfBefore);
 
   AutoRules beginRulesSniffing(this, EditAction::undo, nsIEditor::eNone);
 
   TextRulesInfo ruleInfo(EditAction::undo);
   RefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
-  nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
 
   if (!cancel && NS_SUCCEEDED(result))
   {
     result = EditorBase::Undo(aCount);
-    result = mRules->DidDoAction(selection, &ruleInfo, result);
+    result = rules->DidDoAction(selection, &ruleInfo, result);
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
   return result;
 }
 
 NS_IMETHODIMP
 TextEditor::Redo(uint32_t aCount)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   AutoUpdateViewBatch beginViewBatching(this);
 
   ForceCompositionEnd();
 
   NotifyEditorObservers(eNotifyEditorObserversOfBefore);
 
   AutoRules beginRulesSniffing(this, EditAction::redo, nsIEditor::eNone);
 
   TextRulesInfo ruleInfo(EditAction::redo);
   RefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
-  nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
 
   if (!cancel && NS_SUCCEEDED(result))
   {
     result = EditorBase::Redo(aCount);
-    result = mRules->DidDoAction(selection, &ruleInfo, result);
+    result = rules->DidDoAction(selection, &ruleInfo, result);
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
   return result;
 }
 
 bool
 TextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed)
@@ -1289,26 +1289,26 @@ TextEditor::GetAndInitDocEncoder(const n
 
 
 NS_IMETHODIMP
 TextEditor::OutputToString(const nsAString& aFormatType,
                            uint32_t aFlags,
                            nsAString& aOutputString)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   nsString resultString;
   TextRulesInfo ruleInfo(EditAction::outputText);
   ruleInfo.outString = &resultString;
   // XXX Struct should store a nsAReadable*
   nsAutoString str(aFormatType);
   ruleInfo.outputFormat = &str;
   bool cancel, handled;
-  nsresult rv = mRules->WillDoAction(nullptr, &ruleInfo, &cancel, &handled);
+  nsresult rv = rules->WillDoAction(nullptr, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(rv)) { return rv; }
   if (handled)
   { // this case will get triggered by password fields
     aOutputString.Assign(*(ruleInfo.outString));
     return rv;
   }
 
   nsAutoCString charsetStr;
@@ -1405,17 +1405,17 @@ TextEditor::PasteAsQuotation(int32_t aSe
   return rv;
 }
 
 NS_IMETHODIMP
 TextEditor::InsertAsQuotation(const nsAString& aQuotedText,
                               nsIDOMNode** aNodeInserted)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   // Let the citer quote it for us:
   nsString quotedStuff;
   nsresult rv = InternetCiter::GetCiteString(aQuotedText, quotedStuff);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // It's best to put a blank line after the quoted text so that mails
   // written without thinking won't be so ugly.
@@ -1427,17 +1427,17 @@ TextEditor::InsertAsQuotation(const nsAS
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::insertText, nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   TextRulesInfo ruleInfo(EditAction::insertElement);
   bool cancel, handled;
-  rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel) return NS_OK; // rules canceled the operation
   if (!handled)
   {
     rv = InsertText(quotedStuff);
 
     // XXX Should set *aNodeInserted to the first node inserted
     if (aNodeInserted && NS_SUCCEEDED(rv))
@@ -1545,52 +1545,55 @@ TextEditor::GetEmbeddedObjects(nsISuppor
  * All editor operations which alter the doc should be prefaced
  * with a call to StartOperation, naming the action and direction.
  */
 NS_IMETHODIMP
 TextEditor::StartOperation(EditAction opID,
                            nsIEditor::EDirection aDirection)
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   EditorBase::StartOperation(opID, aDirection);  // will set mAction, mDirection
-  if (mRules) return mRules->BeforeEdit(mAction, mDirection);
+  if (rules) {
+    return rules->BeforeEdit(mAction, mDirection);
+  }
   return NS_OK;
 }
 
 /**
  * All editor operations which alter the doc should be followed
  * with a call to EndOperation.
  */
 NS_IMETHODIMP
 TextEditor::EndOperation()
 {
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   // post processing
   nsresult res = NS_OK;
-  if (mRules) res = mRules->AfterEdit(mAction, mDirection);
+  if (rules) {
+    res = rules->AfterEdit(mAction, mDirection);
+  }
   EditorBase::EndOperation();  // will clear mAction, mDirection
   return res;
 }
 
 nsresult
 TextEditor::SelectEntireDocument(Selection* aSelection)
 {
   if (!aSelection || !mRules) { return NS_ERROR_NULL_POINTER; }
 
   // Protect the edit rules object from dying
-  nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
+  nsCOMPtr<nsIEditRules> rules(mRules);
 
   // is doc empty?
   bool bDocIsEmpty;
-  if (NS_SUCCEEDED(mRules->DocumentIsEmpty(&bDocIsEmpty)) && bDocIsEmpty)
-  {
+  if (NS_SUCCEEDED(rules->DocumentIsEmpty(&bDocIsEmpty)) && bDocIsEmpty) {
     // get root node
     nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
     NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
 
     // if it's empty don't select entire doc - that would select the bogus node
     return aSelection->Collapse(rootElement, 0);
   }
 
--- a/editor/txmgr/nsTransactionItem.cpp
+++ b/editor/txmgr/nsTransactionItem.cpp
@@ -250,19 +250,19 @@ nsTransactionItem::UndoChildren(nsTransa
   return result;
 }
 
 nsresult
 nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
 {
   nsresult result;
 
-  nsCOMPtr<nsITransaction> kungfuDeathGrip(mTransaction);
-  if (mTransaction) {
-    result = mTransaction->RedoTransaction();
+  nsCOMPtr<nsITransaction> transaction(mTransaction);
+  if (transaction) {
+    result = transaction->RedoTransaction();
 
     NS_ENSURE_SUCCESS(result, result);
   }
 
   result = RedoChildren(aTxMgr);
 
   if (NS_FAILED(result)) {
     RecoverFromRedoError(aTxMgr);
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -3162,17 +3162,16 @@ nsTextServicesDocument::FirstTextNodeInC
   // XXX: What should we return if last is null?
 
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::FirstTextNodeInPrevBlock(nsIContentIterator *aIterator)
 {
-  nsCOMPtr<nsIContent> content;
   nsresult result;
 
   NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   // XXX: What if mIterator is not currently on a text node?
 
   // Make sure mIterator is pointing to the first text node in the
   // current block: