LCOV - code coverage report
Current view: top level - parser/html - nsHtml5Module.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 37 62 59.7 %
Date: 2017-07-14 16:53:18 Functions: 6 11 54.5 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       4             : 
       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"
      20             : 
      21             : using namespace mozilla;
      22             : 
      23             : // static
      24             : bool nsHtml5Module::sOffMainThread = true;
      25             : nsIThread* nsHtml5Module::sStreamParserThread = nullptr;
      26             : nsIThread* nsHtml5Module::sMainThread = nullptr;
      27             : 
      28             : // static
      29             : void
      30           3 : nsHtml5Module::InitializeStatics()
      31             : {
      32           3 :   Preferences::AddBoolVarCache(&sOffMainThread, "html5.offmainthread");
      33           3 :   nsHtml5AttributeName::initializeStatics();
      34           3 :   nsHtml5ElementName::initializeStatics();
      35           3 :   nsHtml5HtmlAttributes::initializeStatics();
      36           3 :   nsHtml5NamedCharacters::initializeStatics();
      37           3 :   nsHtml5Portability::initializeStatics();
      38           3 :   nsHtml5StackNode::initializeStatics();
      39           3 :   nsHtml5Tokenizer::initializeStatics();
      40           3 :   nsHtml5TreeBuilder::initializeStatics();
      41           3 :   nsHtml5UTF16Buffer::initializeStatics();
      42           3 :   nsHtml5StreamParser::InitializeStatics();
      43           3 :   nsHtml5TreeOpExecutor::InitializeStatics();
      44             : #ifdef DEBUG
      45           3 :   sNsHtml5ModuleInitialized = true;
      46             : #endif
      47           3 : }
      48             : 
      49             : // static
      50             : void
      51           0 : nsHtml5Module::ReleaseStatics()
      52             : {
      53             : #ifdef DEBUG
      54           0 :   sNsHtml5ModuleInitialized = false;
      55             : #endif
      56           0 :   nsHtml5AttributeName::releaseStatics();
      57           0 :   nsHtml5ElementName::releaseStatics();
      58           0 :   nsHtml5HtmlAttributes::releaseStatics();
      59           0 :   nsHtml5NamedCharacters::releaseStatics();
      60           0 :   nsHtml5Portability::releaseStatics();
      61           0 :   nsHtml5StackNode::releaseStatics();
      62           0 :   nsHtml5Tokenizer::releaseStatics();
      63           0 :   nsHtml5TreeBuilder::releaseStatics();
      64           0 :   nsHtml5UTF16Buffer::releaseStatics();
      65           0 :   NS_IF_RELEASE(sStreamParserThread);
      66           0 :   NS_IF_RELEASE(sMainThread);
      67           0 : }
      68             : 
      69             : // static
      70             : already_AddRefed<nsIParser>
      71           2 : nsHtml5Module::NewHtml5Parser()
      72             : {
      73           2 :   MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
      74           4 :   nsCOMPtr<nsIParser> rv = new nsHtml5Parser();
      75           4 :   return rv.forget();
      76             : }
      77             : 
      78             : // static
      79             : nsresult
      80           2 : nsHtml5Module::Initialize(nsIParser* aParser, nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer, nsIChannel* aChannel)
      81             : {
      82           2 :   MOZ_ASSERT(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
      83           2 :   nsHtml5Parser* parser = static_cast<nsHtml5Parser*> (aParser);
      84           2 :   return parser->Initialize(aDoc, aURI, aContainer, aChannel);
      85             : }
      86             : 
      87             : class nsHtml5ParserThreadTerminator final : public nsIObserver
      88             : {
      89             :   public:
      90             :     NS_DECL_ISUPPORTS
      91           2 :     explicit nsHtml5ParserThreadTerminator(nsIThread* aThread)
      92           2 :       : mThread(aThread)
      93           2 :     {}
      94           0 :     NS_IMETHOD Observe(nsISupports *, const char *topic, const char16_t *) override
      95             :     {
      96           0 :       NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"), 
      97             :                    "Unexpected topic");
      98           0 :       if (mThread) {
      99           0 :         mThread->Shutdown();
     100           0 :         mThread = nullptr;
     101             :       }
     102           0 :       return NS_OK;
     103             :     }
     104             :   private:
     105           0 :     ~nsHtml5ParserThreadTerminator() {}
     106             : 
     107             :     nsCOMPtr<nsIThread> mThread;
     108             : };
     109             : 
     110           2 : NS_IMPL_ISUPPORTS(nsHtml5ParserThreadTerminator, nsIObserver)
     111             : 
     112             : // static 
     113             : nsIThread*
     114           2 : nsHtml5Module::GetStreamParserThread()
     115             : {
     116           2 :   if (sOffMainThread) {
     117           2 :     if (!sStreamParserThread) {
     118           2 :       NS_NewNamedThread("HTML5 Parser", &sStreamParserThread);
     119           2 :       NS_ASSERTION(sStreamParserThread, "Thread creation failed!");
     120           4 :       nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     121           2 :       NS_ASSERTION(os, "do_GetService failed");
     122           4 :       os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread), 
     123             :                       "xpcom-shutdown-threads",
     124           4 :                       false);
     125             :     }
     126           2 :     return sStreamParserThread;
     127             :   }
     128           0 :   if (!sMainThread) {
     129           0 :     NS_GetMainThread(&sMainThread);
     130           0 :     NS_ASSERTION(sMainThread, "Main thread getter failed");
     131             :   }
     132           0 :   return sMainThread;
     133             : }
     134             : 
     135             : #ifdef DEBUG
     136             : bool nsHtml5Module::sNsHtml5ModuleInitialized = false;
     137             : #endif

Generated by: LCOV version 1.13