Bug 1516853 - Merge nsIDocument and nsDocument. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 31 Dec 2018 14:10:19 +0000
changeset 452201 d96e39ed615b40b9b1ccb661f72b29c81b34fe34
parent 452200 51fa00bbe97e6553e67d8d85ae12e5cf98b4ba8b
child 452212 595b7807fb110bbb87717938a2f85bd083b608f3
child 452213 862527552b97325c4340c499db679cd2ec7b6074
push id35292
push userdvarga@mozilla.com
push dateMon, 31 Dec 2018 21:26:28 +0000
treeherdermozilla-central@d96e39ed615b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1516853
milestone66.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 1516853 - Merge nsIDocument and nsDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15498
caps/nsScriptSecurityManager.cpp
docshell/base/nsDocShell.cpp
docshell/base/nsPingListener.cpp
dom/animation/KeyframeUtils.cpp
dom/base/ChildIterator.cpp
dom/base/CustomElementRegistry.h
dom/base/DOMParser.cpp
dom/base/DocumentOrShadowRoot.cpp
dom/base/Element.cpp
dom/base/Element.h
dom/base/FragmentOrElement.cpp
dom/base/InProcessTabChildMessageManager.cpp
dom/base/nsContentUtils.cpp
dom/base/nsDOMWindowUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsFocusManager.cpp
dom/base/nsGlobalWindowInner.cpp
dom/base/nsIDocument.h
dom/base/nsINode.cpp
dom/base/nsNodeInfoManager.cpp
dom/base/nsNodeUtils.cpp
dom/base/nsObjectLoadingContent.cpp
dom/base/nsObjectLoadingContent.h
dom/base/nsTextNode.cpp
dom/console/Console.cpp
dom/html/HTMLImageElement.cpp
dom/html/HTMLInputElement.cpp
dom/html/HTMLSlotElement.cpp
dom/html/HTMLUnknownElement.cpp
dom/html/MediaDocument.cpp
dom/html/nsHTMLDocument.cpp
dom/html/nsHTMLDocument.h
dom/ipc/ContentChild.cpp
dom/smil/SMILAnimationController.h
dom/smil/nsSMILCompositorTable.h
dom/webidl/Animatable.webidl
dom/webidl/Animation.webidl
dom/webidl/AnimationEffect.webidl
dom/webidl/AnimationPlaybackEvent.webidl
dom/webidl/AnimationTimeline.webidl
dom/webidl/CSSAnimation.webidl
dom/webidl/CSSPseudoElement.webidl
dom/webidl/CSSTransition.webidl
dom/webidl/Document.webidl
dom/webidl/DocumentTimeline.webidl
dom/webidl/Element.webidl
dom/webidl/KeyframeEffect.webidl
dom/xml/XMLDocument.cpp
dom/xml/XMLDocument.h
dom/xml/nsXMLContentSink.cpp
dom/xul/XULDocument.cpp
editor/composer/moz.build
gfx/layers/apz/util/DoubleTapToZoom.cpp
image/SVGDocumentWrapper.cpp
intl/l10n/DocumentL10n.h
layout/base/PresShell.cpp
layout/base/ZoomConstraintsClient.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsLayoutUtils.cpp
layout/inspector/ServoStyleRuleMap.cpp
toolkit/content/contentAreaUtils.js
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -385,17 +385,17 @@ nsresult nsScriptSecurityManager::GetCha
  * that may or may not inherit)."
  */
 NS_IMETHODIMP
 nsScriptSecurityManager::GetChannelURIPrincipal(nsIChannel* aChannel,
                                                 nsIPrincipal** aPrincipal) {
   MOZ_ASSERT(aChannel, "Must have channel!");
 
   // Get the principal from the URI.  Make sure this does the same thing
-  // as nsDocument::Reset and XULDocument::StartDocumentLoad.
+  // as nsIDocument::Reset and XULDocument::StartDocumentLoad.
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
 
   // Inherit the origin attributes from loadInfo.
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2471,17 +2471,17 @@ void nsDocShell::MaybeCreateInitialClien
   }
 
   nsIPrincipal* principal =
       aPrincipal ? aPrincipal : GetInheritedPrincipal(false);
 
   // Sometimes there is no principal available when we are called from
   // CreateAboutBlankContentViewer.  For example, sometimes the principal
   // is only extracted from the load context after the document is created
