parser/htmlparser/src/nsExpatDriver.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial