diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/xul/nsXULPrototypeDocument.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/xul/nsXULPrototypeDocument.h')
-rw-r--r-- | dom/xul/nsXULPrototypeDocument.h | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/dom/xul/nsXULPrototypeDocument.h b/dom/xul/nsXULPrototypeDocument.h new file mode 100644 index 0000000000..511f4b3e2b --- /dev/null +++ b/dom/xul/nsXULPrototypeDocument.h @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsXULPrototypeDocument_h__ +#define nsXULPrototypeDocument_h__ + +#include "js/TracingAPI.h" +#include "mozilla/Attributes.h" +#include "nsCOMArray.h" +#include "nsCOMPtr.h" +#include "nsTArray.h" +#include "nsISerializable.h" +#include "nsCycleCollectionParticipant.h" +#include <functional> + +class nsAtom; +class nsIPrincipal; +class nsIURI; +class nsNodeInfoManager; +class nsXULPrototypeElement; +class nsXULPrototypePI; + +namespace mozilla::dom { +class Element; +} + +/** + * A "prototype" document that stores shared document information + * for the XUL cache. + * Among other things, stores the tree of nsXULPrototype* + * objects, from which the real DOM tree is built later in + * PrototypeDocumentContentSink::ResumeWalk. + */ +class nsXULPrototypeDocument final : public nsISerializable { + public: + using Callback = std::function<void()>; + + // nsISupports interface + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + + // nsISerializable interface + NS_DECL_NSISERIALIZABLE + + nsresult InitPrincipal(nsIURI* aURI, nsIPrincipal* aPrincipal); + nsIURI* GetURI(); + + /** + * Get/set the root nsXULPrototypeElement of the document. + */ + nsXULPrototypeElement* GetRootElement(); + void SetRootElement(nsXULPrototypeElement* aElement); + + /** + * Add a processing instruction to the prolog. Note that only + * PI nodes are currently stored in a XUL prototype document's + * prolog and that they're handled separately from the rest of + * prototype node tree. + * + * @param aPI an already adrefed PI proto to add. This method takes + * ownership of the passed PI. + */ + nsresult AddProcessingInstruction(nsXULPrototypePI* aPI); + /** + * @note GetProcessingInstructions retains the ownership (the PI + * protos only get deleted when the proto document is deleted) + */ + const nsTArray<RefPtr<nsXULPrototypePI> >& GetProcessingInstructions() const; + + nsIPrincipal* DocumentPrincipal(); + void SetDocumentPrincipal(nsIPrincipal* aPrincipal); + + /** + * If current prototype document has not yet finished loading, + * appends aDocument to the list of documents to notify (via + * PrototypeDocumentContentSink::OnPrototypeLoadDone()) and + * sets aLoaded to false. Otherwise sets aLoaded to true. + */ + nsresult AwaitLoadDone(Callback&& aCallback, bool* aResult); + + /** + * Notifies each document registered via AwaitLoadDone on this + * prototype document that the prototype has finished loading. + * The notification is performed by calling + * PrototypeDocumentContentSink::OnPrototypeLoadDone on the + * registered documents. + */ + nsresult NotifyLoadDone(); + + nsNodeInfoManager* GetNodeInfoManager(); + + void MarkInCCGeneration(uint32_t aCCGeneration); + + NS_DECL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument) + + bool WasL10nCached() { return mWasL10nCached; }; + + void SetIsL10nCached(bool aIsCached); + void RebuildPrototypeFromElement(nsXULPrototypeElement* aPrototype, + mozilla::dom::Element* aElement, bool aDeep); + void RebuildL10nPrototype(mozilla::dom::Element* aElement, bool aDeep); + + protected: + nsCOMPtr<nsIURI> mURI; + RefPtr<nsXULPrototypeElement> mRoot; + nsTArray<RefPtr<nsXULPrototypePI> > mProcessingInstructions; + + bool mLoaded; + nsTArray<Callback> mPrototypeWaiters; + + RefPtr<nsNodeInfoManager> mNodeInfoManager; + + uint32_t mCCGeneration; + + nsXULPrototypeDocument(); + virtual ~nsXULPrototypeDocument(); + nsresult Init(); + + friend NS_IMETHODIMP NS_NewXULPrototypeDocument( + nsXULPrototypeDocument** aResult); + + static uint32_t gRefCnt; + bool mWasL10nCached; +}; + +#endif // nsXULPrototypeDocument_h__ |