michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NS_EXPAT_DRIVER__ michael@0: #define NS_EXPAT_DRIVER__ michael@0: michael@0: #include "expat_config.h" michael@0: #include "expat.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: #include "nsIDTD.h" michael@0: #include "nsITokenizer.h" michael@0: #include "nsIInputStream.h" michael@0: #include "nsIParser.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: michael@0: class nsIExpatSink; michael@0: class nsIExtendedExpatSink; michael@0: struct nsCatalogData; michael@0: michael@0: class nsExpatDriver : public nsIDTD, michael@0: public nsITokenizer michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_NSIDTD michael@0: NS_DECL_NSITOKENIZER michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD) michael@0: michael@0: nsExpatDriver(); michael@0: virtual ~nsExpatDriver(); michael@0: michael@0: int HandleExternalEntityRef(const char16_t *aOpenEntityNames, michael@0: const char16_t *aBase, michael@0: const char16_t *aSystemId, michael@0: const char16_t *aPublicId); michael@0: nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts); michael@0: nsresult HandleEndElement(const char16_t *aName); michael@0: nsresult HandleCharacterData(const char16_t *aCData, const uint32_t aLength); michael@0: nsresult HandleComment(const char16_t *aName); michael@0: nsresult HandleProcessingInstruction(const char16_t *aTarget, michael@0: const char16_t *aData); michael@0: nsresult HandleXMLDeclaration(const char16_t *aVersion, michael@0: const char16_t *aEncoding, michael@0: int32_t aStandalone); michael@0: nsresult HandleDefault(const char16_t *aData, const uint32_t aLength); michael@0: nsresult HandleStartCdataSection(); michael@0: nsresult HandleEndCdataSection(); michael@0: nsresult HandleStartDoctypeDecl(const char16_t* aDoctypeName, michael@0: const char16_t* aSysid, michael@0: const char16_t* aPubid, michael@0: bool aHasInternalSubset); michael@0: nsresult HandleEndDoctypeDecl(); michael@0: nsresult HandleStartNamespaceDecl(const char16_t* aPrefix, michael@0: const char16_t* aUri); michael@0: nsresult HandleEndNamespaceDecl(const char16_t* aPrefix); michael@0: nsresult HandleNotationDecl(const char16_t* aNotationName, michael@0: const char16_t* aBase, michael@0: const char16_t* aSysid, michael@0: const char16_t* aPubid); michael@0: nsresult HandleUnparsedEntityDecl(const char16_t* aEntityName, michael@0: const char16_t* aBase, michael@0: const char16_t* aSysid, michael@0: const char16_t* aPubid, michael@0: const char16_t* aNotationName); michael@0: michael@0: private: michael@0: // Load up an external stream to get external entity information michael@0: nsresult OpenInputStreamFromExternalDTD(const char16_t* aFPIStr, michael@0: const char16_t* aURLStr, michael@0: const char16_t* aBaseURL, michael@0: nsIInputStream** aStream, michael@0: nsAString& aAbsURL); michael@0: michael@0: /** michael@0: * Pass a buffer to Expat. If Expat is blocked aBuffer should be null and michael@0: * aLength should be 0. The result of the call will be stored in michael@0: * mInternalState. Expat will parse as much of the buffer as it can and store michael@0: * the rest in its internal buffer. michael@0: * michael@0: * @param aBuffer the buffer to pass to Expat. May be null. michael@0: * @param aLength the length of the buffer to pass to Expat (in number of michael@0: * char16_t's). Must be 0 if aBuffer is null and > 0 if michael@0: * aBuffer is not null. michael@0: * @param aIsFinal whether there will definitely not be any more new buffers michael@0: * passed in to ParseBuffer michael@0: * @param aConsumed [out] the number of PRUnichars that Expat consumed. This michael@0: * doesn't include the PRUnichars that Expat stored in michael@0: * its buffer but didn't parse yet. michael@0: */ michael@0: void ParseBuffer(const char16_t *aBuffer, uint32_t aLength, bool aIsFinal, michael@0: uint32_t *aConsumed); michael@0: nsresult HandleError(); michael@0: michael@0: void MaybeStopParser(nsresult aState); michael@0: michael@0: bool BlockedOrInterrupted() michael@0: { michael@0: return mInternalState == NS_ERROR_HTMLPARSER_BLOCK || michael@0: mInternalState == NS_ERROR_HTMLPARSER_INTERRUPTED; michael@0: } michael@0: michael@0: XML_Parser mExpatParser; michael@0: nsString mLastLine; michael@0: nsString mCDataText; michael@0: // Various parts of a doctype michael@0: nsString mDoctypeName; michael@0: nsString mSystemID; michael@0: nsString mPublicID; michael@0: nsString mInternalSubset; michael@0: bool mInCData; michael@0: bool mInInternalSubset; michael@0: bool mInExternalDTD; michael@0: bool mMadeFinalCallToExpat; michael@0: michael@0: // Whether we're sure that we won't be getting more buffers to parse from michael@0: // Necko michael@0: bool mIsFinalChunk; michael@0: michael@0: nsresult mInternalState; michael@0: michael@0: // The length of the data in Expat's buffer (in number of PRUnichars). michael@0: uint32_t mExpatBuffered; michael@0: michael@0: // These sinks all refer the same conceptual object. mOriginalSink is michael@0: // identical with the nsIContentSink* passed to WillBuildModel, and exists michael@0: // only to avoid QI-ing back to nsIContentSink*. michael@0: nsCOMPtr mOriginalSink; michael@0: nsCOMPtr mSink; michael@0: nsCOMPtr mExtendedSink; michael@0: michael@0: const nsCatalogData* mCatalogData; // weak michael@0: nsString mURISpec; michael@0: michael@0: // Used for error reporting. michael@0: uint64_t mInnerWindowID; michael@0: }; michael@0: michael@0: #endif