1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
10 * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
11 * to the point of being near-unrecognizable).
13 * Please DO NOT #include this file in comm-central code, in your XULRunner
14 * app or binary extensions.
16 * Please DO NOT #include this into new files even inside Gecko. It is more
17 * likely than not that #including this header is the wrong thing to do.
20 #include "nsISupports.h"
21 #include "nsIStreamListener.h"
26 #include "nsParserBase.h"
27 #include "mozilla/NotNull.h"
29 #define NS_IPARSER_IID \
31 0x2c4ad90a, 0x740e, 0x4212, { \
32 0xba, 0x3f, 0xfe, 0xac, 0xda, 0x4b, 0x92, 0x9e \
37 class nsIRequestObserver
;
44 enum eParserCommands
{ eViewNormal
, eViewSource
, eViewFragment
, eViewErrors
};
46 enum eParserDocType
{ eUnknown
= 0, eXML
, eHTML_Quirks
, eHTML_Strict
};
48 enum eStreamState
{ eNone
, eOnStart
, eOnDataAvail
, eOnStop
};
51 * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
52 * to the point of being near-unrecognizable).
54 * Please DO NOT #include this file in comm-central code, in your XULRunner
55 * app or binary extensions.
57 * Please DO NOT #include this into new files even inside Gecko. It is more
58 * likely than not that #including this header is the wrong thing to do.
60 class nsIParser
: public nsParserBase
{
62 using Encoding
= mozilla::Encoding
;
64 using NotNull
= mozilla::NotNull
<T
>;
67 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID
)
70 * Select given content sink into parser for parser output
72 * @param aSink is the new sink to be used by parser
75 NS_IMETHOD_(void) SetContentSink(nsIContentSink
* aSink
) = 0;
78 * retrieve the sink set into the parser
80 * @return current sink
82 NS_IMETHOD_(nsIContentSink
*) GetContentSink(void) = 0;
85 * Call this method once you've created a parser, and want to instruct it
86 * about the command which caused the parser to be constructed. For example,
87 * this allows us to select a DTD which can do, say, view-source.
89 * @update gess 3/25/98
90 * @param aCommand -- ptrs to string that contains command
93 NS_IMETHOD_(void) GetCommand(nsCString
& aCommand
) = 0;
94 NS_IMETHOD_(void) SetCommand(const char* aCommand
) = 0;
95 NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand
) = 0;
98 * Call this method once you've created a parser, and want to instruct it
99 * about what charset to load
101 * @update ftang 4/23/99
102 * @param aCharset- the charest of a document
103 * @param aCharsetSource- the soure of the chares
104 * @param aForceAutoDetection- whether Repair Text Encoding menu item was
108 virtual void SetDocumentCharset(NotNull
<const Encoding
*> aCharset
,
110 bool aForceAutoDetection
= false) = 0;
113 * Get the nsIStreamListener for this parser
115 virtual nsIStreamListener
* GetStreamListener() = 0;
117 /**************************************************************************
118 * Parse methods always begin with an input source, and perform
119 * conversions until you wind up being emitted to the given contentsink
120 * (which may or may not be a proxy for the NGLayout content model).
121 ************************************************************************/
123 // Call this method to resume the parser from an unblocked state.
124 // This can happen, for example, if parsing was interrupted and then the
125 // consumer needed to restart the parser without waiting for more data.
126 // This also happens after loading scripts, which unblock the parser in
127 // order to process the output of document.write() and then need to
128 // continue on with the page load on an enabled parser.
129 NS_IMETHOD
ContinueInterruptedParsing() = 0;
131 // Stops parsing temporarily.
132 NS_IMETHOD_(void) BlockParser() = 0;
134 // Open up the parser for tokenization, building up content
135 // model..etc. However, this method does not resume parsing
136 // automatically. It's the callers' responsibility to restart
137 // the parsing engine.
138 NS_IMETHOD_(void) UnblockParser() = 0;
141 * Asynchronously continues parsing.
143 NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0;
145 NS_IMETHOD_(bool) IsParserEnabled() override
= 0;
146 NS_IMETHOD_(bool) IsComplete() = 0;
148 NS_IMETHOD
Parse(nsIURI
* aURL
) = 0;
150 NS_IMETHOD
Terminate(void) = 0;
153 * True if the insertion point (per HTML5) is defined.
155 virtual bool IsInsertionPointDefined() = 0;
158 * Call immediately before starting to evaluate a parser-inserted script or
159 * in general when the spec says to increment the script nesting level.
161 virtual void IncrementScriptNestingLevel() = 0;
164 * Call immediately after having evaluated a parser-inserted script or
165 * generally want to restore to the state before the last
166 * IncrementScriptNestingLevel call.
168 virtual void DecrementScriptNestingLevel() = 0;
171 * True if this is an HTML5 parser whose script nesting level (in
173 * <https://html.spec.whatwg.org/multipage/parsing.html#script-nesting-level>)
176 virtual bool HasNonzeroScriptNestingLevel() const = 0;
179 * True if this is a script-created HTML5 parser.
181 virtual bool IsScriptCreated() = 0;
184 NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser
, NS_IPARSER_IID
)