Bug 1516366 - Move CC / nsISupports bits to nsIDocument. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 26 Dec 2018 03:35:16 +0100
changeset 509253 1c324add4b92260e92eeaaff387ab27d5abe7736
parent 509252 947bf2c04aa507ace1fa8765c783d7c42f118446
child 509254 16a7aabf4fea82d82f242d45a5915e30c6049494
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1516366
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 1516366 - Move CC / nsISupports bits to nsIDocument. r=smaug This allows us to remove the MOZ_CRASH-ing implementation I added earlier in this series. Differential Revision: https://phabricator.services.mozilla.com/D15365
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1620,55 +1620,41 @@ nsDocument::~nsDocument() {
 
   ClearAllBoxObjects();
 
   mPendingTitleChangeEvent.Revoke();
 
   mPlugins.Clear();
 }
 
-// In practice these three are always overriden by the nsDocument version, we
-// just need them to avoid making nsIDocument::AddRef / Release ambiguous.
-//
-// We can get rid of these once we merge nsIDocument and nsDocument.
-NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::Release() {
-  MOZ_CRASH("Should never be reachable");
-}
-NS_IMETHODIMP_(MozExternalRefCountType) nsIDocument::AddRef() {
-  MOZ_CRASH("Should never be reachable");
-}
-NS_IMETHODIMP nsIDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
-  MOZ_CRASH("Should never be reachable");
-}
-
-NS_INTERFACE_TABLE_HEAD(nsDocument)
+NS_INTERFACE_TABLE_HEAD(nsIDocument)
   NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
   NS_INTERFACE_TABLE_BEGIN
-    NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsDocument, nsISupports, nsINode)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsINode)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDocument)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIScriptObjectPrincipal)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, mozilla::dom::EventTarget)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsISupportsWeakReference)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIRadioGroupContainer)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIMutationObserver)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIApplicationCacheContainer)
+    NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsIDocument, nsISupports, nsINode)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsINode)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIDocument)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIScriptObjectPrincipal)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, mozilla::dom::EventTarget)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsISupportsWeakReference)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIRadioGroupContainer)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIMutationObserver)
+    NS_INTERFACE_TABLE_ENTRY(nsIDocument, nsIApplicationCacheContainer)
   NS_INTERFACE_TABLE_END
-  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDocument)
+  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsIDocument)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDocument)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(nsIDocument)
 NS_IMETHODIMP_(MozExternalRefCountType)
-nsDocument::Release() {
+nsIDocument::Release() {
   MOZ_ASSERT(0 != mRefCnt, "dup release");
-  NS_ASSERT_OWNINGTHREAD(nsDocument);
-  nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(nsDocument)::Upcast(this);
+  NS_ASSERT_OWNINGTHREAD(nsIDocument);
+  nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(nsIDocument)::Upcast(this);
   bool shouldDelete = false;
   nsrefcnt count = mRefCnt.decr(base, &shouldDelete);
-  NS_LOG_RELEASE(this, count, "nsDocument");
+  NS_LOG_RELEASE(this, count, "nsIDocument");
   if (count == 0) {
     if (mStackRefCnt && !mNeedsReleaseAfterStackRefCntRelease) {
       mNeedsReleaseAfterStackRefCntRelease = true;
       NS_ADDREF_THIS();
       return mRefCnt.get();
     }
     mRefCnt.incr(base);
     nsNodeUtils::LastRelease(this);
@@ -1677,61 +1663,61 @@ nsDocument::Release() {
       mRefCnt.stabilizeForDeletion();
       DeleteCycleCollectable();
     }
   }
   return count;
 }
 
 NS_IMETHODIMP_(void)
-nsDocument::DeleteCycleCollectable() { delete this; }
-
-NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument)
+nsIDocument::DeleteCycleCollectable() { delete this; }
+
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsIDocument)
   if (Element::CanSkip(tmp, aRemovingAllowed)) {
     EventListenerManager* elm = tmp->GetExistingListenerManager();
     if (elm) {
       elm->MarkForCC();
     }
     return true;
   }
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
 
-NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsDocument)
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsIDocument)
   return Element::CanSkipInCC(tmp);
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
 
-NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsDocument)
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsIDocument)
   return Element::CanSkipThis(tmp);
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
 
 static const char* kNSURIs[] = {"([none])", "(xmlns)", "(xml)", "(xhtml)",
                                 "(XLink)",  "(XSLT)",  "(XBL)", "(MathML)",
                                 "(RDF)",    "(XUL)"};
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsIDocument)
   if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
     char name[512];
     nsAutoCString loadedAsData;
     if (tmp->IsLoadedAsData()) {
       loadedAsData.AssignLiteral("data");
     } else {
       loadedAsData.AssignLiteral("normal");
     }
     uint32_t nsid = tmp->GetDefaultNamespaceID();
     nsAutoCString uri;
     if (tmp->mDocumentURI) uri = tmp->mDocumentURI->GetSpecOrDefault();
     if (nsid < ArrayLength(kNSURIs)) {
-      SprintfLiteral(name, "nsDocument %s %s %s", loadedAsData.get(),
+      SprintfLiteral(name, "nsIDocument %s %s %s", loadedAsData.get(),
                      kNSURIs[nsid], uri.get());
     } else {
-      SprintfLiteral(name, "nsDocument %s %s", loadedAsData.get(), uri.get());
+      SprintfLiteral(name, "nsIDocument %s %s", loadedAsData.get(), uri.get());
     }
     cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
   } else {
-    NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsDocument, tmp->mRefCnt.get())
+    NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsIDocument, tmp->mRefCnt.get())
   }
 
   if (!nsINode::Traverse(tmp, cb)) {
     return NS_SUCCESS_INTERRUPTED_TRAVERSE;
   }
 
   if (tmp->mMaybeEndOutermostXBLUpdateRunner) {
     // The cached runnable keeps a reference to the document object..
@@ -1832,34 +1818,34 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
     if (mql->HasListeners() &&
         NS_SUCCEEDED(mql->CheckInnerWindowCorrectness())) {
       NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mDOMMediaQueryLists item");
       cb.NoteXPCOMChild(mql);
     }
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocument)
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsDocument)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
+NS_IMPL_CYCLE_COLLECTION_CLASS(nsIDocument)
+
+NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsIDocument)
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsIDocument)
   tmp->mInUnlinkOrDeletion = true;
 
   // Clear out our external resources
   tmp->mExternalResourceMap.Shutdown();
 
   nsAutoScriptBlocker scriptBlocker;
 
   nsINode::Unlink(tmp);
 
   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();
   }
 
   tmp->UnlinkOriginalDocumentIfStatic();
 
