michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=78: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef NS_IPARSER___ michael@0: #define NS_IPARSER___ michael@0: michael@0: michael@0: /** michael@0: * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored michael@0: * to the point of being near-unrecognizable). michael@0: * michael@0: * Please DO NOT #include this file in comm-central code, in your XULRunner michael@0: * app or binary extensions. michael@0: * michael@0: * Please DO NOT #include this into new files even inside Gecko. It is more michael@0: * likely than not that #including this header is the wrong thing to do. michael@0: */ michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsIStreamListener.h" michael@0: #include "nsIDTD.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsParserBase.h" michael@0: michael@0: #define NS_IPARSER_IID \ michael@0: { 0x2c4ad90a, 0x740e, 0x4212, \ michael@0: { 0xba, 0x3f, 0xfe, 0xac, 0xda, 0x4b, 0x92, 0x9e } } michael@0: michael@0: // {41421C60-310A-11d4-816F-000064657374} michael@0: #define NS_IDEBUG_DUMP_CONTENT_IID \ michael@0: { 0x41421c60, 0x310a, 0x11d4, \ michael@0: { 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } michael@0: michael@0: class nsIContentSink; michael@0: class nsIRequestObserver; michael@0: class nsString; michael@0: class nsIURI; michael@0: class nsIChannel; michael@0: class nsIContent; michael@0: michael@0: enum eParserCommands { michael@0: eViewNormal, michael@0: eViewSource, michael@0: eViewFragment, michael@0: eViewErrors michael@0: }; michael@0: michael@0: enum eParserDocType { michael@0: ePlainText = 0, michael@0: eXML, michael@0: eHTML_Quirks, michael@0: eHTML_Strict michael@0: }; michael@0: michael@0: enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop}; michael@0: michael@0: /** michael@0: * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored michael@0: * to the point of being near-unrecognizable). michael@0: * michael@0: * Please DO NOT #include this file in comm-central code, in your XULRunner michael@0: * app or binary extensions. michael@0: * michael@0: * Please DO NOT #include this into new files even inside Gecko. It is more michael@0: * likely than not that #including this header is the wrong thing to do. michael@0: */ michael@0: class nsIParser : public nsParserBase { michael@0: public: michael@0: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID) michael@0: michael@0: /** michael@0: * Select given content sink into parser for parser output michael@0: * @update gess5/11/98 michael@0: * @param aSink is the new sink to be used by parser michael@0: * @return michael@0: */ michael@0: NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0; michael@0: michael@0: michael@0: /** michael@0: * retrieve the sink set into the parser michael@0: * @update gess5/11/98 michael@0: * @return current sink michael@0: */ michael@0: NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0; michael@0: michael@0: /** michael@0: * Call this method once you've created a parser, and want to instruct it michael@0: * about the command which caused the parser to be constructed. For example, michael@0: * this allows us to select a DTD which can do, say, view-source. michael@0: * michael@0: * @update gess 3/25/98 michael@0: * @param aCommand -- ptrs to string that contains command michael@0: * @return nada michael@0: */ michael@0: NS_IMETHOD_(void) GetCommand(nsCString& aCommand)=0; michael@0: NS_IMETHOD_(void) SetCommand(const char* aCommand)=0; michael@0: NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0; michael@0: michael@0: /** michael@0: * Call this method once you've created a parser, and want to instruct it michael@0: * about what charset to load michael@0: * michael@0: * @update ftang 4/23/99 michael@0: * @param aCharset- the charest of a document michael@0: * @param aCharsetSource- the soure of the chares michael@0: * @return nada michael@0: */ michael@0: NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, int32_t aSource)=0; michael@0: NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, int32_t& oSource)=0; michael@0: michael@0: /** michael@0: * Get the channel associated with this parser michael@0: * @update harishd,gagan 07/17/01 michael@0: * @param aChannel out param that will contain the result michael@0: * @return NS_OK if successful michael@0: */ michael@0: NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0; michael@0: michael@0: /** michael@0: * Get the DTD associated with this parser michael@0: * @update vidur 9/29/99 michael@0: * @param aDTD out param that will contain the result michael@0: * @return NS_OK if successful, NS_ERROR_FAILURE for runtime error michael@0: */ michael@0: NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0; michael@0: michael@0: /** michael@0: * Get the nsIStreamListener for this parser michael@0: */ michael@0: virtual nsIStreamListener* GetStreamListener() = 0; michael@0: michael@0: /************************************************************************** michael@0: * Parse methods always begin with an input source, and perform michael@0: * conversions until you wind up being emitted to the given contentsink michael@0: * (which may or may not be a proxy for the NGLayout content model). michael@0: ************************************************************************/ michael@0: michael@0: // Call this method to resume the parser from an unblocked state. michael@0: // This can happen, for example, if parsing was interrupted and then the michael@0: // consumer needed to restart the parser without waiting for more data. michael@0: // This also happens after loading scripts, which unblock the parser in michael@0: // order to process the output of document.write() and then need to michael@0: // continue on with the page load on an enabled parser. michael@0: NS_IMETHOD ContinueInterruptedParsing() = 0; michael@0: michael@0: // Stops parsing temporarily. michael@0: NS_IMETHOD_(void) BlockParser() = 0; michael@0: michael@0: // Open up the parser for tokenization, building up content michael@0: // model..etc. However, this method does not resume parsing michael@0: // automatically. It's the callers' responsibility to restart michael@0: // the parsing engine. michael@0: NS_IMETHOD_(void) UnblockParser() = 0; michael@0: michael@0: /** michael@0: * Asynchronously continues parsing. michael@0: */ michael@0: NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0; michael@0: michael@0: NS_IMETHOD_(bool) IsParserEnabled() = 0; michael@0: NS_IMETHOD_(bool) IsComplete() = 0; michael@0: michael@0: NS_IMETHOD Parse(nsIURI* aURL, michael@0: nsIRequestObserver* aListener = nullptr, michael@0: void* aKey = 0, michael@0: nsDTDMode aMode = eDTDMode_autodetect) = 0; michael@0: michael@0: NS_IMETHOD Terminate(void) = 0; michael@0: michael@0: /** michael@0: * This method gets called when you want to parse a fragment of HTML or XML michael@0: * surrounded by the context |aTagStack|. It requires that the parser have michael@0: * been given a fragment content sink. michael@0: * michael@0: * @param aSourceBuffer The XML or HTML that hasn't been parsed yet. michael@0: * @param aTagStack The context of the source buffer. michael@0: * @return Success or failure. michael@0: */ michael@0: NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer, michael@0: nsTArray& aTagStack) = 0; michael@0: michael@0: /** michael@0: * This method gets called when the tokens have been consumed, and it's time michael@0: * to build the model via the content sink. michael@0: * @update gess5/11/98 michael@0: * @return error code -- 0 if model building went well . michael@0: */ michael@0: NS_IMETHOD BuildModel(void) = 0; michael@0: michael@0: /** michael@0: * Call this method to cancel any pending parsing events. michael@0: * Parsing events may be pending if all of the document's content michael@0: * has been passed to the parser but the parser has been interrupted michael@0: * because processing the tokens took too long. michael@0: * michael@0: * @update kmcclusk 05/18/01 michael@0: * @return NS_OK if succeeded else ERROR. michael@0: */ michael@0: michael@0: NS_IMETHOD CancelParsingEvents() = 0; michael@0: michael@0: virtual void Reset() = 0; michael@0: michael@0: /** michael@0: * True if the insertion point (per HTML5) is defined. michael@0: */ michael@0: virtual bool IsInsertionPointDefined() = 0; michael@0: michael@0: /** michael@0: * Call immediately before starting to evaluate a parser-inserted script. michael@0: */ michael@0: virtual void BeginEvaluatingParserInsertedScript() = 0; michael@0: michael@0: /** michael@0: * Call immediately after having evaluated a parser-inserted script. michael@0: */ michael@0: virtual void EndEvaluatingParserInsertedScript() = 0; michael@0: michael@0: /** michael@0: * Marks the HTML5 parser as not a script-created parser. michael@0: */ michael@0: virtual void MarkAsNotScriptCreated(const char* aCommand) = 0; michael@0: michael@0: /** michael@0: * True if this is a script-created HTML5 parser. michael@0: */ michael@0: virtual bool IsScriptCreated() = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID) michael@0: michael@0: /* ===========================================================* michael@0: Some useful constants... michael@0: * ===========================================================*/ michael@0: michael@0: #include "nsError.h" michael@0: michael@0: const nsresult kEOF = NS_ERROR_HTMLPARSER_EOF; michael@0: const nsresult kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN; michael@0: const nsresult kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE; michael@0: const nsresult kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH; michael@0: const nsresult kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME; michael@0: const nsresult kBadURL = NS_ERROR_HTMLPARSER_BADURL; michael@0: const nsresult kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT; michael@0: const nsresult kBlocked = NS_ERROR_HTMLPARSER_BLOCK; michael@0: const nsresult kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL; michael@0: const nsresult kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP; michael@0: const nsresult kFakeEndTag = NS_ERROR_HTMLPARSER_FAKE_ENDTAG; michael@0: const nsresult kNotAComment = NS_ERROR_HTMLPARSER_INVALID_COMMENT; michael@0: michael@0: #define NS_IPARSER_FLAG_UNKNOWN_MODE 0x00000000 michael@0: #define NS_IPARSER_FLAG_QUIRKS_MODE 0x00000002 michael@0: #define NS_IPARSER_FLAG_STRICT_MODE 0x00000004 michael@0: #define NS_IPARSER_FLAG_AUTO_DETECT_MODE 0x00000010 michael@0: #define NS_IPARSER_FLAG_VIEW_NORMAL 0x00000020 michael@0: #define NS_IPARSER_FLAG_VIEW_SOURCE 0x00000040 michael@0: #define NS_IPARSER_FLAG_VIEW_ERRORS 0x00000080 michael@0: #define NS_IPARSER_FLAG_PLAIN_TEXT 0x00000100 michael@0: #define NS_IPARSER_FLAG_XML 0x00000200 michael@0: #define NS_IPARSER_FLAG_HTML 0x00000400 michael@0: #define NS_IPARSER_FLAG_SCRIPT_ENABLED 0x00000800 michael@0: #define NS_IPARSER_FLAG_FRAMES_ENABLED 0x00001000 michael@0: michael@0: #endif