parser/htmlparser/public/nsIParser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/htmlparser/public/nsIParser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,270 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim: set ts=2 sw=2 et tw=78: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +#ifndef NS_IPARSER___
    1.10 +#define NS_IPARSER___
    1.11 +
    1.12 +
    1.13 + /**
    1.14 + * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
    1.15 + * to the point of being near-unrecognizable).
    1.16 + *
    1.17 + * Please DO NOT #include this file in comm-central code, in your XULRunner
    1.18 + * app or binary extensions.
    1.19 + *
    1.20 + * Please DO NOT #include this into new files even inside Gecko. It is more
    1.21 + * likely than not that #including this header is the wrong thing to do.
    1.22 + */
    1.23 +
    1.24 +#include "nsISupports.h"
    1.25 +#include "nsIStreamListener.h"
    1.26 +#include "nsIDTD.h"
    1.27 +#include "nsString.h"
    1.28 +#include "nsTArray.h"
    1.29 +#include "nsIAtom.h"
    1.30 +#include "nsParserBase.h"
    1.31 +
    1.32 +#define NS_IPARSER_IID \
    1.33 +{ 0x2c4ad90a, 0x740e, 0x4212, \
    1.34 +  { 0xba, 0x3f, 0xfe, 0xac, 0xda, 0x4b, 0x92, 0x9e } }
    1.35 +
    1.36 +// {41421C60-310A-11d4-816F-000064657374}
    1.37 +#define NS_IDEBUG_DUMP_CONTENT_IID \
    1.38 +{ 0x41421c60, 0x310a, 0x11d4, \
    1.39 +{ 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
    1.40 +
    1.41 +class nsIContentSink;
    1.42 +class nsIRequestObserver;
    1.43 +class nsString;
    1.44 +class nsIURI;
    1.45 +class nsIChannel;
    1.46 +class nsIContent;
    1.47 +
    1.48 +enum eParserCommands {
    1.49 +  eViewNormal,
    1.50 +  eViewSource,
    1.51 +  eViewFragment,
    1.52 +  eViewErrors
    1.53 +};
    1.54 +
    1.55 +enum eParserDocType {
    1.56 +  ePlainText = 0,
    1.57 +  eXML,
    1.58 +  eHTML_Quirks,
    1.59 +  eHTML_Strict
    1.60 +};
    1.61 +
    1.62 +enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
    1.63 +
    1.64 +/**
    1.65 + * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
    1.66 + * to the point of being near-unrecognizable).
    1.67 + *
    1.68 + * Please DO NOT #include this file in comm-central code, in your XULRunner
    1.69 + * app or binary extensions.
    1.70 + *
    1.71 + * Please DO NOT #include this into new files even inside Gecko. It is more
    1.72 + * likely than not that #including this header is the wrong thing to do.
    1.73 + */
    1.74 +class nsIParser : public nsParserBase {
    1.75 +  public:
    1.76 +
    1.77 +    NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
    1.78 +
    1.79 +    /**
    1.80 +     * Select given content sink into parser for parser output
    1.81 +     * @update	gess5/11/98
    1.82 +     * @param   aSink is the new sink to be used by parser
    1.83 +     * @return  
    1.84 +     */
    1.85 +    NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
    1.86 +
    1.87 +
    1.88 +    /**
    1.89 +     * retrieve the sink set into the parser 
    1.90 +     * @update	gess5/11/98
    1.91 +     * @return  current sink
    1.92 +     */
    1.93 +    NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
    1.94 +
    1.95 +    /**
    1.96 +     *  Call this method once you've created a parser, and want to instruct it
    1.97 +	   *  about the command which caused the parser to be constructed. For example,
    1.98 +     *  this allows us to select a DTD which can do, say, view-source.
    1.99 +     *  
   1.100 +     *  @update  gess 3/25/98
   1.101 +     *  @param   aCommand -- ptrs to string that contains command
   1.102 +     *  @return	 nada
   1.103 +     */
   1.104 +    NS_IMETHOD_(void) GetCommand(nsCString& aCommand)=0;
   1.105 +    NS_IMETHOD_(void) SetCommand(const char* aCommand)=0;
   1.106 +    NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0;
   1.107 +
   1.108 +    /**
   1.109 +     *  Call this method once you've created a parser, and want to instruct it
   1.110 +     *  about what charset to load
   1.111 +     *  
   1.112 +     *  @update  ftang 4/23/99
   1.113 +     *  @param   aCharset- the charest of a document
   1.114 +     *  @param   aCharsetSource- the soure of the chares
   1.115 +     *  @return	 nada
   1.116 +     */
   1.117 +    NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, int32_t aSource)=0;
   1.118 +    NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, int32_t& oSource)=0;
   1.119 +
   1.120 +    /** 
   1.121 +     * Get the channel associated with this parser
   1.122 +     * @update harishd,gagan 07/17/01
   1.123 +     * @param aChannel out param that will contain the result
   1.124 +     * @return NS_OK if successful
   1.125 +     */
   1.126 +    NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0;
   1.127 +
   1.128 +    /** 
   1.129 +     * Get the DTD associated with this parser
   1.130 +     * @update vidur 9/29/99
   1.131 +     * @param aDTD out param that will contain the result
   1.132 +     * @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
   1.133 +     */
   1.134 +    NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;
   1.135 +    
   1.136 +    /**
   1.137 +     * Get the nsIStreamListener for this parser
   1.138 +     */
   1.139 +    virtual nsIStreamListener* GetStreamListener() = 0;
   1.140 +
   1.141 +    /**************************************************************************
   1.142 +     *  Parse methods always begin with an input source, and perform
   1.143 +     *  conversions until you wind up being emitted to the given contentsink
   1.144 +     *  (which may or may not be a proxy for the NGLayout content model).
   1.145 +     ************************************************************************/
   1.146 +    
   1.147 +    // Call this method to resume the parser from an unblocked state.
   1.148 +    // This can happen, for example, if parsing was interrupted and then the
   1.149 +    // consumer needed to restart the parser without waiting for more data.
   1.150 +    // This also happens after loading scripts, which unblock the parser in
   1.151 +    // order to process the output of document.write() and then need to
   1.152 +    // continue on with the page load on an enabled parser.
   1.153 +    NS_IMETHOD ContinueInterruptedParsing() = 0;
   1.154 +    
   1.155 +    // Stops parsing temporarily.
   1.156 +    NS_IMETHOD_(void) BlockParser() = 0;
   1.157 +    
   1.158 +    // Open up the parser for tokenization, building up content 
   1.159 +    // model..etc. However, this method does not resume parsing 
   1.160 +    // automatically. It's the callers' responsibility to restart
   1.161 +    // the parsing engine.
   1.162 +    NS_IMETHOD_(void) UnblockParser() = 0;
   1.163 +
   1.164 +    /**
   1.165 +     * Asynchronously continues parsing.
   1.166 +     */
   1.167 +    NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0;
   1.168 +
   1.169 +    NS_IMETHOD_(bool) IsParserEnabled() = 0;
   1.170 +    NS_IMETHOD_(bool) IsComplete() = 0;
   1.171 +    
   1.172 +    NS_IMETHOD Parse(nsIURI* aURL,
   1.173 +                     nsIRequestObserver* aListener = nullptr,
   1.174 +                     void* aKey = 0,
   1.175 +                     nsDTDMode aMode = eDTDMode_autodetect) = 0;
   1.176 +
   1.177 +    NS_IMETHOD Terminate(void) = 0;
   1.178 +
   1.179 +    /**
   1.180 +     * This method gets called when you want to parse a fragment of HTML or XML
   1.181 +     * surrounded by the context |aTagStack|. It requires that the parser have
   1.182 +     * been given a fragment content sink.
   1.183 +     *
   1.184 +     * @param aSourceBuffer The XML or HTML that hasn't been parsed yet.
   1.185 +     * @param aTagStack The context of the source buffer.
   1.186 +     * @return Success or failure.
   1.187 +     */
   1.188 +    NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
   1.189 +                             nsTArray<nsString>& aTagStack) = 0;
   1.190 +
   1.191 +    /**
   1.192 +     * This method gets called when the tokens have been consumed, and it's time
   1.193 +     * to build the model via the content sink.
   1.194 +     * @update	gess5/11/98
   1.195 +     * @return  error code -- 0 if model building went well .
   1.196 +     */
   1.197 +    NS_IMETHOD BuildModel(void) = 0;
   1.198 +
   1.199 +    /**
   1.200 +     *  Call this method to cancel any pending parsing events.
   1.201 +     *  Parsing events may be pending if all of the document's content
   1.202 +     *  has been passed to the parser but the parser has been interrupted
   1.203 +     *  because processing the tokens took too long.
   1.204 +     *  
   1.205 +     *  @update  kmcclusk 05/18/01
   1.206 +     *  @return  NS_OK if succeeded else ERROR.
   1.207 +     */
   1.208 +
   1.209 +    NS_IMETHOD CancelParsingEvents() = 0;
   1.210 +
   1.211 +    virtual void Reset() = 0;
   1.212 +
   1.213 +    /**
   1.214 +     * True if the insertion point (per HTML5) is defined.
   1.215 +     */
   1.216 +    virtual bool IsInsertionPointDefined() = 0;
   1.217 +
   1.218 +    /**
   1.219 +     * Call immediately before starting to evaluate a parser-inserted script.
   1.220 +     */
   1.221 +    virtual void BeginEvaluatingParserInsertedScript() = 0;
   1.222 +
   1.223 +    /**
   1.224 +     * Call immediately after having evaluated a parser-inserted script.
   1.225 +     */
   1.226 +    virtual void EndEvaluatingParserInsertedScript() = 0;
   1.227 +
   1.228 +    /**
   1.229 +     * Marks the HTML5 parser as not a script-created parser.
   1.230 +     */
   1.231 +    virtual void MarkAsNotScriptCreated(const char* aCommand) = 0;
   1.232 +
   1.233 +    /**
   1.234 +     * True if this is a script-created HTML5 parser.
   1.235 +     */
   1.236 +    virtual bool IsScriptCreated() = 0;
   1.237 +};
   1.238 +
   1.239 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)
   1.240 +
   1.241 +/* ===========================================================*
   1.242 +  Some useful constants...
   1.243 + * ===========================================================*/
   1.244 +
   1.245 +#include "nsError.h"
   1.246 +
   1.247 +const nsresult  kEOF              = NS_ERROR_HTMLPARSER_EOF;
   1.248 +const nsresult  kUnknownError     = NS_ERROR_HTMLPARSER_UNKNOWN;
   1.249 +const nsresult  kCantPropagate    = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
   1.250 +const nsresult  kContextMismatch  = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
   1.251 +const nsresult  kBadFilename      = NS_ERROR_HTMLPARSER_BADFILENAME;
   1.252 +const nsresult  kBadURL           = NS_ERROR_HTMLPARSER_BADURL;
   1.253 +const nsresult  kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
   1.254 +const nsresult  kBlocked          = NS_ERROR_HTMLPARSER_BLOCK;
   1.255 +const nsresult  kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
   1.256 +const nsresult  kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
   1.257 +const nsresult  kFakeEndTag       = NS_ERROR_HTMLPARSER_FAKE_ENDTAG;
   1.258 +const nsresult  kNotAComment      = NS_ERROR_HTMLPARSER_INVALID_COMMENT;
   1.259 +
   1.260 +#define NS_IPARSER_FLAG_UNKNOWN_MODE         0x00000000
   1.261 +#define NS_IPARSER_FLAG_QUIRKS_MODE          0x00000002
   1.262 +#define NS_IPARSER_FLAG_STRICT_MODE          0x00000004
   1.263 +#define NS_IPARSER_FLAG_AUTO_DETECT_MODE     0x00000010
   1.264 +#define NS_IPARSER_FLAG_VIEW_NORMAL          0x00000020
   1.265 +#define NS_IPARSER_FLAG_VIEW_SOURCE          0x00000040
   1.266 +#define NS_IPARSER_FLAG_VIEW_ERRORS          0x00000080
   1.267 +#define NS_IPARSER_FLAG_PLAIN_TEXT           0x00000100
   1.268 +#define NS_IPARSER_FLAG_XML                  0x00000200
   1.269 +#define NS_IPARSER_FLAG_HTML                 0x00000400
   1.270 +#define NS_IPARSER_FLAG_SCRIPT_ENABLED       0x00000800
   1.271 +#define NS_IPARSER_FLAG_FRAMES_ENABLED       0x00001000
   1.272 +
   1.273 +#endif 

mercurial