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
WillBuildModel(nsDTDMode aDTDMode
) override
;
37 NS_IMETHOD
DidBuildModel(bool aTerminated
) override
;
38 NS_IMETHOD
WillInterrupt(void) override
;
39 NS_IMETHOD
WillResume(void) override
;
40 NS_IMETHOD
SetParser(nsParserBase
* aParser
) override
;
41 virtual void FlushPendingNotifications(mozilla::FlushType aType
) override
{}
42 virtual void SetDocumentCharset(NotNull
<const Encoding
*> aEncoding
) override
;
43 virtual nsISupports
* GetTarget() override
;
46 * Initialize the content sink, giving it a document with which to communicate
47 * with the outside world, and an nsXULPrototypeDocument to build.
49 nsresult
Init(mozilla::dom::Document
* aDocument
,
50 nsXULPrototypeDocument
* aPrototype
);
53 virtual ~XULContentSinkImpl();
61 nsresult
AddAttributes(const char16_t
** aAttributes
, const uint32_t aAttrLen
,
62 nsXULPrototypeElement
* aElement
);
64 nsresult
OpenRoot(const char16_t
** aAttributes
, const uint32_t aAttrLen
,
65 mozilla::dom::NodeInfo
* aNodeInfo
);
67 nsresult
OpenTag(const char16_t
** aAttributes
, const uint32_t aAttrLen
,
68 const uint32_t aLineNumber
,
69 mozilla::dom::NodeInfo
* aNodeInfo
);
71 // If OpenScript returns NS_OK and after it returns our state is eInScript,
72 // that means that we created a prototype script and stuck it on
73 // mContextStack. If NS_OK is returned but the state is still
74 // eInDocumentElement then we didn't create a prototype script (e.g. the
75 // script had an unknown type), and the caller should create a prototype
77 nsresult
OpenScript(const char16_t
** aAttributes
, const uint32_t aLineNumber
);
79 static bool IsDataInBuffer(char16_t
* aBuffer
, int32_t aLength
);
82 nsresult
FlushText(bool aCreateTextNode
= true);
83 nsresult
AddText(const char16_t
* aText
, int32_t aLength
);
85 RefPtr
<nsNodeInfoManager
> mNodeInfoManager
;
87 nsresult
NormalizeAttributeString(const char16_t
* aExpatName
,
91 enum State
{ eInProlog
, eInDocumentElement
, eInScript
, eInEpilog
};
96 // content stack management
100 RefPtr
<nsXULPrototypeNode
> mNode
;
101 // a LOT of nodes have children; preallocate for 8
102 nsPrototypeArray mChildren
;
105 Entry(RefPtr
<nsXULPrototypeNode
>&& aNode
, State aState
, Entry
* aNext
)
106 : mNode(std::move(aNode
)),
119 int32_t Depth() { return mDepth
; }
121 void Push(RefPtr
<nsXULPrototypeNode
>&& aNode
, State aState
);
122 nsresult
Pop(State
* aState
);
124 nsresult
GetTopNode(RefPtr
<nsXULPrototypeNode
>& aNode
);
125 nsresult
GetTopChildren(nsPrototypeArray
** aChildren
);
129 void Traverse(nsCycleCollectionTraversalCallback
& aCallback
);
132 friend class ContextStack
;
133 ContextStack mContextStack
;
135 nsWeakPtr mDocument
; // [OWNER]
136 nsCOMPtr
<nsIURI
> mDocumentURL
; // [OWNER]
138 RefPtr
<nsXULPrototypeDocument
> mPrototype
; // [OWNER]
140 RefPtr
<nsParserBase
> mParser
;
141 nsCOMPtr
<nsIScriptSecurityManager
> mSecMan
;
144 #endif /* nsXULContentSink_h__ */