LCOV - code coverage report
Current view: directory - parser/htmlparser/src - CParserContext.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 38 36 94.7 %
Date: 2012-06-02 Functions: 4 4 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim: set ts=2 sw=2 et tw=80: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : 
      40                 : #include "nsIAtom.h"
      41                 : #include "CParserContext.h"
      42                 : #include "nsToken.h"
      43                 : #include "prenv.h"  
      44                 : #include "nsIHTMLContentSink.h"
      45                 : #include "nsHTMLTokenizer.h"
      46                 : #include "nsMimeTypes.h"
      47                 : 
      48            3344 : CParserContext::CParserContext(CParserContext* aPrevContext,
      49                 :                                nsScanner* aScanner, 
      50                 :                                void *aKey, 
      51                 :                                eParserCommands aCommand,
      52                 :                                nsIRequestObserver* aListener, 
      53                 :                                eAutoDetectResult aStatus, 
      54                 :                                bool aCopyUnused)
      55                 :   : mListener(aListener),
      56                 :     mKey(aKey),
      57                 :     mPrevContext(aPrevContext),
      58                 :     mScanner(aScanner),
      59                 :     mDTDMode(eDTDMode_unknown),
      60                 :     mStreamListenerState(eNone),
      61                 :     mContextType(eCTNone),
      62                 :     mAutoDetectStatus(aStatus),
      63                 :     mParserCommand(aCommand),
      64                 :     mMultipart(true),
      65                 :     mCopyUnused(aCopyUnused),
      66            3344 :     mNumConsumed(0)
      67                 : { 
      68            3344 :   MOZ_COUNT_CTOR(CParserContext); 
      69            3344 : } 
      70                 : 
      71            6688 : CParserContext::~CParserContext()
      72                 : {
      73                 :   // It's ok to simply ingore the PrevContext.
      74            3344 :   MOZ_COUNT_DTOR(CParserContext);
      75            3344 : }
      76                 : 
      77                 : void
      78            3342 : CParserContext::SetMimeType(const nsACString& aMimeType)
      79                 : {
      80            3342 :   mMimeType.Assign(aMimeType);
      81                 : 
      82            3342 :   mDocType = ePlainText;
      83                 : 
      84            3342 :   if (mMimeType.EqualsLiteral(TEXT_HTML))
      85              28 :     mDocType = eHTML_Strict;
      86            4913 :   else if (mMimeType.EqualsLiteral(TEXT_XML)              ||
      87             331 :            mMimeType.EqualsLiteral(APPLICATION_XML)       ||
      88             213 :            mMimeType.EqualsLiteral(APPLICATION_XHTML_XML) ||
      89             213 :            mMimeType.EqualsLiteral(TEXT_XUL)              ||
      90             213 :            mMimeType.EqualsLiteral(IMAGE_SVG_XML)         ||
      91             213 :            mMimeType.EqualsLiteral(APPLICATION_MATHML_XML) ||
      92             213 :            mMimeType.EqualsLiteral(APPLICATION_RDF_XML)   ||
      93             203 :            mMimeType.EqualsLiteral(TEXT_RDF))
      94            3111 :     mDocType = eXML;
      95            3342 : }
      96                 : 
      97                 : nsresult
      98           30370 : CParserContext::GetTokenizer(nsIDTD* aDTD,
      99                 :                              nsIContentSink* aSink,
     100                 :                              nsITokenizer*& aTokenizer)
     101                 : {
     102           30370 :   nsresult result = NS_OK;
     103           30370 :   PRInt32 type = aDTD ? aDTD->GetType() : NS_IPARSER_FLAG_HTML;
     104                 : 
     105           30370 :   if (!mTokenizer) {
     106            3342 :     if (type == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) {
     107              56 :       nsCOMPtr<nsIHTMLContentSink> theSink = do_QueryInterface(aSink);
     108                 :       mTokenizer = new nsHTMLTokenizer(mDTDMode, mDocType, mParserCommand,
     109              56 :                                        nsHTMLTokenizer::GetFlags(aSink));
     110              28 :       if (!mTokenizer) {
     111               0 :         return NS_ERROR_OUT_OF_MEMORY;
     112                 :       }
     113                 : 
     114                 :       // Make sure the new tokenizer has all of the necessary information.
     115                 :       // XXX this might not be necessary.
     116              28 :       if (mPrevContext) {
     117               0 :         mTokenizer->CopyState(mPrevContext->mTokenizer);
     118              28 :       }
     119                 :     }
     120            3314 :     else if (type == NS_IPARSER_FLAG_XML) {
     121            3314 :       mTokenizer = do_QueryInterface(aDTD, &result);
     122                 :     }
     123                 :   }
     124                 : 
     125           30370 :   aTokenizer = mTokenizer;
     126                 : 
     127           30370 :   return result;
     128                 : }

Generated by: LCOV version 1.7