Bug 1544343 - part 3: Make layout use mozilla::PresShell instead of nsIPresShell as far as possible r=emilio
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 16 Apr 2019 07:25:10 +0000
changeset 469632 35aed2f899c3
parent 469631 4b56de3cd46c
child 469633 904d371bd450
push id35878
push userapavel@mozilla.com
push dateTue, 16 Apr 2019 15:43:40 +0000
treeherdermozilla-central@258af4e91151 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1544343
milestone68.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 1544343 - part 3: Make layout use mozilla::PresShell instead of nsIPresShell as far as possible r=emilio This patch changes remaining things under `layout/`. However, there are some places which still need to use `nsIPresShell`. That will be fixed in a follow up bug. Differential Revision: https://phabricator.services.mozilla.com/D27477
layout/base/AccessibleCaret.cpp
layout/base/AccessibleCaret.h
layout/base/AccessibleCaretEventHub.cpp
layout/base/AccessibleCaretEventHub.h
layout/base/AccessibleCaretManager.cpp
layout/base/AccessibleCaretManager.h
layout/base/GeckoMVMContext.cpp
layout/base/GeckoMVMContext.h
layout/base/MobileViewportManager.h
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/RestyleManager.cpp
layout/base/ZoomConstraintsClient.cpp
layout/base/ZoomConstraintsClient.h
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCaret.cpp
layout/base/nsCaret.h
layout/base/nsFrameManager.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/base/nsRefreshDriver.cpp
layout/base/nsRefreshDriver.h
layout/base/nsStyleSheetService.cpp
layout/base/nsStyleSheetService.h
layout/doc/DD-SpaceManager.html
layout/forms/nsTextControlFrame.cpp
layout/generic/nsContainerFrame.cpp
layout/generic/nsContainerFrame.h
layout/generic/nsFloatManager.cpp
layout/generic/nsFloatManager.h
layout/generic/nsFrame.cpp
layout/generic/nsFrame.h
layout/generic/nsFrameList.cpp
layout/generic/nsFrameList.h
layout/generic/nsFrameSelection.cpp
layout/generic/nsIFrame.h
layout/generic/nsImageFrame.cpp
layout/generic/nsImageFrame.h
layout/generic/nsIntervalSet.cpp
layout/generic/nsIntervalSet.h
layout/generic/nsLineBox.cpp
layout/generic/nsLineBox.h
layout/generic/nsSubDocumentFrame.cpp
layout/generic/nsSubDocumentFrame.h
layout/painting/RetainedDisplayListBuilder.cpp
layout/painting/nsDisplayList.cpp
layout/painting/nsDisplayList.h
layout/printing/nsPrintJob.cpp
layout/printing/nsPrintJob.h
layout/printing/nsPrintObject.cpp
layout/printing/nsPrintObject.h
layout/style/ComputedStyle.h
layout/style/CounterStyleManager.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/nsFontFaceUtils.cpp
layout/svg/SVGObserverUtils.cpp
layout/xul/nsBoxLayoutState.h
layout/xul/nsGroupBoxFrame.cpp
layout/xul/nsIPopupContainer.h
layout/xul/nsResizerFrame.cpp
layout/xul/nsResizerFrame.h
layout/xul/nsRootBoxFrame.cpp
layout/xul/nsSliderFrame.cpp
layout/xul/nsStackFrame.cpp
layout/xul/nsStackLayout.h
layout/xul/nsXULPopupManager.cpp
layout/xul/nsXULPopupManager.h
--- a/layout/base/AccessibleCaret.cpp
+++ b/layout/base/AccessibleCaret.cpp
@@ -3,16 +3,17 @@
 /* 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 "AccessibleCaret.h"
 
 #include "AccessibleCaretLogger.h"
 #include "mozilla/FloatingPoint.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/ToString.h"
 #include "nsCanvasFrame.h"
 #include "nsCaret.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsDOMTokenList.h"
 #include "nsIFrame.h"
 #include "nsPlaceholderFrame.h"
@@ -61,17 +62,17 @@ std::ostream& operator<<(
   }
   return aStream;
 }
 #undef AC_PROCESS_ENUM_TO_STREAM
 
 // -----------------------------------------------------------------------------
 // Implementation of AccessibleCaret methods
 
-AccessibleCaret::AccessibleCaret(nsIPresShell* aPresShell)
+AccessibleCaret::AccessibleCaret(PresShell* aPresShell)
     : mPresShell(aPresShell) {
   // Check all resources required.
   if (mPresShell) {
     MOZ_ASSERT(RootFrame());
     MOZ_ASSERT(mPresShell->GetDocument());
     InjectCaretElement(mPresShell->GetDocument());
   }
 }
--- a/layout/base/AccessibleCaret.h
+++ b/layout/base/AccessibleCaret.h
@@ -15,21 +15,20 @@
 #include "nsISupportsBase.h"
 #include "nsISupportsImpl.h"
 #include "nsLiteralString.h"
 #include "nsRect.h"
 #include "mozilla/RefPtr.h"
 #include "nsString.h"
 
 class nsIFrame;
-class nsIPresShell;
 struct nsPoint;
 
 namespace mozilla {
-
+class PresShell;
 namespace dom {
 class Event;
 }  // namespace dom
 
 // -----------------------------------------------------------------------------
 // Upon the creation of AccessibleCaret, it will insert DOM Element as an
 // anonymous content containing the caret image. The caret appearance and
 // position can be controlled by SetAppearance() and SetPosition().
@@ -41,17 +40,17 @@ class Event;
 // that SetPosition() works correctly, the caller must make sure the layout is
 // up to date.
 //
 // Please see the wiki page for more information.
 // https://wiki.mozilla.org/AccessibleCaret
 //
 class AccessibleCaret {
  public:
-  explicit AccessibleCaret(nsIPresShell* aPresShell);
+  explicit AccessibleCaret(PresShell* aPresShell);
   virtual ~AccessibleCaret();
 
   // This enumeration representing the visibility and visual style of an
   // AccessibleCaret.
   //
   // Use SetAppearance() to change the appearance, and use GetAppearance() to
   // get the current appearance.
   enum class Appearance : uint8_t {
@@ -188,17 +187,17 @@ class AccessibleCaret {
 
   // Member variables
   Appearance mAppearance = Appearance::None;
 
   // AccessibleCaretManager owns us by a UniquePtr. When it's terminated by
   // AccessibleCaretEventHub::Terminate() which is called in
   // PresShell::Destroy(), it frees us automatically. No need to worry if we
   // outlive mPresShell.
-  nsIPresShell* const MOZ_NON_OWNING_REF mPresShell = nullptr;
+  PresShell* const MOZ_NON_OWNING_REF mPresShell = nullptr;
 
   RefPtr<dom::AnonymousContent> mCaretElementHolder;
 
   // mImaginaryCaretRect is relative to root frame.
   nsRect mImaginaryCaretRect;
 
   // Cache current zoom level to determine whether position is changed.
   float mZoomLevel = 0.0f;
--- a/layout/base/AccessibleCaretEventHub.cpp
+++ b/layout/base/AccessibleCaretEventHub.cpp
@@ -7,26 +7,27 @@
 #include "AccessibleCaretEventHub.h"
 
 #include "AccessibleCaretLogger.h"
 #include "AccessibleCaretManager.h"
 #include "Layers.h"
 #include "gfxPrefs.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
+#include "mozilla/dom/Document.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/dom/Selection.h"
 #include "nsCanvasFrame.h"
 #include "nsDocShell.h"
 #include "nsFocusManager.h"
 #include "nsFrameSelection.h"
-#include "mozilla/dom/Document.h"
 #include "nsITimer.h"
 #include "nsPresContext.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 namespace mozilla {
 
@@ -315,17 +316,17 @@ void AccessibleCaretEventHub::SetState(S
 
 MOZ_IMPL_STATE_CLASS_GETTER(NoActionState)
 MOZ_IMPL_STATE_CLASS_GETTER(PressCaretState)
 MOZ_IMPL_STATE_CLASS_GETTER(DragCaretState)
 MOZ_IMPL_STATE_CLASS_GETTER(PressNoCaretState)
 MOZ_IMPL_STATE_CLASS_GETTER(ScrollState)
 MOZ_IMPL_STATE_CLASS_GETTER(LongTapState)
 
-AccessibleCaretEventHub::AccessibleCaretEventHub(nsIPresShell* aPresShell)
+AccessibleCaretEventHub::AccessibleCaretEventHub(PresShell* aPresShell)
     : mPresShell(aPresShell) {}
 
 void AccessibleCaretEventHub::Init() {
   if (mInitialized && mManager) {
     mManager->OnFrameReconstruction();
   }
 
   if (mInitialized || !mPresShell || !mPresShell->GetCanvasFrame()) {
--- a/layout/base/AccessibleCaretEventHub.h
+++ b/layout/base/AccessibleCaretEventHub.h
@@ -14,21 +14,21 @@
 #include "nsDocShell.h"
 #include "nsIFrame.h"
 #include "nsIReflowObserver.h"
 #include "nsIScrollObserver.h"
 #include "nsPoint.h"
 #include "mozilla/RefPtr.h"
 #include "nsWeakReference.h"
 
-class nsIPresShell;
 class nsITimer;
 
 namespace mozilla {
 class AccessibleCaretManager;
+class PresShell;
 class WidgetKeyboardEvent;
 class WidgetMouseEvent;
 class WidgetTouchEvent;
 
 // -----------------------------------------------------------------------------
 // Each PresShell holds a shared pointer to an AccessibleCaretEventHub; each
 // AccessibleCaretEventHub holds a unique pointer to an AccessibleCaretManager.
 // Thus, there's one AccessibleCaretManager per PresShell.
@@ -58,17 +58,17 @@ class WidgetTouchEvent;
 //
 // Please see the wiki page for more information.
 // https://wiki.mozilla.org/AccessibleCaret
 //
 class AccessibleCaretEventHub : public nsIReflowObserver,
                                 public nsIScrollObserver,
                                 public nsSupportsWeakReference {
  public:
-  explicit AccessibleCaretEventHub(nsIPresShell* aPresShell);
+  explicit AccessibleCaretEventHub(PresShell* aPresShell);
   void Init();
   void Terminate();
 
   MOZ_CAN_RUN_SCRIPT
   nsEventStatus HandleEvent(WidgetEvent* aEvent);
 
   // Call this function to notify the blur event happened.
   MOZ_CAN_RUN_SCRIPT
@@ -146,17 +146,17 @@ class AccessibleCaretEventHub : public n
 
   MOZ_CAN_RUN_SCRIPT_BOUNDARY
   static void FireScrollEnd(nsITimer* aTimer, void* aAccessibleCaretEventHub);
 
   // Member variables
   State* mState = NoActionState();
 
   // Will be set to nullptr in Terminate().
-  nsIPresShell* MOZ_NON_OWNING_REF mPresShell = nullptr;
+  PresShell* MOZ_NON_OWNING_REF mPresShell = nullptr;
 
   UniquePtr<AccessibleCaretManager> mManager;
 
   WeakPtr<nsDocShell> mDocShell;
 
   // Use this timer for injecting a long tap event when APZ is disabled. If APZ
   // is enabled, it will send long tap event to us.
   nsCOMPtr<nsITimer> mLongTapInjectorTimer;
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -66,17 +66,17 @@ std::ostream& operator<<(
     AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::Default);
     AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::RespectOldAppearance);
     AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::DispatchNoEvent);
   }
   return aStream;
 }
 #undef AC_PROCESS_ENUM_TO_STREAM
 
-AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
+AccessibleCaretManager::AccessibleCaretManager(PresShell* aPresShell)
     : mPresShell(aPresShell) {
   if (!mPresShell) {
     return;
   }
 
   mFirstCaret = MakeUnique<AccessibleCaret>(mPresShell);
   mSecondCaret = MakeUnique<AccessibleCaret>(mPresShell);
 }
--- a/layout/base/AccessibleCaretManager.h
+++ b/layout/base/AccessibleCaretManager.h
@@ -18,21 +18,20 @@
 #include "nsCOMPtr.h"
 #include "nsCoord.h"
 #include "nsIFrame.h"
 #include "nsISelectionListener.h"
 
 class nsFrameSelection;
 class nsIContent;
 
-class nsIPresShell;
 struct nsPoint;
 
 namespace mozilla {
-
+class PresShell;
 namespace dom {
 class Element;
 class Selection;
 }  // namespace dom
 
 // -----------------------------------------------------------------------------
 // AccessibleCaretManager does not deal with events or callbacks directly. It
 // relies on AccessibleCaretEventHub to call its public methods to do the work.
@@ -43,17 +42,17 @@ class Selection;
 // prior to performing its task. The caller must ensure the layout is up to
 // date.
 //
 // Please see the wiki page for more information.
 // https://wiki.mozilla.org/AccessibleCaret
 //
 class AccessibleCaretManager {
  public:
-  explicit AccessibleCaretManager(nsIPresShell* aPresShell);
+  explicit AccessibleCaretManager(PresShell* aPresShell);
   virtual ~AccessibleCaretManager();
 
   // Called by AccessibleCaretEventHub to inform us that PresShell is destroyed.
   void Terminate();
 
   // The aPoint in the following public methods should be relative to root
   // frame.
 
@@ -290,17 +289,17 @@ class AccessibleCaretManager {
   //
   nscoord mOffsetYToCaretLogicalPosition = NS_UNCONSTRAINEDSIZE;
 
   // AccessibleCaretEventHub owns us by a UniquePtr. When it's destroyed, we'll
   // also be destroyed. No need to worry if we outlive mPresShell.
   //
   // mPresShell will be set to nullptr in Terminate(). Therefore mPresShell is
   // nullptr either we are in gtest or PresShell::IsDestroying() is true.
-  nsIPresShell* MOZ_NON_OWNING_REF mPresShell = nullptr;
+  PresShell* MOZ_NON_OWNING_REF mPresShell = nullptr;
 
   // First caret is attached to nsCaret in cursor mode, and is attached to
   // selection highlight as the left caret in selection mode.
   UniquePtr<AccessibleCaret> mFirstCaret;
 
   // Second caret is used solely in selection mode, and is attached to selection
   // highlight as the right caret.
   UniquePtr<AccessibleCaret> mSecondCaret;
--- a/layout/base/GeckoMVMContext.cpp
+++ b/layout/base/GeckoMVMContext.cpp
@@ -1,29 +1,29 @@
 /* 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 "GeckoMVMContext.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/Document.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMEventListener.h"
 #include "nsIFrame.h"
 #include "nsIObserverService.h"
-#include "nsIPresShell.h"
 #include "nsLayoutUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsPresContext.h"
 
 namespace mozilla {
 
 GeckoMVMContext::GeckoMVMContext(dom::Document* aDocument,
-                                 nsIPresShell* aPresShell)
+                                 PresShell* aPresShell)
     : mDocument(aDocument), mPresShell(aPresShell) {
   if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
     mEventTarget = window->GetChromeEventHandler();
   }
 }
 
 void GeckoMVMContext::AddEventListener(const nsAString& aType,
                                        nsIDOMEventListener* aListener,
@@ -157,17 +157,17 @@ void GeckoMVMContext::UpdateDisplayPortM
     nsIScrollableFrame* scrollable = do_QueryFrame(root);
     nsLayoutUtils::CalculateAndSetDisplayPortMargins(
         scrollable, nsLayoutUtils::RepaintMode::DoNotRepaint);
   }
 }
 
 void GeckoMVMContext::Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize) {
   MOZ_ASSERT(mPresShell);
-  nsCOMPtr<nsIPresShell> presShell = mPresShell;
+  RefPtr<PresShell> presShell = mPresShell;
   presShell->ResizeReflowIgnoreOverride(
       nsPresContext::CSSPixelsToAppUnits(aNewSize.width),
       nsPresContext::CSSPixelsToAppUnits(aNewSize.height),
       nsPresContext::CSSPixelsToAppUnits(aOldSize.width),
       nsPresContext::CSSPixelsToAppUnits(aOldSize.height));
 }
 
 }  // namespace mozilla
--- a/layout/base/GeckoMVMContext.h
+++ b/layout/base/GeckoMVMContext.h
@@ -6,32 +6,31 @@
 #define GeckoMVMContext_h_
 
 #include "MVMContext.h"
 
 #include "mozilla/Attributes.h"  // for MOZ_NON_OWNING_REF
 #include "mozilla/RefPtr.h"
 #include "nsCOMPtr.h"
 
-class nsIPresShell;
-
 namespace mozilla {
+class PresShell;
 namespace dom {
 class Document;
 class EventTarget;
 }  // namespace dom
 
 /**
  * An implementation of MVMContext that uses actual Gecko components.
  * This is intended for production use (whereas TestMVMContext is intended for
  * testing.)
  */
 class GeckoMVMContext : public MVMContext {
  public:
-  explicit GeckoMVMContext(dom::Document* aDocument, nsIPresShell* aPresShell);
+  explicit GeckoMVMContext(dom::Document* aDocument, PresShell* aPresShell);
   void AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
                         bool aUseCapture) override;
   void RemoveEventListener(const nsAString& aType,
                            nsIDOMEventListener* aListener,
                            bool aUseCapture) override;
   void AddObserver(nsIObserver* aObserver, const char* aTopic,
                    bool aOwnsWeak) override;
   void RemoveObserver(nsIObserver* aObserver, const char* aTopic) override;
@@ -53,15 +52,15 @@ class GeckoMVMContext : public MVMContex
   void SetVisualViewportSize(const CSSSize& aSize) override;
   void UpdateDisplayPortMargins() override;
   MOZ_CAN_RUN_SCRIPT_BOUNDARY
   void Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize) override;
 
  private:
   RefPtr<dom::Document> mDocument;
   // raw ref since the presShell owns this
-  nsIPresShell* MOZ_NON_OWNING_REF mPresShell;
+  PresShell* MOZ_NON_OWNING_REF mPresShell;
   nsCOMPtr<dom::EventTarget> mEventTarget;
 };
 
 }  // namespace mozilla
 
 #endif  // GeckoMVMContext_h_
--- a/layout/base/MobileViewportManager.h
+++ b/layout/base/MobileViewportManager.h
@@ -9,17 +9,16 @@
 
 #include "mozilla/Maybe.h"
 #include "mozilla/MVMContext.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMEventListener.h"
 #include "nsIObserver.h"
 #include "Units.h"
 
-class nsIPresShell;
 class nsViewportInfo;
 
 namespace mozilla {
 class MVMContext;
 namespace dom {
 class Document;
 class EventTarget;
 }  // namespace dom
@@ -45,17 +44,17 @@ class MobileViewportManager final : publ
                             mozilla::LayoutDeviceIntSize aDisplaySize);
 
   /* Compute the "intrinsic resolution", which is the smallest resolution at
    * which the layout viewport fills the visual viewport. (In typical
    * scenarios, where the aspect ratios of the two viewports match, it's the
    * resolution at which they are the same size.)
    *
    * The returned resolution is suitable for passing to
-   * nsIPresShell::SetResolutionAndScaleTo(). It's not in typed units for
+   * PresShell::SetResolutionAndScaleTo(). It's not in typed units for
    * reasons explained at the declaration of FrameMetrics::mPresShellResolution.
    */
   float ComputeIntrinsicResolution() const;
 
  private:
   void SetRestoreResolution(float aResolution);
 
  public:
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -362,17 +362,17 @@ class ReflowCountMgr {
                   nsPresContext* aPresContext, nsIFrame* aFrame,
                   const nsPoint& aOffset, uint32_t aColor);
 
   FILE* GetOutFile() { return mFD; }
 
   void SetPresContext(nsPresContext* aPresContext) {
     mPresContext = aPresContext;  // weak reference
   }
