1 /* -*- Mode: C++; tab-width: 4; 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/. */
6 #ifndef nsXULContentSink_h__
7 #define nsXULContentSink_h__
9 #include "mozilla/Attributes.h"
10 #include "nsIExpatSink.h"
11 #include "nsIWeakReferenceUtils.h"
12 #include "nsIXMLContentSink.h"
13 #include "nsNodeInfoManager.h"
14 #include "nsXULElement.h"
17 class nsIScriptSecurityManager
;
19 class nsXULPrototypeDocument
;
20 class nsXULPrototypeElement
;
21 class nsXULPrototypeNode
;
23 class XULContentSinkImpl final
: public nsIXMLContentSink
, public nsIExpatSink
{
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(XULContentSinkImpl
,
35 NS_IMETHOD
WillParse(void) override
{ return NS_OK
; }
36 NS_IMETHOD
DidBuildModel(bool aTerminated
) override
;
37 NS_IMETHOD
WillInterrupt(void) override
;
38 void WillResume() override
;
39 NS_IMETHOD
SetParser(nsParserBase
* aParser
) override
;
40 virtual void FlushPendingNotifications(mozilla::FlushType aType
) override
{}
41 virtual void SetDocumentCharset(NotNull
<const Encoding
*> aEncoding
) override
;
42 virtual nsISupports
* GetTarget() override
;
45 * Initialize the content sink, giving it a document with which to communicate
46 * with the outside world, and an nsXULPrototypeDocument to build.
48 nsresult
Init(mozilla::dom::Document
* aDocument
,
49 nsXULPrototypeDocument
* aPrototype
);
52 virtual ~XULContentSinkImpl();
60 nsresult
AddAttributes(const char16_t
** aAttributes
, const uint32_t aAttrLen
,
61 nsXULPrototypeElement
* aElement
);
63 nsresult
OpenRoot(const char16_t
** aAttributes
, const uint32_t aAttrLen
,
64 mozilla::dom::NodeInfo
* aNodeInfo
);
66 nsresult
OpenTag(const char16_t
** aAttributes
, const uint32_t aAttrLen
,
67 const uint32_t aLineNumber
,
68 mozilla::dom::NodeInfo
* aNodeInfo
);
70 // If OpenScript returns NS_OK and after it returns our state is eInScript,
71 // that means that we created a prototype script and stuck it on
72 // mContextStack. If NS_OK is returned but the state is still
73 // eInDocumentElement then we didn't create a prototype script (e.g. the
74 // script had an unknown type), and the caller should create a prototype
76 nsresult
OpenScript(const char16_t
** aAttributes
, const uint32_t aLineNumber
);
78 static bool IsDataInBuffer(char16_t
* aBuffer
, int32_t aLength
);
81 nsresult
FlushText(bool aCreateTextNode
= true);
82 nsresult
AddText(const char16_t
* aText
, int32_t aLength
);
84 RefPtr
<nsNodeInfoManager
> mNodeInfoManager
;
86 nsresult
NormalizeAttributeString(const char16_t
* aExpatName
,
90 enum State
{ eInProlog
, eInDocumentElement
, eInScript
, eInEpilog
};
95 // content stack management
99 RefPtr
<nsXULPrototypeNode
> mNode
;
100 // a LOT of nodes have children; preallocate for 8
101 nsPrototypeArray mChildren
;
104 Entry(RefPtr
<nsXULPrototypeNode
>&& aNode
, State aState
, Entry
* aNext
)
105 : mNode(std::move(aNode
)),
118 int32_t Depth() { return mDepth
; }
120 void Push(RefPtr
<nsXULPrototypeNode
>&& aNode
, State aState
);
121 nsresult
Pop(State
* aState
);
123 nsresult
GetTopNode(RefPtr
<nsXULPrototypeNode
>& aNode
);
124 nsresult
GetTopChildren(nsPrototypeArray
** aChildren
);
128 void Traverse(nsCycleCollectionTraversalCallback
& aCallback
);
131 friend class ContextStack
;
132 ContextStack mContextStack
;
134 nsWeakPtr mDocument
; // [OWNER]
135 nsCOMPtr
<nsIURI
> mDocumentURL
; // [OWNER]
137 RefPtr
<nsXULPrototypeDocument
> mPrototype
; // [OWNER]
139 RefPtr
<nsParserBase
> mParser
;
140 nsCOMPtr
<nsIScriptSecurityManager
> mSecMan
;
143 #endif /* nsXULContentSink_h__ */