1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsIContentSink_h___
6 #define nsIContentSink_h___
12 * This pure virtual interface is used as the "glue" that connects the parsing
13 * process to the content model construction process.
15 * The icontentsink interface is a very lightweight wrapper that represents the
16 * content-sink model building process. There is another one that you may care
17 * about more, which is the IHTMLContentSink interface. (See that file for
20 #include "nsISupports.h"
22 #include "mozilla/FlushType.h"
23 #include "mozilla/NotNull.h"
31 #define NS_ICONTENT_SINK_IID \
33 0xcf9a7cbb, 0xfcbc, 0x4e13, { \
34 0x8e, 0xf5, 0x18, 0xef, 0x2d, 0x3d, 0x58, 0x29 \
38 class nsIContentSink
: public nsISupports
{
40 using Encoding
= mozilla::Encoding
;
42 using NotNull
= mozilla::NotNull
<T
>;
45 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_SINK_IID
)
48 * This method is called by the parser when it is entered from
49 * the event loop. The content sink wants to know how long the
50 * parser has been active since we last processed events on the
51 * main event loop and this call calibrates that measurement.
53 NS_IMETHOD
WillParse(void) = 0;
56 * This method gets called when the parser begins the process
57 * of building the content model via the content sink.
59 * Default implementation provided since the sink should have the option of
60 * doing nothing in response to this call.
64 NS_IMETHOD
WillBuildModel(nsDTDMode aDTDMode
) { return NS_OK
; }
67 * This method gets called when the parser concludes the process
68 * of building the content model via the content sink.
70 * Default implementation provided since the sink should have the option of
71 * doing nothing in response to this call.
75 NS_IMETHOD
DidBuildModel(bool aTerminated
) { return NS_OK
; }
78 * This method gets called when the parser gets i/o blocked,
79 * and wants to notify the sink that it may be a while before
80 * more data is available.
84 NS_IMETHOD
WillInterrupt(void) = 0;
87 * This method gets called when the parser i/o gets unblocked,
88 * and we're about to start dumping content again to the sink.
90 virtual void WillResume() = 0;
93 * This method returns nullptr unless `this` can
94 * be cast as nsHtml5TreeOpExecutor.
96 virtual nsIContentSink
* AsExecutor() { return nullptr; }
99 * This method gets called by the parser so that the content
100 * sink can retain a reference to the parser. The expectation
101 * is that the content sink will drop the reference when it
102 * gets the DidBuildModel notification i.e. when parsing is done.
104 NS_IMETHOD
SetParser(nsParserBase
* aParser
) = 0;
107 * Flush content so that the content model is in sync with the state
110 * @param aType the type of flush to perform
112 virtual void FlushPendingNotifications(mozilla::FlushType aType
) = 0;
115 * Set the document character set. This should be passed on to the
118 virtual void SetDocumentCharset(NotNull
<const Encoding
*> aEncoding
) = 0;
121 * Returns the target object (often a document object) into which
122 * the content built by this content sink is being added, if any
123 * (IOW, may return null).
125 virtual nsISupports
* GetTarget() = 0;
128 * Returns true if there's currently script executing that we need to hold
131 virtual bool IsScriptExecuting() { return false; }
134 * Posts a runnable that continues parsing.
136 virtual void ContinueInterruptedParsingAsync() {}
138 virtual void InitialTranslationCompleted() {}
141 NS_DEFINE_STATIC_IID_ACCESSOR(nsIContentSink
, NS_ICONTENT_SINK_IID
)
143 #endif /* nsIContentSink_h___ */