1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=78: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsHtml5DocumentBuilder.h"
9 #include "mozilla/dom/ScriptLoader.h"
10 #include "mozilla/dom/LinkStyle.h"
11 #include "nsNameSpaceManager.h"
13 using mozilla::dom::LinkStyle
;
15 NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder
, nsContentSink
,
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsHtml5DocumentBuilder
)
19 NS_INTERFACE_MAP_END_INHERITING(nsContentSink
)
21 NS_IMPL_ADDREF_INHERITED(nsHtml5DocumentBuilder
, nsContentSink
)
22 NS_IMPL_RELEASE_INHERITED(nsHtml5DocumentBuilder
, nsContentSink
)
24 nsHtml5DocumentBuilder::nsHtml5DocumentBuilder(bool aRunsToCompletion
)
25 : mBroken(NS_OK
), mFlushState(eHtml5FlushState::eNotFlushing
) {
26 mRunsToCompletion
= aRunsToCompletion
;
29 nsresult
nsHtml5DocumentBuilder::Init(mozilla::dom::Document
* aDoc
,
30 nsIURI
* aURI
, nsISupports
* aContainer
,
31 nsIChannel
* aChannel
) {
32 return nsContentSink::Init(aDoc
, aURI
, aContainer
, aChannel
);
35 nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder() = default;
37 nsresult
nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason
) {
42 void nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent
* aElement
) {
43 auto* linkStyle
= LinkStyle::FromNode(*aElement
);
45 MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled
,
46 "Node didn't QI to style, but SVG wasn't disabled.");
50 auto updateOrError
= linkStyle
->EnableUpdatesAndUpdateStyleSheet(
51 mRunsToCompletion
? nullptr : this);
53 if (updateOrError
.isOk() && updateOrError
.unwrap().ShouldBlock() &&
56 mScriptLoader
->AddParserBlockingScriptExecutionBlocker();
60 void nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m
) {
61 nsCompatibility mode
= eCompatibility_NavQuirks
;
62 const char* errMsgId
= nullptr;
66 mode
= eCompatibility_FullStandards
;
68 case ALMOST_STANDARDS_MODE
:
69 mode
= eCompatibility_AlmostStandards
;
70 errMsgId
= "errAlmostStandardsDoctypeVerbose";
73 mode
= eCompatibility_NavQuirks
;
74 errMsgId
= "errQuirkyDoctypeVerbose";
77 mDocument
->SetCompatibilityMode(mode
);
79 if (errMsgId
&& !mDocument
->IsLoadedAsData()) {
80 nsCOMPtr
<nsIURI
> docURI
= mDocument
->GetDocumentURI();
82 docURI
->SchemeIs("data", &isData
);
84 docURI
->SchemeIs("http", &isHttp
);
86 docURI
->SchemeIs("https", &isHttps
);
88 nsCOMPtr
<nsIPrincipal
> principal
= mDocument
->GetPrincipal();
89 if (principal
->GetIsNullPrincipal() && !isData
&& !isHttp
&& !isHttps
) {
90 // Don't normally warn for null principals. It may well be internal
91 // documents for which the warning is not applicable.
95 nsContentUtils::ReportToConsole(
96 nsIScriptError::warningFlag
, "HTML_PARSER__DOCTYPE"_ns
, mDocument
,
97 nsContentUtils::eHTMLPARSER_PROPERTIES
, errMsgId
);
101 // nsContentSink overrides
103 void nsHtml5DocumentBuilder::UpdateChildCounts() {
107 nsresult
nsHtml5DocumentBuilder::FlushTags() { return NS_OK
; }