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 "nsIStyleSheetLinkingElement.h"
10 #include "nsStyleLinkElement.h"
11 #include "nsScriptLoader.h"
12 #include "nsIHTMLDocument.h"
14 NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder
, nsContentSink
,
17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder
)
18 NS_INTERFACE_MAP_END_INHERITING(nsContentSink
)
20 NS_IMPL_ADDREF_INHERITED(nsHtml5DocumentBuilder
, nsContentSink
)
21 NS_IMPL_RELEASE_INHERITED(nsHtml5DocumentBuilder
, nsContentSink
)
23 nsHtml5DocumentBuilder::nsHtml5DocumentBuilder(bool aRunsToCompletion
)
25 mRunsToCompletion
= aRunsToCompletion
;
29 nsHtml5DocumentBuilder::Init(nsIDocument
* aDoc
,
31 nsISupports
* aContainer
,
34 return nsContentSink::Init(aDoc
, aURI
, aContainer
, aChannel
);
37 nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder()
42 nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason
)
49 nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(nsACString
& aCharset
, int32_t aCharsetSource
)
52 mDocument
->SetDocumentCharacterSetSource(aCharsetSource
);
53 mDocument
->SetDocumentCharacterSet(aCharset
);
58 nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent
* aElement
)
60 // Break out of the doc update created by Flush() to zap a runnable
61 // waiting to call UpdateStyleSheet without the right observer
64 if (MOZ_UNLIKELY(!mParser
)) {
65 // EndDocUpdate ran stuff that called nsIParser::Terminate()
69 nsCOMPtr
<nsIStyleSheetLinkingElement
> ssle(do_QueryInterface(aElement
));
70 NS_ASSERTION(ssle
, "Node didn't QI to style.");
72 ssle
->SetEnableUpdates(true);
76 nsresult rv
= ssle
->UpdateStyleSheet(mRunsToCompletion
? nullptr : this,
79 if (NS_SUCCEEDED(rv
) && willNotify
&& !isAlternate
&& !mRunsToCompletion
) {
81 mScriptLoader
->AddExecuteBlocker();
84 if (aElement
->IsHTML(nsGkAtoms::link
)) {
85 // look for <link rel="next" href="url">
87 aElement
->GetAttr(kNameSpaceID_None
, nsGkAtoms::rel
, relVal
);
88 if (!relVal
.IsEmpty()) {
90 nsStyleLinkElement::ParseLinkTypes(relVal
, aElement
->NodePrincipal());
91 bool hasPrefetch
= linkTypes
& nsStyleLinkElement::ePREFETCH
;
92 if (hasPrefetch
|| (linkTypes
& nsStyleLinkElement::eNEXT
)) {
94 aElement
->GetAttr(kNameSpaceID_None
, nsGkAtoms::href
, hrefVal
);
95 if (!hrefVal
.IsEmpty()) {
96 PrefetchHref(hrefVal
, aElement
, hasPrefetch
);
99 if (linkTypes
& nsStyleLinkElement::eDNS_PREFETCH
) {
100 nsAutoString hrefVal
;
101 aElement
->GetAttr(kNameSpaceID_None
, nsGkAtoms::href
, hrefVal
);
102 if (!hrefVal
.IsEmpty()) {
103 PrefetchDNS(hrefVal
);
114 nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m
)
116 nsCompatibility mode
= eCompatibility_NavQuirks
;
119 mode
= eCompatibility_FullStandards
;
121 case ALMOST_STANDARDS_MODE
:
122 mode
= eCompatibility_AlmostStandards
;
125 mode
= eCompatibility_NavQuirks
;
128 nsCOMPtr
<nsIHTMLDocument
> htmlDocument
= do_QueryInterface(mDocument
);
129 NS_ASSERTION(htmlDocument
, "Document didn't QI into HTML document.");
130 htmlDocument
->SetCompatibilityMode(mode
);
133 // nsContentSink overrides
136 nsHtml5DocumentBuilder::UpdateChildCounts()
142 nsHtml5DocumentBuilder::FlushTags()