Bug 1507540 part 2. Use more notxpcom attributes in docshell/. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 19 Nov 2018 20:17:53 -0500
changeset 447152 a1e826769668287bd7250e85fa529a6c66bfb495
parent 447151 edff28b27f207b3d6e592b131bd0f7bf94da9982
child 447153 52d07c32fa7c1f4114be113fc857484ed20a1630
push id35067
push userrmaries@mozilla.com
push dateTue, 20 Nov 2018 05:04:04 +0000
treeherdermozilla-central@74c27e915067 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1507540
milestone65.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 1507540 part 2. Use more notxpcom attributes in docshell/. r=smaug
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsDocShellTreeOwner.cpp
docshell/base/nsIContentViewer.idl
docshell/base/nsIDocShell.idl
dom/base/FuzzingFunctions.cpp
dom/base/TextInputProcessor.cpp
dom/base/nsContentUtils.cpp
dom/base/nsDOMWindowUtils.cpp
dom/base/nsFrameLoader.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsJSEnvironment.cpp
dom/canvas/CanvasRenderingContext2D.cpp
dom/events/EventStateManager.cpp
dom/events/IMEContentObserver.cpp
dom/events/TouchEvent.cpp
dom/html/nsGenericHTMLFrameElement.cpp
dom/media/webrtc/MediaEngineTabVideoSource.cpp
gfx/ipc/CrossProcessPaint.cpp
gfx/thebes/gfxSVGGlyphs.cpp
image/SVGDocumentWrapper.cpp
image/SVGDocumentWrapper.h
image/VectorImage.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresContext.cpp
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsSubDocumentFrame.cpp
layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
toolkit/components/sessionstore/nsSessionStoreUtils.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
widget/android/fennec/ThumbnailHelper.h
xpfe/appshell/nsWebShellWindow.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -1110,72 +1110,58 @@ nsDocShell::ValidateOrigin(nsIDocShellTr
   }
 
   return innerOriginURI && innerTargetURI &&
          NS_SUCCEEDED(innerOriginURI->SchemeIs("file", &originIsFile)) &&
          NS_SUCCEEDED(innerTargetURI->SchemeIs("file", &targetIsFile)) &&
          originIsFile && targetIsFile;
 }
 
-nsresult
-nsDocShell::GetEldestPresContext(nsPresContext** aPresContext)
-{
-  NS_ENSURE_ARG_POINTER(aPresContext);
-  *aPresContext = nullptr;
-
-  nsCOMPtr<nsIContentViewer> viewer = mContentViewer;
+nsPresContext*
+nsDocShell::GetEldestPresContext()
+{
+  nsIContentViewer* viewer = mContentViewer;
   while (viewer) {
-    nsCOMPtr<nsIContentViewer> prevViewer;
-    viewer->GetPreviousViewer(getter_AddRefs(prevViewer));
+    nsIContentViewer* prevViewer = viewer->GetPreviousViewer();
     if (!prevViewer) {
-      return viewer->GetPresContext(aPresContext);
+      return viewer->GetPresContext();
     }
     viewer = prevViewer;
   }
 
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDocShell::GetPresContext(nsPresContext** aPresContext)
-{
-  NS_ENSURE_ARG_POINTER(aPresContext);
-  *aPresContext = nullptr;
-
+  return nullptr;
+}
+
+nsPresContext*
+nsDocShell::GetPresContext()
+{
   if (!mContentViewer) {
-    return NS_OK;
-  }
-
-  return mContentViewer->GetPresContext(aPresContext);
-}
-
-NS_IMETHODIMP_(nsIPresShell*)
+    return nullptr;
+  }
+
+  return mContentViewer->GetPresContext();
+}
+
+nsIPresShell*
 nsDocShell::GetPresShell()
 {
-  RefPtr<nsPresContext> presContext;
-  (void)GetPresContext(getter_AddRefs(presContext));
+  nsPresContext* presContext = GetPresContext();
   return presContext ? presContext->GetPresShell() : nullptr;
 }
 
