source: trunk/third/mozilla/htmlparser/public/nsIParser.h @ 20551

Revision 20551, 15.0 KB checked in by rbasch, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20550, which included commits to RCS files with non-trunk default branches.
RevLine 
[19517]1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
[18859]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
66class nsIContentSink;
67class nsIRequestObserver;
68class nsIParserFilter;
69class nsString;
70class nsIURI;
71class nsIChannel;
72
73enum eParserCommands {
74  eViewNormal,
75  eViewSource,
76  eViewFragment,
77  eViewErrors
78};
79
80enum eCRCQuality {
81  eCRCGood = 0,
82  eCRCFair,
83  eCRCPoor
84};
85
86
87enum 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
115enum 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 */
126class nsIDebugDumpContent : public nsISupports {
127public:
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 */
138class 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     */
[19517]150    NS_IMETHOD RegisterDTD(nsIDTD* aDTD)=0;
[18859]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
[19517]157     * @return 
[18859]158     */
[19517]159    NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
[18859]160
161
162    /**
[19517]163     * retrieve the sink set into the parser
[18859]164     * @update  gess5/11/98
[19517]165     * @return  current sink
[18859]166     */
[19517]167    NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
[18859]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     */
[19517]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;
[18859]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     */
[20013]191    NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource)=0;
192    NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, PRInt32& oSource)=0;
[18859]193
[19517]194    NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter) = 0;
[18859]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..
[19517]219    NS_IMETHOD ContinueParsing() = 0;
[18859]220   
221    // Stops parsing temporarily.
[19517]222    NS_IMETHOD_(void) BlockParser() = 0;
[18859]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.
[19517]228    NS_IMETHOD_(void) UnblockParser() = 0;
[18859]229
[19517]230    NS_IMETHOD_(PRBool) IsParserEnabled() = 0;
231    NS_IMETHOD_(PRBool) IsComplete() = 0;
[18859]232   
[19517]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;
[18859]249   
[19517]250    NS_IMETHOD Terminate(void) = 0;
[18859]251
[19517]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;
[18859]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     */
[19517]265    NS_IMETHOD BuildModel(void) = 0;
[18859]266
267
268    /**
269     *  Retrieve the parse mode from the parser...
270     * 
271     *  @update  gess 6/9/98
272     *  @return  ptr to scanner
273     */
[19517]274    NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0;
[18859]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
[19517]286    NS_IMETHOD CancelParsingEvents() = 0;
[18859]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
319const PRUint32  kEOF              = NS_ERROR_HTMLPARSER_EOF;
320const PRUint32  kUnknownError     = NS_ERROR_HTMLPARSER_UNKNOWN;
321const PRUint32  kCantPropagate    = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
322const PRUint32  kContextMismatch  = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
323const PRUint32  kBadFilename      = NS_ERROR_HTMLPARSER_BADFILENAME;
324const PRUint32  kBadURL           = NS_ERROR_HTMLPARSER_BADURL;
325const PRUint32  kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
326const PRUint32  kBlocked          = NS_ERROR_HTMLPARSER_BLOCK;
327const PRUint32  kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
328const PRUint32  kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
329
330const PRUnichar  kNewLine          = '\n';
331const PRUnichar  kCR               = '\r';
332const PRUnichar  kLF               = '\n';
333const PRUnichar  kTab              = '\t';
334const PRUnichar  kSpace            = ' ';
335const PRUnichar  kQuote            = '"';
336const PRUnichar  kApostrophe       = '\'';
337const PRUnichar  kLessThan         = '<';
338const PRUnichar  kGreaterThan      = '>';
339const PRUnichar  kAmpersand        = '&';
340const PRUnichar  kForwardSlash     = '/';
341const PRUnichar  kBackSlash        = '\\';
342const PRUnichar  kEqual            = '=';
343const PRUnichar  kMinus            = '-';
344const PRUnichar  kPlus             = '+';
345const PRUnichar  kExclamation      = '!';
346const PRUnichar  kSemicolon        = ';';
347const PRUnichar  kHashsign         = '#';
348const PRUnichar  kAsterisk         = '*';
349const PRUnichar  kUnderbar         = '_';
350const PRUnichar  kComma            = ',';
351const PRUnichar  kLeftParen        = '(';
352const PRUnichar  kRightParen       = ')';
353const PRUnichar  kLeftBrace        = '{';
354const PRUnichar  kRightBrace       = '}';
355const PRUnichar  kQuestionMark     = '?';
356const PRUnichar  kLeftSquareBracket  = '[';
357const PRUnichar  kRightSquareBracket = ']';
358const 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
[20550]383#define NS_IPARSER_FLAG_PRESERVE_CONTENT     0x00000100
384#define NS_IPARSER_FLAG_PLAIN_TEXT           0x00000200
385#define NS_IPARSER_FLAG_XML                  0x00000400
386#define NS_IPARSER_FLAG_HTML                 0x00000800
[18859]387
388#endif
Note: See TracBrowser for help on using the repository browser.