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
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "nsHtml5Module.h"
|
2009-11-24 15:28:18 +03:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
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
|
|
|
#include "mozilla/Services.h"
|
2011-05-29 03:42:57 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-06-13 08:07:59 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-05-29 03:42:57 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsHtml5Module::sOffMainThread = true;
|
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()
|
|
|
|
{
|
2011-05-29 03:42:57 +04:00
|
|
|
Preferences::AddBoolVarCache(&sOffMainThread, "html5.offmainthread");
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5Atoms::AddRefAtoms();
|
|
|
|
nsHtml5AttributeName::initializeStatics();
|
|
|
|
nsHtml5ElementName::initializeStatics();
|
|
|
|
nsHtml5HtmlAttributes::initializeStatics();
|
|
|
|
nsHtml5NamedCharacters::initializeStatics();
|
|
|
|
nsHtml5Portability::initializeStatics();
|
|
|
|
nsHtml5StackNode::initializeStatics();
|
|
|
|
nsHtml5Tokenizer::initializeStatics();
|
|
|
|
nsHtml5TreeBuilder::initializeStatics();
|
|
|
|
nsHtml5UTF16Buffer::initializeStatics();
|
2009-11-17 11:52:30 +03:00
|
|
|
nsHtml5StreamParser::InitializeStatics();
|
2012-03-27 10:27:45 +04:00
|
|
|
nsHtml5TreeOpExecutor::InitializeStatics();
|
2009-06-29 02:44:22 +04:00
|
|
|
#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()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(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
|
|
|
|
nsresult
|
|
|
|
nsHtml5Module::Initialize(nsIParser* aParser, nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer, nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
|
|
|
|
nsHtml5Parser* parser = static_cast<nsHtml5Parser*> (aParser);
|
|
|
|
return parser->Initialize(aDoc, aURI, aContainer, aChannel);
|
|
|
|
}
|
|
|
|
|
2012-06-13 08:07:59 +04:00
|
|
|
class nsHtml5ParserThreadTerminator MOZ_FINAL : public nsIObserver
|
2009-11-24 15:28:18 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2014-09-02 02:04:52 +04:00
|
|
|
explicit nsHtml5ParserThreadTerminator(nsIThread* aThread)
|
2009-11-24 15:28:18 +03:00
|
|
|
: mThread(aThread)
|
|
|
|
{}
|
2015-01-06 23:11:44 +03:00
|
|
|
NS_IMETHODIMP Observe(nsISupports *, const char *topic, const char16_t *) MOZ_OVERRIDE
|
2009-11-24 15:28:18 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"),
|
|
|
|
"Unexpected topic");
|
|
|
|
if (mThread) {
|
|
|
|
mThread->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mThread = nullptr;
|
2009-11-24 15:28:18 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
2014-06-27 22:41:03 +04:00
|
|
|
~nsHtml5ParserThreadTerminator() {}
|
|
|
|
|
2009-11-24 15:28:18 +03:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsHtml5ParserThreadTerminator, nsIObserver)
|
2009-11-24 15:28:18 +03:00
|
|
|
|
2009-09-25 21:11:02 +04:00
|
|
|
// static
|
|
|
|
nsIThread*
|
|
|
|
nsHtml5Module::GetStreamParserThread()
|
|
|
|
{
|
2009-11-19 14:53:32 +03:00
|
|
|
if (sOffMainThread) {
|
|
|
|
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");
|
|
|
|
os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread),
|
|
|
|
"xpcom-shutdown-threads",
|
2011-10-17 18:59:28 +04:00
|
|
|
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
|