nsIParser.h (6124B)
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/. */ 6 #ifndef NS_IPARSER___ 7 #define NS_IPARSER___ 8 9 /** 10 * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored 11 * to the point of being near-unrecognizable). 12 * 13 * Please DO NOT #include this file in comm-central code, in your XULRunner 14 * app or binary extensions. 15 * 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. 18 */ 19 20 #include "nsISupports.h" 21 #include "nsIStreamListener.h" 22 #include "nsString.h" 23 #include "nsTArray.h" 24 #include "nsAtom.h" 25 #include "nsParserBase.h" 26 #include "mozilla/NotNull.h" 27 28 #define NS_IPARSER_IID \ 29 {0x2c4ad90a, 0x740e, 0x4212, {0xba, 0x3f, 0xfe, 0xac, 0xda, 0x4b, 0x92, 0x9e}} 30 31 class nsIContentSink; 32 class nsIRequestObserver; 33 class nsIURI; 34 class nsIChannel; 35 namespace mozilla { 36 class Encoding; 37 } 38 39 enum eParserCommands { eViewNormal, eViewSource, eViewFragment, eViewErrors }; 40 41 enum eParserDocType { eUnknown = 0, eXML, eHTML_Quirks, eHTML_Strict }; 42 43 enum eStreamState { eNone, eOnStart, eOnDataAvail, eOnStop }; 44 45 /** 46 * This GECKO-INTERNAL interface is on track to being REMOVED (or refactored 47 * to the point of being near-unrecognizable). 48 * 49 * Please DO NOT #include this file in comm-central code, in your XULRunner 50 * app or binary extensions. 51 * 52 * Please DO NOT #include this into new files even inside Gecko. It is more 53 * likely than not that #including this header is the wrong thing to do. 54 */ 55 class nsIParser : public nsParserBase { 56 protected: 57 using Encoding = mozilla::Encoding; 58 template <typename T> 59 using NotNull = mozilla::NotNull<T>; 60 61 public: 62 NS_INLINE_DECL_STATIC_IID(NS_IPARSER_IID) 63 64 /** 65 * Select given content sink into parser for parser output 66 * @update gess5/11/98 67 * @param aSink is the new sink to be used by parser 68 * @return 69 */ 70 NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink) = 0; 71 72 /** 73 * retrieve the sink set into the parser 74 * @update gess5/11/98 75 * @return current sink 76 */ 77 NS_IMETHOD_(nsIContentSink*) GetContentSink(void) = 0; 78 79 /** 80 * Call this method once you've created a parser, and want to instruct it 81 * about the command which caused the parser to be constructed. For example, 82 * this allows us to select a DTD which can do, say, view-source. 83 * 84 * @update gess 3/25/98 85 * @param aCommand -- ptrs to string that contains command 86 * @return nada 87 */ 88 NS_IMETHOD_(void) GetCommand(nsCString& aCommand) = 0; 89 NS_IMETHOD_(void) SetCommand(const char* aCommand) = 0; 90 NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand) = 0; 91 92 /** 93 * Call this method once you've created a parser, and want to instruct it 94 * about what charset to load 95 * 96 * @update ftang 4/23/99 97 * @param aCharset- the charest of a document 98 * @param aCharsetSource- the soure of the chares 99 * @param aForceAutoDetection- whether Repair Text Encoding menu item was 100 * invoked 101 * @return nada 102 */ 103 virtual void SetDocumentCharset(NotNull<const Encoding*> aCharset, 104 int32_t aSource, 105 bool aForceAutoDetection = false) = 0; 106 107 /** 108 * Get the nsIStreamListener for this parser 109 */ 110 virtual nsIStreamListener* GetStreamListener() = 0; 111 112 /************************************************************************** 113 * Parse methods always begin with an input source, and perform 114 * conversions until you wind up being emitted to the given contentsink 115 * (which may or may not be a proxy for the NGLayout content model). 116 ************************************************************************/ 117 118 // Call this method to resume the parser from an unblocked state. 119 // This can happen, for example, if parsing was interrupted and then the 120 // consumer needed to restart the parser without waiting for more data. 121 // This also happens after loading scripts, which unblock the parser in 122 // order to process the output of document.write() and then need to 123 // continue on with the page load on an enabled parser. 124 NS_IMETHOD ContinueInterruptedParsing() = 0; 125 126 // Stops parsing temporarily. 127 NS_IMETHOD_(void) BlockParser() = 0; 128 129 // Open up the parser for tokenization, building up content 130 // model..etc. However, this method does not resume parsing 131 // automatically. It's the callers' responsibility to restart 132 // the parsing engine. 133 NS_IMETHOD_(void) UnblockParser() = 0; 134 135 /** 136 * Asynchronously continues parsing. 137 */ 138 NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0; 139 140 NS_IMETHOD_(bool) IsParserEnabled() override = 0; 141 NS_IMETHOD_(bool) IsComplete() = 0; 142 143 NS_IMETHOD Parse(nsIURI* aURL) = 0; 144 145 NS_IMETHOD Terminate(void) = 0; 146 147 /** 148 * True if the insertion point (per HTML5) is defined. 149 */ 150 virtual bool IsInsertionPointDefined() = 0; 151 152 /** 153 * Call immediately before starting to evaluate a parser-inserted script or 154 * in general when the spec says to increment the script nesting level. 155 */ 156 virtual void IncrementScriptNestingLevel() = 0; 157 158 /** 159 * Call immediately after having evaluated a parser-inserted script or 160 * generally want to restore to the state before the last 161 * IncrementScriptNestingLevel call. 162 */ 163 virtual void DecrementScriptNestingLevel() = 0; 164 165 /** 166 * True if this is an HTML5 parser whose script nesting level (in 167 * the sense of 168 * <https://html.spec.whatwg.org/multipage/parsing.html#script-nesting-level>) 169 * is nonzero. 170 */ 171 virtual bool HasNonzeroScriptNestingLevel() const = 0; 172 173 /** 174 * True if this is a script-created HTML5 parser. 175 */ 176 virtual bool IsScriptCreated() = 0; 177 178 /** 179 * True iff this is an about:blank-mode HTML5 parser 180 * (i.e. a parser for non-initial about:blank). 181 */ 182 virtual bool IsAboutBlankMode() = 0; 183 }; 184 185 #endif