Bumping manifests a=b2g-bump
[gecko.git] / parser / html / nsHtml5DocumentBuilder.cpp
blob08e4d8a1b6c95ce15e388ed46a0e25dff423bf6f
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,
15 mOwnedElements)
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;
28 nsresult
29 nsHtml5DocumentBuilder::Init(nsIDocument* aDoc,
30 nsIURI* aURI,
31 nsISupports* aContainer,
32 nsIChannel* aChannel)
34 return nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
37 nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder()
41 nsresult
42 nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason)
44 mBroken = aReason;
45 return aReason;
48 void
49 nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(nsACString& aCharset, int32_t aCharsetSource)
51 if (mDocument) {
52 mDocument->SetDocumentCharacterSetSource(aCharsetSource);
53 mDocument->SetDocumentCharacterSet(aCharset);
57 void
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
62 EndDocUpdate();
64 if (MOZ_UNLIKELY(!mParser)) {
65 // EndDocUpdate ran stuff that called nsIParser::Terminate()
66 return;
69 nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aElement));
70 NS_ASSERTION(ssle, "Node didn't QI to style.");
72 ssle->SetEnableUpdates(true);
74 bool willNotify;
75 bool isAlternate;
76 nsresult rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
77 &willNotify,
78 &isAlternate);
79 if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) {
80 ++mPendingSheetCount;
81 mScriptLoader->AddExecuteBlocker();
84 if (aElement->IsHTML(nsGkAtoms::link)) {
85 // look for <link rel="next" href="url">
86 nsAutoString relVal;
87 aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
88 if (!relVal.IsEmpty()) {
89 uint32_t linkTypes =
90 nsStyleLinkElement::ParseLinkTypes(relVal, aElement->NodePrincipal());
91 bool hasPrefetch = linkTypes & nsStyleLinkElement::ePREFETCH;
92 if (hasPrefetch || (linkTypes & nsStyleLinkElement::eNEXT)) {
93 nsAutoString hrefVal;
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);
109 // Re-open update
110 BeginDocUpdate();
113 void
114 nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m)
116 nsCompatibility mode = eCompatibility_NavQuirks;
117 switch (m) {
118 case STANDARDS_MODE:
119 mode = eCompatibility_FullStandards;
120 break;
121 case ALMOST_STANDARDS_MODE:
122 mode = eCompatibility_AlmostStandards;
123 break;
124 case QUIRKS_MODE:
125 mode = eCompatibility_NavQuirks;
126 break;
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
135 void
136 nsHtml5DocumentBuilder::UpdateChildCounts()
138 // No-op
141 nsresult
142 nsHtml5DocumentBuilder::FlushTags()
144 return NS_OK;