no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / parser / prototype / PrototypeDocumentParser.h
blob3e7935bffc02bddb65f4f1e0722efa9c2d87510b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_parser_PrototypeDocumentParser_h
8 #define mozilla_parser_PrototypeDocumentParser_h
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsIContentSink.h"
12 #include "nsIParser.h"
13 #include "nsXULPrototypeDocument.h"
15 class nsIExpatSink;
17 namespace mozilla {
18 namespace dom {
19 class PrototypeDocumentContentSink;
20 } // namespace dom
21 } // namespace mozilla
23 namespace mozilla {
24 namespace parser {
26 // The PrototypeDocumentParser is more of a stub than a real parser. It is
27 // responsible for loading an nsXULPrototypeDocument either from the startup
28 // cache or creating a new prototype from the original source if a cached
29 // version does not exist. Once the parser finishes loading the prototype it
30 // will notify the content sink.
31 class PrototypeDocumentParser final : public nsIParser,
32 public nsIStreamListener {
33 public:
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
36 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PrototypeDocumentParser, nsIParser)
38 explicit PrototypeDocumentParser(nsIURI* aDocumentURI,
39 dom::Document* aDocument);
41 NS_DECL_NSIREQUESTOBSERVER
42 NS_DECL_NSISTREAMLISTENER
44 // Start nsIParser
45 // Ideally, this would just implement nsBaseParser since most of these are
46 // stubs, but Document.h expects an nsIParser.
47 NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink) override;
49 NS_IMETHOD_(nsIContentSink*) GetContentSink() override;
51 NS_IMETHOD_(void) GetCommand(nsCString& aCommand) override {}
53 NS_IMETHOD_(void) SetCommand(const char* aCommand) override {}
55 NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand) override {}
57 virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding,
58 int32_t aSource,
59 bool aForceAutoDetection) override {}
61 virtual nsIStreamListener* GetStreamListener() override;
63 NS_IMETHOD ContinueInterruptedParsing() override {
64 return NS_ERROR_NOT_IMPLEMENTED;
67 NS_IMETHOD_(void) BlockParser() override {}
69 NS_IMETHOD_(void) UnblockParser() override {}
71 NS_IMETHOD_(void) ContinueInterruptedParsingAsync() override {}
73 NS_IMETHOD_(bool) IsParserEnabled() override { return true; }
75 NS_IMETHOD_(bool) IsComplete() override;
77 NS_IMETHOD Parse(nsIURI* aURL) override;
79 NS_IMETHOD Terminate() override { return NS_ERROR_NOT_IMPLEMENTED; }
81 virtual bool IsInsertionPointDefined() override { return false; }
83 void IncrementScriptNestingLevel() final {}
85 void DecrementScriptNestingLevel() final {}
87 bool HasNonzeroScriptNestingLevel() const final { return false; }
89 virtual bool IsScriptCreated() override { return false; }
91 // End nsIParser
93 private:
94 virtual ~PrototypeDocumentParser();
96 protected:
97 nsresult PrepareToLoadPrototype(nsIURI* aURI,
98 nsIPrincipal* aDocumentPrincipal,
99 nsIParser** aResult);
101 // This is invoked whenever the prototype for this document is loaded
102 // and should be walked, regardless of whether the XUL cache is
103 // disabled, whether the protototype was loaded, whether the
104 // prototype was loaded from the cache or created by parsing the
105 // actual XUL source, etc.
106 nsresult OnPrototypeLoadDone();
108 nsCOMPtr<nsIURI> mDocumentURI;
109 RefPtr<dom::PrototypeDocumentContentSink> mOriginalSink;
110 RefPtr<dom::Document> mDocument;
112 // The XML parser that data is forwarded to when the prototype does not exist
113 // and must be parsed from disk.
114 nsCOMPtr<nsIStreamListener> mStreamListener;
116 // The current prototype that we are walking to construct the
117 // content model.
118 RefPtr<nsXULPrototypeDocument> mCurrentPrototype;
120 // True if there was a prototype in the cache and it finished loading
121 // already.
122 bool mPrototypeAlreadyLoaded;
124 // True after the parser has notified the content sink that it is done.
125 bool mIsComplete;
128 } // namespace parser
129 } // namespace mozilla
131 #endif // mozilla_parser_PrototypeDocumentParser_h