From bd517c26ac2444c5b6a71bc87d7b81ba00986c09 Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Wed, 15 Mar 2006 17:45:25 +0000 Subject: [PATCH] 326477 extend nsIExpatSink in order to support SAX patch by Robert Sayre r=sicking sr=peterv git-svn-id: svn://10.0.0.236/trunk@192427 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/parser/expat/lib/xmlparse.c | 5 + mozilla/parser/htmlparser/public/Makefile.in | 1 + .../public/nsIExtendedExpatSink.idl | 104 +++++++++++++++ .../parser/htmlparser/src/nsExpatDriver.cpp | 125 ++++++++++++++++++ mozilla/parser/htmlparser/src/nsExpatDriver.h | 14 ++ 5 files changed, 249 insertions(+) create mode 100644 mozilla/parser/htmlparser/public/nsIExtendedExpatSink.idl diff --git a/mozilla/parser/expat/lib/xmlparse.c b/mozilla/parser/expat/lib/xmlparse.c index 47f8bc22e79..0b9871b9a5b 100644 --- a/mozilla/parser/expat/lib/xmlparse.c +++ b/mozilla/parser/expat/lib/xmlparse.c @@ -1341,6 +1341,8 @@ XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end) { endDoctypeDeclHandler = end; } +#endif +/* END MOZILLA CHANGE */ void XMLCALL XML_SetUnparsedEntityDeclHandler(XML_Parser parser, @@ -1365,6 +1367,9 @@ XML_SetNamespaceDeclHandler(XML_Parser parser, endNamespaceDeclHandler = end; } + +/* BEGIN MOZILLA CHANGE (unused API) */ +#if 0 void XMLCALL XML_SetStartNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start) { diff --git a/mozilla/parser/htmlparser/public/Makefile.in b/mozilla/parser/htmlparser/public/Makefile.in index a60ca4b0a69..e2e9ef38896 100644 --- a/mozilla/parser/htmlparser/public/Makefile.in +++ b/mozilla/parser/htmlparser/public/Makefile.in @@ -47,6 +47,7 @@ GRE_MODULE = 1 XPIDLSRCS = \ nsIExpatSink.idl \ + nsIExtendedExpatSink.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/parser/htmlparser/public/nsIExtendedExpatSink.idl b/mozilla/parser/htmlparser/public/nsIExtendedExpatSink.idl new file mode 100644 index 00000000000..3423c8dc5dc --- /dev/null +++ b/mozilla/parser/htmlparser/public/nsIExtendedExpatSink.idl @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Robert Sayre. + * + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIExpatSink.idl" + +/** + * This interface provides notification of syntax-level events. + */ +[scriptable, uuid(0C2DC80F-7AA4-467A-9454-B89DBA0E0779)] +interface nsIExtendedExpatSink : nsIExpatSink +{ + /** + * Called at the beginning of the DTD, before any entity or notation + * events. + * @param aDoctypeName The document type name. + * @param aSysid The declared system identifier for the external DTD subset, + * or null if none was declared. + * @param aPubid The declared public identifier for the external DTD subset, + * or null if none was declared. + */ + void handleStartDTD(in wstring aDoctypeName, + in wstring aSysid, + in wstring aPubid); + + /** + * Called when a prefix mapping starts to be in-scope, before any + * startElement events. + * @param aPrefix The Namespace prefix being declared. An empty string + * is used for the default element namespace, which has + * no prefix. + * @param aUri The Namespace URI the prefix is mapped to. + */ + void handleStartNamespaceDecl(in wstring aPrefix, + in wstring aUri); + + /** + * Called when a prefix mapping is no longer in-scope, after any + * endElement events. + * @param aPrefix The prefix that was being mapped. This is the empty string + * when a default mapping scope ends. + */ + void handleEndNamespaceDecl(in wstring aPrefix); + + /** + * This is called for a declaration of notation. The base argument is + * whatever was set by XML_SetBase. aNotationName will never be + * null. The other arguments can be. + * @param aNotationName The notation name. + * @param aSysId The notation's system identifier, or null if none was given. + * @param aPubId The notation's pubilc identifier, or null if none was given. + */ + void handleNotationDecl(in wstring aNotationName, + in wstring aSysid, + in wstring aPubid); + + /** + * This is called for a declaration of an unparsed (NDATA) entity. + * aName, aSysid and aNotationName arguments will never be + * null. The other arguments may be. + * @param aName The unparsed entity's name. + * @param aSysId The notation's system identifier. + * @param aPubId The notation's pubilc identifier, or null if none was given. + * @param aNotationName The name of the associated notation. + */ + void handleUnparsedEntityDecl(in wstring aName, + in wstring aSysid, + in wstring aPubid, + in wstring aNotationName); + +}; diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index 4d5ee8683c1..7f95d8d8395 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -41,6 +41,7 @@ #include "nsParserCIID.h" #include "CParserContext.h" #include "nsIExpatSink.h" +#include "nsIExtendedExpatSink.h" #include "nsIContentSink.h" #include "nsParserMsgUtils.h" #include "nsIURL.h" @@ -206,6 +207,60 @@ Driver_HandleExternalEntityRef(void *aExternalEntityRefHandler, aPublicId); } +PR_STATIC_CALLBACK(void) +Driver_HandleStartNamespaceDecl(void *aUserData, + const XML_Char *aPrefix, + const XML_Char *aUri) +{ + NS_ASSERTION(aUserData, "expat driver should exist"); + if (aUserData) { + NS_STATIC_CAST(nsExpatDriver*, aUserData)-> + HandleStartNamespaceDecl(aPrefix, aUri); + } +} + +PR_STATIC_CALLBACK(void) +Driver_HandleEndNamespaceDecl(void *aUserData, + const XML_Char *aPrefix) +{ + NS_ASSERTION(aUserData, "expat driver should exist"); + if (aUserData) { + NS_STATIC_CAST(nsExpatDriver*, aUserData)-> + HandleEndNamespaceDecl(aPrefix); + } +} + +PR_STATIC_CALLBACK(void) +Driver_HandleNotationDecl(void *aUserData, + const XML_Char *aNotationName, + const XML_Char *aBase, + const XML_Char *aSysid, + const XML_Char *aPubid) +{ + NS_ASSERTION(aUserData, "expat driver should exist"); + if (aUserData) { + NS_STATIC_CAST(nsExpatDriver*, aUserData)-> + HandleNotationDecl(aNotationName, aBase, aSysid, aPubid); + } +} + +PR_STATIC_CALLBACK(void) +Driver_HandleUnparsedEntityDecl(void *aUserData, + const XML_Char *aEntityName, + const XML_Char *aBase, + const XML_Char *aSysid, + const XML_Char *aPubid, + const XML_Char *aNotationName) +{ + NS_ASSERTION(aUserData, "expat driver should exist"); + if (aUserData) { + NS_STATIC_CAST(nsExpatDriver*, aUserData)-> + HandleUnparsedEntityDecl(aEntityName, aBase, aSysid, aPubid, + aNotationName); + } +} + + /***************************** END CALL BACKS ********************************/ /***************************** CATALOG UTILS *********************************/ @@ -506,6 +561,56 @@ nsExpatDriver::HandleEndCdataSection() return NS_OK; } +nsresult +nsExpatDriver::HandleStartNamespaceDecl(const PRUnichar* aPrefix, + const PRUnichar* aUri) +{ + if (mExtendedSink) { + mInternalState = mExtendedSink->HandleStartNamespaceDecl(aPrefix, + aUri); + } + return NS_OK; +} + +nsresult +nsExpatDriver::HandleEndNamespaceDecl(const PRUnichar* aPrefix) +{ + if (mExtendedSink) { + mInternalState = mExtendedSink->HandleEndNamespaceDecl(aPrefix); + } + return NS_OK; +} + +nsresult +nsExpatDriver::HandleNotationDecl(const PRUnichar* aNotationName, + const PRUnichar* aBase, + const PRUnichar* aSysid, + const PRUnichar* aPubid) +{ + if (mExtendedSink) { + mInternalState = mExtendedSink->HandleNotationDecl(aNotationName, + aSysid, + aPubid); + } + return NS_OK; +} + +nsresult +nsExpatDriver::HandleUnparsedEntityDecl(const PRUnichar* aEntityName, + const PRUnichar* aBase, + const PRUnichar* aSysid, + const PRUnichar* aPubid, + const PRUnichar* aNotationName) +{ + if (mExtendedSink) { + mInternalState = mExtendedSink->HandleUnparsedEntityDecl(aEntityName, + aSysid, + aPubid, + aNotationName); + } + return NS_OK; +} + nsresult nsExpatDriver::HandleStartDoctypeDecl(const PRUnichar* aDoctypeName, const PRUnichar* aSysid, @@ -516,6 +621,11 @@ nsExpatDriver::HandleStartDoctypeDecl(const PRUnichar* aDoctypeName, mSystemID = aSysid; mPublicID = aPubid; + if (mExtendedSink) { + mInternalState = mExtendedSink->HandleStartDTD(aDoctypeName, + aSysid, aPubid); + } + if (aHasInternalSubset) { // Consuming a huge internal subset translates to numerous // allocations. In an effort to avoid too many allocations @@ -1098,6 +1208,19 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext, XML_SetDoctypeDeclHandler(mExpatParser, Driver_HandleStartDoctypeDecl, Driver_HandleEndDoctypeDecl); + // If the sink is an nsIExtendedExpatSink, + // register some addtional handlers. + mExtendedSink = do_QueryInterface(mSink); + if (mExtendedSink) { + XML_SetNamespaceDeclHandler(mExpatParser, + Driver_HandleStartNamespaceDecl, + Driver_HandleEndNamespaceDecl); + XML_SetUnparsedEntityDeclHandler(mExpatParser, + Driver_HandleUnparsedEntityDecl); + XML_SetNotationDeclHandler(mExpatParser, + Driver_HandleNotationDecl); + } + // Set up the user data. XML_SetUserData(mExpatParser, this); @@ -1127,6 +1250,8 @@ nsExpatDriver::DidBuildModel(nsresult anErrorCode, mSink = nsnull; } + mExtendedSink = nsnull; + return result; } diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.h b/mozilla/parser/htmlparser/src/nsExpatDriver.h index 95156bc6d77..3ff5d0a1b76 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.h +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.h @@ -47,6 +47,7 @@ #include "nsIInputStream.h" class nsIExpatSink; +class nsIExtendedExpatSink; struct nsCatalogData; class nsExpatDriver : public nsIDTD, @@ -81,6 +82,18 @@ public: const PRUnichar* aPubid, PRBool aHasInternalSubset); nsresult HandleEndDoctypeDecl(); + nsresult HandleStartNamespaceDecl(const PRUnichar* aPrefix, + const PRUnichar* aUri); + nsresult HandleEndNamespaceDecl(const PRUnichar* aPrefix); + nsresult HandleNotationDecl(const PRUnichar* aNotationName, + const PRUnichar* aBase, + const PRUnichar* aSysid, + const PRUnichar* aPubid); + nsresult HandleUnparsedEntityDecl(const PRUnichar* aEntityName, + const PRUnichar* aBase, + const PRUnichar* aSysid, + const PRUnichar* aPubid, + const PRUnichar* aNotationName); private: // Load up an external stream to get external entity information @@ -132,6 +145,7 @@ private: PRUint32 mExpatBuffered; nsCOMPtr mSink; + nsCOMPtr mExtendedSink; const nsCatalogData* mCatalogData; // weak nsString mURISpec; };