parser/xml/nsSAXXMLReader.h
author Jan de Mooij <jdemooij@mozilla.com>
Sat, 24 Jan 2015 14:43:57 +0100
changeset 225548 13f7779c31edff977a51176027472d2428b4704c
parent 223370 ac69293e8e269564f11e28e077cca2d9224ecc90
child 234933 ac4464790ec4896a5188fa50cfc69ae0ffeddc08
permissions -rw-r--r--
Bug 1066878 - Inline Object.create(x) in Ion. r=bhackett

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsSAXXMLReader_h__
#define nsSAXXMLReader_h__

#include "nsCOMPtr.h"
#include "nsIContentSink.h"
#include "nsIExtendedExpatSink.h"
#include "nsIParser.h"
#include "nsIURI.h"
#include "nsISAXXMLReader.h"
#include "nsISAXContentHandler.h"
#include "nsISAXDTDHandler.h"
#include "nsISAXErrorHandler.h"
#include "nsISAXLexicalHandler.h"
#include "nsIMozSAXXMLDeclarationHandler.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Attributes.h"

#define NS_SAXXMLREADER_CONTRACTID "@mozilla.org/saxparser/xmlreader;1"
#define NS_SAXXMLREADER_CID  \
{ 0xab1da296, 0x6125, 0x40ba, \
{ 0x96, 0xd0, 0x47, 0xa8, 0x28, 0x2a, 0xe3, 0xdb} }

class nsSAXXMLReader MOZ_FINAL : public nsISAXXMLReader,
                                 public nsIExtendedExpatSink,
                                 public nsIContentSink
{
public:
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsSAXXMLReader, nsISAXXMLReader)
  NS_DECL_NSIEXPATSINK
  NS_DECL_NSIEXTENDEDEXPATSINK
  NS_DECL_NSISAXXMLREADER
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSISTREAMLISTENER

  nsSAXXMLReader();

  //nsIContentSink
  NS_IMETHOD WillParse() MOZ_OVERRIDE
  {
    return NS_OK;
  }

  NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE;
  NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE;
  NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE;
  
  NS_IMETHOD WillInterrupt() MOZ_OVERRIDE
  {
    return NS_OK;
  }

  NS_IMETHOD WillResume() MOZ_OVERRIDE
  {
    return NS_OK;
  }
  
  virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE
  {
  }
  
  NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE
  {
    return NS_OK;
  }
  
  virtual nsISupports *GetTarget() MOZ_OVERRIDE
  {
    return nullptr;
  }

private:
  ~nsSAXXMLReader() {}

  nsCOMPtr<nsISAXContentHandler> mContentHandler;
  nsCOMPtr<nsISAXDTDHandler> mDTDHandler;
  nsCOMPtr<nsISAXErrorHandler> mErrorHandler;
  nsCOMPtr<nsISAXLexicalHandler> mLexicalHandler;
  nsCOMPtr<nsIMozSAXXMLDeclarationHandler> mDeclarationHandler;
  nsCOMPtr<nsIURI> mBaseURI;
  nsCOMPtr<nsIStreamListener> mListener;
  nsCOMPtr<nsIRequestObserver> mParserObserver;
  bool mIsAsyncParse;
  static bool TryChannelCharset(nsIChannel *aChannel,
                                  int32_t& aCharsetSource,
                                  nsACString& aCharset);
  nsresult EnsureBaseURI();
  nsresult InitParser(nsIRequestObserver *aListener, nsIChannel *aChannel);
  nsresult SplitExpatName(const char16_t *aExpatName,
                          nsString &aURI,
                          nsString &aLocalName,
                          nsString &aQName);
  nsString mPublicId;
  nsString mSystemId;

  // Feature flags
  bool mEnableNamespacePrefixes;
};

#endif // nsSAXXMLReader_h__