-  // in nsDocument::ResetToURI().  Ideally we would do something similar
+  // in nsIDocument::ResetToURI().  Ideally we would do something similar
   // here, but for now lets just avoid the issue by not preallocating the
   // client.
   if (!principal) {
     return;
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
   if (!win) {
@@ -10880,17 +10880,17 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, 
 }
 
 bool nsDocShell::OnLoadingSite(nsIChannel* aChannel, bool aFireOnLocationChange,
                                bool aAddToGlobalHistory) {
   nsCOMPtr<nsIURI> uri;
   // If this a redirect, use the final url (uri)
   // else use the original url
   //
-  // Note that this should match what documents do (see nsDocument::Reset).
+  // Note that this should match what documents do (see nsIDocument::Reset).
   NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
   NS_ENSURE_TRUE(uri, false);
 
   // Pass false for aCloneSHChildren, since we're loading a new page here.
   return OnNewURI(uri, aChannel, nullptr, nullptr, mLoadType,
                   aFireOnLocationChange, aAddToGlobalHistory, false);
 }
 
--- a/docshell/base/nsPingListener.cpp
+++ b/docshell/base/nsPingListener.cpp
@@ -11,17 +11,17 @@
 #include "mozilla/dom/DocGroup.h"
 
 #include "nsIDocument.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIInputStream.h"
 #include "nsIProtocolHandler.h"
 #include "nsIUploadChannel2.h"
 
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsNetUtil.h"
 #include "nsStreamUtils.h"
 #include "nsStringStream.h"
 #include "nsWhitespaceTokenizer.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -22,17 +22,17 @@
 #include "mozilla/dom/KeyframeEffect.h"  // For PropertyValuesPair etc.
 #include "mozilla/dom/Nullable.h"
 #include "jsapi.h"  // For ForOfIterator etc.
 #include "nsClassHashtable.h"
 #include "nsContentUtils.h"  // For GetContextForContent
 #include "nsCSSPropertyIDSet.h"
 #include "nsCSSProps.h"
 #include "nsCSSPseudoElements.h"  // For CSSPseudoElementType
-#include "nsDocument.h"  // For nsDocument::AreWebAnimationsImplicitKeyframesEnabled
+#include "nsIDocument.h"  // For nsIDocument::AreWebAnimationsImplicitKeyframesEnabled
 #include "nsIScriptError.h"
 #include "nsTArray.h"
 #include <algorithm>  // For std::stable_sort, std::min
 
 using mozilla::dom::Nullable;
 
 namespace mozilla {
 
@@ -219,17 +219,17 @@ static void DistributeRange(const Range<
   }
 
   if (aRv.Failed()) {
     MOZ_ASSERT(keyframes.IsEmpty(),
                "Should not set any keyframes when there is an error");
     return keyframes;
   }
 
-  if (!nsDocument::AreWebAnimationsImplicitKeyframesEnabled(aCx, nullptr) &&
+  if (!nsIDocument::AreWebAnimationsImplicitKeyframesEnabled(aCx, nullptr) &&
       HasImplicitKeyframeValues(keyframes, aDocument)) {
     keyframes.Clear();
     aRv.Throw(NS_ERROR_DOM_ANIM_MISSING_PROPS_ERR);
   }
 
   return keyframes;
 }
 
--- a/dom/base/ChildIterator.cpp
+++ b/dom/base/ChildIterator.cpp
@@ -7,17 +7,17 @@
 #include "ChildIterator.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/HTMLSlotElement.h"
 #include "mozilla/dom/XBLChildrenElement.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsIFrame.h"
 #include "nsCSSAnonBoxes.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 
 namespace mozilla {
 namespace dom {
 
 ExplicitChildIterator::ExplicitChildIterator(const nsIContent* aParent,
                                              bool aStartAtBeginning)
     : mParent(aParent),
       mChild(nullptr),
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -17,18 +17,16 @@
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/WebComponentsBinding.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsGenericHTMLElement.h"
 #include "nsWrapperCache.h"
 #include "nsContentUtils.h"
 
-class nsDocument;
-
 namespace mozilla {
 namespace dom {
 
 struct CustomElementData;
 struct ElementDefinitionOptions;
 class CallbackFunction;
 class CustomElementReaction;
 class DocGroup;
@@ -346,18 +344,16 @@ class CustomElementReactionsStack {
     }
 
    private:
     RefPtr<CustomElementReactionsStack> mReactionStack;
   };
 };
 
 class CustomElementRegistry final : public nsISupports, public nsWrapperCache {
-  // Allow nsDocument to access mCustomDefinitions and mCandidatesMap.
-  friend class ::nsDocument;
 
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CustomElementRegistry)
 
  public:
   explicit CustomElementRegistry(nsPIDOMWindowInner* aWindow);
 
--- a/dom/base/DOMParser.cpp
+++ b/dom/base/DOMParser.cpp
@@ -266,20 +266,20 @@ already_AddRefed<DOMParser> DOMParser::C
 
   RefPtr<DOMParser> domParser =
       new DOMParser(nullptr, docPrincipal, documentURI, nullptr);
   return domParser.forget();
 }
 
 already_AddRefed<nsIDocument> DOMParser::SetUpDocument(DocumentFlavor aFlavor,
                                                        ErrorResult& aRv) {
-  // We should really just use mOwner here, but nsDocument gets confused
+  // We should really just use mOwner here, but nsIDocument gets confused
   // if we pass it a scriptHandlingObject that doesn't QI to
   // nsIScriptGlobalObject, and test_isequalnode.js (an xpcshell test without
-  // a window global) breaks. The correct solution is just to wean nsDocument
+  // a window global) breaks. The correct solution is just to wean nsIDocument
   // off of nsIScriptGlobalObject, but that's a yak to shave another day.
   nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
       do_QueryInterface(mOwner);
 
   // Try to inherit a style backend.
   NS_ASSERTION(mPrincipal, "Must have principal by now");
   NS_ASSERTION(mDocumentURI, "Must have document URI by now");
 
--- a/dom/base/DocumentOrShadowRoot.cpp
+++ b/dom/base/DocumentOrShadowRoot.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DocumentOrShadowRoot.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/dom/StyleSheetList.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsFocusManager.h"
 #include "nsIRadioVisitor.h"
 #include "nsIFormControl.h"
 #include "nsLayoutUtils.h"
 #include "nsSVGUtils.h"
 #include "nsWindowSizes.h"
 
 namespace mozilla {
@@ -471,18 +471,18 @@ HTMLInputElement* DocumentOrShadowRoot::
     const nsAString& aName) {
   return GetOrCreateRadioGroup(aName)->mSelectedRadioButton;
 }
 
 nsresult DocumentOrShadowRoot::GetNextRadioButton(
     const nsAString& aName, const bool aPrevious,
     HTMLInputElement* aFocusedRadio, HTMLInputElement** aRadioOut) {
   // XXX Can we combine the HTML radio button method impls of
-  //     nsDocument and nsHTMLFormControl?
-  // XXX Why is HTML radio button stuff in nsDocument, as
+  //     nsIDocument and nsHTMLFormControl?
+  // XXX Why is HTML radio button stuff in nsIDocument, as
   //     opposed to nsHTMLDocument?
   *aRadioOut = nullptr;
 
   nsRadioGroupStruct* radioGroup = GetOrCreateRadioGroup(aName);
 
   // Return the radio button relative to the focused radio button.
   // If no radio is focused, get the radio relative to the selected one.
   RefPtr<HTMLInputElement> currentRadio;
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -71,17 +71,17 @@
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/SizeOfState.h"
 #include "mozilla/TextEditor.h"
 #include "mozilla/TextEvents.h"
 #include "nsNodeUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsAttrValueOrString.h"
 #include "nsAttrValueInlines.h"
 #include "nsCSSPseudoElements.h"
 #include "nsWindowSizes.h"
 #ifdef MOZ_XUL
 #include "nsXULElement.h"
 #endif /* MOZ_XUL */
 #include "SVGElement.h"
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -54,17 +54,16 @@ class nsAttrValueOrString;
 class nsContentList;
 class nsDOMTokenList;
 struct nsRect;
 class nsFocusManager;
 class nsGlobalWindowInner;
 class nsGlobalWindowOuter;
 class nsDOMCSSAttributeDeclaration;
 class nsISMILAttr;
-class nsDocument;
 class nsDOMStringMap;
 struct ServoNodeData;
 
 class nsIDOMXULButtonElement;
 class nsIDOMXULContainerElement;
 class nsIDOMXULContainerItemElement;
 class nsIDOMXULControlElement;
 class nsIDOMXULMenuListElement;
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -56,17 +56,17 @@
 #include "nsDOMTokenList.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsError.h"
 #include "nsDOMString.h"
 #include "nsIScriptSecurityManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MouseEvents.h"
 #include "nsNodeUtils.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsAttrValueOrString.h"
 #include "nsQueryObject.h"
 #ifdef MOZ_XUL
 #include "nsXULElement.h"
 #endif /* MOZ_XUL */
 #include "nsFrameSelection.h"
 #ifdef DEBUG
 #include "nsRange.h"
@@ -1138,17 +1138,17 @@ void FragmentOrElement::SetTextContentIn
 }
 
 void FragmentOrElement::DestroyContent() {
   // Drop any servo data. We do this before the RemovedFromDocument call below
   // so that it doesn't need to try to keep the style state sane when shuffling
   // around the flattened tree.
   //
   // TODO(emilio): I suspect this can be asserted against instead, with a bit of
-  // effort to avoid calling nsDocument::Destroy with a shell...
+  // effort to avoid calling nsIDocument::Destroy with a shell...
   if (IsElement()) {
     AsElement()->ClearServoData();
   }
 
   nsIDocument* document = OwnerDoc();
 
   document->BindingManager()->RemovedFromDocument(this, document,
                                                   nsBindingManager::eRunDtor);
@@ -1229,17 +1229,17 @@ class ContentUnbinder : public Runnable 
 
       while (container->HasChildren()) {
         // Hold a strong ref to the node when we remove it, because we may be
         // the last reference to it.  We need to call DisconnectChild()
         // before calling UnbindFromTree, since this last can notify various
         // observers and they should really see consistent
         // tree state.
         // If this code changes, change the corresponding code in
-        // FragmentOrElement's and nsDocument's unlink impls.
+        // FragmentOrElement's and nsIDocument's unlink impls.
         nsCOMPtr<nsIContent> child = container->GetLastChild();
         container->DisconnectChild(child);
         UnbindSubtree(child);
         child->UnbindFromTree();
       }
     }
   }
 
@@ -1335,17 +1335,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Fr
 
   // Unlink child content (and unbind our subtree).
   if (tmp->UnoptimizableCCNode() || !nsCCUncollectableMarker::sGeneration) {
     // Don't allow script to run while we're unbinding everything.
     nsAutoScriptBlocker scriptBlocker;
     while (tmp->HasChildren()) {
       // Hold a strong ref to the node when we remove it, because we may be
       // the last reference to it.
-      // If this code changes, change the corresponding code in nsDocument's
+      // If this code changes, change the corresponding code in nsIDocument's
       // unlink impl and ContentUnbinder::UnbindSubtree.
       nsCOMPtr<nsIContent> child = tmp->GetLastChild();
       tmp->DisconnectChild(child);
       child->UnbindFromTree();
     }
   } else if (!tmp->GetParent() && tmp->HasChildren()) {
     ContentUnbinder::Append(tmp);
   } /* else {
--- a/dom/base/InProcessTabChildMessageManager.cpp
+++ b/dom/base/InProcessTabChildMessageManager.cpp
@@ -178,17 +178,17 @@ uint64_t InProcessTabChildMessageManager
   if (!topWin) {
     return 0;
   }
 
   return topWin->WindowID();
 }
 
 void InProcessTabChildMessageManager::FireUnloadEvent() {
-  // We're called from nsDocument::MaybeInitializeFinalizeFrameLoaders, so it
+  // We're called from nsIDocument::MaybeInitializeFinalizeFrameLoaders, so it
   // should be safe to run script.
   MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
 
   // Don't let the unload event propagate to chrome event handlers.
   mPreventEventsEscaping = true;
   DOMEventTargetHelper::DispatchTrustedEvent(NS_LITERAL_STRING("unload"));
 
   // Allow events fired during docshell destruction (pagehide, unload) to
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -106,17 +106,17 @@
 #include "nsContentPolicyUtils.h"
 #include "nsContentSecurityManager.h"
 #include "nsCPrefetchService.h"
 #include "nsCRT.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsCycleCollector.h"
 #include "nsDataHashtable.h"
 #include "nsDocShellCID.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsDOMCID.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "nsDOMJSUtils.h"
 #include "nsDOMMutationObserver.h"
 #include "nsError.h"
 #include "nsFocusManager.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGenericHTMLFrameElement.h"
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -8,17 +8,16 @@
 
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/LayerTransactionChild.h"
 #include "nsPresContext.h"
 #include "nsContentList.h"
 #include "nsError.h"
 #include "nsQueryContentEventResult.h"
 #include "nsGlobalWindow.h"
-#include "nsIDocument.h"
 #include "nsFocusManager.h"
 #include "nsFrameManager.h"
 #include "nsRefreshDriver.h"
 #include "mozilla/dom/Animation.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/BlobBinding.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/Touch.h"
@@ -99,17 +98,17 @@
 #include "nsIInterfaceRequestorUtils.h"
 #include "GeckoProfiler.h"
 #include "mozilla/Preferences.h"
 #include "nsIContentIterator.h"
 #include "nsIStyleSheetService.h"
 #include "nsContentPermissionHelper.h"
 #include "nsCSSPseudoElements.h"  // for CSSPseudoElementType
 #include "nsNetUtil.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "HTMLImageElement.h"
 #include "HTMLCanvasElement.h"
 #include "mozilla/css/ImageLoader.h"
 #include "mozilla/layers/IAPZCTreeManager.h"  // for layers::ZoomToRectBehavior
 #include "mozilla/dom/Promise.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/gfx/GPUProcessManager.h"
@@ -3788,18 +3787,18 @@ nsDOMWindowUtils::ForceUseCounterFlush(n
   NS_ENSURE_ARG_POINTER(aNode);
 
   if (nsCOMPtr<nsIDocument> doc = do_QueryInterface(aNode)) {
     mozilla::css::ImageLoader* loader = doc->StyleImageLoader();
     loader->FlushUseCounters();
 
     // Flush the document and any external documents that it depends on.
     const auto reportKind =
-        nsDocument::UseCounterReportKind::eIncludeExternalResources;
-    static_cast<nsDocument*>(doc.get())->ReportUseCounters(reportKind);
+        nsIDocument::UseCounterReportKind::eIncludeExternalResources;
+    doc->ReportUseCounters(reportKind);
     return NS_OK;
   }
 
   if (nsCOMPtr<nsIContent> content = do_QueryInterface(aNode)) {
     if (HTMLImageElement* img = HTMLImageElement::FromNode(content)) {
       img->FlushUseCounters();
       return NS_OK;
     }
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Base class for all our document implementations.
  */
 
 #include "AudioChannelService.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsIDocumentInlines.h"
 #include "mozilla/AnimationComparator.h"
 #include "mozilla/AntiTrackingCommon.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/BinarySearch.h"
 #include "mozilla/CSSEnabledState.h"
 #include "mozilla/DebugOnly.h"
@@ -290,16 +290,21 @@
 #include "mozilla/ClearOnShutdown.h"
 #include "nsHTMLTags.h"
 #include "NodeUbiReporting.h"
 #include "nsICookieService.h"
 #include "mozilla/net/ChannelEventQueue.h"
 #include "mozilla/net/RequestContextService.h"
 #include "StorageAccessPermissionRequest.h"
 
+#define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0)
+#define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1)
+#define XML_DECLARATION_BITS_STANDALONE_EXISTS (1 << 2)
+#define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3)
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 typedef nsTArray<Link*> LinkArray;
 
 static LazyLogModule gDocumentLeakPRLog("DocumentLeak");
 static LazyLogModule gCspPRLog("CSP");
 static LazyLogModule gUserInteractionPRLog("UserInteraction");
@@ -1233,17 +1238,17 @@ struct nsIDocument::FrameRequest {
 
   RefPtr<FrameRequestCallback> mCallback;
   int32_t mHandle;
 };
 
 // ==================================================================
 // =
 // ==================================================================
-nsIDocument::nsIDocument()
+nsIDocument::nsIDocument(const char* aContentType)
     : nsINode(nullptr),
       DocumentOrShadowRoot(*this),
       mReferrerPolicySet(false),
       mReferrerPolicy(mozilla::net::RP_Unset),
       mBlockAllMixedContent(false),
       mBlockAllMixedContentPreloads(false),
       mUpgradeInsecureRequests(false),
       mUpgradeInsecurePreloads(false),
@@ -1373,92 +1378,73 @@ nsIDocument::nsIDocument()
       mHasUserInteractionTimerScheduled(false),
       mUserGestureActivated(false),
       mStackRefCnt(0),
       mUpdateNestLevel(0),
       mViewportType(Unknown),
       mViewportOverflowType(ViewportOverflowType::NoOverflow),
       mSubDocuments(nullptr),
       mHeaderData(nullptr),
+      mPrincipalFlashClassifier(new PrincipalFlashClassifier()),
       mFlashClassification(FlashClassification::Unclassified),
       mBoxObjectTable(nullptr),
       mCurrentOrientationAngle(0),
       mCurrentOrientationType(OrientationType::Portrait_primary),
       mServoRestyleRootDirtyBits(0),
       mThrowOnDynamicMarkupInsertionCounter(0),
       mIgnoreOpensDuringUnloadCounter(0),
       mDocLWTheme(Doc_Theme_Uninitialized),
       mSavedResolution(1.0f) {
+  MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug, ("DOCUMENT %p created", this));
+
   SetIsInDocument();
   SetIsConnected(true);
 
   if (StaticPrefs::layout_css_use_counters_enabled()) {
     mStyleUseCounters.reset(Servo_UseCounters_Create());
   }
-}
-
-nsDocument::nsDocument(const char* aContentType) : nsIDocument() {
+
   SetContentTypeInternal(nsDependentCString(aContentType));
 
-  MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug, ("DOCUMENT %p created", this));
-
   // Start out mLastStyleSheetSet as null, per spec
   SetDOMStringToNull(mLastStyleSheetSet);
 
   // void state used to differentiate an empty source from an unselected source
   mPreloadPictureFoundSource.SetIsVoid(true);
-  // For determining if this is a flash document which should be
-  // blocked based on its principal.
-  mPrincipalFlashClassifier = new PrincipalFlashClassifier();
 }
 
 void nsIDocument::ClearAllBoxObjects() {
   if (mBoxObjectTable) {
     for (auto iter = mBoxObjectTable->Iter(); !iter.Done(); iter.Next()) {
       nsPIBoxObject* boxObject = iter.UserData();
       if (boxObject) {
         boxObject->Clear();
       }
     }
     delete mBoxObjectTable;
     mBoxObjectTable = nullptr;
   }
 }
 
-nsIDocument::~nsIDocument() {
-  MOZ_ASSERT(mDOMMediaQueryLists.isEmpty(),
-             "must not have media query lists left");
-
-  if (mNodeInfoManager) {
-    mNodeInfoManager->DropDocumentReference();
-  }
-
-  if (mDocGroup) {
-    mDocGroup->RemoveDocument(this);
-  }
-
-  UnlinkOriginalDocumentIfStatic();
-}
-
 bool nsIDocument::IsAboutPage() const {
   nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
   nsCOMPtr<nsIURI> uri;
   principal->GetURI(getter_AddRefs(uri));
   bool isAboutScheme = true;
   if (uri) {
     uri->SchemeIs("about", &isAboutScheme);
   }
   return isAboutScheme;
 }
 
 void nsIDocument::ConstructUbiNode(void* storage) {
   JS::ubi::Concrete<nsIDocument>::construct(storage, this);
 }
 
-nsDocument::~nsDocument() {
+nsIDocument::~nsIDocument() {
   MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug, ("DOCUMENT %p destroyed", this));
   MOZ_ASSERT(!IsTopLevelContentDocument() || !IsResourceDoc(),
              "Can't be top-level and a resource doc at the same time");
 
   NS_ASSERTION(!mIsShowing, "Destroying a currently-showing document");
 
   if (IsTopLevelContentDocument()) {
     // don't report for about: pages
@@ -1633,16 +1619,29 @@ nsDocument::~nsDocument() {
 
   delete mHeaderData;
 
   ClearAllBoxObjects();
 
   mPendingTitleChangeEvent.Revoke();
 
   mPlugins.Clear();
+
+  MOZ_ASSERT(mDOMMediaQueryLists.isEmpty(),
+             "must not have media query lists left");
+
+  if (mNodeInfoManager) {
+    mNodeInfoManager->DropDocumentReference();
+  }
+
+  if (mDocGroup) {
+    mDocGroup->RemoveDocument(this);
+  }
+
+  UnlinkOriginalDocumentIfStatic();
 }
 
 NS_INTERFACE_TABLE_HEAD(nsIDocument)
   NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
   NS_INTERFACE_TABLE_BEGIN
     NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsIDocument, nsISupports, nsINode)
     NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsINode)
     NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIDocument)
@@ -1749,17 +1748,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 
   // Traverse all nsIDocument pointer members.
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSecurityInfo)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDisplayDocument)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFontFaceSet)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadyForIdle)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentL10n)
 
-  // Traverse all nsDocument nsCOMPtrs.
+  // Traverse all nsIDocument nsCOMPtrs.
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParser)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptGlobalObject)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListenerManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMStyleSheets)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheetSetList)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptLoader)
 
   DocumentOrShadowRoot::Traverse(tmp, cb);
@@ -2744,18 +2743,17 @@ nsresult nsIDocument::InitCSP(nsIChannel
 
     return NS_OK;
   }
 
   MOZ_LOG(gCspPRLog, LogLevel::Debug,
           ("Document is an add-on or CSP header specified %p", this));
 
   nsCOMPtr<nsIContentSecurityPolicy> csp;
