Bug 1534561 - Make editor use PresShell directly rather than nsIPresShell r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 15 Mar 2019 05:01:10 +0000
changeset 525017 dd95011124a522d76265e0cd3382bf7ada44b750
parent 525016 a7d81b7bc493094223744d4010c87789cdf2977e
child 525018 ec0fcbde84b91eedd1d37bab07ce8aa61b241932
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1534561
milestone67.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 1534561 - Make editor use PresShell directly rather than nsIPresShell r=m_kato `PresShell.h` is exposed as `mozilla/PresShell.h` and `PresShell` is the only concrete class of `nsIPresShell`. Therefore, we have no reason to access `PresShell` via `nsIPresShell`. Differential Revision: https://phabricator.services.mozilla.com/D23277
editor/composer/nsEditingSession.cpp
editor/libeditor/CompositionTransaction.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/EditorEventListener.cpp
editor/libeditor/EditorEventListener.h
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLAnonymousNodeEditor.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLEditorDocumentCommands.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLInlineTableEditor.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/TextEditRulesBidi.cpp
editor/libeditor/TextEditor.cpp
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -6,16 +6,17 @@
 
 #include <string.h>  // for nullptr, strcmp
 
 #include "imgIContainer.h"                    // for imgIContainer, etc
 #include "mozilla/ComposerCommandsUpdater.h"  // for ComposerCommandsUpdater
 #include "mozilla/FlushType.h"                // for FlushType::Frames
 #include "mozilla/HTMLEditor.h"               // for HTMLEditor
 #include "mozilla/mozalloc.h"                 // for operator new
+#include "mozilla/PresShell.h"                // for PresShell
 #include "nsAString.h"
 #include "nsComponentManagerUtils.h"  // for do_CreateInstance
 #include "nsContentUtils.h"
 #include "nsDebug.h"  // for NS_ENSURE_SUCCESS, etc
 #include "nsEditingSession.h"
 #include "nsError.h"               // for NS_ERROR_FAILURE, NS_OK, etc
 #include "nsIChannel.h"            // for nsIChannel
 #include "nsICommandManager.h"     // for nsICommandManager
@@ -28,17 +29,16 @@
 #include "nsIDOMWindow.h"          // for nsIDOMWindow
 #include "nsIDocShell.h"           // for nsIDocShell
 #include "mozilla/dom/Document.h"  // for Document
 #include "nsIDocumentStateListener.h"
 #include "nsIEditor.h"                   // for nsIEditor
 #include "nsIHTMLDocument.h"             // for nsIHTMLDocument, etc
 #include "nsIInterfaceRequestorUtils.h"  // for do_GetInterface
 #include "nsIPlaintextEditor.h"          // for nsIPlaintextEditor, etc
-#include "nsIPresShell.h"                // for nsIPresShell
 #include "nsIRefreshURI.h"               // for nsIRefreshURI
 #include "nsIRequest.h"                  // for nsIRequest
 #include "nsITimer.h"                    // for nsITimer, etc
 #include "nsITransactionManager.h"       // for nsITransactionManager
 #include "nsIWeakReference.h"            // for nsISupportsWeakReference, etc
 #include "nsIWebNavigation.h"            // for nsIWebNavigation
 #include "nsIWebProgress.h"              // for nsIWebProgress, etc
 #include "nsLiteralString.h"             // for NS_LITERAL_STRING
@@ -361,18 +361,21 @@ nsEditingSession::SetupEditorOnWindow(mo
     mComposerCommandsUpdater->NotifyDocumentCreated();
     return NS_ERROR_FAILURE;
   }
 
   // Create editor and do other things
   //  only if we haven't found some error above,
   nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
