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 nsSAXXMLReader_h__ 7 #define nsSAXXMLReader_h__ 8 9 #include "nsCOMPtr.h" 10 #include "nsIContentSink.h" 11 #include "nsIExtendedExpatSink.h" 12 #include "nsIParser.h" 13 #include "nsIURI.h" 14 #include "nsISAXXMLReader.h" 15 #include "nsISAXContentHandler.h" 16 #include "nsISAXDTDHandler.h" 17 #include "nsISAXErrorHandler.h" 18 #include "nsISAXLexicalHandler.h" 19 #include "nsIMozSAXXMLDeclarationHandler.h" 20 #include "nsCycleCollectionParticipant.h" 21 #include "mozilla/Attributes.h" 22 23 #define NS_SAXXMLREADER_CONTRACTID "@mozilla.org/saxparser/xmlreader;1" 24 #define NS_SAXXMLREADER_CID \ 25 { 0xab1da296, 0x6125, 0x40ba, \ 26 { 0x96, 0xd0, 0x47, 0xa8, 0x28, 0x2a, 0xe3, 0xdb} } 27 28 class nsSAXXMLReader final : public nsISAXXMLReader, 29 public nsIExtendedExpatSink, 30 public nsIContentSink 31 { 32 public: 33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 34 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsSAXXMLReader, nsISAXXMLReader) 35 NS_DECL_NSIEXPATSINK 36 NS_DECL_NSIEXTENDEDEXPATSINK 37 NS_DECL_NSISAXXMLREADER 38 NS_DECL_NSIREQUESTOBSERVER 39 NS_DECL_NSISTREAMLISTENER 40 41 nsSAXXMLReader(); 42 43 //nsIContentSink WillParse()44 NS_IMETHOD WillParse() override 45 { 46 return NS_OK; 47 } 48 49 NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override; 50 NS_IMETHOD DidBuildModel(bool aTerminated) override; 51 NS_IMETHOD SetParser(nsParserBase* aParser) override; 52 WillInterrupt()53 NS_IMETHOD WillInterrupt() override 54 { 55 return NS_OK; 56 } 57 WillResume()58 NS_IMETHOD WillResume() override 59 { 60 return NS_OK; 61 } 62 FlushPendingNotifications(mozFlushType aType)63 virtual void FlushPendingNotifications(mozFlushType aType) override 64 { 65 } 66 SetDocumentCharset(nsACString & aCharset)67 NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override 68 { 69 return NS_OK; 70 } 71 GetTarget()72 virtual nsISupports *GetTarget() override 73 { 74 return nullptr; 75 } 76 77 private: ~nsSAXXMLReader()78 ~nsSAXXMLReader() {} 79 80 nsCOMPtr<nsISAXContentHandler> mContentHandler; 81 nsCOMPtr<nsISAXDTDHandler> mDTDHandler; 82 nsCOMPtr<nsISAXErrorHandler> mErrorHandler; 83 nsCOMPtr<nsISAXLexicalHandler> mLexicalHandler; 84 nsCOMPtr<nsIMozSAXXMLDeclarationHandler> mDeclarationHandler; 85 nsCOMPtr<nsIURI> mBaseURI; 86 nsCOMPtr<nsIStreamListener> mListener; 87 nsCOMPtr<nsIRequestObserver> mParserObserver; 88 bool mIsAsyncParse; 89 static bool TryChannelCharset(nsIChannel *aChannel, 90 int32_t& aCharsetSource, 91 nsACString& aCharset); 92 nsresult EnsureBaseURI(); 93 nsresult InitParser(nsIRequestObserver *aListener, nsIChannel *aChannel); 94 nsresult SplitExpatName(const char16_t *aExpatName, 95 nsString &aURI, 96 nsString &aLocalName, 97 nsString &aQName); 98 nsString mPublicId; 99 nsString mSystemId; 100 101 // Feature flags 102 bool mEnableNamespacePrefixes; 103 }; 104 105 #endif // nsSAXXMLReader_h__ 106