Skip to content

Commit

Permalink
Bug 1550524 part 1. Make NewHtml5Parser() return an nsHtml5Parser. r=…
Browse files Browse the repository at this point in the history
…hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D30750

--HG--
extra : moz-landing-system : lando
  • Loading branch information
bzbarsky committed May 14, 2019
1 parent 55a63d1 commit 0c6443c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
19 changes: 11 additions & 8 deletions dom/html/nsHTMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,18 +542,20 @@ nsresult nsHTMLDocument::StartDocumentLoad(const char* aCommand,
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;
Expand Down Expand Up @@ -691,7 +693,7 @@ nsresult nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
} else {
if (loadAsHtml5) {
nsHtml5Module::Initialize(mParser, this, uri, docShell, aChannel);
html5Parser->Initialize(this, uri, docShell, aChannel);
} else {
// about:blank *only*
nsCOMPtr<nsIHTMLContentSink> htmlsink;
Expand Down Expand Up @@ -1178,8 +1180,9 @@ Document* nsHTMLDocument::Open(const Optional<nsAString>& /* unused */,
// 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.
Expand Down
13 changes: 2 additions & 11 deletions parser/html/nsHtml5Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,12 @@ void nsHtml5Module::ReleaseStatics() {
}

// 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
Expand Down
8 changes: 3 additions & 5 deletions parser/html/nsHtml5Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
#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:
Expand Down

0 comments on commit 0c6443c

Please sign in to comment.