parser/html/nsHtml5Module.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsHtml5AttributeName.h"
michael@0 6 #include "nsHtml5ElementName.h"
michael@0 7 #include "nsHtml5HtmlAttributes.h"
michael@0 8 #include "nsHtml5NamedCharacters.h"
michael@0 9 #include "nsHtml5Portability.h"
michael@0 10 #include "nsHtml5StackNode.h"
michael@0 11 #include "nsHtml5Tokenizer.h"
michael@0 12 #include "nsHtml5TreeBuilder.h"
michael@0 13 #include "nsHtml5UTF16Buffer.h"
michael@0 14 #include "nsHtml5Module.h"
michael@0 15 #include "nsIObserverService.h"
michael@0 16 #include "nsIServiceManager.h"
michael@0 17 #include "mozilla/Services.h"
michael@0 18 #include "mozilla/Preferences.h"
michael@0 19 #include "mozilla/Attributes.h"
michael@0 20
michael@0 21 using namespace mozilla;
michael@0 22
michael@0 23 // static
michael@0 24 bool nsHtml5Module::sOffMainThread = true;
michael@0 25 nsIThread* nsHtml5Module::sStreamParserThread = nullptr;
michael@0 26 nsIThread* nsHtml5Module::sMainThread = nullptr;
michael@0 27
michael@0 28 // static
michael@0 29 void
michael@0 30 nsHtml5Module::InitializeStatics()
michael@0 31 {
michael@0 32 Preferences::AddBoolVarCache(&sOffMainThread, "html5.offmainthread");
michael@0 33 nsHtml5Atoms::AddRefAtoms();
michael@0 34 nsHtml5AttributeName::initializeStatics();
michael@0 35 nsHtml5ElementName::initializeStatics();
michael@0 36 nsHtml5HtmlAttributes::initializeStatics();
michael@0 37 nsHtml5NamedCharacters::initializeStatics();
michael@0 38 nsHtml5Portability::initializeStatics();
michael@0 39 nsHtml5StackNode::initializeStatics();
michael@0 40 nsHtml5Tokenizer::initializeStatics();
michael@0 41 nsHtml5TreeBuilder::initializeStatics();
michael@0 42 nsHtml5UTF16Buffer::initializeStatics();
michael@0 43 nsHtml5StreamParser::InitializeStatics();
michael@0 44 nsHtml5TreeOpExecutor::InitializeStatics();
michael@0 45 #ifdef DEBUG
michael@0 46 sNsHtml5ModuleInitialized = true;
michael@0 47 #endif
michael@0 48 }
michael@0 49
michael@0 50 // static
michael@0 51 void
michael@0 52 nsHtml5Module::ReleaseStatics()
michael@0 53 {
michael@0 54 #ifdef DEBUG
michael@0 55 sNsHtml5ModuleInitialized = false;
michael@0 56 #endif
michael@0 57 nsHtml5AttributeName::releaseStatics();
michael@0 58 nsHtml5ElementName::releaseStatics();
michael@0 59 nsHtml5HtmlAttributes::releaseStatics();
michael@0 60 nsHtml5NamedCharacters::releaseStatics();
michael@0 61 nsHtml5Portability::releaseStatics();
michael@0 62 nsHtml5StackNode::releaseStatics();
michael@0 63 nsHtml5Tokenizer::releaseStatics();
michael@0 64 nsHtml5TreeBuilder::releaseStatics();
michael@0 65 nsHtml5UTF16Buffer::releaseStatics();
michael@0 66 NS_IF_RELEASE(sStreamParserThread);
michael@0 67 NS_IF_RELEASE(sMainThread);
michael@0 68 }
michael@0 69
michael@0 70 // static
michael@0 71 already_AddRefed<nsIParser>
michael@0 72 nsHtml5Module::NewHtml5Parser()
michael@0 73 {
michael@0 74 NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
michael@0 75 nsCOMPtr<nsIParser> rv = new nsHtml5Parser();
michael@0 76 return rv.forget();
michael@0 77 }
michael@0 78
michael@0 79 // static
michael@0 80 nsresult
michael@0 81 nsHtml5Module::Initialize(nsIParser* aParser, nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer, nsIChannel* aChannel)
michael@0 82 {
michael@0 83 NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
michael@0 84 nsHtml5Parser* parser = static_cast<nsHtml5Parser*> (aParser);
michael@0 85 return parser->Initialize(aDoc, aURI, aContainer, aChannel);
michael@0 86 }
michael@0 87
michael@0 88 class nsHtml5ParserThreadTerminator MOZ_FINAL : public nsIObserver
michael@0 89 {
michael@0 90 public:
michael@0 91 NS_DECL_ISUPPORTS
michael@0 92 nsHtml5ParserThreadTerminator(nsIThread* aThread)
michael@0 93 : mThread(aThread)
michael@0 94 {}
michael@0 95 NS_IMETHODIMP Observe(nsISupports *, const char *topic, const char16_t *)
michael@0 96 {
michael@0 97 NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"),
michael@0 98 "Unexpected topic");
michael@0 99 if (mThread) {
michael@0 100 mThread->Shutdown();
michael@0 101 mThread = nullptr;
michael@0 102 }
michael@0 103 return NS_OK;
michael@0 104 }
michael@0 105 private:
michael@0 106 nsCOMPtr<nsIThread> mThread;
michael@0 107 };
michael@0 108
michael@0 109 NS_IMPL_ISUPPORTS(nsHtml5ParserThreadTerminator, nsIObserver)
michael@0 110
michael@0 111 // static
michael@0 112 nsIThread*
michael@0 113 nsHtml5Module::GetStreamParserThread()
michael@0 114 {
michael@0 115 if (sOffMainThread) {
michael@0 116 if (!sStreamParserThread) {
michael@0 117 NS_NewNamedThread("HTML5 Parser", &sStreamParserThread);
michael@0 118 NS_ASSERTION(sStreamParserThread, "Thread creation failed!");
michael@0 119 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
michael@0 120 NS_ASSERTION(os, "do_GetService failed");
michael@0 121 os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread),
michael@0 122 "xpcom-shutdown-threads",
michael@0 123 false);
michael@0 124 }
michael@0 125 return sStreamParserThread;
michael@0 126 }
michael@0 127 if (!sMainThread) {
michael@0 128 NS_GetMainThread(&sMainThread);
michael@0 129 NS_ASSERTION(sMainThread, "Main thread getter failed");
michael@0 130 }
michael@0 131 return sMainThread;
michael@0 132 }
michael@0 133
michael@0 134 #ifdef DEBUG
michael@0 135 bool nsHtml5Module::sNsHtml5ModuleInitialized = false;
michael@0 136 #endif

mercurial