Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / xul / nsXULPrototypeDocument.h
blob511f4b3e2b63268edfafe63df2bbda55b19410db
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 nsXULPrototypeDocument_h__
7 #define nsXULPrototypeDocument_h__
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>
18 class nsAtom;
19 class nsIPrincipal;
20 class nsIURI;
21 class nsNodeInfoManager;
22 class nsXULPrototypeElement;
23 class nsXULPrototypePI;
25 namespace mozilla::dom {
26 class Element;
29 /**
30 * A "prototype" document that stores shared document information
31 * for the XUL cache.
32 * Among other things, stores the tree of nsXULPrototype*
33 * objects, from which the real DOM tree is built later in
34 * PrototypeDocumentContentSink::ResumeWalk.
36 class nsXULPrototypeDocument final : public nsISerializable {
37 public:
38 using Callback = std::function<void()>;
40 // nsISupports interface
41 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
43 // nsISerializable interface
44 NS_DECL_NSISERIALIZABLE
46 nsresult InitPrincipal(nsIURI* aURI, nsIPrincipal* aPrincipal);
47 nsIURI* GetURI();
49 /**
50 * Get/set the root nsXULPrototypeElement of the document.
52 nsXULPrototypeElement* GetRootElement();
53 void SetRootElement(nsXULPrototypeElement* aElement);
55 /**
56 * Add a processing instruction to the prolog. Note that only
57 * PI nodes are currently stored in a XUL prototype document's
58 * prolog and that they're handled separately from the rest of
59 * prototype node tree.
61 * @param aPI an already adrefed PI proto to add. This method takes
62 * ownership of the passed PI.
64 nsresult AddProcessingInstruction(nsXULPrototypePI* aPI);
65 /**
66 * @note GetProcessingInstructions retains the ownership (the PI
67 * protos only get deleted when the proto document is deleted)
69 const nsTArray<RefPtr<nsXULPrototypePI> >& GetProcessingInstructions() const;
71 nsIPrincipal* DocumentPrincipal();
72 void SetDocumentPrincipal(nsIPrincipal* aPrincipal);
74 /**
75 * If current prototype document has not yet finished loading,
76 * appends aDocument to the list of documents to notify (via
77 * PrototypeDocumentContentSink::OnPrototypeLoadDone()) and
78 * sets aLoaded to false. Otherwise sets aLoaded to true.
80 nsresult AwaitLoadDone(Callback&& aCallback, bool* aResult);
82 /**
83 * Notifies each document registered via AwaitLoadDone on this
84 * prototype document that the prototype has finished loading.
85 * The notification is performed by calling
86 * PrototypeDocumentContentSink::OnPrototypeLoadDone on the
87 * registered documents.
89 nsresult NotifyLoadDone();
91 nsNodeInfoManager* GetNodeInfoManager();
93 void MarkInCCGeneration(uint32_t aCCGeneration);
95 NS_DECL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument)
97 bool WasL10nCached() { return mWasL10nCached; };
99 void SetIsL10nCached(bool aIsCached);
100 void RebuildPrototypeFromElement(nsXULPrototypeElement* aPrototype,
101 mozilla::dom::Element* aElement, bool aDeep);
102 void RebuildL10nPrototype(mozilla::dom::Element* aElement, bool aDeep);
104 protected:
105 nsCOMPtr<nsIURI> mURI;
106 RefPtr<nsXULPrototypeElement> mRoot;
107 nsTArray<RefPtr<nsXULPrototypePI> > mProcessingInstructions;
109 bool mLoaded;
110 nsTArray<Callback> mPrototypeWaiters;
112 RefPtr<nsNodeInfoManager> mNodeInfoManager;
114 uint32_t mCCGeneration;
116 nsXULPrototypeDocument();
117 virtual ~nsXULPrototypeDocument();
118 nsresult Init();
120 friend NS_IMETHODIMP NS_NewXULPrototypeDocument(
121 nsXULPrototypeDocument** aResult);
123 static uint32_t gRefCnt;
124 bool mWasL10nCached;
127 #endif // nsXULPrototypeDocument_h__