-  nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
-  NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
+  RefPtr<PresShell> presShell =
+      static_cast<PresShell*>(docShell->GetPresShell());
+  if (NS_WARN_IF(!presShell)) {
+    return NS_ERROR_FAILURE;
+  }
 
   if (!mInteractive) {
     // Disable animation of images in this document:
     nsPresContext* presContext = presShell->GetPresContext();
     NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
     mImageAnimationMode = presContext->ImageAnimationMode();
     presContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
@@ -1198,18 +1201,21 @@ void nsEditingSession::RemoveWebProgress
 
 void nsEditingSession::RestoreAnimationMode(nsPIDOMWindowOuter* aWindow) {
   if (mInteractive) {
     return;
   }
 
   nsCOMPtr<nsIDocShell> docShell = aWindow ? aWindow->GetDocShell() : nullptr;
   NS_ENSURE_TRUE_VOID(docShell);
-  nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
-  NS_ENSURE_TRUE_VOID(presShell);
+  RefPtr<PresShell> presShell =
+      static_cast<PresShell*>(docShell->GetPresShell());
+  if (NS_WARN_IF(!presShell)) {
+    return;
+  }
   nsPresContext* presContext = presShell->GetPresContext();
   NS_ENSURE_TRUE_VOID(presContext);
 
   presContext->SetImageAnimationMode(mImageAnimationMode);
 }
 
 nsresult nsEditingSession::DetachFromWindow(mozIDOMWindowProxy* aWindow) {
   NS_ENSURE_TRUE(mDoneSetup, NS_OK);
@@ -1286,18 +1292,21 @@ nsresult nsEditingSession::ReattachToWin
   // Get editor
   RefPtr<HTMLEditor> htmlEditor = GetHTMLEditorForWindow(aWindow);
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
 
   if (!mInteractive) {
     // Disable animation of images in this document:
-    nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
-    NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
+    RefPtr<PresShell> presShell =
+        static_cast<PresShell*>(docShell->GetPresShell());
+    if (NS_WARN_IF(!presShell)) {
+      return NS_ERROR_FAILURE;
+    }
     nsPresContext* presContext = presShell->GetPresContext();
     NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
     mImageAnimationMode = presContext->ImageAnimationMode();
     presContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
   }
 
   // The third controller takes an nsIEditor as the context
--- a/editor/libeditor/CompositionTransaction.cpp
+++ b/editor/libeditor/CompositionTransaction.cpp
@@ -8,18 +8,18 @@
 #include "mozilla/EditorBase.h"       // mEditorBase
 #include "mozilla/SelectionState.h"   // RangeUpdater
 #include "mozilla/TextComposition.h"  // TextComposition
 #include "mozilla/dom/Selection.h"    // local var
 #include "mozilla/dom/Text.h"         // mTextNode
 #include "nsAString.h"                // params
 #include "nsDebug.h"                  // for NS_ASSERTION, etc
 #include "nsError.h"                  // for NS_SUCCEEDED, NS_FAILED, etc
-#include "nsIPresShell.h"             // nsISelectionController constants
 #include "nsRange.h"                  // local var
+#include "nsISelectionController.h"   // for nsISelectionController constants
 #include "nsQueryObject.h"            // for do_QueryObject
 
 namespace mozilla {
 
 using namespace dom;
 
 // static
 already_AddRefed<CompositionTransaction> CompositionTransaction::Create(
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -36,16 +36,17 @@
 #include "mozilla/EditTransactionBase.h"    // for EditTransactionBase
 #include "mozilla/FlushType.h"              // for FlushType::Frames
 #include "mozilla/IMEContentObserver.h"     // for IMEContentObserver
 #include "mozilla/IMEStateManager.h"        // for IMEStateManager
 #include "mozilla/mozalloc.h"               // for operator new, etc.
 #include "mozilla/mozInlineSpellChecker.h"  // for mozInlineSpellChecker
 #include "mozilla/mozSpellChecker.h"        // for mozSpellChecker
 #include "mozilla/Preferences.h"            // for Preferences
+#include "mozilla/PresShell.h"              // for PresShell
 #include "mozilla/RangeBoundary.h"      // for RawRangeBoundary, RangeBoundary
 #include "mozilla/dom/Selection.h"      // for Selection, etc.
 #include "mozilla/Services.h"           // for GetObserverService
 #include "mozilla/ServoCSSParser.h"     // for ServoCSSParser
 #include "mozilla/TextComposition.h"    // for TextComposition
 #include "mozilla/TextInputListener.h"  // for TextInputListener
 #include "mozilla/TextServicesDocument.h"  // for TextServicesDocument
 #include "mozilla/TextEvents.h"
@@ -82,17 +83,16 @@
 #include "nsIEditorObserver.h"         // for nsIEditorObserver
 #include "nsIEditorSpellCheck.h"       // for nsIEditorSpellCheck
 #include "nsIFrame.h"                  // for nsIFrame
 #include "nsIHTMLDocument.h"           // for nsIHTMLDocument
 #include "nsIInlineSpellChecker.h"     // for nsIInlineSpellChecker, etc.
 #include "nsNameSpaceManager.h"        // for kNameSpaceID_None, etc.
 #include "nsINode.h"                   // for nsINode, etc.
 #include "nsIPlaintextEditor.h"        // for nsIPlaintextEditor, etc.
-#include "nsIPresShell.h"              // for nsIPresShell
 #include "nsISelectionController.h"    // for nsISelectionController, etc.
 #include "nsISelectionDisplay.h"       // for nsISelectionDisplay, etc.
 #include "nsISupportsBase.h"           // for nsISupports
 #include "nsISupportsUtils.h"          // for NS_ADDREF, NS_IF_ADDREF
 #include "nsITransferable.h"           // for nsITransferable
 #include "nsITransaction.h"            // for nsITransaction
 #include "nsITransactionManager.h"
 #include "nsIWeakReference.h"  // for nsISupportsWeakReference
@@ -256,18 +256,17 @@ nsresult EditorBase::Init(Document& aDoc
   // HTML editors currently don't have their own selection controller,
   // so they'll pass null as aSelCon, and we'll get the selection controller
   // off of the presshell.
   nsCOMPtr<nsISelectionController> selectionController;
   if (aSelectionController) {
     mSelectionController = aSelectionController;
     selectionController = aSelectionController;
   } else {
-    nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-    selectionController = do_QueryInterface(presShell);
+    selectionController = GetPresShell();
   }
   MOZ_ASSERT(selectionController,
              "Selection controller should be available at this point");
 
   if (mEditActionData) {
     // During edit action, selection is cached. But this selection is invalid
     // now since selection controller is updated, so we have to update this
     // cache.
@@ -445,17 +444,17 @@ bool EditorBase::GetDesiredSpellCheckSta
   if (!spellcheckLevel) {
     return false;  // Spellchecking forced off globally
   }
 
   if (!CanEnableSpellCheck()) {
     return false;
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  PresShell* presShell = GetPresShell();
   if (presShell) {
     nsPresContext* context = presShell->GetPresContext();
     if (context && !context->IsDynamic()) {
       return false;
     }
   }
 
   // Check DOM state
@@ -637,21 +636,21 @@ EditorBase::GetIsDocumentEditable(bool* 
 
 NS_IMETHODIMP
 EditorBase::GetDocument(Document** aDoc) {
   NS_IF_ADDREF(*aDoc = mDocument);
   return *aDoc ? NS_OK : NS_ERROR_NOT_INITIALIZED;
 }
 
 already_AddRefed<nsIWidget> EditorBase::GetWidget() {
-  nsCOMPtr<nsIPresShell> ps = GetPresShell();
-  NS_ENSURE_TRUE(ps, nullptr);
-  nsPresContext* pc = ps->GetPresContext();
-  NS_ENSURE_TRUE(pc, nullptr);
-  nsCOMPtr<nsIWidget> widget = pc->GetRootWidget();
+  nsPresContext* presContext = GetPresContext();
+  if (NS_WARN_IF(!presContext)) {
+    return nullptr;
+  }
+  nsCOMPtr<nsIWidget> widget = presContext->GetRootWidget();
   NS_ENSURE_TRUE(widget.get(), nullptr);
   return widget.forget();
 }
 
 NS_IMETHODIMP
 EditorBase::GetContentsMIMEType(char** aContentsMIMEType) {
   NS_ENSURE_ARG_POINTER(aContentsMIMEType);
   *aContentsMIMEType = ToNewCString(mContentMIMEType);
@@ -2945,19 +2944,19 @@ void EditorBase::DoSplitNode(const Edito
     }
   }
 
   // XXX Why do we ignore an error while moving nodes from the right node to
   //     the left node?
   aError.SuppressException();
 
   // Handle selection
-  nsCOMPtr<nsIPresShell> ps = GetPresShell();
-  if (ps) {
-    ps->FlushPendingNotifications(FlushType::Frames);
+  RefPtr<PresShell> presShell = GetPresShell();
+  if (presShell) {
+    presShell->FlushPendingNotifications(FlushType::Frames);
   }
   NS_WARNING_ASSERTION(!Destroyed(),
                        "The editor is destroyed during splitting a node");
 
   bool allowedTransactionsToChangeSelection =
       AllowsTransactionsToChangeSelection();
 
   RefPtr<Selection> previousSelection;
@@ -4374,29 +4373,24 @@ nsresult EditorBase::InitializeSelection
   if (NS_WARN_IF(!targetNode)) {
     return NS_ERROR_INVALID_ARG;
   }
   nsCOMPtr<nsIContent> selectionRootContent = FindSelectionRoot(targetNode);
   if (!selectionRootContent) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-  if (NS_WARN_IF(!presShell)) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-
   nsCOMPtr<nsISelectionController> selectionController =
       GetSelectionController();
   if (NS_WARN_IF(!selectionController)) {
     return NS_ERROR_FAILURE;
   }
 
   // Init the caret
-  RefPtr<nsCaret> caret = presShell->GetCaret();
+  RefPtr<nsCaret> caret = GetCaret();
   if (NS_WARN_IF(!caret)) {
     return NS_ERROR_FAILURE;
   }
   caret->SetSelection(SelectionRefPtr());
   selectionController->SetCaretReadOnly(IsReadonly());
   selectionController->SetCaretEnabled(true);
   // NOTE(emilio): It's important for this call to be after
   // SetCaretEnabled(true), since that would override mIgnoreUserModify to true.
@@ -4477,22 +4471,21 @@ nsresult EditorBase::FinalizeSelection()
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   SelectionRefPtr()->SetAncestorLimiter(nullptr);
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-  if (NS_WARN_IF(!presShell)) {
+  if (NS_WARN_IF(!GetPresShell())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  if (RefPtr<nsCaret> caret = presShell->GetCaret()) {
+  if (RefPtr<nsCaret> caret = GetCaret()) {
     caret->SetIgnoreUserModify(true);
   }
 
   selectionController->SetCaretEnabled(false);
 
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
   if (NS_WARN_IF(!fm)) {
     return NS_ERROR_NOT_INITIALIZED;
@@ -4860,20 +4853,20 @@ int32_t EditorBase::GetIMESelectionStart
   return minOffset < INT32_MAX ? minOffset : -1;
 }
 
 void EditorBase::HideCaret(bool aHide) {
   if (mHidingCaret == aHide) {
     return;
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-  NS_ENSURE_TRUE_VOID(presShell);
-  RefPtr<nsCaret> caret = presShell->GetCaret();
-  NS_ENSURE_TRUE_VOID(caret);
+  RefPtr<nsCaret> caret = GetCaret();
+  if (NS_WARN_IF(!caret)) {
+    return;
+  }
 
   mHidingCaret = aHide;
   if (aHide) {
     caret->AddForceHide();
   } else {
     caret->RemoveForceHide();
   }
 }
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -35,22 +35,22 @@
 #include "nsLiteralString.h"         // for NS_LITERAL_STRING
 #include "nsString.h"                // for nsCString
 #include "nsTArray.h"                // for nsTArray and nsAutoTArray
 #include "nsWeakReference.h"         // for nsSupportsWeakReference
 #include "nscore.h"                  // for nsresult, nsAString, etc.
 
 class mozInlineSpellChecker;
 class nsAtom;
+class nsCaret;
 class nsIContent;
 class nsIDocumentStateListener;
 class nsIEditActionListener;
 class nsIEditorObserver;
 class nsINode;
-class nsIPresShell;
 class nsISupports;
 class nsITransferable;
 class nsITransaction;
 class nsITransactionListener;
 class nsIWidget;
 class nsRange;
 
 namespace mozilla {
@@ -72,16 +72,17 @@ class EditTransactionBase;
 class ErrorResult;
 class HTMLEditor;
 class HTMLEditUtils;
 class IMEContentObserver;
 class InsertNodeTransaction;
 class InsertTextTransaction;
 class JoinNodeTransaction;
 class PlaceholderTransaction;
+class PresShell;
 class SplitNodeResult;
 class SplitNodeTransaction;
 class TextComposition;
 class TextEditor;
 class TextEditRules;
 class TextInputListener;
 class TextServicesDocument;
 class TypeInState;
@@ -189,39 +190,41 @@ class EditorBase : public nsIEditor,
    */
   virtual void PreDestroy(bool aDestroyingFrames);
 
   bool IsInitialized() const { return !!mDocument; }
   bool Destroyed() const { return mDidPreDestroy; }
 
   Document* GetDocument() const { return mDocument; }
 
-  nsIPresShell* GetPresShell() const {
-    return mDocument ? mDocument->GetShell() : nullptr;
+  PresShell* GetPresShell() const {
+    return mDocument ? static_cast<PresShell*>(mDocument->GetShell()) : nullptr;
   }
   nsPresContext* GetPresContext() const {
-    nsIPresShell* presShell = GetPresShell();
+    PresShell* presShell = GetPresShell();
     return presShell ? presShell->GetPresContext() : nullptr;
   }
+  already_AddRefed<nsCaret> GetCaret() const {
+    PresShell* presShell = GetPresShell();
+    if (NS_WARN_IF(!presShell)) {
+      return nullptr;
+    }
+    return presShell->GetCaret();
+  }
 
   already_AddRefed<nsIWidget> GetWidget();
 
   nsISelectionController* GetSelectionController() const {
     if (mSelectionController) {
       return mSelectionController;
     }
     if (!mDocument) {
       return nullptr;
     }
-    nsIPresShell* presShell = mDocument->GetShell();
-    if (!presShell) {
-      return nullptr;
-    }
-    nsISelectionController* sc = static_cast<PresShell*>(presShell);
-    return sc;
+    return static_cast<PresShell*>(mDocument->GetShell());
   }
 
   nsresult GetSelection(SelectionType aSelectionType,
                         Selection** aSelection) const;
 
   Selection* GetSelection(
       SelectionType aSelectionType = SelectionType::eNormal) const {
     if (aSelectionType == SelectionType::eNormal &&
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -9,16 +9,17 @@
 #include "mozilla/Assertions.h"  // for MOZ_ASSERT, etc.
 #include "mozilla/AutoRestore.h"
 #include "mozilla/ContentEvents.h"         // for InternalFocusEvent
 #include "mozilla/EditorBase.h"            // for EditorBase, etc.
 #include "mozilla/EventListenerManager.h"  // for EventListenerManager
 #include "mozilla/EventStateManager.h"     // for EventStateManager
 #include "mozilla/IMEStateManager.h"       // for IMEStateManager
 #include "mozilla/Preferences.h"           // for Preferences
+#include "mozilla/PresShell.h"             // for PresShell
 #include "mozilla/TextEditor.h"            // for TextEditor
 #include "mozilla/TextEvents.h"            // for WidgetCompositionEvent
 #include "mozilla/dom/Element.h"           // for Element
 #include "mozilla/dom/Event.h"             // for Event
 #include "mozilla/dom/EventTarget.h"       // for EventTarget
 #include "mozilla/dom/MouseEvent.h"        // for MouseEvent
 #include "mozilla/dom/Selection.h"
 #include "nsAString.h"
@@ -33,17 +34,16 @@
 #include "mozilla/dom/DOMStringList.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "mozilla/dom/DragEvent.h"
 #include "mozilla/dom/Document.h"    // for Document
 #include "nsIFocusManager.h"         // for nsIFocusManager
 #include "nsIFormControl.h"          // for nsIFormControl, etc.
 #include "nsINode.h"                 // for nsINode, ::NODE_IS_EDITABLE, etc.
 #include "nsIPlaintextEditor.h"      // for nsIPlaintextEditor, etc.
-#include "nsIPresShell.h"            // for nsIPresShell
 #include "nsISelectionController.h"  // for nsISelectionController, etc.
 #include "nsITransferable.h"         // for kFileMime, kHTMLMime, etc.
 #include "nsIWidget.h"               // for nsIWidget
 #include "nsLiteralString.h"         // for NS_LITERAL_STRING
 #include "nsPIWindowRoot.h"          // for nsPIWindowRoot
 #include "nsPrintfCString.h"         // for nsPrintfCString
 #include "nsRange.h"
 #include "nsServiceManagerUtils.h"  // for do_GetService
@@ -249,23 +249,23 @@ void EditorEventListener::UninstallFromE
   elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("text"),
                                   TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("compositionstart"),
                                   TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("compositionend"),
                                   TrustedEventsAtSystemGroupBubble());
 }
 
-nsIPresShell* EditorEventListener::GetPresShell() const {
+PresShell* EditorEventListener::GetPresShell() const {
   MOZ_ASSERT(!DetachedFromEditor());
   return mEditorBase->GetPresShell();
 }
 
 nsPresContext* EditorEventListener::GetPresContext() const {
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  PresShell* presShell = GetPresShell();
   return presShell ? presShell->GetPresContext() : nullptr;
 }
 
 nsIContent* EditorEventListener::GetFocusedRootContent() {
   MOZ_ASSERT(!DetachedFromEditor());
   nsCOMPtr<nsIContent> focusedContent = mEditorBase->GetFocusedContent();
   if (!focusedContent) {
     return nullptr;
@@ -553,20 +553,24 @@ nsresult EditorEventListener::KeyPress(W
   if (!ShouldHandleNativeKeyBindings(aKeyboardEvent)) {
     return NS_OK;
   }
 
   // Now, ask the native key bindings to handle the event.
   nsIWidget* widget = aKeyboardEvent->mWidget;
   // If the event is created by chrome script, the widget is always nullptr.
   if (!widget) {
-    nsCOMPtr<nsIPresShell> ps = GetPresShell();
-    nsPresContext* pc = ps ? ps->GetPresContext() : nullptr;
-    widget = pc ? pc->GetNearestWidget() : nullptr;
-    NS_ENSURE_TRUE(widget, NS_OK);
+    nsPresContext* presContext = GetPresContext();
+    if (NS_WARN_IF(!presContext)) {
+      return NS_OK;
+    }
+    widget = presContext->GetNearestWidget();
+    if (NS_WARN_IF(!widget)) {
+      return NS_OK;
+    }
   }
 
   RefPtr<Document> doc = editorBase->GetDocument();
 
   // WidgetKeyboardEvent::ExecuteEditCommands() requires non-nullptr mWidget.
   // If the event is created by chrome script, it is nullptr but we need to
   // execute native key bindings.  Therefore, we need to set widget to
   // WidgetEvent::mWidget temporarily.
@@ -625,17 +629,17 @@ nsresult EditorEventListener::MouseClick
   //     though this makes web apps cannot prevent middle click paste with
   //     calling preventDefault() of "click" nor "auxclick".
 
   if (aMouseClickEvent->button != WidgetMouseEventBase::eMiddleButton ||
       !WidgetMouseEvent::IsMiddleClickPasteEnabled()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return NS_OK;
   }
   nsPresContext* presContext = GetPresContext();
   if (NS_WARN_IF(!presContext)) {
     return NS_OK;
   }
   MOZ_ASSERT(!aMouseClickEvent->DefaultPrevented());
@@ -684,18 +688,20 @@ nsresult EditorEventListener::MouseDown(
  * Drag event implementation
  */
 
 nsresult EditorEventListener::DragEnter(DragEvent* aDragEvent) {
   if (NS_WARN_IF(!aDragEvent) || DetachedFromEditor()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-  NS_ENSURE_TRUE(presShell, NS_OK);
+  RefPtr<PresShell> presShell = GetPresShell();
+  if (NS_WARN_IF(!presShell)) {
+    return NS_OK;
+  }
 
   if (!mCaret) {
     mCaret = new nsCaret();
     mCaret->Init(presShell);
     mCaret->SetCaretReadOnly(true);
     // This is to avoid the requirement that the Selection is Collapsed which
     // it can't be when dragging a selection in the same shell.
     // See nsCaret::IsVisible().
@@ -746,17 +752,17 @@ nsresult EditorEventListener::DragOver(D
 
 void EditorEventListener::CleanupDragDropCaret() {
   if (!mCaret) {
     return;
   }
 
   mCaret->SetVisible(false);  // hide it, so that it turns off its timer
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (presShell) {
     presShell->RestoreCaret();
   }
 
   mCaret->Terminate();
   mCaret = nullptr;
 }
 
@@ -1020,21 +1026,22 @@ nsresult EditorEventListener::Focus(Inte
     }
   }
 
   editorBase->OnFocus(target);
   if (DetachedFromEditorOrDefaultPrevented(aFocusEvent)) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPresShell> ps = GetPresShell();
-  NS_ENSURE_TRUE(ps, NS_OK);
+  nsPresContext* presContext = GetPresContext();
+  if (NS_WARN_IF(!presContext)) {
+    return NS_OK;
+  }
   nsCOMPtr<nsIContent> focusedContent = editorBase->GetFocusedContentForIME();
-  IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent,
-                                   *editorBase);
+  IMEStateManager::OnFocusInEditor(presContext, focusedContent, *editorBase);
 
   return NS_OK;
 }
 
 nsresult EditorEventListener::Blur(InternalFocusEvent* aBlurEvent) {
   if (NS_WARN_IF(!aBlurEvent) || DetachedFromEditor()) {
     return NS_OK;
   }
--- a/editor/libeditor/EditorEventListener.h
+++ b/editor/libeditor/EditorEventListener.h
@@ -11,32 +11,32 @@
 #include "nsCOMPtr.h"
 #include "nsError.h"
 #include "nsIDOMEventListener.h"
 #include "nsISupportsImpl.h"
 #include "nscore.h"
 
 class nsCaret;
 class nsIContent;
-class nsIPresShell;
 class nsPresContext;
 
 // X.h defines KeyPress
 #ifdef KeyPress
 #  undef KeyPress
 #endif
 
 #ifdef XP_WIN
 // On Windows, we support switching the text direction by pressing Ctrl+Shift
 #  define HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
 #endif
 
 namespace mozilla {
 
 class EditorBase;
+class PresShell;
 
 namespace dom {
 class DragEvent;
 class MouseEvent;
 }  // namespace dom
 
 class EditorEventListener : public nsIDOMEventListener {
  public:
@@ -81,17 +81,17 @@ class EditorEventListener : public nsIDO
   nsresult Blur(InternalFocusEvent* aBlurEvent);
   MOZ_CAN_RUN_SCRIPT nsresult DragEnter(dom::DragEvent* aDragEvent);
   MOZ_CAN_RUN_SCRIPT nsresult DragOver(dom::DragEvent* aDragEvent);
   nsresult DragExit(dom::DragEvent* aDragEvent);
   MOZ_CAN_RUN_SCRIPT nsresult Drop(dom::DragEvent* aDragEvent);
 
   MOZ_CAN_RUN_SCRIPT bool CanDrop(dom::DragEvent* aEvent);
   void CleanupDragDropCaret();
-  nsIPresShell* GetPresShell() const;
+  PresShell* GetPresShell() const;
   nsPresContext* GetPresContext() const;
   nsIContent* GetFocusedRootContent();
   // Returns true if IME consumes the mouse event.
   bool NotifyIMEOfMouseButtonEvent(WidgetMouseEvent* aMouseEvent);
   bool EditorHasFocus();
   bool IsFileControlTextBox();
   bool ShouldHandleNativeKeyBindings(WidgetKeyboardEvent* aKeyboardEvent);
 
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -7,16 +7,17 @@
 #include <math.h>
 
 #include "HTMLEditorEventListener.h"
 #include "HTMLEditRules.h"
 #include "HTMLEditUtils.h"
 #include "TextEditUtils.h"
 #include "mozilla/EditAction.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEditRules.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/EventTarget.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
@@ -25,17 +26,16 @@
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsROCSSPrimitiveValue.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMWindow.h"
 #include "nsIHTMLObjectResizer.h"
 #include "nsINode.h"
-#include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsISupportsUtils.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nscore.h"
 #include <algorithm>
@@ -296,17 +296,17 @@ void HTMLEditor::HideGrabberInternal() {
 
   DebugOnly<nsresult> rv = absolutePositioningObject->UnsetAttr(
       kNameSpaceID_None, nsGkAtoms::_moz_abspos, true);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to unset the attribute");
 
   // We allow the pres shell to be null; when it is, we presume there
   // are no document observers to notify, but we still want to
   // UnbindFromTree.
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (grabber) {
     DeleteRefToAnonymousNode(std::move(grabber), presShell);
   }
   if (positioningShadow) {
     DeleteRefToAnonymousNode(std::move(positioningShadow), presShell);
   }
 }
 
@@ -399,20 +399,22 @@ nsresult HTMLEditor::GrabberClicked() {
     return NS_OK;
   }
   mGrabberClicked = true;
   return rv;
 }
 
 nsresult HTMLEditor::EndMoving() {
   if (mPositioningShadow) {
-    nsCOMPtr<nsIPresShell> ps = GetPresShell();
-    NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
+    RefPtr<PresShell> presShell = GetPresShell();
+    if (NS_WARN_IF(!presShell)) {
+      return NS_ERROR_NOT_INITIALIZED;
+    }
 
-    DeleteRefToAnonymousNode(std::move(mPositioningShadow), ps);
+    DeleteRefToAnonymousNode(std::move(mPositioningShadow), presShell);
 
     mPositioningShadow = nullptr;
   }
 
   if (mEventListener) {
     DebugOnly<nsresult> rvIgnored =
         static_cast<HTMLEditorEventListener*>(mEventListener.get())
             ->ListenToMouseMoveEventForGrabber(false);
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/HTMLEditor.h"
 
 #include "mozilla/Attributes.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/EventTarget.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsComputedDOMStyle.h"
 #include "nsDebug.h"
 #include "nsError.h"
@@ -21,17 +22,16 @@
 #include "nsIDOMWindow.h"
 #include "mozilla/dom/Document.h"
 #include "nsIDocumentObserver.h"
 #include "nsIHTMLAbsPosEditor.h"
 #include "nsIHTMLInlineTableEditor.h"
 #include "nsIHTMLObjectResizer.h"
 #include "nsStubMutationObserver.h"
 #include "nsINode.h"
-#include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsISupportsUtils.h"
 #include "nsLiteralString.h"
 #include "nsPresContext.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nsUnicharUtils.h"
@@ -141,18 +141,18 @@ ManualNACPtr HTMLEditor::CreateAnonymous
   }
 
   RefPtr<Document> doc = GetDocument();
   if (NS_WARN_IF(!doc)) {
     return nullptr;
   }
 
   // Get the pres shell
-  nsCOMPtr<nsIPresShell> ps = GetPresShell();
-  if (NS_WARN_IF(!ps)) {
+  RefPtr<PresShell> presShell = GetPresShell();
+  if (NS_WARN_IF(!presShell)) {
     return nullptr;
   }
 
   // Create a new node through the element factory
   RefPtr<Element> newContentRaw = CreateHTMLContent(aTag);
   if (NS_WARN_IF(!newContentRaw)) {
     return nullptr;
   }
@@ -187,17 +187,17 @@ ManualNACPtr HTMLEditor::CreateAnonymous
       return nullptr;
     }
   }
 
   ManualNACPtr newContent(newContentRaw.forget());
 
   // Must style the new element, otherwise the PostRecreateFramesFor call
   // below will do nothing.
-  ServoStyleSet* styleSet = ps->StyleSet();
+  ServoStyleSet* styleSet = presShell->StyleSet();
   // Sometimes editor likes to append anonymous content to elements
   // in display:none subtrees, so avoid styling in those cases.
   if (ServoStyleSet::MayTraverseFrom(newContent)) {
     styleSet->StyleNewSubtree(newContent);
   }
 
   ElementDeletionObserver* observer =
       new ElementDeletionObserver(newContent, &aParentContent);
@@ -210,60 +210,61 @@ ManualNACPtr HTMLEditor::CreateAnonymous
   // can't _really_ deal with anonymous content (because it can't get the frame
   // tree ordering right).  But for us the ordering doesn't matter so this is
   // sort of ok.
   newContent->SetProperty(nsGkAtoms::restylableAnonymousNode,
                           reinterpret_cast<void*>(true));
 #endif  // DEBUG
 
   // display the element
-  ps->PostRecreateFramesFor(newContent);
+  presShell->PostRecreateFramesFor(newContent);
 
   return newContent;
 }
 
 // Removes event listener and calls DeleteRefToAnonymousNode.
 void HTMLEditor::RemoveListenerAndDeleteRef(const nsAString& aEvent,
                                             nsIDOMEventListener* aListener,
                                             bool aUseCapture,
                                             ManualNACPtr aElement,
-                                            nsIPresShell* aShell) {
+                                            PresShell* aPresShell) {
   if (aElement) {
     aElement->RemoveEventListener(aEvent, aListener, aUseCapture);
   }
-  DeleteRefToAnonymousNode(std::move(aElement), aShell);
+  DeleteRefToAnonymousNode(std::move(aElement), aPresShell);
 }
 
 // Deletes all references to an anonymous element
 void HTMLEditor::DeleteRefToAnonymousNode(ManualNACPtr aContent,
-                                          nsIPresShell* aShell) {
+                                          PresShell* aPresShell) {
   // call ContentRemoved() for the anonymous content
   // node so its references get removed from the frame manager's
   // undisplay map, and its layout frames get destroyed!
 
   if (NS_WARN_IF(!aContent)) {
     return;
   }
 
   nsIContent* parentContent = aContent->GetParent();
   if (NS_WARN_IF(!parentContent)) {
     // aContent was already removed?
     return;
   }
 
   nsAutoScriptBlocker scriptBlocker;
-  // Need to check whether aShell has been destroyed (but not yet deleted).
+  // Need to check whether aPresShell has been destroyed (but not yet deleted).
   // See bug 338129.
-  if (aContent->IsInComposedDoc() && aShell && !aShell->IsDestroying()) {
+  if (aContent->IsInComposedDoc() && aPresShell &&
+      !aPresShell->IsDestroying()) {
     MOZ_ASSERT(aContent->IsRootOfAnonymousSubtree());
     MOZ_ASSERT(!aContent->GetPreviousSibling(), "NAC has no siblings");
 
     // FIXME(emilio): This is the only caller to PresShell::ContentRemoved that
     // passes NAC into it. This is not great!
-    aShell->ContentRemoved(aContent, nullptr);
+    aPresShell->ContentRemoved(aContent, nullptr);
   }
 
   // The ManualNACPtr destructor will invoke UnbindFromTree.
 }
 
 void HTMLEditor::HideAnonymousEditingUIs() {
   if (mAbsolutelyPositionedObject) {
     HideGrabberInternal();
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -7,16 +7,17 @@
 
 #include "mozilla/ComposerCommandsUpdater.h"
 #include "mozilla/ContentIterator.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EditAction.h"
 #include "mozilla/EditorDOMPoint.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/mozInlineSpellChecker.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 
 #include "nsCRT.h"
 
 #include "nsUnicharUtils.h"
 
 #include "HTMLEditorEventListener.h"
 #include "HTMLEditRules.h"
@@ -33,17 +34,16 @@
 
 #include "mozilla/css/Loader.h"
 
 #include "nsIContent.h"
 #include "nsIMutableArray.h"
 #include "nsContentUtils.h"
 #include "nsIDocumentEncoder.h"
 #include "nsGenericHTMLElement.h"
-#include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsFocusManager.h"
 #include "nsPIDOMWindow.h"
 
 // netwerk
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 
@@ -191,20 +191,19 @@ HTMLEditor::HTMLEditor()
 HTMLEditor::~HTMLEditor() {
   if (mRules && mRules->AsHTMLEditRules()) {
     mRules->AsHTMLEditRules()->EndListeningToEditSubActions();
   }
 
   mTypeInState = nullptr;
 
   if (mLinkHandler && IsInitialized()) {
-    nsCOMPtr<nsIPresShell> ps = GetPresShell();
-
-    if (ps && ps->GetPresContext()) {
-      ps->GetPresContext()->SetLinkHandler(mLinkHandler);
+    PresShell* presShell = GetPresShell();
+    if (presShell && presShell->GetPresContext()) {
+      presShell->GetPresContext()->SetLinkHandler(mLinkHandler);
     }
   }
 
   RemoveEventListeners();
 
   HideAnonymousEditingUIs();
 }
 
@@ -296,18 +295,20 @@ nsresult HTMLEditor::Init(Document& aDoc
       SetAbsolutePositioningEnabled(false);
       SetSnapToGridEnabled(false);
     }
 
     // Init the HTML-CSS utils
     mCSSEditUtils = MakeUnique<CSSEditUtils>(this);
 
     // disable links
-    nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-    NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
+    PresShell* presShell = GetPresShell();
+    if (NS_WARN_IF(!presShell)) {
+      return NS_ERROR_FAILURE;
+    }
     nsPresContext* context = presShell->GetPresContext();
     NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
     if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
       mLinkHandler = context->GetLinkHandler();
       context->SetLinkHandler(nullptr);
     }
 
     // init the type-in state
@@ -3078,17 +3079,17 @@ HTMLEditor::AddOverrideStyleSheet(const 
 
 nsresult HTMLEditor::AddOverrideStyleSheetInternal(const nsAString& aURL) {
   // Enable existing sheet if already loaded.
   if (EnableExistingStyleSheet(aURL)) {
     return NS_OK;
   }
 
   // Make sure the pres shell doesn't disappear during the load.
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsCOMPtr<nsIURI> uaURI;
   nsresult rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
@@ -3179,17 +3180,17 @@ nsresult HTMLEditor::RemoveOverrideStyle
 
   // Make sure we remove the stylesheet from our internal list in all
   // cases.
   RefPtr<StyleSheet> sheet = RemoveStyleSheetFromList(aURL);
   if (!sheet) {
     return NS_OK;  // It's okay even if not found.
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   presShell->RemoveOverrideStyleSheet(sheet);
   presShell->ApplicableStylesChanged();
 
   return NS_OK;
@@ -3641,18 +3642,18 @@ nsresult HTMLEditor::SelectAllInternal()
   }
 
   nsIContent* anchorContent = anchorNode->AsContent();
   nsIContent* rootContent;
   if (anchorContent->HasIndependentSelection()) {
     SelectionRefPtr()->SetAncestorLimiter(nullptr);
     rootContent = mRootElement;
   } else {
-    nsCOMPtr<nsIPresShell> ps = GetPresShell();
-    rootContent = anchorContent->GetSelectionRootContent(ps);
+    RefPtr<PresShell> presShell = GetPresShell();
+    rootContent = anchorContent->GetSelectionRootContent(presShell);
   }
 
   if (NS_WARN_IF(!rootContent)) {
     return NS_ERROR_UNEXPECTED;
   }
 
   Maybe<Selection::AutoUserInitiated> userSelection;
   if (!rootContent->IsEditable()) {
@@ -4599,24 +4600,28 @@ nsresult HTMLEditor::CopyLastEditableChi
 nsresult HTMLEditor::GetElementOrigin(Element& aElement, int32_t& aX,
                                       int32_t& aY) {
   aX = 0;
   aY = 0;
 
   if (NS_WARN_IF(!IsInitialized())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
-  nsCOMPtr<nsIPresShell> ps = GetPresShell();
-  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
+  PresShell* presShell = GetPresShell();
+  if (NS_WARN_IF(!presShell)) {
+    return NS_ERROR_NOT_INITIALIZED;
+  }
 
   nsIFrame* frame = aElement.GetPrimaryFrame();
   NS_ENSURE_TRUE(frame, NS_OK);
 
-  nsIFrame* container = ps->GetAbsoluteContainingBlock(frame);
-  NS_ENSURE_TRUE(container, NS_OK);
+  nsIFrame* container = presShell->GetAbsoluteContainingBlock(frame);
+  if (NS_WARN_IF(!container)) {
+    return NS_OK;
+  }
   nsPoint off = frame->GetOffsetTo(container);
   aX = nsPresContext::AppUnitsToIntCSSPixels(off.x);
   aY = nsPresContext::AppUnitsToIntCSSPixels(off.y);
 
   return NS_OK;
 }
 
 Element* HTMLEditor::GetSelectionContainerElement() const {
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -2121,18 +2121,18 @@ class HTMLEditor final : public TextEdit
    *                    insure we reset the caret in a table-editing method.
    */
   void SetSelectionAfterTableEdit(Element* aTable, int32_t aRow, int32_t aCol,
                                   int32_t aDirection, bool aSelected);
 
   void RemoveListenerAndDeleteRef(const nsAString& aEvent,
                                   nsIDOMEventListener* aListener,
                                   bool aUseCapture, ManualNACPtr aElement,
-                                  nsIPresShell* aShell);
-  void DeleteRefToAnonymousNode(ManualNACPtr aContent, nsIPresShell* aShell);
+                                  PresShell* aPresShell);
+  void DeleteRefToAnonymousNode(ManualNACPtr aContent, PresShell* aPresShell);
 
   /**
    * RefereshEditingUI() may refresh editing UIs for current Selection, focus,
    * etc.  If this shows or hides some UIs, it causes reflow.  So, this is
    * not safe method.
    */
   nsresult RefereshEditingUI();
 
--- a/editor/libeditor/HTMLEditorDocumentCommands.cpp
+++ b/editor/libeditor/HTMLEditorDocumentCommands.cpp
@@ -11,17 +11,16 @@
 #include "nsCRT.h"                       // for nsCRT
 #include "nsDebug.h"                     // for NS_ENSURE_ARG_POINTER, etc
 #include "nsError.h"                     // for NS_ERROR_INVALID_ARG, etc
 #include "nsIDocShell.h"                 // for nsIDocShell
 #include "mozilla/dom/Document.h"        // for Document
 #include "nsIEditingSession.h"           // for nsIEditingSession, etc
 #include "nsIEditor.h"                   // for nsIEditor
 #include "nsIPlaintextEditor.h"          // for nsIPlaintextEditor, etc
-#include "nsIPresShell.h"                // for nsIPresShell
 #include "nsISelectionController.h"      // for nsISelectionController
 #include "nsISupportsImpl.h"             // for nsPresContext::Release
 #include "nsISupportsUtils.h"            // for NS_IF_ADDREF
 #include "nsIURI.h"                      // for nsIURI
 #include "nsPresContext.h"               // for nsPresContext
 #include "nscore.h"                      // for NS_IMETHODIMP, nsresult, etc
 
 class nsISupports;
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -6,31 +6,31 @@
 #include "mozilla/HTMLEditor.h"
 
 #include "HTMLEditorEventListener.h"
 #include "HTMLEditUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/MouseEvent.h"
 #include "mozilla/dom/EventTarget.h"
 #include "nsAString.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsIContent.h"
 #include "nsID.h"
 #include "mozilla/dom/Document.h"
-#include "nsIPresShell.h"
 #include "nsISupportsUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nscore.h"
 #include <algorithm>
 
@@ -444,17 +444,17 @@ nsresult HTMLEditor::HideResizersInterna
   // Don't warn even if resizers are visible since script cannot check
   // if they are visible and this is non-virtual method.  So, the cost of
   // calling this can be ignored.
   if (!mResizedObject) {
     return NS_OK;
   }
 
   // get the presshell's document observer interface.
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   NS_WARNING_ASSERTION(presShell, "There is no presShell");
   // We allow the pres shell to be null; when it is, we presume there
   // are no document observers to notify, but we still want to
   // UnbindFromTree.
 
   NS_NAMED_LITERAL_STRING(mousedown, "mousedown");
 
   // HTMLEditor should forget all members related to resizers first since
--- a/editor/libeditor/HTMLInlineTableEditor.cpp
+++ b/editor/libeditor/HTMLInlineTableEditor.cpp
@@ -1,24 +1,24 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/HTMLEditor.h"
 
 #include "HTMLEditUtils.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Element.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIContent.h"
 #include "nsIHTMLObjectResizer.h"
-#include "nsIPresShell.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nscore.h"
 
 namespace mozilla {
 
 NS_IMETHODIMP
@@ -162,38 +162,38 @@ void HTMLEditor::HideInlineTableEditingU
   RemoveMouseClickListener(mAddColumnBeforeButton);
   RemoveMouseClickListener(mRemoveColumnButton);
   RemoveMouseClickListener(mAddColumnAfterButton);
   RemoveMouseClickListener(mAddRowBeforeButton);
   RemoveMouseClickListener(mRemoveRowButton);
   RemoveMouseClickListener(mAddRowAfterButton);
 
   // get the presshell's document observer interface.
-  nsCOMPtr<nsIPresShell> ps = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   // We allow the pres shell to be null; when it is, we presume there
   // are no document observers to notify, but we still want to
   // UnbindFromTree.
 
   // Calling DeleteRefToAnonymousNode() may cause showing the UI again.
   // Therefore, we should forget all anonymous contents first.
   // Otherwise, we could leak the old content because of overwritten by
   // ShowInlineTableEditingUIInternal().
   ManualNACPtr addColumnBeforeButton(std::move(mAddColumnBeforeButton));
   ManualNACPtr removeColumnButton(std::move(mRemoveColumnButton));
   ManualNACPtr addColumnAfterButton(std::move(mAddColumnAfterButton));
   ManualNACPtr addRowBeforeButton(std::move(mAddRowBeforeButton));
   ManualNACPtr removeRowButton(std::move(mRemoveRowButton));
   ManualNACPtr addRowAfterButton(std::move(mAddRowAfterButton));
 
-  DeleteRefToAnonymousNode(std::move(addColumnBeforeButton), ps);
-  DeleteRefToAnonymousNode(std::move(removeColumnButton), ps);
-  DeleteRefToAnonymousNode(std::move(addColumnAfterButton), ps);
-  DeleteRefToAnonymousNode(std::move(addRowBeforeButton), ps);
-  DeleteRefToAnonymousNode(std::move(removeRowButton), ps);
-  DeleteRefToAnonymousNode(std::move(addRowAfterButton), ps);
+  DeleteRefToAnonymousNode(std::move(addColumnBeforeButton), presShell);
+  DeleteRefToAnonymousNode(std::move(removeColumnButton), presShell);
+  DeleteRefToAnonymousNode(std::move(addColumnAfterButton), presShell);
+  DeleteRefToAnonymousNode(std::move(addRowBeforeButton), presShell);
+  DeleteRefToAnonymousNode(std::move(removeRowButton), presShell);
+  DeleteRefToAnonymousNode(std::move(addRowAfterButton), presShell);
 }
 
 nsresult HTMLEditor::DoInlineTableEditingAction(const Element& aElement) {
   nsAutoString anonclass;
   aElement.GetAttr(kNameSpaceID_None, nsGkAtoms::_moz_anonclass, anonclass);
 
   if (!StringBeginsWith(anonclass, NS_LITERAL_STRING("mozTable"))) {
     return NS_OK;
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -8,30 +8,30 @@
 #include "mozilla/HTMLEditor.h"
 
 #include "HTMLEditUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/EditAction.h"
 #include "mozilla/EditorDOMPoint.h"
 #include "mozilla/EditorUtils.h"
 #include "mozilla/FlushType.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Element.h"
 #include "nsAString.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsFrameSelection.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsIContent.h"
 #include "nsIFrame.h"
 #include "nsINode.h"
-#include "nsIPresShell.h"
 #include "nsISupportsUtils.h"
 #include "nsITableCellLayout.h"  // For efficient access to table cell
 #include "nsLiteralString.h"
 #include "nsQueryFrame.h"
 #include "nsRange.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsTableCellFrame.h"
@@ -767,17 +767,17 @@ nsresult HTMLEditor::InsertTableRowsWith
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   // SetSelectionAfterTableEdit from AutoSelectionSetterAfterTableEdit will
   // access frame selection, so we need reframe.
   // Because GetTableCellElementAt() depends on frame.
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (presShell) {
     presShell->FlushPendingNotifications(FlushType::Frames);
   }
 
   return NS_OK;
 }
 
 nsresult HTMLEditor::DeleteTableElementAndChildrenWithTransaction(
--- a/editor/libeditor/TextEditRulesBidi.cpp
+++ b/editor/libeditor/TextEditRulesBidi.cpp
@@ -8,17 +8,16 @@
 #include "mozilla/TextEditor.h"
 #include "mozilla/dom/Selection.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsFrameSelection.h"
 #include "nsIContent.h"
 #include "nsIEditor.h"
-#include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsPresContext.h"
 #include "nscore.h"
 
 namespace mozilla {
 
 using namespace dom;
 
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -13,16 +13,17 @@
 #include "mozilla/Assertions.h"
 #include "mozilla/ContentIterator.h"
 #include "mozilla/EditAction.h"
 #include "mozilla/EditorDOMPoint.h"
 #include "mozilla/HTMLEditor.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEditRules.h"
 #include "mozilla/TextComposition.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TextServicesDocument.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/Element.h"
 #include "nsAString.h"
@@ -37,17 +38,16 @@
 #include "nsDependentSubstring.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsIAbsorbingTransaction.h"
 #include "nsIClipboard.h"
 #include "nsIContent.h"
 #include "nsIDocumentEncoder.h"
 #include "nsINode.h"
-#include "nsIPresShell.h"
 #include "nsISelectionController.h"
 #include "nsISupportsPrimitives.h"
 #include "nsITransferable.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsNameSpaceManager.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsServiceManagerUtils.h"
@@ -1317,18 +1317,17 @@ nsresult TextEditor::OnCompositionChange
     MOZ_ASSERT(!aCompositionChangeEvent.mData.IsVoid());
     editActionData.SetData(aCompositionChangeEvent.mData);
   }
 
   if (!EnsureComposition(aCompositionChangeEvent)) {
     return NS_OK;
   }
 
-  nsIPresShell* presShell = GetPresShell();
-  if (NS_WARN_IF(!presShell)) {
+  if (NS_WARN_IF(!GetPresShell())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // NOTE: TextComposition should receive selection change notification before
   //       CompositionChangeEventHandlingMarker notifies TextComposition of the
   //       end of handling compositionchange event because TextComposition may
   //       need to ignore selection changes caused by composition.  Therefore,
   //       CompositionChangeEventHandlingMarker must be destroyed after a call
@@ -1337,31 +1336,31 @@ nsresult TextEditor::OnCompositionChange
   //       TextComposition of a selection change.
   MOZ_ASSERT(
       !mPlaceholderBatch,
       "UpdateIMEComposition() must be called without place holder batch");
   TextComposition::CompositionChangeEventHandlingMarker
       compositionChangeEventHandlingMarker(mComposition,
                                            &aCompositionChangeEvent);
 
-  RefPtr<nsCaret> caretP = presShell->GetCaret();
+  RefPtr<nsCaret> caret = GetCaret();
 
   nsresult rv;
   {
     AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::IMETxnName);
 
     MOZ_ASSERT(
         mIsInEditSubAction,
         "AutoPlaceholderBatch should've notified the observes of before-edit");
     rv = InsertTextAsSubAction(aCompositionChangeEvent.mData);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                          "Failed to insert new composition string");
 
-    if (caretP) {
-      caretP->SetSelection(SelectionRefPtr());
+    if (caret) {
+      caret->SetSelection(SelectionRefPtr());
     }
   }
 
   // If still composing, we should fire input event via observer.
   // Note that if the composition will be committed by the following
   // compositionend event, we don't need to notify editor observes of this
   // change.
   // NOTE: We must notify after the auto batch will be gone.
@@ -1750,17 +1749,17 @@ bool TextEditor::FireClipboardEvent(Even
                                     int32_t aSelectionType,
                                     bool* aActionTaken) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   if (aEventMessage == ePaste) {
     CommitComposition();
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return false;
   }
 
   if (!nsCopySupport::FireClipboardEvent(aEventMessage, aSelectionType,
                                          presShell, SelectionRefPtr(),
                                          aActionTaken)) {
     return false;