1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Chris Waterson <waterson@netscape.com>
24 : * L. David Baron <dbaron@dbaron.org>
25 : * Ben Goodger <ben@netscape.com>
26 : * Mark Hammond <mhammond@skippinet.com.au>
27 : *
28 : * Alternatively, the contents of this file may be used under the terms of
29 : * either of the GNU General Public License Version 2 or later (the "GPL"),
30 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 : * in which case the provisions of the GPL or the LGPL are applicable instead
32 : * of those above. If you wish to allow use of your version of this file only
33 : * under the terms of either the GPL or the LGPL, and not to allow others to
34 : * use your version of this file under the terms of the MPL, indicate your
35 : * decision by deleting the provisions above and replace them with the notice
36 : * and other provisions required by the GPL or the LGPL. If you do not delete
37 : * the provisions above, a recipient may use your version of this file under
38 : * the terms of any one of the MPL, the GPL or the LGPL.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : #ifndef nsXULPrototypeDocument_h__
43 : #define nsXULPrototypeDocument_h__
44 :
45 : #include "nsAutoPtr.h"
46 : #include "nsCOMArray.h"
47 : #include "nsCOMPtr.h"
48 : #include "nsTArray.h"
49 : #include "nsIScriptGlobalObjectOwner.h"
50 : #include "nsISerializable.h"
51 : #include "nsIDocument.h"
52 : #include "nsCycleCollectionParticipant.h"
53 :
54 : class nsIAtom;
55 : class nsIPrincipal;
56 : class nsIURI;
57 : class nsNodeInfoManager;
58 : class nsXULDocument;
59 : class nsXULPrototypeElement;
60 : class nsXULPrototypePI;
61 : class nsXULPDGlobalObject;
62 :
63 : /**
64 : * A "prototype" document that stores shared document information
65 : * for the XUL cache.
66 : * Among other things, stores the tree of nsXULPrototype*
67 : * objects, from which the real DOM tree is built later in
68 : * nsXULDocument::ResumeWalk.
69 : */
70 : class nsXULPrototypeDocument : public nsIScriptGlobalObjectOwner,
71 : public nsISerializable
72 : {
73 : public:
74 : static nsresult
75 : Create(nsIURI* aURI, nsXULPrototypeDocument** aResult);
76 :
77 : // nsISupports interface
78 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
79 :
80 : // nsISerializable interface
81 : NS_DECL_NSISERIALIZABLE
82 :
83 : nsresult InitPrincipal(nsIURI* aURI, nsIPrincipal* aPrincipal);
84 : nsIURI* GetURI();
85 :
86 : /**
87 : * Get/set the root nsXULPrototypeElement of the document.
88 : */
89 : nsXULPrototypeElement* GetRootElement();
90 : void SetRootElement(nsXULPrototypeElement* aElement);
91 :
92 : /**
93 : * Add a processing instruction to the prolog. Note that only
94 : * PI nodes are currently stored in a XUL prototype document's
95 : * prolog and that they're handled separately from the rest of
96 : * prototype node tree.
97 : *
98 : * @param aPI an already adrefed PI proto to add. This method takes
99 : * ownership of the passed PI.
100 : */
101 : nsresult AddProcessingInstruction(nsXULPrototypePI* aPI);
102 : /**
103 : * @note GetProcessingInstructions retains the ownership (the PI
104 : * protos only get deleted when the proto document is deleted)
105 : */
106 : const nsTArray<nsRefPtr<nsXULPrototypePI> >& GetProcessingInstructions() const;
107 :
108 : /**
109 : * Access the array of style overlays for this document.
110 : *
111 : * Style overlays are stylesheets that need to be applied to the
112 : * document, but are not referenced from within the document. They
113 : * are currently obtained from the chrome registry via
114 : * nsIXULOverlayProvider::getStyleOverlays.)
115 : */
116 : void AddStyleSheetReference(nsIURI* aStyleSheet);
117 : const nsCOMArray<nsIURI>& GetStyleSheetReferences() const;
118 :
119 : /**
120 : * Access HTTP header data.
121 : * @note Not implemented.
122 : */
123 : NS_IMETHOD GetHeaderData(nsIAtom* aField, nsAString& aData) const;
124 : NS_IMETHOD SetHeaderData(nsIAtom* aField, const nsAString& aData);
125 :
126 : nsIPrincipal *DocumentPrincipal();
127 : void SetDocumentPrincipal(nsIPrincipal *aPrincipal);
128 :
129 : /**
130 : * If current prototype document has not yet finished loading,
131 : * appends aDocument to the list of documents to notify (via
132 : * nsXULDocument::OnPrototypeLoadDone()) and sets aLoaded to false.
133 : * Otherwise sets aLoaded to true.
134 : */
135 : nsresult AwaitLoadDone(nsXULDocument* aDocument, bool* aResult);
136 :
137 : /**
138 : * Notifies each document registered via AwaitLoadDone on this
139 : * prototype document that the prototype has finished loading.
140 : * The notification is performed by calling
141 : * nsIXULDocument::OnPrototypeLoadDone on the registered documents.
142 : */
143 : nsresult NotifyLoadDone();
144 :
145 : nsNodeInfoManager *GetNodeInfoManager();
146 :
147 : // nsIScriptGlobalObjectOwner methods
148 : virtual nsIScriptGlobalObject* GetScriptGlobalObject();
149 :
150 0 : void MarkInCCGeneration(PRUint32 aCCGeneration)
151 : {
152 0 : mCCGeneration = aCCGeneration;
153 0 : }
154 :
155 1464 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPrototypeDocument,
156 : nsIScriptGlobalObjectOwner)
157 :
158 : protected:
159 : nsCOMPtr<nsIURI> mURI;
160 : nsRefPtr<nsXULPrototypeElement> mRoot;
161 : nsTArray<nsRefPtr<nsXULPrototypePI> > mProcessingInstructions;
162 : nsCOMArray<nsIURI> mStyleSheetReferences;
163 :
164 : nsRefPtr<nsXULPDGlobalObject> mGlobalObject;
165 :
166 : bool mLoaded;
167 : nsTArray< nsRefPtr<nsXULDocument> > mPrototypeWaiters;
168 :
169 : nsRefPtr<nsNodeInfoManager> mNodeInfoManager;
170 :
171 : PRUint32 mCCGeneration;
172 :
173 : nsXULPrototypeDocument();
174 : virtual ~nsXULPrototypeDocument();
175 : nsresult Init();
176 :
177 : friend NS_IMETHODIMP
178 : NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult);
179 :
180 : nsXULPDGlobalObject *NewXULPDGlobalObject();
181 :
182 : static nsIPrincipal* gSystemPrincipal;
183 : static nsXULPDGlobalObject* gSystemGlobal;
184 : static PRUint32 gRefCnt;
185 :
186 : friend class nsXULPDGlobalObject;
187 : };
188 :
189 : #endif // nsXULPrototypeDocument_h__
|