Bug 1540930 - Make nsPresContext use mozilla::PresShell directly rather than via nsIPresShell r=emilio
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 03 Apr 2019 12:40:26 +0000
changeset 467756 ca4ff21cf3541314675bd0d66690ef9a9e989abe
parent 467755 d33dcf17faaa6458f0a834297ab5ed51d1f3ebcb
child 467757 feb07dd48b7045fd14514f76339eaf04d9e7f79d
push id35810
push useraciure@mozilla.com
push dateThu, 04 Apr 2019 04:33:36 +0000
treeherdermozilla-central@b72c02e34261 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1540930
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 1540930 - Make nsPresContext use mozilla::PresShell directly rather than via nsIPresShell r=emilio `nsPresContext` should use `mozilla::PresShell` directly instead of `nsIPresShell`. This patch makes it. Unfortunately, `nsPresContext` and `nsIFrame` have `PresShell()`. Therefore, we cannot use `PresShell*` in its methods so that this patch uses `mozilla::` namespace prefix. It might be better to rename them as `PresShellPtr()` in another bug. Differential Revision: https://phabricator.services.mozilla.com/D25721
accessible/generic/Accessible.cpp
accessible/generic/HyperTextAccessible.cpp
accessible/xul/XULTreeAccessible.cpp
accessible/xul/XULTreeGridAccessible.cpp
docshell/base/nsDocShellTreeOwner.cpp
dom/animation/EffectCompositor.cpp
dom/base/Element.cpp
dom/base/Selection.cpp
dom/base/nsFrameLoader.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsImageLoadingContent.cpp
dom/canvas/CanvasRenderingContext2D.cpp
dom/events/Event.cpp
dom/events/EventStateManager.cpp
dom/events/IMEContentObserver.cpp
dom/events/TextComposition.cpp
dom/events/UIEvent.cpp
dom/html/HTMLButtonElement.cpp
dom/html/HTMLInputElement.cpp
dom/html/HTMLMediaElement.cpp
dom/html/nsGenericHTMLFrameElement.cpp
dom/html/nsTextEditorState.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
gfx/ipc/CrossProcessPaint.cpp
layout/base/PositionedEventTargeting.cpp
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/RestyleManager.cpp
layout/base/nsBidiPresUtils.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
layout/base/nsRefreshDriver.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsBulletFrame.cpp
layout/generic/nsCanvasFrame.cpp
layout/generic/nsContainerFrame.cpp
layout/generic/nsFirstLetterFrame.cpp
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsFrameList.cpp
layout/generic/nsFrameSetFrame.cpp
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsIFrame.h
layout/generic/nsImageFrame.cpp
layout/generic/nsLineBox.cpp
layout/generic/nsPageContentFrame.cpp
layout/generic/nsPageFrame.cpp
layout/generic/nsPluginFrame.cpp
layout/generic/nsSimplePageSequenceFrame.cpp
layout/generic/nsSubDocumentFrame.cpp
layout/generic/nsTextFrame.cpp
layout/mathml/nsMathMLmtableFrame.cpp
layout/painting/FrameLayerBuilder.cpp
layout/painting/nsCSSRendering.cpp
layout/painting/nsDisplayList.cpp
layout/style/CounterStyleManager.cpp
layout/style/nsFontFaceUtils.cpp
layout/svg/SVGTextFrame.cpp
layout/svg/nsSVGForeignObjectFrame.cpp
layout/tables/nsCellMap.cpp
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableFrame.cpp
layout/tables/nsTableRowGroupFrame.cpp
layout/xul/nsBoxLayoutState.h
layout/xul/nsButtonBoxFrame.cpp
layout/xul/nsDeckFrame.cpp
layout/xul/nsMenuPopupFrame.cpp
layout/xul/nsPopupSetFrame.cpp
layout/xul/nsResizerFrame.cpp
layout/xul/nsSplitterFrame.cpp
layout/xul/nsTitleBarFrame.cpp
layout/xul/nsXULPopupManager.cpp
layout/xul/tree/nsTreeBodyFrame.cpp
toolkit/components/sessionstore/SessionStoreUtils.cpp
widget/android/fennec/ThumbnailHelper.h
widget/nsNativeTheme.cpp
--- a/accessible/generic/Accessible.cpp
+++ b/accessible/generic/Accessible.cpp
@@ -39,17 +39,16 @@
 
 #include "mozilla/dom/Document.h"
 #include "nsIContent.h"
 #include "nsIForm.h"
 #include "nsIFormControl.h"
 
 #include "nsDeckFrame.h"
 #include "nsLayoutUtils.h"
-#include "nsIPresShell.h"
 #include "nsIStringBundle.h"
 #include "nsPresContext.h"
 #include "nsIFrame.h"
 #include "nsView.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIScrollableFrame.h"
 #include "nsFocusManager.h"
 
@@ -69,16 +68,17 @@
 
 #include "mozilla/Assertions.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Unused.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/CanvasRenderingContext2D.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
 #include "mozilla/dom/HTMLBodyElement.h"
 #include "mozilla/dom/KeyboardEventBinding.h"
 #include "mozilla/dom/TreeWalker.h"
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -32,16 +32,17 @@
 #include "nsIMathMLFrame.h"
 #include "nsRange.h"
 #include "nsTextFragment.h"
 #include "mozilla/BinarySearch.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/MathAlgorithms.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEditor.h"
 #include "gfxSkipChars.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/accessible/xul/XULTreeAccessible.cpp