@@ -1913,17 +1899,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
 
   tmp->mFrameRequestCallbacks.Clear();
   MOZ_RELEASE_ASSERT(!tmp->mFrameRequestCallbacksScheduled,
                      "How did we get here without our presshell going away "
                      "first?");
 
   DocumentOrShadowRoot::Unlink(tmp);
 
-  // nsDocument has a pretty complex destructor, so we're going to
+  // nsIDocument has a pretty complex destructor, so we're going to
   // assume that *most* cycles you actually want to break somewhere
   // else, and not unlink an awful lot here.
 
   tmp->mIdentifierMap.Clear();
   tmp->mExpandoAndGeneration.OwnerUnlinked();
 
   if (tmp->mAnimationController) {
     tmp->mAnimationController->Unlink();
@@ -2944,17 +2930,17 @@ void nsIDocument::GetLastModified(nsAStr
   if (!mLastModified.IsEmpty()) {
     aLastModified.Assign(mLastModified);
   } else {
     GetFormattedTimeString(PR_Now(), aLastModified);
   }
 }
 
 static void IncrementExpandoGeneration(nsIDocument& aDoc) {
-  ++static_cast<nsDocument&>(aDoc).mExpandoAndGeneration.generation;
+  ++aDoc.mExpandoAndGeneration.generation;
 }
 
 void nsIDocument::AddToNameTable(Element* aElement, nsAtom* aName) {
   MOZ_ASSERT(
       nsGenericHTMLElement::ShouldExposeNameAsHTMLDocumentProperty(aElement),
       "Only put elements that need to be exposed as document['name'] in "
       "the named table.");
 
@@ -4349,20 +4335,20 @@ void nsIDocument::SetContainer(nsDocShel
     // check if same type root
     nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
     aContainer->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
     NS_ASSERTION(
         sameTypeRoot,
         "No document shell root tree item from document shell tree item!");
 
     if (sameTypeRoot == aContainer) {
-      static_cast<nsDocument*>(this)->SetIsTopLevelContentDocument(true);
-    }
-
-    static_cast<nsDocument*>(this)->SetIsContentDocument(true);
+      SetIsTopLevelContentDocument(true);
+    }
+
+    SetIsContentDocument(true);
   }
 
   mAncestorPrincipals = aContainer->AncestorPrincipals();
   mAncestorOuterWindowIDs = aContainer->AncestorOuterWindowIDs();
 }
 
 nsISupports* nsIDocument::GetContainer() const {
   return static_cast<nsIDocShell*>(mDocumentContainer);
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -88,46 +88,26 @@ class nsOnloadBlocker final : public nsI
   NS_DECL_NSIREQUEST
 
  private:
   ~nsOnloadBlocker() {}
 };
 
 // Base class for our document implementations.
 class nsDocument : public nsIDocument {
-  friend class nsIDocument;
-
- public:
-  typedef mozilla::dom::Element Element;
-  typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
-
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-
  public:
   using mozilla::dom::DocumentOrShadowRoot::GetElementById;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS;
 
-  NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument,
-                                                                   nsINode)
-
- protected:
-  friend class nsNodeUtils;
-
   explicit nsDocument(const char* aContentType);
   virtual ~nsDocument();
 
- public:
-
-  friend class nsCallRequestFullscreen;
-
  private:
-  friend class nsUnblockOnloadEvent;
-
   // These are not implemented and not supported.
   nsDocument(const nsDocument& aOther);
   nsDocument& operator=(const nsDocument& aOther);
 };
 
 class nsDocumentOnStack {
  public:
   explicit nsDocumentOnStack(nsIDocument* aDoc) : mDoc(aDoc) {
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -454,20 +454,24 @@ class nsIDocument : public nsINode,
  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)
-  NS_DECL_ISUPPORTS_INHERITED
+
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   NS_DECL_ADDSIZEOFEXCLUDINGTHIS
 
+  NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsIDocument,
+                                                                   nsINode)
+
 #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_)                          \
   do {                                                                        \
     NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \
                                              func_, params_);                 \
     /* FIXME(emilio): Apparently we can keep observing from the BFCache? That \
        looks bogus. */                                                        \
     if (nsIPresShell* shell = GetObservingShell()) {                          \
       shell->func_ params_;                                                   \