parser/htmlparser/src/nsExpatDriver.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/htmlparser/src/nsExpatDriver.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef NS_EXPAT_DRIVER__
    1.10 +#define NS_EXPAT_DRIVER__
    1.11 +
    1.12 +#include "expat_config.h"
    1.13 +#include "expat.h"
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsString.h"
    1.16 +#include "nsIDTD.h"
    1.17 +#include "nsITokenizer.h"
    1.18 +#include "nsIInputStream.h"
    1.19 +#include "nsIParser.h"
    1.20 +#include "nsCycleCollectionParticipant.h"
    1.21 +
    1.22 +class nsIExpatSink;
    1.23 +class nsIExtendedExpatSink;
    1.24 +struct nsCatalogData;
    1.25 +
    1.26 +class nsExpatDriver : public nsIDTD,
    1.27 +                      public nsITokenizer
    1.28 +{
    1.29 +public:
    1.30 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.31 +  NS_DECL_NSIDTD
    1.32 +  NS_DECL_NSITOKENIZER
    1.33 +  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD)
    1.34 +
    1.35 +  nsExpatDriver();
    1.36 +  virtual ~nsExpatDriver();
    1.37 +
    1.38 +  int HandleExternalEntityRef(const char16_t *aOpenEntityNames,
    1.39 +                              const char16_t *aBase,
    1.40 +                              const char16_t *aSystemId,
    1.41 +                              const char16_t *aPublicId);
    1.42 +  nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts);
    1.43 +  nsresult HandleEndElement(const char16_t *aName);
    1.44 +  nsresult HandleCharacterData(const char16_t *aCData, const uint32_t aLength);
    1.45 +  nsresult HandleComment(const char16_t *aName);
    1.46 +  nsresult HandleProcessingInstruction(const char16_t *aTarget,
    1.47 +                                       const char16_t *aData);
    1.48 +  nsresult HandleXMLDeclaration(const char16_t *aVersion,
    1.49 +                                const char16_t *aEncoding,
    1.50 +                                int32_t aStandalone);
    1.51 +  nsresult HandleDefault(const char16_t *aData, const uint32_t aLength);
    1.52 +  nsresult HandleStartCdataSection();
    1.53 +  nsresult HandleEndCdataSection();
    1.54 +  nsresult HandleStartDoctypeDecl(const char16_t* aDoctypeName,
    1.55 +                                  const char16_t* aSysid,
    1.56 +                                  const char16_t* aPubid,
    1.57 +                                  bool aHasInternalSubset);
    1.58 +  nsresult HandleEndDoctypeDecl();
    1.59 +  nsresult HandleStartNamespaceDecl(const char16_t* aPrefix,
    1.60 +                                    const char16_t* aUri);
    1.61 +  nsresult HandleEndNamespaceDecl(const char16_t* aPrefix);
    1.62 +  nsresult HandleNotationDecl(const char16_t* aNotationName,
    1.63 +                              const char16_t* aBase,
    1.64 +                              const char16_t* aSysid,
    1.65 +                              const char16_t* aPubid);
    1.66 +  nsresult HandleUnparsedEntityDecl(const char16_t* aEntityName,
    1.67 +                                    const char16_t* aBase,
    1.68 +                                    const char16_t* aSysid,
    1.69 +                                    const char16_t* aPubid,
    1.70 +                                    const char16_t* aNotationName);
    1.71 +
    1.72 +private:
    1.73 +  // Load up an external stream to get external entity information
    1.74 +  nsresult OpenInputStreamFromExternalDTD(const char16_t* aFPIStr,
    1.75 +                                          const char16_t* aURLStr,
    1.76 +                                          const char16_t* aBaseURL,
    1.77 +                                          nsIInputStream** aStream,
    1.78 +                                          nsAString& aAbsURL);
    1.79 +
    1.80 +  /**
    1.81 +   * Pass a buffer to Expat. If Expat is blocked aBuffer should be null and
    1.82 +   * aLength should be 0. The result of the call will be stored in
    1.83 +   * mInternalState. Expat will parse as much of the buffer as it can and store
    1.84 +   * the rest in its internal buffer.
    1.85 +   *
    1.86 +   * @param aBuffer the buffer to pass to Expat. May be null.
    1.87 +   * @param aLength the length of the buffer to pass to Expat (in number of
    1.88 +   *                char16_t's). Must be 0 if aBuffer is null and > 0 if
    1.89 +   *                aBuffer is not null.
    1.90 +   * @param aIsFinal whether there will definitely not be any more new buffers
    1.91 +   *                 passed in to ParseBuffer
    1.92 +   * @param aConsumed [out] the number of PRUnichars that Expat consumed. This
    1.93 +   *                        doesn't include the PRUnichars that Expat stored in
    1.94 +   *                        its buffer but didn't parse yet.
    1.95 +   */
    1.96 +  void ParseBuffer(const char16_t *aBuffer, uint32_t aLength, bool aIsFinal,
    1.97 +                   uint32_t *aConsumed);
    1.98 +  nsresult HandleError();
    1.99 +
   1.100 +  void MaybeStopParser(nsresult aState);
   1.101 +
   1.102 +  bool BlockedOrInterrupted()
   1.103 +  {
   1.104 +    return mInternalState == NS_ERROR_HTMLPARSER_BLOCK ||
   1.105 +           mInternalState == NS_ERROR_HTMLPARSER_INTERRUPTED;
   1.106 +  }
   1.107 +
   1.108 +  XML_Parser       mExpatParser;
   1.109 +  nsString         mLastLine;
   1.110 +  nsString         mCDataText;
   1.111 +  // Various parts of a doctype
   1.112 +  nsString         mDoctypeName;
   1.113 +  nsString         mSystemID;
   1.114 +  nsString         mPublicID;
   1.115 +  nsString         mInternalSubset;
   1.116 +  bool             mInCData;
   1.117 +  bool             mInInternalSubset;
   1.118 +  bool             mInExternalDTD;
   1.119 +  bool             mMadeFinalCallToExpat;
   1.120 +
   1.121 +  // Whether we're sure that we won't be getting more buffers to parse from
   1.122 +  // Necko
   1.123 +  bool             mIsFinalChunk;
   1.124 +
   1.125 +  nsresult         mInternalState;
   1.126 +
   1.127 +  // The length of the data in Expat's buffer (in number of PRUnichars).
   1.128 +  uint32_t         mExpatBuffered;
   1.129 +
   1.130 +  // These sinks all refer the same conceptual object. mOriginalSink is
   1.131 +  // identical with the nsIContentSink* passed to WillBuildModel, and exists
   1.132 +  // only to avoid QI-ing back to nsIContentSink*.
   1.133 +  nsCOMPtr<nsIContentSink> mOriginalSink;
   1.134 +  nsCOMPtr<nsIExpatSink> mSink;
   1.135 +  nsCOMPtr<nsIExtendedExpatSink> mExtendedSink;
   1.136 +
   1.137 +  const nsCatalogData* mCatalogData; // weak
   1.138 +  nsString         mURISpec;
   1.139 +
   1.140 +  // Used for error reporting.
   1.141 +  uint64_t         mInnerWindowID;
   1.142 +};
   1.143 +
   1.144 +#endif

mercurial