Bug 1550524 part 1. Make NewHtml5Parser() return an nsHtml5Parser. r=hsivonen
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 14 May 2019 19:46:25 +0000
changeset 474553 0c1f4aee5de04bbef034b98f39c4e367b34cc5ba
parent 474552 8fe96c8d21b7a9fdebdf3300de2367f2cc9232c3
child 474554 3eef21fc64b778f57aaa416f2b0c2ed469033a10
push id36042
push userdvarga@mozilla.com
push dateTue, 21 May 2019 04:19:40 +0000
treeherdermozilla-central@ca560ff55451 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1550524
milestone69.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 1550524 part 1. Make NewHtml5Parser() return an nsHtml5Parser. r=hsivonen Differential Revision: https://phabricator.services.mozilla.com/D30750
dom/html/nsHTMLDocument.cpp
parser/html/nsHtml5Module.cpp
parser/html/nsHtml5Module.h
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -537,28 +537,30 @@ nsresult nsHTMLDocument::StartDocumentLo
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
 
   bool loadWithPrototype = false;
+  RefPtr<nsHtml5Parser> html5Parser;
   if (loadAsHtml5) {
-    mParser = nsHtml5Module::NewHtml5Parser();
+    html5Parser = nsHtml5Module::NewHtml5Parser();
+    mParser = html5Parser;
     if (mIsPlainText) {
       if (viewSource) {
-        mParser->MarkAsNotScriptCreated("view-source-plain");
+        html5Parser->MarkAsNotScriptCreated("view-source-plain");
       } else {
-        mParser->MarkAsNotScriptCreated("plain-text");
+        html5Parser->MarkAsNotScriptCreated("plain-text");
       }
     } else if (viewSource && !html) {
-      mParser->MarkAsNotScriptCreated("view-source-xml");
+      html5Parser->MarkAsNotScriptCreated("view-source-xml");
     } else {
-      mParser->MarkAsNotScriptCreated(aCommand);
+      html5Parser->MarkAsNotScriptCreated(aCommand);
     }
   } else if (xhtml && ShouldUsePrototypeDocument(aChannel, this)) {
     loadWithPrototype = true;
     nsCOMPtr<nsIURI> originalURI;
     aChannel->GetOriginalURI(getter_AddRefs(originalURI));
     mParser = new mozilla::parser::PrototypeDocumentParser(originalURI, this);
   } else {
     mParser = do_CreateInstance(kCParserCID, &rv);
@@ -686,17 +688,17 @@ nsresult nsHTMLDocument::StartDocumentLo
     } else {
       nsCOMPtr<nsIXMLContentSink> xmlsink;
       NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, uri, docShell,
                            aChannel);
       mParser->SetContentSink(xmlsink);
     }
   } else {
     if (loadAsHtml5) {
-      nsHtml5Module::Initialize(mParser, this, uri, docShell, aChannel);
+      html5Parser->Initialize(this, uri, docShell, aChannel);
     } else {
       // about:blank *only*
       nsCOMPtr<nsIHTMLContentSink> htmlsink;
       NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri, docShell,
                             aChannel);
       mParser->SetContentSink(htmlsink);
     }
   }
@@ -1173,18 +1175,19 @@ Document* nsHTMLDocument::Open(const Opt
                         /* updateTimingInformation = */ false);
 
   // Step 13 -- set our compat mode to standards.
   SetCompatibilityMode(eCompatibility_FullStandards);
 
   // Step 14 -- create a new parser associated with document.  This also does
   // step 16 implicitly.
   mParserAborted = false;
-  mParser = nsHtml5Module::NewHtml5Parser();
-  nsHtml5Module::Initialize(mParser, this, GetDocumentURI(), shell, nullptr);
+  RefPtr<nsHtml5Parser> parser = nsHtml5Module::NewHtml5Parser();
+  mParser = parser;
+  parser->Initialize(this, GetDocumentURI(), shell, nullptr);
   if (mReferrerPolicySet) {
     // CSP may have set the referrer policy, so a speculative parser should
     // start with the new referrer policy.
     nsHtml5TreeOpExecutor* executor = nullptr;
     executor = static_cast<nsHtml5TreeOpExecutor*>(mParser->GetContentSink());
     if (executor && mReferrerPolicySet) {
       executor->SetSpeculationReferrerPolicy(
           static_cast<ReferrerPolicy>(mReferrerPolicy));
--- a/parser/html/nsHtml5Module.cpp
+++ b/parser/html/nsHtml5Module.cpp
@@ -55,31 +55,22 @@ void nsHtml5Module::ReleaseStatics() {
   nsHtml5Tokenizer::releaseStatics();
   nsHtml5TreeBuilder::releaseStatics();
   nsHtml5UTF16Buffer::releaseStatics();
   NS_IF_RELEASE(sStreamParserThread);
   NS_IF_RELEASE(sMainThread);
 }
 
 // static
-already_AddRefed<nsIParser> nsHtml5Module::NewHtml5Parser() {
+already_AddRefed<nsHtml5Parser> nsHtml5Module::NewHtml5Parser() {
   MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
-  nsCOMPtr<nsIParser> rv = new nsHtml5Parser();
+  RefPtr<nsHtml5Parser> rv = new nsHtml5Parser();
   return rv.forget();
 }
 
-// static
-nsresult nsHtml5Module::Initialize(nsIParser* aParser, dom::Document* aDoc,
-                                   nsIURI* aURI, nsISupports* aContainer,
-                                   nsIChannel* aChannel) {
-  MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
-  nsHtml5Parser* parser = static_cast<nsHtml5Parser*>(aParser);
-  return parser->Initialize(aDoc, aURI, aContainer, aChannel);
-}
-
 class nsHtml5ParserThreadTerminator final : public nsIObserver {
  public:
   NS_DECL_ISUPPORTS
   explicit nsHtml5ParserThreadTerminator(nsIThread* aThread)
       : mThread(aThread) {}
   NS_IMETHOD Observe(nsISupports*, const char* topic,
                      const char16_t*) override {
     NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"), "Unexpected topic");
--- a/parser/html/nsHtml5Module.h
+++ b/parser/html/nsHtml5Module.h
@@ -1,26 +1,24 @@
 /* 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 nsHtml5Module_h
 #define nsHtml5Module_h
 
-#include "nsIParser.h"
 #include "nsIThread.h"
 
+class nsHtml5Parser;
+
 class nsHtml5Module {
  public:
   static void InitializeStatics();
   static void ReleaseStatics();
-  static already_AddRefed<nsIParser> NewHtml5Parser();
-  static nsresult Initialize(nsIParser* aParser, mozilla::dom::Document* aDoc,
-                             nsIURI* aURI, nsISupports* aContainer,
-                             nsIChannel* aChannel);
+  static already_AddRefed<nsHtml5Parser> NewHtml5Parser();
   static nsIThread* GetStreamParserThread();
 
  private:
 #ifdef DEBUG
   static bool sNsHtml5ModuleInitialized;
 #endif
   static nsIThread* sStreamParserThread;
   static nsIThread* sMainThread;