-  void SetPresShell(nsIPresShell* aPresShell) {
+  void SetPresShell(PresShell* aPresShell) {
     mPresShell = aPresShell;  // weak reference
   }
 
   void SetDumpFrameCounts(bool aVal) { mDumpFrameCounts = aVal; }
   void SetDumpFrameByFrameCounts(bool aVal) { mDumpFrameByFrameCounts = aVal; }
   void SetPaintFrameCounts(bool aVal) { mPaintFrameByFrameCounts = aVal; }
 
   bool IsPaintingFrameCounts() { return mPaintFrameByFrameCounts; }
@@ -394,17 +394,17 @@ class ReflowCountMgr {
   bool mDumpFrameCounts;
   bool mDumpFrameByFrameCounts;
   bool mPaintFrameByFrameCounts;
 
   bool mCycledOnce;
 
   // Root Frame for Individual Tracking
   nsPresContext* mPresContext;
-  nsIPresShell* mPresShell;
+  PresShell* mPresShell;
 
   // ReflowCountMgr gReflowCountMgr;
 };
 #endif
 //========================================================================
 
 // comment out to hide caret
 #define SHOW_CARET
@@ -424,49 +424,50 @@ struct nsCallbackEventRequest {
 };
 
 // ----------------------------------------------------------------------------
 //
 // NOTE(emilio): It'd be nice for this to assert that our document isn't in the
 // bfcache, but font pref changes don't care about that, and maybe / probably
 // shouldn't.
 #ifdef DEBUG
-#  define ASSERT_REFLOW_SCHEDULED_STATE()                                   \
-    {                                                                       \
-      if (ObservingLayoutFlushes()) {                                       \
-        MOZ_ASSERT(                                                         \
-            mDocument->GetBFCacheEntry() ||                                 \
-                mPresContext->RefreshDriver()->IsLayoutFlushObserver(this), \
-            "Unexpected state");                                            \
-      } else {                                                              \
-        MOZ_ASSERT(                                                         \
-            !mPresContext->RefreshDriver()->IsLayoutFlushObserver(this),    \
-            "Unexpected state");                                            \
-      }                                                                     \
+#  define ASSERT_REFLOW_SCHEDULED_STATE()                                    \
+    {                                                                        \
+      if (ObservingLayoutFlushes()) {                                        \
+        MOZ_ASSERT(mDocument->GetBFCacheEntry() ||                           \
+                       mPresContext->RefreshDriver()->IsLayoutFlushObserver( \
+                           static_cast<PresShell*>(this)),                   \
+                   "Unexpected state");                                      \
+      } else {                                                               \
+        MOZ_ASSERT(!mPresContext->RefreshDriver()->IsLayoutFlushObserver(    \
+                       static_cast<PresShell*>(this)),                       \
+                   "Unexpected state");                                      \
+      }                                                                      \
     }
 #else
 #  define ASSERT_REFLOW_SCHEDULED_STATE() /* nothing */
 #endif
 
 class nsAutoCauseReflowNotifier {
  public:
-  explicit nsAutoCauseReflowNotifier(nsIPresShell* aShell) : mShell(aShell) {
-    mShell->WillCauseReflow();
+  explicit nsAutoCauseReflowNotifier(PresShell* aPresShell)
+      : mPresShell(aPresShell) {
+    mPresShell->WillCauseReflow();
   }
   ~nsAutoCauseReflowNotifier() {
     // This check should not be needed. Currently the only place that seem
     // to need it is the code that deals with bug 337586.
-    if (!mShell->mHaveShutDown) {
-      mShell->DidCauseReflow();
+    if (!mPresShell->mHaveShutDown) {
+      mPresShell->DidCauseReflow();
     } else {
       nsContentUtils::RemoveScriptBlocker();
     }
   }
 
-  nsIPresShell* mShell;
+  PresShell* mPresShell;
 };
 
 class MOZ_STACK_CLASS nsPresShellEventCB : public EventDispatchingCallback {
  public:
   explicit nsPresShellEventCB(PresShell* aPresShell) : mPresShell(aPresShell) {}
 
   MOZ_CAN_RUN_SCRIPT
   virtual void HandleEvent(EventChainPostVisitor& aVisitor) override {
@@ -1056,17 +1057,17 @@ void PresShell::Init(Document* aDocument
     // We call this to create mMobileViewportManager, if it is needed.
     UpdateViewportOverridden(false);
   }
 }
 
 enum TextPerfLogType { eLog_reflow, eLog_loaddone, eLog_totals };
 
 static void LogTextPerfStats(gfxTextPerfMetrics* aTextPerf,
-                             nsIPresShell* aPresShell,
+                             PresShell* aPresShell,
                              const gfxTextPerfMetrics::TextCounts& aCounts,
                              float aTime, TextPerfLogType aLogType,
                              const char* aURL) {
   LogModule* tpLog = gfxPlatform::GetLog(eGfxLog_textperf);
 
   // ignore XUL contexts unless at debug level
   mozilla::LogLevel logLevel = LogLevel::Warning;
   if (aCounts.numContentTextRuns == 0) {
@@ -1369,36 +1370,36 @@ void PresShell::Destroy() {
   mHaveShutDown = true;
 
   mTouchManager.Destroy();
 }
 
 void nsIPresShell::StopObservingRefreshDriver() {
   nsRefreshDriver* rd = mPresContext->RefreshDriver();
   if (mResizeEventPending) {
-    rd->RemoveResizeEventFlushObserver(this);
+    rd->RemoveResizeEventFlushObserver(static_cast<PresShell*>(this));
   }
   if (mObservingLayoutFlushes) {
-    rd->RemoveLayoutFlushObserver(this);
+    rd->RemoveLayoutFlushObserver(static_cast<PresShell*>(this));
   }
   if (mObservingStyleFlushes) {
-    rd->RemoveStyleFlushObserver(this);
+    rd->RemoveStyleFlushObserver(static_cast<PresShell*>(this));
   }
 }
 
 void nsIPresShell::StartObservingRefreshDriver() {
   nsRefreshDriver* rd = mPresContext->RefreshDriver();
   if (mResizeEventPending) {
-    rd->AddResizeEventFlushObserver(this);
+    rd->AddResizeEventFlushObserver(static_cast<PresShell*>(this));
   }
   if (mObservingLayoutFlushes) {
-    rd->AddLayoutFlushObserver(this);
+    rd->AddLayoutFlushObserver(static_cast<PresShell*>(this));
   }
   if (mObservingStyleFlushes) {
-    rd->AddStyleFlushObserver(this);
+    rd->AddStyleFlushObserver(static_cast<PresShell*>(this));
   }
 }
 
 nsRefreshDriver* nsIPresShell::GetRefreshDriver() const {
   return mPresContext ? mPresContext->RefreshDriver() : nullptr;
 }
 
 void nsIPresShell::SetAuthorStyleDisabled(bool aStyleDisabled) {
@@ -1677,17 +1678,17 @@ nsresult PresShell::Initialize() {
     // Nothing to do
     return NS_OK;
   }
 
   MOZ_LOG(gLog, LogLevel::Debug, ("PresShell::Initialize this=%p", this));
 
   NS_ASSERTION(!mDidInitialize, "Why are we being called?");
 
-  nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
+  RefPtr<PresShell> kungFuDeathGrip(this);
 
   RecomputeFontSizeInflationEnabled();
   MOZ_DIAGNOSTIC_ASSERT(!mIsDestroying);
 
   // Ensure the pres context doesn't think it has changed, since we haven't even
   // started layout. This avoids spurious restyles / reflows afterwards.
   //
   // Note that this is very intentionally before setting mDidInitialize so it
@@ -1887,17 +1888,17 @@ nsresult PresShell::ResizeReflowIgnoreOv
     }
     isBSizeChanging = true;
   }
 
   const bool suppressingResizeReflow =
       GetPresContext()->SuppressingResizeReflow();
 
   RefPtr<nsViewManager> viewManager = mViewManager;
-  nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
+  RefPtr<PresShell> kungFuDeathGrip(this);
 
   if (!suppressingResizeReflow && shrinkToFit) {
     // Make sure that style is flushed before setting the pres context
     // VisibleArea if we're shrinking to fit.
     //
     // Otherwise we may end up with bogus viewport units resolved against the
     // unconstrained bsize, or restyling the whole document resolving viewport
     // units against targetWidth, which may end up doing wasteful work.
@@ -2803,17 +2804,18 @@ nsIScrollableFrame* nsIPresShell::GetScr
   nsCOMPtr<nsIContent> content = GetContentForScrolling();
   return GetScrollableFrameToScrollForContent(content.get(), aDirection);
 }
 
 void nsIPresShell::CancelAllPendingReflows() {
   mDirtyRoots.Clear();
 
   if (mObservingLayoutFlushes) {
-    GetPresContext()->RefreshDriver()->RemoveLayoutFlushObserver(this);
+    GetPresContext()->RefreshDriver()->RemoveLayoutFlushObserver(
+        static_cast<PresShell*>(this));
     mObservingLayoutFlushes = false;
   }
 
   ASSERT_REFLOW_SCHEDULED_STATE();
 }
 
 static bool DestroyFramesAndStyleDataFor(
     Element* aElement, nsPresContext& aPresContext,
@@ -3975,31 +3977,31 @@ static void AssertFrameSubtreeIsSane(con
   for (; !childLists.IsDone(); childLists.Next()) {
     for (const nsIFrame* child : childLists.CurrentList()) {
       AssertFrameSubtreeIsSane(*child);
     }
   }
 }
 #endif
 
-static inline void AssertFrameTreeIsSane(const nsIPresShell& aShell) {
+static inline void AssertFrameTreeIsSane(const PresShell& aPresShell) {
 #ifdef DEBUG
-  if (const nsIFrame* root = aShell.GetRootFrame()) {
+  if (const nsIFrame* root = aPresShell.GetRootFrame()) {
     AssertFrameSubtreeIsSane(*root);
   }
 #endif
 }
 
 void PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush aFlush) {
   // FIXME(emilio, bug 1530177): Turn into a release assert when bug 1530188 and
   // bug 1530190 are fixed.
   MOZ_DIAGNOSTIC_ASSERT(!mForbiddenToFlush, "This is bad!");
 
   // Per our API contract, hold a strong ref to ourselves until we return.
-  nsCOMPtr<nsIPresShell> kungFuDeathGrip = this;
+  RefPtr<PresShell> kungFuDeathGrip = this;
 
   /**
    * VERY IMPORTANT: If you add some sort of new flushing to this
    * method, make sure to add the relevant SetNeedLayoutFlush or
    * SetNeedStyleFlush calls on the shell.
    */
   FlushType flushType = aFlush.mFlushType;
 
@@ -4371,33 +4373,33 @@ void PresShell::ContentRemoved(nsIConten
   // NOTE(emilio): It's important that this goes after the frame constructor
   // stuff, otherwise the frame constructor can't see elements which are
   // display: contents / display: none, because we'd have cleared all the style
   // data from there.
   mPresContext->RestyleManager()->ContentRemoved(aChild, oldNextSibling);
 }
 
 void nsIPresShell::NotifyCounterStylesAreDirty() {
-  nsAutoCauseReflowNotifier reflowNotifier(this);
+  nsAutoCauseReflowNotifier reflowNotifier(static_cast<PresShell*>(this));
   mFrameConstructor->NotifyCounterStylesAreDirty();
 }
 
 bool nsIPresShell::FrameIsAncestorOfDirtyRoot(nsIFrame* aFrame) const {
   return mDirtyRoots.FrameIsAncestorOfDirtyRoot(aFrame);
 }
 
 void PresShell::ReconstructFrames() {
   MOZ_ASSERT(!mFrameConstructor->GetRootFrame() || mDidInitialize,
              "Must not have root frame before initial reflow");
   if (!mDidInitialize || mIsDestroying) {
     // Nothing to do here
     return;
   }
 
-  nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
+  RefPtr<PresShell> kungFuDeathGrip(this);
 
   // Have to make sure that the content notifications are flushed before we
   // start messing with the frame model; otherwise we can get content doubling.
   //
   // Also make sure that styles are flushed before calling into the frame
   // constructor, since that's what it expects.
   mDocument->FlushPendingNotifications(FlushType::Style);
 
@@ -5273,18 +5275,17 @@ void PresShell::SetRenderingState(const 
 void PresShell::SynthesizeMouseMove(bool aFromScroll) {
   if (!sSynthMouseMove) return;
 
   if (mPaintingSuppressed || !mIsActive || !mPresContext) {
     return;
   }
 
   if (!mPresContext->IsRoot()) {
-    nsIPresShell* rootPresShell = GetRootPresShell();
-    if (rootPresShell) {
+    if (PresShell* rootPresShell = GetRootPresShell()) {
       rootPresShell->SynthesizeMouseMove(aFromScroll);
     }
     return;
   }
 
   if (mMouseLocation == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE))
     return;
 
@@ -5388,17 +5389,17 @@ void PresShell::ProcessSynthMouseMoveEve
     mSynthMouseMoveEvent.Forget();
     return;
   }
 
   NS_ASSERTION(mPresContext->IsRoot(), "Only a root pres shell should be here");
 
   // Hold a ref to ourselves so DispatchEvent won't destroy us (since
   // we need to access members after we call DispatchEvent).
-  nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
+  RefPtr<PresShell> kungFuDeathGrip(this);
 
 #ifdef DEBUG_MOUSE_LOCATION
   printf("[ps=%p]synthesizing mouse move to (%d,%d)\n", this, mMouseLocation.x,
          mMouseLocation.y);
 #endif
 
   int32_t APD = mPresContext->AppUnitsPerDevPixel();
 
@@ -5556,17 +5557,17 @@ void PresShell::MarkFramesInSubtreeAppro
       // The frame was added to mApproximatelyVisibleFrames, so increment its
       // visible count.
       aFrame->IncApproximateVisibleCount();
     }
   }
 
   nsSubDocumentFrame* subdocFrame = do_QueryFrame(aFrame);
   if (subdocFrame) {
-    nsIPresShell* presShell = subdocFrame->GetSubdocumentPresShellForPainting(
+    PresShell* presShell = subdocFrame->GetSubdocumentPresShellForPainting(
         nsSubDocumentFrame::IGNORE_PAINT_SUPPRESSION);
     if (presShell && !presShell->AssumeAllFramesVisible()) {
       nsRect rect = aRect;
       nsIFrame* root = presShell->GetRootFrame();
       if (root) {
         rect.MoveBy(aFrame->GetOffsetToCrossDoc(root));
       } else {
         rect.MoveBy(-aFrame->GetContentRectRelativeToSelf().TopLeft());
@@ -6346,17 +6347,17 @@ void PresShell::RecordMouseLocation(Widg
     printf("[ps=%p]got mouse exit for %p\n", this, aEvent->mWidget);
     printf("[ps=%p]clearing mouse location\n", this);
 #endif
   }
 }
 
 // static
 nsIFrame* PresShell::EventHandler::GetNearestFrameContainingPresShell(
-    nsIPresShell* aPresShell) {
+    PresShell* aPresShell) {
   nsView* view = aPresShell->GetViewManager()->GetRootView();
   while (view && !view->GetFrame()) {
     view = view->GetParent();
   }
 
   nsIFrame* frame = nullptr;
   if (view) {
     frame = view->GetFrame();
@@ -9237,18 +9238,18 @@ bool nsIPresShell::DoReflow(nsIFrame* ta
     mWasLastReflowInterrupted = true;
     MaybeScheduleReflow();
   }
 
   // dump text perf metrics for reflows with significant text processing
   if (tp) {
     if (tp->current.numChars > 100) {
       TimeDuration reflowTime = TimeStamp::Now() - timeStart;
-      LogTextPerfStats(tp, this, tp->current, reflowTime.ToMilliseconds(),
-                       eLog_reflow, nullptr);
+      LogTextPerfStats(tp, static_cast<PresShell*>(this), tp->current,
+                       reflowTime.ToMilliseconds(), eLog_reflow, nullptr);
     }
     tp->Accumulate();
   }
 
   if (isTimelineRecording) {
     timelines->AddMarkerForDocShell(docShell, "Reflow", MarkerTracingType::END);
   }
 
@@ -9546,26 +9547,28 @@ bool nsIPresShell::RemovePostRefreshObse
   return true;
 }
 
 void nsIPresShell::DoObserveStyleFlushes() {
   MOZ_ASSERT(!ObservingStyleFlushes());
   mObservingStyleFlushes = true;
 
   if (MOZ_LIKELY(!mDocument->GetBFCacheEntry())) {
-    mPresContext->RefreshDriver()->AddStyleFlushObserver(this);
+    mPresContext->RefreshDriver()->AddStyleFlushObserver(
+        static_cast<PresShell*>(this));
   }
 }
 
 void nsIPresShell::DoObserveLayoutFlushes() {
   MOZ_ASSERT(!ObservingLayoutFlushes());
   mObservingLayoutFlushes = true;
 
   if (MOZ_LIKELY(!mDocument->GetBFCacheEntry())) {
-    mPresContext->RefreshDriver()->AddLayoutFlushObserver(this);
+    mPresContext->RefreshDriver()->AddLayoutFlushObserver(
+        static_cast<PresShell*>(this));
   }
 }
 
 //------------------------------------------------------
 // End of protected and private methods on the PresShell
 //------------------------------------------------------
 
 //------------------------------------------------------------------
@@ -9875,17 +9878,17 @@ bool nsIPresShell::VerifyIncrementalRefl
   NS_ENSURE_TRUE(presShell, false);
 
   // Note that after we create the shell, we must make sure to destroy it
   presShell->SetVerifyReflowEnable(
       false);  // turn off verify reflow while we're
                // reflowing the test frame tree
   vm->SetPresShell(presShell);
   {
-    nsAutoCauseReflowNotifier crNotifier(this);
+    nsAutoCauseReflowNotifier crNotifier(static_cast<PresShell*>(this));
     presShell->Initialize();
   }
   mDocument->BindingManager()->ProcessAttachedQueue();
   presShell->FlushPendingNotifications(FlushType::Layout);
   presShell->SetVerifyReflowEnable(
       true);  // turn on verify reflow again now that
               // we're done reflowing the test frame tree
   // Force the non-primary presshell to unsuppress; it doesn't want to normally
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -599,18 +599,17 @@ class PresShell final : public nsIPresSh
     /**
      * OnPresShellDestroy() is called when every PresShell instance is being
      * destroyed.
      */
     static inline void OnPresShellDestroy(Document* aDocument);
 
    private:
     static bool InZombieDocument(nsIContent* aContent);
-    static nsIFrame* GetNearestFrameContainingPresShell(
-        nsIPresShell* aPresShell);
+    static nsIFrame* GetNearestFrameContainingPresShell(PresShell* aPresShell);
     static already_AddRefed<nsIURI> GetDocumentURIToCompareWithBlacklist(
         PresShell& aPresShell);
 
     /**
      * HandleEventUsingCoordinates() handles aGUIEvent whose
      * IsUsingCoordinates() returns true with the following helper methods.
      *
      * @param aFrameForPresShell        The frame for PresShell.  See
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -1183,18 +1183,18 @@ static bool IsPrimaryFrameOfRootOrBodyEl
   }
   if (aFrame == bodyFrame) {
     return true;
   }
 
   return false;
 }
 
-static void ApplyRenderingChangeToTree(nsIPresShell* aPresShell,
-                                       nsIFrame* aFrame, nsChangeHint aChange) {
+static void ApplyRenderingChangeToTree(PresShell* aPresShell, nsIFrame* aFrame,
+                                       nsChangeHint aChange) {
   // We check StyleDisplay()->HasTransformStyle() in addition to checking
   // IsTransformed() since we can get here for some frames that don't support
   // CSS transforms.
   NS_ASSERTION(!(aChange & nsChangeHint_UpdateTransformLayer) ||
                    nsLayoutUtils::GetPrimaryFrameFromStyleFrame(aFrame)
                        ->IsTransformed() ||
                    aFrame->StyleDisplay()->HasTransformStyle(),
                "Unexpected UpdateTransformLayer hint");
--- a/layout/base/ZoomConstraintsClient.cpp
+++ b/layout/base/ZoomConstraintsClient.cpp
@@ -39,21 +39,21 @@ using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 
 ZoomConstraintsClient::ZoomConstraintsClient()
     : mDocument(nullptr), mPresShell(nullptr) {}
 
 ZoomConstraintsClient::~ZoomConstraintsClient() {}
 
-static nsIWidget* GetWidget(nsIPresShell* aShell) {
-  if (!aShell) {
+static nsIWidget* GetWidget(PresShell* aPresShell) {
+  if (!aPresShell) {
     return nullptr;
   }
-  if (nsIFrame* rootFrame = aShell->GetRootFrame()) {
+  if (nsIFrame* rootFrame = aPresShell->GetRootFrame()) {
 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_UIKIT)
     return rootFrame->GetNearestWidget();
 #else
     if (nsView* view = rootFrame->GetView()) {
       return view->GetWidget();
     }
 #endif
   }
@@ -91,18 +91,17 @@ void ZoomConstraintsClient::Destroy() {
       mGuid = Nothing();
     }
   }
 
   mDocument = nullptr;
   mPresShell = nullptr;
 }
 
-void ZoomConstraintsClient::Init(nsIPresShell* aPresShell,
-                                 Document* aDocument) {
+void ZoomConstraintsClient::Init(PresShell* aPresShell, Document* aDocument) {
   if (!(aPresShell && aDocument)) {
     return;
   }
 
   mPresShell = aPresShell;
   mDocument = aDocument;
 
   if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
--- a/layout/base/ZoomConstraintsClient.h
+++ b/layout/base/ZoomConstraintsClient.h
@@ -8,19 +8,18 @@
 #define ZoomConstraintsClient_h_
 
 #include "mozilla/layers/ScrollableLayerGuid.h"
 #include "mozilla/Maybe.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMEventListener.h"
 #include "nsIObserver.h"
 
-class nsIPresShell;
-
 namespace mozilla {
+class PresShell;
 namespace dom {
 class EventTarget;
 }  // namespace dom
 }  // namespace mozilla
 
 class ZoomConstraintsClient final : public nsIDOMEventListener,
                                     public nsIObserver {
  public:
@@ -29,23 +28,23 @@ class ZoomConstraintsClient final : publ
   NS_DECL_NSIOBSERVER
 
   ZoomConstraintsClient();
 
  private:
   ~ZoomConstraintsClient();
 
  public:
-  void Init(nsIPresShell* aPresShell, mozilla::dom::Document* aDocument);
+  void Init(mozilla::PresShell* aPresShell, mozilla::dom::Document* aDocument);
   void Destroy();
   void ScreenSizeChanged();
 
  private:
   void RefreshZoomConstraints();
 
   RefPtr<mozilla::dom::Document> mDocument;
   // raw ref since the presShell owns this
-  nsIPresShell* MOZ_NON_OWNING_REF mPresShell;
+  mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell;
   nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
   mozilla::Maybe<mozilla::layers::ScrollableLayerGuid> mGuid;
 };
 
 #endif
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -6904,18 +6904,17 @@ void nsCSSFrameConstructor::ContentAppen
   if (gReallyNoisyContentUpdates) {
     printf("nsCSSFrameConstructor::ContentAppended: resulting frame model:\n");
     parentFrame->List(stdout);
   }
 #endif
 
 #ifdef ACCESSIBILITY
   if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-    accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
-                                     aFirstNewContent, nullptr);
+    accService->ContentRangeInserted(mPresShell, aFirstNewContent, nullptr);
   }
 #endif
 }
 
 void nsCSSFrameConstructor::ContentInserted(nsIContent* aChild,
                                             nsILayoutHistoryState* aFrameState,
                                             InsertionKind aInsertionKind) {
   ContentRangeInserted(aChild, aChild->GetNextSibling(), aFrameState,
@@ -7017,18 +7016,17 @@ void nsCSSFrameConstructor::ContentRange
       // Restore frame state for the root scroll frame if there is one
       if (nsIFrame* rootScrollFrame = mPresShell->GetRootScrollFrame()) {
         RestoreFrameStateFor(rootScrollFrame, aFrameState);
       }
     }
 
 #ifdef ACCESSIBILITY
     if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-      accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
-                                       aStartChild, aEndChild);
+      accService->ContentRangeInserted(mPresShell, aStartChild, aEndChild);
     }
 #endif
 
     return;
   }
 
   InsertionPoint insertion;
   if (isSingleInsert) {
@@ -7384,18 +7382,17 @@ void nsCSSFrameConstructor::ContentRange
         "nsCSSFrameConstructor::ContentRangeInserted: resulting frame "
         "model:\n");
     insertion.mParentFrame->List(stdout);
   }
 #endif
 
 #ifdef ACCESSIBILITY
   if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-    accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
-                                     aStartChild, aEndChild);
+    accService->ContentRangeInserted(mPresShell, aStartChild, aEndChild);
   }
 #endif
 }
 
 bool nsCSSFrameConstructor::ContentRemoved(nsIContent* aChild,
                                            nsIContent* aOldNextSibling,
                                            RemoveFlags aFlags) {
   MOZ_ASSERT(aChild);
@@ -7585,17 +7582,17 @@ bool nsCSSFrameConstructor::ContentRemov
       RecreateFramesForContent(grandparentFrame->GetContent(),
                                InsertionKind::Async);
       LAYOUT_PHASE_TEMP_REENTER();
       return true;
     }
 
 #ifdef ACCESSIBILITY
     if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-      accService->ContentRemoved(static_cast<PresShell*>(mPresShell), aChild);
+      accService->ContentRemoved(mPresShell, aChild);
     }
 #endif
 
     // Examine the containing-block for the removed content and see if
     // :first-letter style applies.
     nsIFrame* inflowChild = childFrame;
     if (childFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
       inflowChild = childFrame->GetPlaceholderFrame();
@@ -11719,18 +11716,17 @@ void nsCSSFrameConstructor::GenerateChil
                     childList, false, nullptr);
 
     aFrame->SetInitialChildList(kPrincipalList, childList);
   }
 
 #ifdef ACCESSIBILITY
   if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
     if (nsIContent* child = aFrame->GetContent()->GetFirstChild()) {
-      accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
-                                       child, nullptr);
+      accService->ContentRangeInserted(mPresShell, child, nullptr);
     }
   }
 #endif
 
   // call XBL constructors after the frames are created
   mPresShell->GetDocument()->BindingManager()->ProcessAttachedQueue();
 }
 
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -112,37 +112,29 @@ nsCaret::nsCaret()
       mIsBlinkOn(false),
       mVisible(false),
       mReadOnly(false),
       mShowDuringSelection(false),
       mIgnoreUserModify(true) {}
 
 nsCaret::~nsCaret() { StopBlinking(); }
 
-nsresult nsCaret::Init(nsIPresShell* inPresShell) {
-  NS_ENSURE_ARG(inPresShell);
+nsresult nsCaret::Init(PresShell* aPresShell) {
+  NS_ENSURE_ARG(aPresShell);
 
   mPresShell =
-      do_GetWeakReference(inPresShell);  // the presshell owns us, so no addref
+      do_GetWeakReference(aPresShell);  // the presshell owns us, so no addref
   NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs");
 
   mShowDuringSelection =
       LookAndFeel::GetInt(LookAndFeel::eIntID_ShowCaretDuringSelection,
                           mShowDuringSelection ? 1 : 0) != 0;
 
-  // get the selection from the pres shell, and set ourselves up as a selection
-  // listener
-
-  nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mPresShell);
-  if (!selCon) {
-    return NS_ERROR_FAILURE;
-  }
-
   RefPtr<Selection> selection =
-      selCon->GetSelection(nsISelectionController::SELECTION_NORMAL);
+      aPresShell->GetSelection(nsISelectionController::SELECTION_NORMAL);
   if (!selection) {
     return NS_ERROR_FAILURE;
   }
 
   selection->AddSelectionListener(this);
   mDomSelectionWeak = selection;
 
   return NS_OK;
--- a/layout/base/nsCaret.h
+++ b/layout/base/nsCaret.h
@@ -18,20 +18,20 @@
 #include "nsPoint.h"
 #include "nsRect.h"
 
 class nsDisplayListBuilder;
 class nsFrameSelection;
 class nsIContent;
 class nsIFrame;
 class nsINode;
-class nsIPresShell;
 class nsITimer;
 
 namespace mozilla {
+class PresShell;
 namespace gfx {
 class DrawTarget;
 }  // namespace gfx
 }  // namespace mozilla
 
 //-----------------------------------------------------------------------------
 class nsCaret final : public nsISelectionListener {
   typedef mozilla::gfx::DrawTarget DrawTarget;
@@ -42,17 +42,17 @@ class nsCaret final : public nsISelectio
  protected:
   virtual ~nsCaret();
 
  public:
   NS_DECL_ISUPPORTS
 
   typedef mozilla::CaretAssociationHint CaretAssociationHint;
 
-  nsresult Init(nsIPresShell* inPresShell);
+  nsresult Init(mozilla::PresShell* aPresShell);
   void Terminate();
 
   void SetSelection(mozilla::dom::Selection* aDOMSel);
   mozilla::dom::Selection* GetSelection();
 
   /**
    * Sets whether the caret should only be visible in nodes that are not
    * user-modify: read-only, or whether it should be visible in all nodes.
--- a/layout/base/nsFrameManager.cpp
+++ b/layout/base/nsFrameManager.cpp
@@ -4,22 +4,22 @@
  * 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/. */
 
 /* storage of the frame tree and information about it */
 
 #include "nsFrameManager.h"
 
 #include "nscore.h"
-#include "nsIPresShell.h"
 #include "nsCOMPtr.h"
 #include "plhash.h"
 #include "nsPlaceholderFrame.h"
 #include "nsGkAtoms.h"
 #include "nsILayoutHistoryState.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/PresState.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Document.h"
 
 #include "nsError.h"
 #include "nsAbsoluteContainingBlock.h"
 #include "ChildIterator.h"
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -755,18 +755,18 @@ bool nsLayoutUtils::AllowZoomingForDocum
   // True if we allow zooming for all documents on this platform, or if we are
   // in RDM and handling meta viewports, which force zoom under some
   // circumstances.
   return gfxPrefs::APZAllowZooming() ||
          (aDocument && aDocument->InRDMPane() &&
           nsLayoutUtils::ShouldHandleMetaViewport(aDocument));
 }
 
-float nsLayoutUtils::GetCurrentAPZResolutionScale(nsIPresShell* aShell) {
-  return aShell ? aShell->GetCumulativeNonRootScaleResolution() : 1.0;
+float nsLayoutUtils::GetCurrentAPZResolutionScale(PresShell* aPresShell) {
+  return aPresShell ? aPresShell->GetCumulativeNonRootScaleResolution() : 1.0;
 }
 
 // Return the maximum displayport size, based on the LayerManager's maximum
 // supported texture size. The result is in app units.
 static nscoord GetMaxDisplayPortSize(nsIContent* aContent,
                                      nsPresContext* aFallbackPrescontext) {
   MOZ_ASSERT(!gfxPrefs::LayersTilesEnabled(),
              "Do not clamp displayports if tiling is enabled");
@@ -1257,17 +1257,17 @@ void nsLayoutUtils::InvalidateForDisplay
       rect->UnionRect(*rect, newRegion.GetBounds());
     } else {
       rect->UnionRect(*rect, aNewDisplayPort);
     }
   }
 }
 
 bool nsLayoutUtils::SetDisplayPortMargins(nsIContent* aContent,
-                                          nsIPresShell* aPresShell,
+                                          PresShell* aPresShell,
                                           const ScreenMargin& aMargins,
                                           uint32_t aPriority,
                                           RepaintMode aRepaintMode) {
   MOZ_ASSERT(aContent);
   MOZ_ASSERT(aContent->GetComposedDoc() == aPresShell->GetDocument());
 
   DisplayPortMarginsPropertyData* currentData =
       static_cast<DisplayPortMarginsPropertyData*>(
@@ -3374,18 +3374,18 @@ bool nsLayoutUtils::MaybeCreateDisplayPo
   if (aFrame->IsPlaceholderFrame()) {
     nsPlaceholderFrame* placeholder = static_cast<nsPlaceholderFrame*>(aFrame);
     if (MaybeCreateDisplayPortInFirstScrollFrameEncountered(
             placeholder->GetOutOfFlowFrame(), aBuilder)) {
       return true;
     }
   }
   if (aFrame->IsSubDocumentFrame()) {
-    nsIPresShell* presShell = static_cast<nsSubDocumentFrame*>(aFrame)
-                                  ->GetSubdocumentPresShellForPainting(0);
+    PresShell* presShell = static_cast<nsSubDocumentFrame*>(aFrame)
+                               ->GetSubdocumentPresShellForPainting(0);
     nsIFrame* root = presShell ? presShell->GetRootFrame() : nullptr;
     if (root) {
       if (MaybeCreateDisplayPortInFirstScrollFrameEncountered(root, aBuilder)) {
         return true;
       }
     }
   }
   if (aFrame->IsDeckFrame()) {
@@ -8766,18 +8766,18 @@ void nsLayoutUtils::SetBSizeFromFontMetr
   }
   aMetrics.SetBlockStartAscent(aMetrics.BlockStartAscent() +
                                aFramePadding.BStart(aFrameWM));
   aMetrics.BSize(aLineWM) += aFramePadding.BStartEnd(aFrameWM);
 }
 
 /* static */
 bool nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(
-    nsIPresShell* aShell) {
-  if (Document* doc = aShell->GetDocument()) {
+    PresShell* aPresShell) {
+  if (Document* doc = aPresShell->GetDocument()) {
     WidgetEvent event(true, eVoidEvent);
     nsTArray<EventTarget*> targets;
     nsresult rv = EventDispatcher::Dispatch(
         ToSupports(doc), nullptr, &event, nullptr, nullptr, nullptr, &targets);
     NS_ENSURE_SUCCESS(rv, false);
     for (size_t i = 0; i < targets.Length(); i++) {
       if (targets[i]->IsApzAware()) {
         return true;
@@ -8821,17 +8821,17 @@ static void MaybeReflowForInflationScree
           }
         }
       }
     }
   }
 }
 
 /* static */
-void nsLayoutUtils::SetVisualViewportSize(nsIPresShell* aPresShell,
+void nsLayoutUtils::SetVisualViewportSize(PresShell* aPresShell,
                                           CSSSize aSize) {
   MOZ_ASSERT(aSize.width >= 0.0 && aSize.height >= 0.0);
 
   aPresShell->SetVisualViewportSize(
       nsPresContext::CSSPixelsToAppUnits(aSize.width),
       nsPresContext::CSSPixelsToAppUnits(aSize.height));
 
   // When the "font.size.inflation.minTwips" preference is set, the
@@ -9436,40 +9436,39 @@ CSSRect nsLayoutUtils::GetBoundingConten
               subFrame, subFrame->GetRectRelativeToSelf(), relativeTo));
 
       result = subFrameRect.Intersect(result);
     }
   }
   return result;
 }
 
-static already_AddRefed<nsIPresShell> GetPresShell(const nsIContent* aContent) {
-  nsCOMPtr<nsIPresShell> result;
+static PresShell* GetPresShell(const nsIContent* aContent) {
   if (Document* doc = aContent->GetComposedDoc()) {
-    result = doc->GetPresShell();
-  }
-  return result.forget();
+    return doc->GetPresShell();
+  }
+  return nullptr;
 }
 
 static void UpdateDisplayPortMarginsForPendingMetrics(
     const RepaintRequest& aMetrics) {
   nsIContent* content = nsLayoutUtils::FindContentFor(aMetrics.GetScrollId());
   if (!content) {
     return;
   }
 
-  nsCOMPtr<nsIPresShell> shell = GetPresShell(content);
-  if (!shell) {
+  RefPtr<PresShell> presShell = GetPresShell(content);
+  if (!presShell) {
     return;
   }
 
-  if (nsLayoutUtils::AllowZoomingForDocument(shell->GetDocument()) &&
+  if (nsLayoutUtils::AllowZoomingForDocument(presShell->GetDocument()) &&
       aMetrics.IsRootContent()) {
     // See APZCCallbackHelper::UpdateRootFrame for details.
-    float presShellResolution = shell->GetResolution();
+    float presShellResolution = presShell->GetResolution();
     if (presShellResolution != aMetrics.GetPresShellResolution()) {
       return;
     }
   }
 
   nsIScrollableFrame* frame =
       nsLayoutUtils::FindScrollableFrameFor(aMetrics.GetScrollId());
 
@@ -9492,17 +9491,18 @@ static void UpdateDisplayPortMarginsForP
   }
 
   CSSPoint frameScrollOffset =
       CSSPoint::FromAppUnits(frame->GetScrollPosition());
   ScreenMargin displayPortMargins =
       APZCCallbackHelper::AdjustDisplayPortForScrollDelta(aMetrics,
                                                           frameScrollOffset);
 
-  nsLayoutUtils::SetDisplayPortMargins(content, shell, displayPortMargins, 0);
+  nsLayoutUtils::SetDisplayPortMargins(content, presShell, displayPortMargins,
+                                       0);
 }
 
 /* static */
 void nsLayoutUtils::UpdateDisplayPortMarginsFromPendingMessages() {
   if (XRE_IsContentProcess() && mozilla::layers::CompositorBridgeChild::Get() &&
       mozilla::layers::CompositorBridgeChild::Get()->GetIPCChannel()) {
     CompositorBridgeChild::Get()->GetIPCChannel()->PeekMessages(
         [](const IPC::Message& aMsg) -> bool {
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -175,16 +175,17 @@ class nsLayoutUtils {
   typedef mozilla::layers::ScrollableLayerGuid::ViewID ViewID;
   typedef mozilla::CSSPoint CSSPoint;
   typedef mozilla::CSSSize CSSSize;
   typedef mozilla::CSSIntSize CSSIntSize;
   typedef mozilla::CSSRect CSSRect;
   typedef mozilla::ScreenMargin ScreenMargin;
   typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
   typedef mozilla::LayoutDeviceRect LayoutDeviceRect;
+  typedef mozilla::PresShell PresShell;
   typedef mozilla::StyleGeometryBox StyleGeometryBox;
   typedef mozilla::SVGImageContext SVGImageContext;
   typedef mozilla::LogicalSize LogicalSize;
 
   /**
    * Finds previously assigned ViewID for the given content element, if any.
    * Returns whether a ViewID was previously assigned.
    */
@@ -279,19 +280,18 @@ class nsLayoutUtils {
    *                                displayport built by combining the base
    *                                rect with the margins, in either direction
    * @param aPriority a priority value to determine which margins take effect
    *                  when multiple callers specify margins
    * @param aRepaintMode whether to schedule a paint after setting the margins
    * @return true if the new margins were applied.
    */
   static bool SetDisplayPortMargins(
-      nsIContent* aContent, nsIPresShell* aPresShell,
-      const ScreenMargin& aMargins, uint32_t aPriority = 0,
-      RepaintMode aRepaintMode = RepaintMode::Repaint);
+      nsIContent* aContent, PresShell* aPresShell, const ScreenMargin& aMargins,
+      uint32_t aPriority = 0, RepaintMode aRepaintMode = RepaintMode::Repaint);
 
   /**
    * Set the display port base rect for given element to be used with display
    * port margins.
    * SetDisplayPortBaseIfNotSet is like SetDisplayPortBase except it only sets
    * the display port base to aBase if no display port base is currently set.
    */
   static void SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase);
@@ -792,17 +792,17 @@ class nsLayoutUtils {
    * @param aEvent          The event having coordinates where you want to
    *                        collapse Selection.
    * @param aContainer      Returns the container node at the point.
    *                        Set nullptr if you don't need this.
    * @param aOffset         Returns offset in the container node at the point.
    *                        Set nullptr if you don't need this.
    */
   MOZ_CAN_RUN_SCRIPT
-  static void GetContainerAndOffsetAtEvent(mozilla::PresShell* aPresShell,
+  static void GetContainerAndOffsetAtEvent(PresShell* aPresShell,
                                            const mozilla::WidgetEvent* aEvent,
                                            nsIContent** aContainer,
                                            int32_t* aOffset);
 
   /**
    * Translate from widget coordinates to the view's coordinates
    * @param aPresContext the PresContext for the view
    * @param aWidget the widget
@@ -1131,17 +1131,17 @@ class nsLayoutUtils {
    * images. If PAINT_WIDGET_LAYERS is set, aFrame must be a display root,
    * and we will use the frame's widget's layer manager to paint
    * even if aRenderingContext is non-null. This is useful if you want
    * to force rendering to use the widget's layer manager for testing
    * or speed. PAINT_WIDGET_LAYERS must be set if aRenderingContext is null.
    * If PAINT_DOCUMENT_RELATIVE is used, the visible region is interpreted
    * as being relative to the document (normally it's relative to the CSS
    * viewport) and the document is painted as if no scrolling has occured.
-   * Only considered if nsIPresShell::IgnoringViewportScrolling is true.
+   * Only considered if PresShell::IgnoringViewportScrolling is true.
    * PAINT_TO_WINDOW sets painting to window to true on the display list
    * builder even if we can't tell that we are painting to the window.
    * If PAINT_EXISTING_TRANSACTION is set, then BeginTransaction() has already
    * been called on aFrame's widget's layer manager and should not be
    * called again.
    * If PAINT_COMPRESSED is set, the FrameLayerBuilder should be set to
    * compressed mode to avoid short cut optimizations.
    *
@@ -2706,17 +2706,17 @@ class nsLayoutUtils {
    * enabled.
    */
   static bool AsyncPanZoomEnabled(nsIFrame* aFrame);
 
   /**
    * Returns the current APZ Resolution Scale. When Java Pan/Zoom is
    * enabled in Fennec it will always return 1.0.
    */
-  static float GetCurrentAPZResolutionScale(nsIPresShell* aShell);
+  static float GetCurrentAPZResolutionScale(PresShell* aPresShell);
 
   /**
    * Returns true if aDocument should be allowed to use resolution
    * zooming.
    */
   static bool AllowZoomingForDocument(const mozilla::dom::Document* aDocument);
 
   /**
@@ -2756,17 +2756,17 @@ class nsLayoutUtils {
   /**
    * Calculate a basic FrameMetrics with enough fields set to perform some
    * layout calculations. The fields set are dev-to-css ratio, pres shell
    * resolution, cumulative resolution, zoom, composition size, root
    * composition size, scroll offset and scrollable rect.
    *
    * Note that for the RCD-RSF, the scroll offset returned is the layout
    * viewport offset; if you need the visual viewport offset, that needs to
-   * be queried independently via nsIPresShell::GetVisualViewportOffset().
+   * be queried independently via PresShell::GetVisualViewportOffset().
    *
    * By contrast, ComputeFrameMetrics() computes all the fields, but requires
    * extra inputs and can only be called during frame layer building.
    */
   static FrameMetrics CalculateBasicFrameMetrics(
       nsIScrollableFrame* aScrollFrame);
 
   /**
@@ -2812,24 +2812,24 @@ class nsLayoutUtils {
 
   static bool IsOutlineStyleAutoEnabled();
 
   static void SetBSizeFromFontMetrics(
       const nsIFrame* aFrame, mozilla::ReflowOutput& aMetrics,
       const mozilla::LogicalMargin& aFramePadding, mozilla::WritingMode aLineWM,
       mozilla::WritingMode aFrameWM);
 
-  static bool HasDocumentLevelListenersForApzAwareEvents(nsIPresShell* aShell);
+  static bool HasDocumentLevelListenersForApzAwareEvents(PresShell* aPresShell);
 
   /**
    * Set the viewport size for the purpose of clamping the scroll position
    * for the root scroll frame of this document
    * (see nsIDOMWindowUtils.setVisualViewportSize).
    */
-  static void SetVisualViewportSize(nsIPresShell* aPresShell, CSSSize aSize);
+  static void SetVisualViewportSize(PresShell* aPresShell, CSSSize aSize);
 
   /**
    * Returns true if the given scroll origin is "higher priority" than APZ.
    * In general any content programmatic scrolls (e.g. scrollTo calls) are
    * higher priority, and take precedence over APZ scrolling. This function
    * returns true for those, and returns false for other origins like APZ
    * itself, or scroll position updates from the history restore code.
    */
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -1503,18 +1503,18 @@ struct DocumentFrameCallbacks {
   RefPtr<Document> mDocument;
   nsTArray<Document::FrameRequest> mCallbacks;
 };
 
 static nsDocShell* GetDocShell(nsPresContext* aPresContext) {
   return static_cast<nsDocShell*>(aPresContext->GetDocShell());
 }
 
-static bool HasPendingAnimations(nsIPresShell* aShell) {
-  Document* doc = aShell->GetDocument();
+static bool HasPendingAnimations(PresShell* aPresShell) {
+  Document* doc = aPresShell->GetDocument();
   if (!doc) {
     return false;
   }
 
   PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
   return tracker && tracker->HasPendingAnimations();
 }
 
@@ -1856,19 +1856,19 @@ void nsRefreshDriver::Tick(VsyncId aId, 
   AutoTArray<nsCOMPtr<nsIRunnable>, 16> earlyRunners;
   earlyRunners.SwapElements(mEarlyRunners);
   for (auto& runner : earlyRunners) {
     runner->Run();
   }
 
   // Resize events should be fired before layout flushes or
   // calling animation frame callbacks.
-  AutoTArray<nsIPresShell*, 16> observers;
+  AutoTArray<PresShell*, 16> observers;
   observers.AppendElements(mResizeEventFlushObservers);
-  for (nsIPresShell* shell : Reversed(observers)) {
+  for (PresShell* shell : Reversed(observers)) {
     if (!mPresContext || !mPresContext->GetPresShell()) {
       StopTimer();
       return;
     }
     // Make sure to not process observers which might have been removed
     // during previous iterations.
     if (!mResizeEventFlushObservers.RemoveElement(shell)) {
       continue;
@@ -1900,50 +1900,50 @@ void nsRefreshDriver::Tick(VsyncId aId, 
 
       DispatchScrollEvents();
       DispatchVisualViewportScrollEvents();
       DispatchAnimationEvents();
       RunFullscreenSteps();
       RunFrameRequestCallbacks(aNowTime);
 
       if (mPresContext && mPresContext->GetPresShell()) {
-        AutoTArray<nsIPresShell*, 16> observers;
+        AutoTArray<PresShell*, 16> observers;
         observers.AppendElements(mStyleFlushObservers);
         for (uint32_t j = observers.Length();
              j && mPresContext && mPresContext->GetPresShell(); --j) {
           // Make sure to not process observers which might have been removed
           // during previous iterations.
-          nsIPresShell* rawPresShell = observers[j - 1];
+          PresShell* rawPresShell = observers[j - 1];
           if (!mStyleFlushObservers.RemoveElement(rawPresShell)) {
             continue;
           }
-          RefPtr<PresShell> presShell = static_cast<PresShell*>(rawPresShell);
+          RefPtr<PresShell> presShell = rawPresShell;
           presShell->mObservingStyleFlushes = false;
           presShell->FlushPendingNotifications(
               ChangesToFlush(FlushType::Style, false));
           // Inform the FontFaceSet that we ticked, so that it can resolve its
           // ready promise if it needs to (though it might still be waiting on
           // a layout flush).
           presShell->NotifyFontFaceSetOnRefresh();
           mNeedToRecomputeVisibility = true;
         }
       }
     } else if (i == 2) {
       // This is the FlushType::Layout case.
-      AutoTArray<nsIPresShell*, 16> observers;
+      AutoTArray<PresShell*, 16> observers;
       observers.AppendElements(mLayoutFlushObservers);
       for (uint32_t j = observers.Length();
            j && mPresContext && mPresContext->GetPresShell(); --j) {
         // Make sure to not process observers which might have been removed
         // during previous iterations.
-        nsIPresShell* rawPresShell = observers[j - 1];
+        PresShell* rawPresShell = observers[j - 1];
         if (!mLayoutFlushObservers.RemoveElement(rawPresShell)) {
           continue;
         }
-        RefPtr<PresShell> presShell = static_cast<PresShell*>(rawPresShell);
+        RefPtr<PresShell> presShell = rawPresShell;
         presShell->mObservingLayoutFlushes = false;
         presShell->mWasLastReflowInterrupted = false;
         FlushType flushType = HasPendingAnimations(presShell)
                                   ? FlushType::Layout
                                   : FlushType::InterruptibleLayout;
         presShell->FlushPendingNotifications(ChangesToFlush(flushType, false));
         // Inform the FontFaceSet that we ticked, so that it can resolve its
         // ready promise if it needs to.
--- a/layout/base/nsRefreshDriver.h
+++ b/layout/base/nsRefreshDriver.h
@@ -24,25 +24,25 @@
 #include "nsHashKeys.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/dom/VisualViewport.h"
 #include "mozilla/layers/TransactionIdAllocator.h"
 #include "mozilla/VsyncDispatcher.h"
 
 class nsPresContext;
-class nsIPresShell;
 
 class imgIRequest;
 class nsINode;
 class nsIRunnable;
 
 namespace mozilla {
 class AnimationEventDispatcher;
 class PendingFullscreenEvent;
+class PresShell;
 class RefreshDriverTimer;
 class Runnable;
 
 namespace layout {
 class VsyncChild;
 }  // namespace layout
 
 namespace dom {
@@ -184,60 +184,60 @@ class nsRefreshDriver final : public moz
    * @returns whether the operation succeeded, or void in the case of removal.
    */
   bool AddImageRequest(imgIRequest* aRequest);
   void RemoveImageRequest(imgIRequest* aRequest);
 
   /**
    * Add / remove presshells which have pending resize event.
    */
-  void AddResizeEventFlushObserver(nsIPresShell* aShell,
+  void AddResizeEventFlushObserver(mozilla::PresShell* aPresShell,
                                    bool aDelayed = false) {
     MOZ_DIAGNOSTIC_ASSERT(
-        !mResizeEventFlushObservers.Contains(aShell) &&
-            !mDelayedResizeEventFlushObservers.Contains(aShell),
+        !mResizeEventFlushObservers.Contains(aPresShell) &&
+            !mDelayedResizeEventFlushObservers.Contains(aPresShell),
         "Double-adding resize event flush observer");
     if (aDelayed) {
-      mDelayedResizeEventFlushObservers.AppendElement(aShell);
+      mDelayedResizeEventFlushObservers.AppendElement(aPresShell);
     } else {
-      mResizeEventFlushObservers.AppendElement(aShell);
+      mResizeEventFlushObservers.AppendElement(aPresShell);
       EnsureTimerStarted();
     }
   }
 
-  void RemoveResizeEventFlushObserver(nsIPresShell* aShell) {
-    mResizeEventFlushObservers.RemoveElement(aShell);
-    mDelayedResizeEventFlushObservers.RemoveElement(aShell);
+  void RemoveResizeEventFlushObserver(mozilla::PresShell* aPresShell) {
+    mResizeEventFlushObservers.RemoveElement(aPresShell);
+    mDelayedResizeEventFlushObservers.RemoveElement(aPresShell);
   }
 
   /**
    * Add / remove presshells that we should flush style and layout on
    */
-  void AddStyleFlushObserver(nsIPresShell* aShell) {
-    MOZ_DIAGNOSTIC_ASSERT(!mStyleFlushObservers.Contains(aShell),
+  void AddStyleFlushObserver(mozilla::PresShell* aPresShell) {
+    MOZ_DIAGNOSTIC_ASSERT(!mStyleFlushObservers.Contains(aPresShell),
                           "Double-adding style flush observer");
-    mStyleFlushObservers.AppendElement(aShell);
+    mStyleFlushObservers.AppendElement(aPresShell);
     EnsureTimerStarted();
   }
 
-  void RemoveStyleFlushObserver(nsIPresShell* aShell) {
-    mStyleFlushObservers.RemoveElement(aShell);
+  void RemoveStyleFlushObserver(mozilla::PresShell* aPresShell) {
+    mStyleFlushObservers.RemoveElement(aPresShell);
   }
-  void AddLayoutFlushObserver(nsIPresShell* aShell) {
-    MOZ_DIAGNOSTIC_ASSERT(!IsLayoutFlushObserver(aShell),
+  void AddLayoutFlushObserver(mozilla::PresShell* aPresShell) {
+    MOZ_DIAGNOSTIC_ASSERT(!IsLayoutFlushObserver(aPresShell),
                           "Double-adding layout flush observer");
-    mLayoutFlushObservers.AppendElement(aShell);
+    mLayoutFlushObservers.AppendElement(aPresShell);
     EnsureTimerStarted();
   }
-  void RemoveLayoutFlushObserver(nsIPresShell* aShell) {
-    mLayoutFlushObservers.RemoveElement(aShell);
+  void RemoveLayoutFlushObserver(mozilla::PresShell* aPresShell) {
+    mLayoutFlushObservers.RemoveElement(aPresShell);
   }
 
-  bool IsLayoutFlushObserver(nsIPresShell* aShell) {
-    return mLayoutFlushObservers.Contains(aShell);
+  bool IsLayoutFlushObserver(mozilla::PresShell* aPresShell) {
+    return mLayoutFlushObservers.Contains(aPresShell);
   }
 
   /**
    * "Early Runner" runnables will be called as the first step when refresh
    * driver tick is triggered. Runners shouldn't keep other objects alive,
    * since it isn't guaranteed they will ever get called.
    */
   void AddEarlyRunner(nsIRunnable* aRunnable) {
@@ -561,20 +561,20 @@ class nsRefreshDriver final : public moz
   AutoTArray<nsCOMPtr<nsIRunnable>, 16> mEarlyRunners;
   VisualViewportResizeEventArray mVisualViewportResizeEvents;
   ScrollEventArray mScrollEvents;
   VisualViewportScrollEventArray mVisualViewportScrollEvents;
 
   // Scroll events on documents that might have events suppressed.
   ScrollEventArray mDelayedScrollEvents;
 
-  AutoTArray<nsIPresShell*, 16> mResizeEventFlushObservers;
-  AutoTArray<nsIPresShell*, 16> mDelayedResizeEventFlushObservers;
-  AutoTArray<nsIPresShell*, 16> mStyleFlushObservers;
-  AutoTArray<nsIPresShell*, 16> mLayoutFlushObservers;
+  AutoTArray<mozilla::PresShell*, 16> mResizeEventFlushObservers;
+  AutoTArray<mozilla::PresShell*, 16> mDelayedResizeEventFlushObservers;
+  AutoTArray<mozilla::PresShell*, 16> mStyleFlushObservers;
+  AutoTArray<mozilla::PresShell*, 16> mLayoutFlushObservers;
   // nsTArray on purpose, because we want to be able to swap.
   nsTArray<Document*> mFrameRequestCallbackDocs;
   nsTArray<Document*> mThrottledFrameRequestCallbackDocs;
   nsTObserverArray<nsAPostRefreshObserver*> mPostRefreshObservers;
   nsTArray<mozilla::UniquePtr<mozilla::PendingFullscreenEvent>>
       mPendingFullscreenEvents;
   AutoTArray<mozilla::AnimationEventDispatcher*, 16>
       mAnimationEventFlushObservers;
--- a/layout/base/nsStyleSheetService.cpp
+++ b/layout/base/nsStyleSheetService.cpp
@@ -4,16 +4,17 @@
  * 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/. */
 
 /* implementation of interface for managing user and user-agent style sheets */
 
 #include "nsStyleSheetService.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/PreloadedStyleSheet.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/Unused.h"
 #include "mozilla/css/Loader.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "nsIURI.h"
@@ -150,18 +151,18 @@ nsStyleSheetService::LoadAndRegisterShee
           u"the sheet, if it's a data URI.";
       consoleService->LogStringMessage(message);
     }
   }
 
   rv = LoadAndRegisterSheetInternal(aSheetURI, aSheetType);
   if (NS_SUCCEEDED(rv)) {
     // Hold on to a copy of the registered PresShells.
-    nsTArray<nsCOMPtr<nsIPresShell>> toNotify(mPresShells);
-    for (nsIPresShell* presShell : toNotify) {
+    nsTArray<RefPtr<PresShell>> toNotify(mPresShells);
+    for (PresShell* presShell : toNotify) {
       StyleSheet* sheet = mSheets[aSheetType].LastElement();
       presShell->NotifyStyleSheetServiceSheetAdded(sheet, aSheetType);
     }
 
     if (XRE_IsParentProcess()) {
       nsTArray<dom::ContentParent*> children;
       dom::ContentParent::GetAll(children);
 
@@ -316,18 +317,18 @@ nsStyleSheetService::UnregisterSheet(nsI
   RefPtr<StyleSheet> sheet;
   int32_t foundIndex = FindSheetByURI(aSheetType, aSheetURI);
   if (foundIndex >= 0) {
     sheet = mSheets[aSheetType][foundIndex];
     mSheets[aSheetType].RemoveElementAt(foundIndex);
   }
 
   // Hold on to a copy of the registered PresShells.
-  nsTArray<nsCOMPtr<nsIPresShell>> toNotify(mPresShells);
-  for (nsIPresShell* presShell : toNotify) {
+  nsTArray<RefPtr<PresShell>> toNotify(mPresShells);
+  for (PresShell* presShell : toNotify) {
     if (presShell->StyleSet()) {
       if (sheet) {
         presShell->NotifyStyleSheetServiceSheetRemoved(sheet, aSheetType);
       }
     }
   }
 
   if (XRE_IsParentProcess()) {
@@ -384,17 +385,17 @@ size_t nsStyleSheetService::SizeOfInclud
       if (sheet) {
         n += sheet->SizeOfIncludingThis(aMallocSizeOf);
       }
     }
   }
   return n;
 }
 
-void nsStyleSheetService::RegisterPresShell(nsIPresShell* aPresShell) {
+void nsStyleSheetService::RegisterPresShell(PresShell* aPresShell) {
   MOZ_ASSERT(!mPresShells.Contains(aPresShell));
   mPresShells.AppendElement(aPresShell);
 }
 
-void nsStyleSheetService::UnregisterPresShell(nsIPresShell* aPresShell) {
+void nsStyleSheetService::UnregisterPresShell(PresShell* aPresShell) {
   MOZ_ASSERT(mPresShells.Contains(aPresShell));
   mPresShells.RemoveElement(aPresShell);
 }
--- a/layout/base/nsStyleSheetService.h
+++ b/layout/base/nsStyleSheetService.h
@@ -15,19 +15,22 @@
 #include "nsIStyleSheetService.h"
 #include "mozilla/Array.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StyleSheet.h"
 
 class nsICategoryManager;
 class nsIMemoryReporter;
-class nsIPresShell;
 class nsISimpleEnumerator;
 
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
+
 #define NS_STYLESHEETSERVICE_CID                     \
   {                                                  \
     0x3b55e72e, 0xab7e, 0x431b, {                    \
       0x89, 0xc0, 0x3b, 0x06, 0xa8, 0xb1, 0x40, 0x16 \
     }                                                \
   }
 
 #define NS_STYLESHEETSERVICE_CONTRACTID \
@@ -45,18 +48,18 @@ class nsStyleSheetService final : public
   NS_DECL_NSIMEMORYREPORTER
 
   nsresult Init();
 
   SheetArray* AgentStyleSheets() { return &mSheets[AGENT_SHEET]; }
   SheetArray* UserStyleSheets() { return &mSheets[USER_SHEET]; }
   SheetArray* AuthorStyleSheets() { return &mSheets[AUTHOR_SHEET]; }
 
-  void RegisterPresShell(nsIPresShell* aPresShell);
-  void UnregisterPresShell(nsIPresShell* aPresShell);
+  void RegisterPresShell(mozilla::PresShell* aPresShell);
+  void UnregisterPresShell(mozilla::PresShell* aPresShell);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   static nsStyleSheetService* GetInstance();
   static nsStyleSheetService* gInstance;
 
  private:
   ~nsStyleSheetService();
@@ -71,12 +74,12 @@ class nsStyleSheetService final : public
   // Like LoadAndRegisterSheet, but doesn't notify.  If successful, the
   // new sheet will be the last sheet in mSheets[aSheetType].
   nsresult LoadAndRegisterSheetInternal(nsIURI* aSheetURI, uint32_t aSheetType);
 
   mozilla::Array<SheetArray, 3> mSheets;
 
   // Registered PresShells that will be notified when sheets are added and
   // removed from the style sheet service.
-  nsTArray<nsCOMPtr<nsIPresShell>> mPresShells;
+  nsTArray<RefPtr<mozilla::PresShell>> mPresShells;
 };
 
 #endif
--- a/layout/doc/DD-SpaceManager.html
+++ b/layout/doc/DD-SpaceManager.html
@@ -59,17 +59,17 @@ impact intervals.
  
 <pre>/**
  * Class for dealing with bands of available space. The space manager
  * defines a coordinate space with an origin at (0, 0) that grows down
  * and to the right.
  */
 class nsSpaceManager {
 public:
-  nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame);
+  nsSpaceManager(PresShell* aPresShell, nsIFrame* aFrame);
   ~nsSpaceManager();
 
   void* operator new(size_t aSize);
   void operator delete(void* aPtr, size_t aSize);
 
   static void Shutdown();
 
   /*
@@ -323,17 +323,17 @@ private:
  
 <h4>Life Cycle:</h4>
 <p>
   The Constructor requires a Presentation Shell, used for arena allocations
  mostly, and a frame that this Space Manager is rooted on. &nbsp;The coordinate
  space of this Space Manager is relative to the frame passed in to the constructor.
 </p>
  
-<pre>  nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame);
+<pre>  nsSpaceManager(PresShell* aPresShell, nsIFrame* aFrame);
   ~nsSpaceManager();
 </pre>
 <p>
   Operators 'new' and 'delete' are overridden to support a recycler. &nbsp;Space
  Manager instances come and go pretty frequently, and this recycler prevents
  excessive heap allocations and the performance penalties associated with
 it. The #define NS_SPACE_MANAGER_CACHE_SIZE is used to control the number
 of Space Manager instances that can be present in the recycler, currently
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -1325,22 +1325,22 @@ NS_IMETHODIMP
 nsTextControlFrame::EditorInitializer::Run() {
   if (!mFrame) {
     return NS_OK;
   }
 
   // Need to block script to avoid bug 669767.
   nsAutoScriptBlocker scriptBlocker;
 
-  nsCOMPtr<nsIPresShell> shell = mFrame->PresContext()->GetPresShell();
-  bool observes = shell->ObservesNativeAnonMutationsForPrint();
-  shell->ObserveNativeAnonMutationsForPrint(true);
+  RefPtr<mozilla::PresShell> presShell = mFrame->PresShell();
+  bool observes = presShell->ObservesNativeAnonMutationsForPrint();
+  presShell->ObserveNativeAnonMutationsForPrint(true);
   // This can cause the frame to be destroyed (and call Revoke()).
   mFrame->EnsureEditorInitialized();
-  shell->ObserveNativeAnonMutationsForPrint(observes);
+  presShell->ObserveNativeAnonMutationsForPrint(observes);
 
   // The frame can *still* be destroyed even though we have a scriptblocker,
   // bug 682684.
   if (!mFrame) {
     return NS_ERROR_FAILURE;
   }
 
   mFrame->FinishedInitializer();
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -145,52 +145,52 @@ void nsContainerFrame::RemoveFrame(Child
   {
     nsIFrame* continuation = aOldFrame;
     while (continuation) {
       continuations.AppendElement(continuation);
       continuation = continuation->GetNextContinuation();
     }
   }
 
-  nsIPresShell* shell = PresShell();
+  mozilla::PresShell* presShell = PresShell();
   nsContainerFrame* lastParent = nullptr;
 
   // Loop and destroy aOldFrame and all of its continuations.
   //
   // Request a reflow on the parent frames involved unless we were explicitly
   // told not to (kNoReflowPrincipalList).
   const bool generateReflowCommand = (kNoReflowPrincipalList != aListID);
   for (nsIFrame* continuation : Reversed(continuations)) {
     nsContainerFrame* parent = continuation->GetParent();
 
     // Please note that 'parent' may not actually be where 'continuation' lives.
     // We really MUST use StealFrame() and nothing else here.
     // @see nsInlineFrame::StealFrame for details.
     parent->StealFrame(continuation);
     continuation->Destroy();
     if (generateReflowCommand && parent != lastParent) {
-      shell->FrameNeedsReflow(parent, nsIPresShell::eTreeChange,
-                              NS_FRAME_HAS_DIRTY_CHILDREN);
+      presShell->FrameNeedsReflow(parent, nsIPresShell::eTreeChange,
+                                  NS_FRAME_HAS_DIRTY_CHILDREN);
       lastParent = parent;
     }
   }
 }
 
 void nsContainerFrame::DestroyAbsoluteFrames(
     nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) {
   if (IsAbsoluteContainer()) {
     GetAbsoluteContainingBlock()->DestroyFrames(this, aDestructRoot,
                                                 aPostDestroyData);
     MarkAsNotAbsoluteContainingBlock();
   }
 }
 
 void nsContainerFrame::SafelyDestroyFrameListProp(
     nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData,
-    nsIPresShell* aPresShell, FrameListPropertyDescriptor aProp) {
+    mozilla::PresShell* aPresShell, FrameListPropertyDescriptor aProp) {
   // Note that the last frame can be removed through another route and thus
   // delete the property -- that's why we fetch the property again before
   // removing each frame rather than fetching it once and iterating the list.
   while (nsFrameList* frameList = GetProperty(aProp)) {
     nsIFrame* frame = frameList->RemoveFirstChild();
     if (MOZ_LIKELY(frame)) {
       frame->DestroyFrom(aDestructRoot, aPostDestroyData);
     } else {
--- a/layout/generic/nsContainerFrame.h
+++ b/layout/generic/nsContainerFrame.h
@@ -21,16 +21,20 @@
 #define NS_FRAME_NO_SIZE_VIEW 0x0004
 #define NS_FRAME_NO_VISIBILITY 0x0008
 // Only applies to ReflowChild; if true, don't delete the next-in-flow, even
 // if the reflow is fully complete.
 #define NS_FRAME_NO_DELETE_NEXT_IN_FLOW_CHILD 0x0010
 
 class nsOverflowContinuationTracker;
 
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
+
 // Some macros for container classes to do sanity checking on
 // width/height/x/y values computed during reflow.
 // NOTE: AppUnitsPerCSSPixel value hardwired here to remove the
 // dependency on nsDeviceContext.h.  It doesn't matter if it's a
 // little off.
 #ifdef DEBUG
 // 10 million pixels, converted to app units. Note that this a bit larger
 // than 1/4 of nscoord_MAX. So, if any content gets to be this large, we're
@@ -645,17 +649,17 @@ class nsContainerFrame : public nsSplitt
 
   /**
    * Safely destroy the frames on the nsFrameList stored on aProp for this
    * frame then remove the property and delete the frame list.
    * Nothing happens if the property doesn't exist.
    */
   void SafelyDestroyFrameListProp(nsIFrame* aDestructRoot,
                                   PostDestroyData& aPostDestroyData,
-                                  nsIPresShell* aPresShell,
+                                  mozilla::PresShell* aPresShell,
                                   FrameListPropertyDescriptor aProp);
 
   // ==========================================================================
 
   // Helper used by Progress and Meter frames. Returns true if the bar should
   // be rendered vertically, based on writing-mode and -moz-orient properties.
   bool ResolvedOrientationIsVertical();
 
--- a/layout/generic/nsFloatManager.cpp
+++ b/layout/generic/nsFloatManager.cpp
@@ -7,36 +7,36 @@
 /* class that manages rules for positioning floats */
 
 #include "nsFloatManager.h"
 
 #include <algorithm>
 #include <initializer_list>
 
 #include "gfxContext.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/ReflowInput.h"
 #include "mozilla/ShapeUtils.h"
 #include "nsBlockFrame.h"
 #include "nsDeviceContext.h"
 #include "nsError.h"
 #include "nsImageRenderer.h"
-#include "nsIPresShell.h"
 #include "nsMemory.h"
 
 using namespace mozilla;
 using namespace mozilla::image;
 using namespace mozilla::gfx;
 
 int32_t nsFloatManager::sCachedFloatManagerCount = 0;
 void* nsFloatManager::sCachedFloatManagers[NS_FLOAT_MANAGER_CACHE_SIZE];
 
 /////////////////////////////////////////////////////////////////////////////
 // nsFloatManager
 
-nsFloatManager::nsFloatManager(nsIPresShell* aPresShell, WritingMode aWM)
+nsFloatManager::nsFloatManager(PresShell* aPresShell, WritingMode aWM)
     :
 #ifdef DEBUG
       mWritingMode(aWM),
 #endif
       mLineLeft(0),
       mBlockStart(0),
       mFloatDamage(aPresShell),
       mPushedLeftFloatPastBreak(false),
--- a/layout/generic/nsFloatManager.h
+++ b/layout/generic/nsFloatManager.h
@@ -14,21 +14,21 @@
 #include "mozilla/UniquePtr.h"
 #include "mozilla/WritingModes.h"
 #include "nsCoord.h"
 #include "nsFrameList.h"  // for DEBUG_FRAME_DUMP
 #include "nsIntervalSet.h"
 #include "nsPoint.h"
 #include "nsTArray.h"
 
-class nsIPresShell;
 class nsIFrame;
 class nsPresContext;
 namespace mozilla {
 struct ReflowInput;
+class PresShell;
 class StyleBasicShape;
 }  // namespace mozilla
 
 enum class nsFlowAreaRectFlags : uint32_t {
   NO_FLAGS = 0,
   HAS_FLOATS = 1 << 0,
   MAY_WIDEN = 1 << 1
 };
@@ -87,17 +87,18 @@ struct nsFlowAreaRect {
  * physical types like nsRect, nsPoint, etc. use this coordinate space. See
  * FloatInfo::mRect for an example.
  *
  * [1] https://drafts.csswg.org/css-writing-modes/#line-mappings
  * [2] https://drafts.csswg.org/css-writing-modes/#logical-to-physical
  */
 class nsFloatManager {
  public:
-  explicit nsFloatManager(nsIPresShell* aPresShell, mozilla::WritingMode aWM);
+  explicit nsFloatManager(mozilla::PresShell* aPresShell,
+                          mozilla::WritingMode aWM);
   ~nsFloatManager();
 
   void* operator new(size_t aSize) CPP_THROW_NEW;
   void operator delete(void* aPtr, size_t aSize);
 
   static void Shutdown();
 
   /**
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -762,17 +762,17 @@ void nsFrame::DestroyFrom(nsIFrame* aDes
     StickyScrollContainer* ssc =
         StickyScrollContainer::GetStickyScrollContainerForFrame(this);
     if (ssc) {
       ssc->RemoveFrame(this);
     }
   }
 
   nsPresContext* presContext = PresContext();
-  nsIPresShell* shell = presContext->GetPresShell();
+  mozilla::PresShell* presShell = presContext->GetPresShell();
   if (mState & NS_FRAME_OUT_OF_FLOW) {
     nsPlaceholderFrame* placeholder = GetPlaceholderFrame();
     NS_ASSERTION(
         !placeholder || (aDestructRoot != this),
         "Don't call Destroy() on OOFs, call Destroy() on the placeholder.");
     NS_ASSERTION(!placeholder || nsLayoutUtils::IsProperAncestorFrame(
                                      aDestructRoot, placeholder),
                  "Placeholder relationship should have been torn down already; "
@@ -812,20 +812,20 @@ void nsFrame::DestroyFrom(nsIFrame* aDes
   // XXX(seth): It'd be ideal to assert that we're already marked nonvisible
   // here, but it's unfortunately tricky to guarantee in the face of things like
   // frame reconstruction induced by style changes.
   DisableVisibilityTracking();
 
   // Ensure that we're not in the approximately visible list anymore.
   PresContext()->GetPresShell()->RemoveFrameFromApproximatelyVisibleList(this);
 
-  shell->NotifyDestroyingFrame(this);
+  presShell->NotifyDestroyingFrame(this);
 
   if (mState & NS_FRAME_EXTERNAL_REFERENCE) {
-    shell->ClearFrameRefs(this);
+    presShell->ClearFrameRefs(this);
   }
 
   nsView* view = GetView();
   if (view) {
     view->SetFrame(nullptr);
     view->Destroy();
   }
 
@@ -853,17 +853,17 @@ void nsFrame::DestroyFrom(nsIFrame* aDes
   // the compiler cannot devirtualize the call to the destructor even
   // if it's from a method defined in the same class.
 
   nsQueryFrame::FrameIID id = GetFrameId();
   this->~nsFrame();
 
 #ifdef DEBUG
   {
-    nsIFrame* rootFrame = shell->GetRootFrame();
+    nsIFrame* rootFrame = presShell->GetRootFrame();
     MOZ_ASSERT(rootFrame);
     if (this != rootFrame) {
       const RetainedDisplayListData* data =
           GetRetainedDisplayListData(rootFrame);
 
       const bool inModifiedList =
           data && (data->GetFlags(this) &
                    RetainedDisplayListData::FrameFlags::Modified);
@@ -871,17 +871,17 @@ void nsFrame::DestroyFrom(nsIFrame* aDes
       MOZ_ASSERT(!inModifiedList,
                  "A dtor added this frame to modified frames list!");
     }
   }
 #endif
 
   // Now that we're totally cleaned out, we need to add ourselves to
   // the presshell's recycler.
-  shell->FreeFrame(id, this);
+  presShell->FreeFrame(id, this);
 }
 
 nsresult nsFrame::GetOffsets(int32_t& aStart, int32_t& aEnd) const {
   aStart = 0;
   aEnd = 0;
   return NS_OK;
 }
 
@@ -4032,17 +4032,17 @@ nsresult nsFrame::HandleEvent(nsPresCont
     } else if (aEvent->mMessage == eMouseUp || aEvent->mMessage == eTouchEnd) {
       HandleRelease(aPresContext, aEvent, aEventStatus);
     }
   }
   return NS_OK;
 }
 
 nsresult nsFrame::GetDataForTableSelection(
-    const nsFrameSelection* aFrameSelection, nsIPresShell* aPresShell,
+    const nsFrameSelection* aFrameSelection, mozilla::PresShell* aPresShell,
     WidgetMouseEvent* aMouseEvent, nsIContent** aParentContent,
     int32_t* aContentOffset, TableSelection* aTarget) {
   if (!aFrameSelection || !aPresShell || !aMouseEvent || !aParentContent ||
       !aContentOffset || !aTarget)
     return NS_ERROR_NULL_POINTER;
 
   *aParentContent = nullptr;
   *aContentOffset = 0;
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -94,28 +94,28 @@ class PresShell;
 // without its own operator new and GetFrameId gets instantiated, the
 // per-frame recycler lists in nsPresArena will not work correctly,
 // with potentially catastrophic consequences (not enough memory is
 // allocated for a frame object).
 
 #define NS_DECL_FRAMEARENA_HELPERS(class)                                      \
   NS_DECL_QUERYFRAME_TARGET(class)                                             \
   static constexpr nsIFrame::ClassID kClassID = nsIFrame::ClassID::class##_id; \
-  void* operator new(size_t, nsIPresShell*) MOZ_MUST_OVERRIDE;                 \
+  void* operator new(size_t, mozilla::PresShell*) MOZ_MUST_OVERRIDE;           \
   nsQueryFrame::FrameIID GetFrameId() const override MOZ_MUST_OVERRIDE {       \
     return nsQueryFrame::class##_id;                                           \
   }
 
-#define NS_IMPL_FRAMEARENA_HELPERS(class)                       \
-  void* class ::operator new(size_t sz, nsIPresShell* aShell) { \
-    return aShell->AllocateFrame(nsQueryFrame::class##_id, sz); \
+#define NS_IMPL_FRAMEARENA_HELPERS(class)                             \
+  void* class ::operator new(size_t sz, mozilla::PresShell* aShell) { \
+    return aShell->AllocateFrame(nsQueryFrame::class##_id, sz);       \
   }
 
-#define NS_DECL_ABSTRACT_FRAME(class)                                   \
-  void* operator new(size_t, nsIPresShell*) MOZ_MUST_OVERRIDE = delete; \
+#define NS_DECL_ABSTRACT_FRAME(class)                                         \
+  void* operator new(size_t, mozilla::PresShell*) MOZ_MUST_OVERRIDE = delete; \
   nsQueryFrame::FrameIID GetFrameId() const override MOZ_MUST_OVERRIDE = 0;
 
 //----------------------------------------------------------------------
 
 struct nsBoxLayoutMetrics;
 struct nsRect;
 
 /**
@@ -153,17 +153,17 @@ class nsFrame : public nsBox {
 
  public:
   // nsQueryFrame
   NS_DECL_QUERYFRAME
   NS_DECL_QUERYFRAME_TARGET(nsFrame)
   virtual nsQueryFrame::FrameIID GetFrameId() const MOZ_MUST_OVERRIDE {
     return kFrameIID;
   }
-  void* operator new(size_t, nsIPresShell*) MOZ_MUST_OVERRIDE;
+  void* operator new(size_t, mozilla::PresShell*) MOZ_MUST_OVERRIDE;
 
   // nsIFrame
   void Init(nsIContent* aContent, nsContainerFrame* aParent,
             nsIFrame* aPrevInFlow) override;
   void DestroyFrom(nsIFrame* aDestructRoot,
                    PostDestroyData& aPostDestroyData) override;
   ComputedStyle* GetAdditionalComputedStyle(int32_t aIndex) const override;
   void SetAdditionalComputedStyle(int32_t aIndex,
@@ -643,17 +643,17 @@ class nsFrame : public nsBox {
   //  Most table/cell selection requires that Ctrl (Cmd on Mac) key is down
   //   during a mouse click or drag. Exception is using Shift+click when
   //   already in "table/cell selection mode" to extend a block selection
   //  Get the parent content node and offset of the frame
   //   of the enclosing cell or table (if not inside a cell)
   //  aTarget tells us what table element to select (currently only cell and
   //  table supported) (enums for this are defined in nsIFrame.h)
   nsresult GetDataForTableSelection(const nsFrameSelection* aFrameSelection,
-                                    nsIPresShell* aPresShell,
+                                    mozilla::PresShell* aPresShell,
                                     mozilla::WidgetMouseEvent* aMouseEvent,
                                     nsIContent** aParentContent,
                                     int32_t* aContentOffset,
                                     mozilla::TableSelection* aTarget);
 
   NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
 
   nsBoxLayoutMetrics* BoxMetrics() const;
--- a/layout/generic/nsFrameList.cpp
+++ b/layout/generic/nsFrameList.cpp
@@ -20,21 +20,21 @@ using namespace mozilla;
 namespace mozilla {
 namespace layout {
 namespace detail {
 const AlignedFrameListBytes gEmptyFrameListBytes = {0};
 }  // namespace detail
 }  // namespace layout
 }  // namespace mozilla
 
-void* nsFrameList::operator new(size_t sz, nsIPresShell* aPresShell) {
+void* nsFrameList::operator new(size_t sz, mozilla::PresShell* aPresShell) {
   return aPresShell->AllocateByObjectID(eArenaObjectID_nsFrameList, sz);
 }
 
-void nsFrameList::Delete(nsIPresShell* aPresShell) {
+void nsFrameList::Delete(mozilla::PresShell* aPresShell) {
   MOZ_ASSERT(this != &EmptyList(), "Shouldn't Delete() this list");
   NS_ASSERTION(IsEmpty(), "Shouldn't Delete() a non-empty list");
 
   aPresShell->FreeByObjectID(eArenaObjectID_nsFrameList, this);
 }
 
 void nsFrameList::DestroyFrames() {
   while (nsIFrame* frame = RemoveFirstChild()) {
--- a/layout/generic/nsFrameList.h
+++ b/layout/generic/nsFrameList.h
@@ -18,20 +18,20 @@
 // DEBUG_FRAME_DUMP enables nsIFrame::List and related methods.
 // You can also define this in a non-DEBUG build if you need frame dumps.
 #  define DEBUG_FRAME_DUMP 1
 #endif
 
 class nsContainerFrame;
 class nsIContent;
 class nsIFrame;
-class nsIPresShell;
 class nsPresContext;
 
 namespace mozilla {
+class PresShell;
 namespace layout {
 class FrameChildList;
 enum FrameChildListID {
   // The individual concrete child lists.
   kPrincipalList,
   kPopupList,
   kCaptionList,
   kColGroupList,
@@ -81,23 +81,23 @@ class nsFrameList {
   }
 
   nsFrameList(const nsFrameList& aOther)
       : mFirstChild(aOther.mFirstChild), mLastChild(aOther.mLastChild) {}
 
   /**
    * Infallibly allocate a nsFrameList from the shell arena.
    */
-  void* operator new(size_t sz, nsIPresShell* aPresShell);
+  void* operator new(size_t sz, mozilla::PresShell* aPresShell);
 
   /**
    * Deallocate this list that was allocated from the shell arena.
    * The list is required to be empty.
    */
-  void Delete(nsIPresShell* aPresShell);
+  void Delete(mozilla::PresShell* aPresShell);
 
   /**
    * For each frame in this list: remove it from the list then call
    * Destroy() on it.
    */
   void DestroyFrames();
 
   /**
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -2736,17 +2736,17 @@ void nsFrameSelection::DisconnectFromPre
  * Therefore, we only update the selection cache on a repaint
  * if the current selection being repainted is not an empty selection.
  *
  * If the current selection is empty. The current selection cache
  * would be cleared by AutoCopyListener::OnSelectionChange().
  */
 nsresult nsFrameSelection::UpdateSelectionCacheOnRepaintSelection(
     Selection* aSel) {
-  PresShell* presShell = static_cast<PresShell*>(aSel->GetPresShell());
+  PresShell* presShell = aSel->GetPresShell();
   if (!presShell) {
     return NS_OK;
   }
   nsCOMPtr<Document> aDoc = presShell->GetDocument();
 
   if (aDoc && aSel && !aSel->IsCollapsed()) {
     return nsCopySupport::HTMLCopy(aSel, aDoc, nsIClipboard::kSelectionCache,
                                    false);
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -3822,17 +3822,17 @@ class nsIFrame : public nsQueryFrame {
         shell->IncrementPaintCount();
       }
     }
   }
 
   /**
    * @return true if we painted @aPresShell during the last repaint.
    */
-  bool DidPaintPresShell(nsIPresShell* aShell) {
+  bool DidPaintPresShell(mozilla::PresShell* aShell) {
     for (nsWeakPtr& item : *PaintedPresShellList()) {
       nsCOMPtr<nsIPresShell> shell = do_QueryReferent(item);
       if (shell == aShell) {
         return true;
       }
     }
     return false;
   }
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -167,18 +167,18 @@ bool nsImageFrame::ShouldShowBrokenImage
            (imageStatus & imgIRequest::STATUS_ERROR);
   }
 
   nsCOMPtr<nsIImageLoadingContent> loader = do_QueryInterface(mContent);
   MOZ_ASSERT(loader);
   return loader->GetImageBlockingStatus() != nsIContentPolicy::ACCEPT;
 }
 
-nsImageFrame* nsImageFrame::CreateContinuingFrame(nsIPresShell* aPresShell,
-                                                  ComputedStyle* aStyle) const {
+nsImageFrame* nsImageFrame::CreateContinuingFrame(
+    mozilla::PresShell* aPresShell, ComputedStyle* aStyle) const {
   return new (aPresShell)
       nsImageFrame(aStyle, aPresShell->GetPresContext(), mKind);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsImageFrame)
 
 nsImageFrame::nsImageFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
                            ClassID aID, Kind aKind)
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -190,17 +190,18 @@ class nsImageFrame : public nsAtomicCont
     // For css 'content: url(..)' on non-generated content.
     ContentProperty,
     // For a child of a ::before / ::after pseudo-element that had an url() item
     // for the content property.
     ContentPropertyAtIndex,
   };
 
   // Creates a suitable continuing frame for this frame.
-  nsImageFrame* CreateContinuingFrame(nsIPresShell*, ComputedStyle*) const;
+  nsImageFrame* CreateContinuingFrame(mozilla::PresShell*,
+                                      ComputedStyle*) const;
 
  private:
   friend nsIFrame* NS_NewImageFrame(mozilla::PresShell*, ComputedStyle*);
   friend nsIFrame* NS_NewImageFrameForContentProperty(mozilla::PresShell*,
                                                       ComputedStyle*);
   friend nsIFrame* NS_NewImageFrameForGeneratedContentIndex(mozilla::PresShell*,
                                                             ComputedStyle*);
 
--- a/layout/generic/nsIntervalSet.cpp
+++ b/layout/generic/nsIntervalSet.cpp
@@ -4,21 +4,21 @@
  * 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/. */
 
 /* a set of ranges on a number-line */
 
 #include "nsIntervalSet.h"
 #include <new>
 #include <algorithm>
-#include "nsIPresShell.h"  // for allocation
+#include "mozilla/PresShell.h"  // for allocation
 
 using namespace mozilla;
 
-nsIntervalSet::nsIntervalSet(nsIPresShell *aPresShell)
+nsIntervalSet::nsIntervalSet(PresShell *aPresShell)
     : mList(nullptr), mPresShell(aPresShell) {}
 
 nsIntervalSet::~nsIntervalSet() {
   Interval *current = mList;
   while (current) {
     Interval *trash = current;
     current = current->mNext;
     FreeInterval(trash);
--- a/layout/generic/nsIntervalSet.h
+++ b/layout/generic/nsIntervalSet.h
@@ -6,27 +6,29 @@
 
 /* a set of ranges on a number-line */
 
 #ifndef nsIntervalSet_h___
 #define nsIntervalSet_h___
 
 #include "nsCoord.h"
 
-class nsIPresShell;
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
 
 /*
  * A list-based class (hopefully tree-based when I get around to it)
  * for representing a set of ranges on a number-line.
  */
 class nsIntervalSet {
  public:
   typedef nscoord coord_type;
 
-  explicit nsIntervalSet(nsIPresShell *aPresShell);
+  explicit nsIntervalSet(mozilla::PresShell *aPresShell);
   ~nsIntervalSet();
 
   /*
    * Include the interval [aBegin, aEnd] in the set.
    *
    * Removal of intervals added is not supported because that would
    * require keeping track of the individual intervals that were
    * added (nsIntervalMap should do that).  It would be simple to
@@ -59,12 +61,12 @@ class nsIntervalSet {
     Interval *mPrev;
     Interval *mNext;
   };
 
   void *AllocateInterval();
   void FreeInterval(Interval *aInterval);
 
   Interval *mList;
-  nsIPresShell *mPresShell;
+  mozilla::PresShell *mPresShell;
 };
 
 #endif  // !defined(nsIntervalSet_h___)
--- a/layout/generic/nsLineBox.cpp
+++ b/layout/generic/nsLineBox.cpp
@@ -71,22 +71,22 @@ nsLineBox::nsLineBox(nsIFrame* aFrame, i
 nsLineBox::~nsLineBox() {
   MOZ_COUNT_DTOR(nsLineBox);
   if (MOZ_UNLIKELY(mFlags.mHasHashedFrames)) {
     delete mFrames;
   }
   Cleanup();
 }
 
-nsLineBox* NS_NewLineBox(nsIPresShell* aPresShell, nsIFrame* aFrame,
+nsLineBox* NS_NewLineBox(PresShell* aPresShell, nsIFrame* aFrame,
                          bool aIsBlock) {
   return new (aPresShell) nsLineBox(aFrame, 1, aIsBlock);
 }
 
-nsLineBox* NS_NewLineBox(nsIPresShell* aPresShell, nsLineBox* aFromLine,
+nsLineBox* NS_NewLineBox(PresShell* aPresShell, nsLineBox* aFromLine,
                          nsIFrame* aFrame, int32_t aCount) {
   nsLineBox* newLine = new (aPresShell) nsLineBox(aFrame, aCount, false);
   newLine->NoteFramesMovedFrom(aFromLine);
   newLine->mContainerSize = aFromLine->mContainerSize;
   return newLine;
 }
 
 void nsLineBox::AddSizeOfExcludingThis(nsWindowSizes& aSizes) const {
@@ -149,21 +149,21 @@ void nsLineBox::NoteFramesMovedFrom(nsLi
       // This line needs a hash table, but it's fewer hash ops to steal
       // aFromLine's hash table and allocate a new hash table for that line.
       StealHashTableFrom(aFromLine, fromNewCount);  // fromNewCount RemoveEntry
       aFromLine->SwitchToHashtable();               // fromNewCount PutEntry
     }
   }
 }
 
-void* nsLineBox::operator new(size_t sz, nsIPresShell* aPresShell) {
+void* nsLineBox::operator new(size_t sz, PresShell* aPresShell) {
   return aPresShell->AllocateByObjectID(eArenaObjectID_nsLineBox, sz);
 }
 
-void nsLineBox::Destroy(nsIPresShell* aPresShell) {
+void nsLineBox::Destroy(PresShell* aPresShell) {
   this->nsLineBox::~nsLineBox();
   aPresShell->FreeByObjectID(eArenaObjectID_nsLineBox, this);
 }
 
 void nsLineBox::Cleanup() {
   if (mData) {
     if (IsBlock()) {
       delete mBlockData;
--- a/layout/generic/nsLineBox.h
+++ b/layout/generic/nsLineBox.h
@@ -17,16 +17,20 @@
 #include <algorithm>
 
 class nsLineBox;
 class nsFloatCache;
 class nsFloatCacheList;
 class nsFloatCacheFreeList;
 class nsWindowSizes;
 
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
+
 // State cached after reflowing a float. This state is used during
 // incremental reflow when we avoid reflowing a float.
 class nsFloatCache {
  public:
   nsFloatCache();
 #ifdef NS_BUILD_REFCNT_LOGGING
   ~nsFloatCache();
 #else
@@ -135,23 +139,23 @@ class nsFloatCacheFreeList : private nsF
 /**
  * Function to create a line box and initialize it with a single frame.
  * The allocation is infallible.
  * If the frame was moved from another line then you're responsible
  * for notifying that line using NoteFrameRemoved().  Alternatively,
  * it's better to use the next function that does that for you in an
  * optimal way.
  */
-nsLineBox* NS_NewLineBox(nsIPresShell* aPresShell, nsIFrame* aFrame,
+nsLineBox* NS_NewLineBox(mozilla::PresShell* aPresShell, nsIFrame* aFrame,
                          bool aIsBlock);
 /**
  * Function to create a line box and initialize it with aCount frames
  * that are currently on aFromLine.  The allocation is infallible.
  */
-nsLineBox* NS_NewLineBox(nsIPresShell* aPresShell, nsLineBox* aFromLine,
+nsLineBox* NS_NewLineBox(mozilla::PresShell* aPresShell, nsLineBox* aFromLine,
                          nsIFrame* aFrame, int32_t aCount);
 
 class nsLineList;
 
 // don't use the following names outside of this file.  Instead, use
 // nsLineList::iterator, etc.  These are just here to allow them to
 // be specified as parameters to methods of nsLineBox.
 class nsLineList_iterator;
@@ -186,27 +190,27 @@ class nsLineLink {
  */
 class nsLineBox final : public nsLineLink {
  private:
   nsLineBox(nsIFrame* aFrame, int32_t aCount, bool aIsBlock);
   ~nsLineBox();
 
   // Infallible overloaded new operator. Uses an arena (which comes from the
   // presShell) to perform the allocation.
-  void* operator new(size_t sz, nsIPresShell* aPresShell);
+  void* operator new(size_t sz, mozilla::PresShell* aPresShell);
   void operator delete(void* aPtr, size_t sz) = delete;
 
  public:
   // Use these functions to allocate and destroy line boxes
-  friend nsLineBox* NS_NewLineBox(nsIPresShell* aPresShell, nsIFrame* aFrame,
-                                  bool aIsBlock);
-  friend nsLineBox* NS_NewLineBox(nsIPresShell* aPresShell,
+  friend nsLineBox* NS_NewLineBox(mozilla::PresShell* aPresShell,
+                                  nsIFrame* aFrame, bool aIsBlock);
+  friend nsLineBox* NS_NewLineBox(mozilla::PresShell* aPresShell,
                                   nsLineBox* aFromLine, nsIFrame* aFrame,
                                   int32_t aCount);
-  void Destroy(nsIPresShell* aPresShell);
+  void Destroy(mozilla::PresShell* aPresShell);
 
   // mBlock bit
   bool IsBlock() const { return mFlags.mBlock; }
   bool IsInline() const { return !mFlags.mBlock; }
 
   // mDirty bit
   void MarkDirty() { mFlags.mDirty = 1; }
   void ClearDirty() { mFlags.mDirty = 0; }
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -189,17 +189,17 @@ void nsSubDocumentFrame::ShowViewer() {
 }
 
 nsIFrame* nsSubDocumentFrame::GetSubdocumentRootFrame() {
   if (!mInnerView) return nullptr;
   nsView* subdocView = mInnerView->GetFirstChild();
   return subdocView ? subdocView->GetFrame() : nullptr;
 }
 
-nsIPresShell* nsSubDocumentFrame::GetSubdocumentPresShellForPainting(
+mozilla::PresShell* nsSubDocumentFrame::GetSubdocumentPresShellForPainting(
     uint32_t aFlags) {
   if (!mInnerView) return nullptr;
 
   nsView* subdocView = mInnerView->GetFirstChild();
   if (!subdocView) return nullptr;
 
   mozilla::PresShell* presShell = nullptr;
 
@@ -348,17 +348,17 @@ void nsSubDocumentFrame::BuildDisplayLis
     nsPoint offset = aBuilder->ToReferenceFrame(this);
     nsRect bounds = this->EnsureInnerView()->GetBounds() + offset;
     clipState.ClipContentDescendants(bounds);
 
     aLists.Content()->AppendNewToTop<nsDisplayRemote>(aBuilder, this);
     return;
   }
 
-  nsCOMPtr<nsIPresShell> presShell = GetSubdocumentPresShellForPainting(
+  RefPtr<mozilla::PresShell> presShell = GetSubdocumentPresShellForPainting(
       aBuilder->IsIgnoringPaintSuppression() ? IGNORE_PAINT_SUPPRESSION : 0);
 
   if (!presShell) {
     return;
   }
 
   if (aBuilder->IsInFilter()) {
     Document* outerDoc = PresShell()->GetDocument();
@@ -887,17 +887,17 @@ nsIFrame* NS_NewSubDocumentFrame(PresShe
       nsSubDocumentFrame(aStyle, aPresShell->GetPresContext());
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSubDocumentFrame)
 
 class nsHideViewer : public Runnable {
  public:
   nsHideViewer(nsIContent* aFrameElement, nsFrameLoader* aFrameLoader,
-               nsIPresShell* aPresShell, bool aHideViewerIfFrameless)
+               PresShell* aPresShell, bool aHideViewerIfFrameless)
       : mozilla::Runnable("nsHideViewer"),
         mFrameElement(aFrameElement),
         mFrameLoader(aFrameLoader),
         mPresShell(aPresShell),
         mHideViewerIfFrameless(aHideViewerIfFrameless) {
     NS_ASSERTION(mFrameElement, "Must have a frame element");
     NS_ASSERTION(mFrameLoader, "Must have a frame loader");
     NS_ASSERTION(mPresShell, "Must have a presshell");
@@ -931,17 +931,17 @@ class nsHideViewer : public Runnable {
       mFrameLoader->Hide();
     }
     return NS_OK;
   }
 
  private:
   nsCOMPtr<nsIContent> mFrameElement;
   RefPtr<nsFrameLoader> mFrameLoader;
-  nsCOMPtr<nsIPresShell> mPresShell;
+  RefPtr<PresShell> mPresShell;
   bool mHideViewerIfFrameless;
 };
 
 static nsView* BeginSwapDocShellsForViews(nsView* aSibling);
 
 void nsSubDocumentFrame::DestroyFrom(nsIFrame* aDestructRoot,
                                      PostDestroyData& aPostDestroyData) {
   if (mPostedReflowCallback) {
--- a/layout/generic/nsSubDocumentFrame.h
+++ b/layout/generic/nsSubDocumentFrame.h
@@ -9,16 +9,17 @@
 
 #include "mozilla/Attributes.h"
 #include "nsAtomicContainerFrame.h"
 #include "nsIReflowCallback.h"
 #include "nsFrameLoader.h"
 #include "Units.h"
 
 namespace mozilla {
+class PresShell;
 namespace layout {
 class RenderFrame;
 }
 }  // namespace mozilla
 
 /******************************************************************************
  * nsSubDocumentFrame
  *****************************************************************************/
@@ -89,17 +90,17 @@ class nsSubDocumentFrame final : public 
 #endif
 
   nsIDocShell* GetDocShell();
   nsresult BeginSwapDocShells(nsIFrame* aOther);
   void EndSwapDocShells(nsIFrame* aOther);
   nsView* EnsureInnerView();
   nsIFrame* GetSubdocumentRootFrame();
   enum { IGNORE_PAINT_SUPPRESSION = 0x1 };
-  nsIPresShell* GetSubdocumentPresShellForPainting(uint32_t aFlags);
+  mozilla::PresShell* GetSubdocumentPresShellForPainting(uint32_t aFlags);
   mozilla::ScreenIntSize GetSubdocumentSize();
 
   // nsIReflowCallback
   bool ReflowFinished() override;
   void ReflowCallbackCanceled() override;
 
   /**
    * Return true if pointer event hit-testing should be allowed to target
--- a/layout/painting/RetainedDisplayListBuilder.cpp
+++ b/layout/painting/RetainedDisplayListBuilder.cpp
@@ -203,17 +203,17 @@ bool RetainedDisplayListBuilder::PreProc
 void RetainedDisplayListBuilder::IncrementSubDocPresShellPaintCount(
     nsDisplayItem* aItem) {
   MOZ_ASSERT(aItem->GetType() == DisplayItemType::TYPE_SUBDOCUMENT);
 
   nsSubDocumentFrame* subDocFrame =
       static_cast<nsDisplaySubDocument*>(aItem)->SubDocumentFrame();
   MOZ_ASSERT(subDocFrame);
 
-  nsIPresShell* presShell = subDocFrame->GetSubdocumentPresShellForPainting(0);
+  PresShell* presShell = subDocFrame->GetSubdocumentPresShellForPainting(0);
   MOZ_ASSERT(presShell);
 
   mBuilder.IncrementPresShellPaintCount(presShell);
 }
 
 static bool AnyContentAncestorModified(nsIFrame* aFrame,
                                        nsIFrame* aStopAtFrame = nullptr) {
   for (nsIFrame* f = aFrame; f;
@@ -720,21 +720,20 @@ static nsIFrame* GetRootFrameForPainting
 
   nsIFrame* subDocFrame = subDocView->GetFrame();
   if (!subDocFrame) {
     return nullptr;
   }
 
   nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(subDocFrame);
   MOZ_ASSERT(subdocumentFrame);
-  presShell = static_cast<PresShell*>(
-      subdocumentFrame->GetSubdocumentPresShellForPainting(
-          aBuilder->IsIgnoringPaintSuppression()
-              ? nsSubDocumentFrame::IGNORE_PAINT_SUPPRESSION
-              : 0));
+  presShell = subdocumentFrame->GetSubdocumentPresShellForPainting(
+      aBuilder->IsIgnoringPaintSuppression()
+          ? nsSubDocumentFrame::IGNORE_PAINT_SUPPRESSION
+          : 0);
   return presShell ? presShell->GetRootFrame() : nullptr;
 }
 
 static bool SubDocEnumCb(Document* aDocument, void* aData) {
   MOZ_ASSERT(aDocument);
   MOZ_ASSERT(aData);
 
   CbData* data = static_cast<CbData*>(aData);
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -1433,20 +1433,19 @@ void nsDisplayListBuilder::SubtractFromV
   }
 }
 
 nsCaret* nsDisplayListBuilder::GetCaret() {
   RefPtr<nsCaret> caret = CurrentPresShellState()->mPresShell->GetCaret();
   return caret;
 }
 
-void nsDisplayListBuilder::IncrementPresShellPaintCount(
-    nsIPresShell* aPresShell) {
+void nsDisplayListBuilder::IncrementPresShellPaintCount(PresShell* aPresShell) {
   if (mIsPaintingToWindow) {
-    mReferenceFrame->AddPaintedPresShell(static_cast<PresShell*>(aPresShell));
+    mReferenceFrame->AddPaintedPresShell(aPresShell);
     aPresShell->IncrementPaintCount();
   }
 }
 
 void nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
                                           bool aPointerEventsNoneDoc) {
   PresShellState* state = mPresShellStates.AppendElement();
   state->mPresShell = aReferenceFrame->PresShell();
--- a/layout/painting/nsDisplayList.h
+++ b/layout/painting/nsDisplayList.h
@@ -64,16 +64,17 @@ class nsSubDocumentFrame;
 class nsDisplayCompositorHitTestInfo;
 class nsDisplayScrollInfoLayer;
 class nsCaret;
 enum class nsDisplayOwnLayerFlags;
 struct WrFiltersHolder;
 
 namespace mozilla {
 class FrameLayerBuilder;
+class PresShell;
 struct MotionPathData;
 namespace layers {
 struct FrameMetrics;
 class RenderRootStateManager;
 class Layer;
 class ImageLayer;
 class ImageContainer;
 class StackingContextHelper;
@@ -818,17 +819,17 @@ class nsDisplayListBuilder {
    */
   void ResetMarkedFramesForDisplayList(nsIFrame* aReferenceFrame);
   /**
    * Notify the display list builder that we're leaving a presshell.
    */
   void LeavePresShell(nsIFrame* aReferenceFrame,
                       nsDisplayList* aPaintedContents);
 
-  void IncrementPresShellPaintCount(nsIPresShell* aPresShell);
+  void IncrementPresShellPaintCount(mozilla::PresShell* aPresShell);
 
   /**
    * Returns true if we're currently building a display list that's
    * directly or indirectly under an nsDisplayTransform.
    */
   bool IsInTransform() const { return mInTransform; }
 
   bool InEventsAndPluginsOnly() const { return mInEventsAndPluginsOnly; }
@@ -1881,17 +1882,17 @@ class nsDisplayListBuilder {
   /**
    * Add the current frame to the AGR budget if possible and remember
    * the outcome. Subsequent calls will return the same value as
    * returned here.
    */
   bool AddToAGRBudget(nsIFrame* aFrame);
 
   struct PresShellState {
-    nsIPresShell* mPresShell;
+    mozilla::PresShell* mPresShell;
 #ifdef DEBUG
     mozilla::Maybe<nsAutoLayoutPhase> mAutoLayoutPhase;
 #endif
     nsIFrame* mCaretFrame;
     nsRect mCaretRect;
     mozilla::Maybe<OutOfFlowDisplayData> mFixedBackgroundDisplayData;
     uint32_t mFirstFrameMarkedForDisplay;
     uint32_t mFirstFrameWithOOFData;
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -1637,17 +1637,17 @@ nsresult nsPrintJob::ReconstructAndReflo
 
       MOZ_ASSERT(!documentIsTopLevel, "How could this happen?");
 
       if (NS_FAILED(rv) || doReturn) {
         return rv;
       }
     }
 
-    RefPtr<PresShell> presShell = static_cast<PresShell*>(po->mPresShell.get());
+    RefPtr<PresShell> presShell = po->mPresShell;
     presShell->FlushPendingNotifications(FlushType::Layout);
 
     // If the printing was canceled or restarted with different data,
     // let's stop doing this printing.
     if (NS_WARN_IF(mPrt != printData)) {
       return NS_ERROR_FAILURE;
     }
 
@@ -2277,27 +2277,26 @@ nsresult nsPrintJob::ReflowPrintObject(c
   aPO->mPresContext->SetPageScale(aPO->mZoomRatio);
   // Calculate scale factor from printer to screen
   float printDPI = float(AppUnitsPerCSSInch()) /
                    float(printData->mPrintDC->AppUnitsPerDevPixel());
   aPO->mPresContext->SetPrintPreviewScale(mScreenDPI / printDPI);
 
   if (mIsCreatingPrintPreview && documentIsTopLevel) {
     mDocViewerPrint->SetPrintPreviewPresentation(
-        aPO->mViewManager, aPO->mPresContext,
-        static_cast<PresShell*>(aPO->mPresShell.get()));
+        aPO->mViewManager, aPO->mPresContext, aPO->mPresShell.get());
   }
 
   rv = aPO->mPresShell->Initialize();
 
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ASSERTION(aPO->mPresShell, "Presshell should still be here");
 
   // Process the reflow event Initialize posted
-  RefPtr<PresShell> presShell = static_cast<PresShell*>(aPO->mPresShell.get());
+  RefPtr<PresShell> presShell = aPO->mPresShell;
   presShell->FlushPendingNotifications(FlushType::Layout);
 
   rv = UpdateSelectionAndShrinkPrintObject(aPO.get(), documentIsTopLevel);
   NS_ENSURE_SUCCESS(rv, rv);
 
 #ifdef EXTENDED_DEBUG_PRINTING
   if (MOZ_LOG_TEST(gPrintingLog, DUMP_LAYOUT_LEVEL)) {
     nsAutoCString docStr;
@@ -2507,17 +2506,17 @@ static nsresult DeleteUnselectedNodes(Do
 
 //-------------------------------------------------------
 nsresult nsPrintJob::DoPrint(const UniquePtr<nsPrintObject>& aPO) {
   PR_PL(("\n"));
   PR_PL(("**************************** %s ****************************\n",
          gFrameTypesStr[aPO->mFrameType]));
   PR_PL(("****** In DV::DoPrint   PO: %p \n", aPO.get()));
 
-  nsIPresShell* poPresShell = aPO->mPresShell;
+  PresShell* poPresShell = aPO->mPresShell;
   nsPresContext* poPresContext = aPO->mPresContext;
 
   NS_ASSERTION(poPresContext, "PrintObject has not been reflowed");
   NS_ASSERTION(poPresContext->Type() != nsPresContext::eContext_PrintPreview,
                "How did this context end up here?");
 
   // Guarantee that mPrt and the objects it owns won't be deleted in this method
   // because it might be cleared if other modules called from here may fire
@@ -3482,19 +3481,18 @@ int RemoveFilesInDir(const char* aDir) {
 
 /** ---------------------------------------------------
  *  Dumps Frames for Printing
  */
 static void RootFrameList(nsPresContext* aPresContext, FILE* out,
                           const char* aPrefix) {
   if (!aPresContext || !out) return;
 
-  nsIPresShell* shell = aPresContext->GetPresShell();
-  if (shell) {
-    nsIFrame* frame = shell->GetRootFrame();
+  if (PresShell* presShell = aPresContext->GetPresShell()) {
+    nsIFrame* frame = presShell->GetRootFrame();
     if (frame) {
       frame->List(out, aPrefix);
     }
   }
 }
 
 /** ---------------------------------------------------
  *  Dumps Frames for Printing
@@ -3532,19 +3530,18 @@ static void DumpFrames(FILE* out, nsPres
  *  Dumps the Views from the DocShell
  */
 static void DumpViews(nsIDocShell* aDocShell, FILE* out) {
   NS_ASSERTION(aDocShell, "Pointer is null!");
   NS_ASSERTION(out, "Pointer is null!");
 
   if (nullptr != aDocShell) {
     fprintf(out, "docshell=%p \n", aDocShell);
-    nsIPresShell* shell = aDocShell->GetPresShell();
-    if (shell) {
-      nsViewManager* vm = shell->GetViewManager();
+    if (PresShell* presShell = aDocShell->GetPresShell()) {
+      nsViewManager* vm = presShell->GetViewManager();
       if (vm) {
         nsView* root = vm->GetRootView();
         if (root) {
           root->List(out);
         }
       }
     } else {
       fputs("null pres shell\n", out);
--- a/layout/printing/nsPrintJob.h
+++ b/layout/printing/nsPrintJob.h
@@ -27,16 +27,17 @@
 class nsPagePrintTimer;
 class nsIDocShell;
 class nsIDocumentViewerPrint;
 class nsPrintObject;
 class nsIDocShell;
 class nsIPageSequenceFrame;
 
 namespace mozilla {
+class PresShell;
 namespace dom {
 class Document;
 }
 }  // namespace mozilla
 
 /**
  * A print job may be instantiated either for printing to an actual physical
  * printer, or for creating a print preview.
@@ -156,17 +157,17 @@ class nsPrintJob final : public nsIObser
 
   void GetDisplayTitleAndURL(const mozilla::UniquePtr<nsPrintObject>& aPO,
                              nsAString& aTitle, nsAString& aURLStr,
                              eDocTitleDefault aDefType);
 
   bool CheckBeforeDestroy();
   nsresult Cancelled();
 
-  nsIPresShell* GetPrintPreviewPresShell() {
+  mozilla::PresShell* GetPrintPreviewPresShell() {
     return mPrtPreview->mPrintObject->mPresShell;
   }
 
   float GetPrintPreviewScale() {
     return mPrtPreview->mPrintObject->mPresContext->GetPrintPreviewScale();
   }
 
   // These calls also update the DocViewer
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -10,20 +10,21 @@
 #include "nsContentUtils.h"  // for nsAutoScriptBlocker
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsPresContext.h"
 #include "nsGkAtoms.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIBaseWindow.h"
-#include "mozilla/dom/Document.h"
 #include "nsDocShell.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/BrowsingContext.h"
+#include "mozilla/dom/Document.h"
 #include "mozilla/dom/Element.h"
 
 using mozilla::dom::BrowsingContext;
 using mozilla::dom::Element;
 
 //---------------------------------------------------
 //-- nsPrintObject Class Impl
 //---------------------------------------------------
@@ -111,15 +112,15 @@ nsresult nsPrintObject::Init(nsIDocShell
 }
 
 //------------------------------------------------------------------
 // Resets PO by destroying the presentation
 void nsPrintObject::DestroyPresentation() {
   if (mPresShell) {
     mPresShell->EndObservingDocument();
     nsAutoScriptBlocker scriptBlocker;
-    nsCOMPtr<nsIPresShell> shell = mPresShell;
+    RefPtr<PresShell> presShell = mPresShell;
     mPresShell = nullptr;
-    shell->Destroy();
+    presShell->Destroy();
   }
   mPresContext = nullptr;
   mViewManager = nullptr;
 }
--- a/layout/printing/nsPrintObject.h
+++ b/layout/printing/nsPrintObject.h
@@ -11,19 +11,22 @@
 
 // Interfaces
 #include "nsCOMPtr.h"
 #include "nsViewManager.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
 
 class nsIContent;
-class nsIPresShell;
 class nsPresContext;
 
+namespace mozilla {
+class PresShell;
+}  // namespace mozilla
+
 // nsPrintObject Document Type
 enum PrintObjectType { eDoc = 0, eFrame = 1, eIFrame = 2, eFrameSet = 3 };
 
 //---------------------------------------------------
 //-- nsPrintObject Class
 //---------------------------------------------------
 class nsPrintObject {
  public:
@@ -38,17 +41,17 @@ class nsPrintObject {
   void DestroyPresentation();
 
   // Data Members
   nsCOMPtr<nsIDocShell> mDocShell;
   nsCOMPtr<nsIDocShellTreeOwner> mTreeOwner;
   RefPtr<mozilla::dom::Document> mDocument;
 
   RefPtr<nsPresContext> mPresContext;
-  nsCOMPtr<nsIPresShell> mPresShell;
+  RefPtr<mozilla::PresShell> mPresShell;
   RefPtr<nsViewManager> mViewManager;
 
   nsCOMPtr<nsIContent> mContent;
   PrintObjectType mFrameType;
 
   nsTArray<mozilla::UniquePtr<nsPrintObject>> mKids;
   nsPrintObject* mParent;  // This is a non-owning pointer.
   bool mHasBeenPrinted;
--- a/layout/style/ComputedStyle.h
+++ b/layout/style/ComputedStyle.h
@@ -20,17 +20,16 @@
 #include "mozilla/ServoUtils.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSPseudoElements.h"
 #include "nsColor.h"
 
 #include "nsStyleStructFwd.h"
 
 enum nsChangeHint : uint32_t;
-class nsIPresShell;
 class nsPresContext;
 class nsWindowSizes;
 
 #define STYLE_STRUCT(name_) struct nsStyle##name_;
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 
 extern "C" {
--- a/layout/style/CounterStyleManager.cpp
+++ b/layout/style/CounterStyleManager.cpp
@@ -883,19 +883,20 @@ class DependentBuiltinCounterStyle final
   virtual CounterStyle* GetFallback() override;
 
   void* operator new(size_t sz, nsPresContext* aPresContext) {
     return aPresContext->PresShell()->AllocateByObjectID(
         eArenaObjectID_DependentBuiltinCounterStyle, sz);
   }
 
   void Destroy() {
-    nsIPresShell* shell = mManager->PresContext()->PresShell();
+    PresShell* presShell = mManager->PresContext()->PresShell();
     this->~DependentBuiltinCounterStyle();
-    shell->FreeByObjectID(eArenaObjectID_DependentBuiltinCounterStyle, this);
+    presShell->FreeByObjectID(eArenaObjectID_DependentBuiltinCounterStyle,
+                              this);
   }
 
  private:
   ~DependentBuiltinCounterStyle() {}
 
   CounterStyleManager* mManager;
 };
 
@@ -978,19 +979,19 @@ class CustomCounterStyle final : public 
   bool IsExtendsSystem() { return mSystem == NS_STYLE_COUNTER_SYSTEM_EXTENDS; }
 
   void* operator new(size_t sz, nsPresContext* aPresContext) {
     return aPresContext->PresShell()->AllocateByObjectID(
         eArenaObjectID_CustomCounterStyle, sz);
   }
 
   void Destroy() {
-    nsIPresShell* shell = mManager->PresContext()->PresShell();
+    PresShell* presShell = mManager->PresContext()->PresShell();
     this->~CustomCounterStyle();
-    shell->FreeByObjectID(eArenaObjectID_CustomCounterStyle, this);
+    presShell->FreeByObjectID(eArenaObjectID_CustomCounterStyle, this);
   }
 
  private:
   ~CustomCounterStyle() {}
 
   nsCSSValue GetDesc(nsCSSCounterDesc aDesc) const {
     nsCSSValue value;
     Servo_CounterStyleRule_GetDescriptor(mRule, aDesc, &value);
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -494,26 +494,27 @@ static inline PseudoStyleType GetPseudoT
   if (!aPseudo) {
     return PseudoStyleType::NotPseudo;
   }
   return nsCSSPseudoElements::GetPseudoType(aPseudo,
                                             CSSEnabledState::eForAllContent);
 }
 
 already_AddRefed<ComputedStyle> nsComputedDOMStyle::DoGetComputedStyleNoFlush(
-    Element* aElement, nsAtom* aPseudo, nsIPresShell* aPresShell,
+    Element* aElement, nsAtom* aPseudo, PresShell* aPresShell,
     StyleType aStyleType) {
   MOZ_ASSERT(aElement, "NULL element");
 
   // If the content has a pres shell, we must use it.  Otherwise we'd
   // potentially mix rule trees by using the wrong pres shell's style
   // set.  Using the pres shell from the content also means that any
   // content that's actually *in* a document will get the style from the
   // correct document.
-  nsIPresShell* presShell = nsContentUtils::GetPresShellForContent(aElement);
+  PresShell* presShell =
+      static_cast<PresShell*>(nsContentUtils::GetPresShellForContent(aElement));
   bool inDocWithShell = true;
   if (!presShell) {
     inDocWithShell = false;
     presShell = aPresShell;
     if (!presShell) {
       return nullptr;
     }
   }
@@ -817,17 +818,17 @@ void nsComputedDOMStyle::UpdateCurrentSt
     document->FlushPendingNotifications(aNeedsLayoutFlush ? FlushType::Layout
                                                           : FlushType::Style);
   }
 
 #ifdef DEBUG
   mFlushedPendingReflows = aNeedsLayoutFlush;
 #endif
 
-  nsCOMPtr<nsIPresShell> presShellForContent =
+  RefPtr<PresShell> presShellForContent =
       nsContentUtils::GetPresShellForContent(mElement);
   if (presShellForContent && presShellForContent->GetDocument() != document) {
     presShellForContent->GetDocument()->FlushPendingNotifications(
         FlushType::Style);
     if (presShellForContent->IsDestroying()) {
       presShellForContent = nullptr;
     }
   }
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -25,23 +25,23 @@
 #include "nsStyleStruct.h"
 #include "mozilla/WritingModes.h"
 
 namespace mozilla {
 namespace dom {
 class DocGroup;
 class Element;
 }  // namespace dom
+class PresShell;
 struct ComputedGridTrackInfo;
 }  // namespace mozilla
 
 struct ComputedStyleMap;
 struct nsCSSKTableEntry;
 class nsIFrame;
-class nsIPresShell;
 class nsDOMCSSValueList;
 struct nsMargin;
 class nsROCSSPrimitiveValue;
 class nsStyleCoord;
 struct nsStyleFilter;
 class nsStyleGradient;
 struct nsStyleImage;
 class nsStyleSides;
@@ -148,17 +148,17 @@ class nsComputedDOMStyle final : public 
 
   // Helper functions called by UpdateCurrentStyleSources.
   void ClearComputedStyle();
   void SetResolvedComputedStyle(RefPtr<ComputedStyle>&& aContext,
                                 uint64_t aGeneration);
   void SetFrameComputedStyle(ComputedStyle* aStyle, uint64_t aGeneration);
 
   static already_AddRefed<ComputedStyle> DoGetComputedStyleNoFlush(
-      Element* aElement, nsAtom* aPseudo, nsIPresShell* aPresShell,
+      Element* aElement, nsAtom* aPseudo, mozilla::PresShell* aPresShell,
       StyleType aStyleType);
 
 #define STYLE_STRUCT(name_)                \
   const nsStyle##name_* Style##name_() {   \
     return mComputedStyle->Style##name_(); \
   }
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
@@ -428,17 +428,17 @@ class nsComputedDOMStyle final : public 
    * which we should use to compute margin, border, padding and content data.
    * Null otherwise.
    */
   nsIFrame* mInnerFrame;
   /*
    * While computing style data, the presshell we're working with.  Null
    * otherwise.
    */
-  nsIPresShell* mPresShell;
+  mozilla::PresShell* mPresShell;
 
   /*
    * The kind of styles we should be returning.
    */
   StyleType mStyleType;
 
   /**
    * The nsComputedDOMStyle generation at the time we last resolved a style
--- a/layout/style/nsFontFaceUtils.cpp
+++ b/layout/style/nsFontFaceUtils.cpp
@@ -79,17 +79,17 @@ static FontUsageKind FrameFontUsage(nsIF
       break;
     }
   }
 
   return kind;
 }
 
 // TODO(emilio): Can we use the restyle-hint machinery instead of this?
-static void ScheduleReflow(nsIPresShell* aShell, nsIFrame* aFrame) {
+static void ScheduleReflow(PresShell* aPresShell, nsIFrame* aFrame) {
   nsIFrame* f = aFrame;
   if (f->IsFrameOfType(nsIFrame::eSVG) || nsSVGUtils::IsInSVGTextSubtree(f)) {
     // SVG frames (and the non-SVG descendants of an SVGTextFrame) need special
     // reflow handling.  We need to search upwards for the first displayed
     // nsSVGOuterSVGFrame or non-SVG frame, which is the frame we can call
     // FrameNeedsReflow on.  (This logic is based on
     // nsSVGUtils::ScheduleReflowSVG and
     // SVGTextFrame::ScheduleReflowSVGNonDisplayText.)
@@ -109,17 +109,18 @@ static void ScheduleReflow(nsIPresShell*
           f->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
         }
         f = f->GetParent();
       }
       MOZ_ASSERT(f, "should have found an ancestor frame to reflow");
     }
   }
 
-  aShell->FrameNeedsReflow(f, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
+  aPresShell->FrameNeedsReflow(f, nsIPresShell::eStyleChange,
+                               NS_FRAME_IS_DIRTY);
 }
 
 enum class ReflowAlreadyScheduled {
   No,
   Yes,
 };
 
 /* static */
--- a/layout/svg/SVGObserverUtils.cpp
+++ b/layout/svg/SVGObserverUtils.cpp
@@ -88,17 +88,17 @@ struct nsSVGFrameReferenceFromProperty {
       Detach();  // mFrame is no longer valid.
     }
     return mFrame;
   }
 
  private:
   // The frame that our property is attached to (may be null).
   nsIFrame* mFrame;
-  nsIPresShell* mFramePresShell;
+  mozilla::PresShell* mFramePresShell;
 };
 
 void SVGRenderingObserver::StartObserving() {
   Element* target = GetReferencedElementWithoutObserving();
   if (target) {
     target->AddMutationObserver(this);
   }
 }
--- a/layout/xul/nsBoxLayoutState.h
+++ b/layout/xul/nsBoxLayoutState.h
@@ -9,38 +9,38 @@
   Author:
   Eric D Vaughan
 
 **/
 
 #ifndef nsBoxLayoutState_h___
 #define nsBoxLayoutState_h___
 
-#include "mozilla/PresShell.h"
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
 
 class gfxContext;
 namespace mozilla {
+class PresShell;
 struct ReflowInput;
 }  // namespace mozilla
 
 class MOZ_STACK_CLASS nsBoxLayoutState {
   using ReflowInput = mozilla::ReflowInput;
 
  public:
   explicit nsBoxLayoutState(nsPresContext* aPresContext,
                             gfxContext* aRenderingContext = nullptr,
                             // see OuterReflowInput() below
                             const ReflowInput* aOuterReflowInput = nullptr,
                             uint16_t aReflowDepth = 0);
   nsBoxLayoutState(const nsBoxLayoutState& aState);
 
   nsPresContext* PresContext() const { return mPresContext; }
-  nsIPresShell* PresShell() const { return mPresContext->PresShell(); }
+  mozilla::PresShell* PresShell() const { return mPresContext->PresShell(); }
 
   uint32_t LayoutFlags() const { return mLayoutFlags; }
   void SetLayoutFlags(uint32_t aFlags) { mLayoutFlags = aFlags; }
 
   // if true no one under us will paint during reflow.
   void SetPaintingDisabled(bool aDisable) { mPaintingDisabled = aDisable; }
   bool PaintingDisabled() const { return mPaintingDisabled; }
 
--- a/layout/xul/nsGroupBoxFrame.cpp
+++ b/layout/xul/nsGroupBoxFrame.cpp
@@ -66,18 +66,18 @@ class nsGroupBoxFrame final : public nsB
 
   nsIFrame* GetCaptionBox(nsRect& aCaptionRect);
 };
 
 /*
 class nsGroupBoxInnerFrame : public nsBoxFrame {
 public:
 
-    nsGroupBoxInnerFrame(nsIPresShell* aShell, ComputedStyle* aStyle):
-      nsBoxFrame(aShell, aContext) {}
+    nsGroupBoxInnerFrame(PresShell* aPresShell, ComputedStyle* aStyle):
+      nsBoxFrame(aPresShell, aContext) {}
 
 
 #ifdef DEBUG_FRAME_DUMP
   NS_IMETHOD GetFrameName(nsString& aResult) const override {
     return MakeFrameName("GroupBoxFrameInner", aResult);
   }
 #endif
 
--- a/layout/xul/nsIPopupContainer.h
+++ b/layout/xul/nsIPopupContainer.h
@@ -4,31 +4,31 @@
  * 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/. */
 
 #ifndef nsIPopupContainer_h___
 #define nsIPopupContainer_h___
 
 #include "nsQueryFrame.h"
 class nsPopupSetFrame;
-class nsIPresShell;
 class nsIContent;
 
 namespace mozilla {
+class PresShell;
 namespace dom {
 class Element;
 }
 }  // namespace mozilla
 
 class nsIPopupContainer {
  public:
   NS_DECL_QUERYFRAME_TARGET(nsIPopupContainer)
 
   virtual nsPopupSetFrame* GetPopupSetFrame() = 0;
   virtual void SetPopupSetFrame(nsPopupSetFrame* aPopupSet) = 0;
 
   virtual mozilla::dom::Element* GetDefaultTooltip() = 0;
   virtual void SetDefaultTooltip(mozilla::dom::Element* aTooltip) = 0;
 
-  static nsIPopupContainer* GetPopupContainer(nsIPresShell* aShell);
+  static nsIPopupContainer* GetPopupContainer(mozilla::PresShell* aShell);
 };
 
 #endif
--- a/layout/xul/nsResizerFrame.cpp
+++ b/layout/xul/nsResizerFrame.cpp
@@ -315,17 +315,17 @@ nsresult nsResizerFrame::HandleEvent(nsP
   if (!doDefault) *aEventStatus = nsEventStatus_eConsumeNoDefault;
 
   if (doDefault && weakFrame.IsAlive())
     return nsTitleBarFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
 
   return NS_OK;
 }
 
-nsIContent* nsResizerFrame::GetContentToResize(nsIPresShell* aPresShell,
+nsIContent* nsResizerFrame::GetContentToResize(mozilla::PresShell* aPresShell,
                                                nsIBaseWindow** aWindow) {
   *aWindow = nullptr;
 
   nsAutoString elementid;
   mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::element,
                                  elementid);
   if (elementid.IsEmpty()) {
     // If the resizer is in a popup, resize the popup's widget, otherwise
--- a/layout/xul/nsResizerFrame.h
+++ b/layout/xul/nsResizerFrame.h
@@ -36,17 +36,17 @@ class nsResizerFrame final : public nsTi
 
   virtual nsresult HandleEvent(nsPresContext* aPresContext,
                                mozilla::WidgetGUIEvent* aEvent,
                                nsEventStatus* aEventStatus) override;
 
   virtual void MouseClicked(mozilla::WidgetMouseEvent* aEvent) override;
 
  protected:
-  nsIContent* GetContentToResize(nsIPresShell* aPresShell,
+  nsIContent* GetContentToResize(mozilla::PresShell* aPresShell,
                                  nsIBaseWindow** aWindow);
 
   Direction GetDirection();
 
   /**
    * Adjust the window position and size in a direction according to the mouse
    * movement and the resizer direction. The minimum and maximum size is used
    * to constrain the size.
--- a/layout/xul/nsRootBoxFrame.cpp
+++ b/layout/xul/nsRootBoxFrame.cpp
@@ -2,38 +2,37 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "nsHTMLParts.h"
 #include "nsStyleConsts.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsBoxFrame.h"
 #include "nsDisplayList.h"
 #include "nsStackLayout.h"
 #include "nsIPopupContainer.h"
 #include "nsIContent.h"
 #include "nsFrameManager.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/PresShell.h"
 
 using namespace mozilla;
 
 // Interface IDs
 
 //#define DEBUG_REFLOW
 
 // static
-nsIPopupContainer* nsIPopupContainer::GetPopupContainer(nsIPresShell* aShell) {
-  if (!aShell) {
+nsIPopupContainer* nsIPopupContainer::GetPopupContainer(PresShell* aPresShell) {
+  if (!aPresShell) {
     return nullptr;
   }
-  nsIFrame* rootFrame = aShell->GetRootFrame();
+  nsIFrame* rootFrame = aPresShell->GetRootFrame();
   if (!rootFrame) {
     return nullptr;
   }
 
   if (rootFrame) {
     rootFrame = rootFrame->PrincipalChildList().FirstChild();
   }
 
--- a/layout/xul/nsSliderFrame.cpp
+++ b/layout/xul/nsSliderFrame.cpp
@@ -888,17 +888,17 @@ nsresult nsSliderMediator::HandleEvent(d
   // Only process the event if the thumb is not being dragged.
   if (mSlider && !mSlider->isDraggingThumb()) return mSlider->StartDrag(aEvent);
 
   return NS_OK;
 }
 
 class AsyncScrollbarDragStarter final : public nsAPostRefreshObserver {
  public:
-  AsyncScrollbarDragStarter(nsIPresShell* aPresShell, nsIWidget* aWidget,
+  AsyncScrollbarDragStarter(mozilla::PresShell* aPresShell, nsIWidget* aWidget,
                             const AsyncDragMetrics& aDragMetrics)
       : mPresShell(aPresShell), mWidget(aWidget), mDragMetrics(aDragMetrics) {}
   virtual ~AsyncScrollbarDragStarter() {}
 
   void DidRefresh() override {
     if (!mPresShell) {
       MOZ_ASSERT_UNREACHABLE(
           "Post-refresh observer fired again after failed attempt at "
@@ -917,17 +917,17 @@ class AsyncScrollbarDragStarter final : 
       mWidget = nullptr;
       return;
     }
 
     delete this;
   }
 
  private:
-  RefPtr<nsIPresShell> mPresShell;
+  RefPtr<mozilla::PresShell> mPresShell;
   RefPtr<nsIWidget> mWidget;
   AsyncDragMetrics mDragMetrics;
 };
 
 static bool UsesSVGEffects(nsIFrame* aFrame) {
   return aFrame->StyleEffects()->HasFilters() ||
          nsSVGIntegrationUtils::UsingMaskOrClipPathForFrame(aFrame);
 }
--- a/layout/xul/nsStackFrame.cpp
+++ b/layout/xul/nsStackFrame.cpp
@@ -13,17 +13,16 @@
 
 #include "nsStackFrame.h"
 
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/PresShell.h"
 #include "nsIContent.h"
 #include "nsCOMPtr.h"
 #include "nsHTMLParts.h"
-#include "nsIPresShell.h"
 #include "nsCSSRendering.h"
 #include "nsBoxLayoutState.h"
 #include "nsStackLayout.h"
 #include "nsDisplayList.h"
 
 using namespace mozilla;
 
 nsIFrame* NS_NewStackFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
--- a/layout/xul/nsStackLayout.h
+++ b/layout/xul/nsStackLayout.h
@@ -15,18 +15,16 @@ one time. So the can be flipped though l
 #ifndef nsStackLayout_h___
 #define nsStackLayout_h___
 
 #include "mozilla/Attributes.h"
 #include "nsBoxLayout.h"
 #include "nsCOMPtr.h"
 #include "nsCoord.h"
 
-class nsIPresShell;
-
 nsresult NS_NewStackLayout(nsCOMPtr<nsBoxLayout>& aNewLayout);
 
 class nsStackLayout : public nsBoxLayout {
  public:
   friend nsresult NS_NewStackLayout(nsCOMPtr<nsBoxLayout>& aNewLayout);
   static void Shutdown();
 
   nsStackLayout();
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -444,17 +444,17 @@ void nsXULPopupManager::AdjustPopupsOnWi
     item = item->GetParent();
   }
 
   for (int32_t l = list.Length() - 1; l >= 0; l--) {
     list[l]->SetPopupPosition(nullptr, true, false, true);
   }
 }
 
-void nsXULPopupManager::AdjustPopupsOnWindowChange(nsIPresShell* aPresShell) {
+void nsXULPopupManager::AdjustPopupsOnWindowChange(PresShell* aPresShell) {
   if (aPresShell->GetDocument()) {
     AdjustPopupsOnWindowChange(aPresShell->GetDocument()->GetWindow());
   }
 }
 
 static nsMenuPopupFrame* GetPopupToMoveOrResize(nsIFrame* aFrame) {
   nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(aFrame);
   if (!menuPopupFrame) return nullptr;
@@ -2625,17 +2625,17 @@ nsXULPopupPositionedEvent::Run() {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULMenuCommandEvent::Run() {
   nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
   if (!pm) return NS_OK;
 
-  // The order of the nsViewManager and nsIPresShell COM pointers is
+  // The order of the nsViewManager and PresShell COM pointers is
   // important below.  We want the pres shell to get released before the
   // associated view manager on exit from this function.
   // See bug 54233.
   // XXXndeakin is this still needed?
 
   nsCOMPtr<nsIContent> popup;
   nsMenuFrame* menuFrame = do_QueryFrame(mMenu->GetPrimaryFrame());
   AutoWeakFrame weakFrame(menuFrame);
--- a/layout/xul/nsXULPopupManager.h
+++ b/layout/xul/nsXULPopupManager.h
@@ -53,16 +53,17 @@ class nsMenuFrame;
 class nsMenuPopupFrame;
 class nsMenuBarFrame;
 class nsMenuParent;
 class nsIDocShellTreeItem;
 class nsPIDOMWindowOuter;
 class nsRefreshDriver;
 
 namespace mozilla {
+class PresShell;
 namespace dom {
 class Event;
 class KeyboardEvent;
 }  // namespace dom
 }  // namespace mozilla
 
 // when a menu command is executed, the closemenu attribute may be used
 // to define how the menu should be closed up
@@ -357,17 +358,17 @@ class nsXULPopupManager final : public n
   //
   // FIXME(emilio): Or something like that, because this is kind of broken in a
   // variety of situations like multiple insertion points.
   static nsContainerFrame* ImmediateParentFrame(nsContainerFrame* aFrame);
 
   // This should be called when a window is moved or resized to adjust the
   // popups accordingly.
   void AdjustPopupsOnWindowChange(nsPIDOMWindowOuter* aWindow);
-  void AdjustPopupsOnWindowChange(nsIPresShell* aPresShell);
+  void AdjustPopupsOnWindowChange(mozilla::PresShell* aPresShell);
 
   // given a menu frame, find the prevous or next menu frame. If aPopup is
   // true then navigate a menupopup, from one item on the menu to the previous
   // or next one. This is used for cursor navigation between items in a popup
   // menu. If aIsPopup is false, the navigation is on a menubar, so navigate
   // between menus on the menubar. This is used for left/right cursor
   // navigation.
   //