2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
#include "nsHtml5Module.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
2018-03-27 03:59:48 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
#include "nsHtml5AttributeName.h"
|
|
|
|
#include "nsHtml5ElementName.h"
|
|
|
|
#include "nsHtml5HtmlAttributes.h"
|
|
|
|
#include "nsHtml5NamedCharacters.h"
|
|
|
|
#include "nsHtml5Portability.h"
|
|
|
|
#include "nsHtml5StackNode.h"
|
|
|
|
#include "nsHtml5Tokenizer.h"
|
|
|
|
#include "nsHtml5TreeBuilder.h"
|
|
|
|
#include "nsHtml5UTF16Buffer.h"
|
2009-11-24 15:28:18 +03:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2011-05-29 03:42:57 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
// static
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIThread* nsHtml5Module::sStreamParserThread = nullptr;
|
|
|
|
nsIThread* nsHtml5Module::sMainThread = nullptr;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
// static
|
|
|
|
void nsHtml5Module::InitializeStatics() {
|
|
|
|
nsHtml5AttributeName::initializeStatics();
|
|
|
|
nsHtml5ElementName::initializeStatics();
|
|
|
|
nsHtml5HtmlAttributes::initializeStatics();
|
|
|
|
nsHtml5NamedCharacters::initializeStatics();
|
|
|
|
nsHtml5Portability::initializeStatics();
|
|
|
|
nsHtml5StackNode::initializeStatics();
|
|
|
|
nsHtml5Tokenizer::initializeStatics();
|
|
|
|
nsHtml5TreeBuilder::initializeStatics();
|
|
|
|
nsHtml5UTF16Buffer::initializeStatics();
|
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
sNsHtml5ModuleInitialized = true;
|
2009-06-29 02:44:22 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void nsHtml5Module::ReleaseStatics() {
|
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
sNsHtml5ModuleInitialized = false;
|
2009-06-29 02:44:22 +04:00
|
|
|
#endif
|
|
|
|
nsHtml5AttributeName::releaseStatics();
|
|
|
|
nsHtml5ElementName::releaseStatics();
|
|
|
|
nsHtml5HtmlAttributes::releaseStatics();
|
|
|
|
nsHtml5NamedCharacters::releaseStatics();
|
|
|
|
nsHtml5Portability::releaseStatics();
|
|
|
|
nsHtml5StackNode::releaseStatics();
|
|
|
|
nsHtml5Tokenizer::releaseStatics();
|
|
|
|
nsHtml5TreeBuilder::releaseStatics();
|
|
|
|
nsHtml5UTF16Buffer::releaseStatics();
|
2009-09-25 21:11:02 +04:00
|
|
|
NS_IF_RELEASE(sStreamParserThread);
|
|
|
|
NS_IF_RELEASE(sMainThread);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<nsIParser> nsHtml5Module::NewHtml5Parser() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
|
2013-04-22 15:15:59 +04:00
|
|
|
nsCOMPtr<nsIParser> rv = new nsHtml5Parser();
|
|
|
|
return rv.forget();
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult nsHtml5Module::Initialize(nsIParser* aParser, dom::Document* aDoc,
|
2018-03-16 18:26:06 +03:00
|
|
|
nsIURI* aURI, nsISupports* aContainer,
|
|
|
|
nsIChannel* aChannel) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
|
2018-03-16 18:26:06 +03:00
|
|
|
nsHtml5Parser* parser = static_cast<nsHtml5Parser*>(aParser);
|
2009-06-29 02:44:22 +04:00
|
|
|
return parser->Initialize(aDoc, aURI, aContainer, aChannel);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsHtml5ParserThreadTerminator final : public nsIObserver {
|
2018-03-16 18:26:06 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
explicit nsHtml5ParserThreadTerminator(nsIThread* aThread)
|
|
|
|
: mThread(aThread) {}
|
|
|
|
NS_IMETHOD Observe(nsISupports*, const char* topic,
|
|
|
|
const char16_t*) override {
|
|
|
|
NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"), "Unexpected topic");
|
|
|
|
if (mThread) {
|
|
|
|
mThread->Shutdown();
|
|
|
|
mThread = nullptr;
|
2009-11-24 15:28:18 +03:00
|
|
|
}
|
2018-03-16 18:26:06 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsHtml5ParserThreadTerminator() {}
|
2014-06-27 22:41:03 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
2009-11-24 15:28:18 +03:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsHtml5ParserThreadTerminator, nsIObserver)
|
2009-11-24 15:28:18 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
// static
|
2009-09-25 21:11:02 +04:00
|
|
|
nsIThread* nsHtml5Module::GetStreamParserThread() {
|
2018-03-27 03:59:48 +03:00
|
|
|
if (StaticPrefs::html5_offmainthread()) {
|
2009-11-19 14:53:32 +03:00
|
|
|
if (!sStreamParserThread) {
|
2012-06-12 21:06:20 +04:00
|
|
|
NS_NewNamedThread("HTML5 Parser", &sStreamParserThread);
|
2009-11-19 14:53:32 +03:00
|
|
|
NS_ASSERTION(sStreamParserThread, "Thread creation failed!");
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2009-11-24 15:28:18 +03:00
|
|
|
NS_ASSERTION(os, "do_GetService failed");
|
2018-03-16 18:26:06 +03:00
|
|
|
os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread),
|
2009-11-24 15:28:18 +03:00
|
|
|
"xpcom-shutdown-threads", false);
|
2009-11-19 14:53:32 +03:00
|
|
|
}
|
|
|
|
return sStreamParserThread;
|
|
|
|
}
|
2009-11-19 18:13:19 +03:00
|
|
|
if (!sMainThread) {
|
|
|
|
NS_GetMainThread(&sMainThread);
|
|
|
|
NS_ASSERTION(sMainThread, "Main thread getter failed");
|
|
|
|
}
|
2009-11-19 14:53:32 +03:00
|
|
|
return sMainThread;
|
2009-09-25 21:11:02 +04:00
|
|
|
}
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsHtml5Module::sNsHtml5ModuleInitialized = false;
|
2009-06-29 02:44:22 +04:00
|
|
|
#endif
|