Bug 1543013 - part 2: Make accessible use mozilla::PresShell directly rather than via nsIPresShell r=Jamie
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 13 Apr 2019 12:13:15 +0000
changeset 528219 5e25c38549869fff1216ebfc742df301fa21ac3f
parent 528218 7f7f40328e31e35e21ec587ddc5320688f5e8469
child 528220 45bf2b32a37712dbdf69b943994a37ae6afc4eb1
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1543013
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 1543013 - part 2: Make accessible use mozilla::PresShell directly rather than via nsIPresShell r=Jamie This patch makes accessible module use `mozilla::PresShell` directly rather than via `nsIPresShell`. Additionally, renames `DocAccessible::PresShell()` to `DocAccessible::PresShellPtr()` for avoiding conflict with using `PresShell` in it and its sub classes. Differential Revision: https://phabricator.services.mozilla.com/D26663
accessible/android/DocAccessibleWrap.cpp
accessible/android/DocAccessibleWrap.h
accessible/android/RootAccessibleWrap.cpp
accessible/android/RootAccessibleWrap.h
accessible/android/SessionAccessibility.cpp
accessible/atk/DocAccessibleWrap.cpp
accessible/atk/DocAccessibleWrap.h
accessible/base/DocManager.h
accessible/base/NotificationController.cpp
accessible/base/NotificationController.h
accessible/base/SelectionManager.cpp
accessible/base/SelectionManager.h
accessible/base/nsAccUtils.h
accessible/base/nsAccessibilityService.cpp
accessible/base/nsAccessibilityService.h
accessible/base/nsCoreUtils.cpp
accessible/base/nsCoreUtils.h
accessible/generic/Accessible-inl.h
accessible/generic/Accessible.cpp
accessible/generic/DocAccessible.cpp
accessible/generic/DocAccessible.h
accessible/generic/HyperTextAccessible.cpp
accessible/generic/RootAccessible.cpp
accessible/generic/RootAccessible.h
accessible/html/HTMLTableAccessible.cpp
accessible/interfaces/nsIAccessibilityService.idl
accessible/ipc/other/DocAccessibleChild.cpp
accessible/mac/DocAccessibleWrap.h
accessible/mac/DocAccessibleWrap.mm
accessible/mac/RootAccessibleWrap.h
accessible/mac/RootAccessibleWrap.mm
accessible/windows/ia2/ia2Accessible.cpp
accessible/windows/msaa/AccessibleWrap.cpp
accessible/windows/msaa/DocAccessibleWrap.cpp
accessible/windows/msaa/DocAccessibleWrap.h
accessible/windows/msaa/RootAccessibleWrap.cpp
accessible/windows/msaa/RootAccessibleWrap.h
accessible/windows/sdn/sdnAccessible.cpp
layout/base/nsCSSFrameConstructor.cpp
--- a/accessible/android/DocAccessibleWrap.cpp
+++ b/accessible/android/DocAccessibleWrap.cpp
@@ -8,27 +8,28 @@
 #include "DocAccessibleWrap.h"
 #include "nsIDocShell.h"
 #include "nsLayoutUtils.h"
 #include "DocAccessibleChild.h"
 #include "nsAccessibilityService.h"
 #include "nsAccUtils.h"
 #include "nsIPersistentProperties2.h"
 #include "SessionAccessibility.h"
+#include "mozilla/PresShell.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 const uint32_t kCacheRefreshInterval = 500;
 
 ////////////////////////////////////////////////////////////////////////////////
 // DocAccessibleWrap
 ////////////////////////////////////////////////////////////////////////////////
 
