Bug 1544215 - Make nsIContentVewer::GetPresShell() return mozilla::PresShell instead of nsIPresShell r=bzbarsky
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 16 Apr 2019 02:47:26 +0000
changeset 469607 38ecdf260ccd
parent 469591 be3f40425b52
child 469608 c918588ff945
push id35876
push useropoprus@mozilla.com
push dateTue, 16 Apr 2019 09:47:48 +0000
treeherdermozilla-central@fe4a28a68cfc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1544215
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 1544215 - Make nsIContentVewer::GetPresShell() return mozilla::PresShell instead of nsIPresShell r=bzbarsky Additionally, this patch makes `nsDocumentViewer` which is the only implementation of `nsIContentViewer` use `mozilla::PresShell` directly rather than via `nsIPresShell`. Differential Revision: https://phabricator.services.mozilla.com/D27470
docshell/base/nsDocShell.cpp
docshell/base/nsIContentViewer.idl
gfx/thebes/gfxSVGGlyphs.cpp
gfx/thebes/gfxSVGGlyphs.h
image/SVGDocumentWrapper.cpp
image/SVGDocumentWrapper.h
image/VectorImage.cpp
layout/base/PresShell.h
layout/base/nsDocumentViewer.cpp
layout/base/nsIDocumentViewerPrint.h
layout/base/nsLayoutUtils.cpp
layout/printing/nsPrintJob.cpp
layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8281,21 +8281,19 @@ nsresult nsDocShell::SetupNewViewer(nsIC
   nsCOMPtr<nsIContentViewer> contentViewer = mContentViewer;
   if (contentViewer) {
     // Stop any activity that may be happening in the old document before
     // releasing it...
     contentViewer->Stop();
 
     // Try to extract the canvas background color from the old
     // presentation shell, so we can use it for the next document.
-    nsCOMPtr<nsIPresShell> shell = contentViewer->GetPresShell();
-
-    if (shell) {
-      bgcolor = shell->GetCanvasBackground();
-      isActive = shell->IsActive();
+    if (PresShell* presShell = contentViewer->GetPresShell()) {
+      bgcolor = presShell->GetCanvasBackground();
+      isActive = presShell->IsActive();
     }
 
     contentViewer->Close(mSavingOldViewer ? mOSHE.get() : nullptr);
     aNewViewer->SetPreviousViewer(contentViewer);
   }
   if (mOSHE && (!mContentViewer || !mSavingOldViewer)) {
     // We don't plan to save a viewer in mOSHE; tell it to drop
     // any other state it's holding.
@@ -8334,22 +8332,20 @@ nsresult nsDocShell::SetupNewViewer(nsIC
     NS_ENSURE_SUCCESS(newCv->SetFullZoom(pageZoom), NS_ERROR_FAILURE);
     NS_ENSURE_SUCCESS(newCv->SetOverrideDPPX(overrideDPPX), NS_ERROR_FAILURE);
     NS_ENSURE_SUCCESS(newCv->SetAuthorStyleDisabled(styleDisabled),
                       NS_ERROR_FAILURE);
   }
 
   // Stuff the bgcolor from the old pres shell into the new
   // pres shell. This improves page load continuity.
-  nsCOMPtr<nsIPresShell> shell = mContentViewer->GetPresShell();
-
-  if (shell) {
-    shell->SetCanvasBackground(bgcolor);
+  if (RefPtr<PresShell> presShell = mContentViewer->GetPresShell()) {
+    presShell->SetCanvasBackground(bgcolor);
     if (isActive) {
-      shell->SetIsActive(isActive);
+      presShell->SetIsActive(isActive);
     }
   }
 
   // XXX: It looks like the LayoutState gets restored again in Embed()
   //      right after the call to SetupNewViewer(...)
 
   // We don't show the mContentViewer yet, since we want to draw the old page
   // until we have enough of the new page to show.  Just return with the new
--- a/docshell/base/nsIContentViewer.idl
+++ b/docshell/base/nsIContentViewer.idl
@@ -10,33 +10,33 @@ interface nsIPrintSettings;
 webidl Document;
 webidl Node;
 
 %{ C++
 #include "nsTArray.h"
 #include "nsRect.h"
 
 class nsIWidget;
-class nsIPresShell;
 class nsPresContext;
 class nsView;
 class nsDOMNavigationTiming;
 namespace mozilla {
 class Encoding;
+class PresShell;
 }
 %}
 
 [ptr] native nsIWidgetPtr(nsIWidget);
 [ref] native nsIntRectRef(nsIntRect);
-[ptr] native nsIPresShellPtr(nsIPresShell);
 [ptr] native nsPresContextPtr(nsPresContext);
 [ptr] native nsViewPtr(nsView);
 [ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming);
 [ref] native nsIContentViewerTArray(nsTArray<nsCOMPtr<nsIContentViewer> >);
 [ptr] native Encoding(const mozilla::Encoding);
+[ptr] native PresShellPtr(mozilla::PresShell);
 
 [scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)]
 interface nsIContentViewer : nsISupports
 {
   [noscript] void init(in nsIWidgetPtr aParentWidget,
                        [const] in nsIntRectRef aBounds);
 
   attribute nsIDocShell container;
@@ -210,17 +210,17 @@ interface nsIContentViewer : nsISupports
   /**
    * Returns whether this content viewer is in a hidden state.
    *
    * @note Only Gecko internal code should set the attribute!
    */
   attribute boolean isHidden;
 
   // presShell can be null.
-  [notxpcom,nostdcall] readonly attribute nsIPresShellPtr presShell;
+  [notxpcom,nostdcall] readonly attribute PresShellPtr presShell;
   // presContext can be null.
   [notxpcom,nostdcall] readonly attribute nsPresContextPtr presContext;
   // aDocument must not be null.
   [noscript] void setDocumentInternal(in Document aDocument,
                                       in boolean aForceReuseInnerWindow);
   /**
    * Find the view to use as the container view for MakeWindow. Returns
    * null if this will be the root of a view manager hierarchy. In that
--- a/gfx/thebes/gfxSVGGlyphs.cpp
+++ b/gfx/thebes/gfxSVGGlyphs.cpp
@@ -1,42 +1,42 @@
 /* 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 "gfxSVGGlyphs.h"
 
+#include "mozilla/BasePrincipal.h"
+#include "mozilla/LoadInfo.h"
+#include "mozilla/NullPrincipal.h"
+#include "mozilla/PresShell.h"
+#include "mozilla/SMILAnimationController.h"
 #include "mozilla/SVGContextPaint.h"
+#include "mozilla/dom/Document.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/FontTableURIProtocolHandler.h"
+#include "mozilla/dom/ImageTracker.h"
+#include "mozilla/dom/SVGDocument.h"
 #include "nsError.h"
 #include "nsString.h"
-#include "mozilla/dom/Document.h"
 #include "nsICategoryManager.h"
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIContentViewer.h"
 #include "nsIStreamListener.h"
 #include "nsServiceManagerUtils.h"
-#include "nsIPresShell.h"
 #include "nsNetUtil.h"
 #include "nsIInputStream.h"
 #include "nsStringStream.h"
 #include "nsStreamUtils.h"
 #include "nsIPrincipal.h"
-#include "mozilla/BasePrincipal.h"
-#include "mozilla/dom/Element.h"
-#include "mozilla/dom/FontTableURIProtocolHandler.h"
-#include "mozilla/dom/SVGDocument.h"
-#include "mozilla/LoadInfo.h"
-#include "mozilla/NullPrincipal.h"
-#include "mozilla/SMILAnimationController.h"
 #include "nsSVGUtils.h"
 #include "nsContentUtils.h"
 #include "gfxFont.h"
 #include "gfxContext.h"
 #include "harfbuzz/hb.h"
-#include "mozilla/dom/ImageTracker.h"
 
 #define SVG_CONTENT_TYPE NS_LITERAL_CSTRING("image/svg+xml")
 #define UTF8_CHARSET NS_LITERAL_CSTRING("utf-8")
 
 using namespace mozilla;
 using mozilla::dom::Document;
 using mozilla::dom::Element;
 
@@ -143,17 +143,17 @@ nsresult gfxSVGGlyphsDocument::SetupPres
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = viewer->Init(nullptr, gfx::IntRect(0, 0, 1000, 1000));
   if (NS_SUCCEEDED(rv)) {
     rv = viewer->Open(nullptr, nullptr);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
+  RefPtr<PresShell> presShell = viewer->GetPresShell();
   if (!presShell->DidInitialize()) {
     rv = presShell->Initialize();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   mDocument->FlushPendingNotifications(FlushType::Layout);
 
   if (mDocument->HasAnimationController()) {
--- a/gfx/thebes/gfxSVGGlyphs.h
+++ b/gfx/thebes/gfxSVGGlyphs.h
@@ -59,17 +59,17 @@ class gfxSVGGlyphsDocument final : publi
   void FindGlyphElements(Element *aElement);
 
   void InsertGlyphId(Element *aGlyphElement);
 
   // Weak so as not to create a cycle. mOwner owns us so this can't dangle.
   gfxSVGGlyphs *mOwner;
   RefPtr<mozilla::dom::Document> mDocument;
   nsCOMPtr<nsIContentViewer> mViewer;
-  nsCOMPtr<nsIPresShell> mPresShell;
+  RefPtr<mozilla::PresShell> mPresShell;
 
   nsBaseHashtable<nsUint32HashKey, Element *, Element *> mGlyphIdMap;
 
   nsCString mSVGGlyphsDocumentURI;
 };
 
 /**
  * Used by |gfxFontEntry| to represent the SVG table of an OpenType font.
--- a/image/SVGDocumentWrapper.cpp
+++ b/image/SVGDocumentWrapper.cpp
@@ -1,38 +1,38 @@
 /* -*- 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 "SVGDocumentWrapper.h"
 
+#include "mozilla/PresShell.h"
+#include "mozilla/SMILAnimationController.h"
+#include "mozilla/dom/Document.h"
 #include "mozilla/dom/DocumentTimeline.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/ImageTracker.h"
 #include "mozilla/dom/SVGDocument.h"
+#include "mozilla/dom/SVGSVGElement.h"
 #include "nsICategoryManager.h"
 #include "nsIChannel.h"
 #include "nsIContentViewer.h"
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIHttpChannel.h"
 #include "nsIObserverService.h"
 #include "nsIParser.h"
-#include "nsIPresShell.h"
 #include "nsIRequest.h"
 #include "nsIStreamListener.h"
 #include "nsIXMLContentSink.h"
 #include "nsNetCID.h"
 #include "nsComponentManagerUtils.h"
-#include "mozilla/SMILAnimationController.h"
 #include "nsServiceManagerUtils.h"
-#include "mozilla/dom/SVGSVGElement.h"
 #include "SVGObserverUtils.h"
 #include "nsMimeTypes.h"
-#include "mozilla/dom/Document.h"
-#include "mozilla/dom/ImageTracker.h"
 
 namespace mozilla {
 
 using namespace dom;
 using namespace gfx;
 
 namespace image {
 
@@ -169,20 +169,18 @@ float SVGDocumentWrapper::GetCurrentTime
 void SVGDocumentWrapper::SetCurrentTime(float aTime) {
   SVGSVGElement* svgElem = GetRootSVGElem();
   if (svgElem && svgElem->GetCurrentTimeAsFloat() != aTime) {
     svgElem->SetCurrentTime(aTime);
   }
 }
 
 void SVGDocumentWrapper::TickRefreshDriver() {
-  nsCOMPtr<nsIPresShell> presShell = mViewer->GetPresShell();
-  if (presShell) {
-    nsPresContext* presContext = presShell->GetPresContext();
-    if (presContext) {
+  if (RefPtr<PresShell> presShell = mViewer->GetPresShell()) {
+    if (RefPtr<nsPresContext> presContext = presShell->GetPresContext()) {
       presContext->RefreshDriver()->DoTick();
     }
   }
 }
 
 /** nsIStreamListener methods **/
 
 NS_IMETHODIMP
--- a/image/SVGDocumentWrapper.h
+++ b/image/SVGDocumentWrapper.h
@@ -12,24 +12,24 @@
 
 #include "nsCOMPtr.h"
 #include "nsIStreamListener.h"
 #include "nsIObserver.h"
 #include "nsIContentViewer.h"
 #include "nsWeakReference.h"
 #include "nsSize.h"
 
-class nsIPresShell;
 class nsIRequest;
 class nsILoadGroup;
 class nsIFrame;
 
 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
 
 namespace mozilla {
+class PresShell;
 namespace dom {
 class SVGSVGElement;
 class SVGDocument;
 }  // namespace dom
 
 namespace image {
 
 class SVGDocumentWrapper final : public nsIStreamListener,
@@ -59,19 +59,19 @@ class SVGDocumentWrapper final : public 
   /**
    * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
    *
    * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
    */
   nsIFrame* GetRootLayoutFrame();
 
   /**
-   * Returns the nsIPresShell for the wrapped document.
+   * Returns the mozilla::PresShell for the wrapped document.
    */
-  inline nsIPresShell* GetPresShell() { return mViewer->GetPresShell(); }
+  inline mozilla::PresShell* GetPresShell() { return mViewer->GetPresShell(); }
 
   /**
    * Modifier to update the viewport dimensions of the wrapped document. This
    * method performs a synchronous "FlushType::Layout" on the wrapped document,
    * since a viewport-change affects layout.
    *
    * @param aViewportSize The new viewport dimensions.
    */
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -257,17 +257,17 @@ class SVGDrawingCallback : public gfxDra
 // Based loosely on nsSVGIntegrationUtils' PaintFrameCallback::operator()
 bool SVGDrawingCallback::operator()(gfxContext* aContext,
                                     const gfxRect& aFillRect,
                                     const SamplingFilter aSamplingFilter,
                                     const gfxMatrix& aTransform) {
   MOZ_ASSERT(mSVGDocumentWrapper, "need an SVGDocumentWrapper");
 
   // Get (& sanity-check) the helper-doc's presShell
-  nsCOMPtr<nsIPresShell> presShell = mSVGDocumentWrapper->GetPresShell();
+  RefPtr<PresShell> presShell = mSVGDocumentWrapper->GetPresShell();
   MOZ_ASSERT(presShell, "GetPresShell returned null for an SVG image?");
 
 #ifdef MOZ_GECKO_PROFILER
   Document* doc = presShell->GetDocument();
   nsIURI* uri = doc ? doc->GetDocumentURI() : nullptr;
   AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING(
       "SVG Image drawing", GRAPHICS,
       nsPrintfCString("%dx%d %s", mSize.width, mSize.height,
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -181,16 +181,19 @@ class PresShell final : public nsIPresSh
   void BackingScaleFactorChanged() override {
     mPresContext->UIResolutionChangedSync();
   }
 
   void SynthesizeMouseMove(bool aFromScroll) override;
 
   Document* GetPrimaryContentDocument() override;
 
+  void PausePainting() override;
+  void ResumePainting() 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;
@@ -1311,19 +1314,16 @@ class PresShell final : public nsIPresSh
 
   PresShell* GetRootPresShell();
 
   nscolor GetDefaultBackgroundColorToDraw();
 
   // The callback for the mPaintSuppressionTimer timer.
   static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
 
-  void PausePainting() override;
-  void ResumePainting() override;
-
   //////////////////////////////////////////////////////////////////////////////
   // Approximate frame visibility tracking implementation.
   //////////////////////////////////////////////////////////////////////////////
 
   void UpdateApproximateFrameVisibility();
   void DoUpdateApproximateFrameVisibility(bool aRemoveOnly);
 
   void ClearApproximatelyVisibleFramesList(
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -1478,18 +1478,17 @@ static void AttachContainerRecurse(nsIDo
     if (doc) {
       doc->SetContainer(static_cast<nsDocShell*>(aShell));
     }
     RefPtr<nsPresContext> pc = viewer->GetPresContext();
     if (pc) {
       nsCOMPtr<nsILinkHandler> handler = do_QueryInterface(aShell);
       pc->SetLinkHandler(handler);
     }
-    nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
-    if (presShell) {
+    if (PresShell* presShell = viewer->GetPresShell()) {
       presShell->SetForwardingContainer(WeakPtr<nsDocShell>());
     }
   }
 
   // Now recurse through the children
   int32_t childCount;
   aShell->GetChildCount(&childCount);
   for (int32_t i = 0; i < childCount; ++i) {
@@ -1639,18 +1638,17 @@ static void DetachContainerRecurse(nsIDo
     Document* doc = viewer->GetDocument();
     if (doc) {
       doc->SetContainer(nullptr);
     }
     RefPtr<nsPresContext> pc = viewer->GetPresContext();
     if (pc) {
       pc->Detach();
     }
-    nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
-    if (presShell) {
+    if (PresShell* presShell = viewer->GetPresShell()) {
       auto weakShell = static_cast<nsDocShell*>(aShell);
       presShell->SetForwardingContainer(weakShell);
     }
   }
 
   // Now recurse through the children
   int32_t childCount;
   aShell->GetChildCount(&childCount);
@@ -1969,17 +1967,17 @@ nsDocumentViewer::SetDocumentInternal(Do
 
     mWindow = nullptr;
     rv = InitInternal(mParentWidget, nullptr, mBounds, true, true, false);
   }
 
   return rv;
 }
 
-nsIPresShell* nsDocumentViewer::GetPresShell() { return mPresShell; }
+PresShell* nsDocumentViewer::GetPresShell() { return mPresShell; }
 
 nsPresContext* nsDocumentViewer::GetPresContext() { return mPresContext; }
 
 nsViewManager* nsDocumentViewer::GetViewManager() { return mViewManager; }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetBounds(nsIntRect& aResult) {
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
@@ -3083,44 +3081,42 @@ NS_IMETHODIMP nsDocumentViewer::AppendSu
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::PausePainting() {
   bool enablePaint = false;
   CallChildren(ChangeChildPaintingEnabled, &enablePaint);
 
-  nsIPresShell* presShell = GetPresShell();
-  if (presShell) {
+  if (PresShell* presShell = GetPresShell()) {
     presShell->PausePainting();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::ResumePainting() {
   bool enablePaint = true;
   CallChildren(ChangeChildPaintingEnabled, &enablePaint);
 
-  nsIPresShell* presShell = GetPresShell();
-  if (presShell) {
+  if (PresShell* presShell = GetPresShell()) {
     presShell->ResumePainting();
   }
 
   return NS_OK;
 }
 
 nsresult nsDocumentViewer::GetContentSizeInternal(int32_t* aWidth,
                                                   int32_t* aHeight,
                                                   nscoord aMaxWidth,
                                                   nscoord aMaxHeight) {
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
 
-  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
+  RefPtr<PresShell> presShell = GetPresShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   // Flush out all content and style updates. We can't use a resize reflow
   // because it won't change some sizes that a style change reflow will.
   mDocument->FlushPendingNotifications(FlushType::Layout);
 
   nsIFrame* root = presShell->GetRootFrame();
   NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
@@ -3369,39 +3365,39 @@ NS_IMPL_ISUPPORTS(nsDocViewerFocusListen
 
 nsDocViewerFocusListener::nsDocViewerFocusListener() : mDocViewer(nullptr) {}
 
 nsDocViewerFocusListener::~nsDocViewerFocusListener() {}
 
 nsresult nsDocViewerFocusListener::HandleEvent(Event* aEvent) {
   NS_ENSURE_STATE(mDocViewer);
 
-  nsCOMPtr<nsIPresShell> shell = mDocViewer->GetPresShell();
-  NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(shell);
+  RefPtr<PresShell> presShell = mDocViewer->GetPresShell();
+  NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
+
   int16_t selectionStatus;
-  selCon->GetDisplaySelection(&selectionStatus);
+  presShell->GetDisplaySelection(&selectionStatus);
 
   nsAutoString eventType;
   aEvent->GetType(eventType);
   if (eventType.EqualsLiteral("focus")) {
     // If selection was disabled, re-enable it.
     if (selectionStatus == nsISelectionController::SELECTION_DISABLED ||
         selectionStatus == nsISelectionController::SELECTION_HIDDEN) {
-      selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
-      selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
+      presShell->SetDisplaySelection(nsISelectionController::SELECTION_ON);
+      presShell->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
     }
   } else {
     MOZ_ASSERT(eventType.EqualsLiteral("blur"), "Unexpected event type");
     // If selection was on, disable it.
     if (selectionStatus == nsISelectionController::SELECTION_ON ||
         selectionStatus == nsISelectionController::SELECTION_ATTENTION) {
-      selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
-      selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
+      presShell->SetDisplaySelection(
+          nsISelectionController::SELECTION_DISABLED);
+      presShell->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
     }
   }
 
   return NS_OK;
 }
 
 nsresult nsDocViewerFocusListener::Init(nsDocumentViewer* aDocViewer) {
   mDocViewer = aDocViewer;
@@ -4176,29 +4172,29 @@ bool nsDocumentViewer::IsInitializedForP
 }
 
 void nsDocumentViewer::InitializeForPrintPreview() {
   mInitializedForPrintPreview = true;
 }
 
 void nsDocumentViewer::SetPrintPreviewPresentation(nsViewManager* aViewManager,
                                                    nsPresContext* aPresContext,
-                                                   nsIPresShell* aPresShell) {
+                                                   PresShell* aPresShell) {
   // Protect against pres shell destruction running scripts and re-entrantly
   // creating a new presentation.
   nsAutoScriptBlocker scriptBlocker;
 
   if (mPresShell) {
     DestroyPresShell();
   }
 
   mWindow = nullptr;
   mViewManager = aViewManager;
   mPresContext = aPresContext;
-  mPresShell = static_cast<PresShell*>(aPresShell);
+  mPresShell = aPresShell;
 
   if (ShouldAttachToTopLevel()) {
     DetachFromTopLevelWidget();
     nsView* rootView = mViewManager->GetRootView();
     rootView->AttachToTopLevelWidget(mParentWidget);
     mAttachedToParent = true;
   }
 }
--- a/layout/base/nsIDocumentViewerPrint.h
+++ b/layout/base/nsIDocumentViewerPrint.h
@@ -6,19 +6,19 @@
 
 #ifndef nsIDocumentViewerPrint_h___
 #define nsIDocumentViewerPrint_h___
 
 #include "nsISupports.h"
 #include "mozilla/UniquePtr.h"
 
 namespace mozilla {
+class PresShell;
 class ServoStyleSet;
 }  // namespace mozilla
-class nsIPresShell;
 class nsPresContext;
 class nsViewManager;
 
 // {c6f255cf-cadd-4382-b57f-cd2a9874169b}
 #define NS_IDOCUMENT_VIEWER_PRINT_IID                \
   {                                                  \
     0xc6f255cf, 0xcadd, 0x4382, {                    \
       0xb5, 0x7f, 0xcd, 0x2a, 0x98, 0x74, 0x16, 0x9b \
@@ -59,17 +59,17 @@ class nsIDocumentViewerPrint : public ns
    */
   virtual void InitializeForPrintPreview() = 0;
 
   /**
    * Replaces the current presentation with print preview presentation.
    */
   virtual void SetPrintPreviewPresentation(nsViewManager* aViewManager,
                                            nsPresContext* aPresContext,
-                                           nsIPresShell* aPresShell) = 0;
+                                           mozilla::PresShell* aPresShell) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint,
                               NS_IDOCUMENT_VIEWER_PRINT_IID)
 
 /* Use this macro when declaring classes that implement this interface. */
 #define NS_DECL_NSIDOCUMENTVIEWERPRINT                          \
   void SetIsPrinting(bool aIsPrinting) override;                \
@@ -78,11 +78,11 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumen
   bool GetIsPrintPreview() override;                            \
   void IncrementDestroyBlockedCount() override;                 \
   void DecrementDestroyBlockedCount() override;                 \
   void OnDonePrinting() override;                               \
   bool IsInitializedForPrintPreview() override;                 \
   void InitializeForPrintPreview() override;                    \
   void SetPrintPreviewPresentation(nsViewManager* aViewManager, \
                                    nsPresContext* aPresContext, \
-                                   nsIPresShell* aPresShell) override;
+                                   mozilla::PresShell* aPresShell) override;
 
 #endif /* nsIDocumentViewerPrint_h___ */
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -8803,22 +8803,21 @@ static void MaybeReflowForInflationScree
       if (docShell) {
         nsCOMPtr<nsIContentViewer> cv;
         docShell->GetContentViewer(getter_AddRefs(cv));
         if (cv) {
           nsTArray<nsCOMPtr<nsIContentViewer>> array;
           cv->AppendSubtree(array);
           for (uint32_t i = 0, iEnd = array.Length(); i < iEnd; ++i) {
             nsCOMPtr<nsIContentViewer> cv = array[i];
-            nsCOMPtr<nsIPresShell> shell = cv->GetPresShell();
-            if (shell) {
-              nsIFrame* rootFrame = shell->GetRootFrame();
+            if (RefPtr<PresShell> descendantPresShell = cv->GetPresShell()) {
+              nsIFrame* rootFrame = descendantPresShell->GetRootFrame();
               if (rootFrame) {
-                shell->FrameNeedsReflow(rootFrame, nsIPresShell::eStyleChange,
-                                        NS_FRAME_IS_DIRTY);
+                descendantPresShell->FrameNeedsReflow(
+                    rootFrame, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
               }
             }
           }
         }
       }
     }
   }
 }
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -2277,17 +2277,18 @@ nsresult nsPrintJob::ReflowPrintObject(c
   aPO->mPresContext->SetPageScale(aPO->mZoomRatio);
   // Calculate scale factor from printer to screen
   float printDPI = float(AppUnitsPerCSSInch()) /
                    float(printData->mPrintDC->AppUnitsPerDevPixel());
   aPO->mPresContext->SetPrintPreviewScale(mScreenDPI / printDPI);
 
   if (mIsCreatingPrintPreview && documentIsTopLevel) {
     mDocViewerPrint->SetPrintPreviewPresentation(
-        aPO->mViewManager, aPO->mPresContext, aPO->mPresShell);
+        aPO->mViewManager, aPO->mPresContext,
+        static_cast<PresShell*>(aPO->mPresShell.get()));
   }
 
   rv = aPO->mPresShell->Initialize();
 
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ASSERTION(aPO->mPresShell, "Presshell should still be here");
 
   // Process the reflow event Initialize posted
--- a/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
+++ b/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
@@ -10,50 +10,52 @@
 #include "nsPIDOMWindow.h"
 #include "nsIContentViewer.h"
 
 #include "nsIServiceManager.h"
 #include "nsAtom.h"
 #include "nsQuickSort.h"
 
 #include "nsIContent.h"
-#include "mozilla/dom/Document.h"
 
-#include "nsIPresShell.h"
 #include "nsViewManager.h"
 #include "nsIFrame.h"
 
 #include "nsILayoutDebugger.h"
 #include "nsLayoutCID.h"
 static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
 
 #include "nsISelectionController.h"
+#include "mozilla/dom/Document.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/PresShell.h"
 
 using namespace mozilla;
 using mozilla::dom::Document;
 
 static already_AddRefed<nsIContentViewer> doc_viewer(nsIDocShell* aDocShell) {
   if (!aDocShell) return nullptr;
   nsCOMPtr<nsIContentViewer> result;
   aDocShell->GetContentViewer(getter_AddRefs(result));
   return result.forget();
 }
 
-static nsIPresShell* pres_shell(nsIDocShell* aDocShell) {
+static PresShell* GetPresShell(nsIDocShell* aDocShell) {
   nsCOMPtr<nsIContentViewer> cv = doc_viewer(aDocShell);
   if (!cv) return nullptr;
   return cv->GetPresShell();
 }
 
 static nsViewManager* view_manager(nsIDocShell* aDocShell) {
-  nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell));
-  if (!shell) return nullptr;
-  return shell->GetViewManager();
+  PresShell* presShell = GetPresShell(aDocShell);
+  if (!presShell) {
+    return nullptr;
+  }
+  return presShell->GetViewManager();
 }
 
 #ifdef DEBUG
 static already_AddRefed<Document> document(nsIDocShell* aDocShell) {
   nsCOMPtr<nsIContentViewer> cv(doc_viewer(aDocShell));
   if (!cv) return nullptr;
   RefPtr<Document> result = cv->GetDocument();
   return result.forget();
@@ -241,20 +243,19 @@ NS_IMETHODIMP
 nsLayoutDebuggingTools::GetReflowCounts(bool* aShow) {
   *aShow = mReflowCounts;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLayoutDebuggingTools::SetReflowCounts(bool aShow) {
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
-  nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
-  if (shell) {
+  if (PresShell* presShell = GetPresShell(mDocShell)) {
 #ifdef MOZ_REFLOW_PERF
-    shell->SetPaintFrameCount(aShow);
+    presShell->SetPaintFrameCount(aShow);
     SetBoolPrefAndRefresh("layout.reflow.showframecounts", aShow);
     mReflowCounts = aShow;
 #else
     printf("************************************************\n");
     printf("Sorry, you have not built with MOZ_REFLOW_PERF=1\n");
     printf("************************************************\n");
 #endif
   }
@@ -329,19 +330,18 @@ nsLayoutDebuggingTools::DumpContent() {
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
   DumpContentRecur(mDocShell, stdout);
   return NS_OK;
 }
 
 static void DumpFramesRecur(nsIDocShell* aDocShell, FILE* out) {
 #ifdef DEBUG_FRAME_DUMP
   fprintf(out, "webshell=%p \n", static_cast<void*>(aDocShell));
-  nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell));
-  if (shell) {
-    nsIFrame* root = shell->GetRootFrame();
+  if (PresShell* presShell = GetPresShell(aDocShell)) {
+    nsIFrame* root = presShell->GetRootFrame();
     if (root) {
       root->List(out);
     }
   } else {
     fputs("null pres shell\n", out);
   }
 
   // dump the frames of the sub documents
@@ -399,48 +399,46 @@ nsLayoutDebuggingTools::DumpViews() {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLayoutDebuggingTools::DumpStyleSheets() {
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
 #ifdef DEBUG
   FILE* out = stdout;
-  nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
-  if (shell)
-    shell->ListStyleSheets(out);
-  else
+  if (PresShell* presShell = GetPresShell(mDocShell)) {
+    presShell->ListStyleSheets(out);
+  } else {
     fputs("null pres shell\n", out);
+  }
 #endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLayoutDebuggingTools::DumpComputedStyles() {
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
 #ifdef DEBUG
   FILE* out = stdout;
-  nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
-  if (shell) {
-    shell->ListComputedStyles(out);
+  if (PresShell* presShell = GetPresShell(mDocShell)) {
+    presShell->ListComputedStyles(out);
   } else {
     fputs("null pres shell\n", out);
   }
 #endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLayoutDebuggingTools::DumpReflowStats() {
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
 #ifdef DEBUG
-  nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell));
-  if (shell) {
+  if (RefPtr<PresShell> presShell = GetPresShell(mDocShell)) {
 #  ifdef MOZ_REFLOW_PERF
-    shell->DumpReflows();
+    presShell->DumpReflows();
 #  else
     printf("************************************************\n");
     printf("Sorry, you have not built with MOZ_REFLOW_PERF=1\n");
     printf("************************************************\n");
 #  endif
   }
 #endif
   return NS_OK;