-NS_IMETHODIMP
-nsDocShell::GetEldestPresShell(nsIPresShell** aPresShell)
-{
-  nsresult rv = NS_OK;
-
-  NS_ENSURE_ARG_POINTER(aPresShell);
-  *aPresShell = nullptr;
-
-  RefPtr<nsPresContext> presContext;
-  (void)GetEldestPresContext(getter_AddRefs(presContext));
+nsIPresShell*
+nsDocShell::GetEldestPresShell()
+{
+  nsPresContext* presContext = GetEldestPresContext();
 
   if (presContext) {
-    NS_IF_ADDREF(*aPresShell = presContext->GetPresShell());
-  }
-
-  return rv;
+    return presContext->GetPresShell();
+  }
+
+  return nullptr;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetContentViewer(nsIContentViewer** aContentViewer)
 {
   NS_ENSURE_ARG_POINTER(aContentViewer);
 
   *aContentViewer = mContentViewer;
@@ -3393,28 +3379,26 @@ nsDocShell::SetTreeOwner(nsIDocShellTree
   // and we never set another parent. Given that this is neither expensive nor
   // performance-critical, let's be safe and unconditionally recompute this
   // state whenever dependent state changes.
   RecomputeCanExecuteScripts();
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+void
 nsDocShell::SetChildOffset(int32_t aChildOffset)
 {
   mChildOffset = aChildOffset;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDocShell::GetChildOffset(int32_t* aChildOffset)
-{
-  *aChildOffset = mChildOffset;
-  return NS_OK;
+}
+
+int32_t
+nsDocShell::GetChildOffset()
+{
+  return mChildOffset;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetHistoryID(nsID** aID)
 {
   *aID = mHistoryID.Clone();
   return NS_OK;
 }
@@ -3941,18 +3925,17 @@ nsDocShell::GetContentBlockingLog(Promis
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetDeviceSizeIsPageSize(bool aValue)
 {
   if (mDeviceSizeIsPageSize != aValue) {
     mDeviceSizeIsPageSize = aValue;
-    RefPtr<nsPresContext> presContext;
-    GetPresContext(getter_AddRefs(presContext));
+    RefPtr<nsPresContext> presContext = GetPresContext();
     if (presContext) {
       presContext->MediaFeatureValuesChanged({
         MediaFeatureChangeReason::DeviceSizeIsPageSizeChange });
     }
   }
   return NS_OK;
 }
 
@@ -8103,18 +8086,20 @@ nsDocShell::RestoreFromHistory()
 
   // In cases where we use a transient about:blank viewer between loads,
   // we never show the transient viewer, so _its_ previous viewer is never
   // unhooked from the view hierarchy.  Destroy any such previous viewer now,
   // before we grab the root view sibling, so that we don't grab a view
   // that's about to go away.
 
   if (mContentViewer) {
-    nsCOMPtr<nsIContentViewer> previousViewer;
-    mContentViewer->GetPreviousViewer(getter_AddRefs(previousViewer));
+    // Make sure to hold a strong ref to previousViewer here while we
+    // drop the reference to it from mContentViewer.
+    nsCOMPtr<nsIContentViewer> previousViewer =
+      mContentViewer->GetPreviousViewer();
     if (previousViewer) {
       mContentViewer->SetPreviousViewer(nullptr);
       previousViewer->Destroy();
     }
   }
 
   // Save off the root view's parent and sibling so that we can insert the
   // new content viewer's root view at the same position.  Also save the
@@ -8814,18 +8799,17 @@ nsDocShell::SetupNewViewer(nsIContentVie
   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(getter_AddRefs(shell));
+    nsCOMPtr<nsIPresShell> shell = contentViewer->GetPresShell();
 
     if (shell) {
       bgcolor = shell->GetCanvasBackground();
       isActive = shell->IsActive();
     }
 
     contentViewer->Close(mSavingOldViewer ? mOSHE.get() : nullptr);
     aNewViewer->SetPreviousViewer(contentViewer);
@@ -8873,18 +8857,17 @@ nsDocShell::SetupNewViewer(nsIContentVie
     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(getter_AddRefs(shell));
+  nsCOMPtr<nsIPresShell> shell = mContentViewer->GetPresShell();
 
   if (shell) {
     shell->SetCanvasBackground(bgcolor);
     if (isActive) {
       shell->SetIsActive(isActive);
     }
   }
 
@@ -9994,22 +9977,17 @@ nsDocShell::InternalLoad(nsIURI* aURI,
     // Stop any current network activity.
     // Also stop content if this is a zombie doc. otherwise
     // the onload will be delayed by other loads initiated in the
     // background by the first document that
     // didn't fully load before the next load was initiated.
     // If not a zombie, don't stop content until data
     // starts arriving from the new URI...
 
-    nsCOMPtr<nsIContentViewer> zombieViewer;
-    if (mContentViewer) {
-      mContentViewer->GetPreviousViewer(getter_AddRefs(zombieViewer));
-    }
-
-    if (zombieViewer ||
+    if ((mContentViewer && mContentViewer->GetPreviousViewer()) ||
         LOAD_TYPE_HAS_FLAGS(aLoadType, LOAD_FLAGS_STOP_CONTENT)) {
       rv = Stop(nsIWebNavigation::STOP_ALL);
     } else {
       rv = Stop(nsIWebNavigation::STOP_NETWORK);
     }
 
     if (NS_FAILED(rv)) {
       return rv;
@@ -10034,22 +10012,22 @@ nsDocShell::InternalLoad(nsIURI* aURI,
 
   // If we have a saved content viewer in history, restore and show it now.
   if (aSHEntry && (mLoadType & LOAD_CMD_HISTORY)) {
     // It's possible that the previous viewer of mContentViewer is the
     // viewer that will end up in aSHEntry when it gets closed.  If that's
     // the case, we need to go ahead and force it into its shentry so we
     // can restore it.
     if (mContentViewer) {
-      nsCOMPtr<nsIContentViewer> prevViewer;
-      mContentViewer->GetPreviousViewer(getter_AddRefs(prevViewer));
+      nsCOMPtr<nsIContentViewer> prevViewer =
+        mContentViewer->GetPreviousViewer();
       if (prevViewer) {
 #ifdef DEBUG
-        nsCOMPtr<nsIContentViewer> prevPrevViewer;
-        prevViewer->GetPreviousViewer(getter_AddRefs(prevPrevViewer));
+        nsCOMPtr<nsIContentViewer> prevPrevViewer =
+          prevViewer->GetPreviousViewer();
         NS_ASSERTION(!prevPrevViewer, "Should never have viewer chain here");
 #endif
         nsCOMPtr<nsISHEntry> viewerEntry;
         prevViewer->GetHistoryEntry(getter_AddRefs(viewerEntry));
         if (viewerEntry == aSHEntry) {
           // Make sure this viewer ends up in the right place
           mContentViewer->SetPreviousViewer(nullptr);
           prevViewer->Destroy();
@@ -14079,21 +14057,19 @@ nsDocShell::SetDisplayMode(uint32_t aDis
         aDisplayMode == nsIDocShell::DISPLAY_MODE_FULLSCREEN ||
         aDisplayMode == nsIDocShell::DISPLAY_MODE_MINIMAL_UI)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (aDisplayMode != mDisplayMode) {
     mDisplayMode = aDisplayMode;
 
-    RefPtr<nsPresContext> presContext;
-    if (NS_SUCCEEDED(GetPresContext(getter_AddRefs(presContext)))) {
-      presContext->MediaFeatureValuesChangedAllDocuments({
-        MediaFeatureChangeReason::DisplayModeChange });
-    }
+    RefPtr<nsPresContext> presContext = GetPresContext();
+    presContext->MediaFeatureValuesChangedAllDocuments({
+      MediaFeatureChangeReason::DisplayModeChange });
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetColorMatrix(float* aMatrix, uint32_t aMatrixLen)
 {
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -881,17 +881,17 @@ private: // member functions
   nsresult EnsureScriptEnvironment();
   nsresult EnsureEditorData();
   nsresult EnsureTransferableHookData();
   nsresult EnsureFind();
   nsresult EnsureCommandHandler();
   nsresult RefreshURIFromQueue();
   nsresult Embed(nsIContentViewer* aContentViewer,
                  const char* aCommand, nsISupports* aExtraInfo);
-  nsresult GetEldestPresContext(nsPresContext** aPresContext);
+  nsPresContext* GetEldestPresContext();
   nsresult CheckLoadingPermissions();
   nsresult PersistLayoutHistoryState();
   nsresult LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType);
   nsresult SetBaseUrlForWyciwyg(nsIContentViewer* aContentViewer);
   nsresult GetHttpChannel(nsIChannel* aChannel, nsIHttpChannel** aReturn);
   nsresult ConfirmRepost(bool* aRepost);
   nsresult GetPromptAndStringBundle(nsIPrompt** aPrompt,
                                     nsIStringBundle** aStringBundle);
--- a/docshell/base/nsDocShellTreeOwner.cpp
+++ b/docshell/base/nsDocShellTreeOwner.cpp
@@ -417,18 +417,17 @@ nsDocShellTreeOwner::SizeShellTo(nsIDocS
 
   // Set the preferred Size
   //XXX
   NS_ERROR("Implement this");
   /*
   Set the preferred size on the aShellItem.
   */
 
-  RefPtr<nsPresContext> presContext;
-  mWebBrowser->mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mWebBrowser->mDocShell->GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
   nsIPresShell* presShell = presContext->GetPresShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   NS_ENSURE_SUCCESS(
     presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
     NS_ERROR_FAILURE);
--- a/docshell/base/nsIContentViewer.idl
+++ b/docshell/base/nsIContentViewer.idl
@@ -38,19 +38,19 @@ interface nsIContentViewer : nsISupports
 {
   [noscript] void init(in nsIWidgetPtr aParentWidget,
                        [const] in nsIntRectRef aBounds);
 
   attribute nsIDocShell container;
 
   [noscript,notxpcom,nostdcall] void loadStart(in Document aDoc);
   void loadComplete(in nsresult aStatus);
-  [noscript] readonly attribute boolean loadCompleted;
+  [notxpcom,nostdcall] readonly attribute boolean loadCompleted;
 
-  [noscript] readonly attribute boolean isStopped;
+  [notxpcom,nostdcall] readonly attribute boolean isStopped;
 
   /**
    * aPermitUnloadFlags are passed to PermitUnload to indicate what action to take
    * if a beforeunload handler wants to prompt the user.  It is also used by
    * permitUnloadInternal to ensure we only prompt once.
    *
    * ePrompt: Prompt and return the user's choice (default).
    * eDontPromptAndDontUnload: Don't prompt and return false (unload not permitted)
@@ -148,17 +148,17 @@ interface nsIContentViewer : nsISupports
   const unsigned long eDelayResize = 1;
   [noscript] void setBoundsWithFlags([const] in nsIntRectRef aBounds,
                                      in unsigned long aFlags);
 
   /**
    * The previous content viewer, which has been |close|d but not
    * |destroy|ed.
    */
-  [noscript] attribute nsIContentViewer previousViewer;
+  [notxpcom,nostdcall] attribute nsIContentViewer previousViewer;
 
   void move(in long aX, in long aY);
 
   void show();
   void hide();
 
   attribute boolean sticky;
 
@@ -209,18 +209,20 @@ 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;
 
-  [noscript] readonly attribute nsIPresShellPtr presShell;
-  [noscript] readonly attribute nsPresContextPtr presContext;
+  // presShell can be null.
+  [notxpcom,nostdcall] readonly attribute nsIPresShellPtr 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
    * case, if mParentWidget is null then this document should not even
    * be displayed.
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -233,28 +233,28 @@ interface nsIDocShell : nsIDocShellTreeI
    *        True to fire the unload event in addition to the pagehide event,
    *        and remove all dynamic subframe history entries.
    */
   [noscript] void firePageHideNotification(in boolean isUnload);
 
   /**
    * Presentation context for the currently loaded document.  This may be null.
    */
-  [noscript] readonly attribute nsPresContext presContext;
+  [notxpcom,nostdcall] readonly attribute nsPresContext presContext;
 
   /**
    * Presentation shell for the currently loaded document.  This may be null.
    */
-  [noscript,notxpcom] nsIPresShell GetPresShell();
+  [notxpcom,nostdcall] readonly attribute nsIPresShell presShell;
 
   /**
    * Presentation shell for the oldest document, if this docshell is
    * currently transitioning between documents.
    */
-  [noscript] readonly attribute nsIPresShell eldestPresShell;
+  [notxpcom,nostdcall] readonly attribute nsIPresShell eldestPresShell;
 
   /**
    * Content Viewer that is currently loaded for this DocShell.  This may
    * change as the underlying content changes.
    */
   readonly attribute nsIContentViewer contentViewer;
 
   /**
@@ -554,17 +554,17 @@ interface nsIDocShell : nsIDocShellTreeI
    * until after OnLocationChange fires.
    */
   readonly attribute nsIChannel currentDocumentChannel;
 
   /**
    * The original offset of this child in its container. This property is -1 for
    * dynamically added docShells.
    */
-  [noscript] attribute long childOffset;
+  [notxpcom,nostdcall] attribute long childOffset;
 
   /**
    * Find out whether the docshell is currently in the middle of a page
    * transition. This is set just before the pagehide/unload events fire.
    */
   readonly attribute boolean isInUnload;
 
   /**
--- a/dom/base/FuzzingFunctions.cpp
+++ b/dom/base/FuzzingFunctions.cpp
@@ -285,18 +285,17 @@ FuzzingFunctions::SynthesizeKeyboardEven
   }
 
   nsIDocShell* docShell = activeWindow->GetDocShell();
   if (NS_WARN_IF(!docShell)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
-  RefPtr<nsPresContext> presContext;
-  docShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = docShell->GetPresContext();
   if (NS_WARN_IF(!presContext)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   event.mWidget = presContext->GetRootWidget();
   if (NS_WARN_IF(!event.mWidget)) {
     aRv.Throw(NS_ERROR_FAILURE);
--- a/dom/base/TextInputProcessor.cpp
+++ b/dom/base/TextInputProcessor.cpp
@@ -387,21 +387,17 @@ TextInputProcessor::BeginInputTransactio
   nsCOMPtr<nsPIDOMWindowInner> pWindow = nsPIDOMWindowInner::From(aWindow);
   if (NS_WARN_IF(!pWindow)) {
     return NS_ERROR_INVALID_ARG;
   }
   nsCOMPtr<nsIDocShell> docShell(pWindow->GetDocShell());
   if (NS_WARN_IF(!docShell)) {
     return NS_ERROR_FAILURE;
   }
-  RefPtr<nsPresContext> presContext;
-  nsresult rv = docShell->GetPresContext(getter_AddRefs(presContext));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
+  RefPtr<nsPresContext> presContext = docShell->GetPresContext();
   if (NS_WARN_IF(!presContext)) {
     return NS_ERROR_FAILURE;
   }
   nsCOMPtr<nsIWidget> widget = presContext->GetRootWidget();
   if (NS_WARN_IF(!widget)) {
     return NS_ERROR_FAILURE;
   }
 
@@ -440,16 +436,17 @@ TextInputProcessor::BeginInputTransactio
     mDispatcher->EndInputTransaction(this);
     if (NS_WARN_IF(mDispatcher)) {
       // Forcibly initialize the members if we failed to end the input
       // transaction.
       UnlinkFromTextEventDispatcher();
     }
   }
 
+  nsresult rv = NS_OK;
   if (aForTests) {
     bool isAPZAware = gfxPrefs::TestEventsAsyncEnabled();
     rv = dispatcher->BeginTestInputTransaction(this, isAPZAware);
   } else {
     rv = dispatcher->BeginInputTransaction(this);
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -6623,24 +6623,21 @@ nsContentUtils::IsSubDocumentTabbable(ns
   }
 
   nsCOMPtr<nsIContentViewer> contentViewer;
   docShell->GetContentViewer(getter_AddRefs(contentViewer));
   if (!contentViewer) {
     return false;
   }
 
-  nsCOMPtr<nsIContentViewer> zombieViewer;
-  contentViewer->GetPreviousViewer(getter_AddRefs(zombieViewer));
-
   // If there are 2 viewers for the current docshell, that
   // means the current document may be a zombie document.
   // While load and pageshow events are dispatched, zombie viewer is the old,
   // to be hidden document.
-  if (zombieViewer) {
+  if (contentViewer->GetPreviousViewer()) {
     bool inOnLoad = false;
     docShell->GetIsExecutingOnLoadHandler(&inOnLoad);
     return inOnLoad;
   }
 
   return true;
 }
 
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -238,19 +238,17 @@ nsPresContext*
 nsDOMWindowUtils::GetPresContext()
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
   if (!window)
     return nullptr;
   nsIDocShell *docShell = window->GetDocShell();
   if (!docShell)
     return nullptr;
-  RefPtr<nsPresContext> presContext;
-  docShell->GetPresContext(getter_AddRefs(presContext));
-  return presContext;
+  return docShell->GetPresContext();
 }
 
 nsIDocument*
 nsDOMWindowUtils::GetDocument()
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
   if (!window) {
     return nullptr;
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -813,18 +813,17 @@ nsFrameLoader::MarginsChanged(uint32_t a
       if (cur->IsHTMLElement(nsGkAtoms::body)) {
         static_cast<HTMLBodyElement*>(cur)->ClearMappedServoStyle();
       }
     }
   }
 
   // Trigger a restyle if there's a prescontext
   // FIXME: This could do something much less expensive.
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (presContext)
     // rebuild, because now the same nsMappedAttributes* will produce
     // a different style
     presContext->RebuildAllStyleData(nsChangeHint(0), eRestyle_Subtree);
 }
 
 bool
 nsFrameLoader::ShowRemoteFrame(const ScreenIntSize& size,
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -3107,79 +3107,74 @@ nsGlobalWindowOuter::SetNameOuter(const 
 
 // Helper functions used by many methods below.
 int32_t
 nsGlobalWindowOuter::DevToCSSIntPixels(int32_t px)
 {
   if (!mDocShell)
     return px; // assume 1:1
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext)
     return px;
 
   return presContext->DevPixelsToIntCSSPixels(px);
 }
 
 int32_t
 nsGlobalWindowOuter::CSSToDevIntPixels(int32_t px)
 {
   if (!mDocShell)
     return px; // assume 1:1
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext)
     return px;
 
   return presContext->CSSPixelsToDevPixels(px);
 }
 
 nsIntSize
 nsGlobalWindowOuter::DevToCSSIntPixels(nsIntSize px)
 {
   if (!mDocShell)
     return px; // assume 1:1
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext)
     return px;
 
   return nsIntSize(
       presContext->DevPixelsToIntCSSPixels(px.width),
       presContext->DevPixelsToIntCSSPixels(px.height));
 }
 
 nsIntSize
 nsGlobalWindowOuter::CSSToDevIntPixels(nsIntSize px)
 {
   if (!mDocShell)
     return px; // assume 1:1
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext)
     return px;
 
   return nsIntSize(
     presContext->CSSPixelsToDevPixels(px.width),
     presContext->CSSPixelsToDevPixels(px.height));
 }
 
 nsresult
 nsGlobalWindowOuter::GetInnerSize(CSSIntSize& aSize)
 {
   EnsureSizeAndPositionUpToDate();
 
   NS_ENSURE_STATE(mDocShell);
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   RefPtr<nsIPresShell> presShell = mDocShell->GetPresShell();
 
   if (!presContext || !presShell) {
     aSize = CSSIntSize(0, 0);
     return NS_OK;
   }
 
   /*
@@ -3397,18 +3392,17 @@ nsGlobalWindowOuter::GetScreenXY(CallerT
   if (!treeOwnerAsWin) {
     aError.Throw(NS_ERROR_FAILURE);
     return CSSIntPoint(0, 0);
   }
 
   int32_t x = 0, y = 0;
   aError = treeOwnerAsWin->GetPosition(&x, &y); // LayoutDevice px values
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext) {
     return CSSIntPoint(x, y);
   }
 
   // Find the global desktop coordinate of the top-left of the screen.
   // We'll use this as a "fake origin" when converting to CSS px units,
   // to avoid overlapping coordinates in cases such as a hi-dpi screen
   // placed to the right of a lo-dpi screen on Windows. (Instead, there
@@ -3488,18 +3482,17 @@ nsGlobalWindowOuter::GetMozInnerScreenYO
 
 double
 nsGlobalWindowOuter::GetDevicePixelRatioOuter(CallerType aCallerType)
 {
   if (!mDocShell) {
     return 1.0;
   }
 
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext) {
     return 1.0;
   }
 
   if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return 1.0;
   }
 
@@ -3642,18 +3635,17 @@ nsGlobalWindowOuter::SetDocShellWidthAnd
 
   return NS_OK;
 }
 
 // NOTE: Arguments to this function should have values in app units
 void
 nsGlobalWindowOuter::SetCSSViewportWidthAndHeight(nscoord aInnerWidth, nscoord aInnerHeight)
 {
-  RefPtr<nsPresContext> presContext;
-  mDocShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
 
   nsRect shellArea = presContext->GetVisibleArea();
   shellArea.SetHeight(aInnerHeight);
   shellArea.SetWidth(aInnerWidth);
 
   presContext->SetVisibleArea(shellArea);
 }
 
@@ -4833,17 +4825,17 @@ nsGlobalWindowOuter::FocusOuter(ErrorRes
       GetPrivateRoot() == this && mDoc) {
     nsIURI* ourURI = mDoc->GetDocumentURI();
     if (ourURI) {
       lookForPresShell = !NS_IsAboutBlank(ourURI);
     }
   }
 
   if (lookForPresShell) {
-    mDocShell->GetEldestPresShell(getter_AddRefs(presShell));
+    presShell = mDocShell->GetEldestPresShell();
   }
 
   nsCOMPtr<nsIDocShellTreeItem> parentDsti;
   mDocShell->GetParent(getter_AddRefs(parentDsti));
 
   // set the parent's current focus to the frame containing this window.
   nsCOMPtr<nsPIDOMWindowOuter> parent =
     parentDsti ? parentDsti->GetWindow() : nullptr;
@@ -7470,17 +7462,17 @@ nsGlobalWindowOuter::SetCursorOuter(cons
     nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(aCursor);
     if (!nsCSSProps::FindKeyword(keyword, nsCSSProps::kCursorKTable, cursor)) {
       return;
     }
   }
 
   RefPtr<nsPresContext> presContext;
   if (mDocShell) {
-    mDocShell->GetPresContext(getter_AddRefs(presContext));
+    presContext = mDocShell->GetPresContext();
   }
 
   if (presContext) {
     // Need root widget.
     nsCOMPtr<nsIPresShell> presShell = mDocShell->GetPresShell();
     if (!presShell) {
       aError.Throw(NS_ERROR_FAILURE);
       return;
@@ -7644,18 +7636,17 @@ nsGlobalWindowOuter::ReportLargeAllocSta
 
 // Helper called by methods that move/resize the window,
 // to ensure the presContext (if any) is aware of resolution
 // change that may happen in multi-monitor configuration.
 void
 nsGlobalWindowOuter::CheckForDPIChange()
 {
   if (mDocShell) {
-    RefPtr<nsPresContext> presContext;
-    mDocShell->GetPresContext(getter_AddRefs(presContext));
+    RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
     if (presContext) {
       if (presContext->DeviceContext()->CheckDPIChange()) {
         presContext->UIResolutionChanged();
       }
     }
   }
 }
 
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -394,18 +394,17 @@ bool
 NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
                      const ErrorEventInit &aErrorEventInit,
                      nsEventStatus *aStatus)
 {
   bool called = false;
   nsCOMPtr<nsPIDOMWindowInner> win(do_QueryInterface(aScriptGlobal));
   nsIDocShell *docShell = win ? win->GetDocShell() : nullptr;
   if (docShell) {
-    RefPtr<nsPresContext> presContext;
-    docShell->GetPresContext(getter_AddRefs(presContext));
+    RefPtr<nsPresContext> presContext = docShell->GetPresContext();
 
     static int32_t errorDepth; // Recursion prevention
     ++errorDepth;
 
     if (errorDepth < 2) {
       // Dispatch() must be synchronous for the recursion block
       // (errorDepth) to work.
       RefPtr<ErrorEvent> event =
@@ -444,18 +443,17 @@ public:
     MOZ_ASSERT(NS_IsMainThread());
     // First, notify the DOM that we have a script error, but only if
     // our window is still the current inner.
     JS::RootingContext* rootingCx = RootingCx();
     if (win->IsCurrentInnerWindow() && win->GetDocShell() && !sHandlingScriptError) {
       AutoRestore<bool> recursionGuard(sHandlingScriptError);
       sHandlingScriptError = true;
 
-      RefPtr<nsPresContext> presContext;
-      win->GetDocShell()->GetPresContext(getter_AddRefs(presContext));
+      RefPtr<nsPresContext> presContext = win->GetDocShell()->GetPresContext();
 
       RootedDictionary<ErrorEventInit> init(rootingCx);
       init.mCancelable = true;
       init.mFilename = mReport->mFileName;
       init.mBubbles = true;
 
       NS_NAMED_LITERAL_STRING(xoriginMsg, "Script error.");
       if (!mReport->mIsMuted) {
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -5283,17 +5283,17 @@ CanvasRenderingContext2D::DrawWindow(nsG
   EnsureTarget(discardContent ? &drawRect : nullptr);
   if (!IsTargetValid()) {
     return;
   }
 
   RefPtr<nsPresContext> presContext;
   nsIDocShell* docshell = aWindow.GetDocShell();
   if (docshell) {
-    docshell->GetPresContext(getter_AddRefs(presContext));
+    presContext = docshell->GetPresContext();
   }
   if (!presContext) {
     aError.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   nscolor backgroundColor;
   if (!ParseColor(aBgColor, &backgroundColor)) {
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -4358,18 +4358,17 @@ EventStateManager::NotifyMouseOut(Widget
 
   if (wrapper->mLastOverFrame) {
     // if the frame is associated with a subdocument,
     // tell the subdocument that we're moving out of it
     nsSubDocumentFrame* subdocFrame = do_QueryFrame(wrapper->mLastOverFrame.GetFrame());
     if (subdocFrame) {
       nsIDocShell* docshell = subdocFrame->GetDocShell();
       if (docshell) {
-        RefPtr<nsPresContext> presContext;
-        docshell->GetPresContext(getter_AddRefs(presContext));
+        RefPtr<nsPresContext> presContext = docshell->GetPresContext();
 
         if (presContext) {
           EventStateManager* kidESM = presContext->EventStateManager();
           // Not moving into any element in this subdocument
           kidESM->NotifyMouseOut(aMouseEvent, nullptr);
         }
       }
     }
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -1801,18 +1801,17 @@ IMEContentObserver::AChangeEvent::IsSafe
 /******************************************************************************
  * mozilla::IMEContentObserver::IMENotificationSender
  ******************************************************************************/
 
 void
 IMEContentObserver::IMENotificationSender::Dispatch(nsIDocShell* aDocShell)
 {
   if (XRE_IsContentProcess() && aDocShell) {
-    RefPtr<nsPresContext> presContext;
-    aDocShell->GetPresContext(getter_AddRefs(presContext));
+    RefPtr<nsPresContext> presContext = aDocShell->GetPresContext();
     if (presContext) {
       nsRefreshDriver* refreshDriver = presContext->RefreshDriver();
       if (refreshDriver) {
         refreshDriver->AddEarlyRunner(this);
         return;
       }
     }
   }
--- a/dom/events/TouchEvent.cpp
+++ b/dom/events/TouchEvent.cpp
@@ -280,18 +280,17 @@ TouchEvent::PrefEnabled(nsIDocShell* aDo
           CrashReporter::Annotation::HasDeviceTouchScreen, enabled);
         firstTime = false;
       }
 
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
       if (enabled && aDocShell) {
         // APZ might be disabled on this particular widget, in which case
         // TouchEvent support will also be disabled. Try to detect that.
-        RefPtr<nsPresContext> pc;
-        aDocShell->GetPresContext(getter_AddRefs(pc));
+        RefPtr<nsPresContext> pc = aDocShell->GetPresContext();
         if (pc && pc->GetRootWidget()) {
           enabled &= pc->GetRootWidget()->AsyncPanZoomEnabled();
         }
       }
 #endif
     } else {
       enabled = !!sPrefCacheValue;
     }
--- a/dom/html/nsGenericHTMLFrameElement.cpp
+++ b/dom/html/nsGenericHTMLFrameElement.cpp
@@ -318,18 +318,17 @@ nsGenericHTMLFrameElement::AfterSetAttr(
         nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(docshell);
         if (scrollable) {
           int32_t cur;
           scrollable->GetDefaultScrollbarPreferences(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(getter_AddRefs(presContext));
+            RefPtr<nsPresContext> presContext = docshell->GetPresContext();
             nsIPresShell* shell = presContext ? presContext->GetPresShell() : nullptr;
             nsIFrame* rootScroll = shell ? shell->GetRootScrollFrame() : nullptr;
             if (rootScroll) {
               shell->FrameNeedsReflow(rootScroll, nsIPresShell::eStyleChange,
                                       NS_FRAME_IS_DIRTY);
             }
           }
         }
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -315,25 +315,23 @@ void MediaEngineTabVideoSource::Draw() {
     mData = MakeUniqueFallible<unsigned char[]>(mDataSize);
   }
   if (!mData) {
     return;
   }
 
   nsCOMPtr<nsIPresShell> presShell;
   if (mWindow) {
-    RefPtr<nsPresContext> presContext;
     nsIDocShell* docshell = mWindow->GetDocShell();
     if (docshell) {
-      docshell->GetPresContext(getter_AddRefs(presContext));
+      presShell = docshell->GetPresShell();
     }
-    if (!presContext) {
+    if (!presShell) {
       return;
     }
-    presShell = presContext->PresShell();
   }
 
   RefPtr<layers::ImageContainer> container =
       layers::LayerManager::CreateImageContainer(
           layers::ImageContainer::ASYNCHRONOUS);
   RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(
       gfxPlatform::GetPlatform()->GetSoftwareBackend(), mData.get(), size,
       stride, SurfaceFormat::B8G8R8X8, true);
--- a/gfx/ipc/CrossProcessPaint.cpp
+++ b/gfx/ipc/CrossProcessPaint.cpp
@@ -72,17 +72,17 @@ PaintFragment::Record(nsIDocShell* aDocS
   }
 
   // Flush any pending notifications
   nsContentUtils::FlushLayoutForTree(aDocShell->GetWindow());
 
   // Grab the presentation shell to render
   RefPtr<nsPresContext> presContext;
   if (aDocShell) {
-    aDocShell->GetPresContext(getter_AddRefs(presContext));
+    presContext = aDocShell->GetPresContext();
   }
   if (!presContext) {
     PF_LOG("Couldn't find PresContext.\n");
     return PaintFragment{};
   }
 
   // Initialize the recorder
   SurfaceFormat format = SurfaceFormat::B8G8R8A8;
--- a/gfx/thebes/gfxSVGGlyphs.cpp
+++ b/gfx/thebes/gfxSVGGlyphs.cpp
@@ -149,19 +149,17 @@ gfxSVGGlyphsDocument::SetupPresentation(
     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;
-    rv = viewer->GetPresShell(getter_AddRefs(presShell));
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
     if (!presShell->DidInitialize()) {
         rv = presShell->Initialize();
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     mDocument->FlushPendingNotifications(FlushType::Layout);
 
     if (mDocument->HasAnimationController()) {
--- a/image/SVGDocumentWrapper.cpp
+++ b/image/SVGDocumentWrapper.cpp
@@ -203,18 +203,17 @@ SVGDocumentWrapper::SetCurrentTime(float
   if (svgElem && svgElem->GetCurrentTime() != aTime) {
     svgElem->SetCurrentTime(aTime);
   }
 }
 
 void
 SVGDocumentWrapper::TickRefreshDriver()
 {
-  nsCOMPtr<nsIPresShell> presShell;
-  mViewer->GetPresShell(getter_AddRefs(presShell));
+  nsCOMPtr<nsIPresShell> presShell = mViewer->GetPresShell();
   if (presShell) {
     nsPresContext* presContext = presShell->GetPresContext();
     if (presContext) {
       presContext->RefreshDriver()->DoTick();
     }
   }
 }
 
--- a/image/SVGDocumentWrapper.h
+++ b/image/SVGDocumentWrapper.h
@@ -66,25 +66,20 @@ 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 (by reference) the nsIPresShell for the wrapped document.
-   *
-   * @param[out] aPresShell On success, this will be populated with a pointer
-   *                        to the wrapped document's nsIPresShell.
-   *
-   * @return NS_OK on success, or an error code on failure.
+   * Returns the nsIPresShell for the wrapped document.
    */
-  inline nsresult  GetPresShell(nsIPresShell** aPresShell)
-    { return mViewer->GetPresShell(aPresShell); }
+  inline nsIPresShell* 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
@@ -284,22 +284,18 @@ 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;
-  if (NS_FAILED(mSVGDocumentWrapper->GetPresShell(getter_AddRefs(presShell)))) {
-    NS_WARNING("Unable to draw -- presShell lookup failed");
-    return false;
-  }
-  MOZ_ASSERT(presShell, "GetPresShell succeeded but returned null");
+  nsCOMPtr<nsIPresShell> presShell = mSVGDocumentWrapper->GetPresShell();
+  MOZ_ASSERT(presShell, "GetPresShell returned null for an SVG image?");
 
 #ifdef MOZ_GECKO_PROFILER
   nsIDocument* 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,
                     uri ? uri->GetSpecOrDefault().get() : "N/A"));
 #endif
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -407,19 +407,17 @@ private:
   void ReturnToGalleyPresentation();
 
   // Whether we should attach to the top level widget. This is true if we
   // are sharing/recycling a single base widget and not creating multiple
   // child widgets.
   bool ShouldAttachToTopLevel();
 
 protected:
-  // These return the current shell/prescontext etc.
-  nsIPresShell* GetPresShell();
-  nsPresContext* GetPresContext();
+  // Returns the current viewmanager.  Might be null.
   nsViewManager* GetViewManager();
 
   void DetachFromTopLevelWidget();
 
   // IMPORTANT: The ownership implicit in the following member
   // variables has been explicitly checked and set using nsCOMPtr
   // for owning pointers and raw COM interface pointers for weak
   // (ie, non owning) references. If you add any members to this
@@ -1230,28 +1228,26 @@ nsDocumentViewer::LoadComplete(nsresult 
     mCachedPrintSettings           = nullptr;
     mCachedPrintWebProgressListner = nullptr;
   }
 #endif
 
   return rv;
 }
 
-NS_IMETHODIMP
-nsDocumentViewer::GetLoadCompleted(bool *aOutLoadCompleted)
+bool
+nsDocumentViewer::GetLoadCompleted()
 {
-  *aOutLoadCompleted = mLoaded;
-  return NS_OK;
+  return mLoaded;
 }
 
-NS_IMETHODIMP
-nsDocumentViewer::GetIsStopped(bool* aOutIsStopped)
+bool
+nsDocumentViewer::GetIsStopped()
 {
-  *aOutIsStopped = mStopped;
-  return NS_OK;
+  return mStopped;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::PermitUnload(uint32_t aPermitUnloadFlags, bool *aPermitUnload)
 {
   return PermitUnloadInternal(&aPermitUnloadFlags, aPermitUnload);
 }
 
@@ -1553,25 +1549,23 @@ AttachContainerRecurse(nsIDocShell* aShe
   nsCOMPtr<nsIContentViewer> viewer;
   aShell->GetContentViewer(getter_AddRefs(viewer));
   if (viewer) {
     viewer->SetIsHidden(false);
     nsIDocument* doc = viewer->GetDocument();
     if (doc) {
       doc->SetContainer(static_cast<nsDocShell*>(aShell));
     }
-    RefPtr<nsPresContext> pc;
-    viewer->GetPresContext(getter_AddRefs(pc));
+    RefPtr<nsPresContext> pc = viewer->GetPresContext();
     if (pc) {
       pc->SetContainer(static_cast<nsDocShell*>(aShell));
       nsCOMPtr<nsILinkHandler> handler = do_QueryInterface(aShell);
       pc->SetLinkHandler(handler);
     }
-    nsCOMPtr<nsIPresShell> presShell;
-    viewer->GetPresShell(getter_AddRefs(presShell));
+    nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
     if (presShell) {
       presShell->SetForwardingContainer(WeakPtr<nsDocShell>());
     }
   }
 
   // Now recurse through the children
   int32_t childCount;
   aShell->GetChildCount(&childCount);
@@ -1723,23 +1717,21 @@ DetachContainerRecurse(nsIDocShell *aShe
   // Unhook this docshell's presentation
   nsCOMPtr<nsIContentViewer> viewer;
   aShell->GetContentViewer(getter_AddRefs(viewer));
   if (viewer) {
     nsIDocument* doc = viewer->GetDocument();
     if (doc) {
       doc->SetContainer(nullptr);
     }
-    RefPtr<nsPresContext> pc;
-    viewer->GetPresContext(getter_AddRefs(pc));
+    RefPtr<nsPresContext> pc = viewer->GetPresContext();
     if (pc) {
       pc->Detach();
     }
-    nsCOMPtr<nsIPresShell> presShell;
-    viewer->GetPresShell(getter_AddRefs(presShell));
+    nsCOMPtr<nsIPresShell> presShell = viewer->GetPresShell();
     if (presShell) {
       auto weakShell = static_cast<nsDocShell*>(aShell);
       presShell->SetForwardingContainer(weakShell);
     }
   }
 
   // Now recurse through the children
   int32_t childCount;
@@ -2089,48 +2081,30 @@ nsDocumentViewer::GetPresContext()
 
 nsViewManager*
 nsDocumentViewer::GetViewManager()
 {
   return mViewManager;
 }
 
 NS_IMETHODIMP
-nsDocumentViewer::GetPresShell(nsIPresShell** aResult)
-{
-  nsIPresShell* shell = GetPresShell();
-  NS_IF_ADDREF(*aResult = shell);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDocumentViewer::GetPresContext(nsPresContext** aResult)
-{
-  nsPresContext* pc = GetPresContext();
-  NS_IF_ADDREF(*aResult = pc);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDocumentViewer::GetBounds(nsIntRect& aResult)
 {
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
   aResult = mBounds;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDocumentViewer::GetPreviousViewer(nsIContentViewer** aViewer)
+nsIContentViewer*
+nsDocumentViewer::GetPreviousViewer()
 {
-  *aViewer = mPreviousViewer;
-  NS_IF_ADDREF(*aViewer);
-  return NS_OK;
+  return mPreviousViewer;
 }
 
-NS_IMETHODIMP
+void
 nsDocumentViewer::SetPreviousViewer(nsIContentViewer* aViewer)
 {
   // NOTE:  |Show| sets |mPreviousViewer| to null without calling this
   // function.
 
   if (aViewer) {
     NS_ASSERTION(!mPreviousViewer,
                  "can't set previous viewer when there already is one");
@@ -2140,27 +2114,28 @@ nsDocumentViewer::SetPreviousViewer(nsIC
     // whole chain of viewers.  In order to avoid this, we always set our previous
     // viewer to the MOST previous viewer in the chain, and then dump the intermediate
     // link from the chain.  This ensures that at most only 2 documents are alive
     // and undestroyed at any given time (the one that is showing and the one that
     // is loading with painting suppressed).
     // It's very important that if this ever gets changed the code
     // before the RestorePresentation call in nsDocShell::InternalLoad
     // be changed accordingly.
-    nsCOMPtr<nsIContentViewer> prevViewer;
-    aViewer->GetPreviousViewer(getter_AddRefs(prevViewer));
+    //
+    // Make sure we hold a strong ref to prevViewer here, since we'll
+    // tell aViewer to drop it.
+    nsCOMPtr<nsIContentViewer> prevViewer = aViewer->GetPreviousViewer();
     if (prevViewer) {
       aViewer->SetPreviousViewer(nullptr);
       aViewer->Destroy();
       return SetPreviousViewer(prevViewer);
     }
   }
 
   mPreviousViewer = aViewer;
-  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetBoundsWithFlags(const nsIntRect& aBounds, uint32_t aFlags)
 {
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
 
   mBounds = aBounds;
@@ -2871,18 +2846,17 @@ NS_IMETHODIMP nsDocumentViewer::SetComma
   root->SetPopupNode(aNode);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDocumentViewer::ScrollToNode(nsINode* aNode)
 {
   NS_ENSURE_ARG(aNode);
   NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
-  nsCOMPtr<nsIPresShell> presShell;
-  NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);
+  nsCOMPtr<nsIPresShell> presShell = GetPresShell();
 
   // Get the nsIContent interface, because that's what we need to
   // get the primary frame
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
   // Tell the PresShell to scroll to the primary frame of the content.
@@ -3516,18 +3490,17 @@ nsDocumentViewer::ResumePainting()
 }
 
 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(getter_AddRefs(presShell));
+  nsCOMPtr<nsIPresShell> 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);
@@ -3540,18 +3513,17 @@ nsDocumentViewer::GetContentSizeInternal
   if (prefWidth > aMaxWidth) {
     prefWidth = aMaxWidth;
   }
 
   nsresult rv = presShell->ResizeReflow(prefWidth, aMaxHeight, 0, 0,
                                         nsIPresShell::ResizeReflowOptions::eBSizeLimit);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  RefPtr<nsPresContext> presContext;
-  GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
   // Protect against bogus returns here
   nsRect shellArea = presContext->GetVisibleArea();
   NS_ENSURE_TRUE(shellArea.width != NS_UNCONSTRAINEDSIZE &&
                  shellArea.height != NS_UNCONSTRAINEDSIZE,
                  NS_ERROR_FAILURE);
 
@@ -3577,18 +3549,17 @@ nsDocumentViewer::GetContentSize(int32_t
 
   return GetContentSizeInternal(aWidth, aHeight, NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::GetContentSizeConstrained(int32_t aMaxWidth, int32_t aMaxHeight,
                                             int32_t* aWidth, int32_t* aHeight)
 {
-  RefPtr<nsPresContext> presContext;
-  GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
   nscoord maxWidth = NS_UNCONSTRAINEDSIZE;
   nscoord maxHeight = NS_UNCONSTRAINEDSIZE;
   if (aMaxWidth > 0) {
     maxWidth = presContext->DevPixelsToAppUnits(aMaxWidth);
   }
   if (aMaxHeight > 0) {
@@ -3793,18 +3764,17 @@ nsDocViewerFocusListener::nsDocViewerFoc
 
 nsDocViewerFocusListener::~nsDocViewerFocusListener(){}
 
 nsresult
 nsDocViewerFocusListener::HandleEvent(Event* aEvent)
 {
   NS_ENSURE_STATE(mDocViewer);
 
-  nsCOMPtr<nsIPresShell> shell;
-  mDocViewer->GetPresShell(getter_AddRefs(shell));
+  nsCOMPtr<nsIPresShell> shell = mDocViewer->GetPresShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(shell);
   int16_t selectionStatus;
   selCon->GetDisplaySelection(&selectionStatus);
 
   nsAutoString eventType;
   aEvent->GetType(eventType);
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -7642,18 +7642,17 @@ nsLayoutUtils::GetDeviceContextForScreen
     nsCOMPtr<nsPIDOMWindowOuter> win = docShell->GetWindow();
     if (!win) {
       // No reason to go on
       return nullptr;
     }
 
     win->EnsureSizeAndPositionUpToDate();
 
-    RefPtr<nsPresContext> presContext;
-    docShell->GetPresContext(getter_AddRefs(presContext));
+    RefPtr<nsPresContext> presContext = docShell->GetPresContext();
     if (presContext) {
       nsDeviceContext* context = presContext->DeviceContext();
       if (context) {
         return context;
       }
     }
 
     nsCOMPtr<nsIDocShellTreeItem> parentItem;
@@ -9210,19 +9209,18 @@ MaybeReflowForInflationScreenSizeChange(
       nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
       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<nsIPresShell> shell;
             nsCOMPtr<nsIContentViewer> cv = array[i];
-            cv->GetPresShell(getter_AddRefs(shell));
+            nsCOMPtr<nsIPresShell> shell = cv->GetPresShell();
             if (shell) {
               nsIFrame *rootFrame = shell->GetRootFrame();
               if (rootFrame) {
                 shell->FrameNeedsReflow(rootFrame,
                                         nsIPresShell::eStyleChange,
                                         NS_FRAME_IS_DIRTY);
               }
             }
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -2063,25 +2063,21 @@ nsPresContext::SetPrintSettings(nsIPrint
 bool
 nsPresContext::EnsureVisible()
 {
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   if (docShell) {
     nsCOMPtr<nsIContentViewer> cv;
     docShell->GetContentViewer(getter_AddRefs(cv));
     // Make sure this is the content viewer we belong with
-    if (cv) {
-      RefPtr<nsPresContext> currentPresContext;
-      cv->GetPresContext(getter_AddRefs(currentPresContext));
-      if (currentPresContext == this) {
-        // OK, this is us.  We want to call Show() on the content viewer.
-        nsresult result = cv->Show();
-        if (NS_SUCCEEDED(result)) {
-          return true;
-        }
+    if (cv && cv->GetPresContext() == this) {
+      // OK, this is us.  We want to call Show() on the content viewer.
+      nsresult result = cv->Show();
+      if (NS_SUCCEEDED(result)) {
+        return true;
       }
     }
   }
   return false;
 }
 
 #ifdef MOZ_REFLOW_PERF
 void
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -4584,18 +4584,18 @@ ScrollFrameHelper::ScrollToRestoredPosit
 auto
 ScrollFrameHelper::GetPageLoadingState() -> LoadingState
 {
   bool loadCompleted = false, stopped = false;
   nsCOMPtr<nsIDocShell> ds = mOuter->GetContent()->GetComposedDoc()->GetDocShell();
   if (ds) {
     nsCOMPtr<nsIContentViewer> cv;
     ds->GetContentViewer(getter_AddRefs(cv));
-    cv->GetLoadCompleted(&loadCompleted);
-    cv->GetIsStopped(&stopped);
+    loadCompleted = cv->GetLoadCompleted();
+    stopped = cv->GetIsStopped();
   }
   return loadCompleted ? (stopped ? LoadingState::Stopped : LoadingState::Loaded)
                        : LoadingState::Loading;
 }
 
 nsresult
 ScrollFrameHelper::FireScrollPortEvent()
 {
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -1207,29 +1207,26 @@ EndSwapDocShellsForDocument(nsIDocument*
   // Our docshell and view trees have been updated for the new hierarchy.
   // Now also update all nsDeviceContext::mWidget to that of the
   // container view in the new hierarchy.
   nsCOMPtr<nsIDocShell> ds = aDocument->GetDocShell();
   if (ds) {
     nsCOMPtr<nsIContentViewer> cv;
     ds->GetContentViewer(getter_AddRefs(cv));
     while (cv) {
-      RefPtr<nsPresContext> pc;
-      cv->GetPresContext(getter_AddRefs(pc));
+      RefPtr<nsPresContext> pc = cv->GetPresContext();
       if (pc && pc->GetPresShell()) {
         pc->GetPresShell()->SetNeverPainting(ds->IsInvisible());
       }
       nsDeviceContext* dc = pc ? pc->DeviceContext() : nullptr;
       if (dc) {
         nsView* v = cv->FindContainerView();
         dc->Init(v ? v->GetNearestWidget(nullptr) : nullptr);
       }
-      nsCOMPtr<nsIContentViewer> prev;
-      cv->GetPreviousViewer(getter_AddRefs(prev));
-      cv = prev;
+      cv = cv->GetPreviousViewer();
     }
   }
 
   aDocument->EnumerateActivityObservers(
     nsPluginFrame::EndSwapDocShells, nullptr);
   aDocument->EnumerateSubDocuments(EndSwapDocShellsForDocument, nullptr);
   return true;
 }
--- a/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
+++ b/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
@@ -36,25 +36,23 @@ doc_viewer(nsIDocShell *aDocShell)
 {
     if (!aDocShell)
         return nullptr;
     nsCOMPtr<nsIContentViewer> result;
     aDocShell->GetContentViewer(getter_AddRefs(result));
     return result.forget();
 }
 
-static already_AddRefed<nsIPresShell>
+static nsIPresShell*
 pres_shell(nsIDocShell *aDocShell)
 {
     nsCOMPtr<nsIContentViewer> cv = doc_viewer(aDocShell);
     if (!cv)
         return nullptr;
-    nsCOMPtr<nsIPresShell> result;
-    cv->GetPresShell(getter_AddRefs(result));
-    return result.forget();
+    return cv->GetPresShell();
 }
 
 static nsViewManager*
 view_manager(nsIDocShell *aDocShell)
 {
     nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell));
     if (!shell)
         return nullptr;
--- a/toolkit/components/sessionstore/nsSessionStoreUtils.cpp
+++ b/toolkit/components/sessionstore/nsSessionStoreUtils.cpp
@@ -106,20 +106,17 @@ nsSessionStoreUtils::ForEachNonDynamicCh
     NS_ENSURE_TRUE(childDocShell, NS_ERROR_FAILURE);
 
     bool isDynamic = false;
     nsresult rv = childDocShell->GetCreatedDynamically(&isDynamic);
     if (NS_SUCCEEDED(rv) && isDynamic) {
       continue;
     }
 
-    int32_t childOffset = 0;
-    rv = childDocShell->GetChildOffset(&childOffset);
-    NS_ENSURE_SUCCESS(rv, rv);
-
+    int32_t childOffset = childDocShell->GetChildOffset();
     aCallback->HandleFrame(item->GetWindow(), childOffset);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSessionStoreUtils::AddDynamicFrameFilteredListener(EventTarget* aTarget,
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -780,18 +780,17 @@ nsTypeAheadFind::GetSearchContainers(nsI
   *aPresContext = nullptr;
 
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
   if (!docShell)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
 
-  RefPtr<nsPresContext> presContext;
-  docShell->GetPresContext(getter_AddRefs(presContext));
+  RefPtr<nsPresContext> presContext = docShell->GetPresContext();
 
   if (!presShell || !presContext)
     return NS_ERROR_FAILURE;
 
   nsIDocument* doc = presShell->GetDocument();
 
   if (!doc)
     return NS_ERROR_FAILURE;
--- a/widget/android/fennec/ThumbnailHelper.h
+++ b/widget/android/fennec/ThumbnailHelper.h
@@ -124,20 +124,23 @@ class ThumbnailHelper final
     static already_AddRefed<nsIDocShell>
     GetThumbnailAndDocShell(mozIDOMWindowProxy* aWindow,
                             jni::ByteBuffer::Param aData,
                             int32_t aThumbWidth, int32_t aThumbHeight,
                             const CSSRect& aPageRect, float aZoomFactor)
     {
         nsCOMPtr<nsPIDOMWindowOuter> win = nsPIDOMWindowOuter::From(aWindow);
         nsCOMPtr<nsIDocShell> docShell = win->GetDocShell();
-        RefPtr<nsPresContext> presContext;
+ 
+        if (!docShell) {
+            return nullptr;
+        }
 
-        if (!docShell || NS_FAILED(docShell->GetPresContext(
-                getter_AddRefs(presContext))) || !presContext) {
+        RefPtr<nsPresContext> presContext = docShell->GetPresContext();
+        if (!presContext) {
             return nullptr;
         }
 
         uint8_t* const data = static_cast<uint8_t*>(aData->Address());
         if (!data) {
             return nullptr;
         }
 
--- a/xpfe/appshell/nsWebShellWindow.cpp
+++ b/xpfe/appshell/nsWebShellWindow.cpp
@@ -707,18 +707,17 @@ bool nsWebShellWindow::ExecuteCloseHandl
   if (mDocShell) {
     eventTarget = do_QueryInterface(mDocShell->GetWindow());
   }
 
   if (eventTarget) {
     nsCOMPtr<nsIContentViewer> contentViewer;
     mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
     if (contentViewer) {
-      RefPtr<nsPresContext> presContext;
-      contentViewer->GetPresContext(getter_AddRefs(presContext));
+      RefPtr<nsPresContext> presContext = contentViewer->GetPresContext();
 
       nsEventStatus status = nsEventStatus_eIgnore;
       WidgetMouseEvent event(true, eClose, nullptr,
                              WidgetMouseEvent::eReal);
 
       nsresult rv = EventDispatcher::Dispatch(eventTarget, presContext,
                                               &event, nullptr, &status);
       if (NS_SUCCEEDED(rv) && status == nsEventStatus_eConsumeNoDefault)