-DocAccessibleWrap::DocAccessibleWrap(Document* aDocument,
-                                     nsIPresShell* aPresShell)
+DocAccessibleWrap::DocAccessibleWrap(Document* aDocument, PresShell* aPresShell)
     : DocAccessible(aDocument, aPresShell) {
   nsCOMPtr<nsIDocShellTreeItem> treeItem(aDocument->GetDocShell());
 
   nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
   treeItem->GetParent(getter_AddRefs(parentTreeItem));
 
   if (treeItem->ItemType() == nsIDocShellTreeItem::typeContent &&
       (!parentTreeItem ||
@@ -79,24 +80,21 @@ nsresult DocAccessibleWrap::HandleAccEve
 
   return DocAccessible::HandleAccEvent(aEvent);
 }
 
 void DocAccessibleWrap::CacheViewportCallback(nsITimer* aTimer,
                                               void* aDocAccParam) {
   RefPtr<DocAccessibleWrap> docAcc(
       dont_AddRef(reinterpret_cast<DocAccessibleWrap*>(aDocAccParam)));
-  if (!docAcc) {
+  if (!docAcc || docAcc->HasShutdown()) {
     return;
   }
 
-  nsIPresShell* presShell = docAcc->PresShell();
-  if (!presShell) {
-    return;
-  }
+  PresShell* presShell = docAcc->PresShellPtr();
   nsIFrame* rootFrame = presShell->GetRootFrame();
   if (!rootFrame) {
     return;
   }
 
   nsTArray<nsIFrame*> frames;
   nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
   nsRect scrollPort = sf ? sf->GetScrollPortRect() : rootFrame->GetRect();
--- a/accessible/android/DocAccessibleWrap.h
+++ b/accessible/android/DocAccessibleWrap.h
@@ -5,21 +5,24 @@
 
 #ifndef mozilla_a11y_DocAccessibleWrap_h__
 #define mozilla_a11y_DocAccessibleWrap_h__
 
 #include "DocAccessible.h"
 #include "nsITimer.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class DocAccessibleWrap : public DocAccessible {
  public:
-  DocAccessibleWrap(Document* aDocument, nsIPresShell* aPresShell);
+  DocAccessibleWrap(Document* aDocument, PresShell* aPresShell);
   virtual ~DocAccessibleWrap();
 
   virtual nsresult HandleAccEvent(AccEvent* aEvent) override;
 
   /**
    * Manage the mapping from id to Accessible.
    */
   void AddID(uint32_t aID, AccessibleWrap* aAcc) {
--- a/accessible/android/RootAccessibleWrap.cpp
+++ b/accessible/android/RootAccessibleWrap.cpp
@@ -5,21 +5,23 @@
 
 #include "RootAccessibleWrap.h"
 
 #include "Accessible-inl.h"
 #include "AccessibleOrProxy.h"
 #include "DocAccessibleParent.h"
 #include "ProxyAccessibleWrap.h"
 #include "SessionAccessibility.h"
+#include "mozilla/PresShell.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
-RootAccessibleWrap::RootAccessibleWrap(mozilla::dom::Document* aDoc,
-                                       nsIPresShell* aPresShell)
+RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDoc,
+                                       PresShell* aPresShell)
     : RootAccessible(aDoc, aPresShell) {}
 
 RootAccessibleWrap::~RootAccessibleWrap() {}
 
 AccessibleWrap* RootAccessibleWrap::GetContentAccessible() {
   if (ProxyAccessible* proxy = GetPrimaryRemoteTopLevelContentDoc()) {
     return WrapperFor(proxy);
   }
--- a/accessible/android/RootAccessibleWrap.h
+++ b/accessible/android/RootAccessibleWrap.h
@@ -4,23 +4,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_a11y_RootAccessibleWrap_h__
 #define mozilla_a11y_RootAccessibleWrap_h__
 
 #include "RootAccessible.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class DocProxyAccessibleWrap;
 
 class RootAccessibleWrap : public RootAccessible {
  public:
-  RootAccessibleWrap(dom::Document* aDocument, nsIPresShell* aPresShell);
+  RootAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell);
   virtual ~RootAccessibleWrap();
 
   AccessibleWrap* GetContentAccessible();
 
   AccessibleWrap* FindAccessibleById(int32_t aID);
 
   // Recursively searches for the accessible ID within the document tree.
   AccessibleWrap* FindAccessibleById(DocAccessibleWrap* aDocument, int32_t aID);
--- a/accessible/android/SessionAccessibility.cpp
+++ b/accessible/android/SessionAccessibility.cpp
@@ -10,16 +10,17 @@
 #include "AccessibilityEvent.h"
 #include "HyperTextAccessible.h"
 #include "JavaBuiltins.h"
 #include "RootAccessibleWrap.h"
 #include "nsAccessibilityService.h"
 #include "nsViewManager.h"
 #include "nsIPersistentProperties2.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/a11y/DocAccessibleParent.h"
 #include "mozilla/a11y/DocManager.h"
 
 #ifdef DEBUG
 #  include <android/log.h>
 #  define AALOG(args...) \
     __android_log_print(ANDROID_LOG_INFO, "GeckoAccessibilityNative", ##args)
@@ -128,18 +129,17 @@ SessionAccessibility* SessionAccessibili
 
   Accessible* chromeDoc = GetExistingDocAccessible(frame->OwnerDoc());
   return chromeDoc ? GetInstanceFor(chromeDoc) : nullptr;
 }
 
 SessionAccessibility* SessionAccessibility::GetInstanceFor(
     Accessible* aAccessible) {
   RootAccessible* rootAcc = aAccessible->RootAccessible();
-  nsIPresShell* shell = rootAcc->PresShell();
-  nsViewManager* vm = shell->GetViewManager();
+  nsViewManager* vm = rootAcc->PresShellPtr()->GetViewManager();
   if (!vm) {
     return nullptr;
   }
 
   nsCOMPtr<nsIWidget> rootWidget;
   vm->GetRootWidget(getter_AddRefs(rootWidget));
   // `rootWidget` can be one of several types. Here we make sure it is an
   // android nsWindow.
--- a/accessible/atk/DocAccessibleWrap.cpp
+++ b/accessible/atk/DocAccessibleWrap.cpp
@@ -1,20 +1,22 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=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 "nsMai.h"
 #include "DocAccessibleWrap.h"
+#include "mozilla/PresShell.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // DocAccessibleWrap
 ////////////////////////////////////////////////////////////////////////////////
 
 DocAccessibleWrap::DocAccessibleWrap(dom::Document* aDocument,
-                                     nsIPresShell* aPresShell)
+                                     PresShell* aPresShell)
     : DocAccessible(aDocument, aPresShell), mActivated(false) {}
 
 DocAccessibleWrap::~DocAccessibleWrap() {}
--- a/accessible/atk/DocAccessibleWrap.h
+++ b/accessible/atk/DocAccessibleWrap.h
@@ -9,21 +9,24 @@
  */
 
 #ifndef mozilla_a11y_DocAccessibleWrap_h__
 #define mozilla_a11y_DocAccessibleWrap_h__
 
 #include "DocAccessible.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class DocAccessibleWrap : public DocAccessible {
  public:
-  DocAccessibleWrap(dom::Document* aDocument, nsIPresShell* aPresShell);
+  DocAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell);
   virtual ~DocAccessibleWrap();
 
   bool mActivated;
 };
 
 }  // namespace a11y
 }  // namespace mozilla
 
--- a/accessible/base/DocManager.h
+++ b/accessible/base/DocManager.h
@@ -36,21 +36,25 @@ class DocManager : public nsIWebProgress
   /**
    * Return document accessible for the given DOM node.
    */
   DocAccessible* GetDocAccessible(dom::Document* aDocument);
 
   /**
    * Return document accessible for the given presshell.
    */
-  DocAccessible* GetDocAccessible(const nsIPresShell* aPresShell) {
-    if (!aPresShell) return nullptr;
+  DocAccessible* GetDocAccessible(const PresShell* aPresShell) {
+    if (!aPresShell) {
+      return nullptr;
+    }
 
     DocAccessible* doc = aPresShell->GetDocAccessible();
-    if (doc) return doc;
+    if (doc) {
+      return doc;
+    }
 
     return GetDocAccessible(aPresShell->GetDocument());
   }
 
   /**
    * Search through all document accessibles for an accessible with the given
    * unique id.
    */
--- a/accessible/base/NotificationController.cpp
+++ b/accessible/base/NotificationController.cpp
@@ -8,28 +8,29 @@
 #include "DocAccessible-inl.h"
 #include "DocAccessibleChild.h"
 #include "nsEventShell.h"
 #include "TextLeafAccessible.h"
 #include "TextUpdater.h"
 
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/Telemetry.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 using namespace mozilla::dom;
 
 ////////////////////////////////////////////////////////////////////////////////
 // NotificationCollector
 ////////////////////////////////////////////////////////////////////////////////
 
 NotificationController::NotificationController(DocAccessible* aDocument,
-                                               nsIPresShell* aPresShell)
+                                               PresShell* aPresShell)
     : EventQueue(aDocument),
       mObservingState(eNotObservingRefresh),
       mPresShell(aPresShell),
       mEventGeneration(0) {
 #ifdef DEBUG
   mMoveGuardOnStack = false;
 #endif
 
--- a/accessible/base/NotificationController.h
+++ b/accessible/base/NotificationController.h
@@ -15,16 +15,19 @@
 
 #include <utility>
 
 #ifdef A11Y_LOG
 #  include "Logging.h"
 #endif
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class DocAccessible;
 
 /**
  * Notification interface.
  */
 class Notification {
@@ -84,17 +87,17 @@ class TNotification : public Notificatio
 };
 
 /**
  * Used to process notifications from core for the document accessible.
  */
 class NotificationController final : public EventQueue,
                                      public nsARefreshObserver {
  public:
-  NotificationController(DocAccessible* aDocument, nsIPresShell* aPresShell);
+  NotificationController(DocAccessible* aDocument, PresShell* aPresShell);
 
   NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
   NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
 
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(NotificationController)
 
   /**
    * Shutdown the notification controller.
@@ -329,17 +332,17 @@ class NotificationController final : pub
     eRefreshProcessing,
     eRefreshProcessingForUpdate
   };
   eObservingState mObservingState;
 
   /**
    * The presshell of the document accessible.
    */
-  nsIPresShell* mPresShell;
+  PresShell* mPresShell;
 
   /**
    * Child documents that needs to be bound to the tree.
    */
   nsTArray<RefPtr<DocAccessible>> mHangingChildDocuments;
 
   /**
    * Pending accessible tree update notifications for content insertions.
--- a/accessible/base/SelectionManager.cpp
+++ b/accessible/base/SelectionManager.cpp
@@ -74,29 +74,29 @@ void SelectionManager::SetControlSelecti
   mCurrCtrlNormalSel = normalSel;
 
   // Register 'this' as selection listener for the spell check selection.
   Selection* spellSel = frameSel->GetSelection(SelectionType::eSpellCheck);
   spellSel->AddSelectionListener(this);
   mCurrCtrlSpellSel = spellSel;
 }
 
-void SelectionManager::AddDocSelectionListener(nsIPresShell* aPresShell) {
+void SelectionManager::AddDocSelectionListener(PresShell* aPresShell) {
   const nsFrameSelection* frameSel = aPresShell->ConstFrameSelection();
 
   // Register 'this' as selection listener for the normal selection.
   Selection* normalSel = frameSel->GetSelection(SelectionType::eNormal);
   normalSel->AddSelectionListener(this);
 
   // Register 'this' as selection listener for the spell check selection.
   Selection* spellSel = frameSel->GetSelection(SelectionType::eSpellCheck);
   spellSel->AddSelectionListener(this);
 }
 
-void SelectionManager::RemoveDocSelectionListener(nsIPresShell* aPresShell) {
+void SelectionManager::RemoveDocSelectionListener(PresShell* aPresShell) {
   const nsFrameSelection* frameSel = aPresShell->ConstFrameSelection();
 
   // Remove 'this' registered as selection listener for the normal selection.
   Selection* normalSel = frameSel->GetSelection(SelectionType::eNormal);
   normalSel->RemoveSelectionListener(this);
 
   // Remove 'this' registered as selection listener for the spellcheck
   // selection.
--- a/accessible/base/SelectionManager.h
+++ b/accessible/base/SelectionManager.h
@@ -5,19 +5,19 @@
 
 #ifndef mozilla_a11y_SelectionManager_h__
 #define mozilla_a11y_SelectionManager_h__
 
 #include "nsIFrame.h"
 #include "nsISelectionListener.h"
 #include "mozilla/WeakPtr.h"
 
-class nsIPresShell;
+namespace mozilla {
 
-namespace mozilla {
+class PresShell;
 
 namespace dom {
 class Element;
 class Selection;
 }  // namespace dom
 
 namespace a11y {
 
@@ -65,22 +65,22 @@ class SelectionManager : public nsISelec
   /**
    * Stop listening to selection events on the control.
    */
   void ClearControlSelectionListener();
 
   /**
    * Listen to selection events on the document.
    */
-  void AddDocSelectionListener(nsIPresShell* aPresShell);
+  void AddDocSelectionListener(PresShell* aPresShell);
 
   /**
    * Stop listening to selection events for a given document
    */
-  void RemoveDocSelectionListener(nsIPresShell* aShell);
+  void RemoveDocSelectionListener(PresShell* aPresShell);
 
   /**
    * Process delayed event, results in caret move and text selection change
    * events.
    */
   void ProcessTextSelChangeEvent(AccEvent* aEvent);
 
   /**
--- a/accessible/base/nsAccUtils.h
+++ b/accessible/base/nsAccUtils.h
@@ -13,16 +13,18 @@
 #include "nsAccessibilityService.h"
 #include "nsCoreUtils.h"
 
 #include "nsIDocShell.h"
 #include "nsPoint.h"
 
 namespace mozilla {
 
+class PresShell;
+
 namespace dom {
 class Element;
 }
 
 namespace a11y {
 
 class HyperTextAccessible;
 class DocAccessible;
@@ -109,18 +111,18 @@ class nsAccUtils {
    */
   static nsStaticAtom* NormalizeARIAToken(mozilla::dom::Element* aElement,
                                           nsAtom* aAttr);
 
   /**
    * Return document accessible for the given DOM node.
    */
   static DocAccessible* GetDocAccessibleFor(nsINode* aNode) {
-    nsIPresShell* presShell = nsCoreUtils::GetPresShellFor(aNode);
-    return GetAccService()->GetDocAccessible(presShell);
+    return GetAccService()->GetDocAccessible(
+        nsCoreUtils::GetPresShellFor(aNode));
   }
 
   /**
    * Return document accessible for the given docshell.
    */
   static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer) {
     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
     return GetAccService()->GetDocAccessible(docShell->GetPresShell());
--- a/accessible/base/nsAccessibilityService.cpp
+++ b/accessible/base/nsAccessibilityService.cpp
@@ -459,17 +459,17 @@ already_AddRefed<Accessible> nsAccessibi
     }
 #  endif
   }
 #endif
 
   return nullptr;
 }
 
