/src/mozilla-central/parser/htmlparser/nsExpatDriver.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; 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/. */ |
5 | | |
6 | | #ifndef NS_EXPAT_DRIVER__ |
7 | | #define NS_EXPAT_DRIVER__ |
8 | | |
9 | | #include "expat_config.h" |
10 | | #include "expat.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsString.h" |
13 | | #include "nsIDTD.h" |
14 | | #include "nsITokenizer.h" |
15 | | #include "nsIInputStream.h" |
16 | | #include "nsIParser.h" |
17 | | #include "nsCycleCollectionParticipant.h" |
18 | | |
19 | | class nsIExpatSink; |
20 | | struct nsCatalogData; |
21 | | |
22 | | class nsExpatDriver : public nsIDTD, |
23 | | public nsITokenizer |
24 | | { |
25 | | virtual ~nsExpatDriver(); |
26 | | |
27 | | public: |
28 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
29 | | NS_DECL_NSIDTD |
30 | | NS_DECL_NSITOKENIZER |
31 | | NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD) |
32 | | |
33 | | nsExpatDriver(); |
34 | | |
35 | | int HandleExternalEntityRef(const char16_t *aOpenEntityNames, |
36 | | const char16_t *aBase, |
37 | | const char16_t *aSystemId, |
38 | | const char16_t *aPublicId); |
39 | | nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts); |
40 | | nsresult HandleEndElement(const char16_t *aName); |
41 | | nsresult HandleCharacterData(const char16_t *aCData, const uint32_t aLength); |
42 | | nsresult HandleComment(const char16_t *aName); |
43 | | nsresult HandleProcessingInstruction(const char16_t *aTarget, |
44 | | const char16_t *aData); |
45 | | nsresult HandleXMLDeclaration(const char16_t *aVersion, |
46 | | const char16_t *aEncoding, |
47 | | int32_t aStandalone); |
48 | | nsresult HandleDefault(const char16_t *aData, const uint32_t aLength); |
49 | | nsresult HandleStartCdataSection(); |
50 | | nsresult HandleEndCdataSection(); |
51 | | nsresult HandleStartDoctypeDecl(const char16_t* aDoctypeName, |
52 | | const char16_t* aSysid, |
53 | | const char16_t* aPubid, |
54 | | bool aHasInternalSubset); |
55 | | nsresult HandleEndDoctypeDecl(); |
56 | | |
57 | | private: |
58 | | // Load up an external stream to get external entity information |
59 | | nsresult OpenInputStreamFromExternalDTD(const char16_t* aFPIStr, |
60 | | const char16_t* aURLStr, |
61 | | const char16_t* aBaseURL, |
62 | | nsIInputStream** aStream, |
63 | | nsAString& aAbsURL); |
64 | | |
65 | | /** |
66 | | * Pass a buffer to Expat. If Expat is blocked aBuffer should be null and |
67 | | * aLength should be 0. The result of the call will be stored in |
68 | | * mInternalState. Expat will parse as much of the buffer as it can and store |
69 | | * the rest in its internal buffer. |
70 | | * |
71 | | * @param aBuffer the buffer to pass to Expat. May be null. |
72 | | * @param aLength the length of the buffer to pass to Expat (in number of |
73 | | * char16_t's). Must be 0 if aBuffer is null and > 0 if |
74 | | * aBuffer is not null. |
75 | | * @param aIsFinal whether there will definitely not be any more new buffers |
76 | | * passed in to ParseBuffer |
77 | | * @param aConsumed [out] the number of PRUnichars that Expat consumed. This |
78 | | * doesn't include the PRUnichars that Expat stored in |
79 | | * its buffer but didn't parse yet. |
80 | | */ |
81 | | void ParseBuffer(const char16_t *aBuffer, uint32_t aLength, bool aIsFinal, |
82 | | uint32_t *aConsumed); |
83 | | nsresult HandleError(); |
84 | | |
85 | | void MaybeStopParser(nsresult aState); |
86 | | |
87 | | bool BlockedOrInterrupted() |
88 | 0 | { |
89 | 0 | return mInternalState == NS_ERROR_HTMLPARSER_BLOCK || |
90 | 0 | mInternalState == NS_ERROR_HTMLPARSER_INTERRUPTED; |
91 | 0 | } |
92 | | |
93 | | XML_Parser mExpatParser; |
94 | | nsString mLastLine; |
95 | | nsString mCDataText; |
96 | | // Various parts of a doctype |
97 | | nsString mDoctypeName; |
98 | | nsString mSystemID; |
99 | | nsString mPublicID; |
100 | | nsString mInternalSubset; |
101 | | bool mInCData; |
102 | | bool mInInternalSubset; |
103 | | bool mInExternalDTD; |
104 | | bool mMadeFinalCallToExpat; |
105 | | |
106 | | // Whether we're sure that we won't be getting more buffers to parse from |
107 | | // Necko |
108 | | bool mIsFinalChunk; |
109 | | |
110 | | nsresult mInternalState; |
111 | | |
112 | | // The length of the data in Expat's buffer (in number of PRUnichars). |
113 | | uint32_t mExpatBuffered; |
114 | | |
115 | | // These sinks all refer the same conceptual object. mOriginalSink is |
116 | | // identical with the nsIContentSink* passed to WillBuildModel, and exists |
117 | | // only to avoid QI-ing back to nsIContentSink*. |
118 | | nsCOMPtr<nsIContentSink> mOriginalSink; |
119 | | nsCOMPtr<nsIExpatSink> mSink; |
120 | | |
121 | | const nsCatalogData* mCatalogData; // weak |
122 | | nsString mURISpec; |
123 | | |
124 | | // Used for error reporting. |
125 | | uint64_t mInnerWindowID; |
126 | | }; |
127 | | |
128 | | #endif |