/src/mozilla-central/parser/html/nsHtml5DocumentBuilder.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsHtml5DocumentBuilder.h" |
8 | | |
9 | | #include "mozilla/dom/ScriptLoader.h" |
10 | | #include "nsIHTMLDocument.h" |
11 | | #include "nsIStyleSheetLinkingElement.h" |
12 | | #include "nsNameSpaceManager.h" |
13 | | #include "nsStyleLinkElement.h" |
14 | | |
15 | | NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder, |
16 | | nsContentSink, |
17 | | mOwnedElements) |
18 | | |
19 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsHtml5DocumentBuilder) |
20 | 0 | NS_INTERFACE_MAP_END_INHERITING(nsContentSink) |
21 | | |
22 | | NS_IMPL_ADDREF_INHERITED(nsHtml5DocumentBuilder, nsContentSink) |
23 | | NS_IMPL_RELEASE_INHERITED(nsHtml5DocumentBuilder, nsContentSink) |
24 | | |
25 | | nsHtml5DocumentBuilder::nsHtml5DocumentBuilder(bool aRunsToCompletion) |
26 | | : mBroken(NS_OK) |
27 | | , mFlushState(eHtml5FlushState::eNotFlushing) |
28 | 0 | { |
29 | 0 | mRunsToCompletion = aRunsToCompletion; |
30 | 0 | } |
31 | | |
32 | | nsresult |
33 | | nsHtml5DocumentBuilder::Init(nsIDocument* aDoc, |
34 | | nsIURI* aURI, |
35 | | nsISupports* aContainer, |
36 | | nsIChannel* aChannel) |
37 | 0 | { |
38 | 0 | return nsContentSink::Init(aDoc, aURI, aContainer, aChannel); |
39 | 0 | } |
40 | | |
41 | 0 | nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder() {} |
42 | | |
43 | | nsresult |
44 | | nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason) |
45 | 0 | { |
46 | 0 | mBroken = aReason; |
47 | 0 | return aReason; |
48 | 0 | } |
49 | | |
50 | | void |
51 | | nsHtml5DocumentBuilder::SetDocumentCharsetAndSource( |
52 | | NotNull<const Encoding*> aEncoding, |
53 | | int32_t aCharsetSource) |
54 | 0 | { |
55 | 0 | if (mDocument) { |
56 | 0 | mDocument->SetDocumentCharacterSetSource(aCharsetSource); |
57 | 0 | mDocument->SetDocumentCharacterSet(aEncoding); |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | void |
62 | | nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement) |
63 | 0 | { |
64 | 0 | nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aElement)); |
65 | 0 | if (!ssle) { |
66 | 0 | MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled, |
67 | 0 | "Node didn't QI to style, but SVG wasn't disabled."); |
68 | 0 | return; |
69 | 0 | } |
70 | 0 |
|
71 | 0 | // Break out of the doc update created by Flush() to zap a runnable |
72 | 0 | // waiting to call UpdateStyleSheet without the right observer |
73 | 0 | EndDocUpdate(); |
74 | 0 |
|
75 | 0 | if (MOZ_UNLIKELY(!mParser)) { |
76 | 0 | // EndDocUpdate ran stuff that called nsIParser::Terminate() |
77 | 0 | return; |
78 | 0 | } |
79 | 0 | |
80 | 0 | ssle->SetEnableUpdates(true); |
81 | 0 |
|
82 | 0 | auto updateOrError = |
83 | 0 | ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this); |
84 | 0 |
|
85 | 0 | if (updateOrError.isOk() && |
86 | 0 | updateOrError.unwrap().ShouldBlock() && |
87 | 0 | !mRunsToCompletion) { |
88 | 0 | ++mPendingSheetCount; |
89 | 0 | mScriptLoader->AddParserBlockingScriptExecutionBlocker(); |
90 | 0 | } |
91 | 0 |
|
92 | 0 | // Re-open update |
93 | 0 | BeginDocUpdate(); |
94 | 0 | } |
95 | | |
96 | | void |
97 | | nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m) |
98 | 0 | { |
99 | 0 | nsCompatibility mode = eCompatibility_NavQuirks; |
100 | 0 | switch (m) { |
101 | 0 | case STANDARDS_MODE: |
102 | 0 | mode = eCompatibility_FullStandards; |
103 | 0 | break; |
104 | 0 | case ALMOST_STANDARDS_MODE: |
105 | 0 | mode = eCompatibility_AlmostStandards; |
106 | 0 | break; |
107 | 0 | case QUIRKS_MODE: |
108 | 0 | mode = eCompatibility_NavQuirks; |
109 | 0 | break; |
110 | 0 | } |
111 | 0 | nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(mDocument); |
112 | 0 | NS_ASSERTION(htmlDocument, "Document didn't QI into HTML document."); |
113 | 0 | htmlDocument->SetCompatibilityMode(mode); |
114 | 0 | } |
115 | | |
116 | | // nsContentSink overrides |
117 | | |
118 | | void |
119 | | nsHtml5DocumentBuilder::UpdateChildCounts() |
120 | 0 | { |
121 | 0 | // No-op |
122 | 0 | } |
123 | | |
124 | | nsresult |
125 | | nsHtml5DocumentBuilder::FlushTags() |
126 | 0 | { |
127 | 0 | return NS_OK; |
128 | 0 | } |