-void nsAccessibilityService::DeckPanelSwitched(nsIPresShell* aPresShell,
+void nsAccessibilityService::DeckPanelSwitched(PresShell* aPresShell,
                                                nsIContent* aDeckNode,
                                                nsIFrame* aPrevBoxFrame,
                                                nsIFrame* aCurrentBoxFrame) {
   // Ignore tabpanels elements (a deck having an accessible) since their
   // children are accessible not depending on selected tab.
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (!document || document->HasAccessible(aDeckNode)) return;
 
@@ -497,17 +497,17 @@ void nsAccessibilityService::DeckPanelSw
       logging::MsgEnd();
     }
 #endif
 
     document->ContentInserted(panelNode, panelNode->GetNextSibling());
   }
 }
 
-void nsAccessibilityService::ContentRangeInserted(nsIPresShell* aPresShell,
+void nsAccessibilityService::ContentRangeInserted(PresShell* aPresShell,
                                                   nsIContent* aStartChild,
                                                   nsIContent* aEndChild) {
   DocAccessible* document = GetDocAccessible(aPresShell);
 #ifdef A11Y_LOG
   if (logging::IsEnabled(logging::eTree)) {
     logging::MsgBegin("TREE", "content inserted; doc: %p", document);
     logging::Node("container", aStartChild->GetParent());
     for (nsIContent* child = aStartChild; child != aEndChild;
@@ -519,17 +519,17 @@ void nsAccessibilityService::ContentRang
   }
 #endif
 
   if (document) {
     document->ContentInserted(aStartChild, aEndChild);
   }
 }
 
-void nsAccessibilityService::ContentRemoved(nsIPresShell* aPresShell,
+void nsAccessibilityService::ContentRemoved(PresShell* aPresShell,
                                             nsIContent* aChildNode) {
   DocAccessible* document = GetDocAccessible(aPresShell);
 #ifdef A11Y_LOG
   if (logging::IsEnabled(logging::eTree)) {
     logging::MsgBegin("TREE", "content removed; doc: %p", document);
     logging::Node("container node", aChildNode->GetFlattenedTreeParent());
     logging::Node("content node", aChildNode);
     logging::MsgEnd();
@@ -543,48 +543,48 @@ void nsAccessibilityService::ContentRemo
 #ifdef A11Y_LOG
   if (logging::IsEnabled(logging::eTree)) {
     logging::MsgEnd();
     logging::Stack();
   }
 #endif
 }
 
-void nsAccessibilityService::UpdateText(nsIPresShell* aPresShell,
+void nsAccessibilityService::UpdateText(PresShell* aPresShell,
                                         nsIContent* aContent) {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) document->UpdateText(aContent);
 }
 
-void nsAccessibilityService::TreeViewChanged(nsIPresShell* aPresShell,
+void nsAccessibilityService::TreeViewChanged(PresShell* aPresShell,
                                              nsIContent* aContent,
                                              nsITreeView* aView) {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) {
     Accessible* accessible = document->GetAccessible(aContent);
     if (accessible) {
       XULTreeAccessible* treeAcc = accessible->AsXULTree();
       if (treeAcc) treeAcc->TreeViewChanged(aView);
     }
   }
 }
 
-void nsAccessibilityService::RangeValueChanged(nsIPresShell* aPresShell,
+void nsAccessibilityService::RangeValueChanged(PresShell* aPresShell,
                                                nsIContent* aContent) {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) {
     Accessible* accessible = document->GetAccessible(aContent);
     if (accessible) {
       document->FireDelayedEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
                                  accessible);
     }
   }
 }
 
-void nsAccessibilityService::UpdateListBullet(nsIPresShell* aPresShell,
+void nsAccessibilityService::UpdateListBullet(PresShell* aPresShell,
                                               nsIContent* aHTMLListItemContent,
                                               bool aHasBullet) {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) {
     Accessible* accessible = document->GetAccessible(aHTMLListItemContent);
     if (accessible) {
       HTMLLIAccessible* listItem = accessible->AsHTMLListItem();
       if (listItem) listItem->UpdateBullet(aHasBullet);
@@ -606,41 +606,41 @@ void nsAccessibilityService::UpdateImage
 
       // If image map was initialized after we created an accessible (that'll
       // be an image accessible) then recreate it.
       RecreateAccessible(presShell, aImageFrame->GetContent());
     }
   }
 }
 
-void nsAccessibilityService::UpdateLabelValue(nsIPresShell* aPresShell,
+void nsAccessibilityService::UpdateLabelValue(PresShell* aPresShell,
                                               nsIContent* aLabelElm,
                                               const nsString& aNewValue) {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) {
     Accessible* accessible = document->GetAccessible(aLabelElm);
     if (accessible) {
       XULLabelAccessible* xulLabel = accessible->AsXULLabel();
       NS_ASSERTION(xulLabel,
                    "UpdateLabelValue was called for wrong accessible!");
       if (xulLabel) xulLabel->UpdateLabelValue(aNewValue);
     }
   }
 }
 
-void nsAccessibilityService::PresShellActivated(nsIPresShell* aPresShell) {
+void nsAccessibilityService::PresShellActivated(PresShell* aPresShell) {
   DocAccessible* document = aPresShell->GetDocAccessible();
   if (document) {
     RootAccessible* rootDocument = document->RootAccessible();
     NS_ASSERTION(rootDocument, "Entirely broken tree: no root document!");
     if (rootDocument) rootDocument->DocumentActivated(document);
   }
 }
 
-void nsAccessibilityService::RecreateAccessible(nsIPresShell* aPresShell,
+void nsAccessibilityService::RecreateAccessible(PresShell* aPresShell,
                                                 nsIContent* aContent) {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) document->RecreateAccessible(aContent);
 }
 
 void nsAccessibilityService::GetStringRole(uint32_t aRole, nsAString& aString) {
 #define ROLE(geckoRole, stringRole, atkRole, macRole, msaaRole, ia2Role, \
              androidClass, nameRule)                                     \
--- a/accessible/base/nsAccessibilityService.h
+++ b/accessible/base/nsAccessibilityService.h
@@ -153,76 +153,76 @@ class nsAccessibilityService final : pub
    */
   void GetStringRelationType(uint32_t aRelationType, nsAString& aString);
 
   // nsAccesibilityService
   /**
    * Notification used to update the accessible tree when deck panel is
    * switched.
    */
-  void DeckPanelSwitched(nsIPresShell* aPresShell, nsIContent* aDeckNode,
+  void DeckPanelSwitched(mozilla::PresShell* aPresShell, nsIContent* aDeckNode,
                          nsIFrame* aPrevBoxFrame, nsIFrame* aCurrentBoxFrame);
 
   /**
    * Notification used to update the accessible tree when new content is
    * inserted.
    */
-  void ContentRangeInserted(nsIPresShell* aPresShell, nsIContent* aStartChild,
-                            nsIContent* aEndChild);
+  void ContentRangeInserted(mozilla::PresShell* aPresShell,
+                            nsIContent* aStartChild, nsIContent* aEndChild);
 
   /**
    * Notification used to update the accessible tree when content is removed.
    */
-  void ContentRemoved(nsIPresShell* aPresShell, nsIContent* aChild);
+  void ContentRemoved(mozilla::PresShell* aPresShell, nsIContent* aChild);
 
-  void UpdateText(nsIPresShell* aPresShell, nsIContent* aContent);
+  void UpdateText(mozilla::PresShell* aPresShell, nsIContent* aContent);
 
   /**
    * Update XUL:tree accessible tree when treeview is changed.
    */
-  void TreeViewChanged(nsIPresShell* aPresShell, nsIContent* aContent,
+  void TreeViewChanged(mozilla::PresShell* aPresShell, nsIContent* aContent,
                        nsITreeView* aView);
 
   /**
    * Notify of input@type="element" value change.
    */
-  void RangeValueChanged(nsIPresShell* aPresShell, nsIContent* aContent);
+  void RangeValueChanged(mozilla::PresShell* aPresShell, nsIContent* aContent);
 
   /**
    * Update list bullet accessible.
    */
-  void UpdateListBullet(nsIPresShell* aPresShell,
+  void UpdateListBullet(mozilla::PresShell* aPresShell,
                         nsIContent* aHTMLListItemContent, bool aHasBullet);
 
   /**
    * Update the image map.
    */
   void UpdateImageMap(nsImageFrame* aImageFrame);
 
   /**
    * Update the label accessible tree when rendered @value is changed.
    */
-  void UpdateLabelValue(nsIPresShell* aPresShell, nsIContent* aLabelElm,
+  void UpdateLabelValue(mozilla::PresShell* aPresShell, nsIContent* aLabelElm,
                         const nsString& aNewValue);
 
   /**
    * Notify accessibility that anchor jump has been accomplished to the given
    * target. Used by layout.
    */
   void NotifyOfAnchorJumpTo(nsIContent* aTarget);
 
   /**
    * Notify that presshell is activated.
    */
-  void PresShellActivated(nsIPresShell* aPresShell);
+  void PresShellActivated(mozilla::PresShell* aPresShell);
 
   /**
    * Recreate an accessible for the given content node in the presshell.
    */
-  void RecreateAccessible(nsIPresShell* aPresShell, nsIContent* aContent);
+  void RecreateAccessible(mozilla::PresShell* aPresShell, nsIContent* aContent);
 
   void FireAccessibleEvent(uint32_t aEvent, Accessible* aTarget);
 
   // nsAccessibiltiyService
 
   /**
    * Return true if accessibility service has been shutdown.
    */
--- a/accessible/base/nsCoreUtils.cpp
+++ b/accessible/base/nsCoreUtils.cpp
@@ -110,17 +110,17 @@ void nsCoreUtils::DispatchClickEvent(XUL
                      rootWidget);
 
   DispatchMouseEvent(eMouseUp, cnvdX, cnvdY, tcElm, tcFrame, presShell,
                      rootWidget);
 }
 
 void nsCoreUtils::DispatchMouseEvent(EventMessage aMessage, int32_t aX,
                                      int32_t aY, nsIContent *aContent,
-                                     nsIFrame *aFrame, nsIPresShell *aPresShell,
+                                     nsIFrame *aFrame, PresShell *aPresShell,
                                      nsIWidget *aRootWidget) {
   WidgetMouseEvent event(true, aMessage, aRootWidget, WidgetMouseEvent::eReal,
                          WidgetMouseEvent::eNormal);
 
   event.mRefPoint = LayoutDeviceIntPoint(aX, aY);
 
   event.mClickCount = 1;
   event.button = WidgetMouseEvent::eLeftButton;
@@ -128,17 +128,17 @@ void nsCoreUtils::DispatchMouseEvent(Eve
   event.inputSource = dom::MouseEvent_Binding::MOZ_SOURCE_UNKNOWN;
 
   nsEventStatus status = nsEventStatus_eIgnore;
   aPresShell->HandleEventWithTarget(&event, aFrame, aContent, &status);
 }
 
 void nsCoreUtils::DispatchTouchEvent(EventMessage aMessage, int32_t aX,
                                      int32_t aY, nsIContent *aContent,
-                                     nsIFrame *aFrame, nsIPresShell *aPresShell,
+                                     nsIFrame *aFrame, PresShell *aPresShell,
                                      nsIWidget *aRootWidget) {
   nsIDocShell *docShell = nullptr;
   if (aPresShell->GetDocument()) {
     docShell = aPresShell->GetDocument()->GetDocShell();
   }
   if (!dom::TouchEvent::PrefEnabled(docShell)) {
     return;
   }
@@ -500,17 +500,17 @@ already_AddRefed<nsTreeColumn> nsCoreUti
 }
 
 bool nsCoreUtils::IsColumnHidden(nsTreeColumn *aColumn) {
   Element *element = aColumn->Element();
   return element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
                               nsGkAtoms::_true, eCaseMatters);
 }
 
-void nsCoreUtils::ScrollTo(nsIPresShell *aPresShell, nsIContent *aContent,
+void nsCoreUtils::ScrollTo(PresShell *aPresShell, nsIContent *aContent,
                            uint32_t aScrollType) {
   nsIPresShell::ScrollAxis vertical, horizontal;
   ConvertScrollTypeToPercents(aScrollType, &vertical, &horizontal);
   aPresShell->ScrollContentIntoView(aContent, vertical, horizontal,
                                     nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
 }
 
 bool nsCoreUtils::IsWhitespaceString(const nsAString &aString) {
--- a/accessible/base/nsCoreUtils.h
+++ b/accessible/base/nsCoreUtils.h
@@ -2,42 +2,43 @@
 /* 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/. */
 
 #ifndef nsCoreUtils_h_
 #define nsCoreUtils_h_
 
 #include "mozilla/EventForwards.h"
-#include "mozilla/PresShell.h"
 #include "mozilla/dom/Element.h"
 #include "nsIAccessibleEvent.h"
 #include "nsIContent.h"
 #include "mozilla/dom/Document.h"  // for GetPresShell()
 
 #include "nsPoint.h"
 #include "nsTArray.h"
 
 class nsRange;
 class nsTreeColumn;
 class nsIFrame;
 class nsIDocShell;
 class nsIWidget;
 
 namespace mozilla {
+class PresShell;
 namespace dom {
 class XULTreeElement;
 }
 }  // namespace mozilla
 
 /**
  * Core utils.
  */
 class nsCoreUtils {
  public:
+  typedef mozilla::PresShell PresShell;
   typedef mozilla::dom::Document Document;
 
   /**
    * Return true if the given node is a label of a control.
    */
   static bool IsLabelWithControl(nsIContent *aContent);
 
   /**
@@ -69,34 +70,34 @@ class nsCoreUtils {
    * @param aContent     [in] the element
    * @param aFrame       [in] frame of the element
    * @param aPresShell   [in] the presshell for the element
    * @param aRootWidget  [in] the root widget of the element
    */
   MOZ_CAN_RUN_SCRIPT
   static void DispatchMouseEvent(mozilla::EventMessage aMessage, int32_t aX,
                                  int32_t aY, nsIContent *aContent,
-                                 nsIFrame *aFrame, nsIPresShell *aPresShell,
+                                 nsIFrame *aFrame, PresShell *aPresShell,
                                  nsIWidget *aRootWidget);
 
   /**
    * Send a touch event with a single touch point to the given element.
    *
    * @param aMessage     [in] an event message (see EventForwards.h)
    * @param aX           [in] x coordinate in dev pixels
    * @param aY           [in] y coordinate in dev pixels
    * @param aContent     [in] the element
    * @param aFrame       [in] frame of the element
    * @param aPresShell   [in] the presshell for the element
    * @param aRootWidget  [in] the root widget of the element
    */
   MOZ_CAN_RUN_SCRIPT
   static void DispatchTouchEvent(mozilla::EventMessage aMessage, int32_t aX,
                                  int32_t aY, nsIContent *aContent,
-                                 nsIFrame *aFrame, nsIPresShell *aPresShell,
+                                 nsIFrame *aFrame, PresShell *aPresShell,
                                  nsIWidget *aRootWidget);
 
   /**
    * Return an accesskey registered on the given element by
    * EventStateManager or 0 if there is no registered accesskey.
    *
    * @param aContent - the given element.
    */
@@ -209,17 +210,17 @@ class nsCoreUtils {
   /**
    * Return true if the given document is an error page.
    */
   static bool IsErrorPage(Document *aDocument);
 
   /**
    * Return presShell for the document containing the given DOM node.
    */
-  static nsIPresShell *GetPresShellFor(nsINode *aNode) {
+  static PresShell *GetPresShellFor(nsINode *aNode) {
     return aNode->OwnerDoc()->GetPresShell();
   }
 
   /**
    * Get the ID for an element, in some types of XML this may not be the ID
    * attribute
    * @param aContent  Node to get the ID for
    * @param aID       Where to put ID string
@@ -281,17 +282,17 @@ class nsCoreUtils {
    * Return true if the given column is hidden (i.e. not sensible).
    */
   static bool IsColumnHidden(nsTreeColumn *aColumn);
 
   /**
    * Scroll content into view.
    */
   MOZ_CAN_RUN_SCRIPT
-  static void ScrollTo(nsIPresShell *aPresShell, nsIContent *aContent,
+  static void ScrollTo(PresShell *aPresShell, nsIContent *aContent,
                        uint32_t aScrollType);
 
   /**
    * Return true if the given node is table header element.
    */
   static bool IsHTMLTableHeader(nsIContent *aContent) {
     return aContent->NodeInfo()->Equals(nsGkAtoms::th) ||
            (aContent->IsElement() && aContent->AsElement()->HasAttr(
--- a/accessible/generic/Accessible-inl.h
+++ b/accessible/generic/Accessible-inl.h
@@ -5,16 +5,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_a11y_Accessible_inl_h_
 #define mozilla_a11y_Accessible_inl_h_
 
 #include "DocAccessible.h"
 #include "ARIAMap.h"
 #include "nsCoreUtils.h"
+#include "mozilla/PresShell.h"
 
 #ifdef A11Y_LOG
 #  include "Logging.h"
 #endif
 
 namespace mozilla {
 namespace a11y {
 
@@ -86,17 +87,17 @@ inline bool Accessible::IsDefunct() cons
   MOZ_ASSERT(mStateFlags & eIsDefunct || IsApplication() || IsDoc() ||
                  mStateFlags & eSharedNode || mContent,
              "No content");
   return mStateFlags & eIsDefunct;
 }
 
 inline void Accessible::ScrollTo(uint32_t aHow) const {
   if (mContent) {
-    nsCOMPtr<nsIPresShell> presShell = mDoc->PresShell();
+    RefPtr<PresShell> presShell = mDoc->PresShellPtr();
     nsCOMPtr<nsIContent> content = mContent;
     nsCoreUtils::ScrollTo(presShell, content, aHow);
   }
 }
 
 inline bool Accessible::InsertAfter(Accessible* aNewChild,
                                     Accessible* aRefChild) {
   MOZ_ASSERT(aNewChild, "No new child to insert");
--- a/accessible/generic/Accessible.cpp
+++ b/accessible/generic/Accessible.cpp
@@ -1824,17 +1824,17 @@ void Accessible::DoCommand(nsIContent* a
   nsCOMPtr<nsIRunnable> runnable = new Runnable(this, content, aActionIndex);
   NS_DispatchToMainThread(runnable);
 }
 
 void Accessible::DispatchClickEvent(nsIContent* aContent,
                                     uint32_t aActionIndex) const {
   if (IsDefunct()) return;
 
-  nsCOMPtr<nsIPresShell> presShell = mDoc->PresShell();
+  RefPtr<PresShell> presShell = mDoc->PresShellPtr();
 
   // Scroll into view.
   presShell->ScrollContentIntoView(aContent, nsIPresShell::ScrollAxis(),
                                    nsIPresShell::ScrollAxis(),
                                    nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
 
   AutoWeakFrame frame = aContent->GetPrimaryFrame();
   if (!frame) return;
--- a/accessible/generic/DocAccessible.cpp
+++ b/accessible/generic/DocAccessible.cpp
@@ -65,17 +65,18 @@ static nsStaticAtom* const kRelationAttr
                                                nsGkAtoms::_for,
                                                nsGkAtoms::control};
 
 static const uint32_t kRelationAttrsLen = ArrayLength(kRelationAttrs);
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/desctructor
 
-DocAccessible::DocAccessible(dom::Document* aDocument, nsIPresShell* aPresShell)
+DocAccessible::DocAccessible(dom::Document* aDocument,
+                             PresShell* aPresShell)
     :  // XXX don't pass a document to the Accessible constructor so that we
        // don't set mDoc until our vtable is fully setup.  If we set mDoc before
        // setting up the vtable we will call Accessible::AddRef() but not the
        // overrides of it for subclasses.  It is important to call those
        // overrides to avoid confusing leak checking machinary.
       HyperTextAccessibleWrap(nullptr, nullptr),
       // XXX aaronl should we use an algorithm for the initial cache size?
       mAccessibleCache(kDefaultCacheLength),
@@ -374,18 +375,19 @@ void DocAccessible::Init() {
   // having no container was loaded.
   if (mDocumentNode->GetReadyStateEnum() == dom::Document::READYSTATE_COMPLETE)
     mLoadState |= eDOMLoaded;
 
   AddEventListeners();
 }
 
 void DocAccessible::Shutdown() {
-  if (!mPresShell)  // already shutdown
+  if (!mPresShell) {  // already shutdown
     return;
+  }
 
 #ifdef A11Y_LOG
   if (logging::IsEnabled(logging::eDocDestroy))
     logging::DocDestroy("document shutdown", mDocumentNode, this);
 #endif
 
   // Mark the document as shutdown before AT is notified about the document
   // removal from its container (valid for root documents on ATK and due to
@@ -447,31 +449,33 @@ void DocAccessible::Shutdown() {
   HyperTextAccessibleWrap::Shutdown();
 
   GetAccService()->NotifyOfDocumentShutdown(this, mDocumentNode);
   mDocumentNode = nullptr;
 }
 
 nsIFrame* DocAccessible::GetFrame() const {
   nsIFrame* root = nullptr;
-  if (mPresShell) root = mPresShell->GetRootFrame();
+  if (mPresShell) {
+    root = mPresShell->GetRootFrame();
+  }
 
   return root;
 }
 
 // DocAccessible protected member
 nsRect DocAccessible::RelativeBounds(nsIFrame** aRelativeFrame) const {
   *aRelativeFrame = GetFrame();
 
   dom::Document* document = mDocumentNode;
   dom::Document* parentDoc = nullptr;
 
   nsRect bounds;
   while (document) {
-    mozilla::PresShell* presShell = document->GetPresShell();
+    PresShell* presShell = document->GetPresShell();
     if (!presShell) {
       return nsRect();
     }
 
     nsRect scrollPort;
     nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
     if (sf) {
       scrollPort = sf->GetScrollPortRect();
@@ -1098,17 +1102,19 @@ nsresult DocAccessible::HandleAccEvent(A
   return HyperTextAccessible::HandleAccEvent(aEvent);
 }
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
 // Public members
 
 void* DocAccessible::GetNativeWindow() const {
-  if (!mPresShell) return nullptr;
+  if (!mPresShell) {
+    return nullptr;
+  }
 
   nsViewManager* vm = mPresShell->GetViewManager();
   if (!vm) return nullptr;
 
   nsCOMPtr<nsIWidget> widget;
   vm->GetRootWidget(getter_AddRefs(widget));
   if (widget) return widget->GetNativeData(NS_NATIVE_WINDOW);
 
--- a/accessible/generic/DocAccessible.h
+++ b/accessible/generic/DocAccessible.h
@@ -22,16 +22,17 @@
 #include "nsIWeakReference.h"
 
 class nsAccessiblePivot;
 
 const uint32_t kDefaultCacheLength = 128;
 
 namespace mozilla {
 
+class PresShell;
 class TextEditor;
 
 namespace dom {
 class Document;
 }
 
 namespace a11y {
 
@@ -53,17 +54,17 @@ class DocAccessible : public HyperTextAc
 
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIACCESSIBLEPIVOTOBSERVER
 
  protected:
   typedef mozilla::dom::Document Document;
 
  public:
-  DocAccessible(Document* aDocument, nsIPresShell* aPresShell);
+  DocAccessible(Document* aDocument, PresShell* aPresShell);
 
   // nsIScrollPositionListener
   virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override {}
   virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override;
 
   // nsIDocumentObserver
   NS_DECL_NSIDOCUMENTOBSERVER
 
@@ -120,19 +121,27 @@ class DocAccessible : public HyperTextAc
   void DocType(nsAString& aType) const;
 
   /**
    * Return virtual cursor associated with the document.
    */
   nsIAccessiblePivot* VirtualCursor();
 
   /**
+   * Returns true if the instance has shutdown.
+   */
+  bool HasShutdown() const { return !mPresShell; }
+
+  /**
    * Return presentation shell for this document accessible.
    */
-  nsIPresShell* PresShell() const { return mPresShell; }
+  PresShell* PresShellPtr() const {
+    MOZ_DIAGNOSTIC_ASSERT(!HasShutdown());
+    return mPresShell;
+  }
 
   /**
    * Return the presentation shell's context.
    */
   nsPresContext* PresContext() const { return mPresShell->GetPresContext(); }
 
   /**
    * Return true if associated DOM document was loaded and isn't unloading.
@@ -705,17 +714,17 @@ class DocAccessible : public HyperTextAc
   /**
    * Used to process notification from core and accessible events.
    */
   RefPtr<NotificationController> mNotificationController;
   friend class EventTree;
   friend class NotificationController;
 
  private:
-  nsIPresShell* mPresShell;
+  PresShell* mPresShell;
 
   // Exclusively owned by IPDL so don't manually delete it!
   DocAccessibleChild* mIPCDoc;
 };
 
 inline DocAccessible* Accessible::AsDoc() {
   return IsDoc() ? static_cast<DocAccessible*>(this) : nullptr;
 }
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -1413,17 +1413,17 @@ int32_t HyperTextAccessible::CaretLineNu
   MOZ_ASSERT_UNREACHABLE(
       "DOM ancestry had this hypertext but frame ancestry didn't");
   return lineNumber;
 }
 
 LayoutDeviceIntRect HyperTextAccessible::GetCaretRect(nsIWidget** aWidget) {
   *aWidget = nullptr;
 
-  RefPtr<nsCaret> caret = mDoc->PresShell()->GetCaret();
+  RefPtr<nsCaret> caret = mDoc->PresShellPtr()->GetCaret();
   NS_ENSURE_TRUE(caret, LayoutDeviceIntRect());
 
   bool isVisible = caret->IsVisible();
   if (!isVisible) return LayoutDeviceIntRect();
 
   nsRect rect;
   nsIFrame* frame = caret->GetGeometry(&rect);
   if (!frame || rect.IsEmpty()) return LayoutDeviceIntRect();
--- a/accessible/generic/RootAccessible.cpp
+++ b/accessible/generic/RootAccessible.cpp
@@ -54,17 +54,17 @@ using namespace mozilla::dom;
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 NS_IMPL_ISUPPORTS_INHERITED(RootAccessible, DocAccessible, nsIDOMEventListener)
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/destructor
 
-RootAccessible::RootAccessible(Document* aDocument, nsIPresShell* aPresShell)
+RootAccessible::RootAccessible(Document* aDocument, PresShell* aPresShell)
     : DocAccessibleWrap(aDocument, aPresShell) {
   mType = eRootType;
 }
 
 RootAccessible::~RootAccessible() {}
 
 ////////////////////////////////////////////////////////////////////////////////
 // Accessible
@@ -439,18 +439,19 @@ void RootAccessible::ProcessDOMEvent(Eve
 #endif
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // Accessible
 
 void RootAccessible::Shutdown() {
   // Called manually or by Accessible::LastRelease()
-  if (!PresShell()) return;  // Already shutdown
-
+  if (HasShutdown()) {
+    return;
+  }
   DocAccessibleWrap::Shutdown();
 }
 
 Relation RootAccessible::RelationByType(RelationType aType) const {
   if (!mDocumentNode || aType != RelationType::EMBEDS)
     return DocAccessibleWrap::RelationByType(aType);
 
   if (nsPIDOMWindowOuter* rootWindow = mDocumentNode->GetWindow()) {
--- a/accessible/generic/RootAccessible.h
+++ b/accessible/generic/RootAccessible.h
@@ -7,23 +7,26 @@
 #define mozilla_a11y_RootAccessible_h__
 
 #include "HyperTextAccessible.h"
 #include "DocAccessibleWrap.h"
 
 #include "nsIDOMEventListener.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class RootAccessible : public DocAccessibleWrap, public nsIDOMEventListener {
   NS_DECL_ISUPPORTS_INHERITED
 
  public:
-  RootAccessible(dom::Document* aDocument, nsIPresShell* aPresShell);
+  RootAccessible(dom::Document* aDocument, PresShell* aPresShell);
 
   // nsIDOMEventListener
   NS_DECL_NSIDOMEVENTLISTENER
 
   // Accessible
   virtual void Shutdown() override;
   virtual mozilla::a11y::ENameValueFlag Name(nsString& aName) const override;
   virtual Relation RelationByType(RelationType aType) const override;
--- a/accessible/html/HTMLTableAccessible.cpp
+++ b/accessible/html/HTMLTableAccessible.cpp
@@ -12,16 +12,17 @@
 #include "nsAccUtils.h"
 #include "DocAccessible.h"
 #include "nsTextEquivUtils.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
 #include "TreeWalker.h"
 
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/HTMLTableElement.h"
 #include "nsIHTMLCollection.h"
 #include "mozilla/dom/Document.h"
 #include "nsIMutableArray.h"
 #include "nsIPersistentProperties2.h"
 #include "nsITableCellLayout.h"
 #include "nsFrameSelection.h"
 #include "nsError.h"
@@ -694,17 +695,17 @@ nsresult HTMLTableAccessible::AddRowOrCo
   if (!tableFrame) return NS_OK;
 
   uint32_t count = 0;
   if (doSelectRow)
     count = ColCount();
   else
     count = RowCount();
 
-  nsIPresShell* presShell(mDoc->PresShell());
+  PresShell* presShell = mDoc->PresShellPtr();
   RefPtr<nsFrameSelection> tableSelection =
       const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
 
   for (uint32_t idx = 0; idx < count; idx++) {
     int32_t rowIdx = doSelectRow ? aIndex : idx;
     int32_t colIdx = doSelectRow ? idx : aIndex;
     nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx);
     if (cellFrame && !cellFrame->IsSelected()) {
@@ -716,17 +717,17 @@ nsresult HTMLTableAccessible::AddRowOrCo
   return NS_OK;
 }
 
 nsresult HTMLTableAccessible::RemoveRowsOrColumnsFromSelection(
     int32_t aIndex, TableSelection aTarget, bool aIsOuter) {
   nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
   if (!tableFrame) return NS_OK;
 
-  nsIPresShell* presShell(mDoc->PresShell());
+  PresShell* presShell = mDoc->PresShellPtr();
   RefPtr<nsFrameSelection> tableSelection =
       const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
 
   bool doUnselectRow = (aTarget == TableSelection::Row);
   uint32_t count = doUnselectRow ? ColCount() : RowCount();
 
   int32_t startRowIdx = doUnselectRow ? aIndex : 0;
   int32_t endRowIdx = doUnselectRow ? aIndex : count - 1;
--- a/accessible/interfaces/nsIAccessibilityService.idl
+++ b/accessible/interfaces/nsIAccessibilityService.idl
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 interface nsIAccessible;
 interface nsIWeakReference;
-interface nsIPresShell;
 interface nsIAccessiblePivot;
 
 webidl Node;
 
 /**
  * An interface for in-process accessibility clients wishing to get an
  * nsIAccessible for a given DOM node.  More documentation at:
  *   http://www.mozilla.org/projects/ui/accessibility
--- a/accessible/ipc/other/DocAccessibleChild.cpp
+++ b/accessible/ipc/other/DocAccessibleChild.cpp
@@ -16,16 +16,17 @@
 #include "TableAccessible.h"
 #include "TableCellAccessible.h"
 #include "nsIPersistentProperties2.h"
 #include "nsISimpleEnumerator.h"
 #include "nsAccUtils.h"
 #ifdef MOZ_ACCESSIBILITY_ATK
 #  include "AccessibleWrap.h"
 #endif
+#include "mozilla/PresShell.h"
 
 namespace mozilla {
 namespace a11y {
 
 Accessible* DocAccessibleChild::IdToAccessible(const uint64_t& aID) const {
   if (!aID) return mDoc;
 
   if (!mDoc) return nullptr;
@@ -240,17 +241,17 @@ mozilla::ipc::IPCResult DocAccessibleChi
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult DocAccessibleChild::RecvScrollTo(
     const uint64_t& aID, const uint32_t& aScrollType) {
   Accessible* acc = IdToAccessible(aID);
   if (acc) {
-    nsCOMPtr<nsIPresShell> presShell = acc->Document()->PresShell();
+    RefPtr<PresShell> presShell = acc->Document()->PresShellPtr();
     nsCOMPtr<nsIContent> content = acc->GetContent();
     nsCoreUtils::ScrollTo(presShell, content, aScrollType);
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult DocAccessibleChild::RecvScrollToPoint(
--- a/accessible/mac/DocAccessibleWrap.h
+++ b/accessible/mac/DocAccessibleWrap.h
@@ -4,20 +4,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_a11y_DocAccessibleWrap_h__
 #define mozilla_a11y_DocAccessibleWrap_h__
 
 #include "DocAccessible.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class DocAccessibleWrap : public DocAccessible {
  public:
-  DocAccessibleWrap(dom::Document* aDocument, nsIPresShell* aPresShell);
+  DocAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell);
   virtual ~DocAccessibleWrap();
 };
 
 }  // namespace a11y
 }  // namespace mozilla
 
 #endif
--- a/accessible/mac/DocAccessibleWrap.mm
+++ b/accessible/mac/DocAccessibleWrap.mm
@@ -2,14 +2,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 "DocAccessibleWrap.h"
 
 #import "mozAccessible.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
-DocAccessibleWrap::DocAccessibleWrap(mozilla::dom::Document* aDocument, nsIPresShell* aPresShell)
+DocAccessibleWrap::DocAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell)
     : DocAccessible(aDocument, aPresShell) {}
 
 DocAccessibleWrap::~DocAccessibleWrap() {}
--- a/accessible/mac/RootAccessibleWrap.h
+++ b/accessible/mac/RootAccessibleWrap.h
@@ -8,21 +8,24 @@
  */
 
 #ifndef mozilla_a11y_RootAccessibleWrap_h__
 #define mozilla_a11y_RootAccessibleWrap_h__
 
 #include "RootAccessible.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class RootAccessibleWrap : public RootAccessible {
  public:
-  RootAccessibleWrap(dom::Document* aDocument, nsIPresShell* aPresShell);
+  RootAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell);
   virtual ~RootAccessibleWrap();
 
   Class GetNativeType();
 
   // let's our native accessible get in touch with the
   // native cocoa view that is our accessible parent.
   void GetNativeWidget(void** aOutView);
 };
--- a/accessible/mac/RootAccessibleWrap.mm
+++ b/accessible/mac/RootAccessibleWrap.mm
@@ -8,19 +8,20 @@
 #include "mozDocAccessible.h"
 
 #include "nsCOMPtr.h"
 #include "nsObjCExceptions.h"
 #include "nsIFrame.h"
 #include "nsView.h"
 #include "nsIWidget.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
-RootAccessibleWrap::RootAccessibleWrap(mozilla::dom::Document* aDocument, nsIPresShell* aPresShell)
+RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell)
     : RootAccessible(aDocument, aPresShell) {}
 
 RootAccessibleWrap::~RootAccessibleWrap() {}
 
 Class RootAccessibleWrap::GetNativeType() {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   return [mozRootAccessible class];
--- a/accessible/windows/ia2/ia2Accessible.cpp
+++ b/accessible/windows/ia2/ia2Accessible.cpp
@@ -17,16 +17,17 @@
 #include "IUnknownImpl.h"
 #include "nsCoreUtils.h"
 #include "nsIAccessibleTypes.h"
 #include "mozilla/a11y/PDocAccessible.h"
 #include "Relation.h"
 #include "TextRange-inl.h"
 #include "nsAccessibilityService.h"
 
+#include "mozilla/PresShell.h"
 #include "nsIPersistentProperties2.h"
 #include "nsISimpleEnumerator.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 template <typename String>
 static void EscapeAttributeChars(String& aStr);
@@ -182,17 +183,17 @@ ia2Accessible::role(long* aRole) {
 
 // XXX Use MOZ_CAN_RUN_SCRIPT_BOUNDARY for now due to bug 1543294.
 MOZ_CAN_RUN_SCRIPT_BOUNDARY STDMETHODIMP
 ia2Accessible::scrollTo(enum IA2ScrollType aScrollType) {
   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
   if (acc->IsDefunct()) return CO_E_OBJNOTCONNECTED;
 
   MOZ_ASSERT(!acc->IsProxy());
-  nsCOMPtr<nsIPresShell> presShell = acc->Document()->PresShell();
+  RefPtr<PresShell> presShell = acc->Document()->PresShellPtr();
   nsCOMPtr<nsIContent> content = acc->GetContent();
   nsCoreUtils::ScrollTo(presShell, content, aScrollType);
 
   return S_OK;
 }
 
 STDMETHODIMP
 ia2Accessible::scrollToPoint(enum IA2CoordinateType aCoordType, long aX,
--- a/accessible/windows/msaa/AccessibleWrap.cpp
+++ b/accessible/windows/msaa/AccessibleWrap.cpp
@@ -28,16 +28,17 @@
 
 #ifdef A11Y_LOG
 #  include "Logging.h"
 #endif
 
 #include "nsIMutableArray.h"
 #include "nsIFrame.h"
 #include "nsIScrollableFrame.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/NodeInfo.h"
 #include "mozilla/dom/TabParent.h"
 #include "nsIServiceManager.h"
 #include "nsNameSpaceManager.h"
 #include "nsTextFormatter.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsEventMap.h"
@@ -1254,19 +1255,17 @@ HWND AccessibleWrap::GetHWNDFor(Accessib
 
   // Popup lives in own windows, use its HWND until the popup window is
   // hidden to make old JAWS versions work with collapsed comboboxes (see
   // discussion in bug 379678).
   nsIFrame* frame = aAccessible->GetFrame();
   if (frame) {
     nsIWidget* widget = frame->GetNearestWidget();
     if (widget && widget->IsVisible()) {
-      nsIPresShell* shell = document->PresShell();
-      nsViewManager* vm = shell->GetViewManager();
-      if (vm) {
+      if (nsViewManager* vm = document->PresShellPtr()->GetViewManager()) {
         nsCOMPtr<nsIWidget> rootWidget;
         vm->GetRootWidget(getter_AddRefs(rootWidget));
         // Make sure the accessible belongs to popup. If not then use
         // document HWND (which might be different from root widget in the
         // case of window emulation).
         if (rootWidget != widget)
           return static_cast<HWND>(widget->GetNativeData(NS_NATIVE_WINDOW));
       }
--- a/accessible/windows/msaa/DocAccessibleWrap.cpp
+++ b/accessible/windows/msaa/DocAccessibleWrap.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=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 "DocAccessibleWrap.h"
 
 #include "Compatibility.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/dom/TabChild.h"
 #include "DocAccessibleChild.h"
 #include "nsWinUtils.h"
 #include "Role.h"
 #include "RootAccessible.h"
 #include "sdnDocAccessible.h"
 #include "Statistics.h"
 
@@ -21,17 +22,17 @@
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // DocAccessibleWrap
 ////////////////////////////////////////////////////////////////////////////////
 
 DocAccessibleWrap::DocAccessibleWrap(dom::Document* aDocument,
-                                     nsIPresShell* aPresShell)
+                                     PresShell* aPresShell)
     : DocAccessible(aDocument, aPresShell), mHWND(nullptr) {}
 
 DocAccessibleWrap::~DocAccessibleWrap() {}
 
 IMPL_IUNKNOWN_QUERY_HEAD(DocAccessibleWrap)
 if (aIID == IID_ISimpleDOMDocument) {
   statistics::ISimpleDOMUsed();
   *aInstancePtr = static_cast<ISimpleDOMDocument*>(new sdnDocAccessible(this));
--- a/accessible/windows/msaa/DocAccessibleWrap.h
+++ b/accessible/windows/msaa/DocAccessibleWrap.h
@@ -5,21 +5,24 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_a11y_DocAccessibleWrap_h__
 #define mozilla_a11y_DocAccessibleWrap_h__
 
 #include "DocAccessible.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class DocAccessibleWrap : public DocAccessible {
  public:
-  DocAccessibleWrap(dom::Document* aDocument, nsIPresShell* aPresShell);
+  DocAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell);
   virtual ~DocAccessibleWrap();
 
   DECL_IUNKNOWN_INHERITED
 
   // IAccessible
 
   // Override get_accParent for e10s
   virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accParent(
--- a/accessible/windows/msaa/RootAccessibleWrap.cpp
+++ b/accessible/windows/msaa/RootAccessibleWrap.cpp
@@ -1,27 +1,29 @@
 /* -*- 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 "RootAccessibleWrap.h"
 
 #include "Compatibility.h"
+#include "mozilla/PresShell.h"
 #include "mozilla/WindowsVersion.h"
 #include "nsCoreUtils.h"
 #include "nsWinUtils.h"
 
+using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/destructor
 
 RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDocument,
-                                       nsIPresShell* aPresShell)
+                                       PresShell* aPresShell)
     : RootAccessible(aDocument, aPresShell), mOuter(&mInternalUnknown) {}
 
 RootAccessibleWrap::~RootAccessibleWrap() {}
 
 ////////////////////////////////////////////////////////////////////////////////
 // Aggregated IUnknown
 HRESULT
 RootAccessibleWrap::InternalQueryInterface(REFIID aIid, void** aOutInterface) {
--- a/accessible/windows/msaa/RootAccessibleWrap.h
+++ b/accessible/windows/msaa/RootAccessibleWrap.h
@@ -5,21 +5,24 @@
 
 #ifndef mozilla_a11y_RootAccessibleWrap_h__
 #define mozilla_a11y_RootAccessibleWrap_h__
 
 #include "mozilla/mscom/Aggregation.h"
 #include "RootAccessible.h"
 
 namespace mozilla {
+
+class PresShell;
+
 namespace a11y {
 
 class RootAccessibleWrap : public RootAccessible {
  public:
-  RootAccessibleWrap(dom::Document* aDocument, nsIPresShell* aPresShell);
+  RootAccessibleWrap(dom::Document* aDocument, PresShell* aPresShell);
   virtual ~RootAccessibleWrap();
 
   // RootAccessible
   virtual void DocumentActivated(DocAccessible* aDocument);
 
   /**
    * This method enables a RootAccessibleWrap to be wrapped by a
    * LazyInstantiator.
--- a/accessible/windows/sdn/sdnAccessible.cpp
+++ b/accessible/windows/sdn/sdnAccessible.cpp
@@ -16,16 +16,17 @@
 #include "nsNameSpaceManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWinUtils.h"
 #include "nsRange.h"
 
 #include "mozilla/dom/BorrowedAttrInfo.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/ErrorResult.h"
+#include "mozilla/PresShell.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 sdnAccessible::~sdnAccessible() {
   if (mUniqueId.isSome()) {
     AccessibleWrap::ReleaseChildID(WrapNotNull(this));
   }
@@ -270,17 +271,17 @@ sdnAccessible::scrollTo(boolean aScrollT
     return CO_E_OBJNOTCONNECTED;
 
   if (!mNode->IsContent()) return S_FALSE;
 
   uint32_t scrollType = aScrollTopLeft
                             ? nsIAccessibleScrollType::SCROLL_TYPE_TOP_LEFT
                             : nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_RIGHT;
 
-  nsCOMPtr<nsIPresShell> presShell = document->PresShell();
+  RefPtr<PresShell> presShell = document->PresShellPtr();
   nsCOMPtr<nsIContent> content = mNode->AsContent();
   nsCoreUtils::ScrollTo(presShell, content, scrollType);
   return S_OK;
 }
 
 STDMETHODIMP
 sdnAccessible::get_parentNode(ISimpleDOMNode __RPC_FAR* __RPC_FAR* aNode) {
   if (!aNode) return E_INVALIDARG;
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -6898,17 +6898,18 @@ void nsCSSFrameConstructor::ContentAppen
   if (gReallyNoisyContentUpdates) {
     printf("nsCSSFrameConstructor::ContentAppended: resulting frame model:\n");
     parentFrame->List(stdout);
   }
 #endif
 
 #ifdef ACCESSIBILITY
   if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-    accService->ContentRangeInserted(mPresShell, aFirstNewContent, nullptr);
+    accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
+                                     aFirstNewContent, nullptr);
   }
 #endif
 }
 
 void nsCSSFrameConstructor::ContentInserted(nsIContent* aChild,
                                             nsILayoutHistoryState* aFrameState,
                                             InsertionKind aInsertionKind) {
   ContentRangeInserted(aChild, aChild->GetNextSibling(), aFrameState,
@@ -7010,17 +7011,18 @@ void nsCSSFrameConstructor::ContentRange
       // Restore frame state for the root scroll frame if there is one
       if (nsIFrame* rootScrollFrame = mPresShell->GetRootScrollFrame()) {
         RestoreFrameStateFor(rootScrollFrame, aFrameState);
       }
     }
 
 #ifdef ACCESSIBILITY
     if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-      accService->ContentRangeInserted(mPresShell, aStartChild, aEndChild);
+      accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
+                                       aStartChild, aEndChild);
     }
 #endif
 
     return;
   }
 
   InsertionPoint insertion;
   if (isSingleInsert) {
@@ -7376,17 +7378,18 @@ void nsCSSFrameConstructor::ContentRange
         "nsCSSFrameConstructor::ContentRangeInserted: resulting frame "
         "model:\n");
     insertion.mParentFrame->List(stdout);
   }
 #endif
 
 #ifdef ACCESSIBILITY
   if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-    accService->ContentRangeInserted(mPresShell, aStartChild, aEndChild);
+    accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
+                                     aStartChild, aEndChild);
   }
 #endif
 }
 
 bool nsCSSFrameConstructor::ContentRemoved(nsIContent* aChild,
                                            nsIContent* aOldNextSibling,
                                            RemoveFlags aFlags) {
   MOZ_ASSERT(aChild);
@@ -7576,17 +7579,17 @@ bool nsCSSFrameConstructor::ContentRemov
       RecreateFramesForContent(grandparentFrame->GetContent(),
                                InsertionKind::Async);
       LAYOUT_PHASE_TEMP_REENTER();
       return true;
     }
 
 #ifdef ACCESSIBILITY
     if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
-      accService->ContentRemoved(mPresShell, aChild);
+      accService->ContentRemoved(static_cast<PresShell*>(mPresShell), aChild);
     }
 #endif
 
     // Examine the containing-block for the removed content and see if
     // :first-letter style applies.
     nsIFrame* inflowChild = childFrame;
     if (childFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
       inflowChild = childFrame->GetPlaceholderFrame();
@@ -11712,17 +11715,18 @@ void nsCSSFrameConstructor::GenerateChil
                     childList, false, nullptr);
 
     aFrame->SetInitialChildList(kPrincipalList, childList);
   }
 
 #ifdef ACCESSIBILITY
   if (nsAccessibilityService* accService = nsIPresShell::AccService()) {
     if (nsIContent* child = aFrame->GetContent()->GetFirstChild()) {
-      accService->ContentRangeInserted(mPresShell, child, nullptr);
+      accService->ContentRangeInserted(static_cast<PresShell*>(mPresShell),
+                                       child, nullptr);
     }
   }
 #endif
 
   // call XBL constructors after the frames are created
   mPresShell->GetDocument()->BindingManager()->ProcessAttachedQueue();
 }