Source code

Revision control

Other Tools

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/. */
5
6
#ifndef nsXULPrototypeDocument_h__
7
#define nsXULPrototypeDocument_h__
8
9
#include "js/TracingAPI.h"
10
#include "mozilla/Attributes.h"
11
#include "nsCOMArray.h"
12
#include "nsCOMPtr.h"
13
#include "nsTArray.h"
14
#include "nsISerializable.h"
15
#include "nsCycleCollectionParticipant.h"
16
#include <functional>
17
#include "mozilla/dom/Element.h"
18
19
class nsAtom;
20
class nsIPrincipal;
21
class nsIURI;
22
class nsNodeInfoManager;
23
class nsXULPrototypeElement;
24
class nsXULPrototypePI;
25
26
/**
27
* A "prototype" document that stores shared document information
28
* for the XUL cache.
29
* Among other things, stores the tree of nsXULPrototype*
30
* objects, from which the real DOM tree is built later in
31
* PrototypeDocumentContentSink::ResumeWalk.
32
*/
33
class nsXULPrototypeDocument final : public nsISerializable {
34
public:
35
static nsresult Create(nsIURI* aURI, nsXULPrototypeDocument** aResult);
36
37
typedef std::function<void()> Callback;
38
39
// nsISupports interface
40
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
41
42
// nsISerializable interface
43
NS_DECL_NSISERIALIZABLE
44
45
nsresult InitPrincipal(nsIURI* aURI, nsIPrincipal* aPrincipal);
46
nsIURI* GetURI();
47
48
/**
49
* Get/set the root nsXULPrototypeElement of the document.
50
*/
51
nsXULPrototypeElement* GetRootElement();
52
void SetRootElement(nsXULPrototypeElement* aElement);
53
54
/**
55
* Add a processing instruction to the prolog. Note that only
56
* PI nodes are currently stored in a XUL prototype document's
57
* prolog and that they're handled separately from the rest of
58
* prototype node tree.
59
*
60
* @param aPI an already adrefed PI proto to add. This method takes
61
* ownership of the passed PI.
62
*/
63
nsresult AddProcessingInstruction(nsXULPrototypePI* aPI);
64
/**
65
* @note GetProcessingInstructions retains the ownership (the PI
66
* protos only get deleted when the proto document is deleted)
67
*/
68
const nsTArray<RefPtr<nsXULPrototypePI> >& GetProcessingInstructions() const;
69
70
nsIPrincipal* DocumentPrincipal();
71
void SetDocumentPrincipal(nsIPrincipal* aPrincipal);
72
73
/**
74
* If current prototype document has not yet finished loading,
75
* appends aDocument to the list of documents to notify (via
76
* PrototypeDocumentContentSink::OnPrototypeLoadDone()) and
77
* sets aLoaded to false. Otherwise sets aLoaded to true.
78
*/
79
nsresult AwaitLoadDone(Callback&& aCallback, bool* aResult);
80
81
/**
82
* Notifies each document registered via AwaitLoadDone on this
83
* prototype document that the prototype has finished loading.
84
* The notification is performed by calling
85
* PrototypeDocumentContentSink::OnPrototypeLoadDone on the
86
* registered documents.
87
*/
88
nsresult NotifyLoadDone();
89
90
nsNodeInfoManager* GetNodeInfoManager();
91
92
void MarkInCCGeneration(uint32_t aCCGeneration);
93
94
NS_DECL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument)
95
96
void TraceProtos(JSTracer* aTrc);
97
98
bool WasL10nCached() { return mWasL10nCached; };
99
100
void SetIsL10nCached();
101
void RebuildPrototypeFromElement(nsXULPrototypeElement* aPrototype,
102
mozilla::dom::Element* aElement, bool aDeep);
103
void RebuildL10nPrototype(mozilla::dom::Element* aElement, bool aDeep);
104
105
protected:
106
nsCOMPtr<nsIURI> mURI;
107
RefPtr<nsXULPrototypeElement> mRoot;
108
nsTArray<RefPtr<nsXULPrototypePI> > mProcessingInstructions;
109
110
bool mLoaded;
111
nsTArray<Callback> mPrototypeWaiters;
112
113
RefPtr<nsNodeInfoManager> mNodeInfoManager;
114
115
uint32_t mCCGeneration;
116
uint32_t mGCNumber;
117
118
nsXULPrototypeDocument();
119
virtual ~nsXULPrototypeDocument();
120
nsresult Init();
121
122
friend NS_IMETHODIMP NS_NewXULPrototypeDocument(
123
nsXULPrototypeDocument** aResult);
124
125
static uint32_t gRefCnt;
126
bool mWasL10nCached;
127
};
128
129
#endif // nsXULPrototypeDocument_h__