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
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/
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
15 * The Original Code is Mozilla Communicator client code.
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.
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>
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.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef nsXULPrototypeDocument_h__
43 #define nsXULPrototypeDocument_h__
45 #include "nsAutoPtr.h"
46 #include "nsCOMArray.h"
49 #include "nsIScriptGlobalObjectOwner.h"
50 #include "nsISerializable.h"
51 #include "nsIDocument.h"
52 #include "nsCycleCollectionParticipant.h"
57 class nsNodeInfoManager
;
59 class nsXULPrototypeElement
;
60 class nsXULPrototypePI
;
61 class nsXULPDGlobalObject
;
64 * A "prototype" document that stores shared document information
66 * Among other things, stores the tree of nsXULPrototype*
67 * objects, from which the real DOM tree is built later in
68 * nsXULDocument::ResumeWalk.
70 class nsXULPrototypeDocument
: public nsIScriptGlobalObjectOwner
,
71 public nsISerializable
75 Create(nsIURI
* aURI
, nsXULPrototypeDocument
** aResult
);
77 // nsISupports interface
78 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
80 // nsISerializable interface
81 NS_DECL_NSISERIALIZABLE
83 nsresult
InitPrincipal(nsIURI
* aURI
, nsIPrincipal
* aPrincipal
);
87 * Get/set the root nsXULPrototypeElement of the document.
89 nsXULPrototypeElement
* GetRootElement();
90 void SetRootElement(nsXULPrototypeElement
* aElement
);
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.
98 * @param aPI an already adrefed PI proto to add. This method takes
99 * ownership of the passed PI.
101 nsresult
AddProcessingInstruction(nsXULPrototypePI
* aPI
);
103 * @note GetProcessingInstructions retains the ownership (the PI
104 * protos only get deleted when the proto document is deleted)
106 const nsTArray
<nsRefPtr
<nsXULPrototypePI
> >& GetProcessingInstructions() const;
109 * Access the array of style overlays for this document.
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.)
116 void AddStyleSheetReference(nsIURI
* aStyleSheet
);
117 const nsCOMArray
<nsIURI
>& GetStyleSheetReferences() const;
120 * Access HTTP header data.
121 * @note Not implemented.
123 NS_IMETHOD
GetHeaderData(nsIAtom
* aField
, nsAString
& aData
) const;
124 NS_IMETHOD
SetHeaderData(nsIAtom
* aField
, const nsAString
& aData
);
126 nsIPrincipal
*DocumentPrincipal();
127 void SetDocumentPrincipal(nsIPrincipal
*aPrincipal
);
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 PR_FALSE.
133 * Otherwise sets aLoaded to PR_TRUE.
135 nsresult
AwaitLoadDone(nsXULDocument
* aDocument
, PRBool
* aResult
);
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.
143 nsresult
NotifyLoadDone();
145 nsNodeInfoManager
*GetNodeInfoManager();
147 // nsIScriptGlobalObjectOwner methods
148 virtual nsIScriptGlobalObject
* GetScriptGlobalObject();
150 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPrototypeDocument
,
151 nsIScriptGlobalObjectOwner
)
154 nsCOMPtr
<nsIURI
> mURI
;
155 nsRefPtr
<nsXULPrototypeElement
> mRoot
;
156 nsTArray
<nsRefPtr
<nsXULPrototypePI
> > mProcessingInstructions
;
157 nsCOMArray
<nsIURI
> mStyleSheetReferences
;
159 nsRefPtr
<nsXULPDGlobalObject
> mGlobalObject
;
161 PRPackedBool mLoaded
;
162 nsTArray
< nsRefPtr
<nsXULDocument
> > mPrototypeWaiters
;
164 nsRefPtr
<nsNodeInfoManager
> mNodeInfoManager
;
166 nsXULPrototypeDocument();
167 virtual ~nsXULPrototypeDocument();
171 NS_NewXULPrototypeDocument(nsXULPrototypeDocument
** aResult
);
173 nsXULPDGlobalObject
*NewXULPDGlobalObject();
175 static nsIPrincipal
* gSystemPrincipal
;
176 static nsXULPDGlobalObject
* gSystemGlobal
;
177 static PRUint32 gRefCnt
;
179 friend class nsXULPDGlobalObject
;
182 #endif // nsXULPrototypeDocument_h__