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