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