2012-05-29 08:52:43 -07: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-28 15:44:22 -07: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 04:28:18 -08: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 09:59:13 -07:00
|
|
|
#include "mozilla/Services.h"
|
2011-05-28 16:42:57 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-06-12 21:07:59 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-05-28 16:42:57 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2009-06-28 15:44:22 -07:00
|
|
|
|
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHtml5Module::sOffMainThread = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIThread* nsHtml5Module::sStreamParserThread = nullptr;
|
|
|
|
nsIThread* nsHtml5Module::sMainThread = nullptr;
|
2009-06-28 15:44:22 -07:00
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsHtml5Module::InitializeStatics()
|
|
|
|
{
|
2011-05-28 16:42:57 -07:00
|
|
|
Preferences::AddBoolVarCache(&sOffMainThread, "html5.offmainthread");
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5Atoms::AddRefAtoms();
|
|
|
|
nsHtml5AttributeName::initializeStatics();
|
|
|
|
nsHtml5ElementName::initializeStatics();
|
|
|
|
nsHtml5HtmlAttributes::initializeStatics();
|
|
|
|
nsHtml5NamedCharacters::initializeStatics();
|
|
|
|
nsHtml5Portability::initializeStatics();
|
|
|
|
nsHtml5StackNode::initializeStatics();
|
|
|
|
nsHtml5Tokenizer::initializeStatics();
|
|
|
|
nsHtml5TreeBuilder::initializeStatics();
|
|
|
|
nsHtml5UTF16Buffer::initializeStatics();
|
2009-11-17 00:52:30 -08:00
|
|
|
nsHtml5StreamParser::InitializeStatics();
|
2012-03-26 23:27:45 -07:00
|
|
|
nsHtml5TreeOpExecutor::InitializeStatics();
|
2009-06-28 15:44:22 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
sNsHtml5ModuleInitialized = true;
|
2009-06-28 15:44:22 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsHtml5Module::ReleaseStatics()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
sNsHtml5ModuleInitialized = false;
|
2009-06-28 15:44:22 -07:00
|
|
|
#endif
|
|
|
|
nsHtml5AttributeName::releaseStatics();
|
|
|
|
nsHtml5ElementName::releaseStatics();
|
|
|
|
nsHtml5HtmlAttributes::releaseStatics();
|
|
|
|
nsHtml5NamedCharacters::releaseStatics();
|
|
|
|
nsHtml5Portability::releaseStatics();
|
|
|
|
nsHtml5StackNode::releaseStatics();
|
|
|
|
nsHtml5Tokenizer::releaseStatics();
|
|
|
|
nsHtml5TreeBuilder::releaseStatics();
|
|
|
|
nsHtml5UTF16Buffer::releaseStatics();
|
2009-09-25 10:11:02 -07:00
|
|
|
NS_IF_RELEASE(sStreamParserThread);
|
|
|
|
NS_IF_RELEASE(sMainThread);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<nsIParser>
|
|
|
|
nsHtml5Module::NewHtml5Parser()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
|
2013-04-22 04:15:59 -07:00
|
|
|
nsCOMPtr<nsIParser> rv = new nsHtml5Parser();
|
|
|
|
return rv.forget();
|
2009-06-28 15:44:22 -07: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-12 21:07:59 -07:00
|
|
|
class nsHtml5ParserThreadTerminator MOZ_FINAL : public nsIObserver
|
2009-11-24 04:28:18 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
nsHtml5ParserThreadTerminator(nsIThread* aThread)
|
|
|
|
: mThread(aThread)
|
|
|
|
{}
|
2014-01-04 07:02:17 -08:00
|
|
|
NS_IMETHODIMP Observe(nsISupports *, const char *topic, const char16_t *)
|
2009-11-24 04:28:18 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"),
|
|
|
|
"Unexpected topic");
|
|
|
|
if (mThread) {
|
|
|
|
mThread->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mThread = nullptr;
|
2009-11-24 04:28:18 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsHtml5ParserThreadTerminator, nsIObserver)
|
|
|
|
|
2009-09-25 10:11:02 -07:00
|
|
|
// static
|
|
|
|
nsIThread*
|
|
|
|
nsHtml5Module::GetStreamParserThread()
|
|
|
|
{
|
2009-11-19 03:53:32 -08:00
|
|
|
if (sOffMainThread) {
|
|
|
|
if (!sStreamParserThread) {
|
2012-06-12 10:06:20 -07:00
|
|
|
NS_NewNamedThread("HTML5 Parser", &sStreamParserThread);
|
2009-11-19 03:53:32 -08: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 09:59:13 -07:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
2009-11-24 04:28:18 -08:00
|
|
|
NS_ASSERTION(os, "do_GetService failed");
|
|
|
|
os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread),
|
|
|
|
"xpcom-shutdown-threads",
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2009-11-19 03:53:32 -08:00
|
|
|
}
|
|
|
|
return sStreamParserThread;
|
|
|
|
}
|
2009-11-19 07:13:19 -08:00
|
|
|
if (!sMainThread) {
|
|
|
|
NS_GetMainThread(&sMainThread);
|
|
|
|
NS_ASSERTION(sMainThread, "Main thread getter failed");
|
|
|
|
}
|
2009-11-19 03:53:32 -08:00
|
|
|
return sMainThread;
|
2009-09-25 10:11:02 -07:00
|
|
|
}
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHtml5Module::sNsHtml5ModuleInitialized = false;
|
2009-06-28 15:44:22 -07:00
|
|
|
#endif
|