LCOV - code coverage report
Current view: directory - parser/html - nsHtml5Module.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 63 29 46.0 %
Date: 2012-06-02 Functions: 11 2 18.2 %

       1                 : /* ***** BEGIN LICENSE BLOCK *****
       2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       3                 :  *
       4                 :  * The contents of this file are subject to the Mozilla Public License Version
       5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       6                 :  * the License. You may obtain a copy of the License at
       7                 :  * http://www.mozilla.org/MPL/
       8                 :  *
       9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11                 :  * for the specific language governing rights and limitations under the
      12                 :  * License.
      13                 :  *
      14                 :  * The Original Code is HTML Parser C++ Translator code.
      15                 :  *
      16                 :  * The Initial Developer of the Original Code is
      17                 :  * Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2008
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Henri Sivonen <hsivonen@iki.fi>
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "nsHtml5AttributeName.h"
      39                 : #include "nsHtml5ElementName.h"
      40                 : #include "nsHtml5HtmlAttributes.h"
      41                 : #include "nsHtml5NamedCharacters.h"
      42                 : #include "nsHtml5Portability.h"
      43                 : #include "nsHtml5StackNode.h"
      44                 : #include "nsHtml5Tokenizer.h"
      45                 : #include "nsHtml5TreeBuilder.h"
      46                 : #include "nsHtml5UTF16Buffer.h"
      47                 : #include "nsHtml5Module.h"
      48                 : #include "nsIObserverService.h"
      49                 : #include "nsIServiceManager.h"
      50                 : #include "mozilla/Services.h"
      51                 : #include "mozilla/Preferences.h"
      52                 : 
      53                 : using namespace mozilla;
      54                 : 
      55                 : // static
      56                 : bool nsHtml5Module::sOffMainThread = true;
      57                 : nsIThread* nsHtml5Module::sStreamParserThread = nsnull;
      58                 : nsIThread* nsHtml5Module::sMainThread = nsnull;
      59                 : 
      60                 : // static
      61                 : void
      62            1404 : nsHtml5Module::InitializeStatics()
      63                 : {
      64            1404 :   Preferences::AddBoolVarCache(&sOffMainThread, "html5.offmainthread");
      65            1404 :   nsHtml5Atoms::AddRefAtoms();
      66            1404 :   nsHtml5AttributeName::initializeStatics();
      67            1404 :   nsHtml5ElementName::initializeStatics();
      68            1404 :   nsHtml5HtmlAttributes::initializeStatics();
      69            1404 :   nsHtml5NamedCharacters::initializeStatics();
      70            1404 :   nsHtml5Portability::initializeStatics();
      71            1404 :   nsHtml5StackNode::initializeStatics();
      72            1404 :   nsHtml5Tokenizer::initializeStatics();
      73            1404 :   nsHtml5TreeBuilder::initializeStatics();
      74            1404 :   nsHtml5UTF16Buffer::initializeStatics();
      75            1404 :   nsHtml5StreamParser::InitializeStatics();
      76                 : #ifdef DEBUG
      77            1404 :   sNsHtml5ModuleInitialized = true;
      78                 : #endif
      79            1404 : }
      80                 : 
      81                 : // static
      82                 : void
      83            1403 : nsHtml5Module::ReleaseStatics()
      84                 : {
      85                 : #ifdef DEBUG
      86            1403 :   sNsHtml5ModuleInitialized = false;
      87                 : #endif
      88            1403 :   nsHtml5AttributeName::releaseStatics();
      89            1403 :   nsHtml5ElementName::releaseStatics();
      90            1403 :   nsHtml5HtmlAttributes::releaseStatics();
      91            1403 :   nsHtml5NamedCharacters::releaseStatics();
      92            1403 :   nsHtml5Portability::releaseStatics();
      93            1403 :   nsHtml5StackNode::releaseStatics();
      94            1403 :   nsHtml5Tokenizer::releaseStatics();
      95            1403 :   nsHtml5TreeBuilder::releaseStatics();
      96            1403 :   nsHtml5UTF16Buffer::releaseStatics();
      97            1403 :   NS_IF_RELEASE(sStreamParserThread);
      98            1403 :   NS_IF_RELEASE(sMainThread);
      99            1403 : }
     100                 : 
     101                 : // static
     102                 : already_AddRefed<nsIParser>
     103               0 : nsHtml5Module::NewHtml5Parser()
     104                 : {
     105               0 :   NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
     106               0 :   nsIParser* rv = static_cast<nsIParser*> (new nsHtml5Parser());
     107               0 :   NS_ADDREF(rv);
     108               0 :   return rv;
     109                 : }
     110                 : 
     111                 : // static
     112                 : nsresult
     113               0 : nsHtml5Module::Initialize(nsIParser* aParser, nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer, nsIChannel* aChannel)
     114                 : {
     115               0 :   NS_ABORT_IF_FALSE(sNsHtml5ModuleInitialized, "nsHtml5Module not initialized.");
     116               0 :   nsHtml5Parser* parser = static_cast<nsHtml5Parser*> (aParser);
     117               0 :   return parser->Initialize(aDoc, aURI, aContainer, aChannel);
     118                 : }
     119                 : 
     120                 : class nsHtml5ParserThreadTerminator : public nsIObserver
     121               0 : {
     122                 :   public:
     123                 :     NS_DECL_ISUPPORTS
     124               0 :     nsHtml5ParserThreadTerminator(nsIThread* aThread)
     125               0 :       : mThread(aThread)
     126               0 :     {}
     127               0 :     NS_IMETHODIMP Observe(nsISupports *, const char *topic, const PRUnichar *)
     128                 :     {
     129               0 :       NS_ASSERTION(!strcmp(topic, "xpcom-shutdown-threads"), 
     130                 :                    "Unexpected topic");
     131               0 :       if (mThread) {
     132               0 :         mThread->Shutdown();
     133               0 :         mThread = nsnull;
     134                 :       }
     135               0 :       return NS_OK;
     136                 :     }
     137                 :   private:
     138                 :     nsCOMPtr<nsIThread> mThread;
     139                 : };
     140                 : 
     141               0 : NS_IMPL_ISUPPORTS1(nsHtml5ParserThreadTerminator, nsIObserver)
     142                 : 
     143                 : // static 
     144                 : nsIThread*
     145               0 : nsHtml5Module::GetStreamParserThread()
     146                 : {
     147               0 :   if (sOffMainThread) {
     148               0 :     if (!sStreamParserThread) {
     149               0 :       NS_NewThread(&sStreamParserThread);
     150               0 :       NS_ASSERTION(sStreamParserThread, "Thread creation failed!");
     151               0 :       nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     152               0 :       NS_ASSERTION(os, "do_GetService failed");
     153               0 :       os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread), 
     154                 :                       "xpcom-shutdown-threads",
     155               0 :                       false);
     156                 :     }
     157               0 :     return sStreamParserThread;
     158                 :   }
     159               0 :   if (!sMainThread) {
     160               0 :     NS_GetMainThread(&sMainThread);
     161               0 :     NS_ASSERTION(sMainThread, "Main thread getter failed");
     162                 :   }
     163               0 :   return sMainThread;
     164                 : }
     165                 : 
     166                 : #ifdef DEBUG
     167                 : bool nsHtml5Module::sNsHtml5ModuleInitialized = false;
     168                 : #endif

Generated by: LCOV version 1.7