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.

     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/. */
     6 #ifndef NS_EXPAT_DRIVER__
     7 #define NS_EXPAT_DRIVER__
     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"
    19 class nsIExpatSink;
    20 class nsIExtendedExpatSink;
    21 struct nsCatalogData;
    23 class nsExpatDriver : public nsIDTD,
    24                       public nsITokenizer
    25 {
    26 public:
    27   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    28   NS_DECL_NSIDTD
    29   NS_DECL_NSITOKENIZER
    30   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD)
    32   nsExpatDriver();
    33   virtual ~nsExpatDriver();
    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   nsresult HandleStartNamespaceDecl(const char16_t* aPrefix,
    57                                     const char16_t* aUri);
    58   nsresult HandleEndNamespaceDecl(const char16_t* aPrefix);
    59   nsresult HandleNotationDecl(const char16_t* aNotationName,
    60                               const char16_t* aBase,
    61                               const char16_t* aSysid,
    62                               const char16_t* aPubid);
    63   nsresult HandleUnparsedEntityDecl(const char16_t* aEntityName,
    64                                     const char16_t* aBase,
    65                                     const char16_t* aSysid,
    66                                     const char16_t* aPubid,
    67                                     const char16_t* aNotationName);
    69 private:
    70   // Load up an external stream to get external entity information
    71   nsresult OpenInputStreamFromExternalDTD(const char16_t* aFPIStr,
    72                                           const char16_t* aURLStr,
    73                                           const char16_t* aBaseURL,
    74                                           nsIInputStream** aStream,
    75                                           nsAString& aAbsURL);
    77   /**
    78    * Pass a buffer to Expat. If Expat is blocked aBuffer should be null and
    79    * aLength should be 0. The result of the call will be stored in
    80    * mInternalState. Expat will parse as much of the buffer as it can and store
    81    * the rest in its internal buffer.
    82    *
    83    * @param aBuffer the buffer to pass to Expat. May be null.
    84    * @param aLength the length of the buffer to pass to Expat (in number of
    85    *                char16_t's). Must be 0 if aBuffer is null and > 0 if
    86    *                aBuffer is not null.
    87    * @param aIsFinal whether there will definitely not be any more new buffers
    88    *                 passed in to ParseBuffer
    89    * @param aConsumed [out] the number of PRUnichars that Expat consumed. This
    90    *                        doesn't include the PRUnichars that Expat stored in
    91    *                        its buffer but didn't parse yet.
    92    */
    93   void ParseBuffer(const char16_t *aBuffer, uint32_t aLength, bool aIsFinal,
    94                    uint32_t *aConsumed);
    95   nsresult HandleError();
    97   void MaybeStopParser(nsresult aState);
    99   bool BlockedOrInterrupted()
   100   {
   101     return mInternalState == NS_ERROR_HTMLPARSER_BLOCK ||
   102            mInternalState == NS_ERROR_HTMLPARSER_INTERRUPTED;
   103   }
   105   XML_Parser       mExpatParser;
   106   nsString         mLastLine;
   107   nsString         mCDataText;
   108   // Various parts of a doctype
   109   nsString         mDoctypeName;
   110   nsString         mSystemID;
   111   nsString         mPublicID;
   112   nsString         mInternalSubset;
   113   bool             mInCData;
   114   bool             mInInternalSubset;
   115   bool             mInExternalDTD;
   116   bool             mMadeFinalCallToExpat;
   118   // Whether we're sure that we won't be getting more buffers to parse from
   119   // Necko
   120   bool             mIsFinalChunk;
   122   nsresult         mInternalState;
   124   // The length of the data in Expat's buffer (in number of PRUnichars).
   125   uint32_t         mExpatBuffered;
   127   // These sinks all refer the same conceptual object. mOriginalSink is
   128   // identical with the nsIContentSink* passed to WillBuildModel, and exists
   129   // only to avoid QI-ing back to nsIContentSink*.
   130   nsCOMPtr<nsIContentSink> mOriginalSink;
   131   nsCOMPtr<nsIExpatSink> mSink;
   132   nsCOMPtr<nsIExtendedExpatSink> mExtendedSink;
   134   const nsCatalogData* mCatalogData; // weak
   135   nsString         mURISpec;
   137   // Used for error reporting.
   138   uint64_t         mInnerWindowID;
   139 };
   141 #endif

mercurial