LCOV - code coverage report
Current view: directory - objdir/dist/include - nsIParser.h (source / functions) Found Hit Coverage
Test: app.info Lines: 2 1 50.0 %
Date: 2012-06-02 Functions: 2 1 50.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* vim: set ts=2 sw=2 et tw=78: */
       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                 : #ifndef NS_IPARSER___
      39                 : #define NS_IPARSER___
      40                 : 
      41                 : 
      42                 : /**
      43                 :  * MODULE NOTES:
      44                 :  *  
      45                 :  *  This class defines the iparser interface. This XPCOM
      46                 :  *  inteface is all that parser clients ever need to see.
      47                 :  *
      48                 :  **/
      49                 : 
      50                 : #include "nsISupports.h"
      51                 : #include "nsIStreamListener.h"
      52                 : #include "nsIDTD.h"
      53                 : #include "nsStringGlue.h"
      54                 : #include "nsTArray.h"
      55                 : #include "nsIAtom.h"
      56                 : #include "nsParserBase.h"
      57                 : 
      58                 : #define NS_IPARSER_IID \
      59                 : { 0xd064f0d6, 0x44e3, 0x4366, \
      60                 :   { 0xa7, 0x05, 0xcf, 0x7a, 0x91, 0x26, 0x14, 0xb6 } }
      61                 : 
      62                 : // {41421C60-310A-11d4-816F-000064657374}
      63                 : #define NS_IDEBUG_DUMP_CONTENT_IID \
      64                 : { 0x41421c60, 0x310a, 0x11d4, \
      65                 : { 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
      66                 : 
      67                 : class nsIContentSink;
      68                 : class nsIRequestObserver;
      69                 : class nsString;
      70                 : class nsIURI;
      71                 : class nsIChannel;
      72                 : class nsIContent;
      73                 : 
      74                 : enum eParserCommands {
      75                 :   eViewNormal,
      76                 :   eViewSource,
      77                 :   eViewFragment,
      78                 :   eViewErrors
      79                 : };
      80                 : 
      81                 : enum eParserDocType {
      82                 :   ePlainText = 0,
      83                 :   eXML,
      84                 :   eHTML_Quirks,
      85                 :   eHTML_Strict
      86                 : };
      87                 : 
      88                 : 
      89                 : // define Charset source constants
      90                 : // note: the value order defines the priority; higher numbers take priority
      91                 : #define kCharsetUninitialized           0
      92                 : #define kCharsetFromWeakDocTypeDefault  1
      93                 : #define kCharsetFromUserDefault         2
      94                 : #define kCharsetFromDocTypeDefault      3 // This and up confident for XHR
      95                 : #define kCharsetFromCache               4
      96                 : #define kCharsetFromParentFrame         5
      97                 : #define kCharsetFromAutoDetection       6
      98                 : #define kCharsetFromHintPrevDoc         7
      99                 : #define kCharsetFromMetaPrescan         8 // this one and smaller: HTML5 Tentative
     100                 : #define kCharsetFromMetaTag             9 // this one and greater: HTML5 Confident
     101                 : #define kCharsetFromIrreversibleAutoDetection 10
     102                 : #define kCharsetFromByteOrderMark      11
     103                 : #define kCharsetFromChannel            12
     104                 : #define kCharsetFromOtherComponent     13
     105                 : // Levels below here will be forced onto childframes too
     106                 : #define kCharsetFromParentForced       14
     107                 : #define kCharsetFromUserForced         15
     108                 : #define kCharsetFromPreviousLoading    16
     109                 : 
     110                 : enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
     111                 : 
     112                 : /** 
     113                 :  *  FOR DEBUG PURPOSE ONLY
     114                 :  *
     115                 :  *  Use this interface to query objects that contain content information.
     116                 :  *  Ex. Parser can trigger dump content by querying the sink that has
     117                 :  *      access to the content.
     118                 :  *  
     119                 :  *  @update  harishd 05/25/00
     120                 :  */
     121               0 : class nsIDebugDumpContent : public nsISupports {
     122                 : public:
     123                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEBUG_DUMP_CONTENT_IID)
     124                 :   NS_IMETHOD DumpContentModel()=0;
     125                 : };
     126                 : 
     127                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIDebugDumpContent, NS_IDEBUG_DUMP_CONTENT_IID)
     128                 : 
     129                 : /**
     130                 :  *  This class defines the iparser interface. This XPCOM
     131                 :  *  inteface is all that parser clients ever need to see.
     132                 :  */
     133            3345 : class nsIParser : public nsParserBase {
     134                 :   public:
     135                 : 
     136                 :     NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
     137                 : 
     138                 :     /**
     139                 :      * Select given content sink into parser for parser output
     140                 :      * @update  gess5/11/98
     141                 :      * @param   aSink is the new sink to be used by parser
     142                 :      * @return  
     143                 :      */
     144                 :     NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
     145                 : 
     146                 : 
     147                 :     /**
     148                 :      * retrieve the sink set into the parser 
     149                 :      * @update  gess5/11/98
     150                 :      * @return  current sink
     151                 :      */
     152                 :     NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
     153                 : 
     154                 :     /**
     155                 :      *  Call this method once you've created a parser, and want to instruct it
     156                 :            *  about the command which caused the parser to be constructed. For example,
     157                 :      *  this allows us to select a DTD which can do, say, view-source.
     158                 :      *  
     159                 :      *  @update  gess 3/25/98
     160                 :      *  @param   aCommand -- ptrs to string that contains command
     161                 :      *  @return  nada
     162                 :      */
     163                 :     NS_IMETHOD_(void) GetCommand(nsCString& aCommand)=0;
     164                 :     NS_IMETHOD_(void) SetCommand(const char* aCommand)=0;
     165                 :     NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0;
     166                 : 
     167                 :     /**
     168                 :      *  Call this method once you've created a parser, and want to instruct it
     169                 :      *  about what charset to load
     170                 :      *  
     171                 :      *  @update  ftang 4/23/99
     172                 :      *  @param   aCharset- the charest of a document
     173                 :      *  @param   aCharsetSource- the soure of the chares
     174                 :      *  @return  nada
     175                 :      */
     176                 :     NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource)=0;
     177                 :     NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, PRInt32& oSource)=0;
     178                 : 
     179                 :     /** 
     180                 :      * Get the channel associated with this parser
     181                 :      * @update harishd,gagan 07/17/01
     182                 :      * @param aChannel out param that will contain the result
     183                 :      * @return NS_OK if successful
     184                 :      */
     185                 :     NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0;
     186                 : 
     187                 :     /** 
     188                 :      * Get the DTD associated with this parser
     189                 :      * @update vidur 9/29/99
     190                 :      * @param aDTD out param that will contain the result
     191                 :      * @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
     192                 :      */
     193                 :     NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;
     194                 :     
     195                 :     /**
     196                 :      * Get the nsIStreamListener for this parser
     197                 :      */
     198                 :     virtual nsIStreamListener* GetStreamListener() = 0;
     199                 : 
     200                 :     /**************************************************************************
     201                 :      *  Parse methods always begin with an input source, and perform
     202                 :      *  conversions until you wind up being emitted to the given contentsink
     203                 :      *  (which may or may not be a proxy for the NGLayout content model).
     204                 :      ************************************************************************/
     205                 :     
     206                 :     // Call this method to resume the parser from an unblocked state.
     207                 :     // This can happen, for example, if parsing was interrupted and then the
     208                 :     // consumer needed to restart the parser without waiting for more data.
     209                 :     // This also happens after loading scripts, which unblock the parser in
     210                 :     // order to process the output of document.write() and then need to
     211                 :     // continue on with the page load on an enabled parser.
     212                 :     NS_IMETHOD ContinueInterruptedParsing() = 0;
     213                 :     
     214                 :     // Stops parsing temporarily.
     215                 :     NS_IMETHOD_(void) BlockParser() = 0;
     216                 :     
     217                 :     // Open up the parser for tokenization, building up content 
     218                 :     // model..etc. However, this method does not resume parsing 
     219                 :     // automatically. It's the callers' responsibility to restart
     220                 :     // the parsing engine.
     221                 :     NS_IMETHOD_(void) UnblockParser() = 0;
     222                 : 
     223                 :     /**
     224                 :      * Asynchronously continues parsing.
     225                 :      */
     226                 :     NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0;
     227                 : 
     228                 :     NS_IMETHOD_(bool) IsParserEnabled() = 0;
     229                 :     NS_IMETHOD_(bool) IsComplete() = 0;
     230                 :     
     231                 :     NS_IMETHOD Parse(nsIURI* aURL,
     232                 :                      nsIRequestObserver* aListener = nsnull,
     233                 :                      void* aKey = 0,
     234                 :                      nsDTDMode aMode = eDTDMode_autodetect) = 0;
     235                 :     NS_IMETHOD Parse(const nsAString& aSourceBuffer,
     236                 :                      void* aKey,
     237                 :                      const nsACString& aMimeType,
     238                 :                      bool aLastCall,
     239                 :                      nsDTDMode aMode = eDTDMode_autodetect) = 0;
     240                 : 
     241                 :     NS_IMETHOD Terminate(void) = 0;
     242                 : 
     243                 :     /**
     244                 :      * This method gets called when you want to parse a fragment of HTML or XML
     245                 :      * surrounded by the context |aTagStack|. It requires that the parser have
     246                 :      * been given a fragment content sink.
     247                 :      *
     248                 :      * @param aSourceBuffer The XML or HTML that hasn't been parsed yet.
     249                 :      * @param aTagStack The context of the source buffer.
     250                 :      * @return Success or failure.
     251                 :      */
     252                 :     NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
     253                 :                              nsTArray<nsString>& aTagStack) = 0;
     254                 : 
     255                 :     /**
     256                 :      * This method gets called when the tokens have been consumed, and it's time
     257                 :      * to build the model via the content sink.
     258                 :      * @update  gess5/11/98
     259                 :      * @return  error code -- 0 if model building went well .
     260                 :      */
     261                 :     NS_IMETHOD BuildModel(void) = 0;
     262                 : 
     263                 :     /**
     264                 :      *  Call this method to cancel any pending parsing events.
     265                 :      *  Parsing events may be pending if all of the document's content
     266                 :      *  has been passed to the parser but the parser has been interrupted
     267                 :      *  because processing the tokens took too long.
     268                 :      *  
     269                 :      *  @update  kmcclusk 05/18/01
     270                 :      *  @return  NS_OK if succeeded else ERROR.
     271                 :      */
     272                 : 
     273                 :     NS_IMETHOD CancelParsingEvents() = 0;
     274                 : 
     275                 :     virtual void Reset() = 0;
     276                 : 
     277                 :     /**
     278                 :      * True if the insertion point (per HTML5) is defined.
     279                 :      */
     280                 :     virtual bool IsInsertionPointDefined() = 0;
     281                 : 
     282                 :     /**
     283                 :      * Call immediately before starting to evaluate a parser-inserted script.
     284                 :      */
     285                 :     virtual void BeginEvaluatingParserInsertedScript() = 0;
     286                 : 
     287                 :     /**
     288                 :      * Call immediately after having evaluated a parser-inserted script.
     289                 :      */
     290                 :     virtual void EndEvaluatingParserInsertedScript() = 0;
     291                 : 
     292                 :     /**
     293                 :      * Marks the HTML5 parser as not a script-created parser.
     294                 :      */
     295                 :     virtual void MarkAsNotScriptCreated(const char* aCommand) = 0;
     296                 : 
     297                 :     /**
     298                 :      * True if this is a script-created HTML5 parser.
     299                 :      */
     300                 :     virtual bool IsScriptCreated() = 0;
     301                 : };
     302                 : 
     303                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)
     304                 : 
     305                 : /* ===========================================================*
     306                 :   Some useful constants...
     307                 :  * ===========================================================*/
     308                 : 
     309                 : #include "prtypes.h"
     310                 : #include "nsError.h"
     311                 : 
     312                 : #define NS_ERROR_HTMLPARSER_EOF                            NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1000)
     313                 : #define NS_ERROR_HTMLPARSER_UNKNOWN                        NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1001)
     314                 : #define NS_ERROR_HTMLPARSER_CANTPROPAGATE                  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1002)
     315                 : #define NS_ERROR_HTMLPARSER_CONTEXTMISMATCH                NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1003)
     316                 : #define NS_ERROR_HTMLPARSER_BADFILENAME                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1004)
     317                 : #define NS_ERROR_HTMLPARSER_BADURL                         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1005)
     318                 : #define NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT           NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1006)
     319                 : #define NS_ERROR_HTMLPARSER_INTERRUPTED                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
     320                 : #define NS_ERROR_HTMLPARSER_BLOCK                          NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
     321                 : #define NS_ERROR_HTMLPARSER_BADTOKENIZER                   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009)
     322                 : #define NS_ERROR_HTMLPARSER_BADATTRIBUTE                   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010)
     323                 : #define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD                  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1011)
     324                 : #define NS_ERROR_HTMLPARSER_MISPLACEDTABLECONTENT          NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1012)
     325                 : #define NS_ERROR_HTMLPARSER_BADDTD                         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1013)
     326                 : #define NS_ERROR_HTMLPARSER_BADCONTEXT                     NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1014)
     327                 : #define NS_ERROR_HTMLPARSER_STOPPARSING                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1015)
     328                 : #define NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL      NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1016)
     329                 : #define NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP               NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1017)
     330                 : #define NS_ERROR_HTMLPARSER_FAKE_ENDTAG                    NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1018)
     331                 : #define NS_ERROR_HTMLPARSER_INVALID_COMMENT                NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1019)
     332                 : 
     333                 : #define NS_ERROR_HTMLPARSER_CONTINUE              NS_OK
     334                 : 
     335                 : 
     336                 : const PRUint32  kEOF              = NS_ERROR_HTMLPARSER_EOF;
     337                 : const PRUint32  kUnknownError     = NS_ERROR_HTMLPARSER_UNKNOWN;
     338                 : const PRUint32  kCantPropagate    = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
     339                 : const PRUint32  kContextMismatch  = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
     340                 : const PRUint32  kBadFilename      = NS_ERROR_HTMLPARSER_BADFILENAME;
     341                 : const PRUint32  kBadURL           = NS_ERROR_HTMLPARSER_BADURL;
     342                 : const PRUint32  kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
     343                 : const PRUint32  kBlocked          = NS_ERROR_HTMLPARSER_BLOCK;
     344                 : const PRUint32  kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
     345                 : const PRUint32  kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
     346                 : const PRUint32  kFakeEndTag       = NS_ERROR_HTMLPARSER_FAKE_ENDTAG;
     347                 : const PRUint32  kNotAComment      = NS_ERROR_HTMLPARSER_INVALID_COMMENT;
     348                 : 
     349                 : #define NS_IPARSER_FLAG_UNKNOWN_MODE         0x00000000
     350                 : #define NS_IPARSER_FLAG_QUIRKS_MODE          0x00000002
     351                 : #define NS_IPARSER_FLAG_STRICT_MODE          0x00000004
     352                 : #define NS_IPARSER_FLAG_AUTO_DETECT_MODE     0x00000010
     353                 : #define NS_IPARSER_FLAG_VIEW_NORMAL          0x00000020
     354                 : #define NS_IPARSER_FLAG_VIEW_SOURCE          0x00000040
     355                 : #define NS_IPARSER_FLAG_VIEW_ERRORS          0x00000080
     356                 : #define NS_IPARSER_FLAG_PLAIN_TEXT           0x00000100
     357                 : #define NS_IPARSER_FLAG_XML                  0x00000200
     358                 : #define NS_IPARSER_FLAG_HTML                 0x00000400
     359                 : #define NS_IPARSER_FLAG_SCRIPT_ENABLED       0x00000800
     360                 : #define NS_IPARSER_FLAG_FRAMES_ENABLED       0x00001000
     361                 : 
     362                 : #endif 

Generated by: LCOV version 1.7