1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
---|
2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
4 | * |
---|
5 | * The contents of this file are subject to the Netscape Public License |
---|
6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. You may obtain a copy of the License at |
---|
8 | * http://www.mozilla.org/NPL/ |
---|
9 | * |
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis, |
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
12 | * for the specific language governing rights and limitations under the |
---|
13 | * License. |
---|
14 | * |
---|
15 | * The Original Code is mozilla.org code. |
---|
16 | * |
---|
17 | * The Initial Developer of the Original Code is |
---|
18 | * Netscape Communications Corporation. |
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998 |
---|
20 | * the Initial Developer. All Rights Reserved. |
---|
21 | * |
---|
22 | * Contributor(s): |
---|
23 | * |
---|
24 | * |
---|
25 | * Alternatively, the contents of this file may be used under the terms of |
---|
26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
27 | * 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 NPL, 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 NPL, 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 | * @update gess 4/1/98 |
---|
45 | * |
---|
46 | * This class defines the iparser interface. This XPCOM |
---|
47 | * inteface is all that parser clients ever need to see. |
---|
48 | * |
---|
49 | **/ |
---|
50 | |
---|
51 | #include "nsISupports.h" |
---|
52 | #include "nsIStreamListener.h" |
---|
53 | #include "nsIDTD.h" |
---|
54 | #include "nsIInputStream.h" |
---|
55 | #include "nsHashtable.h" |
---|
56 | #include "nsVoidArray.h" |
---|
57 | |
---|
58 | #define NS_IPARSER_IID \ |
---|
59 | {0x355cbba0, 0xbf7d, 0x11d1, \ |
---|
60 | {0xaa, 0xd9, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}} |
---|
61 | |
---|
62 | // {41421C60-310A-11d4-816F-000064657374} |
---|
63 | #define NS_IDEBUG_DUMP_CONTENT_IID \ |
---|
64 | { 0x41421c60, 0x310a, 0x11d4, { 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }; |
---|
65 | |
---|
66 | class nsIContentSink; |
---|
67 | class nsIRequestObserver; |
---|
68 | class nsIParserFilter; |
---|
69 | class nsString; |
---|
70 | class nsIURI; |
---|
71 | class nsIChannel; |
---|
72 | |
---|
73 | enum eParserCommands { |
---|
74 | eViewNormal, |
---|
75 | eViewSource, |
---|
76 | eViewFragment, |
---|
77 | eViewErrors |
---|
78 | }; |
---|
79 | |
---|
80 | enum eCRCQuality { |
---|
81 | eCRCGood = 0, |
---|
82 | eCRCFair, |
---|
83 | eCRCPoor |
---|
84 | }; |
---|
85 | |
---|
86 | |
---|
87 | enum eParserDocType { |
---|
88 | ePlainText = 0, |
---|
89 | eXML, |
---|
90 | eHTML_Quirks, |
---|
91 | eHTML3_Quirks, // separate, for editor output, since HTML pre-4.0 lacks tbody |
---|
92 | eHTML_Strict |
---|
93 | }; |
---|
94 | |
---|
95 | |
---|
96 | // define Charset source constants |
---|
97 | // note: the value order define the priority |
---|
98 | #define kCharsetUninitialized 0 |
---|
99 | #define kCharsetFromWeakDocTypeDefault 1 |
---|
100 | #define kCharsetFromUserDefault 2 |
---|
101 | #define kCharsetFromDocTypeDefault 3 |
---|
102 | #define kCharsetFromCache 4 |
---|
103 | #define kCharsetFromParentFrame 5 |
---|
104 | #define kCharsetFromBookmarks 6 |
---|
105 | #define kCharsetFromAutoDetection 7 |
---|
106 | #define kCharsetFromHintPrevDoc 8 |
---|
107 | #define kCharsetFromMetaTag 9 |
---|
108 | #define kCharsetFromByteOrderMark 10 |
---|
109 | #define kCharsetFromChannel 11 |
---|
110 | #define kCharsetFromParentForced 12 |
---|
111 | #define kCharsetFromUserForced 13 |
---|
112 | #define kCharsetFromOtherComponent 14 |
---|
113 | #define kCharsetFromPreviousLoading 15 |
---|
114 | |
---|
115 | enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop}; |
---|
116 | |
---|
117 | /** |
---|
118 | * FOR DEBUG PURPOSE ONLY |
---|
119 | * |
---|
120 | * Use this interface to query objects that contain content information. |
---|
121 | * Ex. Parser can trigger dump content by querying the sink that has |
---|
122 | * access to the content. |
---|
123 | * |
---|
124 | * @update harishd 05/25/00 |
---|
125 | */ |
---|
126 | class nsIDebugDumpContent : public nsISupports { |
---|
127 | public: |
---|
128 | NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDEBUG_DUMP_CONTENT_IID) |
---|
129 | NS_IMETHOD DumpContentModel()=0; |
---|
130 | }; |
---|
131 | |
---|
132 | /** |
---|
133 | * This class defines the iparser interface. This XPCOM |
---|
134 | * inteface is all that parser clients ever need to see. |
---|
135 | * |
---|
136 | * @update gess 3/25/98 |
---|
137 | */ |
---|
138 | class nsIParser : public nsISupports { |
---|
139 | public: |
---|
140 | |
---|
141 | NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPARSER_IID) |
---|
142 | |
---|
143 | /** |
---|
144 | * Call this method if you have a DTD that you want to share with the parser. |
---|
145 | * Registered DTD's get remembered until the system shuts down. |
---|
146 | * |
---|
147 | * @update gess 3/25/98 |
---|
148 | * @param aDTD -- ptr DTD that you're publishing the services of |
---|
149 | */ |
---|
150 | NS_IMETHOD RegisterDTD(nsIDTD* aDTD)=0; |
---|
151 | |
---|
152 | |
---|
153 | /** |
---|
154 | * Select given content sink into parser for parser output |
---|
155 | * @update gess5/11/98 |
---|
156 | * @param aSink is the new sink to be used by parser |
---|
157 | * @return |
---|
158 | */ |
---|
159 | NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0; |
---|
160 | |
---|
161 | |
---|
162 | /** |
---|
163 | * retrieve the sink set into the parser |
---|
164 | * @update gess5/11/98 |
---|
165 | * @return current sink |
---|
166 | */ |
---|
167 | NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0; |
---|
168 | |
---|
169 | /** |
---|
170 | * Call this method once you've created a parser, and want to instruct it |
---|
171 | * about the command which caused the parser to be constructed. For example, |
---|
172 | * this allows us to select a DTD which can do, say, view-source. |
---|
173 | * |
---|
174 | * @update gess 3/25/98 |
---|
175 | * @param aCommand -- ptrs to string that contains command |
---|
176 | * @return nada |
---|
177 | */ |
---|
178 | NS_IMETHOD_(void) GetCommand(nsString& aCommand)=0; |
---|
179 | NS_IMETHOD_(void) SetCommand(const char* aCommand)=0; |
---|
180 | NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0; |
---|
181 | |
---|
182 | /** |
---|
183 | * Call this method once you've created a parser, and want to instruct it |
---|
184 | * about what charset to load |
---|
185 | * |
---|
186 | * @update ftang 4/23/99 |
---|
187 | * @param aCharset- the charest of a document |
---|
188 | * @param aCharsetSource- the soure of the chares |
---|
189 | * @return nada |
---|
190 | */ |
---|
191 | NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource)=0; |
---|
192 | NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, PRInt32& oSource)=0; |
---|
193 | |
---|
194 | NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter) = 0; |
---|
195 | |
---|
196 | /** |
---|
197 | * Get the channel associated with this parser |
---|
198 | * @update harishd,gagan 07/17/01 |
---|
199 | * @param aChannel out param that will contain the result |
---|
200 | * @return NS_OK if successful |
---|
201 | */ |
---|
202 | NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0; |
---|
203 | |
---|
204 | /** |
---|
205 | * Get the DTD associated with this parser |
---|
206 | * @update vidur 9/29/99 |
---|
207 | * @param aDTD out param that will contain the result |
---|
208 | * @return NS_OK if successful, NS_ERROR_FAILURE for runtime error |
---|
209 | */ |
---|
210 | NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0; |
---|
211 | |
---|
212 | /****************************************************************************************** |
---|
213 | * Parse methods always begin with an input source, and perform conversions |
---|
214 | * until you wind up being emitted to the given contentsink (which may or may not |
---|
215 | * be a proxy for the NGLayout content model). |
---|
216 | ******************************************************************************************/ |
---|
217 | |
---|
218 | // Call this method to resume the parser from the blocked state.. |
---|
219 | NS_IMETHOD ContinueParsing() = 0; |
---|
220 | |
---|
221 | // Stops parsing temporarily. |
---|
222 | NS_IMETHOD_(void) BlockParser() = 0; |
---|
223 | |
---|
224 | // Open up the parser for tokenization, building up content |
---|
225 | // model..etc. However, this method does not resume parsing |
---|
226 | // automatically. It's the callers' responsibility to restart |
---|
227 | // the parsing engine. |
---|
228 | NS_IMETHOD_(void) UnblockParser() = 0; |
---|
229 | |
---|
230 | NS_IMETHOD_(PRBool) IsParserEnabled() = 0; |
---|
231 | NS_IMETHOD_(PRBool) IsComplete() = 0; |
---|
232 | |
---|
233 | NS_IMETHOD Parse(nsIURI* aURL, |
---|
234 | nsIRequestObserver* aListener = nsnull, |
---|
235 | PRBool aEnableVerify = PR_FALSE, |
---|
236 | void* aKey = 0, |
---|
237 | nsDTDMode aMode = eDTDMode_autodetect) = 0; |
---|
238 | NS_IMETHOD Parse(nsIInputStream* aStream, |
---|
239 | const nsACString& aMimeType, |
---|
240 | PRBool aEnableVerify = PR_FALSE, |
---|
241 | void* aKey = 0, |
---|
242 | nsDTDMode aMode = eDTDMode_autodetect) = 0; |
---|
243 | NS_IMETHOD Parse(const nsAString& aSourceBuffer, |
---|
244 | void* aKey, |
---|
245 | const nsACString& aMimeType, |
---|
246 | PRBool aEnableVerify, |
---|
247 | PRBool aLastCall, |
---|
248 | nsDTDMode aMode = eDTDMode_autodetect) = 0; |
---|
249 | |
---|
250 | NS_IMETHOD Terminate(void) = 0; |
---|
251 | |
---|
252 | NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer, |
---|
253 | void* aKey, |
---|
254 | nsVoidArray& aTagStack, |
---|
255 | PRUint32 anInsertPos, |
---|
256 | const nsACString& aContentType, |
---|
257 | nsDTDMode aMode = eDTDMode_autodetect) = 0; |
---|
258 | |
---|
259 | /** |
---|
260 | * This method gets called when the tokens have been consumed, and it's time |
---|
261 | * to build the model via the content sink. |
---|
262 | * @update gess5/11/98 |
---|
263 | * @return error code -- 0 if model building went well . |
---|
264 | */ |
---|
265 | NS_IMETHOD BuildModel(void) = 0; |
---|
266 | |
---|
267 | |
---|
268 | /** |
---|
269 | * Retrieve the parse mode from the parser... |
---|
270 | * |
---|
271 | * @update gess 6/9/98 |
---|
272 | * @return ptr to scanner |
---|
273 | */ |
---|
274 | NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0; |
---|
275 | |
---|
276 | /** |
---|
277 | * Call this method to cancel any pending parsing events. |
---|
278 | * Parsing events may be pending if all of the document's content |
---|
279 | * has been passed to the parser but the parser has been interrupted |
---|
280 | * because processing the tokens took too long. |
---|
281 | * |
---|
282 | * @update kmcclusk 05/18/01 |
---|
283 | * @return NS_OK if succeeded else ERROR. |
---|
284 | */ |
---|
285 | |
---|
286 | NS_IMETHOD CancelParsingEvents() = 0; |
---|
287 | }; |
---|
288 | |
---|
289 | /* ===========================================================* |
---|
290 | Some useful constants... |
---|
291 | * ===========================================================*/ |
---|
292 | |
---|
293 | #include "prtypes.h" |
---|
294 | #include "nsError.h" |
---|
295 | |
---|
296 | #define NS_ERROR_HTMLPARSER_EOF NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1000) |
---|
297 | #define NS_ERROR_HTMLPARSER_UNKNOWN NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1001) |
---|
298 | #define NS_ERROR_HTMLPARSER_CANTPROPAGATE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1002) |
---|
299 | #define NS_ERROR_HTMLPARSER_CONTEXTMISMATCH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1003) |
---|
300 | #define NS_ERROR_HTMLPARSER_BADFILENAME NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1004) |
---|
301 | #define NS_ERROR_HTMLPARSER_BADURL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1005) |
---|
302 | #define NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1006) |
---|
303 | #define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007) |
---|
304 | #define NS_ERROR_HTMLPARSER_BLOCK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008) |
---|
305 | #define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009) |
---|
306 | #define NS_ERROR_HTMLPARSER_BADATTRIBUTE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010) |
---|
307 | #define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1011) |
---|
308 | #define NS_ERROR_HTMLPARSER_MISPLACEDTABLECONTENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1012) |
---|
309 | #define NS_ERROR_HTMLPARSER_BADDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1013) |
---|
310 | #define NS_ERROR_HTMLPARSER_BADCONTEXT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1014) |
---|
311 | #define NS_ERROR_HTMLPARSER_STOPPARSING NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1015) |
---|
312 | #define NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1016) |
---|
313 | #define NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1017) |
---|
314 | |
---|
315 | |
---|
316 | #define NS_ERROR_HTMLPARSER_CONTINUE NS_OK |
---|
317 | |
---|
318 | |
---|
319 | const PRUint32 kEOF = NS_ERROR_HTMLPARSER_EOF; |
---|
320 | const PRUint32 kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN; |
---|
321 | const PRUint32 kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE; |
---|
322 | const PRUint32 kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH; |
---|
323 | const PRUint32 kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME; |
---|
324 | const PRUint32 kBadURL = NS_ERROR_HTMLPARSER_BADURL; |
---|
325 | const PRUint32 kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT; |
---|
326 | const PRUint32 kBlocked = NS_ERROR_HTMLPARSER_BLOCK; |
---|
327 | const PRUint32 kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL; |
---|
328 | const PRUint32 kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP; |
---|
329 | |
---|
330 | const PRUnichar kNewLine = '\n'; |
---|
331 | const PRUnichar kCR = '\r'; |
---|
332 | const PRUnichar kLF = '\n'; |
---|
333 | const PRUnichar kTab = '\t'; |
---|
334 | const PRUnichar kSpace = ' '; |
---|
335 | const PRUnichar kQuote = '"'; |
---|
336 | const PRUnichar kApostrophe = '\''; |
---|
337 | const PRUnichar kLessThan = '<'; |
---|
338 | const PRUnichar kGreaterThan = '>'; |
---|
339 | const PRUnichar kAmpersand = '&'; |
---|
340 | const PRUnichar kForwardSlash = '/'; |
---|
341 | const PRUnichar kBackSlash = '\\'; |
---|
342 | const PRUnichar kEqual = '='; |
---|
343 | const PRUnichar kMinus = '-'; |
---|
344 | const PRUnichar kPlus = '+'; |
---|
345 | const PRUnichar kExclamation = '!'; |
---|
346 | const PRUnichar kSemicolon = ';'; |
---|
347 | const PRUnichar kHashsign = '#'; |
---|
348 | const PRUnichar kAsterisk = '*'; |
---|
349 | const PRUnichar kUnderbar = '_'; |
---|
350 | const PRUnichar kComma = ','; |
---|
351 | const PRUnichar kLeftParen = '('; |
---|
352 | const PRUnichar kRightParen = ')'; |
---|
353 | const PRUnichar kLeftBrace = '{'; |
---|
354 | const PRUnichar kRightBrace = '}'; |
---|
355 | const PRUnichar kQuestionMark = '?'; |
---|
356 | const PRUnichar kLeftSquareBracket = '['; |
---|
357 | const PRUnichar kRightSquareBracket = ']'; |
---|
358 | const PRUnichar kNullCh = '\0'; |
---|
359 | |
---|
360 | #define kHTMLTextContentType "text/html" |
---|
361 | #define kXMLTextContentType "text/xml" |
---|
362 | #define kXMLApplicationContentType "application/xml" |
---|
363 | #define kXHTMLApplicationContentType "application/xhtml+xml" |
---|
364 | #define kXULTextContentType "application/vnd.mozilla.xul+xml" |
---|
365 | #define kRDFTextContentType "text/rdf" |
---|
366 | #define kXIFTextContentType "text/xif" |
---|
367 | #define kPlainTextContentType "text/plain" |
---|
368 | #define kViewSourceCommand "view-source" |
---|
369 | #define kViewFragmentCommand "view-fragment" |
---|
370 | #define kTextCSSContentType "text/css" |
---|
371 | #define kApplicationJSContentType "application/x-javascript" |
---|
372 | #define kTextJSContentType "text/javascript" |
---|
373 | #define kSGMLTextContentType "text/sgml" |
---|
374 | #define kSVGTextContentType "image/svg+xml" |
---|
375 | |
---|
376 | #define NS_IPARSER_FLAG_UNKNOWN_MODE 0x00000000 |
---|
377 | #define NS_IPARSER_FLAG_QUIRKS_MODE 0x00000002 |
---|
378 | #define NS_IPARSER_FLAG_STRICT_MODE 0x00000004 |
---|
379 | #define NS_IPARSER_FLAG_AUTO_DETECT_MODE 0x00000010 |
---|
380 | #define NS_IPARSER_FLAG_VIEW_NORMAL 0x00000020 |
---|
381 | #define NS_IPARSER_FLAG_VIEW_SOURCE 0x00000040 |
---|
382 | #define NS_IPARSER_FLAG_VIEW_ERRORS 0x00000080 |
---|
383 | #define NS_IPARSER_FLAG_PLAIN_TEXT 0x00000100 |
---|
384 | #define NS_IPARSER_FLAG_XML 0x00000200 |
---|
385 | #define NS_IPARSER_FLAG_HTML 0x00000400 |
---|
386 | |
---|
387 | #endif |
---|