-  rv =
-      principal->EnsureCSP(static_cast<nsDocument*>(this), getter_AddRefs(csp));
+  rv = principal->EnsureCSP(this, getter_AddRefs(csp));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // ----- if the doc is an addon, apply its CSP.
   if (addonPolicy) {
     nsCOMPtr<nsIAddonPolicyService> aps =
         do_GetService("@mozilla.org/addons/policy-service;1");
 
     nsAutoString addonCSP;
@@ -4489,22 +4487,22 @@ void nsIDocument::SetScriptGlobalObject(
   // doing the initial document load and don't want to fire the event for this
   // change.
   dom::VisibilityState oldState = mVisibilityState;
   mVisibilityState = ComputeVisibilityState();
   // When the visibility is changed, notify it to observers.
   // Some observers need the notification, for example HTMLMediaElement uses
   // it to update internal media resource allocation.
   // When video is loaded via VideoDocument, HTMLMediaElement and MediaDecoder
-  // creation are already done before nsDocument::SetScriptGlobalObject() call.
+  // creation are already done before nsIDocument::SetScriptGlobalObject() call.
   // MediaDecoder decides whether starting decoding is decided based on
   // document's visibility. When the MediaDecoder is created,
-  // nsDocument::SetScriptGlobalObject() is not yet called and document is
+  // nsIDocument::SetScriptGlobalObject() is not yet called and document is
   // hidden state. Therefore the MediaDecoder decides that decoding is
-  // not yet necessary. But soon after nsDocument::SetScriptGlobalObject()
+  // not yet necessary. But soon after nsIDocument::SetScriptGlobalObject()
   // call, the document becomes not hidden. At the time, MediaDecoder needs
   // to know it and needs to start updating decoding.
   if (oldState != mVisibilityState) {
     EnumerateActivityObservers(NotifyActivityChanged, nullptr);
   }
 
   // The global in the template contents owner document should be the same.
   if (mTemplateContentsOwner && mTemplateContentsOwner != this) {
@@ -4611,18 +4609,18 @@ void nsIDocument::MaybeEndOutermostXBLUp
   // we're not in an update and it is safe to run scripts.
   if (mUpdateNestLevel == 0 && mInXBLUpdate) {
     if (nsContentUtils::IsSafeToRunScript()) {
       mInXBLUpdate = false;
       BindingManager()->EndOutermostUpdate();
     } else if (!mInDestructor) {
       if (!mMaybeEndOutermostXBLUpdateRunner) {
         mMaybeEndOutermostXBLUpdateRunner =
-            NewRunnableMethod("nsDocument::MaybeEndOutermostXBLUpdate", this,
-                              &nsDocument::MaybeEndOutermostXBLUpdate);
+            NewRunnableMethod("nsIDocument::MaybeEndOutermostXBLUpdate", this,
+                              &nsIDocument::MaybeEndOutermostXBLUpdate);
       }
       nsContentUtils::AddScriptRunner(mMaybeEndOutermostXBLUpdateRunner);
     }
   }
 }
 
 void nsIDocument::BeginUpdate() {
   // If the document is going away, then it's probably okay to do things to it
@@ -7285,17 +7283,17 @@ already_AddRefed<Element> nsIDocument::C
   }
   qName.Append(aName);
 
   // Note: "a:b:c" is a valid name in non-namespaces XML, and
   // nsIDocument::CreateElement can call us with such a name and no prefix,
   // which would cause an error if we just used true here.
   bool nsAware = aPrefix != nullptr || aNamespaceID != GetDefaultNamespaceID();
   NS_ASSERTION(NS_SUCCEEDED(nsContentUtils::CheckQName(qName, nsAware)),
-               "Don't pass invalid prefixes to nsDocument::CreateElem, "
+               "Don't pass invalid prefixes to nsIDocument::CreateElem, "
                "check caller.");
 #endif
 
   RefPtr<mozilla::dom::NodeInfo> nodeInfo;
   mNodeInfoManager->GetNodeInfo(aName, aPrefix, aNamespaceID, ELEMENT_NODE,
                                 getter_AddRefs(nodeInfo));
   NS_ENSURE_TRUE(nodeInfo, nullptr);
 
@@ -7969,24 +7967,24 @@ void nsIDocument::OnPageHide(bool aPersi
   if (FullscreenStackTop()) {
     // If this document was fullscreen, we should exit fullscreen in this
     // doctree branch. This ensures that if the user navigates while in
     // fullscreen mode we don't leave its still visible ancestor documents
     // in fullscreen mode. So exit fullscreen in the document's fullscreen
     // root document, as this will exit fullscreen in all the root's
     // descendant documents. Note that documents are removed from the
     // doctree by the time OnPageHide() is called, so we must store a
-    // reference to the root (in nsDocument::mFullscreenRoot) since we can't
+    // reference to the root (in nsIDocument::mFullscreenRoot) since we can't
     // just traverse the doctree to get the root.
     nsIDocument::ExitFullscreenInDocTree(this);
 
     // Since the document is removed from the doctree before OnPageHide() is
     // called, ExitFullscreen() can't traverse from the root down to *this*
     // document, so we must manually call CleanupFullscreenState() below too.
-    // Note that CleanupFullscreenState() clears nsDocument::mFullscreenRoot,
+    // Note that CleanupFullscreenState() clears nsIDocument::mFullscreenRoot,
     // so we *must* call it after ExitFullscreen(), not before.
     // OnPageHide() is called in every hidden (i.e. descendant) document,
     // so calling CleanupFullscreenState() here will ensure all hidden
     // documents have their fullscreen state reset.
     CleanupFullscreenState();
 
     // The fullscreenchange event is to be queued in the refresh driver,
     // however a hidden page wouldn't trigger that again, so it makes no
@@ -8152,17 +8150,17 @@ nsresult nsIDocument::CloneDocHelper(nsI
   clone->mCharacterSet = mCharacterSet;
   clone->mCharacterSetSource = mCharacterSetSource;
   clone->mCompatMode = mCompatMode;
   clone->mBidiOptions = mBidiOptions;
   clone->mContentLanguage = mContentLanguage;
   clone->SetContentTypeInternal(GetContentTypeInternal());
   clone->mSecurityInfo = mSecurityInfo;
 
-  // State from nsDocument
+  // State from nsIDocument
   clone->mType = mType;
   clone->mXMLDeclarationBits = mXMLDeclarationBits;
   clone->mBaseTarget = mBaseTarget;
 
   return NS_OK;
 }
 
 void nsIDocument::SetReadyStateInternal(ReadyState rs) {
@@ -8577,28 +8575,25 @@ nsIDocument* nsIDocument::GetTemplateCon
                           true,          // aLoadedAsData
                           scriptObject,  // aEventObject
                           DocumentFlavorHTML);
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     mTemplateContentsOwner = document;
     NS_ENSURE_TRUE(mTemplateContentsOwner, nullptr);
 
-    nsDocument* doc = static_cast<nsDocument*>(mTemplateContentsOwner.get());
-
     if (!scriptObject) {
       mTemplateContentsOwner->SetScopeObject(GetScopeObject());
     }
 
-    doc->mHasHadScriptHandlingObject = hasHadScriptObject;
-
-    // Set |doc| as the template contents owner of itself so that
-    // |doc| is the template contents owner of template elements created
-    // by |doc|.
-    doc->mTemplateContentsOwner = doc;
+    mTemplateContentsOwner->mHasHadScriptHandlingObject = hasHadScriptObject;
+
+    // Set |mTemplateContentsOwner| as the template contents owner of itself so
+    // that it is the template contents owner of nested template elements.
+    mTemplateContentsOwner->mTemplateContentsOwner = mTemplateContentsOwner;
   }
 
   return mTemplateContentsOwner;
 }
 
 static already_AddRefed<nsPIDOMWindowOuter> FindTopWindowForElement(
     Element* element) {
   nsIDocument* document = element->OwnerDoc();
@@ -8872,34 +8867,32 @@ void nsIDocument::FlushPendingLinkUpdate
         }
       }
     }
   }
 }
 
 already_AddRefed<nsIDocument> nsIDocument::CreateStaticClone(
     nsIDocShell* aCloneContainer) {
-  nsDocument* thisAsDoc = static_cast<nsDocument*>(this);
   mCreatingStaticClone = true;
 
   // Make document use different container during cloning.
   RefPtr<nsDocShell> originalShell = mDocumentContainer.get();
   SetContainer(static_cast<nsDocShell*>(aCloneContainer));
   ErrorResult rv;
-  nsCOMPtr<nsINode> clonedNode = thisAsDoc->CloneNode(true, rv);
+  nsCOMPtr<nsINode> clonedNode = this->CloneNode(true, rv);
   SetContainer(originalShell);
 
-  RefPtr<nsDocument> clonedDoc;
+  nsCOMPtr<nsIDocument> clonedDoc;
   if (rv.Failed()) {
     // Don't return yet; we need to reset mCreatingStaticClone
     rv.SuppressException();
   } else {
-    nsCOMPtr<nsIDocument> tmp = do_QueryInterface(clonedNode);
-    if (tmp) {
-      clonedDoc = static_cast<nsDocument*>(tmp.get());
+    clonedDoc = do_QueryInterface(clonedNode);
+    if (clonedDoc) {
       if (IsStaticDocument()) {
         clonedDoc->mOriginalDocument = mOriginalDocument;
       } else {
         clonedDoc->mOriginalDocument = this;
       }
 
       clonedDoc->mOriginalDocument->mStaticCloneCount++;
 
@@ -9711,17 +9704,17 @@ void FullscreenRoots::Remove(nsIDocument
   }
 }
 
 /* static */
 bool FullscreenRoots::IsEmpty() { return !sInstance; }
 
 // Any fullscreen change waiting for the widget to finish transition
 // is queued here. This is declared static instead of a member of
-// nsDocument because in the majority of time, there would be at most
+// nsIDocument because in the majority of time, there would be at most
 // one document requesting or exiting fullscreen. We shouldn't waste
 // the space to hold for it in every document.
 class PendingFullscreenChangeList {
  public:
   PendingFullscreenChangeList() = delete;
 
   template <typename T>
   static void Add(UniquePtr<T> aChange) {
@@ -10572,17 +10565,17 @@ bool nsIDocument::ApplyFullscreen(Unique
 
     NS_ASSERTION(child->GetFullscreenRoot() == fullScreenRootDoc,
                  "Fullscreen root should be set!");
     if (child == fullScreenRootDoc) {
       break;
     }
     nsIDocument* parent = child->GetParentDocument();
     Element* element = parent->FindContentForSubDocument(child);
-    if (static_cast<nsDocument*>(parent)->FullscreenStackPush(element)) {
+    if (parent->FullscreenStackPush(element)) {
       changed.AppendElement(parent);
       child = parent;
     } else {
       // We've reached either the root, or a point in the doctree where the
       // new fullscreen element container is the same as the previous
       // fullscreen element's container. No more changes need to be made
       // to the fullscreen stacks of documents further up the tree.
       break;
@@ -10756,63 +10749,62 @@ static void ChangePointerLockedElement(E
   nsIPresShell::SetCapturingContent(aElement, CAPTURE_POINTERLOCK);
   DispatchPointerLockChange(aDocument);
 }
 
 NS_IMETHODIMP
 PointerLockRequest::Run() {
   nsCOMPtr<Element> e = do_QueryReferent(mElement);
   nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
-  nsDocument* d = static_cast<nsDocument*>(doc.get());
   const char* error = nullptr;
-  if (!e || !d || !e->GetComposedDoc()) {
+  if (!e || !doc || !e->GetComposedDoc()) {
     error = "PointerLockDeniedNotInDocument";
-  } else if (e->GetComposedDoc() != d) {
+  } else if (e->GetComposedDoc() != doc) {
     error = "PointerLockDeniedMovedDocument";
   }
   if (!error) {
     nsCOMPtr<Element> pointerLockedElement =
         do_QueryReferent(EventStateManager::sPointerLockedElement);
     if (e == pointerLockedElement) {
-      DispatchPointerLockChange(d);
+      DispatchPointerLockChange(doc);
       return NS_OK;
     }
     // Note, we must bypass focus change, so pass true as the last parameter!
     error = GetPointerLockError(e, pointerLockedElement, true);
     // Another element in the same document is requesting pointer lock,
     // just grant it without user input check.
     if (!error && pointerLockedElement) {
-      ChangePointerLockedElement(e, d, pointerLockedElement);
+      ChangePointerLockedElement(e, doc, pointerLockedElement);
       return NS_OK;
     }
   }
   // If it is neither user input initiated, nor requested in fullscreen,
   // it should be rejected.
   if (!error && !mUserInputOrChromeCaller && !doc->GetFullscreenElement()) {
     error = "PointerLockDeniedNotInputDriven";
   }
-  if (!error && !d->SetPointerLock(e, NS_STYLE_CURSOR_NONE)) {
+  if (!error && !doc->SetPointerLock(e, NS_STYLE_CURSOR_NONE)) {
     error = "PointerLockDeniedFailedToLock";
   }
   if (error) {
-    DispatchPointerLockError(d, error);
+    DispatchPointerLockError(doc, error);
     return NS_OK;
   }
 
-  ChangePointerLockedElement(e, d, nullptr);
+  ChangePointerLockedElement(e, doc, nullptr);
   nsContentUtils::DispatchEventOnlyToChrome(
       doc, ToSupports(e), NS_LITERAL_STRING("MozDOMPointerLock:Entered"),
       CanBubble::eYes, Cancelable::eNo, /* DefaultAction */ nullptr);
   return NS_OK;
 }
 
 void nsIDocument::RequestPointerLock(Element* aElement,
                                      CallerType aCallerType) {
   NS_ASSERTION(aElement,
-               "Must pass non-null element to nsDocument::RequestPointerLock");
+               "Must pass non-null element to nsIDocument::RequestPointerLock");
 
   nsCOMPtr<Element> pointerLockedElement =
       do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (aElement == pointerLockedElement) {
     DispatchPointerLockChange(this);
     return;
   }
 
@@ -11184,18 +11176,17 @@ nsIDocument* nsIDocument::GetTopLevelCon
     }
 
     // If we ever have a non-content parent before we hit a toplevel content
     // parent, then we're never going to find one.  Just bail.
     if (!parent->IsContentDocument()) {
       return nullptr;
     }
 
-    nsIDocument* candidate = parent->GetParentDocument();
-    parent = static_cast<nsDocument*>(candidate);
+    parent = parent->GetParentDocument();
   } while (parent);
 
   return parent;
 }
 
 static bool MightBeChromeScheme(nsIURI* aURI) {
   MOZ_ASSERT(aURI);
   bool isChrome = true;
@@ -11301,18 +11292,18 @@ bool nsIDocument::InlineScriptAllowedByC
     NS_ENSURE_SUCCESS(rv, true);
   }
   return allowsInlineScript;
 }
 
 static bool ReportExternalResourceUseCounters(nsIDocument* aDocument,
                                               void* aData) {
   const auto reportKind =
-      nsDocument::UseCounterReportKind::eIncludeExternalResources;
-  static_cast<nsDocument*>(aDocument)->ReportUseCounters(reportKind);
+      nsIDocument::UseCounterReportKind::eIncludeExternalResources;
+  aDocument->ReportUseCounters(reportKind);
   return true;
 }
 
 void nsIDocument::ReportUseCounters(UseCounterReportKind aKind) {
   static const bool sDebugUseCounters = false;
   if (mReportedUseCounters) {
     return;
   }
@@ -11456,18 +11447,18 @@ void nsIDocument::UpdateIntersectionObse
 }
 
 void nsIDocument::ScheduleIntersectionObserverNotification() {
   if (mIntersectionObservers.IsEmpty()) {
     return;
   }
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   nsCOMPtr<nsIRunnable> notification =
-      NewRunnableMethod("nsDocument::NotifyIntersectionObservers", this,
-                        &nsDocument::NotifyIntersectionObservers);
+      NewRunnableMethod("nsIDocument::NotifyIntersectionObservers", this,
+                        &nsIDocument::NotifyIntersectionObservers);
   Dispatch(TaskCategory::Other, notification.forget());
 }
 
 void nsIDocument::NotifyIntersectionObservers() {
   nsTArray<RefPtr<DOMIntersectionObserver>> observers(
       mIntersectionObservers.Count());
   for (auto iter = mIntersectionObservers.Iter(); !iter.Done(); iter.Next()) {
     DOMIntersectionObserver* observer = iter.Get()->GetKey();
@@ -12060,34 +12051,34 @@ nsIDocument* nsIDocument::GetSameTypePar
  */
 FlashClassification nsIDocument::PrincipalFlashClassification() {
   MOZ_ASSERT(mPrincipalFlashClassifier);
   return mPrincipalFlashClassifier->ClassifyMaybeSync(NodePrincipal(),
                                                       IsThirdParty());
 }
 
 /**
- * Helper function for |nsDocument::PrincipalFlashClassification|
+ * Helper function for |nsIDocument::PrincipalFlashClassification|
  *
  * Adds a table name string to a table list (a comma separated string). The
  * table will not be added if the name is an empty string.
  */
 static void MaybeAddTableToTableList(const nsACString& aTableNames,
                                      nsACString& aTableList) {
   if (aTableNames.IsEmpty()) {
     return;
   }
   if (!aTableList.IsEmpty()) {
     aTableList.AppendLiteral(",");
   }
   aTableList.Append(aTableNames);
 }
 
 /**
- * Helper function for |nsDocument::PrincipalFlashClassification|
+ * Helper function for |nsIDocument::PrincipalFlashClassification|
  *
  * Takes an array of table names and a comma separated list of table names
  * Returns |true| if any table name in the array matches a table name in the
  * comma separated list.
  */
 static bool ArrayContainsTable(const nsTArray<nsCString>& aTableArray,
                                const nsACString& aTableNames) {
   for (const nsCString& table : aTableArray) {
@@ -12482,17 +12473,17 @@ FlashClassification nsIDocument::Compute
  * This function will NOT return FlashClassification::Unclassified
  */
 FlashClassification nsIDocument::DocumentFlashClassification() {
   if (mFlashClassification == FlashClassification::Unclassified) {
     FlashClassification result = ComputeFlashClassification();
     mFlashClassification = result;
     MOZ_ASSERT(
         result != FlashClassification::Unclassified,
-        "nsDocument::GetPluginClassification should never return Unclassified");
+        "nsIDocument::GetPluginClassification should never return Unclassified");
   }
 
   return mFlashClassification;
 }
 
 /**
  * Initializes |mIsThirdParty| if necessary and returns its value. The value
  * returned represents whether this document should be considered Third-Party.
deleted file mode 100644
--- a/dom/base/nsDocument.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/*
- * Base class for all our document implementations.
- */
-
-#ifndef nsDocument_h___
-#define nsDocument_h___
-
-#include "nsIDocument.h"
-
-#define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0)
-#define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1)
-#define XML_DECLARATION_BITS_STANDALONE_EXISTS (1 << 2)
-#define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3)
-
-// Base class for our document implementations.
-class nsDocument : public nsIDocument {
- protected:
-
-  explicit nsDocument(const char* aContentType);
-  virtual ~nsDocument();
-
-  // Don't add stuff here, add to nsIDocument instead.
-
- private:
-  nsDocument(const nsDocument& aOther) = delete;
-  nsDocument& operator=(const nsDocument& aOther) = delete;
-};
-
-#endif /* nsDocument_h___ */
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -8,17 +8,17 @@
 
 #include "nsFocusManager.h"
 
 #include "ChildIterator.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsGkAtoms.h"
 #include "nsGlobalWindow.h"
 #include "nsContentUtils.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsIContentParent.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIFormControl.h"
 #include "nsLayoutUtils.h"
@@ -981,17 +981,17 @@ nsFocusManager::FireDelayedEvents(nsIDoc
   // fire any delayed focus and blur events in the same order that they were
   // added
   for (uint32_t i = 0; i < mDelayedBlurFocusEvents.Length(); i++) {
     if (mDelayedBlurFocusEvents[i].mDocument == aDocument) {
       if (!aDocument->GetInnerWindow() ||
           !aDocument->GetInnerWindow()->IsCurrentInnerWindow()) {
         // If the document was navigated away from or is defunct, don't bother
         // firing events on it. Note the symmetry between this condition and
-        // the similar one in nsDocument.cpp:FireOrClearDelayedEvents.
+        // the similar one in nsIDocument.cpp:FireOrClearDelayedEvents.
         mDelayedBlurFocusEvents.RemoveElementAt(i);
         --i;
       } else if (!aDocument->EventHandlingSuppressed()) {
         EventMessage message = mDelayedBlurFocusEvents[i].mEventMessage;
         nsCOMPtr<EventTarget> target = mDelayedBlurFocusEvents[i].mTarget;
         nsCOMPtr<nsIPresShell> presShell =
             mDelayedBlurFocusEvents[i].mPresShell;
         nsCOMPtr<EventTarget> relatedTarget =
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -1994,17 +1994,17 @@ nsresult nsGlobalWindowInner::PostHandle
     // down.
     if (mDoc) {
       mDoc->BindingManager()->ExecuteDetachedHandlers();
     }
     mIsDocumentLoaded = false;
   } else if (aVisitor.mEvent->mMessage == eLoad &&
              aVisitor.mEvent->IsTrusted()) {
     // This is page load event since load events don't propagate to |window|.
-    // @see nsDocument::GetEventTargetParent.
+    // @see nsIDocument::GetEventTargetParent.
     mIsDocumentLoaded = true;
 
     mTimeoutManager->OnDocumentLoaded();
 
     nsCOMPtr<Element> element = GetOuterWindow()->GetFrameElementInternal();
     nsIDocShell* docShell = GetDocShell();
     if (element && GetParentInternal() && docShell &&
         docShell->ItemType() != nsIDocShellTreeItem::typeChrome) {
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -446,16 +446,22 @@ class nsIDocument : public nsINode,
                     public mozilla::dom::DispatcherTrait {
   typedef mozilla::dom::GlobalObject GlobalObject;
 
  protected:
   using Encoding = mozilla::Encoding;
   template <typename T>
   using NotNull = mozilla::NotNull<T>;
 
+  explicit nsIDocument(const char* aContentType);
+  virtual ~nsIDocument();
+
+  nsIDocument(const nsIDocument&) = delete;
+  nsIDocument& operator=(const nsIDocument&) = delete;
+
  public:
   typedef nsExternalResourceMap::ExternalResourceLoad ExternalResourceLoad;
   typedef mozilla::FullscreenRequest FullscreenRequest;
   typedef mozilla::net::ReferrerPolicy ReferrerPolicyEnum;
   typedef mozilla::dom::Element Element;
   typedef mozilla::dom::SVGElement SVGElement;
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
@@ -473,20 +479,16 @@ class nsIDocument : public nsINode,
                                              func_, params_);                 \
     /* FIXME(emilio): Apparently we can keep observing from the BFCache? That \
        looks bogus. */                                                        \
     if (nsIPresShell* shell = GetObservingShell()) {                          \
       shell->func_ params_;                                                   \
     }                                                                         \
   } while (0)
 
-#ifdef MOZILLA_INTERNAL_API
-  nsIDocument();
-#endif
-
   // nsIApplicationCacheContainer
   NS_DECL_NSIAPPLICATIONCACHECONTAINER
 
   // nsIRadioGroupContainer
   NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor,
                             bool aFlushContent) final {
     return DocumentOrShadowRoot::WalkRadioGroup(aName, aVisitor, aFlushContent);
   }
@@ -619,17 +621,17 @@ class nsIDocument : public nsINode,
   nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo,
                  nsINode** aResult) const override {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   nsresult CloneDocHelper(nsIDocument* clone) const;
 
   /**
    * Signal that the document title may have changed
-   * (see nsDocument::GetTitle).
+   * (see nsIDocument::GetTitle).
    * @param aBoundTitleElement true if an HTML or SVG <title> element
    * has just been bound to the document.
    */
   virtual void NotifyPossibleTitleChange(bool aBoundTitleElement);
 
   /**
    * Return the URI for the document. May return null.
    *
@@ -1897,17 +1899,17 @@ class nsIDocument : public nsINode,
 
   // notify that a content node changed state.  This must happen under
   // a scriptblocker but NOT within a begin/end update.
   void ContentStateChanged(nsIContent* aContent,
                            mozilla::EventStates aStateMask);
 
   // Notify that a document state has changed.
   // This should only be called by callers whose state is also reflected in the
-  // implementation of nsDocument::GetDocumentState.
+  // implementation of nsIDocument::GetDocumentState.
   void DocumentStatesChanged(mozilla::EventStates aStateMask);
 
   // Observation hooks for style data to propagate notifications
   // to document observers
   void StyleRuleChanged(mozilla::StyleSheet* aStyleSheet,
                         mozilla::css::Rule* aStyleRule);
   void StyleRuleAdded(mozilla::StyleSheet* aStyleSheet,
                       mozilla::css::Rule* aStyleRule);
@@ -3619,18 +3621,16 @@ class nsIDocument : public nsINode,
 
   void DecreaseStackRefCnt() {
     if (--mStackRefCnt == 0 && mNeedsReleaseAfterStackRefCntRelease) {
       mNeedsReleaseAfterStackRefCntRelease = false;
       NS_RELEASE_THIS();
     }
   }
 
-  ~nsIDocument();
-
   // Never ever call this. Only call GetWindow!
   nsPIDOMWindowOuter* GetWindowInternal() const;
 
   // Never ever call this. Only call GetScriptHandlingObject!
   nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const;
 
   // Never ever call this. Only call AllowXULXBL!
   bool InternalAllowXULXBL();
@@ -3808,17 +3808,17 @@ class nsIDocument : public nsINode,
   bool mIgnoreDocGroupMismatches : 1;
 
   // True if we're loaded as data and therefor has any dangerous stuff, such
   // as scripts and plugins, disabled.
   bool mLoadedAsData : 1;
 
   // This flag is only set in XMLDocument, for e.g. documents used in XBL. We
   // don't want animations to play in such documents, so we need to store the
-  // flag here so that we can check it in nsDocument::GetAnimationController.
+  // flag here so that we can check it in nsIDocument::GetAnimationController.
   bool mLoadedAsInteractiveData : 1;
 
   // If true, whoever is creating the document has gotten it to the
   // point where it's safe to start layout on it.
   bool mMayStartLayout : 1;
 
   // True iff we've ever fired a DOMTitleChanged event for this document
   bool mHaveFiredTitleChange : 1;
@@ -4103,17 +4103,17 @@ class nsIDocument : public nsINode,
   // The sandbox flags on the document. These reflect the value of the sandbox
   // attribute of the associated IFRAME or CSP-protectable content, if existent.
   // These are set at load time and are immutable - see nsSandboxFlags.h for the
   // possible flags.
   uint32_t mSandboxFlags;
 
   nsCString mContentLanguage;
 
-  // The channel that got passed to nsDocument::StartDocumentLoad(), if any.
+  // The channel that got passed to nsIDocument::StartDocumentLoad(), if any.
   nsCOMPtr<nsIChannel> mChannel;
 
  private:
   nsCString mContentType;
 
  protected:
   // For document.write() we may need a different content type than
   // mContentType.
@@ -4308,16 +4308,18 @@ class nsIDocument : public nsINode,
     MinScaleSize,
   };
   ViewportOverflowType mViewportOverflowType;
 
   PLDHashTable* mSubDocuments;
 
   nsDocHeaderData* mHeaderData;
 
+  // For determining if this is a flash document which should be
+  // blocked based on its principal.
   RefPtr<PrincipalFlashClassifier> mPrincipalFlashClassifier;
   mozilla::dom::FlashClassification mFlashClassification;
   // Do not use this value directly. Call the |IsThirdParty()| method, which
   // caches its result here.
   mozilla::Maybe<bool> mIsThirdParty;
 
   nsRevocableEventPtr<nsRunnableMethod<nsIDocument, void, false>>
       mPendingTitleChangeEvent;
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -38,17 +38,17 @@
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsAttrValueOrString.h"
 #include "nsBindingManager.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentList.h"
 #include "nsContentUtils.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "mozilla/dom/Attr.h"
 #include "nsDOMAttributeMap.h"
 #include "nsDOMCID.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsError.h"
 #include "nsDOMMutationObserver.h"
 #include "nsDOMString.h"
 #include "nsDOMTokenList.h"
@@ -1786,17 +1786,17 @@ void nsINode::Append(const Sequence<Owni
   AppendChild(*node, aRv);
 }
 
 void nsINode::RemoveChildNode(nsIContent* aKid, bool aNotify) {
   // NOTE: This function must not trigger any calls to
   // nsIDocument::GetRootElement() calls until *after* it has removed aKid from
   // aChildArray. Any calls before then could potentially restore a stale
   // value for our cached root element, per note in
-  // nsDocument::RemoveChildNode().
+  // nsIDocument::RemoveChildNode().
   MOZ_ASSERT(aKid && aKid->GetParentNode() == this, "Bogus aKid");
   MOZ_ASSERT(!IsAttr());
 
   nsMutationGuard::DidMutate();
   mozAutoDocUpdate updateBatch(GetComposedDoc(), aNotify);
 
   nsIContent* previousSibling = aKid->GetPreviousSibling();
 
--- a/dom/base/nsNodeInfoManager.cpp
+++ b/dom/base/nsNodeInfoManager.cpp
@@ -24,17 +24,17 @@
 #include "nsReadableUtils.h"
 #include "nsGkAtoms.h"
 #include "nsComponentManagerUtils.h"
 #include "nsLayoutStatics.h"
 #include "nsBindingManager.h"
 #include "nsHashKeys.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsNameSpaceManager.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsWindowSizes.h"
 
 using namespace mozilla;
 using mozilla::dom::NodeInfo;
 
 #include "mozilla/Logging.h"
 
 static LazyLogModule gNodeInfoManagerLeakPRLog("NodeInfoManagerLeak");
@@ -80,31 +80,31 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBindingManager)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsNodeInfoManager, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsNodeInfoManager, Release)
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsNodeInfoManager)
   if (tmp->mDocument) {
-    return NS_CYCLE_COLLECTION_PARTICIPANT(nsDocument)
+    return NS_CYCLE_COLLECTION_PARTICIPANT(nsIDocument)
         ->CanSkip(tmp->mDocument, aRemovingAllowed);
   }
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsNodeInfoManager)
   if (tmp->mDocument) {
-    return NS_CYCLE_COLLECTION_PARTICIPANT(nsDocument)
+    return NS_CYCLE_COLLECTION_PARTICIPANT(nsIDocument)
         ->CanSkipInCC(tmp->mDocument);
   }
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsNodeInfoManager)
   if (tmp->mDocument) {
-    return NS_CYCLE_COLLECTION_PARTICIPANT(nsDocument)
+    return NS_CYCLE_COLLECTION_PARTICIPANT(nsIDocument)
         ->CanSkipThis(tmp->mDocument);
   }
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
 
 nsresult nsNodeInfoManager::Init(nsIDocument* aDocument) {
   MOZ_ASSERT(!mPrincipal, "Being inited when we already have a principal?");
 
   mPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
--- a/dom/base/nsNodeUtils.cpp
+++ b/dom/base/nsNodeUtils.cpp
@@ -13,17 +13,17 @@
 #include "mozilla/dom/Element.h"
 #include "nsIMutationObserver.h"
 #include "nsIDocument.h"
 #include "mozilla/EventListenerManager.h"
 #include "nsIXPConnect.h"
 #include "PLDHashTable.h"
 #include "nsCOMArray.h"
 #include "nsPIDOMWindow.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #ifdef MOZ_XUL
 #include "nsXULElement.h"
 #endif
 #include "nsBindingManager.h"
 #include "nsGenericHTMLElement.h"
 #include "mozilla/AnimationTarget.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ErrorResult.h"
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -913,17 +913,17 @@ nsresult nsObjectLoadingContent::BuildPa
 
   GetNestedParams(mCachedParameters);
 
   return NS_OK;
 }
 
 void nsObjectLoadingContent::NotifyOwnerDocumentActivityChanged() {
   // XXX(johns): We cannot touch plugins or run arbitrary script from this call,
-  //             as nsDocument is in a non-reentrant state.
+  //             as nsIDocument is in a non-reentrant state.
 
   // If we have a plugin we want to queue an event to stop it unless we are
   // moved into an active document before returning to the event loop.
   if (mInstanceOwner || mInstantiating) {
     QueueCheckPluginStopEvent();
   }
 }
 
--- a/dom/base/nsObjectLoadingContent.h
+++ b/dom/base/nsObjectLoadingContent.h
@@ -150,17 +150,17 @@ class nsObjectLoadingContent : public ns
    *
    * aIsLoading indicates that we are in the loading code, and we can bypass
    * the mIsLoading check.
    */
   nsresult InstantiatePluginInstance(bool aIsLoading = false);
 
   /**
    * Notify this class the document state has changed
-   * Called by nsDocument so we may suspend plugins in inactive documents)
+   * Called by nsIDocument so we may suspend plugins in inactive documents)
    */
   void NotifyOwnerDocumentActivityChanged();
 
   /**
    * When a plug-in is instantiated, it can create a scriptable
    * object that the page wants to interact with.  We expose this
    * object by placing it on the prototype chain of our element,
    * between the element itself and its most-derived DOM prototype.
--- a/dom/base/nsTextNode.cpp
+++ b/dom/base/nsTextNode.cpp
@@ -15,17 +15,17 @@
 #include "nsIDOMEventListener.h"
 #include "nsIDocument.h"
 #include "nsThreadUtils.h"
 #include "nsStubMutationObserver.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #ifdef DEBUG
 #include "nsRange.h"
 #endif
-#include "nsDocument.h"
+#include "nsIDocument.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 /**
  * class used to implement attr() generated content
  */
 class nsAttributeTextNode final : public nsTextNode,
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -23,17 +23,17 @@
 #include "mozilla/dom/WorkerRunnable.h"
 #include "mozilla/dom/WorkerScope.h"
 #include "mozilla/dom/WorkletGlobalScope.h"
 #include "mozilla/dom/WorkletImpl.h"
 #include "mozilla/dom/WorkletThread.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/StaticPrefs.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsDOMNavigationTiming.h"
 #include "nsGlobalWindow.h"
 #include "nsJSUtils.h"
 #include "nsNetUtil.h"
 #include "xpcpublic.h"
 #include "nsContentUtils.h"
 #include "nsDocShell.h"
 #include "nsProxyRelease.h"
--- a/dom/html/HTMLImageElement.cpp
+++ b/dom/html/HTMLImageElement.cpp
@@ -6,17 +6,17 @@
 
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/HTMLImageElementBinding.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsMappedAttributes.h"
 #include "nsSize.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsIDocument.h"
 #include "nsImageFrame.h"
 #include "nsIScriptContext.h"
 #include "nsIURL.h"
 #include "nsIIOService.h"
 #include "nsIServiceManager.h"
 #include "nsContentUtils.h"
 #include "nsContainerFrame.h"
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -46,17 +46,17 @@
 #include "nsIPresShell.h"
 #include "nsIFormControlFrame.h"
 #include "nsITextControlFrame.h"
 #include "nsIFrame.h"
 #include "nsRangeFrame.h"
 #include "nsIServiceManager.h"
 #include "nsError.h"
 #include "nsIEditor.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsAttrValueOrString.h"
 #include "nsDateTimeControlFrame.h"
 
 #include "mozilla/PresState.h"
 #include "nsLinebreakConverter.h"  //to strip out carriage returns
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsLayoutUtils.h"
--- a/dom/html/HTMLSlotElement.cpp
+++ b/dom/html/HTMLSlotElement.cpp
@@ -5,17 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/HTMLSlotElement.h"
 #include "mozilla/dom/HTMLSlotElementBinding.h"
 #include "mozilla/dom/HTMLUnknownElement.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "nsGkAtoms.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 
 nsGenericHTMLElement* NS_NewHTMLSlotElement(
     already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
     mozilla::dom::FromParser aFromParser) {
   RefPtr<mozilla::dom::NodeInfo> nodeInfo(std::move(aNodeInfo));
   return new mozilla::dom::HTMLSlotElement(nodeInfo.forget());
 }
 
--- a/dom/html/HTMLUnknownElement.cpp
+++ b/dom/html/HTMLUnknownElement.cpp
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "mozilla/dom/HTMLUnknownElement.h"
 #include "mozilla/dom/HTMLElementBinding.h"
 #include "jsapi.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Unknown)
 
 namespace mozilla {
 namespace dom {
--- a/dom/html/MediaDocument.cpp
+++ b/dom/html/MediaDocument.cpp
@@ -138,17 +138,17 @@ nsresult MediaDocument::Init() {
 }
 
 nsresult MediaDocument::StartDocumentLoad(const char* aCommand,
                                           nsIChannel* aChannel,
                                           nsILoadGroup* aLoadGroup,
                                           nsISupports* aContainer,
                                           nsIStreamListener** aDocListener,
                                           bool aReset, nsIContentSink* aSink) {
-  nsresult rv = nsDocument::StartDocumentLoad(
+  nsresult rv = nsIDocument::StartDocumentLoad(
       aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // We try to set the charset of the current document to that of the
   // 'genuine' (as opposed to an intervening 'chrome') parent document
   // that may be in a different window/tab. Even if we fail here,
@@ -269,17 +269,17 @@ void MediaDocument::GetFileName(nsAStrin
 
   nsAutoCString fileName;
   url->GetFileName(fileName);
   if (fileName.IsEmpty()) return;
 
   nsAutoCString docCharset;
   // Now that the charset is set in |StartDocumentLoad| to the charset of
   // the document viewer instead of a bogus value ("windows-1252" set in
-  // |nsDocument|'s ctor), the priority is given to the current charset.
+  // |nsIDocument|'s ctor), the priority is given to the current charset.
   // This is necessary to deal with a media document being opened in a new
   // window or a new tab.
   if (mCharacterSetSource != kCharsetUninitialized) {
     mCharacterSet->Name(docCharset);
   } else {
     // resort to UTF-8
     SetDocumentCharacterSet(UTF_8_ENCODING);
   }
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -160,17 +160,17 @@ nsresult NS_NewHTMLDocument(nsIDocument*
 
   doc->SetLoadedAsData(aLoadedAsData);
   doc.forget(aInstancePtrResult);
 
   return NS_OK;
 }
 
 nsHTMLDocument::nsHTMLDocument()
-    : nsDocument("text/html"),
+    : nsIDocument("text/html"),
       mContentListHolder(nullptr),
       mNumForms(0),
       mWriteLevel(0),
       mLoadFlags(0),
       mTooDeepWriteRecursion(false),
       mDisableDocWrite(false),
       mWarnedWidthHeight(false),
       mContentEditableCount(0),
@@ -179,51 +179,51 @@ nsHTMLDocument::nsHTMLDocument()
       mPendingMaybeEditingStateChanged(false) {
   mType = eHTML;
   mDefaultElementType = kNameSpaceID_XHTML;
   mCompatMode = eCompatibility_NavQuirks;
 }
 
 nsHTMLDocument::~nsHTMLDocument() {}
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsDocument, mAll,
+NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsIDocument, mAll,
                                    mWyciwygChannel, mMidasCommandManager)
 
-NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsDocument,
+NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsIDocument,
                                              nsIHTMLDocument)
 
 JSObject* nsHTMLDocument::WrapNode(JSContext* aCx,
                                    JS::Handle<JSObject*> aGivenProto) {
   return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 nsresult nsHTMLDocument::Init() {
-  nsresult rv = nsDocument::Init();
+  nsresult rv = nsIDocument::Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Now reset the compatibility mode of the CSSLoader
   // to match our compat mode.
   CSSLoader()->SetCompatibilityMode(mCompatMode);
 
   return NS_OK;
 }
 
 void nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
-  nsDocument::Reset(aChannel, aLoadGroup);
+  nsIDocument::Reset(aChannel, aLoadGroup);
 
   if (aChannel) {
     aChannel->GetLoadFlags(&mLoadFlags);
   }
 }
 
 void nsHTMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
                                 nsIPrincipal* aPrincipal) {
   mLoadFlags = nsIRequest::LOAD_NORMAL;
 
-  nsDocument::ResetToURI(aURI, aLoadGroup, aPrincipal);
+  nsIDocument::ResetToURI(aURI, aLoadGroup, aPrincipal);
 
   mImages = nullptr;
   mApplets = nullptr;
   mEmbeds = nullptr;
   mLinks = nullptr;
   mAnchors = nullptr;
   mScripts = nullptr;
 
@@ -438,17 +438,17 @@ void nsHTMLDocument::TryFallback(int32_t
   if (kCharsetFromFallback <= aCharsetSource) return;
 
   aCharsetSource = kCharsetFromFallback;
   aEncoding = FallbackEncoding::FromLocale();
 }
 
 void nsHTMLDocument::SetDocumentCharacterSet(
     NotNull<const Encoding*> aEncoding) {
-  nsDocument::SetDocumentCharacterSet(aEncoding);
+  nsIDocument::SetDocumentCharacterSet(aEncoding);
   // Make sure to stash this charset on our channel as needed if it's a wyciwyg
   // channel.
   nsCOMPtr<nsIWyciwygChannel> wyciwygChannel = do_QueryInterface(mChannel);
   if (wyciwygChannel) {
     nsAutoCString charset;
     aEncoding->Name(charset);
     wyciwygChannel->SetCharsetAndSource(GetDocumentCharacterSetSource(),
                                         charset);
@@ -521,17 +521,17 @@ nsresult nsHTMLDocument::StartDocumentLo
       if (uri->GetSpecOrDefault().EqualsLiteral("about:blank")) {
         loadAsHtml5 = false;
       }
     }
   }
 
   CSSLoader()->SetCompatibilityMode(mCompatMode);
 
-  nsresult rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
+  nsresult rv = nsIDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup,
                                               aContainer, aDocListener, aReset);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // Store the security info for future use with wyciwyg channels.
   aChannel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
 
@@ -766,38 +766,38 @@ void nsHTMLDocument::StopDocumentLoad() 
 
   // Remove the wyciwyg channel request from the document load group
   // that we added in Open() if Open() was called on this doc.
   RemoveWyciwygChannel();
   NS_ASSERTION(!mWyciwygChannel,
                "nsHTMLDocument::StopDocumentLoad(): "
                "nsIWyciwygChannel could not be removed!");
 
-  nsDocument::StopDocumentLoad();
+  nsIDocument::StopDocumentLoad();
   UnblockOnload(false);
 }
 
 void nsHTMLDocument::BeginLoad() {
   if (IsEditingOn()) {
     // Reset() blows away all event listeners in the document, and our
     // editor relies heavily on those. Midas is turned on, to make it
     // work, re-initialize it to give it a chance to add its event
     // listeners again.
 
     TurnEditingOff();
     EditingStateChanged();
   }
-  nsDocument::BeginLoad();
+  nsIDocument::BeginLoad();
 }
 
 void nsHTMLDocument::EndLoad() {
   bool turnOnEditing =
       mParser && (HasFlag(NODE_IS_EDITABLE) || mContentEditableCount > 0);
-  // Note: nsDocument::EndLoad nulls out mParser.
-  nsDocument::EndLoad();
+  // Note: nsIDocument::EndLoad nulls out mParser.
+  nsIDocument::EndLoad();
   if (turnOnEditing) {
     EditingStateChanged();
   }
 }
 
 void nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode) {
   NS_ASSERTION(IsHTMLDocument() || aMode == eCompatibility_FullStandards,
                "Bad compat mode for XHTML document!");
@@ -811,17 +811,17 @@ void nsHTMLDocument::SetCompatibilityMod
     pc->CompatibilityModeChanged();
   }
 }
 
 nsIContent* nsHTMLDocument::GetUnfocusedKeyEventTarget() {
   if (nsGenericHTMLElement* body = GetBody()) {
     return body;
   }
-  return nsDocument::GetUnfocusedKeyEventTarget();
+  return nsIDocument::GetUnfocusedKeyEventTarget();
 }
 
 already_AddRefed<nsIURI> nsHTMLDocument::GetDomainURI() {
   nsIPrincipal* principal = NodePrincipal();
 
   nsCOMPtr<nsIURI> uri;
   principal->GetDomain(getter_AddRefs(uri));
   if (uri) {
@@ -2017,17 +2017,17 @@ void nsHTMLDocument::MaybeEditingStateCh
                             &nsHTMLDocument::MaybeEditingStateChanged));
     }
   }
 }
 
 void nsHTMLDocument::EndUpdate() {
   const bool reset = !mPendingMaybeEditingStateChanged;
   mPendingMaybeEditingStateChanged = true;
-  nsDocument::EndUpdate();
+  nsIDocument::EndUpdate();
   if (reset) {
     mPendingMaybeEditingStateChanged = false;
   }
   MaybeEditingStateChanged();
 }
 
 void nsHTMLDocument::SetMayStartLayout(bool aMayStartLayout) {
   nsIDocument::SetMayStartLayout(aMayStartLayout);
@@ -3095,22 +3095,22 @@ bool nsHTMLDocument::IsEditingOnAfterFlu
     doc->FlushPendingNotifications(FlushType::Frames);
   }
 
   return IsEditingOn();
 }
 
 void nsHTMLDocument::RemovedFromDocShell() {
   mEditingState = eOff;
-  nsDocument::RemovedFromDocShell();
+  nsIDocument::RemovedFromDocShell();
 }
 
 /* virtual */ void nsHTMLDocument::DocAddSizeOfExcludingThis(
     nsWindowSizes& aWindowSizes) const {
-  nsDocument::DocAddSizeOfExcludingThis(aWindowSizes);
+  nsIDocument::DocAddSizeOfExcludingThis(aWindowSizes);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - mLinks
   // - mAnchors
   // - mWyciwygChannel
   // - mMidasCommandManager
 }
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef nsHTMLDocument_h___
 #define nsHTMLDocument_h___
 
 #include "mozilla/Attributes.h"
 #include "nsContentList.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsIHTMLDocument.h"
 #include "nsIHTMLCollection.h"
 #include "nsIScriptElement.h"
 #include "nsTArray.h"
 
 #include "PLDHashTable.h"
 #include "nsIHttpChannel.h"
 #include "nsThreadUtils.h"
@@ -28,28 +28,28 @@ class nsIWyciwygChannel;
 class nsILoadGroup;
 
 namespace mozilla {
 namespace dom {
 class HTMLAllCollection;
 }  // namespace dom
 }  // namespace mozilla
 
-class nsHTMLDocument : public nsDocument, public nsIHTMLDocument {
+class nsHTMLDocument : public nsIDocument, public nsIHTMLDocument {
   typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
 
  public:
-  using nsDocument::GetPlugins;
-  using nsDocument::SetDocumentURI;
+  using nsIDocument::GetPlugins;
+  using nsIDocument::SetDocumentURI;
 
   nsHTMLDocument();
   virtual nsresult Init() override;
 
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, nsDocument)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, nsIDocument)
 
   // nsIDocument
   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
   virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
                           nsIPrincipal* aPrincipal) override;
 
   virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
                                      nsILoadGroup* aLoadGroup,
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -972,17 +972,17 @@ nsresult ContentChild::ProvideWindowComm
                           aTabOpener->WebWidget()->GetDefaultScale().scale);
     }
 
     newChild->SetMaxTouchPoints(maxTouchPoints);
     newChild->SetHasSiblings(hasSiblings);
 
     // Set the opener window for this window before we start loading the
     // document inside of it. We have to do this before loading the remote
-    // scripts, because they can poke at the document and cause the nsDocument
+    // scripts, because they can poke at the document and cause the nsIDocument
     // to be created before the openerwindow
     nsCOMPtr<mozIDOMWindowProxy> windowProxy =
         do_GetInterface(newChild->WebNavigation());
     if (!aForceNoOpener && windowProxy && aParent) {
       nsPIDOMWindowOuter* outer = nsPIDOMWindowOuter::From(windowProxy);
       nsPIDOMWindowOuter* parent = nsPIDOMWindowOuter::From(aParent);
       outer->SetOpenerWindow(parent, *aWindowIsNew);
     }
--- a/dom/smil/SMILAnimationController.h
+++ b/dom/smil/SMILAnimationController.h
@@ -28,17 +28,17 @@ class Element;
 class SVGAnimationElement;
 }  // namespace dom
 
 //----------------------------------------------------------------------
 // SMILAnimationController
 //
 // The animation controller maintains the animation timer and determines the
 // sample times and sample rate for all SMIL animations in a document. There is
-// at most one animation controller per nsDocument so that frame-rate tuning can
+// at most one animation controller per document so that frame-rate tuning can
 // be performed at a document-level.
 //
 // The animation controller can contain many child time containers (timed
 // document root objects) which may correspond to SVG document fragments within
 // a compound document. These time containers can be paused individually or
 // here, at the document level.
 //
 class SMILAnimationController final : public nsSMILTimeContainer,
--- a/dom/smil/nsSMILCompositorTable.h
+++ b/dom/smil/nsSMILCompositorTable.h
@@ -8,16 +8,16 @@
 #define NS_SMILCOMPOSITORTABLE_H_
 
 #include "nsTHashtable.h"
 
 //----------------------------------------------------------------------
 // nsSMILCompositorTable : A hashmap of nsSMILCompositors
 //
 // This is just a forward-declaration because it is included in
-// SMILAnimationController which is used in nsDocument. We don't want to
+// SMILAnimationController which is used in nsIDocument. We don't want to
 // expose all of nsSMILCompositor or otherwise any changes to it will mean the
 // whole world will need to be rebuilt.
 
 class nsSMILCompositor;
 typedef nsTHashtable<nsSMILCompositor> nsSMILCompositorTable;
 
 #endif  // NS_SMILCOMPOSITORTABLE_H_
--- a/dom/webidl/Animatable.webidl
+++ b/dom/webidl/Animatable.webidl
@@ -18,11 +18,11 @@ dictionary AnimationFilter {
   boolean subtree = false;
 };
 
 [NoInterfaceObject]
 interface Animatable {
   [Throws]
   Animation animate(object? keyframes,
                     optional UnrestrictedDoubleOrKeyframeAnimationOptions options);
-  [Func="nsDocument::IsWebAnimationsGetAnimationsEnabled"]
+  [Func="nsIDocument::IsWebAnimationsGetAnimationsEnabled"]
   sequence<Animation> getAnimations(optional AnimationFilter filter);
 };
--- a/dom/webidl/Animation.webidl
+++ b/dom/webidl/Animation.webidl
@@ -11,33 +11,33 @@
  */
 
 enum AnimationPlayState { "idle", "running", "paused", "finished" };
 
 [Constructor (optional AnimationEffect? effect = null,
               optional AnimationTimeline? timeline)]
 interface Animation : EventTarget {
   attribute DOMString id;
-  [Func="nsDocument::IsWebAnimationsEnabled", Pure]
+  [Func="nsIDocument::IsWebAnimationsEnabled", Pure]
   attribute AnimationEffect? effect;
-  [Func="nsDocument::AreWebAnimationsTimelinesEnabled"]
+  [Func="nsIDocument::AreWebAnimationsTimelinesEnabled"]
   attribute AnimationTimeline? timeline;
   [BinaryName="startTimeAsDouble"]
   attribute double? startTime;
   [SetterThrows, BinaryName="currentTimeAsDouble"]
   attribute double? currentTime;
 
            attribute double             playbackRate;
   [BinaryName="playStateFromJS"]
   readonly attribute AnimationPlayState playState;
   [BinaryName="pendingFromJS"]
   readonly attribute boolean            pending;
-  [Func="nsDocument::IsWebAnimationsEnabled", Throws]
+  [Func="nsIDocument::IsWebAnimationsEnabled", Throws]
   readonly attribute Promise<Animation> ready;
-  [Func="nsDocument::IsWebAnimationsEnabled", Throws]
+  [Func="nsIDocument::IsWebAnimationsEnabled", Throws]
   readonly attribute Promise<Animation> finished;
            attribute EventHandler       onfinish;
            attribute EventHandler       oncancel;
   void cancel ();
   [Throws]
   void finish ();
   [Throws, BinaryName="playFromJS"]
   void play ();
--- a/dom/webidl/AnimationEffect.webidl
+++ b/dom/webidl/AnimationEffect.webidl
@@ -50,16 +50,16 @@ dictionary OptionalEffectTiming {
 dictionary ComputedEffectTiming : EffectTiming {
   unrestricted double   endTime = 0.0;
   unrestricted double   activeDuration = 0.0;
   double?               localTime = null;
   double?               progress = null;
   unrestricted double?  currentIteration = null;
 };
 
-[Func="nsDocument::IsWebAnimationsEnabled"]
+[Func="nsIDocument::IsWebAnimationsEnabled"]
 interface AnimationEffect {
   EffectTiming getTiming();
   [BinaryName="getComputedTimingAsDict"]
   ComputedEffectTiming getComputedTiming();
   [Throws]
   void updateTiming(optional OptionalEffectTiming timing);
 };
--- a/dom/webidl/AnimationPlaybackEvent.webidl
+++ b/dom/webidl/AnimationPlaybackEvent.webidl
@@ -5,17 +5,17 @@
  *
  * The origin of this IDL file is
  * https://drafts.csswg.org/web-animations/#animationplaybackevent
  *
  * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-[Func="nsDocument::IsWebAnimationsEnabled",
+[Func="nsIDocument::IsWebAnimationsEnabled",
  Constructor(DOMString type,
              optional AnimationPlaybackEventInit eventInitDict)]
 interface AnimationPlaybackEvent : Event {
   readonly attribute double? currentTime;
   readonly attribute double? timelineTime;
 };
 
 dictionary AnimationPlaybackEventInit : EventInit {
--- a/dom/webidl/AnimationTimeline.webidl
+++ b/dom/webidl/AnimationTimeline.webidl
@@ -5,13 +5,13 @@
  *
  * The origin of this IDL file is
  * https://drafts.csswg.org/web-animations/#animationtimeline
  *
  * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-[Func="nsDocument::AreWebAnimationsTimelinesEnabled"]
+[Func="nsIDocument::AreWebAnimationsTimelinesEnabled"]
 interface AnimationTimeline {
   [BinaryName="currentTimeAsDouble"]
   readonly attribute double? currentTime;
 };
--- a/dom/webidl/CSSAnimation.webidl
+++ b/dom/webidl/CSSAnimation.webidl
@@ -5,13 +5,13 @@
  *
  * The origin of this IDL file is
  * http://dev.w3.org/csswg/css-animations-2/#the-CSSAnimation-interface
  *
  * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-[Func="nsDocument::IsWebAnimationsGetAnimationsEnabled",
+[Func="nsIDocument::IsWebAnimationsGetAnimationsEnabled",
  HeaderFile="nsAnimationManager.h"]
 interface CSSAnimation : Animation {
   [Constant] readonly attribute DOMString animationName;
 };
--- a/dom/webidl/CSSPseudoElement.webidl
+++ b/dom/webidl/CSSPseudoElement.webidl
@@ -10,16 +10,16 @@
  * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 // Both CSSOM and CSS Pseudo-Elements 4 provide contradictory definitions for
 // this interface.
 // What we implement here is a minimal subset of the two definitions which we
 // ship behind a pref until the specification issues have been resolved.
-[Func="nsDocument::IsWebAnimationsGetAnimationsEnabled"]
+[Func="nsIDocument::IsWebAnimationsGetAnimationsEnabled"]
 interface CSSPseudoElement {
   readonly attribute DOMString type;
   readonly attribute Element parentElement;
 };
 
 // https://drafts.csswg.org/web-animations/#extensions-to-the-pseudoelement-interface
 CSSPseudoElement implements Animatable;
--- a/dom/webidl/CSSTransition.webidl
+++ b/dom/webidl/CSSTransition.webidl
@@ -5,13 +5,13 @@
  *
  * The origin of this IDL file is
  * http://dev.w3.org/csswg/css-transitions-2/#the-CSSTransition-interface
  *
  * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-[Func="nsDocument::IsWebAnimationsGetAnimationsEnabled",
+[Func="nsIDocument::IsWebAnimationsGetAnimationsEnabled",
  HeaderFile="nsTransitionManager.h"]
 interface CSSTransition : Animation {
   [Constant] readonly attribute DOMString transitionProperty;
 };
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -256,34 +256,34 @@ partial interface Document {
 
   //(HTML only)[SameObject] readonly attribute HTMLAllCollection all;
 };
 
 // https://fullscreen.spec.whatwg.org/#api
 partial interface Document {
   // Note: Per spec the 'S' in these two is lowercase, but the "Moz"
   // versions have it uppercase.
-  [LenientSetter, Unscopable, Func="nsDocument::IsUnprefixedFullscreenEnabled"]
+  [LenientSetter, Unscopable, Func="nsIDocument::IsUnprefixedFullscreenEnabled"]
   readonly attribute boolean fullscreen;
   [BinaryName="fullscreen"]
   readonly attribute boolean mozFullScreen;
-  [LenientSetter, Func="nsDocument::IsUnprefixedFullscreenEnabled", NeedsCallerType]
+  [LenientSetter, Func="nsIDocument::IsUnprefixedFullscreenEnabled", NeedsCallerType]
   readonly attribute boolean fullscreenEnabled;
   [BinaryName="fullscreenEnabled", NeedsCallerType]
   readonly attribute boolean mozFullScreenEnabled;
 
-  [Throws, Func="nsDocument::IsUnprefixedFullscreenEnabled"]
+  [Throws, Func="nsIDocument::IsUnprefixedFullscreenEnabled"]
   Promise<void> exitFullscreen();
   [Throws, BinaryName="exitFullscreen"]
   Promise<void> mozCancelFullScreen();
 
   // Events handlers
-  [Func="nsDocument::IsUnprefixedFullscreenEnabled"]
+  [Func="nsIDocument::IsUnprefixedFullscreenEnabled"]
   attribute EventHandler onfullscreenchange;
-  [Func="nsDocument::IsUnprefixedFullscreenEnabled"]
+  [Func="nsIDocument::IsUnprefixedFullscreenEnabled"]
   attribute EventHandler onfullscreenerror;
 };
 
 // https://w3c.github.io/pointerlock/#extensions-to-the-document-interface
 // https://w3c.github.io/pointerlock/#extensions-to-the-documentorshadowroot-mixin
 partial interface Document {
   void exitPointerLock();
 
@@ -324,19 +324,19 @@ partial interface Document {
   NodeList  querySelectorAll(DOMString selectors);
 
   //(Not implemented)Element?  find(DOMString selectors, optional (Element or sequence<Node>)? refNodes);
   //(Not implemented)NodeList  findAll(DOMString selectors, optional (Element or sequence<Node>)? refNodes);
 };
 
 // https://drafts.csswg.org/web-animations/#extensions-to-the-document-interface
 partial interface Document {
-  [Func="nsDocument::AreWebAnimationsTimelinesEnabled"]
+  [Func="nsIDocument::AreWebAnimationsTimelinesEnabled"]
   readonly attribute DocumentTimeline timeline;
-  [Func="nsDocument::IsWebAnimationsGetAnimationsEnabled"]
+  [Func="nsIDocument::IsWebAnimationsGetAnimationsEnabled"]
   sequence<Animation> getAnimations();
 };
 
 // https://svgwg.org/svg2-draft/struct.html#InterfaceDocumentExtensions
 partial interface Document {
   [BinaryName="SVGRootElement"]
   readonly attribute SVGSVGElement? rootElement;
 };
@@ -523,17 +523,17 @@ enum FlashClassification {
   "denied"          // Site is on the Flash blacklist
 };
 partial interface Document {
   [ChromeOnly]
   readonly attribute FlashClassification documentFlashClassification;
 };
 
 partial interface Document {
-  [Func="nsDocument::DocumentSupportsL10n"] readonly attribute DocumentL10n? l10n;
+  [Func="nsIDocument::DocumentSupportsL10n"] readonly attribute DocumentL10n? l10n;
 };
 
 Document implements XPathEvaluator;
 Document implements GlobalEventHandlers;
 Document implements DocumentAndElementEventHandlers;
 Document implements TouchEventHandlers;
 Document implements ParentNode;
 Document implements OnErrorEventHandlerForNodes;
--- a/dom/webidl/DocumentTimeline.webidl
+++ b/dom/webidl/DocumentTimeline.webidl
@@ -9,12 +9,12 @@
  * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 dictionary DocumentTimelineOptions {
   DOMHighResTimeStamp originTime = 0;
 };
 
-[Func="nsDocument::AreWebAnimationsTimelinesEnabled",
+[Func="nsIDocument::AreWebAnimationsTimelinesEnabled",
  Constructor (optional DocumentTimelineOptions options)]
 interface DocumentTimeline : AnimationTimeline {
 };
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -235,17 +235,17 @@ dictionary ShadowRootInit {
 // https://dom.spec.whatwg.org/#element
 partial interface Element {
   // Shadow DOM v1
   [Throws, UseCounter]
   ShadowRoot attachShadow(ShadowRootInit shadowRootInitDict);
   [BinaryName="shadowRootByMode"]
   readonly attribute ShadowRoot? shadowRoot;
 
-  [Func="nsDocument::IsCallerChromeOrAddon", BinaryName="shadowRoot"]
+  [Func="nsIDocument::IsCallerChromeOrAddon", BinaryName="shadowRoot"]
   readonly attribute ShadowRoot? openOrClosedShadowRoot;
 
   [BinaryName="assignedSlotByMode"]
   readonly attribute HTMLSlotElement? assignedSlot;
 
   [ChromeOnly, BinaryName="assignedSlot"]
   readonly attribute HTMLSlotElement? openOrClosedAssignedSlot;
 
@@ -256,25 +256,25 @@ partial interface Element {
 Element implements ChildNode;
 Element implements NonDocumentTypeChildNode;
 Element implements ParentNode;
 Element implements Animatable;
 Element implements GeometryUtils;
 
 // https://fullscreen.spec.whatwg.org/#api
 partial interface Element {
-  [Throws, Func="nsDocument::IsUnprefixedFullscreenEnabled", NeedsCallerType]
+  [Throws, Func="nsIDocument::IsUnprefixedFullscreenEnabled", NeedsCallerType]
   Promise<void> requestFullscreen();
   [Throws, BinaryName="requestFullscreen", NeedsCallerType, Deprecated="MozRequestFullScreenDeprecatedPrefix"]
   Promise<void> mozRequestFullScreen();
 
   // Events handlers
-  [Func="nsDocument::IsUnprefixedFullscreenEnabled"]
+  [Func="nsIDocument::IsUnprefixedFullscreenEnabled"]
   attribute EventHandler onfullscreenchange;
-  [Func="nsDocument::IsUnprefixedFullscreenEnabled"]
+  [Func="nsIDocument::IsUnprefixedFullscreenEnabled"]
   attribute EventHandler onfullscreenerror;
 };
 
 // https://w3c.github.io/pointerlock/#extensions-to-the-element-interface
 partial interface Element {
   [NeedsCallerType, Pref="dom.pointer-lock.enabled"]
   void requestPointerLock();
 };
--- a/dom/webidl/KeyframeEffect.webidl
+++ b/dom/webidl/KeyframeEffect.webidl
@@ -17,17 +17,17 @@ enum IterationCompositeOperation {
 
 dictionary KeyframeEffectOptions : EffectTiming {
   IterationCompositeOperation iterationComposite = "replace";
   CompositeOperation          composite = "replace";
 };
 
 // KeyframeEffect should run in the caller's compartment to do custom
 // processing on the `keyframes` object.
-[Func="nsDocument::IsWebAnimationsEnabled",
+[Func="nsIDocument::IsWebAnimationsEnabled",
  RunConstructorInCallerCompartment,
  Constructor ((Element or CSSPseudoElement)? target,
               object? keyframes,
               optional (unrestricted double or KeyframeEffectOptions) options),
  Constructor (KeyframeEffect source)]
 interface KeyframeEffect : AnimationEffect {
   attribute (Element or CSSPseudoElement)?  target;
   [Pref="dom.animations-api.compositing.enabled"]
--- a/dom/xml/XMLDocument.cpp
+++ b/dom/xml/XMLDocument.cpp
@@ -120,34 +120,33 @@ nsresult NS_NewDOMDocument(nsIDocument**
   }
 
   if (isHTML) {
     nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(d);
     NS_ASSERTION(htmlDoc, "HTML Document doesn't implement nsIHTMLDocument?");
     htmlDoc->SetCompatibilityMode(eCompatibility_FullStandards);
     htmlDoc->SetIsXHTML(isXHTML);
   }
-  nsDocument* doc = static_cast<nsDocument*>(d.get());
-  doc->SetLoadedAsData(aLoadedAsData);
-  doc->nsDocument::SetDocumentURI(aDocumentURI);
+  d->SetLoadedAsData(aLoadedAsData);
+  d->SetDocumentURI(aDocumentURI);
   // Must set the principal first, since SetBaseURI checks it.
-  doc->SetPrincipal(aPrincipal);
-  doc->SetBaseURI(aBaseURI);
+  d->SetPrincipal(aPrincipal);
+  d->SetBaseURI(aBaseURI);
 
   // We need to set the script handling object after we set the principal such
   // that the doc group is assigned correctly.
   if (nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aEventObject)) {
     d->SetScriptHandlingObject(sgo);
   } else if (aEventObject) {
     d->SetScopeObject(aEventObject);
   }
 
   // XMLDocuments and documents "created in memory" get to be UTF-8 by default,
   // unlike the legacy HTML mess
-  doc->SetDocumentCharacterSet(UTF_8_ENCODING);
+  d->SetDocumentCharacterSet(UTF_8_ENCODING);
 
   if (aDoctype) {
     ErrorResult result;
     d->AppendChild(*aDoctype, result);
     // Need to WouldReportJSException() if our callee can throw a JS
     // exception (which it can) and we're neither propagating the
     // error out nor unconditionally suppressing it.
     result.WouldReportJSException();
@@ -157,17 +156,17 @@ nsresult NS_NewDOMDocument(nsIDocument**
   }
 
   if (!aQualifiedName.IsEmpty()) {
     ErrorResult result;
     ElementCreationOptionsOrString options;
     options.SetAsString();
 
     nsCOMPtr<Element> root =
-        doc->CreateElementNS(aNamespaceURI, aQualifiedName, options, result);
+        d->CreateElementNS(aNamespaceURI, aQualifiedName, options, result);
     if (NS_WARN_IF(result.Failed())) {
       return result.StealNSResult();
     }
 
     d->AppendChild(*root, result);
     // Need to WouldReportJSException() if our callee can throw a JS
     // exception (which it can) and we're neither propagating the
     // error out nor unconditionally suppressing it.
@@ -204,69 +203,68 @@ nsresult NS_NewXBLDocument(nsIDocument**
                            nsIURI* aDocumentURI, nsIURI* aBaseURI,
                            nsIPrincipal* aPrincipal) {
   nsresult rv = NS_NewDOMDocument(
       aInstancePtrResult, NS_LITERAL_STRING("http://www.mozilla.org/xbl"),
       NS_LITERAL_STRING("bindings"), nullptr, aDocumentURI, aBaseURI,
       aPrincipal, false, nullptr, DocumentFlavorLegacyGuess);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsIDocument* idoc = *aInstancePtrResult;
+  nsIDocument* doc = *aInstancePtrResult;
 
   // XBL documents must allow XUL and XBL elements in them but the usual check
   // only checks if the document is loaded in the system principal which is
   // sometimes not the case.
-  idoc->ForceEnableXULXBL();
+  doc->ForceEnableXULXBL();
 
-  nsDocument* doc = static_cast<nsDocument*>(idoc);
   doc->SetLoadedAsInteractiveData(true);
   doc->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
 
   return NS_OK;
 }
 
 namespace mozilla {
 namespace dom {
 
 XMLDocument::XMLDocument(const char* aContentType)
-    : nsDocument(aContentType),
+    : nsIDocument(aContentType),
       mChannelIsPending(false),
       mAsync(true),
       mLoopingForSyncLoad(false),
       mIsPlainDocument(false),
       mSuppressParserErrorElement(false),
       mSuppressParserErrorConsoleMessages(false) {
   mType = eGenericXML;
 }
 
 XMLDocument::~XMLDocument() {
   // XXX We rather crash than hang
   mLoopingForSyncLoad = false;
 }
 
 nsresult XMLDocument::Init() {
-  nsresult rv = nsDocument::Init();
+  nsresult rv = nsIDocument::Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return rv;
 }
 
 void XMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
-  nsDocument::Reset(aChannel, aLoadGroup);
+  nsIDocument::Reset(aChannel, aLoadGroup);
 }
 
 void XMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
                              nsIPrincipal* aPrincipal) {
   if (mChannelIsPending) {
     StopDocumentLoad();
     mChannel->Cancel(NS_BINDING_ABORTED);
     mChannelIsPending = false;
   }
 
-  nsDocument::ResetToURI(aURI, aLoadGroup, aPrincipal);
+  nsIDocument::ResetToURI(aURI, aLoadGroup, aPrincipal);
 }
 
 bool XMLDocument::Load(const nsAString& aUrl, CallerType aCallerType,
                        ErrorResult& aRv) {
   bool hasHadScriptObject = true;
   nsIScriptGlobalObject* scriptObject =
       GetScriptHandlingObject(hasHadScriptObject);
   if (!scriptObject && hasHadScriptObject) {
@@ -474,17 +472,17 @@ bool XMLDocument::SuppressParserErrorCon
 }
 
 nsresult XMLDocument::StartDocumentLoad(const char* aCommand,
                                         nsIChannel* aChannel,
                                         nsILoadGroup* aLoadGroup,
                                         nsISupports* aContainer,
                                         nsIStreamListener** aDocListener,
                                         bool aReset, nsIContentSink* aSink) {
-  nsresult rv = nsDocument::StartDocumentLoad(
+  nsresult rv = nsIDocument::StartDocumentLoad(
       aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink);
   if (NS_FAILED(rv)) return rv;
 
   if (nsCRT::strcmp("loadAsInteractiveData", aCommand) == 0) {
     mLoadedAsInteractiveData = true;
     aCommand = kLoadAsData;  // XBL, for example, needs scripts and styles
   }
 
@@ -532,31 +530,31 @@ nsresult XMLDocument::StartDocumentLoad(
   return NS_OK;
 }
 
 void XMLDocument::EndLoad() {
   mChannelIsPending = false;
   mLoopingForSyncLoad = false;
 
   mSynchronousDOMContentLoaded = (mLoadedAsData || mLoadedAsInteractiveData);
-  nsDocument::EndLoad();
+  nsIDocument::EndLoad();
   if (mSynchronousDOMContentLoaded) {
     mSynchronousDOMContentLoaded = false;
-    nsDocument::SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
+    nsIDocument::SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE);
     // Generate a document load event for the case when an XML
     // document was loaded as pure data without any presentation
     // attached to it.
     WidgetEvent event(true, eLoad);
     EventDispatcher::Dispatch(ToSupports(this), nullptr, &event);
   }
 }
 
 /* virtual */ void XMLDocument::DocAddSizeOfExcludingThis(
     nsWindowSizes& aWindowSizes) const {
-  nsDocument::DocAddSizeOfExcludingThis(aWindowSizes);
+  nsIDocument::DocAddSizeOfExcludingThis(aWindowSizes);
 }
 
 // nsIDocument interface
 
 nsresult XMLDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const {
   NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
                "Can't import this document into another document!");
 
--- a/dom/xml/XMLDocument.h
+++ b/dom/xml/XMLDocument.h
@@ -4,30 +4,30 @@
  * 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 mozilla_dom_XMLDocument_h
 #define mozilla_dom_XMLDocument_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/BindingDeclarations.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsIScriptContext.h"
 
 class nsIURI;
 class nsIChannel;
 
 namespace mozilla {
 namespace dom {
 
-class XMLDocument : public nsDocument {
+class XMLDocument : public nsIDocument {
  public:
   explicit XMLDocument(const char* aContentType = "application/xml");
 
-  NS_INLINE_DECL_REFCOUNTING_INHERITED(XMLDocument, nsDocument)
+  NS_INLINE_DECL_REFCOUNTING_INHERITED(XMLDocument, nsIDocument)
 
   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
   virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
                           nsIPrincipal* aPrincipal) override;
 
   virtual void SetSuppressParserErrorElement(bool aSuppress) override;
   virtual bool SuppressParserErrorElement() override;
 
@@ -53,17 +53,17 @@ class XMLDocument : public nsDocument {
 
   // WebIDL API
   bool Load(const nsAString& aUrl, CallerType aCallerType, ErrorResult& aRv);
   bool Async() const { return mAsync; }
   void SetAsync(bool aAsync) { mAsync = aAsync; }
 
   // .location is [Unforgeable], so we have to make it clear that the
   // nsIDocument version applies to us (it's shadowed by the XPCOM thing on
-  // nsDocument).
+  // nsIDocument).
   using nsIDocument::GetLocation;
 
  protected:
   virtual ~XMLDocument();
 
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aGivenProto) override;
 
--- a/dom/xml/nsXMLContentSink.cpp
+++ b/dom/xml/nsXMLContentSink.cpp
@@ -236,17 +236,17 @@ static void CheckXSLTParamPI(ProcessingI
     }
   }
 }
 
 NS_IMETHODIMP
 nsXMLContentSink::DidBuildModel(bool aTerminated) {
   if (!mParser) {
     // If mParser is null, this parse has already been terminated and must
-    // not been terminated again. However, nsDocument may still think that
+    // not been terminated again. However, nsIDocument may still think that
     // the parse has not been terminated and call back into here in the case
     // where the XML parser has finished but the XSLT transform associated
     // with the document has not.
     return NS_OK;
   }
 
   DidBuildModelImpl(aTerminated);
 
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -135,17 +135,17 @@ XULDocument::XULDocument(void)
       mDocumentLoaded(false),
       mStillWalking(false),
       mPendingSheets(0),
       mCurrentScriptProto(nullptr),
       mOffThreadCompiling(false),
       mOffThreadCompileStringBuf(nullptr),
       mOffThreadCompileStringLength(0),
       mInitialLayoutComplete(false) {
-  // Override the default in nsDocument
+  // Override the default in nsIDocument
   mCharacterSet = UTF_8_ENCODING;
 
   mDefaultElementType = kNameSpaceID_XUL;
   mType = eXUL;
 
   mDelayFrameLoaderInitialization = true;
 
   mAllowXULXBL = eTriTrue;
@@ -249,17 +249,17 @@ nsresult XULDocument::StartDocumentLoad(
       nsAutoCString urlspec;
       rv = uri->GetSpec(urlspec);
       if (NS_SUCCEEDED(rv)) {
         MOZ_LOG(gXULLog, LogLevel::Warning,
                 ("xul: load document '%s'", urlspec.get()));
       }
     }
   }
-  // NOTE: If this ever starts calling nsDocument::StartDocumentLoad
+  // NOTE: If this ever starts calling nsIDocument::StartDocumentLoad
   // we'll possibly need to reset our content type afterwards.
   mStillWalking = true;
   mMayStartLayout = false;
   mDocumentLoadGroup = do_GetWeakReference(aLoadGroup);
 
   mChannel = aChannel;
 
   // Get the URI.  Note that this should match nsDocShell::OnLoadingSite
--- a/editor/composer/moz.build
+++ b/editor/composer/moz.build
@@ -22,17 +22,17 @@ UNIFIED_SOURCES += [
 EXPORTS += [
     'nsEditingSession.h',
 ]
 
 EXPORTS.mozilla += [
     'ComposerCommandsUpdater.h',
 ]
 
-# Needed because we include HTMLEditor.h which indirectly includes nsDocument.h
+# Needed because we include HTMLEditor.h which indirectly includes nsIDocument.h
 LOCAL_INCLUDES += [
     '/dom/base',
     '/dom/html',  # For nsHTMLDocument
     '/editor/spellchecker', # nsComposeTxtSrvFilter.h
     '/layout/style', # For things nsHTMLDocument includes.
 ]
 
 FINAL_LIBRARY = 'xul'
--- a/gfx/layers/apz/util/DoubleTapToZoom.cpp
+++ b/gfx/layers/apz/util/DoubleTapToZoom.cpp
@@ -26,18 +26,18 @@ namespace layers {
 namespace {
 
 using FrameForPointOption = nsLayoutUtils::FrameForPointOption;
 
 // Returns the DOM element found at |aPoint|, interpreted as being relative to
 // the root frame of |aShell|. If the point is inside a subdocument, returns
 // an element inside the subdocument, rather than the subdocument element
 // (and does so recursively).
-// The implementation was adapted from nsDocument::ElementFromPoint(), with
-// the notable exception that we don't pass nsLayoutUtils::IGNORE_CROSS_DOC
+// The implementation was adapted from DocumentOrShadowRoot::ElementFromPoint(),
+// with the notable exception that we don't pass nsLayoutUtils::IGNORE_CROSS_DOC
 // to GetFrameForPoint(), so as to get the behaviour described above in the
 // presence of subdocuments.
 static already_AddRefed<dom::Element> ElementFromPoint(
     const nsCOMPtr<nsIPresShell>& aShell, const CSSPoint& aPoint) {
   nsIFrame* rootFrame = aShell->GetRootFrame();
   if (!rootFrame) {
     return nullptr;
   }
--- a/image/SVGDocumentWrapper.cpp
+++ b/image/SVGDocumentWrapper.cpp
@@ -23,17 +23,17 @@
 #include "nsComponentManagerUtils.h"
 #include "mozilla/SMILAnimationController.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/dom/SVGSVGElement.h"
 #include "SVGObserverUtils.h"
 #include "mozilla/dom/SVGAnimatedLength.h"
 #include "nsMimeTypes.h"
 #include "DOMSVGLength.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "mozilla/dom/ImageTracker.h"
 
 namespace mozilla {
 
 using namespace dom;
 using namespace gfx;
 
 namespace image {
--- a/intl/l10n/DocumentL10n.h
+++ b/intl/l10n/DocumentL10n.h
@@ -38,23 +38,23 @@ class PromiseResolver final : public Pro
   virtual ~PromiseResolver();
 
   RefPtr<Promise> mPromise;
 };
 
 enum class DocumentL10nState { Initialized = 0, InitialTranslationTriggered };
 
 /**
- * This class maintains localization status of the nsDocument.
+ * This class maintains localization status of the document.
  *
- * The nsDocument will initialize it lazily when a link with a
- * localization resource is added to the document.
+ * The nsIDocument will initialize it lazily when a link with a localization
+ * resource is added to the document.
  *
  * Once initialized, DocumentL10n relays all API methods to an
- * instance of mozIDOMLocalization and maintaines a single promise
+ * instance of mozIDOMLocalization and maintains a single promise
  * which gets resolved the first time the document gets translated.
  */
 class DocumentL10n final : public nsIDOMEventListener, public nsWrapperCache {
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DocumentL10n)
   NS_DECL_NSIDOMEVENTLISTENER
 
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4030,29 +4030,29 @@ void PresShell::DoFlushPendingNotificati
   MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mDocument->GetShell() == this);
 
   // Make sure the view manager stays alive.
   RefPtr<nsViewManager> viewManager = mViewManager;
   bool didStyleFlush = false;
   bool didLayoutFlush = false;
   if (isSafeToFlush) {
     // Record that we are in a flush, so that our optimization in
-    // nsDocument::FlushPendingNotifications doesn't skip any re-entrant
+    // nsIDocument::FlushPendingNotifications doesn't skip any re-entrant
     // calls to us.  Otherwise, we might miss some needed flushes, since
     // we clear mNeedStyleFlush / mNeedLayoutFlush here at the top of
     // the function but we might not have done the work yet.
     AutoRestore<bool> guard(mInFlush);
     mInFlush = true;
 
     // We need to make sure external resource documents are flushed too (for
     // example, svg filters that reference a filter in an external document
     // need the frames in the external document to be constructed for the
     // filter to work). We only need external resources to be flushed when the
     // main document is flushing >= FlushType::Frames, so we flush external
-    // resources here instead of nsDocument::FlushPendingNotifications.
+    // resources here instead of nsIDocument::FlushPendingNotifications.
     mDocument->FlushExternalResources(flushType);
 
     // Force flushing of any pending content notifications that might have
     // queued up while our event was pending.  That will ensure that we don't
     // construct frames for content right now that's still waiting to be
     // notified on,
     mDocument->FlushPendingNotifications(FlushType::ContentAndNotify);
 
--- a/layout/base/ZoomConstraintsClient.cpp
+++ b/layout/base/ZoomConstraintsClient.cpp
@@ -10,17 +10,17 @@
 #include "gfxPrefs.h"
 #include "LayersLogging.h"
 #include "mozilla/layers/APZCCallbackHelper.h"
 #include "mozilla/layers/ScrollableLayerGuid.h"
 #include "mozilla/layers/ZoomConstraints.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/dom/Event.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsIFrame.h"
 #include "nsLayoutUtils.h"
 #include "nsPoint.h"
 #include "nsView.h"
 #include "nsViewportInfo.h"
 #include "Units.h"
 #include "UnitTransforms.h"
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2573,17 +2573,17 @@ NS_IMETHODIMP nsDocumentViewer::ClearSel
 
   ErrorResult rv;
   selection->CollapseToStart(rv);
   return rv.StealNSResult();
 }
 
 NS_IMETHODIMP nsDocumentViewer::SelectAll() {
   // XXX this is a temporary implementation copied from nsWebShell
-  // for now. I think nsDocument and friends should have some helper
+  // for now. I think nsIDocument and friends should have some helper
   // functions to make this easier.
 
   // use nsCopySupport::GetSelectionForCopy() ?
   RefPtr<mozilla::dom::Selection> selection = GetDocumentSelection();
   if (!selection) {
     return NS_ERROR_FAILURE;
   }
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -19,17 +19,17 @@
 #include "mozilla/layers/PAPZ.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/ServoStyleSetInlines.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/Unused.h"
 #include "nsCharTraits.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsFontMetrics.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsFrameList.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsCaret.h"
--- a/layout/inspector/ServoStyleRuleMap.cpp
+++ b/layout/inspector/ServoStyleRuleMap.cpp
@@ -9,17 +9,17 @@
 #include "mozilla/css/GroupRule.h"
 #include "mozilla/dom/CSSImportRule.h"
 #include "mozilla/dom/CSSRuleBinding.h"
 #include "mozilla/dom/CSSStyleRule.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/IntegerRange.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/StyleSheetInlines.h"
-#include "nsDocument.h"
+#include "nsIDocument.h"
 #include "nsStyleSheetService.h"
 #include "nsXBLPrototypeResources.h"
 
 using namespace mozilla::dom;
 
 namespace mozilla {
 
 void ServoStyleRuleMap::EnsureTable(ServoStyleSet& aStyleSet) {
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -188,17 +188,17 @@ function saveDocument(aDocument, aSkipPr
   let contentDisposition = null;
   let cacheKey = 0;
 
   if (aDocument instanceof Ci.nsIWebBrowserPersistDocument) {
     // nsIWebBrowserPersistDocument exposes these directly.
     contentDisposition = aDocument.contentDisposition;
     cacheKey = aDocument.cacheKey;
   } else if (aDocument.nodeType == 9 /* DOCUMENT_NODE */) {
-    // Otherwise it's an actual nsDocument (and possibly a CPOW).
+    // Otherwise it's an actual document (and possibly a CPOW).
     // We want to use cached data because the document is currently visible.
     let win = aDocument.defaultView;
 
     try {
       contentDisposition = win.windowUtils
                               .getDocumentMetadata("content-disposition");
     } catch (ex) {
       // Failure to get a content-disposition is ok