+++ b/accessible/xul/XULTreeAccessible.cpp
@@ -25,16 +25,17 @@
 #include "nsIAutoCompletePopup.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsIDOMXULMultSelectCntrlEl.h"
 #include "nsITreeSelection.h"
 #include "nsIMutableArray.h"
 #include "nsTreeBodyFrame.h"
 #include "nsTreeColumns.h"
 #include "nsTreeUtils.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/XULTreeElementBinding.h"
 
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULTreeAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -155,17 +156,17 @@ role XULTreeAccessible::NativeRole() con
 // XULTreeAccessible: Accessible implementation (DON'T put methods here)
 
 Accessible* XULTreeAccessible::ChildAtPoint(int32_t aX, int32_t aY,
                                             EWhichChildAtPoint aWhichChild) {
   nsIFrame* frame = GetFrame();
   if (!frame) return nullptr;
 
   nsPresContext* presContext = frame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
 
   nsIFrame* rootFrame = presShell->GetRootFrame();
   NS_ENSURE_TRUE(rootFrame, nullptr);
 
   CSSIntRect rootRect = rootFrame->GetScreenRect();
 
   int32_t clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.X();
   int32_t clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.Y();
--- a/accessible/xul/XULTreeGridAccessible.cpp
+++ b/accessible/xul/XULTreeGridAccessible.cpp
@@ -15,16 +15,17 @@
 #include "States.h"
 #include "nsQueryObject.h"
 #include "nsTreeColumns.h"
 
 #include "nsIMutableArray.h"
 #include "nsPersistentProperties.h"
 #include "nsITreeSelection.h"
 #include "nsComponentManagerUtils.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/TreeColumnBinding.h"
 #include "mozilla/dom/XULTreeElementBinding.h"
 
 using namespace mozilla::a11y;
 using namespace mozilla;
 
 XULTreeGridAccessible::~XULTreeGridAccessible() {}
@@ -252,17 +253,17 @@ ENameValueFlag XULTreeGridRowAccessible:
 }
 
 Accessible* XULTreeGridRowAccessible::ChildAtPoint(
     int32_t aX, int32_t aY, EWhichChildAtPoint aWhichChild) {
   nsIFrame* frame = GetFrame();
   if (!frame) return nullptr;
 
   nsPresContext* presContext = frame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
 
   nsIFrame* rootFrame = presShell->GetRootFrame();
   NS_ENSURE_TRUE(rootFrame, nullptr);
 
   CSSIntRect rootRect = rootFrame->GetScreenRect();
 
   int32_t clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.X();
   int32_t clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.Y();
--- a/docshell/base/nsDocShellTreeOwner.cpp
+++ b/docshell/base/nsDocShellTreeOwner.cpp
@@ -28,40 +28,39 @@
 #include "nsINode.h"
 #include "Link.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/MouseEvent.h"
 #include "mozilla/dom/SVGTitleElement.h"
 #include "nsIFormControl.h"
 #include "nsIImageLoadingContent.h"
 #include "nsIWebNavigation.h"
-#include "nsIPresShell.h"
 #include "nsIStringBundle.h"
 #include "nsPIDOMWindow.h"
 #include "nsPIWindowRoot.h"
 #include "nsIWindowWatcher.h"
 #include "nsPIWindowWatcher.h"
 #include "nsIPrompt.h"
 #include "nsITabParent.h"
 #include "nsITabChild.h"
 #include "nsRect.h"
 #include "nsIWebBrowserChromeFocus.h"
 #include "nsIContent.h"
 #include "imgIContainer.h"
-#include "nsPresContext.h"
 #include "nsViewManager.h"
 #include "nsView.h"
 #include "nsIConstraintValidation.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/DragEvent.h"
 #include "mozilla/dom/Event.h"     // for Event
 #include "mozilla/dom/File.h"      // for input type=file
 #include "mozilla/dom/FileList.h"  // for input type=file
 #include "mozilla/dom/LoadURIOptionsBinding.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 // A helper routine that navigates the tricky path from a |nsWebBrowser| to
 // a |EventTarget| via the window root and chrome event handler.
 static nsresult GetDOMEventTarget(nsWebBrowser* aInBrowser,
@@ -389,17 +388,17 @@ nsDocShellTreeOwner::SizeShellTo(nsIDocS
   NS_ERROR("Implement this");
   /*
   Set the preferred size on the aShellItem.
   */
 
   RefPtr<nsPresContext> presContext = mWebBrowser->mDocShell->GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
-  nsIPresShell* presShell = presContext->GetPresShell();
+  PresShell* presShell = presContext->GetPresShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   NS_ENSURE_SUCCESS(
       presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
       NS_ERROR_FAILURE);
 
   // XXX: this is weird, but we used to call a method here
   // (webBrowserChrome->SizeBrowserTo()) whose implementations all failed like
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -15,28 +15,28 @@
 #include "mozilla/AnimationComparator.h"
 #include "mozilla/AnimationPerformanceWarning.h"
 #include "mozilla/AnimationTarget.h"
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/ComputedStyleInlines.h"
 #include "mozilla/EffectSet.h"
 #include "mozilla/LayerAnimationInfo.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/ServoBindings.h"  // Servo_GetProperties_Overriding_Animation
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/StyleAnimationValue.h"
 #include "mozilla/TypeTraits.h"  // For std::forward<>
 #include "nsContentUtils.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSPropertyIDSet.h"
 #include "nsCSSProps.h"
 #include "nsDisplayItemTypes.h"
 #include "nsAtom.h"
-#include "nsIPresShell.h"
 #include "nsIPresShellInlines.h"
 #include "nsLayoutUtils.h"
 #include "nsTArray.h"
 #include "PendingAnimationTracker.h"
 
 using mozilla::dom::Animation;
 using mozilla::dom::Element;
 using mozilla::dom::KeyframeEffect;
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -2153,26 +2153,26 @@ nsresult Element::DispatchEvent(nsPresCo
   MOZ_ASSERT(aTarget, "Must have target");
   MOZ_ASSERT(aEvent, "Must have source event");
   MOZ_ASSERT(aStatus, "Null out param?");
 
   if (!aPresContext) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
-  if (!shell) {
+  RefPtr<PresShell> presShell = aPresContext->GetPresShell();
+  if (!presShell) {
     return NS_OK;
   }
 
   if (aFullDispatch) {
-    return shell->HandleEventWithTarget(aEvent, nullptr, aTarget, aStatus);
-  }
-
-  return shell->HandleDOMEventWithTarget(aTarget, aEvent, aStatus);
+    return presShell->HandleEventWithTarget(aEvent, nullptr, aTarget, aStatus);
+  }
+
+  return presShell->HandleDOMEventWithTarget(aTarget, aEvent, aStatus);
 }
 
 /* static */
 nsresult Element::DispatchClickEvent(nsPresContext* aPresContext,
                                      WidgetInputEvent* aSourceEvent,
                                      nsIContent* aTarget, bool aFullDispatch,
                                      const EventFlags* aExtraEventFlags,
                                      nsEventStatus* aStatus) {
@@ -3115,26 +3115,26 @@ nsresult Element::PostHandleEventForLink
       WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
       if (mouseEvent->IsLeftClickEvent()) {
         if (mouseEvent->IsControl() || mouseEvent->IsMeta() ||
             mouseEvent->IsAlt() || mouseEvent->IsShift()) {
           break;
         }
 
         // The default action is simply to dispatch DOMActivate
-        nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
-        if (shell) {
+        if (RefPtr<PresShell> presShell =
+                aVisitor.mPresContext->GetPresShell()) {
           // single-click
           nsEventStatus status = nsEventStatus_eIgnore;
           // DOMActive event should be trusted since the activation is actually
           // occurred even if the cause is an untrusted click event.
           InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
           actEvent.mDetail = 1;
 
-          rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status);
+          rv = presShell->HandleDOMEventWithTarget(this, &actEvent, &status);
           if (NS_SUCCEEDED(rv)) {
             aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
           }
         }
       }
       break;
     }
     case eLegacyDOMActivate: {
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -1859,18 +1859,17 @@ nsresult Selection::StopAutoScrollTimer(
 nsresult Selection::DoAutoScroll(nsIFrame* aFrame, nsPoint aPoint) {
   MOZ_ASSERT(aFrame, "Need a frame");
 
   if (mAutoScrollTimer) {
     (void)mAutoScrollTimer->Stop();
   }
 
   nsPresContext* presContext = aFrame->PresContext();
-  RefPtr<PresShell> presShell =
-      static_cast<PresShell*>(presContext->PresShell());
+  RefPtr<PresShell> presShell = presContext->PresShell();
   nsRootPresContext* rootPC = presContext->GetRootPresContext();
   if (!rootPC) return NS_OK;
   nsIFrame* rootmostFrame = rootPC->PresShell()->GetRootFrame();
   AutoWeakFrame weakRootFrame(rootmostFrame);
   AutoWeakFrame weakFrame(aFrame);
   // Get the point relative to the root most frame because the scroll we are
   // about to do will change the coordinates of aFrame.
   nsPoint globalPoint = aPoint + aFrame->GetOffsetToCrossDoc(rootmostFrame);
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -73,16 +73,17 @@
 #include "ContentParent.h"
 #include "TabParent.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/HTMLEditor.h"
 #include "mozilla/NullPrincipal.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/ChromeMessageSender.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/FrameLoaderBinding.h"
 #include "mozilla/dom/MozFrameLoaderOwnerBinding.h"
 #include "mozilla/gfx/CrossProcessPaint.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "mozilla/layout/RenderFrame.h"
@@ -959,18 +960,18 @@ void nsFrameLoader::ForceLayoutIfNecessa
   nsPresContext* presContext = frame->PresContext();
   if (!presContext) {
     return;
   }
 
   // Only force the layout flush if the frameloader hasn't ever been
   // run through layout.
   if (frame->GetStateBits() & NS_FRAME_FIRST_REFLOW) {
-    if (nsCOMPtr<nsIPresShell> shell = presContext->GetPresShell()) {
-      shell->FlushPendingNotifications(FlushType::Layout);
+    if (RefPtr<PresShell> presShell = presContext->GetPresShell()) {
+      presShell->FlushPendingNotifications(FlushType::Layout);
     }
   }
 }
 
 nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
     nsFrameLoader* aOther, nsFrameLoaderOwner* aThisOwner,
     nsFrameLoaderOwner* aOtherOwner) {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -93,16 +93,17 @@
 #include "mozilla/dom/ToJSValue.h"
 #include "nsJSPrincipals.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Components.h"
 #include "mozilla/Debug.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/ProcessHangMonitor.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/ThrottledEventQueue.h"
 #include "AudioChannelService.h"
 #include "nsAboutProtocolUtils.h"
 #include "nsCharTraits.h"  // NS_IS_HIGH/LOW_SURROGATE
 #include "PostMessageEvent.h"
 #include "mozilla/dom/DocGroup.h"
@@ -118,17 +119,16 @@
 #include "nsIContent.h"
 #include "nsIDocShell.h"
 #include "mozilla/dom/Document.h"
 #include "Crypto.h"
 #include "nsDOMString.h"
 #include "nsIEmbeddingSiteWindow.h"
 #include "nsThreadUtils.h"
 #include "nsILoadContext.h"
-#include "nsIPresShell.h"
 #include "nsIScrollableFrame.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsISelectionController.h"
 #include "nsIPrompt.h"
 #include "nsIPromptService.h"
 #include "nsIPromptFactory.h"
 #include "nsIAddonPolicyService.h"
@@ -6288,27 +6288,28 @@ void nsGlobalWindowOuter::EnterModalStat
     return;
   }
 
   // If there is an active ESM in this window, clear it. Otherwise, this can
   // cause a problem if a modal state is entered during a mouseup event.
   EventStateManager* activeESM = static_cast<EventStateManager*>(
       EventStateManager::GetActiveEventStateManager());
   if (activeESM && activeESM->GetPresContext()) {
-    nsIPresShell* activeShell = activeESM->GetPresContext()->GetPresShell();
-    if (activeShell && (nsContentUtils::ContentIsCrossDocDescendantOf(
-                            activeShell->GetDocument(), mDoc) ||
-                        nsContentUtils::ContentIsCrossDocDescendantOf(
-                            mDoc, activeShell->GetDocument()))) {
+    PresShell* activePresShell = activeESM->GetPresContext()->GetPresShell();
+    if (activePresShell && (nsContentUtils::ContentIsCrossDocDescendantOf(
+                                activePresShell->GetDocument(), mDoc) ||
+                            nsContentUtils::ContentIsCrossDocDescendantOf(
+                                mDoc, activePresShell->GetDocument()))) {
       EventStateManager::ClearGlobalActiveContent(activeESM);
 
       nsIPresShell::SetCapturingContent(nullptr, 0);
 
-      if (activeShell) {
-        RefPtr<nsFrameSelection> frameSelection = activeShell->FrameSelection();
+      if (activePresShell) {
+        RefPtr<nsFrameSelection> frameSelection =
+            activePresShell->FrameSelection();
         frameSelection->SetDragState(false);
       }
     }
   }
 
   // If there are any drag and drop operations in flight, try to end them.
   nsCOMPtr<nsIDragService> ds =
       do_GetService("@mozilla.org/widget/dragservice;1");
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -24,18 +24,16 @@
 #include "imgIContainer.h"
 #include "imgLoader.h"
 #include "imgRequestProxy.h"
 #include "nsThreadUtils.h"
 #include "nsNetUtil.h"
 #include "nsImageFrame.h"
 #include "nsSVGImageFrame.h"
 
-#include "nsIPresShell.h"
-
 #include "nsIChannel.h"
 #include "nsIStreamListener.h"
 
 #include "nsIFrame.h"
 
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsIContentPolicy.h"
@@ -48,16 +46,17 @@
 #include "mozilla/AutoRestore.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ImageTracker.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/net/UrlClassifierFeatureFactory.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 
 #ifdef LoadImage
 // Undefine LoadImage to prevent naming conflict with Windows.
 #  undef LoadImage
 #endif
 
 using namespace mozilla;
 using namespace mozilla::dom;
@@ -313,17 +312,17 @@ void nsImageLoadingContent::OnUnlockedDr
     return;
   }
 
   nsPresContext* presContext = frame->PresContext();
   if (!presContext) {
     return;
   }
 
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->GetPresShell();
   if (!presShell) {
     return;
   }
 
   presShell->EnsureFrameInApproximatelyVisibleList(frame);
 }
 
 nsresult nsImageLoadingContent::OnImageIsAnimated(imgIRequest* aRequest) {
@@ -860,17 +859,17 @@ nsImageLoadingContent::FrameDestroyed(ns
   if (mPendingRequest) {
     nsLayoutUtils::DeregisterImageRequest(presContext, mPendingRequest,
                                           &mPendingRequestRegistered);
   }
 
   UntrackImage(mCurrentRequest);
   UntrackImage(mPendingRequest);
 
-  nsIPresShell* presShell = presContext ? presContext->GetPresShell() : nullptr;
+  PresShell* presShell = presContext ? presContext->GetPresShell() : nullptr;
   if (presShell) {
     presShell->RemoveFrameFromApproximatelyVisibleList(aFrame);
   }
 }
 
 /* static */
 nsContentPolicyType nsImageLoadingContent::PolicyTypeForLoad(
     ImageLoadType aImageLoadType) {
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -10,21 +10,21 @@
 
 #include "nsAutoPtr.h"
 #include "nsIServiceManager.h"
 #include "nsMathUtils.h"
 #include "SVGImageContext.h"
 
 #include "nsContentUtils.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
 #include "SVGObserverUtils.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 #include "nsIPresShellInlines.h"
 
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIFrame.h"
 #include "nsError.h"
 
 #include "nsCSSPseudoElements.h"
 #include "nsComputedDOMStyle.h"
@@ -4732,19 +4732,20 @@ void CanvasRenderingContext2D::DrawWindo
       return;
     }
 
     thebes = gfxContext::CreateOrNull(drawDT);
     MOZ_ASSERT(thebes);  // alrady checked the draw target above
     thebes->SetMatrix(Matrix::Scaling(matrix._11, matrix._22));
   }
 
-  nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
-
-  Unused << shell->RenderDocument(r, renderDocFlags, backgroundColor, thebes);
+  RefPtr<PresShell> presShell = presContext->PresShell();
+
+  Unused << presShell->RenderDocument(r, renderDocFlags, backgroundColor,
+                                      thebes);
   // If this canvas was contained in the drawn window, the pre-transaction
   // callback may have returned its DT. If so, we must reacquire it here.
   EnsureTarget(discardContent ? &drawRect : nullptr);
 
   if (drawDT) {
     RefPtr<SourceSurface> snapshot = drawDT->Snapshot();
     if (NS_WARN_IF(!snapshot)) {
       aError.Throw(NS_ERROR_FAILURE);
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -12,31 +12,31 @@
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "nsContentUtils.h"
 #include "nsCOMPtr.h"
 #include "nsDeviceContext.h"
 #include "nsError.h"
 #include "nsGlobalWindow.h"
 #include "nsIFrame.h"
 #include "nsIContent.h"
 #include "nsIContentInlines.h"
-#include "nsIPresShell.h"
 #include "nsIScrollableFrame.h"
 #include "nsJSEnvironment.h"
 #include "nsLayoutUtils.h"
 #include "nsPIWindowRoot.h"
 #include "nsRFPService.h"
 
 namespace mozilla {
 namespace dom {
@@ -528,18 +528,19 @@ CSSIntPoint Event::GetScreenCoords(nsPre
   if (!aPresContext || !(guiEvent && guiEvent->mWidget)) {
     return CSSIntPoint(aPoint.x, aPoint.y);
   }
 
   nsPoint pt = LayoutDevicePixel::ToAppUnits(
       aPoint,
       aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
 
-  if (nsIPresShell* ps = aPresContext->GetPresShell()) {
-    pt = pt.RemoveResolution(nsLayoutUtils::GetCurrentAPZResolutionScale(ps));
+  if (PresShell* presShell = aPresContext->GetPresShell()) {
+    pt = pt.RemoveResolution(
+        nsLayoutUtils::GetCurrentAPZResolutionScale(presShell));
   }
 
   pt += LayoutDevicePixel::ToAppUnits(
       guiEvent->mWidget->WidgetToScreenOffset(),
       aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
 
   return CSSPixel::FromAppUnitsRounded(pt);
 }
@@ -549,18 +550,19 @@ CSSIntPoint Event::GetPageCoords(nsPresC
                                  WidgetEvent* aEvent,
                                  LayoutDeviceIntPoint aPoint,
                                  CSSIntPoint aDefaultPoint) {
   CSSIntPoint pagePoint =
       Event::GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
 
   // If there is some scrolling, add scroll info to client point.
   if (aPresContext && aPresContext->GetPresShell()) {
-    nsIPresShell* shell = aPresContext->GetPresShell();
-    nsIScrollableFrame* scrollframe = shell->GetRootScrollFrameAsScrollable();
+    PresShell* presShell = aPresContext->PresShell();
+    nsIScrollableFrame* scrollframe =
+        presShell->GetRootScrollFrameAsScrollable();
     if (scrollframe) {
       pagePoint +=
           CSSIntPoint::FromAppUnitsRounded(scrollframe->GetScrollPosition());
     }
   }
 
   return pagePoint;
 }
@@ -607,26 +609,26 @@ CSSIntPoint Event::GetOffsetCoords(nsPre
                                    CSSIntPoint aDefaultPoint) {
   if (!aEvent->mTarget) {
     return GetPageCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
   }
   nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->mTarget);
   if (!content || !aPresContext) {
     return CSSIntPoint(0, 0);
   }
-  nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
-  if (!shell) {
+  RefPtr<PresShell> presShell = aPresContext->GetPresShell();
+  if (!presShell) {
     return CSSIntPoint(0, 0);
   }
-  shell->FlushPendingNotifications(FlushType::Layout);
+  presShell->FlushPendingNotifications(FlushType::Layout);
   nsIFrame* frame = content->GetPrimaryFrame();
   if (!frame) {
     return CSSIntPoint(0, 0);
   }
-  nsIFrame* rootFrame = shell->GetRootFrame();
+  nsIFrame* rootFrame = presShell->GetRootFrame();
   if (!rootFrame) {
     return CSSIntPoint(0, 0);
   }
   CSSIntPoint clientCoords =
       GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
   nsPoint pt = CSSPixel::ToAppUnits(clientCoords);
   if (nsLayoutUtils::TransformPoint(rootFrame, frame, pt) ==
       nsLayoutUtils::TRANSFORM_SUCCEEDED) {
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -8,16 +8,17 @@
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/HTMLEditor.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/ScrollTypes.h"
 #include "mozilla/TextComposition.h"
 #include "mozilla/TextEditor.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/DragEvent.h"
 #include "mozilla/dom/Event.h"
@@ -42,17 +43,16 @@
 #include "nsIContent.h"
 #include "nsIContentInlines.h"
 #include "mozilla/dom/Document.h"
 #include "nsIFrame.h"
 #include "nsFrameLoaderOwner.h"
 #include "nsITextControlElement.h"
 #include "nsIWidget.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 #include "nsGkAtoms.h"
 #include "nsIFormControl.h"
 #include "nsComboboxControlFrame.h"
 #include "nsIScrollableFrame.h"
 #include "nsIDOMXULControlElement.h"
 #include "nsNameSpaceManager.h"
 #include "nsIBaseWindow.h"
 #include "nsFrameSelection.h"
@@ -1649,20 +1649,21 @@ void EventStateManager::FillInEventFromG
   // different
   aEvent->mRefPoint =
       mGestureDownPoint - aEvent->mWidget->WidgetToScreenOffset();
   aEvent->mModifiers = mGestureModifiers;
   aEvent->buttons = mGestureDownButtons;
 }
 
 void EventStateManager::MaybeFirePointerCancel(WidgetInputEvent* aEvent) {
-  nsCOMPtr<nsIPresShell> shell = mPresContext->GetPresShell();
+  RefPtr<PresShell> presShell = mPresContext->GetPresShell();
   AutoWeakFrame targetFrame = mCurrentTarget;
 
-  if (!PointerEventHandler::IsPointerEventEnabled() || !shell || !targetFrame) {
+  if (!PointerEventHandler::IsPointerEventEnabled() || !presShell ||
+      !targetFrame) {
     return;
   }
 
   nsCOMPtr<nsIContent> content;
   targetFrame->GetContentForEvent(aEvent, getter_AddRefs(content));
   if (!content) {
     return;
   }
@@ -1670,26 +1671,26 @@ void EventStateManager::MaybeFirePointer
   nsEventStatus status = nsEventStatus_eIgnore;
 
   if (WidgetMouseEvent* aMouseEvent = aEvent->AsMouseEvent()) {
     WidgetPointerEvent event(*aMouseEvent);
     PointerEventHandler::InitPointerEventFromMouse(&event, aMouseEvent,
                                                    ePointerCancel);
 
     event.convertToPointer = false;
-    shell->HandleEventWithTarget(&event, targetFrame, content, &status);
+    presShell->HandleEventWithTarget(&event, targetFrame, content, &status);
   } else if (WidgetTouchEvent* aTouchEvent = aEvent->AsTouchEvent()) {
     WidgetPointerEvent event(aTouchEvent->IsTrusted(), ePointerCancel,
                              aTouchEvent->mWidget);
 
     PointerEventHandler::InitPointerEventFromTouch(
         &event, aTouchEvent, aTouchEvent->mTouches[0], true);
 
     event.convertToPointer = false;
-    shell->HandleEventWithTarget(&event, targetFrame, content, &status);
+    presShell->HandleEventWithTarget(&event, targetFrame, content, &status);
   } else {
     MOZ_ASSERT(false);
   }
 
   // HandleEventWithTarget clears out mCurrentTarget, which may be used in the
   // caller GenerateDragGesture. We have to restore mCurrentTarget.
   mCurrentTarget = targetFrame;
 }
@@ -3234,19 +3235,18 @@ nsresult EventStateManager::PostHandleEv
         // Make sure to dispatch the click even if there is no frame for
         // the current target element. This is required for Web compatibility.
         RefPtr<EventStateManager> esm =
             ESMFromContentOrThis(aOverrideClickTarget);
         ret =
             esm->PostHandleMouseUp(mouseUpEvent, aStatus, aOverrideClickTarget);
       }
 
-      nsIPresShell* shell = presContext->GetPresShell();
-      if (shell) {
-        RefPtr<nsFrameSelection> frameSelection = shell->FrameSelection();
+      if (PresShell* presShell = presContext->GetPresShell()) {
+        RefPtr<nsFrameSelection> frameSelection = presShell->FrameSelection();
         frameSelection->SetDragState(false);
       }
     } break;
     case eWheelOperationEnd: {
       MOZ_ASSERT(aEvent->IsTrusted());
       ScrollbarsForWheel::MayInactivate();
       WidgetWheelEvent* wheelEvent = aEvent->AsWheelEvent();
       nsIScrollableFrame* scrollTarget =
@@ -4896,17 +4896,17 @@ nsresult EventStateManager::InitAndDispa
 
 nsresult EventStateManager::PostHandleMouseUp(
     WidgetMouseEvent* aMouseUpEvent, nsEventStatus* aStatus,
     nsIContent* aOverrideClickTarget) {
   MOZ_ASSERT(aMouseUpEvent);
   MOZ_ASSERT(EventCausesClickEvents(*aMouseUpEvent));
   MOZ_ASSERT(aStatus);
 
-  nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
+  RefPtr<PresShell> presShell = mPresContext->GetPresShell();
   if (!presShell) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIContent> clickTarget =
       do_QueryInterface(aMouseUpEvent->mClickTarget);
   NS_ENSURE_STATE(clickTarget);
 
@@ -5110,49 +5110,47 @@ nsresult EventStateManager::HandleMiddle
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to paste");
   }
   *aStatus = nsEventStatus_eConsumeNoDefault;
 
   return NS_OK;
 }
 
 nsIFrame* EventStateManager::GetEventTarget() {
-  nsIPresShell* shell;
+  PresShell* presShell;
   if (mCurrentTarget || !mPresContext ||
-      !(shell = mPresContext->GetPresShell())) {
+      !(presShell = mPresContext->GetPresShell())) {
     return mCurrentTarget;
   }
 
   if (mCurrentTargetContent) {
     mCurrentTarget = mPresContext->GetPrimaryFrameFor(mCurrentTargetContent);
     if (mCurrentTarget) {
       return mCurrentTarget;
     }
   }
 
-  nsIFrame* frame = shell->GetCurrentEventFrame();
+  nsIFrame* frame = presShell->GetCurrentEventFrame();
   return (mCurrentTarget = frame);
 }
 
 already_AddRefed<nsIContent> EventStateManager::GetEventTargetContent(
     WidgetEvent* aEvent) {
   if (aEvent && (aEvent->mMessage == eFocus || aEvent->mMessage == eBlur)) {
     nsCOMPtr<nsIContent> content = GetFocusedContent();
     return content.forget();
   }
 
   if (mCurrentTargetContent) {
     nsCOMPtr<nsIContent> content = mCurrentTargetContent;
     return content.forget();
   }
 
   nsCOMPtr<nsIContent> content;
-
-  nsIPresShell* presShell = mPresContext->GetPresShell();
-  if (presShell) {
+  if (PresShell* presShell = mPresContext->GetPresShell()) {
     content = presShell->GetEventTargetContent(aEvent);
   }
 
   // Some events here may set mCurrentTarget but not set the corresponding
   // event target in the PresShell.
   if (!content && mCurrentTarget) {
     mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(content));
   }
@@ -5485,20 +5483,19 @@ uint32_t EventStateManager::GetRegistere
   return accessKey.First();
 }
 
 void EventStateManager::EnsureDocument(nsPresContext* aPresContext) {
   if (!mDocument) mDocument = aPresContext->Document();
 }
 
 void EventStateManager::FlushPendingEvents(nsPresContext* aPresContext) {
-  MOZ_ASSERT(nullptr != aPresContext, "nullptr ptr");
-  nsIPresShell* shell = aPresContext->GetPresShell();
-  if (shell) {
-    shell->FlushPendingNotifications(FlushType::InterruptibleLayout);
+  MOZ_ASSERT(aPresContext, "nullptr ptr");
+  if (RefPtr<PresShell> presShell = aPresContext->GetPresShell()) {
+    presShell->FlushPendingNotifications(FlushType::InterruptibleLayout);
   }
 }
 
 nsIContent* EventStateManager::GetFocusedContent() {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   EnsureDocument(mPresContext);
   if (!fm || !mDocument) return nullptr;
 
@@ -5644,18 +5641,18 @@ nsresult EventStateManager::DoContentCom
   }
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult EventStateManager::DoContentCommandScrollEvent(
     WidgetContentCommandEvent* aEvent) {
   NS_ENSURE_TRUE(mPresContext, NS_ERROR_NOT_AVAILABLE);
-  nsIPresShell* ps = mPresContext->GetPresShell();
-  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_AVAILABLE);
+  PresShell* presShell = mPresContext->GetPresShell();
+  NS_ENSURE_TRUE(presShell, NS_ERROR_NOT_AVAILABLE);
   NS_ENSURE_TRUE(aEvent->mScroll.mAmount != 0, NS_ERROR_INVALID_ARG);
 
   nsIScrollableFrame::ScrollUnit scrollUnit;
   switch (aEvent->mScroll.mUnit) {
     case WidgetContentCommandEvent::eCmdScrollUnit_Line:
       scrollUnit = nsIScrollableFrame::LINES;
       break;
     case WidgetContentCommandEvent::eCmdScrollUnit_Page:
@@ -5666,17 +5663,17 @@ nsresult EventStateManager::DoContentCom
       break;
     default:
       return NS_ERROR_INVALID_ARG;
   }
 
   aEvent->mSucceeded = true;
 
   nsIScrollableFrame* sf =
-      ps->GetScrollableFrameToScroll(nsIPresShell::eEither);
+      presShell->GetScrollableFrameToScroll(nsIPresShell::eEither);
   aEvent->mIsEnabled =
       sf ? (aEvent->mScroll.mIsHorizontal ? WheelHandlingUtils::CanScrollOn(
                                                 sf, aEvent->mScroll.mAmount, 0)
                                           : WheelHandlingUtils::CanScrollOn(
                                                 sf, 0, aEvent->mScroll.mAmount))
          : false;
 
   if (!aEvent->mIsEnabled || aEvent->mOnlyEnabledCheck) {
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -8,28 +8,28 @@
 
 #include "ContentEventHandler.h"
 #include "IMEContentObserver.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextComposition.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Selection.h"
 #include "nsContentUtils.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsIContent.h"
 #include "mozilla/dom/Document.h"
 #include "nsIFrame.h"
 #include "nsINode.h"
-#include "nsIPresShell.h"
 #include "nsISelectionController.h"
 #include "nsISupports.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsIWidget.h"
 #include "nsPresContext.h"
 #include "nsRange.h"
 #include "nsRefreshDriver.h"
 #include "WritingModes.h"
@@ -300,30 +300,30 @@ bool IMEContentObserver::InitWithEditor(
     return false;
   }
 
   mEditorBase = aEditorBase;
   if (NS_WARN_IF(!mEditorBase)) {
     return false;
   }
 
-  nsIPresShell* presShell = aPresContext->PresShell();
+  PresShell* presShell = aPresContext->GetPresShell();
 
   // get selection and root content
   nsCOMPtr<nsISelectionController> selCon;
   if (mEditableNode->IsContent()) {
     nsIFrame* frame = mEditableNode->AsContent()->GetPrimaryFrame();
     if (NS_WARN_IF(!frame)) {
       return false;
     }
 
     frame->GetSelectionController(aPresContext, getter_AddRefs(selCon));
   } else {
     // mEditableNode is a document
-    selCon = do_QueryInterface(presShell);
+    selCon = presShell;
   }
 
   if (NS_WARN_IF(!selCon)) {
     return false;
   }
 
   mSelection = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL);
   if (NS_WARN_IF(!mSelection)) {
@@ -1455,17 +1455,17 @@ void IMEContentObserver::PostComposition
   mNeedsToNotifyIMEOfCompositionEventHandled = true;
 }
 
 bool IMEContentObserver::IsReflowLocked() const {
   nsPresContext* presContext = GetPresContext();
   if (NS_WARN_IF(!presContext)) {
     return false;
   }
-  nsIPresShell* presShell = presContext->GetPresShell();
+  PresShell* presShell = presContext->GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return false;
   }
   // During reflow, we shouldn't notify IME because IME may query content
   // synchronously.  Then, it causes ContentEventHandler will try to flush
   // pending notifications during reflow.
   return presShell->IsReflowLocked();
 }
--- a/dom/events/TextComposition.cpp
+++ b/dom/events/TextComposition.cpp
@@ -4,24 +4,24 @@
  * 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 "ContentEventHandler.h"
 #include "IMEContentObserver.h"
 #include "IMEStateManager.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
-#include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/EditorBase.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/TextComposition.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/TabParent.h"
 
 #ifdef XP_MACOSX
 // Some defiens will be conflict with OSX SDK
@@ -85,17 +85,17 @@ void TextComposition::Destroy() {
   mCompositionLengthInTextNode = UINT32_MAX;
   // TODO: If the editor is still alive and this is held by it, we should tell
   //       this being destroyed for cleaning up the stuff.
 }
 
 bool TextComposition::IsValidStateForComposition(nsIWidget* aWidget) const {
   return !Destroyed() && aWidget && !aWidget->Destroyed() &&
          mPresContext->GetPresShell() &&
-         !mPresContext->GetPresShell()->IsDestroying();
+         !mPresContext->PresShell()->IsDestroying();
 }
 
 bool TextComposition::MaybeDispatchCompositionUpdate(
     const WidgetCompositionEvent* aCompositionEvent) {
   MOZ_RELEASE_ASSERT(!mTabParent);
 
   if (!IsValidStateForComposition(aCompositionEvent->mWidget)) {
     return false;
--- a/dom/events/UIEvent.cpp
+++ b/dom/events/UIEvent.cpp
@@ -6,16 +6,17 @@
 
 #include "base/basictypes.h"
 #include "ipc/IPCMessageUtils.h"
 #include "mozilla/dom/UIEvent.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventStateManager.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIDocShell.h"
 #include "nsIDOMWindow.h"
 #include "nsIFrame.h"
@@ -160,31 +161,31 @@ int32_t UIEvent::PageY() const {
                               mClientPoint)
       .y;
 }
 
 already_AddRefed<nsINode> UIEvent::GetRangeParent() {
   if (NS_WARN_IF(!mPresContext)) {
     return nullptr;
   }
-  nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
+  RefPtr<PresShell> presShell = mPresContext->GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return nullptr;
   }
   nsCOMPtr<nsIContent> container;
   nsLayoutUtils::GetContainerAndOffsetAtEvent(
       presShell, mEvent, getter_AddRefs(container), nullptr);
   return container.forget();
 }
 
 int32_t UIEvent::RangeOffset() const {
   if (NS_WARN_IF(!mPresContext)) {
     return 0;
   }
-  nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
+  RefPtr<PresShell> presShell = mPresContext->GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return 0;
   }
   int32_t offset = 0;
   nsLayoutUtils::GetContainerAndOffsetAtEvent(presShell, mEvent, nullptr,
                                               &offset);
   return offset;
 }
--- a/dom/html/HTMLButtonElement.cpp
+++ b/dom/html/HTMLButtonElement.cpp
@@ -6,29 +6,29 @@
 
 #include "mozilla/dom/HTMLButtonElement.h"
 
 #include "HTMLFormSubmissionConstants.h"
 #include "mozilla/dom/HTMLButtonElementBinding.h"
 #include "mozilla/dom/HTMLFormSubmission.h"
 #include "nsAttrValueInlines.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIFormControl.h"
 #include "nsIURL.h"
 #include "nsIFrame.h"
 #include "nsIFormControlFrame.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 #include "nsUnicharUtils.h"
 #include "nsLayoutUtils.h"
 #include "mozilla/PresState.h"
 #include "nsError.h"
 #include "nsFocusManager.h"
 #include "mozilla/dom/HTMLFormElement.h"
 #include "mozAutoDocUpdate.h"
@@ -199,21 +199,20 @@ nsresult HTMLButtonElement::PostHandleEv
   if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
     WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
     if (mouseEvent && mouseEvent->IsLeftClickEvent()) {
       // DOMActive event should be trusted since the activation is actually
       // occurred even if the cause is an untrusted click event.
       InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
       actEvent.mDetail = 1;
 
-      nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
-      if (shell) {
+      if (RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell()) {
         nsEventStatus status = nsEventStatus_eIgnore;
         mInInternalActivate = true;
-        shell->HandleDOMEventWithTarget(this, &actEvent, &status);
+        presShell->HandleDOMEventWithTarget(this, &actEvent, &status);
         mInInternalActivate = false;
 
         // If activate is cancelled, we must do the same as when click is
         // cancelled (revert the checkbox to its original value).
         if (status == nsEventStatus_eConsumeNoDefault) {
           aVisitor.mEventStatus = status;
         }
       }
@@ -253,18 +252,17 @@ nsresult HTMLButtonElement::PostHandleEv
     if (aVisitor.mItemFlags & NS_OUTER_ACTIVATE_EVENT) {
       if (mForm &&
           (mType == NS_FORM_BUTTON_SUBMIT || mType == NS_FORM_BUTTON_RESET)) {
         InternalFormEvent event(
             true, (mType == NS_FORM_BUTTON_RESET) ? eFormReset : eFormSubmit);
         event.mOriginator = this;
         nsEventStatus status = nsEventStatus_eIgnore;
 
-        nsCOMPtr<nsIPresShell> presShell =
-            aVisitor.mPresContext->GetPresShell();
+        RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell();
         // If |nsIPresShell::Destroy| has been called due to
         // handling the event, the pres context will return
         // a null pres shell.  See bug 125624.
         //
         // Using presShell to dispatch the event. It makes sure that
         // event is not handled if the window is being destroyed.
         if (presShell && (event.mMessage != eFormSubmit ||
                           mForm->SubmissionCanProceed(this))) {
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -11,16 +11,17 @@
 #include "mozilla/DebugOnly.h"
 #include "mozilla/dom/Date.h"
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/DocumentOrShadowRoot.h"
 #include "mozilla/dom/HTMLFormSubmission.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/GetFilesHelper.h"
 #include "mozilla/dom/WheelEventBinding.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StaticPrefs.h"
 #include "nsAttrValueInlines.h"
 #include "nsCRTGlue.h"
 #include "nsQueryObject.h"
 
 #include "nsITextControlElement.h"
 #include "nsIRadioVisitor.h"
 #include "InputType.h"
@@ -38,17 +39,16 @@
 #include "nsIComponentManager.h"
 #include "mozilla/dom/ProgressEvent.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsMappedAttributes.h"
 #include "nsIFormControl.h"
 #include "mozilla/dom/Document.h"
-#include "nsIPresShell.h"
 #include "nsIFormControlFrame.h"
 #include "nsITextControlFrame.h"
 #include "nsIFrame.h"
 #include "nsRangeFrame.h"
 #include "nsIServiceManager.h"
 #include "nsError.h"
 #include "nsIEditor.h"
 #include "nsAttrValueOrString.h"
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -51,16 +51,17 @@
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/EMEUtils.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/dom/AudioTrack.h"
 #include "mozilla/dom/AudioTrackList.h"
 #include "mozilla/dom/BlobURLProtocolHandler.h"
 #include "mozilla/dom/ElementInlines.h"
 #include "mozilla/dom/HTMLAudioElement.h"
@@ -96,17 +97,16 @@
 #include "nsIClassOfService.h"
 #include "nsIContentPolicy.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsIDocShell.h"
 #include "mozilla/dom/Document.h"
 #include "nsIFrame.h"
 #include "nsIObserverService.h"
 #include "nsIPermissionManager.h"
-#include "nsIPresShell.h"
 #include "nsIRequest.h"
 #include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIThreadInternal.h"
 #include "nsITimer.h"
 #include "nsIXPConnect.h"
 #include "nsJSUtils.h"
@@ -5913,17 +5913,17 @@ void HTMLMediaElement::NotifyDecoderPrin
 void HTMLMediaElement::Invalidate(bool aImageSizeChanged,
                                   Maybe<nsIntSize>& aNewIntrinsicSize,
                                   bool aForceInvalidate) {
   nsIFrame* frame = GetPrimaryFrame();
   if (aNewIntrinsicSize) {
     UpdateMediaSize(aNewIntrinsicSize.value());
     if (frame) {
       nsPresContext* presContext = frame->PresContext();
-      nsIPresShell* presShell = presContext->PresShell();
+      PresShell* presShell = presContext->PresShell();
       presShell->FrameNeedsReflow(frame, nsIPresShell::eStyleChange,
                                   NS_FRAME_IS_DIRTY);
     }
   }
 
   RefPtr<ImageContainer> imageContainer = GetImageContainer();
   bool asyncInvalidate =
       imageContainer && imageContainer->IsAsync() && !aForceInvalidate;
--- a/dom/html/nsGenericHTMLFrameElement.cpp
+++ b/dom/html/nsGenericHTMLFrameElement.cpp
@@ -5,25 +5,25 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsGenericHTMLFrameElement.h"
 
 #include "mozilla/dom/HTMLIFrameElement.h"
 #include "mozilla/dom/XULFrameElement.h"
 #include "mozilla/dom/WindowProxyHolder.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/ErrorResult.h"
 #include "GeckoProfiler.h"
 #include "nsAttrValueInlines.h"
 #include "nsContentUtils.h"
 #include "nsIDocShell.h"
 #include "nsIFrame.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIPermissionManager.h"
-#include "nsIPresShell.h"
 #include "nsIScrollable.h"
 #include "nsPresContext.h"
 #include "nsServiceManagerUtils.h"
 #include "nsSubDocumentFrame.h"
 #include "nsAttrValueOrString.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
@@ -291,23 +291,23 @@ nsresult nsGenericHTMLFrameElement::Afte
               nsIScrollable::ScrollOrientation_X, &cur);
           int32_t val = MapScrollingAttribute(aValue);
           if (cur != val) {
             scrollable->SetDefaultScrollbarPreferences(
                 nsIScrollable::ScrollOrientation_X, val);
             scrollable->SetDefaultScrollbarPreferences(
                 nsIScrollable::ScrollOrientation_Y, val);
             RefPtr<nsPresContext> presContext = docshell->GetPresContext();
-            nsIPresShell* shell =
+            PresShell* presShell =
                 presContext ? presContext->GetPresShell() : nullptr;
             nsIFrame* rootScroll =
-                shell ? shell->GetRootScrollFrame() : nullptr;
+                presShell ? presShell->GetRootScrollFrame() : nullptr;
             if (rootScroll) {
-              shell->FrameNeedsReflow(rootScroll, nsIPresShell::eStyleChange,
-                                      NS_FRAME_IS_DIRTY);
+              presShell->FrameNeedsReflow(
+                  rootScroll, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
             }
           }
         }
       }
     } else if (aName == nsGkAtoms::mozbrowser) {
       mReallyIsBrowser = !!aValue && BrowserFramesEnabled() &&
                          PrincipalAllowsBrowserFrame(NodePrincipal());
     }
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -1173,18 +1173,17 @@ nsresult nsTextEditorState::BindToFrame(
     GetValue(currentValue, true);
   }
 
   mBoundFrame = aFrame;
 
   Element* rootNode = aFrame->GetRootNode();
   MOZ_ASSERT(rootNode);
 
-  PresShell* presShell =
-      static_cast<PresShell*>(aFrame->PresContext()->GetPresShell());
+  PresShell* presShell = aFrame->PresContext()->GetPresShell();
   MOZ_ASSERT(presShell);
 
   // Create selection
   RefPtr<nsFrameSelection> frameSel = new nsFrameSelection();
 
   // Create a SelectionController
   mSelCon = new nsTextInputSelectionImpl(frameSel, presShell, rootNode);
   MOZ_ASSERT(!mTextListener, "Should not overwrite the object");
@@ -1264,17 +1263,17 @@ nsresult nsTextEditorState::PrepareEdito
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // Note that we don't check mTextEditor here, because we might already have
   // one around, in which case we don't create a new one, and we'll just tie
   // the required machinery to it.
 
   nsPresContext* presContext = mBoundFrame->PresContext();
-  nsIPresShell* shell = presContext->GetPresShell();
+  PresShell* presShell = presContext->GetPresShell();
 
   // Setup the editor flags
   uint32_t editorFlags = nsIPlaintextEditor::eEditorPlaintextMask;
   if (IsSingleLineTextControl())
     editorFlags |= nsIPlaintextEditor::eEditorSingleLineMask;
   if (IsPasswordTextControl())
     editorFlags |= nsIPlaintextEditor::eEditorPasswordMask;
 
@@ -1327,17 +1326,17 @@ nsresult nsTextEditorState::PrepareEdito
 
   if (!mEditorInitialized) {
     // Now initialize the editor.
     //
     // NOTE: Conversion of '\n' to <BR> happens inside the
     //       editor's Init() call.
 
     // Get the DOM document
-    nsCOMPtr<Document> doc = shell->GetDocument();
+    nsCOMPtr<Document> doc = presShell->GetDocument();
     if (NS_WARN_IF(!doc)) {
       return NS_ERROR_FAILURE;
     }
 
     // What follows is a bit of a hack.  The editor uses the public DOM APIs
     // for its content manipulations, and it causes it to fail some security
     // checks deep inside when initializing. So we explictly make it clear that
     // we're native code.
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -46,16 +46,17 @@ using mozilla::DefaultXDisplay;
 #include "nsIDocShell.h"
 #include "ImageContainer.h"
 #include "GLContext.h"
 #include "EGLUtils.h"
 #include "nsIContentInlines.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/NullPrincipal.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "mozilla/dom/DragEvent.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/HTMLObjectElementBinding.h"
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/dom/WheelEventBinding.h"
--- a/gfx/ipc/CrossProcessPaint.cpp
+++ b/gfx/ipc/CrossProcessPaint.cpp
@@ -93,18 +93,18 @@ PaintFragment PaintFragment::Record(nsID
   {
     nsRect r(nsPresContext::CSSPixelsToAppUnits(aRect.x),
              nsPresContext::CSSPixelsToAppUnits(aRect.y),
              nsPresContext::CSSPixelsToAppUnits(aRect.width),
              nsPresContext::CSSPixelsToAppUnits(aRect.height));
 
     RefPtr<gfxContext> thebes = gfxContext::CreateOrNull(dt);
     thebes->SetMatrix(Matrix::Scaling(aScale, aScale));
-    nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
-    Unused << shell->RenderDocument(r, 0, aBackgroundColor, thebes);
+    RefPtr<PresShell> presShell = presContext->PresShell();
+    Unused << presShell->RenderDocument(r, 0, aBackgroundColor, thebes);
   }
 
   ByteBuf recording = ByteBuf((uint8_t*)recorder->mOutputStream.mData,
                               recorder->mOutputStream.mLength,
                               recorder->mOutputStream.mCapacity);
   recorder->mOutputStream.mData = nullptr;
   recorder->mOutputStream.mLength = 0;
   recorder->mOutputStream.mCapacity = 0;
--- a/layout/base/PositionedEventTargeting.cpp
+++ b/layout/base/PositionedEventTargeting.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "PositionedEventTargeting.h"
 
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "nsLayoutUtils.h"
 #include "nsGkAtoms.h"
 #include "nsFontMetrics.h"
 #include "nsPrintfCString.h"
 #include "mozilla/dom/Element.h"
 #include "nsRegion.h"
 #include "nsDeviceContext.h"
@@ -253,17 +254,17 @@ static nsIContent* GetClickableAncestor(
       return content;
     }
   }
   return nullptr;
 }
 
 static nscoord AppUnitsFromMM(nsIFrame* aFrame, uint32_t aMM) {
   nsPresContext* pc = aFrame->PresContext();
-  nsIPresShell* presShell = pc->PresShell();
+  PresShell* presShell = pc->PresShell();
   float result = float(aMM) * (pc->DeviceContext()->AppUnitsPerPhysicalInch() /
                                MM_PER_INCH_FLOAT);
   result = result / presShell->GetResolution();
   return NSToCoordRound(result);
 }
 
 /**
  * Clip aRect with the bounds of aFrame in the coordinate system of
@@ -351,17 +352,17 @@ static bool IsElementPresent(nsTArray<ns
   }
   return false;
 }
 
 static bool IsLargeElement(nsIFrame* aFrame, const EventRadiusPrefs* aPrefs) {
   uint32_t keepLimitSizeForCluster = aPrefs->mKeepLimitSizeForCluster;
   nsSize frameSize = aFrame->GetSize();
   nsPresContext* pc = aFrame->PresContext();
-  nsIPresShell* presShell = pc->PresShell();
+  PresShell* presShell = pc->PresShell();
   float cumulativeResolution = presShell->GetCumulativeResolution();
   if ((pc->AppUnitsToGfxUnits(frameSize.height) * cumulativeResolution) >
           keepLimitSizeForCluster &&
       (pc->AppUnitsToGfxUnits(frameSize.width) * cumulativeResolution) >
           keepLimitSizeForCluster) {
     return true;
   }
   return false;
@@ -482,17 +483,17 @@ static bool IsElementClickableAndReadabl
 
   if (aEvent->mClass != eMouseEventClass) {
     return true;
   }
 
   uint32_t limitReadableSize = aPrefs->mLimitReadableSize;
   nsSize frameSize = aFrame->GetSize();
   nsPresContext* pc = aFrame->PresContext();
-  nsIPresShell* presShell = pc->PresShell();
+  PresShell* presShell = pc->PresShell();
   float cumulativeResolution = presShell->GetCumulativeResolution();
   if ((pc->AppUnitsToGfxUnits(frameSize.height) * cumulativeResolution) <
           limitReadableSize ||
       (pc->AppUnitsToGfxUnits(frameSize.width) * cumulativeResolution) <
           limitReadableSize) {
     return false;
   }
   // We want to detect small clickable text elements using the font size.
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -935,17 +935,17 @@ void PresShell::Init(Document* aDocument
 
   mFrameManager = mFrameConstructor.get();
 
   // The document viewer owns both view manager and pres shell.
   mViewManager->SetPresShell(this);
 
   // Bind the context to the presentation shell.
   mPresContext = aPresContext;
-  mPresContext->AttachShell(this);
+  mPresContext->AttachPresShell(this);
 
   mPresContext->DeviceContext()->InitFontCache();
 
   // Add the preference style sheet.
   UpdatePreferenceStyles();
 
   bool accessibleCaretEnabled =
       AccessibleCaretEnabled(mDocument->GetDocShell());
@@ -1347,17 +1347,17 @@ void PresShell::Destroy() {
   for (WeakFrame* weakFrame : toRemove) {
     weakFrame->Clear(this);
   }
 
   if (mPresContext) {
     // We hold a reference to the pres context, and it holds a weak link back
     // to us. To avoid the pres context having a dangling reference, set its
     // pres shell to nullptr
-    mPresContext->DetachShell();
+    mPresContext->DetachPresShell();
 
     // Clear the link handler (weak reference) as well
     mPresContext->SetLinkHandler(nullptr);
   }
 
   mHaveShutDown = true;
 
   mTouchManager.Destroy();
@@ -5060,17 +5060,17 @@ static bool IsTransparentContainerElemen
   nsCOMPtr<nsPIDOMWindowOuter> pwin = docShell->GetWindow();
   if (!pwin) return false;
   nsCOMPtr<Element> containerElement = pwin->GetFrameElementInternal();
 
   TabChild* tab = TabChild::GetFrom(docShell);
   if (tab) {
     // Check if presShell is the top PresShell. Only the top can
     // influence the canvas background color.
-    nsCOMPtr<nsIPresShell> presShell = aPresContext->GetPresShell();
+    PresShell* presShell = aPresContext->GetPresShell();
     nsCOMPtr<nsIPresShell> topPresShell = tab->GetPresShell();
     if (presShell != topPresShell) {
       tab = nullptr;
     }
   }
 
   return (containerElement && containerElement->HasAttr(
                                   kNameSpaceID_None, nsGkAtoms::transparent)) ||
@@ -5202,27 +5202,27 @@ float PresShell::GetCumulativeResolution
   if (parentCtx) {
     resolution *= parentCtx->PresShell()->GetCumulativeResolution();
   }
   return resolution;
 }
 
 float PresShell::GetCumulativeNonRootScaleResolution() {
   float resolution = 1.0;
-  nsIPresShell* currentShell = this;
-  while (currentShell) {
-    nsPresContext* currentCtx = currentShell->GetPresContext();
+  PresShell* currentPresShell = this;
+  while (currentPresShell) {
+    nsPresContext* currentCtx = currentPresShell->GetPresContext();
     if (currentCtx != currentCtx->GetRootPresContext()) {
-      resolution *= currentShell->GetResolution();
+      resolution *= currentPresShell->GetResolution();
     }
     nsPresContext* parentCtx = currentCtx->GetParentPresContext();
     if (parentCtx) {
-      currentShell = parentCtx->PresShell();
+      currentPresShell = parentCtx->PresShell();
     } else {
-      currentShell = nullptr;
+      currentPresShell = nullptr;
     }
   }
   return resolution;
 }
 
 void PresShell::SetRestoreResolution(float aResolution,
                                      LayoutDeviceIntSize aDisplaySize) {
   if (mMobileViewportManager) {
@@ -6395,56 +6395,53 @@ PresShell* PresShell::GetShellForEventTa
     }
     return doc->GetPresShell();
   }
   return nullptr;
 }
 
 /* static */
 PresShell* PresShell::GetShellForTouchEvent(WidgetGUIEvent* aEvent) {
-  PresShell* shell = nullptr;
   switch (aEvent->mMessage) {
     case eTouchMove:
     case eTouchCancel:
     case eTouchEnd: {
       // get the correct shell to dispatch to
       WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
       for (dom::Touch* touch : touchEvent->mTouches) {
         if (!touch) {
-          break;
+          return nullptr;
         }
 
         RefPtr<dom::Touch> oldTouch =
             TouchManager::GetCapturedTouch(touch->Identifier());
         if (!oldTouch) {
-          break;
+          return nullptr;
         }
 
         nsCOMPtr<nsIContent> content = do_QueryInterface(oldTouch->GetTarget());
         if (!content) {
-          break;
+          return nullptr;
         }
 
         nsIFrame* contentFrame = content->GetPrimaryFrame();
         if (!contentFrame) {
-          break;
+          return nullptr;
         }
 
-        shell =
-            static_cast<PresShell*>(contentFrame->PresContext()->PresShell());
-        if (shell) {
-          break;
+        PresShell* presShell = contentFrame->PresContext()->GetPresShell();
+        if (presShell) {
+          return presShell;
         }
       }
-      break;
+      return nullptr;
     }
     default:
-      break;
-  }
-  return shell;
+      return nullptr;
+  }
 }
 
 nsresult PresShell::HandleEvent(nsIFrame* aFrameForPresShell,
                                 WidgetGUIEvent* aGUIEvent,
                                 bool aDontRetargetEvents,
                                 nsEventStatus* aEventStatus) {
   MOZ_ASSERT(aGUIEvent);
   EventHandler eventHandler(*this);
@@ -7133,18 +7130,18 @@ bool PresShell::EventHandler::MaybeHandl
 
   // If we reached same frame as set to HandleEvent(), the caller should handle
   // the event by itself.
   if (frame == aFrameForPresShell) {
     return false;
   }
 
   // We need to handle aGUIEvent with another PresShell.
-  nsCOMPtr<nsIPresShell> shell = frame->PresContext()->GetPresShell();
-  *aRv = shell->HandleEvent(frame, aGUIEvent, true, aEventStatus);
+  RefPtr<PresShell> presShell = frame->PresContext()->PresShell();
+  *aRv = presShell->HandleEvent(frame, aGUIEvent, true, aEventStatus);
   return true;
 }
 
 bool PresShell::EventHandler::MaybeDiscardOrDelayKeyboardEvent(
     WidgetGUIEvent* aGUIEvent) {
   MOZ_ASSERT(aGUIEvent);
 
   if (aGUIEvent->mClass != eKeyboardEventClass) {
@@ -10551,17 +10548,17 @@ nsresult PresShell::UpdateImageLockingSt
 
   return rv;
 }
 
 PresShell* PresShell::GetRootPresShell() {
   if (mPresContext) {
     nsPresContext* rootPresContext = mPresContext->GetRootPresContext();
     if (rootPresContext) {
-      return static_cast<PresShell*>(rootPresContext->PresShell());
+      return rootPresContext->PresShell();
     }
   }
   return nullptr;
 }
 
 void PresShell::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const {
   MallocSizeOf mallocSizeOf = aSizes.mState.mMallocSizeOf;
   mFrameArena.AddSizeOfExcludingThis(aSizes);
@@ -10962,30 +10959,29 @@ bool PresShell::EventHandler::EventTarge
     return false;
   }
 
   nsPresContext* activePresContext = activeESM->GetPresContext();
   if (!activePresContext) {
     return false;
   }
 
-  nsIPresShell* activePresShell = activePresContext->GetPresShell();
+  PresShell* activePresShell = activePresContext->GetPresShell();
   if (!activePresShell) {
     return false;
   }
 
   // Note, currently for backwards compatibility we don't forward mouse events
   // to the active document when mouse is over some subdocument.
   if (!nsContentUtils::ContentIsCrossDocDescendantOf(
           activePresShell->GetDocument(), GetDocument())) {
     return false;
   }
 
-  SetPresShellAndFrame(static_cast<PresShell*>(activePresShell),
-                       activePresShell->GetRootFrame());
+  SetPresShellAndFrame(activePresShell, activePresShell->GetRootFrame());
   return true;
 }
 
 bool PresShell::EventHandler::EventTargetData::ComputeElementFromFrame(
     WidgetGUIEvent* aGUIEvent) {
   MOZ_ASSERT(aGUIEvent);
   MOZ_ASSERT(aGUIEvent->IsUsingCoordinates());
   MOZ_ASSERT(mPresShell);
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -174,16 +174,18 @@ class PresShell final : public nsIPresSh
   // Widget notificiations
   void WindowSizeMoveDone() override;
   void SysColorChanged() override { mPresContext->SysColorChanged(); }
   void ThemeChanged() override { mPresContext->ThemeChanged(); }
   void BackingScaleFactorChanged() override {
     mPresContext->UIResolutionChangedSync();
   }
 
+  void SynthesizeMouseMove(bool aFromScroll) override;
+
   // nsIViewObserver interface
 
   void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
              uint32_t aFlags) override;
   MOZ_CAN_RUN_SCRIPT nsresult HandleEvent(nsIFrame* aFrameForPresShell,
                                           WidgetGUIEvent* aEvent,
                                           bool aDontRetargetEvents,
                                           nsEventStatus* aEventStatus) override;
@@ -209,16 +211,18 @@ class PresShell final : public nsIPresSh
   NS_IMETHOD SetCaretReadOnly(bool aReadOnly) override;
   NS_IMETHOD GetCaretEnabled(bool* aOutEnabled) override;
   NS_IMETHOD SetCaretVisibilityDuringSelection(bool aVisibility) override;
   NS_IMETHOD GetCaretVisible(bool* _retval) override;
 
   NS_IMETHOD SetSelectionFlags(int16_t aInEnable) override;
   NS_IMETHOD GetSelectionFlags(int16_t* aOutEnable) override;
 
+  using nsIPresShell::GetSelectionFlags;
+
   // nsISelectionController
 
   NS_IMETHOD PhysicalMove(int16_t aDirection, int16_t aAmount,
                           bool aExtend) override;
   NS_IMETHOD CharacterMove(bool aForward, bool aExtend) override;
   NS_IMETHOD CharacterExtendForDelete() override;
   NS_IMETHOD CharacterExtendForBackspace() override;
   NS_IMETHOD WordMove(bool aForward, bool aExtend) override;
@@ -269,21 +273,20 @@ class PresShell final : public nsIPresSh
 
   void ListStyleSheets(FILE* out, int32_t aIndent = 0) override;
 #endif
 
   void DisableNonTestMouseEvents(bool aDisable) override;
 
   void UpdateCanvasBackground() override;
 
-  void AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
-                                    nsDisplayList& aList, nsIFrame* aFrame,
-                                    const nsRect& aBounds,
-                                    nscolor aBackstopColor,
-                                    uint32_t aFlags) override;
+  void AddCanvasBackgroundColorItem(
+      nsDisplayListBuilder& aBuilder, nsDisplayList& aList, nsIFrame* aFrame,
+      const nsRect& aBounds, nscolor aBackstopColor = NS_RGBA(0, 0, 0, 0),
+      uint32_t aFlags = 0) override;
 
   void AddPrintPreviewBackgroundItem(nsDisplayListBuilder& aBuilder,
                                      nsDisplayList& aList, nsIFrame* aFrame,
                                      const nsRect& aBounds) override;
 
   nscolor ComputeBackstopColor(nsView* aDisplayRoot) override;
 
   nsresult SetIsActive(bool aIsActive) override;
@@ -1278,18 +1281,16 @@ class PresShell final : public nsIPresSh
 
     OwningNonNull<PresShell> mPresShell;
     AutoCurrentEventInfoSetter* mCurrentEventInfoSetter;
     static TimeStamp sLastInputCreated;
     static TimeStamp sLastInputProcessed;
     static StaticRefPtr<dom::Element> sLastKeyDownEventTargetElement;
   };
 
-  void SynthesizeMouseMove(bool aFromScroll) override;
-
   PresShell* GetRootPresShell();
 
   nscolor GetDefaultBackgroundColorToDraw();
 
   // The callback for the mPaintSuppressionTimer timer.
   static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
 
   Document* GetPrimaryContentDocument() override;
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -10,16 +10,17 @@
 #include "mozilla/AutoTimelineMarker.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/ComputedStyleInlines.h"
 #include "mozilla/DocumentStyleRootIterator.h"
 #include "mozilla/GeckoBindings.h"
 #include "mozilla/LayerAnimationInfo.h"
 #include "mozilla/layers/AnimationInfo.h"
 #include "mozilla/layout/ScrollAnchorContainer.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/ServoStyleSetInlines.h"
 #include "mozilla/Unused.h"
 #include "mozilla/ViewportFrame.h"
 #include "mozilla/dom/ChildIterator.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "mozilla/dom/ElementInlines.h"
 #include "mozilla/dom/HTMLBodyElement.h"
@@ -2660,17 +2661,17 @@ static ServoPostTraversalFlags SendA11yN
   } else {
     // If we shouldn't skip in any case, we need to check whether our
     // own visibility has changed.
     bool wasVisible = aOldComputedStyle->StyleVisibility()->IsVisible();
     needsNotify = wasVisible != isVisible;
   }
 
   if (needsNotify) {
-    nsIPresShell* presShell = aPresContext->PresShell();
+    PresShell* presShell = aPresContext->PresShell();
     if (isVisible) {
       accService->ContentRangeInserted(presShell, aElement,
                                        aElement->GetNextSibling());
       // We are adding the subtree. Accessibility service would handle
       // descendants, so we should just skip them from notifying.
       return Flags::SkipA11yNotifications;
     }
     // Remove the subtree of this invisible element, and ask any shown
@@ -3014,41 +3015,41 @@ ServoElementSnapshot& RestyleManager::Sn
 
   // Now that we have a snapshot, make sure a restyle is triggered.
   aElement.NoteDirtyForServo();
   return *snapshot;
 }
 
 void RestyleManager::DoProcessPendingRestyles(ServoTraversalFlags aFlags) {
   nsPresContext* presContext = PresContext();
-  nsIPresShell* shell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
 
   MOZ_ASSERT(presContext->Document(), "No document?  Pshaw!");
   // FIXME(emilio): In the "flush animations" case, ideally, we should only
   // recascade animation styles running on the compositor, so we shouldn't care
   // about other styles, or new rules that apply to the page...
   //
   // However, that's not true as of right now, see bug 1388031 and bug 1388692.
   MOZ_ASSERT((aFlags & ServoTraversalFlags::FlushThrottledAnimations) ||
                  !presContext->HasPendingMediaQueryUpdates(),
              "Someone forgot to update media queries?");
   MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(), "Missing a script blocker!");
   MOZ_RELEASE_ASSERT(!mInStyleRefresh, "Reentrant call?");
 
-  if (MOZ_UNLIKELY(!shell->DidInitialize())) {
+  if (MOZ_UNLIKELY(!presShell->DidInitialize())) {
     // PresShell::FlushPendingNotifications doesn't early-return in the case
     // where the PresShell hasn't yet been initialized (and therefore we haven't
     // yet done the initial style traversal of the DOM tree). We should arguably
     // fix up the callers and assert against this case, but we just detect and
     // handle it for now.
     return;
   }
 
   // It'd be bad!
-  nsIPresShell::AutoAssertNoFlush noReentrantFlush(*shell);
+  nsIPresShell::AutoAssertNoFlush noReentrantFlush(*presShell);
 
   // Create a AnimationsWithDestroyedFrame during restyling process to
   // stop animations and transitions on elements that have no frame at the end
   // of the restyling process.
   AnimationsWithDestroyedFrame animationsWithDestroyedFrame(this);
 
   ServoStyleSet* styleSet = StyleSet();
   Document* doc = presContext->Document();
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -2,16 +2,17 @@
 /* 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 "nsBidiPresUtils.h"
 
 #include "mozilla/IntegerRange.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Text.h"
 
 #include "gfxContext.h"
 #include "nsFontMetrics.h"
 #include "nsGkAtoms.h"
 #include "nsPresContext.h"
 #include "nsBidiUtils.h"
 #include "nsCSSFrameConstructor.h"
@@ -484,17 +485,17 @@ static bool IsBidiLeaf(nsIFrame* aFrame)
  * @param aParent the first parent frame to be split
  * @param aFrame the child frames after this frame are reparented to the
  *        newly-created continuation of aParent.
  *        If aFrame is null, all the children of aParent are reparented.
  */
 static nsresult SplitInlineAncestors(nsContainerFrame* aParent,
                                      nsIFrame* aFrame) {
   nsPresContext* presContext = aParent->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   nsIFrame* frame = aFrame;
   nsContainerFrame* parent = aParent;
   nsContainerFrame* newParent;
 
   while (IsBidiSplittable(parent)) {
     nsContainerFrame* grandparent = parent->GetParent();
     NS_ASSERTION(grandparent,
                  "Couldn't get parent's parent in "
@@ -574,17 +575,17 @@ static void JoinInlineAncestors(nsIFrame
 static nsresult CreateContinuation(nsIFrame* aFrame, nsIFrame** aNewFrame,
                                    bool aIsFluid) {
   MOZ_ASSERT(aNewFrame, "null OUT ptr");
   MOZ_ASSERT(aFrame, "null ptr");
 
   *aNewFrame = nullptr;
 
   nsPresContext* presContext = aFrame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   NS_ASSERTION(presShell,
                "PresShell must be set on PresContext before calling "
                "nsBidiPresUtils::CreateContinuation");
 
   nsContainerFrame* parent = aFrame->GetParent();
   NS_ASSERTION(
       parent,
       "Couldn't get frame parent in nsBidiPresUtils::CreateContinuation");
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2744,33 +2744,33 @@ nsDocumentViewer::GetEffectiveTextZoom(f
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetFullZoom(float aFullZoom) {
 #ifdef NS_PRINT_PREVIEW
   if (GetIsPrintPreview()) {
     nsPresContext* pc = GetPresContext();
     NS_ENSURE_TRUE(pc, NS_OK);
-    nsCOMPtr<nsIPresShell> shell = pc->GetPresShell();
-    NS_ENSURE_TRUE(shell, NS_OK);
+    PresShell* presShell = pc->GetPresShell();
+    NS_ENSURE_TRUE(presShell, NS_OK);
 
     if (!mPrintPreviewZoomed) {
       mOriginalPrintPreviewScale = pc->GetPrintPreviewScale();
       mPrintPreviewZoomed = true;
     }
 
     mPrintPreviewZoom = aFullZoom;
     pc->SetPrintPreviewScale(aFullZoom * mOriginalPrintPreviewScale);
-    nsIPageSequenceFrame* pf = shell->GetPageSequenceFrame();
+    nsIPageSequenceFrame* pf = presShell->GetPageSequenceFrame();
     if (pf) {
       nsIFrame* f = do_QueryFrame(pf);
-      shell->FrameNeedsReflow(f, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
+      presShell->FrameNeedsReflow(f, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
     }
 
-    nsIFrame* rootFrame = shell->GetRootFrame();
+    nsIFrame* rootFrame = presShell->GetRootFrame();
     if (rootFrame) {
       rootFrame->InvalidateFrame();
     }
     return NS_OK;
   }
 #endif
 
   // If we don't have a document, then we need to bail.
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -819,17 +819,17 @@ static nsRect GetDisplayPortFromMarginsD
   //   render (it chooses that in FrameLayerBuilder, but this can be called
   //   during display list building). Therefore, we perform the alignment in
   //   Screen space, which basically assumes that Layout chose to render at
   //   screen resolution; since this is what Layout does most of the time,
   //   this is a good approximation. A proper solution would involve moving
   //   the choosing of the resolution to display-list building time.
   ScreenSize alignment;
 
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   MOZ_ASSERT(presShell);
 
   if (presShell->IsDisplayportSuppressed()) {
     alignment = ScreenSize(1, 1);
   } else if (gfxPrefs::LayersTilesEnabled()) {
     // Don't align to tiles if they are too large, because we could expand
     // the displayport by a lot which can take more paint time. It's a tradeoff
     // though because if we don't align to tiles we have more waste on upload.
@@ -1042,17 +1042,17 @@ static bool GetDisplayPortImpl(
   }
 
   bool isDisplayportSuppressed = false;
 
   nsIFrame* frame = aContent->GetPrimaryFrame();
   if (frame) {
     nsPresContext* presContext = frame->PresContext();
     MOZ_ASSERT(presContext);
-    nsIPresShell* presShell = presContext->PresShell();
+    PresShell* presShell = presContext->PresShell();
     MOZ_ASSERT(presShell);
     isDisplayportSuppressed = presShell->IsDisplayportSuppressed();
   }
 
   nsRect result;
   if (rectData) {
     result = GetDisplayPortFromRectData(aContent, rectData, aMultiplier);
   } else if (isDisplayportSuppressed ||
@@ -3133,17 +3133,17 @@ FrameMetrics nsLayoutUtils::CalculateBas
   nsIFrame* frame = do_QueryFrame(aScrollFrame);
   MOZ_ASSERT(frame);
 
   // Calculate the metrics necessary for calculating the displayport.
   // This code has a lot in common with the code in ComputeFrameMetrics();
   // we may want to refactor this at some point.
   FrameMetrics metrics;
   nsPresContext* presContext = frame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   CSSToLayoutDeviceScale deviceScale = presContext->CSSToDevPixelScale();
   float resolution = 1.0f;
   if (frame == presShell->GetRootScrollFrame()) {
     // Only the root scrollable frame for a given presShell should pick up
     // the presShell's resolution. All the other frames are 1.0.
     resolution = presShell->GetResolution();
   }
   // Note: unlike in ComputeFrameMetrics(), we don't know the full cumulative
@@ -3201,17 +3201,17 @@ bool nsLayoutUtils::CalculateAndSetDispl
   nsIFrame* frame = do_QueryFrame(aScrollFrame);
   MOZ_ASSERT(frame);
   nsIContent* content = frame->GetContent();
   MOZ_ASSERT(content);
 
   FrameMetrics metrics = CalculateBasicFrameMetrics(aScrollFrame);
   ScreenMargin displayportMargins =
       apz::CalculatePendingDisplayPort(metrics, ParentLayerPoint(0.0f, 0.0f));
-  nsIPresShell* presShell = frame->PresContext()->GetPresShell();
+  PresShell* presShell = frame->PresContext()->GetPresShell();
   return nsLayoutUtils::SetDisplayPortMargins(
       content, presShell, displayportMargins, 0, aRepaintMode);
 }
 
 bool nsLayoutUtils::MaybeCreateDisplayPort(nsDisplayListBuilder& aBuilder,
                                            nsIFrame* aScrollFrame,
                                            RepaintMode aRepaintMode) {
   nsIContent* content = aScrollFrame->GetContent();
@@ -3358,17 +3358,17 @@ void nsLayoutUtils::ExpireDisplayPortOnA
 void nsLayoutUtils::AddExtraBackgroundItems(nsDisplayListBuilder& aBuilder,
                                             nsDisplayList& aList,
                                             nsIFrame* aFrame,
                                             const nsRect& aCanvasArea,
                                             const nsRegion& aVisibleRegion,
                                             nscolor aBackstop) {
   LayoutFrameType frameType = aFrame->Type();
   nsPresContext* presContext = aFrame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
 
   // For the viewport frame in print preview/page layout we want to paint
   // the grey background behind the page, not the canvas color.
   if (frameType == LayoutFrameType::Viewport &&
       nsLayoutUtils::NeedsPrintPreviewBackground(presContext)) {
     nsRect bounds =
         nsRect(aBuilder.ToReferenceFrame(aFrame), aFrame->GetSize());
     nsDisplayListBuilder::AutoBuildingDisplayList buildingDisplayList(
@@ -3492,17 +3492,17 @@ nsresult nsLayoutUtils::PaintFrame(gfxCo
     nsView* view = aFrame->GetView();
     if (!(view && view->GetWidget() && GetDisplayRootFrame(aFrame) == aFrame)) {
       aFlags &= ~PaintFrameFlags::PAINT_WIDGET_LAYERS;
       NS_ASSERTION(aRenderingContext, "need a rendering context");
     }
   }
 
   nsPresContext* presContext = aFrame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   nsRootPresContext* rootPresContext = presContext->GetRootPresContext();
   if (!rootPresContext) {
     return NS_OK;
   }
 
   TimeStamp startBuildDisplayList = TimeStamp::Now();
 
   const bool buildCaret = !(aFlags & PaintFrameFlags::PAINT_HIDE_CARET);
@@ -8015,17 +8015,17 @@ nsUnsetAttrRunnable::Run() {
 /**
  * Compute the minimum font size inside of a container with the given
  * width, such that **when the user zooms the container to fill the full
  * width of the device**, the fonts satisfy our minima.
  */
 static nscoord MinimumFontSizeFor(nsPresContext* aPresContext,
                                   WritingMode aWritingMode,
                                   nscoord aContainerISize) {
-  nsIPresShell* presShell = aPresContext->PresShell();
+  PresShell* presShell = aPresContext->PresShell();
 
   uint32_t emPerLine = presShell->FontSizeInflationEmPerLine();
   uint32_t minTwips = presShell->FontSizeInflationMinTwips();
   if (emPerLine == 0 && minTwips == 0) {
     return 0;
   }
 
   nscoord byLine = 0, byInch = 0;
@@ -8202,22 +8202,20 @@ float nsLayoutUtils::FontSizeInflationFo
     return 1.0f;
   }
 
   return FontSizeInflationInner(aFrame, InflationMinFontSizeFor(aFrame));
 }
 
 /* static */
 bool nsLayoutUtils::FontSizeInflationEnabled(nsPresContext* aPresContext) {
-  nsIPresShell* presShell = aPresContext->GetPresShell();
-
+  PresShell* presShell = aPresContext->GetPresShell();
   if (!presShell) {
     return false;
   }
-
   return presShell->FontSizeInflationEnabled();
 }
 
 /* static */
 nsRect nsLayoutUtils::GetBoxShadowRectForFrame(nsIFrame* aFrame,
                                                const nsSize& aFrameSize) {
   nsCSSShadowArray* boxShadows = aFrame->StyleEffects()->mBoxShadow;
   if (!boxShadows) {
@@ -8323,17 +8321,17 @@ static bool UpdateCompositionBoundsForRC
 
 /* static */
 nsMargin nsLayoutUtils::ScrollbarAreaToExcludeFromCompositionBoundsFor(
     nsIFrame* aScrollFrame) {
   if (!aScrollFrame || !aScrollFrame->GetScrollTargetFrame()) {
     return nsMargin();
   }
   nsPresContext* presContext = aScrollFrame->PresContext();
-  nsIPresShell* presShell = presContext->GetPresShell();
+  PresShell* presShell = presContext->GetPresShell();
   if (!presShell) {
     return nsMargin();
   }
   bool isRootScrollFrame = aScrollFrame == presShell->GetRootScrollFrame();
   bool isRootContentDocRootScrollFrame =
       isRootScrollFrame && presContext->IsRootContentDocument();
   if (!isRootContentDocRootScrollFrame) {
     return nsMargin();
@@ -8355,17 +8353,17 @@ nsSize nsLayoutUtils::CalculateCompositi
   // scroll port. The scroll port excludes the frame borders and the scroll
   // bars, which we don't want to be part of the composition bounds.
   nsIScrollableFrame* scrollableFrame = aFrame->GetScrollTargetFrame();
   nsRect rect = scrollableFrame ? scrollableFrame->GetScrollPortRect()
                                 : aFrame->GetRect();
   nsSize size = rect.Size();
 
   nsPresContext* presContext = aFrame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
 
   bool isRootContentDocRootScrollFrame =
       presContext->IsRootContentDocument() &&
       aFrame == presShell->GetRootScrollFrame();
   if (isRootContentDocRootScrollFrame) {
     ParentLayerRect compBounds;
     if (UpdateCompositionBoundsForRCDRSF(compBounds, presContext, false)) {
       int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
@@ -8395,17 +8393,17 @@ CSSSize nsLayoutUtils::CalculateRootComp
   }
   nsPresContext* presContext = aFrame->PresContext();
   ScreenSize rootCompositionSize;
   nsPresContext* rootPresContext =
       presContext->GetToplevelContentDocumentPresContext();
   if (!rootPresContext) {
     rootPresContext = presContext->GetRootPresContext();
   }
-  nsIPresShell* rootPresShell = nullptr;
+  PresShell* rootPresShell = nullptr;
   if (rootPresContext) {
     rootPresShell = rootPresContext->PresShell();
     if (nsIFrame* rootFrame = rootPresShell->GetRootFrame()) {
       LayoutDeviceToLayerScale2D cumulativeResolution(
           rootPresShell->GetCumulativeResolution() *
           nsLayoutUtils::GetTransformToAncestorScale(rootFrame));
       ParentLayerRect compBounds;
       if (UpdateCompositionBoundsForRCDRSF(compBounds, rootPresContext, true)) {
@@ -8699,17 +8697,17 @@ bool nsLayoutUtils::HasDocumentLevelList
     }
   }
   return false;
 }
 
 static void MaybeReflowForInflationScreenSizeChange(
     nsPresContext* aPresContext) {
   if (aPresContext) {
-    nsIPresShell* presShell = aPresContext->GetPresShell();
+    PresShell* presShell = aPresContext->GetPresShell();
     const bool fontInflationWasEnabled = presShell->FontSizeInflationEnabled();
     presShell->RecomputeFontSizeInflationEnabled();
     bool changed = false;
     if (presShell->FontSizeInflationEnabled() &&
         presShell->FontSizeInflationMinTwips() != 0) {
       aPresContext->ScreenSizeInchesForFontInflation(&changed);
     }
 
@@ -8769,17 +8767,17 @@ ScrollMetadata nsLayoutUtils::ComputeScr
     nsIFrame* aForFrame, nsIFrame* aScrollFrame, nsIContent* aContent,
     const nsIFrame* aReferenceFrame, LayerManager* aLayerManager,
     ViewID aScrollParentId, const nsRect& aViewport,
     const Maybe<nsRect>& aClipRect, bool aIsRootContent,
     const Maybe<ContainerLayerParameters>& aContainerParameters) {
   nsPresContext* presContext = aForFrame->PresContext();
   int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
 
-  nsIPresShell* presShell = presContext->GetPresShell();
+  PresShell* presShell = presContext->GetPresShell();
   ScrollMetadata metadata;
   FrameMetrics& metrics = metadata.GetMetrics();
   metrics.SetLayoutViewport(CSSRect::FromAppUnits(aViewport));
 
   ViewID scrollId = ScrollableLayerGuid::NULL_SCROLL_ID;
   if (aContent) {
     if (void* paintRequestTime =
             aContent->GetProperty(nsGkAtoms::paintRequestTime)) {
@@ -9108,17 +9106,17 @@ ScrollMetadata nsLayoutUtils::ComputeScr
 
 /*static*/
 Maybe<ScrollMetadata> nsLayoutUtils::GetRootMetadata(
     nsDisplayListBuilder* aBuilder, LayerManager* aLayerManager,
     const ContainerLayerParameters& aContainerParameters,
     const std::function<bool(ViewID& aScrollId)>& aCallback) {
   nsIFrame* frame = aBuilder->RootReferenceFrame();
   nsPresContext* presContext = frame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   Document* document = presShell->GetDocument();
 
   // If we're using containerless scrolling, there is still one case where we
   // want the root container layer to have metrics. If the parent process is
   // using XUL windows, there is no root scrollframe, and without explicitly
   // creating metrics there will be no guaranteed top-level APZC.
   bool addMetrics = gfxPrefs::LayoutUseContainersForRootFrames() ||
                     (XRE_IsParentProcess() && !presShell->GetRootScrollFrame());
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -136,17 +136,17 @@ void nsPresContext::ForceReflowForFontIn
 }
 
 static bool IsVisualCharset(NotNull<const Encoding*> aCharset) {
   return aCharset == ISO_8859_8_ENCODING;
 }
 
 nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
     : mType(aType),
-      mShell(nullptr),
+      mPresShell(nullptr),
       mDocument(aDocument),
       mMedium(aType == eContext_Galley ? nsGkAtoms::screen : nsGkAtoms::print),
       mMediaEmulated(mMedium),
       mLinkHandler(nullptr),
       mInflationDisabledForShrinkWrap(false),
       mSystemFontScale(1.0),
       mTextZoom(1.0),
       mEffectiveTextZoom(1.0),
@@ -265,18 +265,18 @@ void nsPresContext::Destroy() {
   Preferences::UnregisterCallbacks(
       PREF_CHANGE_METHOD(nsPresContext::PreferenceChanged), gExactCallbackPrefs,
       this);
 
   mRefreshDriver = nullptr;
 }
 
 nsPresContext::~nsPresContext() {
-  MOZ_ASSERT(!mShell, "Presshell forgot to clear our mShell pointer");
-  DetachShell();
+  MOZ_ASSERT(!mPresShell, "Presshell forgot to clear our mPresShell pointer");
+  DetachPresShell();
 
   Destroy();
 }
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPresContext)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
@@ -395,18 +395,20 @@ void nsPresContext::GetUserPreferences()
 
   // We don't need to force reflow: either we are initializing a new
   // prescontext or we are being called from UpdateAfterPreferencesChanged()
   // which triggers a reflow anyway.
   SetBidi(bidiOptions);
 }
 
 void nsPresContext::InvalidatePaintedLayers() {
-  if (!mShell) return;
-  if (nsIFrame* rootFrame = mShell->GetRootFrame()) {
+  if (!mPresShell) {
+    return;
+  }
+  if (nsIFrame* rootFrame = mPresShell->GetRootFrame()) {
     // FrameLayerBuilder caches invalidation-related values that depend on the
     // appunits-per-dev-pixel ratio, so ensure that all PaintedLayer drawing
     // is completely flushed.
     rootFrame->InvalidateFrameSubtree();
   }
 }
 
 void nsPresContext::AppUnitsPerDevPixelChanged() {
@@ -423,18 +425,18 @@ void nsPresContext::AppUnitsPerDevPixelC
                              MediaFeatureChangeReason::ResolutionChange});
 
   mCurAppUnitsPerDevPixel = mDeviceContext->AppUnitsPerDevPixel();
 
   // nsSubDocumentFrame uses a AppUnitsPerDevPixel difference between parent and
   // child document to determine if it needs to build a nsDisplayZoom item. So
   // if we that changes then we need to invalidate the subdoc frame so that
   // item gets created/removed.
-  if (mShell) {
-    if (nsIFrame* frame = mShell->GetRootFrame()) {
+  if (mPresShell) {
+    if (nsIFrame* frame = mPresShell->GetRootFrame()) {
       frame = nsLayoutUtils::GetCrossDocParentFrame(frame);
       if (frame) {
         int32_t parentAPD = frame->PresContext()->AppUnitsPerDevPixel();
         if ((parentAPD == oldAppUnitsPerDevPixel) !=
             (parentAPD == mCurAppUnitsPerDevPixel)) {
           frame->InvalidateFrame();
         }
       }
@@ -446,22 +448,22 @@ void nsPresContext::AppUnitsPerDevPixelC
   // would invalidate all subdocument frames already.
 }
 
 void nsPresContext::PreferenceChanged(const char* aPrefName) {
   nsDependentCString prefName(aPrefName);
   if (prefName.EqualsLiteral("layout.css.dpi") ||
       prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
     int32_t oldAppUnitsPerDevPixel = mDeviceContext->AppUnitsPerDevPixel();
-    if (mDeviceContext->CheckDPIChange() && mShell) {
-      nsCOMPtr<nsIPresShell> shell = mShell;
+    if (mDeviceContext->CheckDPIChange() && mPresShell) {
+      OwningNonNull<mozilla::PresShell> presShell(*mPresShell);
       // Re-fetch the view manager's window dimensions in case there's a
       // deferred resize which hasn't affected our mVisibleArea yet
       nscoord oldWidthAppUnits, oldHeightAppUnits;
-      RefPtr<nsViewManager> vm = shell->GetViewManager();
+      RefPtr<nsViewManager> vm = presShell->GetViewManager();
       if (!vm) {
         return;
       }
       vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
       float oldWidthDevPixels = oldWidthAppUnits / oldAppUnitsPerDevPixel;
       float oldHeightDevPixels = oldHeightAppUnits / oldAppUnitsPerDevPixel;
 
       AppUnitsPerDevPixelChanged();
@@ -539,33 +541,33 @@ void nsPresContext::DispatchPrefChangedR
   nsresult rv = Document()->Dispatch(TaskCategory::Other, runnable.forget());
   if (NS_SUCCEEDED(rv)) {
     mPostedPrefChangedRunnable = true;
   }
 }
 
 void nsPresContext::UpdateAfterPreferencesChanged() {
   mPostedPrefChangedRunnable = false;
-  if (!mShell) {
+  if (!mPresShell) {
     return;
   }
 
   if (mDocument->IsInChromeDocShell()) {
     // FIXME(emilio): Do really all these prefs not affect chrome docs? I
     // suspect we should move this check somewhere else.
     return;
   }
 
   StaticPresData::Get()->InvalidateFontPrefs();
 
   // Initialize our state from the user preferences
   GetUserPreferences();
 
   // update the presShell: tell it to set the preference style rules up
-  mShell->UpdatePreferenceStyles();
+  mPresShell->UpdatePreferenceStyles();
 
   InvalidatePaintedLayers();
   mDeviceContext->FlushFontCache();
 
   nsChangeHint hint = nsChangeHint(0);
 
   if (mPrefChangePendingNeedsReflow) {
     hint |= NS_STYLE_HINT_REFLOW;
@@ -662,28 +664,28 @@ nsresult nsPresContext::Init(nsDeviceCon
   mInitialized = true;
 #endif
 
   return NS_OK;
 }
 
 // Note: We don't hold a reference on the shell; it has a reference to
 // us
-void nsPresContext::AttachShell(nsIPresShell* aShell) {
-  MOZ_ASSERT(!mShell);
-  mShell = aShell;
+void nsPresContext::AttachPresShell(mozilla::PresShell* aPresShell) {
+  MOZ_ASSERT(!mPresShell);
+  mPresShell = aPresShell;
 
   mRestyleManager = MakeUnique<mozilla::RestyleManager>(this);
 
   // Since CounterStyleManager is also the name of a method of
   // nsPresContext, it is necessary to prefix the class with the mozilla
   // namespace here.
   mCounterStyleManager = new mozilla::CounterStyleManager(this);
 
-  dom::Document* doc = mShell->GetDocument();
+  dom::Document* doc = mPresShell->GetDocument();
   MOZ_ASSERT(doc);
   // Have to update PresContext's mDocument before calling any other methods.
   mDocument = doc;
   // Initialize our state from the user preferences, now that we
   // have a presshell, and hence a document.
   GetUserPreferences();
 
   nsIURI* docURI = doc->GetDocumentURI();
@@ -698,29 +700,29 @@ void nsPresContext::AttachShell(nsIPresS
       mImageAnimationMode = mImageAnimationModePref;
     else
       mImageAnimationMode = imgIContainer::kNormalAnimMode;
   }
 
   UpdateCharSet(doc->GetDocumentCharacterSet());
 }
 
-void nsPresContext::DetachShell() {
+void nsPresContext::DetachPresShell() {
   // The counter style manager's destructor needs to deallocate with the
   // presshell arena. Disconnect it before nulling out the shell.
   //
   // XXXbholley: Given recent refactorings, it probably makes more sense to
-  // just null our mShell at the bottom of this function. I'm leaving it
+  // just null our mPresShell at the bottom of this function. I'm leaving it
   // this way to preserve the old ordering, but I doubt anything would break.
   if (mCounterStyleManager) {
     mCounterStyleManager->Disconnect();
     mCounterStyleManager = nullptr;
   }
 
-  mShell = nullptr;
+  mPresShell = nullptr;
 
   if (mAnimationEventDispatcher) {
     mAnimationEventDispatcher->Disconnect();
     mAnimationEventDispatcher = nullptr;
   }
   if (mEffectCompositor) {
     mEffectCompositor->Disconnect();
     mEffectCompositor = nullptr;
@@ -780,19 +782,19 @@ void nsPresContext::UpdateCharSet(NotNul
 }
 
 void nsPresContext::DispatchCharSetChange(NotNull<const Encoding*> aEncoding) {
   // In Servo RebuildAllStyleData is async, so no need to do the runnable dance.
   DoChangeCharSet(aEncoding);
 }
 
 nsPresContext* nsPresContext::GetParentPresContext() {
-  nsIPresShell* shell = GetPresShell();
-  if (shell) {
-    nsViewManager* viewManager = shell->GetViewManager();
+  mozilla::PresShell* presShell = GetPresShell();
+  if (presShell) {
+    nsViewManager* viewManager = presShell->GetViewManager();
     if (viewManager) {
       nsView* view = viewManager->GetRootView();
       if (view) {
         view = view->GetParent();  // anonymous inner view
         if (view) {
           view = view->GetParent();  // subdocumentframe's view
           if (view) {
             nsIFrame* f = view->GetFrame();
@@ -813,25 +815,25 @@ nsPresContext* nsPresContext::GetTopleve
   for (;;) {
     nsPresContext* parent = pc->GetParentPresContext();
     if (!parent || parent->IsChrome()) return pc;
     pc = parent;
   }
 }
 
 nsIWidget* nsPresContext::GetNearestWidget(nsPoint* aOffset) {
-  NS_ENSURE_TRUE(mShell, nullptr);
-  nsIFrame* frame = mShell->GetRootFrame();
+  NS_ENSURE_TRUE(mPresShell, nullptr);
+  nsIFrame* frame = mPresShell->GetRootFrame();
   NS_ENSURE_TRUE(frame, nullptr);
   return frame->GetView()->GetNearestWidget(aOffset);
 }
 
 nsIWidget* nsPresContext::GetRootWidget() {
-  NS_ENSURE_TRUE(mShell, nullptr);
-  nsViewManager* vm = mShell->GetViewManager();
+  NS_ENSURE_TRUE(mPresShell, nullptr);
+  nsViewManager* vm = mPresShell->GetViewManager();
   if (!vm) {
     return nullptr;
   }
   nsCOMPtr<nsIWidget> widget;
   vm->GetRootWidget(getter_AddRefs(widget));
   return widget.get();
 }
 
@@ -903,18 +905,18 @@ void nsPresContext::SetImageAnimationMod
                    aMode == imgIContainer::kLoopOnceAnimMode,
                "Wrong Animation Mode is being set!");
 
   // Image animation mode cannot be changed when rendering to a printer.
   if (!IsDynamic()) return;
 
   // Now walk the content tree and set the animation mode
   // on all the images.
-  if (mShell != nullptr) {
-    dom::Document* doc = mShell->GetDocument();
+  if (mPresShell) {
+    dom::Document* doc = mPresShell->GetDocument();
     if (doc) {
       doc->StyleImageLoader()->SetAnimationMode(aMode);
 
       Element* rootElement = doc->GetRootElement();
       if (rootElement) {
         SetImgAnimations(rootElement, aMode);
       }
       SetSMILAnimations(doc, aMode, mImageAnimationMode);
@@ -944,38 +946,38 @@ void nsPresContext::UpdateEffectiveTextZ
                              MediaFeatureChangeReason::ZoomChange});
 }
 
 float nsPresContext::GetDeviceFullZoom() {
   return mDeviceContext->GetFullZoom();
 }
 
 void nsPresContext::SetFullZoom(float aZoom) {
-  if (!mShell || mFullZoom == aZoom) {
+  if (!mPresShell || mFullZoom == aZoom) {
     return;
   }
 
   // Re-fetch the view manager's window dimensions in case there's a deferred
   // resize which hasn't affected our mVisibleArea yet
   nscoord oldWidthAppUnits, oldHeightAppUnits;
-  mShell->GetViewManager()->GetWindowDimensions(&oldWidthAppUnits,
-                                                &oldHeightAppUnits);
+  mPresShell->GetViewManager()->GetWindowDimensions(&oldWidthAppUnits,
+                                                    &oldHeightAppUnits);
   float oldWidthDevPixels = oldWidthAppUnits / float(mCurAppUnitsPerDevPixel);
   float oldHeightDevPixels = oldHeightAppUnits / float(mCurAppUnitsPerDevPixel);
   mDeviceContext->SetFullZoom(aZoom);
 
   NS_ASSERTION(!mSuppressResizeReflow,
                "two zooms happening at the same time? impossible!");
   mSuppressResizeReflow = true;
 
   mFullZoom = aZoom;
 
   AppUnitsPerDevPixelChanged();
 
-  mShell->GetViewManager()->SetWindowDimensions(
+  mPresShell->GetViewManager()->SetWindowDimensions(
       NSToCoordRound(oldWidthDevPixels * AppUnitsPerDevPixel()),
       NSToCoordRound(oldHeightDevPixels * AppUnitsPerDevPixel()));
 
   mSuppressResizeReflow = false;
 }
 
 void nsPresContext::SetOverrideDPPX(float aDPPX) {
   // SetOverrideDPPX is called during navigations, including history
@@ -1427,17 +1429,17 @@ void nsPresContext::UIResolutionChangedI
 void nsPresContext::EmulateMedium(const nsAString& aMediaType) {
   nsAtom* previousMedium = Medium();
   mIsEmulatingMedia = true;
 
   nsAutoString mediaType;
   nsContentUtils::ASCIIToLower(aMediaType, mediaType);
 
   mMediaEmulated = NS_Atomize(mediaType);
-  if (mMediaEmulated != previousMedium && mShell) {
+  if (mMediaEmulated != previousMedium && mPresShell) {
     MediaFeatureValuesChanged({MediaFeatureChangeReason::MediumChange});
   }
 }
 
 void nsPresContext::StopEmulatingMedium() {
   nsAtom* previousMedium = Medium();
   mIsEmulatingMedia = false;
   if (Medium() != previousMedium) {
@@ -1447,31 +1449,31 @@ void nsPresContext::StopEmulatingMedium(
 
 void nsPresContext::ContentLanguageChanged() {
   PostRebuildAllStyleDataEvent(nsChangeHint(0),
                                RestyleHint::RecascadeSubtree());
 }
 
 void nsPresContext::MediaFeatureValuesChanged(
     const MediaFeatureChange& aChange) {
-  if (mShell) {
-    mShell->EnsureStyleFlush();
+  if (mPresShell) {
+    mPresShell->EnsureStyleFlush();
   }
 
   if (!mPendingMediaFeatureValuesChange) {
     mPendingMediaFeatureValuesChange.emplace(aChange);
     return;
   }
 
   *mPendingMediaFeatureValuesChange |= aChange;
 }
 
 void nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint,
                                         RestyleHint aRestyleHint) {
-  if (!mShell) {
+  if (!mPresShell) {
     // We must have been torn down. Nothing to do here.
     return;
   }
 
   // FIXME(emilio): Why is it safe to reset mUsesRootEMUnits / mUsesEXChUnits
   // here if there's no restyle hint? That looks pretty bogus.
   mUsesRootEMUnits = false;
   mUsesExChUnits = false;
@@ -1486,17 +1488,17 @@ void nsPresContext::RebuildAllStyleData(
   MarkCounterStylesDirty();
   MarkFontFeatureValuesDirty();
 
   RestyleManager()->RebuildAllStyleData(aExtraHint, aRestyleHint);
 }
 
 void nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
                                                  RestyleHint aRestyleHint) {
-  if (!mShell) {
+  if (!mPresShell) {
     // We must have been torn down. Nothing to do here.
     return;
   }
   RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
 }
 
 static bool MediaFeatureValuesChangedAllDocumentsCallback(Document* aDocument,
                                                           void* aChange) {
@@ -1519,26 +1521,26 @@ void nsPresContext::FlushPendingMediaFea
   if (!mPendingMediaFeatureValuesChange) {
     return;
   }
 
   MediaFeatureChange change = *mPendingMediaFeatureValuesChange;
   mPendingMediaFeatureValuesChange.reset();
 
   // MediumFeaturesChanged updates the applied rules, so it always gets called.
-  if (mShell) {
+  if (mPresShell) {
     change.mRestyleHint |=
-        mShell->StyleSet()->MediumFeaturesChanged(change.mReason);
+        mPresShell->StyleSet()->MediumFeaturesChanged(change.mReason);
   }
 
   if (change.mRestyleHint || change.mChangeHint) {
     RebuildAllStyleData(change.mChangeHint, change.mRestyleHint);
   }
 
-  if (!mShell || !mShell->DidInitialize()) {
+  if (!mPresShell || !mPresShell->DidInitialize()) {
     return;
   }
 
   if (mDocument->IsBeingUsedAsImage()) {
     MOZ_ASSERT(mDocument->MediaQueryLists().isEmpty());
     return;
   }
 
@@ -1616,18 +1618,18 @@ bool nsPresContext::EnsureVisible() {
   }
   // OK, this is us.  We want to call Show() on the content viewer.
   nsresult result = cv->Show();
   return NS_SUCCEEDED(result);
 }
 
 #ifdef MOZ_REFLOW_PERF
 void nsPresContext::CountReflows(const char* aName, nsIFrame* aFrame) {
-  if (mShell) {
-    mShell->CountReflows(aName, aFrame);
+  if (mPresShell) {
+    mPresShell->CountReflows(aName, aFrame);
   }
 }
 #endif
 
 bool nsPresContext::HasAuthorSpecifiedRules(const nsIFrame* aFrame,
                                             uint32_t aRuleTypeMask) const {
   Element* elem = aFrame->GetContent()->AsElement();
 
@@ -1653,17 +1655,19 @@ bool nsPresContext::HasAuthorSpecifiedRu
                                        aRuleTypeMask);
 }
 
 gfxUserFontSet* nsPresContext::GetUserFontSet() {
   return mDocument->GetUserFontSet();
 }
 
 void nsPresContext::UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont) {
-  if (!mShell) return;
+  if (!mPresShell) {
+    return;
+  }
 
   // Note: this method is called without a font when rules in the userfont set
   // are updated.
   //
   // We can avoid a full restyle if font-metric-dependent units are not in use,
   // since we know there's no style resolution that would depend on this font
   // and trigger its load.
   //
@@ -1677,17 +1681,17 @@ void nsPresContext::UserFontSetUpdated(g
   }
 
   // Iterate over the frame tree looking for frames associated with the
   // downloadable font family in question. If a frame's nsStyleFont has
   // the name, check the font group associated with the metrics to see if
   // it contains that specific font (i.e. the one chosen within the family
   // given the weight, width, and slant from the nsStyleFont). If it does,
   // mark that frame dirty and skip inspecting its descendants.
-  if (nsIFrame* root = mShell->GetRootFrame()) {
+  if (nsIFrame* root = mPresShell->GetRootFrame()) {
     nsFontFaceUtils::MarkDirtyForFontChange(root, aUpdatedFont);
   }
 }
 
 class CounterStyleCleaner final : public nsAPostRefreshObserver {
  public:
   CounterStyleCleaner(nsRefreshDriver* aRefreshDriver,
                       CounterStyleManager* aCounterStyleManager)
@@ -1702,17 +1706,17 @@ class CounterStyleCleaner final : public
   }
 
  private:
   RefPtr<nsRefreshDriver> mRefreshDriver;
   RefPtr<CounterStyleManager> mCounterStyleManager;
 };
 
 void nsPresContext::FlushCounterStyles() {
-  if (!mShell) {
+  if (!mPresShell) {
     return;  // we've been torn down
   }
   if (mCounterStyleManager->IsInitial()) {
     // Still in its initial state, no need to clean.
     return;
   }
 
   if (mCounterStylesDirty) {
@@ -1738,17 +1742,17 @@ void nsPresContext::MarkCounterStylesDir
 
 void nsPresContext::NotifyMissingFonts() {
   if (mMissingFonts) {
     mMissingFonts->Flush();
   }
 }
 
 void nsPresContext::EnsureSafeToHandOutCSSRules() {
-  if (!mShell->StyleSet()->EnsureUniqueInnerOnCSSSheets()) {
+  if (!mPresShell->StyleSet()->EnsureUniqueInnerOnCSSSheets()) {
     // Nothing to do.
     return;
   }
 
   RebuildAllStyleData(nsChangeHint(0), RestyleHint::RestyleSubtree());
 }
 
 void nsPresContext::FireDOMPaintEvent(
@@ -2220,18 +2224,18 @@ bool nsPresContext::HavePendingInputEven
         }
       }
       return false;
     }
   }
 }
 
 bool nsPresContext::HasPendingRestyleOrReflow() {
-  nsIPresShell* shell = PresShell();
-  return shell->NeedStyleFlush() || shell->HasPendingReflow();
+  mozilla::PresShell* presShell = PresShell();
+  return presShell->NeedStyleFlush() || presShell->HasPendingReflow();
 }
 
 void nsPresContext::ReflowStarted(bool aInterruptible) {
 #ifdef NOISY_INTERRUPTIBLE_REFLOW
   if (!aInterruptible) {
     printf("STARTING NONINTERRUPTIBLE REFLOW\n");
   }
 #endif
@@ -2252,17 +2256,17 @@ void nsPresContext::ReflowStarted(bool a
 
   if (mInterruptsEnabled) {
     mReflowStartTime = TimeStamp::Now();
   }
 }
 
 bool nsPresContext::CheckForInterrupt(nsIFrame* aFrame) {
   if (mHasPendingInterrupt) {
-    mShell->FrameNeedsToContinueReflow(aFrame);
+    mPresShell->FrameNeedsToContinueReflow(aFrame);
     return true;
   }
 
   if (!sGotInterruptEnv) {
     sGotInterruptEnv = true;
     GetInterruptEnv();
   }
 
@@ -2286,17 +2290,17 @@ bool nsPresContext::CheckForInterrupt(ns
     mPendingInterruptFromTest = false;
     mHasPendingInterrupt = true;
   }
 
   if (mHasPendingInterrupt) {
 #ifdef NOISY_INTERRUPTIBLE_REFLOW
     printf("*** DETECTED pending interrupt (time=%lld)\n", PR_Now());
 #endif /* NOISY_INTERRUPTIBLE_REFLOW */
-    mShell->FrameNeedsToContinueReflow(aFrame);
+    mPresShell->FrameNeedsToContinueReflow(aFrame);
   }
   return mHasPendingInterrupt;
 }
 
 nsIFrame* nsPresContext::GetPrimaryFrameFor(nsIContent* aContent) {
   MOZ_ASSERT(aContent, "Don't do that");
   if (GetPresShell() &&
       GetPresShell()->GetDocument() == aContent->GetComposedDoc()) {
@@ -2358,17 +2362,17 @@ void nsPresContext::NotifyContentfulPain
         mFirstContentfulPaintTransactionId =
             Some(rootPresContext->mRefreshDriver->LastTransactionId().Next());
       }
     }
   }
 }
 
 void nsPresContext::NotifyDOMContentFlushed() {
-  NS_ENSURE_TRUE_VOID(mShell);
+  NS_ENSURE_TRUE_VOID(mPresShell);
   if (IsRootContentDocument()) {
     RefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
     if (timing) {
       timing->NotifyDOMContentFlushedForRootContentDocument();
     }
   }
 }
 
@@ -2422,33 +2426,33 @@ nsBidi& nsPresContext::GetBidiEngine() {
 
   if (!mBidiEngine) {
     mBidiEngine.reset(new nsBidi());
   }
   return *mBidiEngine;
 }
 
 void nsPresContext::FlushFontFeatureValues() {
-  if (!mShell) {
+  if (!mPresShell) {
     return;  // we've been torn down
   }
 
   if (mFontFeatureValuesDirty) {
-    ServoStyleSet* styleSet = mShell->StyleSet();
+    ServoStyleSet* styleSet = mPresShell->StyleSet();
     mFontFeatureValuesLookup = styleSet->BuildFontFeatureValueSet();
     mFontFeatureValuesDirty = false;
   }
 }
 
 #ifdef DEBUG
 
 void nsPresContext::ValidatePresShellAndDocumentReleation() const {
-  NS_ASSERTION(
-      !mShell || !mShell->GetDocument() || mShell->GetDocument() == mDocument,
-      "nsPresContext doesn't have the same document as nsPresShell!");
+  NS_ASSERTION(!mPresShell || !mPresShell->GetDocument() ||
+                   mPresShell->GetDocument() == mDocument,
+               "nsPresContext doesn't have the same document as nsPresShell!");
 }
 
 #endif  // #ifdef DEBUG
 
 nsRootPresContext::nsRootPresContext(dom::Document* aDocument,
                                      nsPresContextType aType)
     : nsPresContext(aDocument, aType) {}
 
@@ -2493,17 +2497,17 @@ void nsRootPresContext::ComputePluginGeo
       // f is not managed by this frame so we should ignore it.
       continue;
     }
     f->SetEmptyWidgetConfiguration();
   }
 
   if (aBuilder) {
     MOZ_ASSERT(aList);
-    nsIFrame* rootFrame = mShell->GetRootFrame();
+    nsIFrame* rootFrame = mPresShell->GetRootFrame();
 
     if (rootFrame && aBuilder->ContainsPluginItem()) {
       aBuilder->SetForPluginGeometry(true);
       // Merging and flattening has already been done and we should not do it
       // again. nsDisplayScroll(Info)Layer doesn't support trying to flatten
       // again.
       aBuilder->SetAllowMergingAndFlattening(false);
       nsRegion region = rootFrame->GetVisualOverflowRectRelativeToSelf();
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -43,17 +43,16 @@
 #include "Units.h"
 #include "prenv.h"
 #include "mozilla/StaticPresData.h"
 
 class nsBidi;
 class nsIPrintSettings;
 class nsDocShell;
 class nsIDocShell;
-class nsIPresShell;
 class nsITheme;
 class nsIContent;
 class nsIFrame;
 class nsFrameManager;
 class nsILinkHandler;
 class nsAtom;
 class nsIRunnable;
 class gfxFontFeatureValueSet;
@@ -73,16 +72,17 @@ class nsDeviceContext;
 class gfxMissingFontRecorder;
 
 namespace mozilla {
 class AnimationEventDispatcher;
 class EffectCompositor;
 class Encoding;
 class EventStateManager;
 class CounterStyleManager;
+class PresShell;
 class RestyleManager;
 namespace layers {
 class ContainerLayer;
 class LayerManager;
 }  // namespace layers
 namespace dom {
 class Document;
 class Element;
@@ -153,30 +153,30 @@ class nsPresContext : public nsISupports
    * Initialize the presentation context from a particular device.
    */
   nsresult Init(nsDeviceContext* aDeviceContext);
 
   /**
    * Set and detach presentation shell that this context is bound to.
    * A presentation context may only be bound to a single shell.
    */
-  void AttachShell(nsIPresShell* aShell);
-  void DetachShell();
+  void AttachPresShell(mozilla::PresShell* aPresShell);
+  void DetachPresShell();
 
   nsPresContextType Type() const { return mType; }
 
   /**
    * Get the PresentationShell that this context is bound to.
    */
-  nsIPresShell* PresShell() const {
-    NS_ASSERTION(mShell, "Null pres shell");
-    return mShell;
+  mozilla::PresShell* PresShell() const {
+    NS_ASSERTION(mPresShell, "Null pres shell");
+    return mPresShell;
   }
 
-  nsIPresShell* GetPresShell() const { return mShell; }
+  mozilla::PresShell* GetPresShell() const { return mPresShell; }
 
   void DispatchCharSetChange(NotNull<const Encoding*> aCharSet);
 
   /**
    * Returns the parent prescontext for this one. Returns null if this is a
    * root.
    */
   nsPresContext* GetParentPresContext();
@@ -1090,19 +1090,19 @@ class nsPresContext : public nsISupports
   };
   TransactionInvalidations* GetInvalidations(TransactionId aTransactionId);
 
   // IMPORTANT: The ownership implicit in the following member variables
   // has been explicitly checked.  If you add any members to this class,
   // please make the ownership explicit (pinkerton, scc).
 
   nsPresContextType mType;
-  // the nsPresShell owns a strong reference to the nsPresContext, and is
+  // the PresShell owns a strong reference to the nsPresContext, and is
   // responsible for nulling this pointer before it is destroyed
-  nsIPresShell* MOZ_NON_OWNING_REF mShell;  // [WEAK]
+  mozilla::PresShell* MOZ_NON_OWNING_REF mPresShell;  // [WEAK]
   RefPtr<mozilla::dom::Document> mDocument;
   RefPtr<nsDeviceContext> mDeviceContext;  // [STRONG] could be weak, but
                                            // better safe than sorry.
                                            // Cannot reintroduce cycles
                                            // since there is no dependency
                                            // from gfx back to layout.
   RefPtr<mozilla::EventStateManager> mEventManager;
   RefPtr<nsRefreshDriver> mRefreshDriver;
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -27,16 +27,17 @@
 #  include "WinUtils.h"
 #endif
 
 #include "mozilla/AnimationEventDispatcher.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/IntegerRange.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/FontTableURIProtocolHandler.h"
 #include "nsITimer.h"
 #include "nsLayoutUtils.h"
 #include "nsPresContext.h"
 #include "nsComponentManagerUtils.h"
 #include "mozilla/Logging.h"
 #include "mozilla/dom/Document.h"
 #include "nsIXULRuntime.h"
@@ -1770,17 +1771,17 @@ void nsRefreshDriver::Tick(VsyncId aId, 
 
   if (mRootRefresh) {
     mRootRefresh->RemoveRefreshObserver(this, FlushType::Style);
     mRootRefresh = nullptr;
   }
   mSkippedPaints = false;
   mWarningThreshold = 1;
 
-  nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
+  RefPtr<PresShell> presShell = mPresContext->GetPresShell();
   if (!presShell ||
       (!HasObservers() && !HasImageRequests() &&
        mVisualViewportResizeEvents.IsEmpty() && mScrollEvents.IsEmpty() &&
        mVisualViewportScrollEvents.IsEmpty())) {
     // Things are being destroyed, or we no longer have any observers.
     // We don't want to stop the timer when observers are initially
     // removed, because sometimes observers can be added and removed
     // often depending on what other things are going on and in that
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -15,17 +15,16 @@
 #include "nsCheckboxRadioFrame.h"
 #include "nsGkAtoms.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsHTMLParts.h"
 #include "nsIFormControl.h"
 #include "nsNameSpaceManager.h"
 #include "nsListControlFrame.h"
 #include "nsPIDOMWindow.h"
-#include "nsIPresShell.h"
 #include "mozilla/PresState.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsIContentInlines.h"
 #include "nsIDOMEventListener.h"
 #include "nsISelectControlFrame.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/Event.h"
@@ -41,16 +40,17 @@
 #include "nsStyleConsts.h"
 #include "mozilla/Likely.h"
 #include <algorithm>
 #include "nsTextNode.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Unused.h"
 #include "gfx2DGlue.h"
 #include "mozilla/widget/nsAutoRollup.h"
 #include "nsILayoutHistoryState.h"
 
 #ifdef XP_WIN
 #  define COMBOBOX_ROLLUP_CONSUME_EVENT 0
 #else
@@ -302,24 +302,24 @@ void nsComboboxControlFrame::ShowPopup(b
     viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
   } else {
     viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
     nsRect emptyRect(0, 0, 0, 0);
     viewManager->ResizeView(view, emptyRect);
   }
 
   // fire a popup dom event if it is safe to do so
-  nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
-  if (shell && nsContentUtils::IsSafeToRunScript()) {
+  RefPtr<mozilla::PresShell> presShell = PresContext()->GetPresShell();
+  if (presShell && nsContentUtils::IsSafeToRunScript()) {
     nsEventStatus status = nsEventStatus_eIgnore;
     WidgetMouseEvent event(true,
                            aShowPopup ? eXULPopupShowing : eXULPopupHiding,
                            nullptr, WidgetMouseEvent::eReal);
 
-    shell->HandleDOMEventWithTarget(mContent, &event, &status);
+    presShell->HandleDOMEventWithTarget(mContent, &event, &status);
   }
 }
 
 bool nsComboboxControlFrame::ShowList(bool aShowList) {
   nsView* view = mDropdownFrame->GetView();
   if (aShowList) {
     NS_ASSERTION(
         !view->HasWidget(),
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -18,26 +18,26 @@
 #include "nsTextFragment.h"
 #include "nsNameSpaceManager.h"
 #include "nsCheckboxRadioFrame.h"  //for registering accesskeys
 
 #include "nsIContent.h"
 #include "nsPresContext.h"
 #include "nsGkAtoms.h"
 #include "nsLayoutUtils.h"
-#include "nsIPresShell.h"
 
 #include <algorithm>
 #include "nsRange.h"  //for selection setting helper func
 #include "nsINode.h"
 #include "nsPIDOMWindow.h"  //needed for notify selection changed to update the menus ect.
 #include "nsQueryObject.h"
 #include "nsILayoutHistoryState.h"
 
 #include "nsFocusManager.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/PresState.h"
 #include "nsAttrValueInlines.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/TextEditRules.h"
 #include "nsContentUtils.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/dom/HTMLTextAreaElement.h"
@@ -704,17 +704,17 @@ void nsTextControlFrame::SetFocus(bool a
   }
 
   RefPtr<Selection> ourSel =
       selCon->GetSelection(nsISelectionController::SELECTION_NORMAL);
   if (!ourSel) {
     return;
   }
 
-  nsIPresShell* presShell = PresContext()->GetPresShell();
+  mozilla::PresShell* presShell = PresContext()->GetPresShell();
   RefPtr<nsCaret> caret = presShell->GetCaret();
   if (!caret) {
     return;
   }
 
   // Scroll the current selection into view
   Selection* caretSelection = caret->GetSelection();
   const bool isFocusedRightNow = ourSel == caretSelection;
@@ -740,19 +740,18 @@ void nsTextControlFrame::SetFocus(bool a
 
   // tell the caret to use our selection
   caret->SetSelection(ourSel);
 
   // mutual-exclusion: the selection is either controlled by the
   // document or by the text input/area. Clear any selection in the
   // document since the focus is now on our independent selection.
 
-  nsCOMPtr<nsISelectionController> selcon = do_QueryInterface(presShell);
   RefPtr<Selection> docSel =
-      selcon->GetSelection(nsISelectionController::SELECTION_NORMAL);
+      presShell->GetSelection(nsISelectionController::SELECTION_NORMAL);
   if (!docSel) {
     return;
   }
 
   if (!docSel->IsCollapsed()) {
     docSel->RemoveAllRanges(IgnoreErrors());
   }
 }
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -28,17 +28,16 @@
 #include "nsGenericHTMLElement.h"
 #include "nsLineBox.h"
 #include "nsLineLayout.h"
 #include "nsPlaceholderFrame.h"
 #include "nsStyleConsts.h"
 #include "nsFrameManager.h"
 #include "nsPresContext.h"
 #include "nsPresContextInlines.h"
-#include "nsIPresShell.h"
 #include "nsHTMLParts.h"
 #include "nsGkAtoms.h"
 #include "nsAttrValueInlines.h"
 #include "mozilla/Sprintf.h"
 #include "nsFloatManager.h"
 #include "prenv.h"
 #include "plstr.h"
 #include "nsError.h"
@@ -49,16 +48,17 @@
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSFrameConstructor.h"
 #include "TextOverflow.h"
 #include "nsIFrameInlines.h"
 #include "CounterStyleManager.h"
 #include "mozilla/dom/HTMLDetailsElement.h"
 #include "mozilla/dom/HTMLSummaryElement.h"
 #include "mozilla/dom/Selection.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/Telemetry.h"
 
 #include "nsBidiPresUtils.h"
 
 #include <inttypes.h>
 
@@ -318,42 +318,42 @@ void nsBlockFrame::AddSizeOfExcludingThi
 }
 
 void nsBlockFrame::DestroyFrom(nsIFrame* aDestructRoot,
                                PostDestroyData& aPostDestroyData) {
   ClearLineCursor();
   DestroyAbsoluteFrames(aDestructRoot, aPostDestroyData);
   mFloats.DestroyFramesFrom(aDestructRoot, aPostDestroyData);
   nsPresContext* presContext = PresContext();
-  nsIPresShell* shell = presContext->PresShell();
+  mozilla::PresShell* presShell = presContext->PresShell();
   nsLineBox::DeleteLineList(presContext, mLines, aDestructRoot, &mFrames,
                             aPostDestroyData);
 
   if (HasPushedFloats()) {
-    SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+    SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                PushedFloatProperty());
     RemoveStateBits(NS_BLOCK_HAS_PUSHED_FLOATS);
   }
 
   // destroy overflow lines now
   FrameLines* overflowLines = RemoveOverflowLines();
   if (overflowLines) {
     nsLineBox::DeleteLineList(presContext, overflowLines->mLines, aDestructRoot,
                               &overflowLines->mFrames, aPostDestroyData);
     delete overflowLines;
   }
 
   if (GetStateBits() & NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS) {
-    SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+    SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                OverflowOutOfFlowsProperty());
     RemoveStateBits(NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS);
   }
 
   if (HasOutsideMarker()) {
-    SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+    SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                OutsideMarkerProperty());
     RemoveStateBits(NS_BLOCK_FRAME_HAS_OUTSIDE_MARKER);
   }
 
   nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
 }
 
 /* virtual */
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -15,24 +15,24 @@
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/layers/LayersMessages.h"
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Move.h"
+#include "mozilla/PresShell.h"
 #include "nsCOMPtr.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsFontMetrics.h"
 #include "nsGkAtoms.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValueInlines.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 #include "mozilla/dom/Document.h"
 #include "nsDisplayList.h"
 #include "nsCounterManager.h"
 #include "nsBidiUtils.h"
 #include "CounterStyleManager.h"
 #include "UnitTransforms.h"
 
 #include "imgIContainer.h"
@@ -1150,20 +1150,20 @@ nsresult nsBulletFrame::OnSizeAvailable(
                       nsSize(nsPresContext::CSSPixelsToAppUnits(w),
                              nsPresContext::CSSPixelsToAppUnits(h)));
 
   if (mIntrinsicSize != newsize) {
     mIntrinsicSize = newsize;
 
     // Now that the size is available (or an error occurred), trigger
     // a reflow of the bullet frame.
-    nsIPresShell* shell = presContext->GetPresShell();
-    if (shell) {
-      shell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
-                              NS_FRAME_IS_DIRTY);
+    mozilla::PresShell* presShell = presContext->GetPresShell();
+    if (presShell) {
+      presShell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
+                                  NS_FRAME_IS_DIRTY);
     }
   }
 
   // Handle animations
   aImage->SetAnimationMode(presContext->ImageAnimationMode());
   // Ensure the animation (if any) is started. Note: There is no
   // corresponding call to Decrement for this. This Increment will be
   // 'cleaned up' by the Request when it is destroyed, but only then.
@@ -1173,21 +1173,22 @@ nsresult nsBulletFrame::OnSizeAvailable(
 }
 
 void nsBulletFrame::GetLoadGroup(nsPresContext* aPresContext,
                                  nsILoadGroup** aLoadGroup) {
   if (!aPresContext) return;
 
   MOZ_ASSERT(nullptr != aLoadGroup, "null OUT parameter pointer");
 
-  nsIPresShell* shell = aPresContext->GetPresShell();
+  mozilla::PresShell* presShell = aPresContext->GetPresShell();
+  if (!presShell) {
+    return;
+  }
 
-  if (!shell) return;
-
-  Document* doc = shell->GetDocument();
+  Document* doc = presShell->GetDocument();
   if (!doc) return;
 
   *aLoadGroup = doc->GetDocumentLoadGroup().take();
 }
 
 float nsBulletFrame::GetFontSizeInflation() const {
   if (!HasFontSizeInflation()) {
     return 1.0f;
--- a/layout/generic/nsCanvasFrame.cpp
+++ b/layout/generic/nsCanvasFrame.cpp
@@ -12,17 +12,16 @@
 #include "gfxUtils.h"
 #include "nsContainerFrame.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsCSSRendering.h"
 #include "nsPresContext.h"
 #include "nsPopupSetFrame.h"
 #include "nsGkAtoms.h"
 #include "nsIFrameInlines.h"
-#include "nsIPresShell.h"
 #include "nsDisplayList.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsFrameManager.h"
 #include "gfxPlatform.h"
 #include "nsPrintfCString.h"
 #include "mozilla/AccessibleCaretEventHub.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/dom/AnonymousContent.h"
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -4,28 +4,28 @@
  * 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/. */
 
 /* base class #1 for rendering objects that have child lists */
 
 #include "nsContainerFrame.h"
 
 #include "mozilla/ComputedStyle.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/HTMLSummaryElement.h"
 #include "nsAbsoluteContainingBlock.h"
 #include "nsAttrValue.h"
 #include "nsAttrValueInlines.h"
 #include "nsFlexContainerFrame.h"
 #include "mozilla/dom/Document.h"
 #include "nsPresContext.h"
 #include "nsRect.h"
 #include "nsPoint.h"
 #include "nsStyleConsts.h"
 #include "nsView.h"
-#include "nsIPresShell.h"
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "nsViewManager.h"
 #include "nsIWidget.h"
 #include "nsCSSRendering.h"
 #include "nsError.h"
 #include "nsDisplayList.h"
 #include "nsIBaseWindow.h"
@@ -252,39 +252,39 @@ void nsContainerFrame::DestroyFrom(nsIFr
       } else if (aProp == BackdropProperty()) {
         hasBackdrop = true;
       }
       return true;
     });
 
     // Destroy frames on the auxiliary frame lists and delete the lists.
     nsPresContext* pc = PresContext();
-    nsIPresShell* shell = pc->PresShell();
+    mozilla::PresShell* presShell = pc->PresShell();
     if (hasO) {
-      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                  OverflowProperty());
     }
 
     MOZ_ASSERT(
         IsFrameOfType(eCanContainOverflowContainers) || !(hasOC || hasEOC),
         "this type of frame shouldn't have overflow containers");
     if (hasOC) {
-      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                  OverflowContainersProperty());
     }
     if (hasEOC) {
-      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                  ExcessOverflowContainersProperty());
     }
 
     MOZ_ASSERT(!GetProperty(BackdropProperty()) ||
                    StyleDisplay()->mTopLayer != NS_STYLE_TOP_LAYER_NONE,
                "only top layer frame may have backdrop");
     if (hasBackdrop) {
-      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, shell,
+      SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
                                  BackdropProperty());
     }
   }
 
   nsSplittableFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
 }
 
 /////////////////////////////////////////////////////////////////////////////
--- a/layout/generic/nsFirstLetterFrame.cpp
+++ b/layout/generic/nsFirstLetterFrame.cpp
@@ -5,22 +5,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* rendering object for CSS :first-letter pseudo-element */
 
 #include "nsFirstLetterFrame.h"
 #include "nsPresContext.h"
 #include "nsPresContextInlines.h"
 #include "mozilla/ComputedStyle.h"
+#include "mozilla/PresShell.h"
+#include "mozilla/RestyleManager.h"
+#include "mozilla/ServoStyleSet.h"
 #include "nsIContent.h"
 #include "nsLineLayout.h"
 #include "nsGkAtoms.h"
-#include "mozilla/ServoStyleSet.h"
 #include "nsFrameManager.h"
-#include "mozilla/RestyleManager.h"
 #include "nsPlaceholderFrame.h"
 #include "nsCSSFrameConstructor.h"
 
 using namespace mozilla;
 using namespace mozilla::layout;
 
 nsFirstLetterFrame* NS_NewFirstLetterFrame(nsIPresShell* aPresShell,
                                            ComputedStyle* aStyle) {
@@ -284,17 +285,17 @@ nsresult nsFirstLetterFrame::CreateConti
     nsPresContext* aPresContext, nsIFrame* aChild, nsIFrame** aContinuation,
     bool aIsFluid) {
   NS_ASSERTION(IsFloating(),
                "can only call this on floating first letter frames");
   MOZ_ASSERT(aContinuation, "bad args");
 
   *aContinuation = nullptr;
 
-  nsIPresShell* presShell = aPresContext->PresShell();
+  mozilla::PresShell* presShell = aPresContext->PresShell();
   nsPlaceholderFrame* placeholderFrame = GetPlaceholderFrame();
   nsContainerFrame* parent = placeholderFrame->GetParent();
 
   nsIFrame* continuation = presShell->FrameConstructor()->CreateContinuingFrame(
       aPresContext, aChild, parent, aIsFluid);
 
   // The continuation will have gotten the first letter style from its
   // prev continuation, so we need to repair the ComputedStyle so it
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -16,16 +16,17 @@
 #include "nsPresContext.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/CSSOrderAwareFrameIterator.h"
 #include "mozilla/Logging.h"
 #include <algorithm>
 #include "gfxContext.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/FloatingPoint.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/UniquePtr.h"
 #include "WritingModes.h"
 
 using namespace mozilla;
 using namespace mozilla::layout;
 
 // Convenience typedefs for helper classes that we forward-declare in .h file
 // (so that nsFlexContainerFrame methods can use them as parameters):
@@ -4415,21 +4416,22 @@ nsFlexContainerFrame* nsFlexContainerFra
     // Generate the FlexContainerInfo data, if it's not already there.
     bool reflowNeeded = !flexFrame->HasProperty(FlexContainerInfo());
 
     if (reflowNeeded) {
       // Trigger a reflow that generates additional flex property data.
       // Hold onto aFrame while we do this, in case reflow destroys it.
       AutoWeakFrame weakFrameRef(aFrame);
 
-      nsIPresShell* shell = flexFrame->PresContext()->PresShell();
+      RefPtr<mozilla::PresShell> presShell =
+          static_cast<mozilla::PresShell*>(flexFrame->PresShell());
       flexFrame->AddStateBits(NS_STATE_FLEX_GENERATE_COMPUTED_VALUES);
-      shell->FrameNeedsReflow(flexFrame, nsIPresShell::eResize,
-                              NS_FRAME_IS_DIRTY);
-      shell->FlushPendingNotifications(FlushType::Layout);
+      presShell->FrameNeedsReflow(flexFrame, nsIPresShell::eResize,
+                                  NS_FRAME_IS_DIRTY);
+      presShell->FlushPendingNotifications(FlushType::Layout);
 
       // Since the reflow may have side effects, get the flex frame
       // again. But if the weakFrameRef is no longer valid, then we
       // must bail out.
       if (!weakFrameRef.IsAlive()) {
         return nullptr;
       }
 
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -439,34 +439,34 @@ AutoWeakFrame::AutoWeakFrame(const WeakF
     : mPrev(nullptr), mFrame(nullptr) {
   Init(aOther.GetFrame());
 }
 
 void AutoWeakFrame::Init(nsIFrame* aFrame) {
   Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
   mFrame = aFrame;
   if (mFrame) {
-    nsIPresShell* shell = mFrame->PresContext()->GetPresShell();
-    NS_WARNING_ASSERTION(shell, "Null PresShell in AutoWeakFrame!");
-    if (shell) {
-      shell->AddAutoWeakFrame(this);
+    mozilla::PresShell* presShell = mFrame->PresContext()->GetPresShell();
+    NS_WARNING_ASSERTION(presShell, "Null PresShell in AutoWeakFrame!");
+    if (presShell) {
+      presShell->AddAutoWeakFrame(this);
     } else {
       mFrame = nullptr;
     }
   }
 }
 
 void WeakFrame::Init(nsIFrame* aFrame) {
   Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
   mFrame = aFrame;
   if (mFrame) {
-    nsIPresShell* shell = mFrame->PresContext()->GetPresShell();
-    MOZ_ASSERT(shell, "Null PresShell in WeakFrame!");
-    if (shell) {
-      shell->AddWeakFrame(this);
+    mozilla::PresShell* presShell = mFrame->PresContext()->GetPresShell();
+    MOZ_ASSERT(presShell, "Null PresShell in WeakFrame!");
+    if (presShell) {
+      presShell->AddWeakFrame(this);
     } else {
       mFrame = nullptr;
     }
   }
 }
 
 nsIFrame* NS_NewEmptyFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) {
   return new (aPresShell) nsFrame(aStyle, aPresShell->GetPresContext());
@@ -4202,23 +4202,25 @@ nsFrame::HandlePress(nsPresContext* aPre
     return NS_OK;
   }
 
   // We often get out of sync state issues with mousedown events that
   // get interrupted by alerts/dialogs.
   // Check with the ESM to see if we should process this one
   if (!aPresContext->EventStateManager()->EventStatusOK(aEvent)) return NS_OK;
 
-  nsIPresShell* shell = aPresContext->GetPresShell();
-  if (!shell) return NS_ERROR_FAILURE;
+  mozilla::PresShell* presShell = aPresContext->GetPresShell();
+  if (!presShell) {
+    return NS_ERROR_FAILURE;
+  }
 
   // if we are in Navigator and the click is in a draggable node, we don't want
   // to start selection because we don't want to interfere with a potential
   // drag of said node and steal all its glory.
-  int16_t isEditor = shell->GetSelectionFlags();
+  int16_t isEditor = presShell->GetSelectionFlags();
   // weaaak. only the editor can display frame selection not just text and
   // images
   isEditor = isEditor == nsISelectionDisplay::DISPLAY_ALL;
 
   WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
 
   if (!mouseEvent->IsAlt()) {
     for (nsIContent* content = mContent; content;
@@ -4262,17 +4264,17 @@ nsFrame::HandlePress(nsPresContext* aPre
   }
 
   // XXX This is screwy; it really should use the selection frame, not the
   // event frame
   const nsFrameSelection* frameselection = nullptr;
   if (useFrameSelection)
     frameselection = GetConstFrameSelection();
   else
-    frameselection = shell->ConstFrameSelection();
+    frameselection = presShell->ConstFrameSelection();
 
   if (!frameselection || frameselection->GetDisplaySelection() ==
                              nsISelectionController::SELECTION_OFF)
     return NS_OK;  // nothing to do we cannot affect selection from here
 
 #ifdef XP_MACOSX
   if (mouseEvent->IsControl())
     return NS_OK;  // short circuit. hard coded for mac due to time restraints.
@@ -4295,17 +4297,17 @@ nsFrame::HandlePress(nsPresContext* aPre
 
   if (!offsets.content) return NS_ERROR_FAILURE;
 
   // Let Ctrl/Cmd+mouse down do table selection instead of drag initiation
   nsCOMPtr<nsIContent> parentContent;
   int32_t contentOffset;
   TableSelection target;
   nsresult rv;
-  rv = GetDataForTableSelection(frameselection, shell, mouseEvent,
+  rv = GetDataForTableSelection(frameselection, presShell, mouseEvent,
                                 getter_AddRefs(parentContent), &contentOffset,
                                 &target);
   if (NS_SUCCEEDED(rv) && parentContent) {
     fc->SetDragState(true);
     return fc->HandleTableSelection(parentContent, contentOffset, target,
                                     mouseEvent);
   }
 
@@ -4546,17 +4548,17 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPres
 
   frameselection->StopAutoScrollTimer();
 
   // Check if we are dragging in a table cell
   nsCOMPtr<nsIContent> parentContent;
   int32_t contentOffset;
   TableSelection target;
   WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
-  nsCOMPtr<nsIPresShell> presShell = aPresContext->PresShell();
+  mozilla::PresShell* presShell = aPresContext->PresShell();
   nsresult result;
   result = GetDataForTableSelection(frameselection, presShell, mouseEvent,
                                     getter_AddRefs(parentContent),
                                     &contentOffset, &target);
 
   AutoWeakFrame weakThis = this;
   if (NS_SUCCEEDED(result) && parentContent) {
     frameselection->HandleTableSelection(parentContent, contentOffset, target,
@@ -4704,18 +4706,17 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsP
 
   // Also check the selection of the capturing content which might be in a
   // different document.
   if (!frameSelection && captureContent) {
     Document* doc = captureContent->GetUncomposedDoc();
     if (doc) {
       mozilla::PresShell* capturingPresShell = doc->GetPresShell();
       if (capturingPresShell &&
-          capturingPresShell !=
-              static_cast<mozilla::PresShell*>(PresContext()->GetPresShell())) {
+          capturingPresShell != PresContext()->GetPresShell()) {
         frameSelection = capturingPresShell->FrameSelection();
       }
     }
   }
 
   if (frameSelection) {
     frameSelection->SetDragState(false);
     frameSelection->StopAutoScrollTimer();
@@ -7633,19 +7634,18 @@ nsresult nsFrame::MakeFrameName(const ns
 void nsIFrame::DumpFrameTree() const { RootFrameList(PresContext(), stderr); }
 
 void nsIFrame::DumpFrameTreeLimited() const { List(stderr); }
 
 void nsIFrame::RootFrameList(nsPresContext* aPresContext, FILE* out,
                              const char* aPrefix) {
   if (!aPresContext || !out) return;
 
-  nsIPresShell* shell = aPresContext->GetPresShell();
-  if (shell) {
-    nsIFrame* frame = shell->GetRootFrame();
+  if (mozilla::PresShell* presShell = aPresContext->GetPresShell()) {
+    nsIFrame* frame = presShell->GetRootFrame();
     if (frame) {
       frame->List(out, aPrefix);
     }
   }
 }
 #endif
 
 bool nsIFrame::IsVisibleForPainting() { return StyleVisibility()->IsVisible(); }
@@ -7674,17 +7674,18 @@ nsresult nsFrame::GetSelectionController
   while (frame && (frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)) {
     nsITextControlFrame* tcf = do_QueryFrame(frame);
     if (tcf) {
       return tcf->GetOwnedSelectionController(aSelCon);
     }
     frame = frame->GetParent();
   }
 
-  return CallQueryInterface(aPresContext->GetPresShell(), aSelCon);
+  *aSelCon = do_AddRef(aPresContext->PresShell()).take();
+  return NS_OK;
 }
 
 already_AddRefed<nsFrameSelection> nsIFrame::GetFrameSelection() {
   RefPtr<nsFrameSelection> fs =
       const_cast<nsFrameSelection*>(GetConstFrameSelection());
   return fs.forget();
 }
 
@@ -7907,19 +7908,21 @@ nsresult nsFrame::GetNextPrevLineFromeBl
         } else {
           point.y = tempRect.height + offset.y;
           point.x = aPos->mDesiredPos.x;
         }
 
         // special check. if we allow non-text selection then we can allow a hit
         // location to fall before a table. otherwise there is no way to get and
         // click signal to fall before a table (it being a line iterator itself)
-        nsIPresShell* shell = aPresContext->GetPresShell();
-        if (!shell) return NS_ERROR_FAILURE;
-        int16_t isEditor = shell->GetSelectionFlags();
+        mozilla::PresShell* presShell = aPresContext->GetPresShell();
+        if (!presShell) {
+          return NS_ERROR_FAILURE;
+        }
+        int16_t isEditor = presShell->GetSelectionFlags();
         isEditor = isEditor == nsISelectionDisplay::DISPLAY_ALL;
         if (isEditor) {
           if (resultFrame->IsTableWrapperFrame()) {
             if (((point.x - offset.x + tempRect.x) < 0) ||
                 ((point.x - offset.x + tempRect.x) >
                  tempRect.width))  // off left/right side
             {
               nsIContent* content = resultFrame->GetContent();
--- a/layout/generic/nsFrameList.cpp
+++ b/layout/generic/nsFrameList.cpp
@@ -2,21 +2,21 @@
 /* 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 "nsFrameList.h"
 
 #include "mozilla/ArenaObjectID.h"
+#include "mozilla/PresShell.h"
 #include "nsBidiPresUtils.h"
 #include "nsContainerFrame.h"
 #include "nsGkAtoms.h"
 #include "nsILineIterator.h"
-#include "nsIPresShell.h"
 #include "nsLayoutUtils.h"
 #include "nsPresContext.h"
 
 using namespace mozilla;
 
 namespace mozilla {
 namespace layout {
 namespace detail {
--- a/layout/generic/nsFrameSetFrame.cpp
+++ b/layout/generic/nsFrameSetFrame.cpp
@@ -10,25 +10,25 @@
 
 #include "gfxContext.h"
 #include "gfxUtils.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Helpers.h"
 #include "mozilla/Likely.h"
+#include "mozilla/PresShell.h"
 
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValueInlines.h"
 #include "nsLeafFrame.h"
 #include "nsContainerFrame.h"
 #include "nsLayoutUtils.h"
 #include "nsPresContext.h"
 #include "nsIContentInlines.h"
-#include "nsIPresShell.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsHTMLParts.h"
 #include "nsNameSpaceManager.h"
 #include "nsCSSAnonBoxes.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/dom/Element.h"
 #include "nsDisplayList.h"
@@ -198,17 +198,17 @@ void nsHTMLFramesetFrame::Init(nsIConten
       mTopLevelFrameset = frameset;
       parentFrame = parentFrame->GetParent();
     } else {
       break;
     }
   }
 
   nsPresContext* presContext = PresContext();
-  nsIPresShell* shell = presContext->PresShell();
+  mozilla::PresShell* presShell = presContext->PresShell();
 
   nsFrameborder frameborder = GetFrameBorder();
   int32_t borderWidth = GetBorderWidth(presContext, false);
   nscolor borderColor = GetBorderColor();
 
   // Get the rows= cols= data
   HTMLFrameSetElement* ourContent = HTMLFrameSetElement::FromNode(mContent);
   NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!");
@@ -276,32 +276,32 @@ void nsHTMLFramesetFrame::Init(nsIConten
     if (!child->IsHTMLElement()) {
       continue;
     }
 
     if (!child->IsAnyOfHTMLElements(nsGkAtoms::frameset, nsGkAtoms::frame)) {
       continue;
     }
 
-    RefPtr<ComputedStyle> kidSC = shell->StyleSet()->ResolveStyleFor(
+    RefPtr<ComputedStyle> kidSC = presShell->StyleSet()->ResolveStyleFor(
         child->AsElement(), LazyComputeBehavior::Allow);
 
     nsIFrame* frame;
     if (child->IsHTMLElement(nsGkAtoms::frameset)) {
-      frame = NS_NewHTMLFramesetFrame(shell, kidSC);
+      frame = NS_NewHTMLFramesetFrame(presShell, kidSC);
 
       nsHTMLFramesetFrame* childFrame = (nsHTMLFramesetFrame*)frame;
       childFrame->SetParentFrameborder(frameborder);
       childFrame->SetParentBorderWidth(borderWidth);
       childFrame->SetParentBorderColor(borderColor);
       frame->Init(child, this, nullptr);
 
       mChildBorderColors[mChildCount].Set(childFrame->GetBorderColor());
     } else {  // frame
-      frame = NS_NewSubDocumentFrame(shell, kidSC);
+      frame = NS_NewSubDocumentFrame(presShell, kidSC);
 
       frame->Init(child, this, nullptr);
 
       mChildFrameborder[mChildCount] = GetFrameBorder(child);
       mChildBorderColors[mChildCount].Set(GetBorderColor(child));
     }
     child->SetPrimaryFrame(frame);
 
@@ -310,22 +310,22 @@ void nsHTMLFramesetFrame::Init(nsIConten
     mChildCount++;
   }
 
   mNonBlankChildCount = mChildCount;
   // add blank frames for frameset cells that had no content provided
   for (int blankX = mChildCount; blankX < numCells; blankX++) {
     RefPtr<ComputedStyle> pseudoComputedStyle;
     pseudoComputedStyle =
-        shell->StyleSet()->ResolveNonInheritingAnonymousBoxStyle(
+        presShell->StyleSet()->ResolveNonInheritingAnonymousBoxStyle(
             PseudoStyleType::framesetBlank);
 
     // XXX the blank frame is using the content of its parent - at some point it
     // should just have null content, if we support that
-    nsHTMLFramesetBlankFrame* blankFrame = new (shell)
+    nsHTMLFramesetBlankFrame* blankFrame = new (presShell)
         nsHTMLFramesetBlankFrame(pseudoComputedStyle, PresContext());
 
     blankFrame->Init(mContent, this, nullptr);
 
     mFrames.AppendFrame(nullptr, blankFrame);
 
     mChildBorderColors[mChildCount].Set(NO_COLOR);
     mChildCount++;
@@ -757,18 +757,18 @@ void nsHTMLFramesetFrame::Reflow(nsPresC
                                  ReflowOutput& aDesiredSize,
                                  const ReflowInput& aReflowInput,
                                  nsReflowStatus& aStatus) {
   MarkInReflow();
   DO_GLOBAL_REFLOW_COUNT("nsHTMLFramesetFrame");
   DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
   MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
 
-  nsIPresShell* shell = aPresContext->PresShell();
-  ServoStyleSet* styleSet = shell->StyleSet();
+  mozilla::PresShell* presShell = aPresContext->PresShell();
+  ServoStyleSet* styleSet = presShell->StyleSet();
 
   GetParent()->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
 
   // printf("FramesetFrame2::Reflow %X (%d,%d) \n", this,
   // aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight());
   // Always get the size so that the caller knows how big we are
   GetDesiredSize(aPresContext, aReflowInput, aDesiredSize);
 
@@ -867,17 +867,17 @@ void nsHTMLFramesetFrame::Reflow(nsPresC
       offset.x = 0;
       offset.y += lastSize.height;
       if (firstTime) {  // create horizontal border
 
         RefPtr<ComputedStyle> pseudoComputedStyle;
         pseudoComputedStyle = styleSet->ResolveNonInheritingAnonymousBoxStyle(
             PseudoStyleType::horizontalFramesetBorder);
 
-        borderFrame = new (shell) nsHTMLFramesetBorderFrame(
+        borderFrame = new (presShell) nsHTMLFramesetBorderFrame(
             pseudoComputedStyle, PresContext(), borderWidth, false, false);
         borderFrame->Init(mContent, this, nullptr);
         mChildCount++;
         mFrames.AppendFrame(nullptr, borderFrame);
         mHorBorders[cellIndex.y - 1] = borderFrame;
         // set the neighbors for determining drag boundaries
         borderFrame->mPrevNeighbor = lastRow;
         borderFrame->mNextNeighbor = cellIndex.y;
@@ -896,17 +896,17 @@ void nsHTMLFramesetFrame::Reflow(nsPresC
         if (0 == cellIndex.y) {  // in 1st row
           if (firstTime) {       // create vertical border
 
             RefPtr<ComputedStyle> pseudoComputedStyle;
             pseudoComputedStyle =
                 styleSet->ResolveNonInheritingAnonymousBoxStyle(
                     PseudoStyleType::verticalFramesetBorder);
 
-            borderFrame = new (shell) nsHTMLFramesetBorderFrame(
+            borderFrame = new (presShell) nsHTMLFramesetBorderFrame(
                 pseudoComputedStyle, PresContext(), borderWidth, true, false);
             borderFrame->Init(mContent, this, nullptr);
             mChildCount++;
             mFrames.AppendFrame(nullptr, borderFrame);
             mVerBorders[cellIndex.x - 1] = borderFrame;
             // set the neighbors for determining drag boundaries
             borderFrame->mPrevNeighbor = lastCol;
             borderFrame->mNextNeighbor = cellIndex.x;
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -34,16 +34,17 @@
 #include "nsIHTMLDocument.h"
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsBidiPresUtils.h"
 #include "nsBidiUtils.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/HTMLTextAreaElement.h"
 #include <stdint.h>
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Telemetry.h"
 #include "FrameLayerBuilder.h"
@@ -3787,17 +3788,17 @@ bool ScrollFrameHelper::DecideScrollable
         // as the required coordinate transformation is expensive.
         if (usingDisplayPort) {
           const nsPresContext* rootPresContext =
               pc->GetToplevelContentDocumentPresContext();
           if (!rootPresContext) {
             rootPresContext = pc->GetRootPresContext();
           }
           if (rootPresContext) {
-            const nsIPresShell* const rootPresShell =
+            const mozilla::PresShell* const rootPresShell =
                 rootPresContext->PresShell();
             nsIFrame* rootFrame = rootPresShell->GetRootScrollFrame();
             if (!rootFrame) {
               rootFrame = rootPresShell->GetRootFrame();
             }
             if (rootFrame) {
               nsRect rootCompBounds = nsRect(
                   nsPoint(0, 0),
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/CSSAlignUtils.h"
 #include "mozilla/CSSOrderAwareFrameIterator.h"
 #include "mozilla/dom/GridBinding.h"
 #include "mozilla/IntegerRange.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/PodOperations.h"  // for PodZero
 #include "mozilla/Poison.h"
+#include "mozilla/PresShell.h"
 #include "nsAbsoluteContainingBlock.h"
 #include "nsAlgorithm.h"  // for clamped()
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsDataHashtable.h"
 #include "nsDisplayList.h"
 #include "nsHashKeys.h"
 #include "nsFieldSetFrame.h"
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -92,17 +92,16 @@
  *    after all reflowing the entire line, for example, but the frame should
  *    still be positioned and sized (and the view sized) during the reflow
  *    (i.e., before sending the DidReflow() notification)
  * 5. the view system handles moving of widgets, i.e., it's not our problem
  */
 
 class nsAtom;
 class nsPresContext;
-class nsIPresShell;
 class nsView;
 class nsIWidget;
 class nsISelectionController;
 class nsBoxLayoutState;
 class nsBoxLayout;
 class nsILineIterator;
 class nsDisplayItem;
 class nsDisplayListBuilder;
@@ -125,16 +124,17 @@ struct nsRect;
 struct nsSize;
 struct nsMargin;
 struct CharacterDataChangeInfo;
 
 namespace mozilla {
 
 enum class PseudoStyleType : uint8_t;
 class EventStates;
+class PresShell;
 struct ReflowInput;
 class ReflowOutput;
 class ServoRestyleState;
 class DisplayItemData;
 class EffectSet;
 
 namespace layers {
 class Layer;
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -20,26 +20,26 @@
 #include "mozilla/gfx/Helpers.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/dom/GeneratedImageContent.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/ResponsiveImageSelector.h"
 #include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Unused.h"
 
 #include "nsCOMPtr.h"
 #include "nsFontMetrics.h"
 #include "nsIImageLoadingContent.h"
 #include "nsImageLoadingContent.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 #include "nsGkAtoms.h"
 #include "mozilla/dom/Document.h"
 #include "nsContentUtils.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsStyleConsts.h"
 #include "nsStyleCoord.h"
 #include "nsStyleUtil.h"
 #include "nsTransform2D.h"
@@ -822,17 +822,17 @@ void nsImageFrame::MaybeDecodeForPredict
     return;  // We won't draw anything, so no point in decoding.
   }
 
   if (GetVisibility() != Visibility::APPROXIMATELY_VISIBLE) {
     return;  // We're not visible, so don't decode.
   }
 
   // OK, we're ready to decode. Compute the scale to the screen...
-  nsIPresShell* presShell = PresContext()->GetPresShell();
+  mozilla::PresShell* presShell = PresContext()->PresShell();
   LayoutDeviceToScreenScale2D resolutionToScreen(
       presShell->GetCumulativeResolution() *
       nsLayoutUtils::GetTransformToAncestorScaleExcludingAnimated(this));
 
   // ...and this frame's content box...
   const nsPoint offset =
       GetOffsetToCrossDoc(nsLayoutUtils::GetReferenceFrame(this));
   const nsRect frameContentBox = GetInnerArea() + offset;
@@ -2449,22 +2449,25 @@ void nsImageFrame::SpecToURI(const nsASt
 }
 
 void nsImageFrame::GetLoadGroup(nsPresContext* aPresContext,
                                 nsILoadGroup** aLoadGroup) {
   if (!aPresContext) return;
 
   MOZ_ASSERT(nullptr != aLoadGroup, "null OUT parameter pointer");
 
-  nsIPresShell* shell = aPresContext->GetPresShell();
-
-  if (!shell) return;
-
-  Document* doc = shell->GetDocument();
-  if (!doc) return;
+  mozilla::PresShell* presShell = aPresContext->GetPresShell();
+  if (!presShell) {
+    return;
+  }
+
+  Document* doc = presShell->GetDocument();
+  if (!doc) {
+    return;
+  }
 
   *aLoadGroup = doc->GetDocumentLoadGroup().take();
 }
 
 nsresult nsImageFrame::LoadIcons(nsPresContext* aPresContext) {
   NS_ASSERTION(!gIconLoad, "called LoadIcons twice");
 
   NS_NAMED_LITERAL_STRING(loadingSrc,
--- a/layout/generic/nsLineBox.cpp
+++ b/layout/generic/nsLineBox.cpp
@@ -6,16 +6,17 @@
 
 /* representation of one line within a block frame, a CSS line box */
 
 #include "nsLineBox.h"
 
 #include "mozilla/ArenaObjectID.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Likely.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/WritingModes.h"
 #include "nsBidiPresUtils.h"
 #include "nsFrame.h"
 #include "nsIFrameInlines.h"
 #include "nsPresArena.h"
 #include "nsPrintfCString.h"
 #include "nsWindowSizes.h"
@@ -347,17 +348,17 @@ bool nsLineBox::CachedIsEmpty() {
   mFlags.mEmptyCacheValid = true;
   mFlags.mEmptyCacheState = result;
   return result;
 }
 
 void nsLineBox::DeleteLineList(nsPresContext* aPresContext, nsLineList& aLines,
                                nsIFrame* aDestructRoot, nsFrameList* aFrames,
                                PostDestroyData& aPostDestroyData) {
-  nsIPresShell* shell = aPresContext->PresShell();
+  PresShell* presShell = aPresContext->PresShell();
 
   // Keep our line list and frame list up to date as we
   // remove frames, in case something wants to traverse the
   // frame tree while we're destroying.
   while (!aLines.empty()) {
     nsLineBox* line = aLines.front();
     if (MOZ_UNLIKELY(line->mFlags.mHasHashedFrames)) {
       line->SwitchToCounter();  // Avoid expensive has table removals.
@@ -368,17 +369,17 @@ void nsLineBox::DeleteLineList(nsPresCon
       MOZ_DIAGNOSTIC_ASSERT(child == line->mFirstChild, "Lines out of sync");
       line->mFirstChild = aFrames->FirstChild();
       line->NoteFrameRemoved(child);
       child->DestroyFrom(aDestructRoot, aPostDestroyData);
     }
     MOZ_DIAGNOSTIC_ASSERT(line == aLines.front(),
                           "destroying child frames messed up our lines!");
     aLines.pop_front();
-    line->Destroy(shell);
+    line->Destroy(presShell);
   }
 }
 
 bool nsLineBox::RFindLineContaining(nsIFrame* aFrame,
                                     const nsLineList::iterator& aBegin,
                                     nsLineList::iterator& aEnd,
                                     nsIFrame* aLastFrameBeforeEnd,
                                     int32_t* aFrameIndexInLine) {
--- a/layout/generic/nsPageContentFrame.cpp
+++ b/layout/generic/nsPageContentFrame.cpp
@@ -1,18 +1,20 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsPageContentFrame.h"
+
+#include "mozilla/PresShell.h"
+
 #include "nsCSSFrameConstructor.h"
 #include "nsPresContext.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsSimplePageSequenceFrame.h"
 
 using namespace mozilla;
 
 nsPageContentFrame* NS_NewPageContentFrame(nsIPresShell* aPresShell,
                                            ComputedStyle* aStyle) {
   return new (aPresShell)
       nsPageContentFrame(aStyle, aPresShell->GetPresContext());
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -1,24 +1,24 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsPageFrame.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/gfx/2D.h"
 #include "gfxContext.h"
 #include "nsDeviceContext.h"
 #include "nsFontMetrics.h"
 #include "nsLayoutUtils.h"
 #include "nsPresContext.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsPageContentFrame.h"
 #include "nsDisplayList.h"
 #include "nsSimplePageSequenceFrame.h"  // for nsSharedPageData
 #include "nsTextFormatter.h"  // for page number localization formatting
 #include "nsBidiUtils.h"
 #include "nsIPrintSettings.h"
 
 #include "mozilla/Logging.h"
--- a/layout/generic/nsPluginFrame.cpp
+++ b/layout/generic/nsPluginFrame.cpp
@@ -9,25 +9,25 @@
 #include "nsPluginFrame.h"
 
 #include "gfx2DGlue.h"
 #include "gfxContext.h"
 #include "gfxMatrix.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #ifdef XP_WIN
 // This is needed for DoublePassRenderingEvent.
 #  include "mozilla/plugins/PluginMessageUtils.h"
 #endif
 
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 #include "nsWidgetsCID.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsString.h"
 #include "nsGkAtoms.h"
 #include "nsIPluginInstanceOwner.h"
 #include "nsNPAPIPluginInstance.h"
 #include "npapi.h"
--- a/layout/generic/nsSimplePageSequenceFrame.cpp
+++ b/layout/generic/nsSimplePageSequenceFrame.cpp
@@ -1,32 +1,33 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsSimplePageSequenceFrame.h"
 
+#include "mozilla/PresShell.h"
+#include "mozilla/dom/HTMLCanvasElement.h"
+
 #include "DateTimeFormat.h"
 #include "nsCOMPtr.h"
 #include "nsDeviceContext.h"
 #include "nsPresContext.h"
 #include "gfxContext.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsIPrintSettings.h"
 #include "nsPageFrame.h"
 #include "nsSubDocumentFrame.h"
 #include "nsRegion.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsHTMLCanvasFrame.h"
-#include "mozilla/dom/HTMLCanvasElement.h"
 #include "nsICanvasRenderingContextInternal.h"
 #include "nsServiceManagerUtils.h"
 #include <algorithm>
 
 #define OFFSET_NOT_SET -1
 
 using namespace mozilla;
 using namespace mozilla::dom;
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -1020,17 +1020,17 @@ static void DestroyDisplayItemDataForFra
       DestroyDisplayItemDataForFrames(childFrames.get());
     }
   }
 }
 
 static bool BeginSwapDocShellsForDocument(Document* aDocument, void*) {
   MOZ_ASSERT(aDocument, "null document");
 
-  PresShell* presShell = aDocument->GetPresShell();
+  mozilla::PresShell* presShell = aDocument->GetPresShell();
   if (presShell) {
     // Disable painting while the views are detached, see bug 946929.
     presShell->SetNeverPainting(true);
 
     nsIFrame* rootFrame = presShell->GetRootFrame();
     if (rootFrame) {
       ::DestroyDisplayItemDataForFrames(rootFrame);
     }
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -12,16 +12,17 @@
 #include "gfxPrefs.h"
 #include "gfxUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MathAlgorithms.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/BinarySearch.h"
 #include "mozilla/IntegerRange.h"
 #include "mozilla/Unused.h"
 #include "mozilla/PodOperations.h"
 
 #include "nsCOMPtr.h"
@@ -34,17 +35,16 @@
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsStyleConsts.h"
 #include "nsStyleStruct.h"
 #include "nsStyleStructInlines.h"
 #include "SVGTextFrame.h"
 #include "nsCoord.h"
 #include "gfxContext.h"
-#include "nsIPresShell.h"
 #include "nsTArray.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsCompatibility.h"
 #include "nsCSSColorUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
 #include "nsFrame.h"
@@ -4768,17 +4768,17 @@ nsresult nsTextFrame::CharacterDataChang
   int32_t endOfChangedText = aInfo.mChangeStart + aInfo.mReplaceLength;
 
   // Parent of the last frame that we passed to FrameNeedsReflow (or noticed
   // had already received an earlier FrameNeedsReflow call).
   // (For subsequent frames with this same parent, we can just set their
   // dirty bit without bothering to call FrameNeedsReflow again.)
   nsIFrame* lastDirtiedFrameParent = nullptr;
 
-  nsIPresShell* shell = PresContext()->GetPresShell();
+  mozilla::PresShell* presShell = PresContext()->GetPresShell();
   do {
     // textFrame contained deleted text (or the insertion point,
     // if this was a pure insertion).
     textFrame->RemoveStateBits(TEXT_WHITESPACE_FLAGS);
     textFrame->ClearTextRuns();
 
     nsIFrame* parentOfTextFrame = textFrame->GetParent();
     bool areAncestorsAwareOfReflowRequest = false;
@@ -4796,18 +4796,18 @@ nsresult nsTextFrame::CharacterDataChang
                  "mReflowRequestedForCharDataChange should only be set "
                  "on dirty frames");
     } else {
       // Make sure textFrame is queued up for a reflow.  Also set a flag so we
       // don't waste time doing this again in repeated calls to this method.
       textFrame->mReflowRequestedForCharDataChange = true;
       if (!areAncestorsAwareOfReflowRequest) {
         // Ask the parent frame to reflow me.
-        shell->FrameNeedsReflow(textFrame, nsIPresShell::eStyleChange,
-                                NS_FRAME_IS_DIRTY);
+        presShell->FrameNeedsReflow(textFrame, nsIPresShell::eStyleChange,
+                                    NS_FRAME_IS_DIRTY);
       } else {
         // We already called FrameNeedsReflow on behalf of an earlier sibling,
         // so we can just mark this frame as dirty and don't need to bother
         // telling its ancestors.
         // Note: if the parent is a block, we're cheating here because we should
         // be marking our line dirty, but we're not. nsTextFrame::SetLength will
         // do that when it gets called during reflow.
         textFrame->AddStateBits(NS_FRAME_IS_DIRTY);
--- a/layout/mathml/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/nsMathMLmtableFrame.cpp
@@ -11,16 +11,17 @@
 #include "nsNameSpaceManager.h"
 #include "nsCSSRendering.h"
 #include "nsMathMLElement.h"
 
 #include "nsTArray.h"
 #include "nsTableFrame.h"
 #include "celldata.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/RestyleManager.h"
 #include <algorithm>
 
 #include "nsIScriptError.h"
 #include "nsContentUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::image;
--- a/layout/painting/FrameLayerBuilder.cpp
+++ b/layout/painting/FrameLayerBuilder.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/DebugOnly.h"
 
 #include "FrameLayerBuilder.h"
 
 #include "gfxContext.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Maybe.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/ProfileTimelineMarkerBinding.h"
 #include "mozilla/gfx/Matrix.h"
 #include "ActiveLayerTracker.h"
 #include "BasicLayers.h"
 #include "ImageContainer.h"
 #include "ImageLayers.h"
 #include "LayerTreeInvalidation.h"
 #include "Layers.h"
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -13,25 +13,25 @@
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Helpers.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/MathAlgorithms.h"
+#include "mozilla/PresShell.h"
 
 #include "BorderConsts.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIFrame.h"
 #include "nsIFrameInlines.h"
 #include "nsPoint.h"
 #include "nsRect.h"
-#include "nsIPresShell.h"
 #include "nsFrameManager.h"
 #include "nsGkAtoms.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsIContent.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "nsIScrollableFrame.h"
 #include "imgIRequest.h"
 #include "imgIContainer.h"
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -2582,17 +2582,17 @@ LayerManager* nsDisplayListBuilder::GetW
 }
 
 FrameLayerBuilder* nsDisplayList::BuildLayers(nsDisplayListBuilder* aBuilder,
                                               LayerManager* aLayerManager,
                                               uint32_t aFlags,
                                               bool aIsWidgetTransaction) {
   nsIFrame* frame = aBuilder->RootReferenceFrame();
   nsPresContext* presContext = frame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
 
   FrameLayerBuilder* layerBuilder = new FrameLayerBuilder();
   layerBuilder->Init(aBuilder, aLayerManager);
 
   if (aFlags & PAINT_COMPRESSED) {
     layerBuilder->SetLayerTreeCompressionMode();
   }
 
@@ -2710,17 +2710,17 @@ already_AddRefed<LayerManager> nsDisplay
       NS_WARNING("Nowhere to paint into");
       return nullptr;
     }
     layerManager = new BasicLayerManager(BasicLayerManager::BLM_OFFSCREEN);
   }
 
   nsIFrame* frame = aBuilder->RootReferenceFrame();
   nsPresContext* presContext = frame->PresContext();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   Document* document = presShell->GetDocument();
 
   if (layerManager->GetBackendType() == layers::LayersBackend::LAYERS_WR) {
     if (doBeginTransaction) {
       if (aCtx) {
         if (!layerManager->BeginTransactionWithTarget(aCtx)) {
           return nullptr;
         }
@@ -6735,17 +6735,17 @@ UniquePtr<ScrollMetadata> nsDisplaySubDo
     const ContainerLayerParameters& aContainerParameters) {
   if (!(mFlags & nsDisplayOwnLayerFlags::eGenerateScrollableLayer)) {
     return UniquePtr<ScrollMetadata>(nullptr);
   }
 
   nsPresContext* presContext = mFrame->PresContext();
   nsIFrame* rootScrollFrame = presContext->PresShell()->GetRootScrollFrame();
   bool isRootContentDocument = presContext->IsRootContentDocument();
-  nsIPresShell* presShell = presContext->PresShell();
+  PresShell* presShell = presContext->PresShell();
   ContainerLayerParameters params(
       aContainerParameters.mXScale * presShell->GetResolution(),
       aContainerParameters.mYScale * presShell->GetResolution(), nsIntPoint(),
       aContainerParameters);
 
   nsRect viewport = mFrame->GetRect() - mFrame->GetPosition() +
                     mFrame->GetOffsetToCrossDoc(ReferenceFrame());
 
--- a/layout/style/CounterStyleManager.cpp
+++ b/layout/style/CounterStyleManager.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CounterStyleManager.h"
 
 #include "mozilla/ArenaObjectID.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/MathAlgorithms.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Types.h"
 #include "mozilla/WritingModes.h"
 #include "nsPresContext.h"
 #include "nsPresContextInlines.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsTHashtable.h"
 #include "nsUnicodeProperties.h"
--- a/layout/style/nsFontFaceUtils.cpp
+++ b/layout/style/nsFontFaceUtils.cpp
@@ -2,16 +2,17 @@
 /* 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 "nsFontFaceUtils.h"
 
 #include "gfxUserFontSet.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/RestyleManager.h"
 #include "nsFontMetrics.h"
 #include "nsIFrame.h"
 #include "nsLayoutUtils.h"
 #include "nsPlaceholderFrame.h"
 #include "nsTArray.h"
 #include "SVGTextFrame.h"
 
@@ -124,17 +125,17 @@ enum class ReflowAlreadyScheduled {
 /* static */
 void nsFontFaceUtils::MarkDirtyForFontChange(nsIFrame* aSubtreeRoot,
                                              const gfxUserFontEntry* aFont) {
   MOZ_ASSERT(aFont);
   AutoTArray<nsIFrame*, 4> subtrees;
   subtrees.AppendElement(aSubtreeRoot);
 
   nsPresContext* pc = aSubtreeRoot->PresContext();
-  nsIPresShell* ps = pc->PresShell();
+  PresShell* presShell = pc->PresShell();
 
   // check descendants, iterating over subtrees that may include
   // additional subtrees associated with placeholders
   do {
     nsIFrame* subtreeRoot = subtrees.PopLastElement();
 
     // Check all descendants to see if they use the font
     AutoTArray<Pair<nsIFrame*, ReflowAlreadyScheduled>, 32> stack;
@@ -145,17 +146,17 @@ void nsFontFaceUtils::MarkDirtyForFontCh
       nsIFrame* f = pair.first();
       ReflowAlreadyScheduled alreadyScheduled = pair.second();
 
       // if this frame uses the font, mark its descendants dirty
       // and skip checking its children
       FontUsageKind kind = FrameFontUsage(f, pc, aFont);
       if (kind != FontUsageKind::None) {
         if (alreadyScheduled == ReflowAlreadyScheduled::No) {
-          ScheduleReflow(ps, f);
+          ScheduleReflow(presShell, f);
           alreadyScheduled = ReflowAlreadyScheduled::Yes;
         }
         if (kind == FontUsageKind::FrameAndFontMetrics) {
           MOZ_ASSERT(f->GetContent() && f->GetContent()->IsElement(),
                      "How could we target a non-element with selectors?");
           f->PresContext()->RestyleManager()->PostRestyleEvent(
               Element::FromNode(f->GetContent()),
               StyleRestyleHint_RECASCADE_SELF, nsChangeHint(0));
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -14,16 +14,17 @@
 #include "gfxFont.h"
 #include "gfxSkipChars.h"
 #include "gfxTypes.h"
 #include "gfxUtils.h"
 #include "LookAndFeel.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PatternHelpers.h"
 #include "mozilla/Likely.h"
+#include "mozilla/PresShell.h"
 #include "nsAlgorithm.h"
 #include "nsBidiPresUtils.h"
 #include "nsBlockFrame.h"
 #include "nsCaret.h"
 #include "nsContentUtils.h"
 #include "nsGkAtoms.h"
 #include "nsQuickSort.h"
 #include "SVGObserverUtils.h"
--- a/layout/svg/nsSVGForeignObjectFrame.cpp
+++ b/layout/svg/nsSVGForeignObjectFrame.cpp
@@ -5,28 +5,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Main header first:
 #include "nsSVGForeignObjectFrame.h"
 
 // Keep others in (case-insensitive) order:
 #include "ImgDrawResult.h"
 #include "gfxContext.h"
+#include "mozilla/AutoRestore.h"
+#include "mozilla/PresShell.h"
+#include "mozilla/dom/SVGForeignObjectElement.h"
 #include "nsDisplayList.h"
 #include "nsGkAtoms.h"
 #include "nsNameSpaceManager.h"
 #include "nsLayoutUtils.h"
 #include "nsRegion.h"
 #include "nsSVGContainerFrame.h"
 #include "SVGObserverUtils.h"
-#include "mozilla/dom/SVGForeignObjectElement.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGOuterSVGFrame.h"
 #include "nsSVGUtils.h"
-#include "mozilla/AutoRestore.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::image;
 
 //----------------------------------------------------------------------
 // Implementation
 
--- a/layout/tables/nsCellMap.cpp
+++ b/layout/tables/nsCellMap.cpp
@@ -1,15 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsCellMap.h"
+
+#include "mozilla/PresShell.h"
+
 #include "nsTArray.h"
-#include "nsCellMap.h"
 #include "nsTableFrame.h"
 #include "nsTableCellFrame.h"
 #include "nsTableRowFrame.h"
 #include "nsTableRowGroupFrame.h"
 #include <algorithm>
 
 using namespace mozilla;
 
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -2,32 +2,32 @@
 /* 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 "nsTableCellFrame.h"
 
 #include "gfxContext.h"
 #include "gfxUtils.h"
+#include "mozilla/ComputedStyle.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Helpers.h"
 #include "nsTableFrame.h"
 #include "nsTableColFrame.h"
 #include "nsTableRowFrame.h"
 #include "nsTableRowGroupFrame.h"
-#include "mozilla/ComputedStyle.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsCSSRendering.h"
 #include "nsIContent.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValueInlines.h"
 #include "nsHTMLParts.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsIServiceManager.h"
 #include "nsDisplayList.h"
 #include "nsLayoutUtils.h"
 #include "nsTextFrame.h"
 #include "FrameLayerBuilder.h"
 #include <algorithm>
 
 // TABLECELL SELECTION
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -6,16 +6,17 @@
 
 #include "nsTableFrame.h"
 
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Helpers.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/IntegerRange.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/WritingModes.h"
 
 #include "gfxContext.h"
 #include "nsCOMPtr.h"
 #include "mozilla/ComputedStyle.h"
 #include "nsStyleConsts.h"
 #include "nsIContent.h"
 #include "nsCellMap.h"
@@ -30,17 +31,16 @@
 #include "BasicTableLayoutStrategy.h"
 #include "FixedTableLayoutStrategy.h"
 
 #include "nsPresContext.h"
 #include "nsContentUtils.h"
 #include "nsCSSRendering.h"
 #include "nsGkAtoms.h"
 #include "nsCSSAnonBoxes.h"
-#include "nsIPresShell.h"
 #include "nsIScriptError.h"
 #include "nsFrameManager.h"
 #include "nsError.h"
 #include "nsCSSFrameConstructor.h"
 #include "mozilla/Range.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/ServoStyleSet.h"
 #include "nsDisplayList.h"
@@ -639,24 +639,24 @@ void nsTableFrame::RemoveCol(nsTableColG
  */
 nsTableCellMap* nsTableFrame::GetCellMap() const {
   return static_cast<nsTableFrame*>(FirstInFlow())->mCellMap;
 }
 
 nsTableColGroupFrame* nsTableFrame::CreateSyntheticColGroupFrame() {
   nsIContent* colGroupContent = GetContent();
   nsPresContext* presContext = PresContext();
-  nsIPresShell* shell = presContext->PresShell();
+  mozilla::PresShell* presShell = presContext->PresShell();
 
   RefPtr<ComputedStyle> colGroupStyle;
-  colGroupStyle = shell->StyleSet()->ResolveNonInheritingAnonymousBoxStyle(
+  colGroupStyle = presShell->StyleSet()->ResolveNonInheritingAnonymousBoxStyle(
       PseudoStyleType::tableColGroup);
   // Create a col group frame
   nsTableColGroupFrame* newFrame =
-      NS_NewTableColGroupFrame(shell, colGroupStyle);
+      NS_NewTableColGroupFrame(presShell, colGroupStyle);
   newFrame->SetIsSynthetic();
   newFrame->Init(colGroupContent, this, nullptr);
   return newFrame;
 }
 
 void nsTableFrame::AppendAnonymousColFrames(int32_t aNumColsToAdd) {
   MOZ_ASSERT(aNumColsToAdd > 0, "We should be adding _something_.");
   // get the last col group frame
--- a/layout/tables/nsTableRowGroupFrame.cpp
+++ b/layout/tables/nsTableRowGroupFrame.cpp
@@ -1,23 +1,25 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsTableRowGroupFrame.h"
+
+#include "mozilla/ComputedStyle.h"
+#include "mozilla/PresShell.h"
+
 #include "nsCOMPtr.h"
-#include "nsTableRowGroupFrame.h"
 #include "nsTableRowFrame.h"
 #include "nsTableFrame.h"
 #include "nsTableCellFrame.h"
 #include "nsPresContext.h"
-#include "mozilla/ComputedStyle.h"
 #include "nsStyleConsts.h"
 #include "nsIContent.h"
 #include "nsGkAtoms.h"
-#include "nsIPresShell.h"
 #include "nsCSSRendering.h"
 #include "nsHTMLParts.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsDisplayList.h"
 
 #include "nsCellMap.h"  //table cell navigation
 #include <algorithm>
 
--- a/layout/xul/nsBoxLayoutState.h
+++ b/layout/xul/nsBoxLayoutState.h
@@ -9,19 +9,19 @@
   Author:
   Eric D Vaughan
 
 **/
 
 #ifndef nsBoxLayoutState_h___
 #define nsBoxLayoutState_h___
 
+#include "mozilla/PresShell.h"
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 
 class gfxContext;
 namespace mozilla {
 struct ReflowInput;
 }  // namespace mozilla
 
 class MOZ_STACK_CLASS nsBoxLayoutState {
   using ReflowInput = mozilla::ReflowInput;
--- a/layout/xul/nsButtonBoxFrame.cpp
+++ b/layout/xul/nsButtonBoxFrame.cpp
@@ -5,25 +5,25 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "nsCOMPtr.h"
 #include "nsButtonBoxFrame.h"
 #include "nsIContent.h"
 #include "nsIDOMXULButtonElement.h"
 #include "nsGkAtoms.h"
 #include "nsNameSpaceManager.h"
 #include "nsPresContext.h"
-#include "nsIPresShell.h"
 #include "nsDisplayList.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/TextEvents.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMPL_ISUPPORTS(nsButtonBoxFrame::nsButtonBoxListener, nsIDOMEventListener)
 
 nsresult nsButtonBoxFrame::nsButtonBoxListener::HandleEvent(
@@ -189,20 +189,23 @@ void nsButtonBoxFrame::Blurred() {
 void nsButtonBoxFrame::MouseClicked(WidgetGUIEvent* aEvent) {
   // Don't execute if we're disabled.
   if (mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
                                          nsGkAtoms::_true, eCaseMatters))
     return;
 
   // Have the content handle the event, propagating it according to normal DOM
   // rules.
-  nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
-  if (!shell) return;
+  RefPtr<mozilla::PresShell> presShell = PresContext()->GetPresShell();
+  if (!presShell) {
+    return;
+  }
 
   // Execute the oncommand event handler.
   WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
   WidgetMouseEventBase* mouseEvent = aEvent->AsMouseEventBase();
   nsContentUtils::DispatchXULCommand(
-      mContent, aEvent->IsTrusted(), nullptr, shell, inputEvent->IsControl(),
-      inputEvent->IsAlt(), inputEvent->IsShift(), inputEvent->IsMeta(),
+      mContent, aEvent->IsTrusted(), nullptr, presShell,
+      inputEvent->IsControl(), inputEvent->IsAlt(), inputEvent->IsShift(),
+      inputEvent->IsMeta(),
       mouseEvent ? mouseEvent->inputSource
                  : MouseEvent_Binding::MOZ_SOURCE_UNKNOWN);
 }
--- a/layout/xul/nsDeckFrame.cpp
+++ b/layout/xul/nsDeckFrame.cpp
@@ -8,23 +8,23 @@
 // Eric Vaughan
 // Netscape Communications
 //
 // See documentation in associated header file
 //
 
 #include "nsDeckFrame.h"
 #include "mozilla/ComputedStyle.h"
+#include "mozilla/PresShell.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsCOMPtr.h"
 #include "nsNameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLParts.h"
-#include "nsIPresShell.h"
 #include "nsCSSRendering.h"
 #include "nsViewManager.h"
 #include "nsBoxLayoutState.h"
 #include "nsStackLayout.h"
 #include "nsDisplayList.h"
 #include "nsContainerFrame.h"
 #include "nsContentUtils.h"
 #include "nsXULPopupManager.h"
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -13,17 +13,16 @@
 #include "nsCSSRendering.h"
 #include "nsNameSpaceManager.h"
 #include "nsViewManager.h"
 #include "nsWidgetsCID.h"
 #include "nsMenuFrame.h"
 #include "nsMenuBarFrame.h"
 #include "nsPopupSetFrame.h"
 #include "nsPIDOMWindow.h"
-#include "nsIPresShell.h"
 #include "nsFrameManager.h"
 #include "mozilla/dom/Document.h"
 #include "nsRect.h"
 #include "nsIComponentManager.h"
 #include "nsBoxLayoutState.h"
 #include "nsIScrollableFrame.h"
 #include "nsIPopupContainer.h"
 #include "nsIDocShell.h"
@@ -46,16 +45,17 @@
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/KeyboardEvent.h"
 #include "mozilla/dom/KeyboardEventBinding.h"
 #include <algorithm>
 
 using namespace mozilla;
 using mozilla::dom::Document;
@@ -1615,17 +1615,17 @@ nsresult nsMenuPopupFrame::SetPopupPosit
 }
 
 void nsMenuPopupFrame::GenerateFrames() {
   const bool generateFrames = IsLeaf();
   MOZ_ASSERT_IF(generateFrames, !mGeneratedChildren);
   mGeneratedChildren = true;
   if (generateFrames) {
     MOZ_ASSERT(PrincipalChildList().IsEmpty());
-    nsCOMPtr<nsIPresShell> presShell = PresContext()->PresShell();
+    RefPtr<mozilla::PresShell> presShell = PresContext()->PresShell();
     presShell->FrameConstructor()->GenerateChildFrames(this);
   }
 }
 
 /* virtual */
 nsMenuFrame* nsMenuPopupFrame::GetCurrentMenuItem() { return mCurrentMenu; }
 
 LayoutDeviceIntRect nsMenuPopupFrame::GetConstraintRect(
--- a/layout/xul/nsPopupSetFrame.cpp
+++ b/layout/xul/nsPopupSetFrame.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsPopupSetFrame.h"
 #include "nsGkAtoms.h"
 #include "nsCOMPtr.h"
 #include "nsIContent.h"
 #include "nsPresContext.h"
 #include "mozilla/ComputedStyle.h"
+#include "mozilla/PresShell.h"
 #include "nsBoxLayoutState.h"
 #include "nsIScrollableFrame.h"
 #include "nsIPopupContainer.h"
 #include "nsMenuPopupFrame.h"
 
 typedef mozilla::ComputedStyle ComputedStyle;
 
 nsIFrame* NS_NewPopupSetFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) {
--- a/layout/xul/nsResizerFrame.cpp
+++ b/layout/xul/nsResizerFrame.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/. */
 
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsResizerFrame.h"
 #include "nsIContent.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Document.h"
 #include "nsGkAtoms.h"
 #include "nsNameSpaceManager.h"
 
 #include "nsPresContext.h"
 #include "nsFrameManager.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
@@ -60,17 +61,17 @@ nsresult nsResizerFrame::HandleEvent(nsP
 
   switch (aEvent->mMessage) {
     case eTouchStart:
     case eMouseDown: {
       if (aEvent->mClass == eTouchEventClass ||
           (aEvent->mClass == eMouseEventClass &&
            aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) {
         nsCOMPtr<nsIBaseWindow> window;
-        nsIPresShell* presShell = aPresContext->GetPresShell();
+        mozilla::PresShell* presShell = aPresContext->GetPresShell();
         nsIContent* contentToResize =
             GetContentToResize(presShell, getter_AddRefs(window));
         if (contentToResize) {
           nsIFrame* frameToResize = contentToResize->GetPrimaryFrame();
           if (!frameToResize) break;
 
           // cache the content rectangle for the frame to resize
           // GetScreenRectInAppUnits returns the border box rectangle, so
@@ -129,17 +130,17 @@ nsresult nsResizerFrame::HandleEvent(nsP
         doDefault = false;
       }
     } break;
 
     case eTouchMove:
     case eMouseMove: {
       if (mTrackingMouseMove) {
         nsCOMPtr<nsIBaseWindow> window;
-        nsIPresShell* presShell = aPresContext->GetPresShell();
+        mozilla::PresShell* presShell = aPresContext->GetPresShell();
         nsCOMPtr<nsIContent> contentToResize =
             GetContentToResize(presShell, getter_AddRefs(window));
 
         // check if the returned content really is a menupopup
         nsMenuPopupFrame* menuPopupFrame = nullptr;
         if (contentToResize) {
           menuPopupFrame = do_QueryFrame(contentToResize->GetPrimaryFrame());
         }
@@ -287,17 +288,17 @@ nsresult nsResizerFrame::HandleEvent(nsP
       if (mouseEvent->IsLeftClickEvent()) {
         MouseClicked(mouseEvent);
       }
       break;
     }
     case eMouseDoubleClick:
       if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
         nsCOMPtr<nsIBaseWindow> window;
-        nsIPresShell* presShell = aPresContext->GetPresShell();
+        mozilla::PresShell* presShell = aPresContext->GetPresShell();
         nsIContent* contentToResize =
             GetContentToResize(presShell, getter_AddRefs(window));
         if (contentToResize) {
           nsMenuPopupFrame* menuPopupFrame =
               do_QueryFrame(contentToResize->GetPrimaryFrame());
           if (menuPopupFrame)
             break;  // Don't restore original sizing for menupopup frames until
                     // we handle screen constraints here. (Bug 357725)
--- a/layout/xul/nsSplitterFrame.cpp
+++ b/layout/xul/nsSplitterFrame.cpp
@@ -15,31 +15,31 @@
 #include "nsSplitterFrame.h"
 #include "nsGkAtoms.h"
 #include "nsXULElement.h"
 #include "nsPresContext.h"
 #include "mozilla/dom/Document.h"
 #include "nsNameSpaceManager.h"
 #include "nsScrollbarButtonFrame.h"
 #include "nsIDOMEventListener.h"
-#include "nsIPresShell.h"
 #include "nsFrameList.h"
 #include "nsHTMLParts.h"
 #include "mozilla/ComputedStyle.h"
 #include "nsBoxLayoutState.h"
 #include "nsIServiceManager.h"
 #include "nsContainerFrame.h"
 #include "nsContentCID.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/MouseEvent.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/UniquePtr.h"
 #include "nsBindingManager.h"
 
 using namespace mozilla;
 
 using mozilla::dom::Event;
 
 class nsSplitterInfo {
--- a/layout/xul/nsTitleBarFrame.cpp
+++ b/layout/xul/nsTitleBarFrame.cpp
@@ -12,16 +12,17 @@
 #include "nsIWidget.h"
 #include "nsMenuPopupFrame.h"
 #include "nsPresContext.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
 #include "nsDisplayList.h"
 #include "nsContentUtils.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/MouseEventBinding.h"
 
 using namespace mozilla;
 
 //
 // NS_NewTitleBarFrame
 //
 // Creates a new TitleBar frame and returns it
@@ -117,17 +118,17 @@ nsresult nsTitleBarFrame::HandleEvent(ns
               static_cast<nsMenuPopupFrame*>(parent);
           nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
           LayoutDeviceIntRect bounds = widget->GetScreenBounds();
 
           CSSPoint cssPos = (bounds.TopLeft() + nsMoveBy) /
                             aPresContext->CSSToDevPixelScale();
           menuPopupFrame->MoveTo(RoundedToInt(cssPos), false);
         } else {
-          nsIPresShell* presShell = aPresContext->PresShell();
+          mozilla::PresShell* presShell = aPresContext->PresShell();
           nsPIDOMWindowOuter* window = presShell->GetDocument()->GetWindow();
           if (window) {
             window->MoveBy(nsMoveBy.x, nsMoveBy.y);
           }
         }
 
         *aEventStatus = nsEventStatus_eConsumeNoDefault;
 
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -1288,17 +1288,17 @@ void nsXULPopupManager::FirePopupShowing
 
   popupFrame->GenerateFrames();
 
   // get the frame again
   popupFrame = do_QueryFrame(aPopup->GetPrimaryFrame());
   if (!popupFrame) return;
 
   nsPresContext* presContext = popupFrame->PresContext();
-  nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
+  RefPtr<PresShell> presShell = presContext->PresShell();
   presShell->FrameNeedsReflow(popupFrame, nsIPresShell::eTreeChange,
                               NS_FRAME_HAS_DIRTY_CHILDREN);
 
   nsPopupType popupType = popupFrame->PopupType();
 
   // cache the popup so that document.popupNode can retrieve the trigger node
   // during the popupshowing event. It will be cleared below after the event
   // has fired.
@@ -1388,17 +1388,17 @@ void nsXULPopupManager::FirePopupShowing
     }
   }
 }
 
 void nsXULPopupManager::FirePopupHidingEvent(
     nsIContent* aPopup, nsIContent* aNextPopup, nsIContent* aLastPopup,
     nsPresContext* aPresContext, nsPopupType aPopupType, bool aDeselectMenu,
     bool aIsCancel) {
-  nsCOMPtr<nsIPresShell> presShell = aPresContext->PresShell();
+  RefPtr<PresShell> presShell = aPresContext->PresShell();
   mozilla::Unused << presShell;  // This presShell may be keeping things alive
                                  // on non GTK platforms
 
   nsEventStatus status = nsEventStatus_eIgnore;
   WidgetMouseEvent event(true, eXULPopupHiding, nullptr,
                          WidgetMouseEvent::eReal);
   EventDispatcher::Dispatch(aPopup, aPresContext, &event, nullptr, &status);
 
@@ -2657,27 +2657,27 @@ nsXULMenuCommandEvent::Run() {
       if (popupFrame) {
         popup = popupFrame->GetContent();
         break;
       }
       frame = frame->GetParent();
     }
 
     nsPresContext* presContext = menuFrame->PresContext();
-    nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
-    RefPtr<nsViewManager> kungFuDeathGrip = shell->GetViewManager();
+    RefPtr<PresShell> presShell = presContext->PresShell();
+    RefPtr<nsViewManager> kungFuDeathGrip = presShell->GetViewManager();
     mozilla::Unused
         << kungFuDeathGrip;  // Not referred to directly within this function
 
     // Deselect ourselves.
     if (mCloseMenuMode != CloseMenuMode_None) menuFrame->SelectMenu(false);
 
-    AutoHandlingUserInputStatePusher userInpStatePusher(mUserInput, nullptr,
-                                                        shell->GetDocument());
-    nsContentUtils::DispatchXULCommand(mMenu, mIsTrusted, nullptr, shell,
+    AutoHandlingUserInputStatePusher userInpStatePusher(
+        mUserInput, nullptr, presShell->GetDocument());
+    nsContentUtils::DispatchXULCommand(mMenu, mIsTrusted, nullptr, presShell,
                                        mControl, mAlt, mShift, mMeta);
   }
 
   if (popup && mCloseMenuMode != CloseMenuMode_None)
     pm->HidePopup(popup, mCloseMenuMode == CloseMenuMode_Auto, true, false,
                   false);
 
   return NS_OK;
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -8,16 +8,17 @@
 #include "mozilla/ContentEvents.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/ResultExtensions.h"
 #include "mozilla/TextEditRules.h"
 
 #include "gfxUtils.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
 #include "nsFontMetrics.h"
 #include "nsPresContext.h"
@@ -718,17 +719,17 @@ void nsTreeBodyFrame::CheckOverflow(cons
 
   if (!horizontalOverflowChanged && !verticalOverflowChanged) {
     return;
   }
 
   AutoWeakFrame weakFrame(this);
 
   RefPtr<nsPresContext> presContext = PresContext();
-  nsCOMPtr<nsIPresShell> presShell = presContext->GetPresShell();
+  RefPtr<mozilla::PresShell> presShell = presContext->GetPresShell();
   nsCOMPtr<nsIContent> content = mContent;
 
   if (verticalOverflowChanged) {
     InternalScrollPortEvent event(
         true, mVerticalOverflow ? eScrollPortOverflow : eScrollPortUnderflow,
         nullptr);
     event.mOrient = InternalScrollPortEvent::eVertical;
     EventDispatcher::Dispatch(content, presContext, &event);
--- a/toolkit/components/sessionstore/SessionStoreUtils.cpp
+++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp
@@ -1,14 +1,15 @@
 /* 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 "js/JSON.h"
 #include "jsapi.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/Document.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/dom/HTMLSelectElement.h"
 #include "mozilla/dom/HTMLTextAreaElement.h"
 #include "mozilla/dom/SessionStoreUtils.h"
 #include "mozilla/dom/txIXPathContext.h"
 #include "mozilla/dom/WindowProxyHolder.h"
--- a/widget/android/fennec/ThumbnailHelper.h
+++ b/widget/android/fennec/ThumbnailHelper.h
@@ -13,22 +13,22 @@
 #include "mozIDOMWindow.h"
 #include "nsAppShell.h"
 #include "nsCOMPtr.h"
 #include "nsGlobalWindowOuter.h"
 #include "nsIChannel.h"
 #include "nsIDOMWindowUtils.h"
 #include "nsIDocShell.h"
 #include "nsIHttpChannel.h"
-#include "nsIPresShell.h"
 #include "nsIURI.h"
 #include "nsPIDOMWindow.h"
 #include "nsPresContext.h"
 
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 
 namespace mozilla {
 
 class ThumbnailHelper final
     : public java::ThumbnailHelper::Natives<ThumbnailHelper> {
   ThumbnailHelper() = delete;
 
   static already_AddRefed<mozIDOMWindowProxy> GetWindowForTab(int32_t aTabId) {
@@ -142,17 +142,17 @@ class ThumbnailHelper final
     RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->CreateDrawTargetForData(
         data, IntSize(aThumbWidth, aThumbHeight), stride,
         is24bit ? SurfaceFormat::B8G8R8A8 : SurfaceFormat::R5G6B5_UINT16);
 
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
 
-    nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
+    RefPtr<PresShell> presShell = presContext->PresShell();
     RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt);
     MOZ_ASSERT(context);  // checked the draw target above
 
     context->SetMatrix(context->CurrentMatrix().PreScale(
         aZoomFactor * float(aThumbWidth) / aPageRect.width,
         aZoomFactor * float(aThumbHeight) / aPageRect.height));
 
     const nsRect drawRect(nsPresContext::CSSPixelsToAppUnits(aPageRect.x),
--- a/widget/nsNativeTheme.cpp
+++ b/widget/nsNativeTheme.cpp
@@ -3,17 +3,16 @@
  * 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 "nsNativeTheme.h"
 #include "nsIWidget.h"
 #include "mozilla/dom/Document.h"
 #include "nsIContent.h"
 #include "nsIFrame.h"
-#include "nsIPresShell.h"
 #include "nsNumberControlFrame.h"
 #include "nsPresContext.h"
 #include "nsString.h"
 #include "nsNameSpaceManager.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsStyleConsts.h"
 #include "nsIComponentManager.h"
 #include "nsPIDOMWindow.h"
@@ -23,16 +22,17 @@
 #include "nsRangeFrame.h"
 #include "nsCSSRendering.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLBodyElement.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/dom/HTMLProgressElement.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsNativeTheme::nsNativeTheme() : mAnimatedContentTimeout(UINT32_MAX) {}