parser/htmlparser/public/nsIParser.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef NS_IPARSER___
     7 #define NS_IPARSER___
    10  /**
    11  * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
    12  * to the point of being near-unrecognizable).
    13  *
    14  * Please DO NOT #include this file in comm-central code, in your XULRunner
    15  * app or binary extensions.
    16  *
    17  * Please DO NOT #include this into new files even inside Gecko. It is more
    18  * likely than not that #including this header is the wrong thing to do.
    19  */
    21 #include "nsISupports.h"
    22 #include "nsIStreamListener.h"
    23 #include "nsIDTD.h"
    24 #include "nsString.h"
    25 #include "nsTArray.h"
    26 #include "nsIAtom.h"
    27 #include "nsParserBase.h"
    29 #define NS_IPARSER_IID \
    30 { 0x2c4ad90a, 0x740e, 0x4212, \
    31   { 0xba, 0x3f, 0xfe, 0xac, 0xda, 0x4b, 0x92, 0x9e } }
    33 // {41421C60-310A-11d4-816F-000064657374}
    34 #define NS_IDEBUG_DUMP_CONTENT_IID \
    35 { 0x41421c60, 0x310a, 0x11d4, \
    36 { 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
    38 class nsIContentSink;
    39 class nsIRequestObserver;
    40 class nsString;
    41 class nsIURI;
    42 class nsIChannel;
    43 class nsIContent;
    45 enum eParserCommands {
    46   eViewNormal,
    47   eViewSource,
    48   eViewFragment,
    49   eViewErrors
    50 };
    52 enum eParserDocType {
    53   ePlainText = 0,
    54   eXML,
    55   eHTML_Quirks,
    56   eHTML_Strict
    57 };
    59 enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
    61 /**
    62  * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
    63  * to the point of being near-unrecognizable).
    64  *
    65  * Please DO NOT #include this file in comm-central code, in your XULRunner
    66  * app or binary extensions.
    67  *
    68  * Please DO NOT #include this into new files even inside Gecko. It is more
    69  * likely than not that #including this header is the wrong thing to do.
    70  */
    71 class nsIParser : public nsParserBase {
    72   public:
    74     NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
    76     /**
    77      * Select given content sink into parser for parser output
    78      * @update	gess5/11/98
    79      * @param   aSink is the new sink to be used by parser
    80      * @return  
    81      */
    82     NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
    85     /**
    86      * retrieve the sink set into the parser 
    87      * @update	gess5/11/98
    88      * @return  current sink
    89      */
    90     NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
    92     /**
    93      *  Call this method once you've created a parser, and want to instruct it
    94 	   *  about the command which caused the parser to be constructed. For example,
    95      *  this allows us to select a DTD which can do, say, view-source.
    96      *  
    97      *  @update  gess 3/25/98
    98      *  @param   aCommand -- ptrs to string that contains command
    99      *  @return	 nada
   100      */
   101     NS_IMETHOD_(void) GetCommand(nsCString& aCommand)=0;
   102     NS_IMETHOD_(void) SetCommand(const char* aCommand)=0;
   103     NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0;
   105     /**
   106      *  Call this method once you've created a parser, and want to instruct it
   107      *  about what charset to load
   108      *  
   109      *  @update  ftang 4/23/99
   110      *  @param   aCharset- the charest of a document
   111      *  @param   aCharsetSource- the soure of the chares
   112      *  @return	 nada
   113      */
   114     NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, int32_t aSource)=0;
   115     NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, int32_t& oSource)=0;
   117     /** 
   118      * Get the channel associated with this parser
   119      * @update harishd,gagan 07/17/01
   120      * @param aChannel out param that will contain the result
   121      * @return NS_OK if successful
   122      */
   123     NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0;
   125     /** 
   126      * Get the DTD associated with this parser
   127      * @update vidur 9/29/99
   128      * @param aDTD out param that will contain the result
   129      * @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
   130      */
   131     NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;
   133     /**
   134      * Get the nsIStreamListener for this parser
   135      */
   136     virtual nsIStreamListener* GetStreamListener() = 0;
   138     /**************************************************************************
   139      *  Parse methods always begin with an input source, and perform
   140      *  conversions until you wind up being emitted to the given contentsink
   141      *  (which may or may not be a proxy for the NGLayout content model).
   142      ************************************************************************/
   144     // Call this method to resume the parser from an unblocked state.
   145     // This can happen, for example, if parsing was interrupted and then the
   146     // consumer needed to restart the parser without waiting for more data.
   147     // This also happens after loading scripts, which unblock the parser in
   148     // order to process the output of document.write() and then need to
   149     // continue on with the page load on an enabled parser.
   150     NS_IMETHOD ContinueInterruptedParsing() = 0;
   152     // Stops parsing temporarily.
   153     NS_IMETHOD_(void) BlockParser() = 0;
   155     // Open up the parser for tokenization, building up content 
   156     // model..etc. However, this method does not resume parsing 
   157     // automatically. It's the callers' responsibility to restart
   158     // the parsing engine.
   159     NS_IMETHOD_(void) UnblockParser() = 0;
   161     /**
   162      * Asynchronously continues parsing.
   163      */
   164     NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0;
   166     NS_IMETHOD_(bool) IsParserEnabled() = 0;
   167     NS_IMETHOD_(bool) IsComplete() = 0;
   169     NS_IMETHOD Parse(nsIURI* aURL,
   170                      nsIRequestObserver* aListener = nullptr,
   171                      void* aKey = 0,
   172                      nsDTDMode aMode = eDTDMode_autodetect) = 0;
   174     NS_IMETHOD Terminate(void) = 0;
   176     /**
   177      * This method gets called when you want to parse a fragment of HTML or XML
   178      * surrounded by the context |aTagStack|. It requires that the parser have
   179      * been given a fragment content sink.
   180      *
   181      * @param aSourceBuffer The XML or HTML that hasn't been parsed yet.
   182      * @param aTagStack The context of the source buffer.
   183      * @return Success or failure.
   184      */
   185     NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
   186                              nsTArray<nsString>& aTagStack) = 0;
   188     /**
   189      * This method gets called when the tokens have been consumed, and it's time
   190      * to build the model via the content sink.
   191      * @update	gess5/11/98
   192      * @return  error code -- 0 if model building went well .
   193      */
   194     NS_IMETHOD BuildModel(void) = 0;
   196     /**
   197      *  Call this method to cancel any pending parsing events.
   198      *  Parsing events may be pending if all of the document's content
   199      *  has been passed to the parser but the parser has been interrupted
   200      *  because processing the tokens took too long.
   201      *  
   202      *  @update  kmcclusk 05/18/01
   203      *  @return  NS_OK if succeeded else ERROR.
   204      */
   206     NS_IMETHOD CancelParsingEvents() = 0;
   208     virtual void Reset() = 0;
   210     /**
   211      * True if the insertion point (per HTML5) is defined.
   212      */
   213     virtual bool IsInsertionPointDefined() = 0;
   215     /**
   216      * Call immediately before starting to evaluate a parser-inserted script.
   217      */
   218     virtual void BeginEvaluatingParserInsertedScript() = 0;
   220     /**
   221      * Call immediately after having evaluated a parser-inserted script.
   222      */
   223     virtual void EndEvaluatingParserInsertedScript() = 0;
   225     /**
   226      * Marks the HTML5 parser as not a script-created parser.
   227      */
   228     virtual void MarkAsNotScriptCreated(const char* aCommand) = 0;
   230     /**
   231      * True if this is a script-created HTML5 parser.
   232      */
   233     virtual bool IsScriptCreated() = 0;
   234 };
   236 NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)
   238 /* ===========================================================*
   239   Some useful constants...
   240  * ===========================================================*/
   242 #include "nsError.h"
   244 const nsresult  kEOF              = NS_ERROR_HTMLPARSER_EOF;
   245 const nsresult  kUnknownError     = NS_ERROR_HTMLPARSER_UNKNOWN;
   246 const nsresult  kCantPropagate    = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
   247 const nsresult  kContextMismatch  = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
   248 const nsresult  kBadFilename      = NS_ERROR_HTMLPARSER_BADFILENAME;
   249 const nsresult  kBadURL           = NS_ERROR_HTMLPARSER_BADURL;
   250 const nsresult  kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
   251 const nsresult  kBlocked          = NS_ERROR_HTMLPARSER_BLOCK;
   252 const nsresult  kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
   253 const nsresult  kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
   254 const nsresult  kFakeEndTag       = NS_ERROR_HTMLPARSER_FAKE_ENDTAG;
   255 const nsresult  kNotAComment      = NS_ERROR_HTMLPARSER_INVALID_COMMENT;
   257 #define NS_IPARSER_FLAG_UNKNOWN_MODE         0x00000000
   258 #define NS_IPARSER_FLAG_QUIRKS_MODE          0x00000002
   259 #define NS_IPARSER_FLAG_STRICT_MODE          0x00000004
   260 #define NS_IPARSER_FLAG_AUTO_DETECT_MODE     0x00000010
   261 #define NS_IPARSER_FLAG_VIEW_NORMAL          0x00000020
   262 #define NS_IPARSER_FLAG_VIEW_SOURCE          0x00000040
   263 #define NS_IPARSER_FLAG_VIEW_ERRORS          0x00000080
   264 #define NS_IPARSER_FLAG_PLAIN_TEXT           0x00000100
   265 #define NS_IPARSER_FLAG_XML                  0x00000200
   266 #define NS_IPARSER_FLAG_HTML                 0x00000400
   267 #define NS_IPARSER_FLAG_SCRIPT_ENABLED       0x00000800
   268 #define NS_IPARSER_FLAG_FRAMES_ENABLED       0x00001000
   270 #endif 

mercurial