Bug 1516366 - Move various miscellaneous methods from nsDocument to nsIDocument. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 26 Dec 2018 03:34:10 +0100
changeset 509247 2909ddd2f7b19f80a75cc0869dfc42d05887a761
parent 509246 599dfe52907f4ba60ac069155b3b3b8c4f063b47
child 509248 0afa3b75fd66e774d04ea8245614c7d351d5ee0e
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 various miscellaneous methods from nsDocument to nsIDocument. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D15359
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2475,22 +2475,22 @@ bool nsIDocument::IsSynthesized() {
 
 // static
 bool nsIDocument::IsCallerChromeOrAddon(JSContext* aCx, JSObject* aObject) {
   nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx);
   return principal && (nsContentUtils::IsSystemPrincipal(principal) ||
                        principal->GetIsAddonOrExpandedAddonPrincipal());
 }
 
-nsresult nsDocument::StartDocumentLoad(const char* aCommand,
-                                       nsIChannel* aChannel,
-                                       nsILoadGroup* aLoadGroup,
-                                       nsISupports* aContainer,
-                                       nsIStreamListener** aDocListener,
-                                       bool aReset, nsIContentSink* aSink) {
+nsresult nsIDocument::StartDocumentLoad(const char* aCommand,
+                                        nsIChannel* aChannel,
+                                        nsILoadGroup* aLoadGroup,
+                                        nsISupports* aContainer,
+                                        nsIStreamListener** aDocListener,
+                                        bool aReset, nsIContentSink* aSink) {
   if (MOZ_LOG_TEST(gDocumentLeakPRLog, LogLevel::Debug)) {
     nsCOMPtr<nsIURI> uri;
     aChannel->GetURI(getter_AddRefs(uri));
     MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug,
             ("DOCUMENT %p StartDocumentLoad %s", this,
              uri ? uri->GetSpecOrDefault().get() : ""));
   }
 
@@ -2878,17 +2878,17 @@ nsresult nsIDocument::InitFeaturePolicy(
   if (NS_SUCCEEDED(rv)) {
     mFeaturePolicy->SetDeclaredPolicy(this, NS_ConvertUTF8toUTF16(value),
                                       NodePrincipal(), nullptr);
   }
 
   return NS_OK;
 }
 
-void nsDocument::StopDocumentLoad() {
+void nsIDocument::StopDocumentLoad() {
   if (mParser) {
     mParserAborted = true;
     mParser->Terminate();
   }
 }
 
 void nsIDocument::SetDocumentURI(nsIURI* aURI) {
   nsCOMPtr<nsIURI> oldBase = GetDocBaseURI();
@@ -3584,20 +3584,20 @@ void nsIDocument::SetHeaderData(nsAtom* 
     enum mozilla::net::ReferrerPolicy policy =
         nsContentUtils::GetReferrerPolicyFromHeader(aData);
     if (policy != mozilla::net::RP_Unset) {
       mReferrerPolicy = policy;
       mReferrerPolicySet = true;
     }
   }
 }
-void nsDocument::TryChannelCharset(nsIChannel* aChannel,
-                                   int32_t& aCharsetSource,
-                                   NotNull<const Encoding*>& aEncoding,
-                                   nsHtml5TreeOpExecutor* aExecutor) {
+void nsIDocument::TryChannelCharset(nsIChannel* aChannel,
+                                    int32_t& aCharsetSource,
+                                    NotNull<const Encoding*>& aEncoding,
+                                    nsHtml5TreeOpExecutor* aExecutor) {
   if (aChannel) {
     nsAutoCString charsetVal;
     nsresult rv = aChannel->GetContentCharset(charsetVal);
     if (NS_SUCCEEDED(rv)) {
       const Encoding* preferred = Encoding::ForLabel(charsetVal);
       if (preferred) {
         aEncoding = WrapNotNull(preferred);
         aCharsetSource = kCharsetFromChannel;
@@ -4640,34 +4640,34 @@ void nsIDocument::BeginUpdate() {
     BindingManager()->BeginOutermostUpdate();
   }
 
   ++mUpdateNestLevel;
   nsContentUtils::AddScriptBlocker();
   NS_DOCUMENT_NOTIFY_OBSERVERS(BeginUpdate, (this));
 }
 
-void nsDocument::EndUpdate() {
+void nsIDocument::EndUpdate() {
   NS_DOCUMENT_NOTIFY_OBSERVERS(EndUpdate, (this));
 
   nsContentUtils::RemoveScriptBlocker();
 
   --mUpdateNestLevel;
 
   // This set of updates may have created XBL bindings.  Let the
   // binding manager know we're done.
   MaybeEndOutermostXBLUpdate();
 
   MaybeInitializeFinalizeFrameLoaders();
   if (mXULBroadcastManager) {
     mXULBroadcastManager->MaybeBroadcast();
   }
 }
 
-void nsDocument::BeginLoad() {
+void nsIDocument::BeginLoad() {
   MOZ_ASSERT(!mDidCallBeginLoad);
   mDidCallBeginLoad = true;
 
   // Block onload here to prevent having to deal with blocking and
   // unblocking it while we know the document is loading.
   BlockOnload();
   mDidFireDOMContentLoaded = false;
   BlockDOMContentLoaded();
@@ -4906,17 +4906,17 @@ static void AssertAboutPageHasCSP(nsIURI
                  "about: page must have a CSP");
     return;
   }
   MOZ_ASSERT(parsedPolicyStr.Find("default-src") >= 0,
              "about: page must contain a CSP including default-src");
 }
 #endif
 
-void nsDocument::EndLoad() {
+void nsIDocument::EndLoad() {
 #if defined(DEBUG) && !defined(ANDROID)
   // only assert if nothing stopped the load on purpose
   if (!mParserAborted) {
     AssertAboutPageHasCSP(mDocumentURI, NodePrincipal());
   }
 #endif
 
   // EndLoad may have been called without a matching call to BeginLoad, in the
@@ -7181,17 +7181,17 @@ bool nsIDocument::IsScriptEnabled() {
       do_QueryInterface(GetInnerWindow());
   if (!globalObject || !globalObject->GetGlobalJSObject()) {
     return false;
   }
 
   return xpc::Scriptability::Get(globalObject->GetGlobalJSObject()).Allowed();
 }
 
-void nsDocument::RetrieveRelevantHeaders(nsIChannel* aChannel) {
+void nsIDocument::RetrieveRelevantHeaders(nsIChannel* aChannel) {
   PRTime modDate = 0;
   nsresult rv;
 
   nsCOMPtr<nsIHttpChannel> httpChannel;
   rv = GetHttpChannelHelper(aChannel, getter_AddRefs(httpChannel));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -96,30 +96,16 @@ class nsDocument : public nsIDocument {
   friend class nsIDocument;
 
  public:
   typedef mozilla::dom::Element Element;
   typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
-  // StartDocumentLoad is pure virtual so that subclasses must override it.
-  // The nsDocument StartDocumentLoad does some setup, but does NOT set
-  // *aDocListener; this is the job of subclasses.
-  virtual nsresult StartDocumentLoad(
-      const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup,
-      nsISupports* aContainer, nsIStreamListener** aDocListener,
-      bool aReset = true, nsIContentSink* aContentSink = nullptr) override = 0;
-
-  virtual void StopDocumentLoad() override;
-
-  virtual void EndUpdate() override;
-  virtual void BeginLoad() override;
-  virtual void EndLoad() override;
-
  public:
   using mozilla::dom::DocumentOrShadowRoot::GetElementById;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS;
 
   // EventTarget
   void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
@@ -141,22 +127,16 @@ class nsDocument : public nsIDocument {
   nsresult CloneDocHelper(nsDocument* clone) const;
 
   // Only BlockOnload should call this!
   void AsyncBlockOnload();
 
  protected:
   friend class nsNodeUtils;
 
-  void RetrieveRelevantHeaders(nsIChannel* aChannel);
-
-  void TryChannelCharset(nsIChannel* aChannel, int32_t& aCharsetSource,
-                         NotNull<const Encoding*>& aEncoding,
-                         nsHtml5TreeOpExecutor* aExecutor);
-
 #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_;                                                   \
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -80,16 +80,17 @@ class imgIRequest;
 class nsBindingManager;
 class nsCachableElementsByNameNodeList;
 class nsIDocShell;
 class nsDocShell;
 class nsDOMNavigationTiming;
 class nsDOMStyleSheetSetList;
 class nsFrameLoader;
 class nsGlobalWindowInner;
+class nsHtml5TreeOpExecutor;
 class nsHTMLCSSStyleSheet;
 class nsHTMLDocument;
 class nsHTMLStyleSheet;
 class nsGenericHTMLElement;
 class nsAtom;
 class nsIBFCacheEntry;
 class nsIChannel;
 class nsIContent;
@@ -567,24 +568,27 @@ class nsIDocument : public nsINode,
    *              This MUST be null if the underlying document is an HTML
    *              document. Even in the XML case, please don't add new calls
    *              with non-null sink.
    *
    * Once this has been called, the document will return false for
    * MayStartLayout() until SetMayStartLayout(true) is called on it.  Making
    * sure this happens is the responsibility of the caller of
    * StartDocumentLoad().
+   *
+   * This function has an implementation, and does some setup, but does NOT set
+   * *aDocListener; this is the job of subclasses.
    */
   virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
                                      nsILoadGroup* aLoadGroup,
                                      nsISupports* aContainer,
                                      nsIStreamListener** aDocListener,
                                      bool aReset,
                                      nsIContentSink* aSink = nullptr) = 0;
-  virtual void StopDocumentLoad() = 0;
+  virtual void StopDocumentLoad();
 
   virtual void SetSuppressParserErrorElement(bool aSuppress) {}
   virtual bool SuppressParserErrorElement() { return false; }
 
   virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {}
   virtual bool SuppressParserErrorConsoleMessages() { return false; }
 
   // nsINode
@@ -1380,16 +1384,22 @@ class nsIDocument : public nsINode,
   void PostUnblockOnloadEvent();
 
   void DoUnblockOnload();
 
   void ClearAllBoxObjects();
 
   void MaybeEndOutermostXBLUpdate();
 
+  void RetrieveRelevantHeaders(nsIChannel* aChannel);
+
+  void TryChannelCharset(nsIChannel* aChannel, int32_t& aCharsetSource,
+                         NotNull<const Encoding*>& aEncoding,
+                         nsHtml5TreeOpExecutor* aExecutor);
+
   void DispatchContentLoadedEvents();
 
   void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget,
                               const nsAString& aType, bool aPersisted,
                               bool aOnlySystemGroup = false);
 
   // Call this before the document does something that will unbind all content.
   // That will stop us from doing a lot of work as each element is removed.
@@ -1844,21 +1854,21 @@ class nsIDocument : public nsINode,
    */
   bool RemoveObserver(nsIDocumentObserver* aObserver);
 
   // Observation hooks used to propagate notifications to document observers.
   // BeginUpdate must be called before any batch of modifications of the
   // content model or of style data, EndUpdate must be called afterward.
   // To make this easy and painless, use the mozAutoDocUpdate helper class.
   void BeginUpdate();
-  virtual void EndUpdate() = 0;
+  virtual void EndUpdate();
   uint32_t UpdateNestingLevel() { return mUpdateNestLevel; }
 
-  virtual void BeginLoad() = 0;
-  virtual void EndLoad() = 0;
+  virtual void BeginLoad();
+  virtual void EndLoad();
 
   enum ReadyState {
     READYSTATE_UNINITIALIZED = 0,
     READYSTATE_LOADING = 1,
     READYSTATE_INTERACTIVE = 3,
     READYSTATE_COMPLETE = 4
   };
   void SetReadyStateInternal(ReadyState rs);