1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsHtml5AttributeName.h"
6 #include "nsHtml5ElementName.h"
7 #include "nsHtml5HtmlAttributes.h"
8 #include "nsHtml5NamedCharacters.h"
9 #include "nsHtml5Portability.h"
10 #include "nsHtml5StackNode.h"
11 #include "nsHtml5Tokenizer.h"
12 #include "nsHtml5TreeBuilder.h"
13 #include "nsHtml5UTF16Buffer.h"
14 #include "nsHtml5Module.h"
15 #include "nsIObserverService.h"
16 #include "nsIServiceManager.h"
17 #include "mozilla/Services.h"
18 #include "mozilla/Preferences.h"
19 #include "mozilla/Attributes.h"
21 using namespace mozilla
;
24 bool nsHtml5Module::sOffMainThread
= true;
25 nsIThread
* nsHtml5Module::sStreamParserThread
= nullptr;
26 nsIThread
* nsHtml5Module::sMainThread
= nullptr;
30 nsHtml5Module::InitializeStatics()
32 Preferences::AddBoolVarCache(&sOffMainThread
, "html5.offmainthread");
33 nsHtml5Atoms::AddRefAtoms();
34 nsHtml5AttributeName::initializeStatics();
35 nsHtml5ElementName::initializeStatics();
36 nsHtml5HtmlAttributes::initializeStatics();
37 nsHtml5NamedCharacters::initializeStatics();
38 nsHtml5Portability::initializeStatics();
39 nsHtml5StackNode::initializeStatics();
40 nsHtml5Tokenizer::initializeStatics();
41 nsHtml5TreeBuilder::initializeStatics();
42 nsHtml5UTF16Buffer::initializeStatics();
43 nsHtml5StreamParser::InitializeStatics();
44 nsHtml5TreeOpExecutor::InitializeStatics();
46 sNsHtml5ModuleInitialized
= true;
52 nsHtml5Module::ReleaseStatics()
55 sNsHtml5ModuleInitialized
= false;
57 nsHtml5AttributeName::releaseStatics();
58 nsHtml5ElementName::releaseStatics();
59 nsHtml5HtmlAttributes::releaseStatics();
60 nsHtml5NamedCharacters::releaseStatics();
61 nsHtml5Portability::releaseStatics();
62 nsHtml5StackNode::releaseStatics();
63 nsHtml5Tokenizer::releaseStatics();
64 nsHtml5TreeBuilder::releaseStatics();
65 nsHtml5UTF16Buffer::releaseStatics();
66 NS_IF_RELEASE(sStreamParserThread
);
67 NS_IF_RELEASE(sMainThread
);
71 already_AddRefed
<nsIParser
>
72 nsHtml5Module::NewHtml5Parser()
74 NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized
, "nsHtml5Module not initialized.");
75 nsIParser
* rv
= static_cast<nsIParser
*> (new nsHtml5Parser());
82 nsHtml5Module::Initialize(nsIParser
* aParser
, nsIDocument
* aDoc
, nsIURI
* aURI
, nsISupports
* aContainer
, nsIChannel
* aChannel
)
84 NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized
, "nsHtml5Module not initialized.");
85 nsHtml5Parser
* parser
= static_cast<nsHtml5Parser
*> (aParser
);
86 return parser
->Initialize(aDoc
, aURI
, aContainer
, aChannel
);
89 class nsHtml5ParserThreadTerminator MOZ_FINAL
: public nsIObserver
93 nsHtml5ParserThreadTerminator(nsIThread
* aThread
)
96 NS_IMETHODIMP
Observe(nsISupports
*, const char *topic
, const PRUnichar
*)
98 NS_ASSERTION(!strcmp(topic
, "xpcom-shutdown-threads"),
107 nsCOMPtr
<nsIThread
> mThread
;
110 NS_IMPL_ISUPPORTS1(nsHtml5ParserThreadTerminator
, nsIObserver
)
114 nsHtml5Module::GetStreamParserThread()
116 if (sOffMainThread
) {
117 if (!sStreamParserThread
) {
118 NS_NewNamedThread("HTML5 Parser", &sStreamParserThread
);
119 NS_ASSERTION(sStreamParserThread
, "Thread creation failed!");
120 nsCOMPtr
<nsIObserverService
> os
= mozilla::services::GetObserverService();
121 NS_ASSERTION(os
, "do_GetService failed");
122 os
->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread
),
123 "xpcom-shutdown-threads",
126 return sStreamParserThread
;
129 NS_GetMainThread(&sMainThread
);
130 NS_ASSERTION(sMainThread
, "Main thread getter failed");
136 bool nsHtml5Module::sNsHtml5ModuleInitialized
= false;