diff --git a/mozilla/content/xbl/src/nsXBLContentSink.cpp b/mozilla/content/xbl/src/nsXBLContentSink.cpp index 962ebe2f5b3..392e9f513c0 100644 --- a/mozilla/content/xbl/src/nsXBLContentSink.cpp +++ b/mozilla/content/xbl/src/nsXBLContentSink.cpp @@ -230,7 +230,7 @@ NS_IMETHODIMP nsXBLContentSink::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber) { nsresult rv = nsXMLContentSink::HandleStartElement(aName,aAtts,aAttsCount,aIndex,aLineNumber); diff --git a/mozilla/content/xbl/src/nsXBLContentSink.h b/mozilla/content/xbl/src/nsXBLContentSink.h index 88d3e8c5c8a..84737500f15 100644 --- a/mozilla/content/xbl/src/nsXBLContentSink.h +++ b/mozilla/content/xbl/src/nsXBLContentSink.h @@ -91,7 +91,7 @@ public: NS_IMETHOD HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber); NS_IMETHOD HandleEndElement(const PRUnichar *aName); diff --git a/mozilla/content/xml/document/src/nsLoadSaveContentSink.cpp b/mozilla/content/xml/document/src/nsLoadSaveContentSink.cpp index 7f0c352310a..6908d9420ae 100644 --- a/mozilla/content/xml/document/src/nsLoadSaveContentSink.cpp +++ b/mozilla/content/xml/document/src/nsLoadSaveContentSink.cpp @@ -139,7 +139,7 @@ NS_IMETHODIMP nsLoadSaveContentSink::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber) { return mExpatSink->HandleStartElement(aName, aAtts, aAttsCount, aIndex, diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index 7739ec5f485..6261d967c28 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -1115,9 +1115,14 @@ NS_IMETHODIMP nsXMLContentSink::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber) { + NS_PRECONDITION(aIndex >= -1, "Bogus aIndex"); + NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount"); + // Adjust aAttsCount so it's the actual number of attributes + aAttsCount /= 2; + nsresult result = NS_OK; PRBool appendContent = PR_TRUE; nsCOMPtr content; @@ -1193,7 +1198,7 @@ nsXMLContentSink::HandleStartElement(const PRUnichar *aName, } // Set the ID attribute atom on the node info object for this node - if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(result)) { + if (aIndex != -1 && NS_SUCCEEDED(result)) { nsCOMPtr IDAttr = do_GetAtom(aAtts[aIndex]); if (IDAttr) { @@ -1472,7 +1477,7 @@ nsXMLContentSink::ReportError(const PRUnichar* aErrorText, const PRUnichar* atts[] = {name.get(), value.get(), nsnull}; rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, - (PRUint32)-1, (PRUint32)-1); + -1, (PRUint32)-1); NS_ENSURE_SUCCESS(rv,rv); rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText)); @@ -1480,7 +1485,7 @@ nsXMLContentSink::ReportError(const PRUnichar* aErrorText, const PRUnichar* noAtts[] = {0, 0}; rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0, - (PRUint32)-1, (PRUint32)-1); + -1, (PRUint32)-1); NS_ENSURE_SUCCESS(rv,rv); rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText)); diff --git a/mozilla/content/xul/document/src/nsXULContentSink.cpp b/mozilla/content/xul/document/src/nsXULContentSink.cpp index dd3bb2b4fc7..5d6938d9690 100644 --- a/mozilla/content/xul/document/src/nsXULContentSink.cpp +++ b/mozilla/content/xul/document/src/nsXULContentSink.cpp @@ -767,12 +767,17 @@ NS_IMETHODIMP XULContentSinkImpl::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber) { // XXX Hopefully the parser will flag this before we get here. If // we're in the epilog, there should be no new elements NS_PRECONDITION(mState != eInEpilog, "tag in XUL doc epilog"); + NS_PRECONDITION(aIndex >= -1, "Bogus aIndex"); + NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount"); + // Adjust aAttsCount so it's the actual number of attributes + aAttsCount /= 2; + if (mState == eInEpilog) return NS_ERROR_UNEXPECTED; @@ -813,7 +818,7 @@ XULContentSinkImpl::HandleStartElement(const PRUnichar *aName, } // Set the ID attribute atom on the node info object for this node - if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(rv)) { + if (aIndex != -1 && NS_SUCCEEDED(rv)) { nsCOMPtr IDAttr = do_GetAtom(aAtts[aIndex]); if (IDAttr) { @@ -1079,14 +1084,14 @@ XULContentSinkImpl::ReportError(const PRUnichar* aErrorText, const PRUnichar* atts[] = {name.get(), value.get(), nsnull};; - rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, 0, 0); + rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, -1, 0); NS_ENSURE_SUCCESS(rv,rv); rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText)); NS_ENSURE_SUCCESS(rv,rv); const PRUnichar* noAtts[] = {0, 0}; - rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0, 0, 0); + rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0, -1, 0); NS_ENSURE_SUCCESS(rv,rv); rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText)); diff --git a/mozilla/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp b/mozilla/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp index 4014ae7d4bf..b8e9bba0f40 100644 --- a/mozilla/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp +++ b/mozilla/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp @@ -148,13 +148,13 @@ NS_IMETHODIMP txStylesheetSink::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber) { - // XXX aIndex should be a signed int, that's a bug in the - // Mozilla content sink api. + NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount"); + nsresult rv = - mCompiler->startElement(aName, aAtts, aAttsCount, (PRInt32)aIndex); + mCompiler->startElement(aName, aAtts, aAttsCount / 2, aIndex); if (NS_FAILED(rv)) { mCompiler->cancel(rv); diff --git a/mozilla/htmlparser/public/nsIExpatSink.idl b/mozilla/htmlparser/public/nsIExpatSink.idl index 6051ad1f55b..4fb8c815732 100644 --- a/mozilla/htmlparser/public/nsIExpatSink.idl +++ b/mozilla/htmlparser/public/nsIExpatSink.idl @@ -38,31 +38,82 @@ #include "nsISupports.idl" +/** + * This interface should be implemented by any content sink that wants + * to get output from expat and do something with it; in other words, + * by any sink that handles some sort of XML dialect. + */ + [scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)] interface nsIExpatSink : nsISupports { + /** + * Called to handle the opening tag of an element. + * @param aName the fully qualified tagname of the element + * @param aAtts the array of attribute names and values. There are + * aAttsCount/2 names and aAttsCount/2 values, so the total number of + * elements in the array is aAttsCount. The names and values + * alternate. Thus, if we number attributes starting with 0, + * aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is + * the value of that attribute Both explicitly specified attributes + * and attributes that are defined to have default values in a DTD are + * present in aAtts. + * @param aAttsCount the number of elements in aAtts. + * @param aIndex If the element has an attribute of type ID, then + * aAtts[aIndex] is the name of that attribute. Otherwise, aIndex + * is -1 + * @param aLineNumber the line number of the start tag in the data stream. + */ void HandleStartElement(in wstring aName, - [array, size_is (aAttsCount)] in wstring aAtts, + [array, size_is(aAttsCount)] in wstring aAtts, in unsigned long aAttsCount, - in unsigned long aIndex, + in long aIndex, in unsigned long aLineNumber); + /** + * Called to handle the closing tag of an element. + * @param aName the fully qualified tagname of the element + */ void HandleEndElement(in wstring aName); - - void HandleComment(in wstring aName); - - void HandleCDataSection(in wstring aData, + + /** + * Called to handle a comment + * @param aCommentText the text of the comment (not including the + * "") + */ + void HandleComment(in wstring aCommentText); + + /** + * Called to handle a CDATA section + * @param aData the text in the CDATA section. This is null-terminated. + * @param aLength the length of the aData string + */ + void HandleCDataSection([size_is(aLength)] in wstring aData, in unsigned long aLength); + /** + * Called to handle the doctype declaration + */ void HandleDoctypeDecl(in AString aSubset, in AString aName, in AString aSystemId, in AString aPublicId, in nsISupports aCatalogData); - void HandleCharacterData(in wstring aData, + /** + * Called to handle character data. Note that this does NOT get + * called for the contents of CDATA sections. + * @param aData the data to handle. aData is NOT NULL-TERMINATED. + * @param aLength the length of the aData string + */ + void HandleCharacterData([size_is(aLength)] in wstring aData, in unsigned long aLength); + /** + * Called to handle a processing instruction + * @param aTarget the PI target (e.g. xml-stylesheet) + * @param aData all the rest of the data in the PI + */ void HandleProcessingInstruction(in wstring aTarget, in wstring aData); @@ -73,7 +124,7 @@ interface nsIExpatSink : nsISupports * @param aLength The length of the declaration from * opening '<' to closing '>'. **/ - void HandleXMLDeclaration(in wstring aData, + void HandleXMLDeclaration([size_is(aLength)] in wstring aData, in unsigned long aLength); void ReportError(in wstring aErrorText, diff --git a/mozilla/htmlparser/src/nsExpatDriver.cpp b/mozilla/htmlparser/src/nsExpatDriver.cpp index cdffc4e37a6..f0553bf1898 100644 --- a/mozilla/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/htmlparser/src/nsExpatDriver.cpp @@ -346,9 +346,20 @@ nsExpatDriver::HandleStartElement(const PRUnichar *aValue, { NS_ASSERTION(mSink, "content sink not found!"); + // Calculate the total number of elements in aAtts. + // XML_GetSpecifiedAttributeCount will only give us the number of specified + // attrs (twice that number, actually), so we have to check for default attrs + // ourselves. + PRUint32 attrArrayLength; + for (attrArrayLength = XML_GetSpecifiedAttributeCount(mExpatParser); + aAtts[attrArrayLength]; + attrArrayLength += 2) { + // Just looping till we find out what the length is + } + if (mSink){ mSink->HandleStartElement(aValue, aAtts, - XML_GetSpecifiedAttributeCount(mExpatParser) / 2, + attrArrayLength, XML_GetIdAttributeIndex(mExpatParser), XML_GetCurrentLineNumber(mExpatParser)); } diff --git a/mozilla/parser/htmlparser/public/nsIExpatSink.idl b/mozilla/parser/htmlparser/public/nsIExpatSink.idl index 6051ad1f55b..4fb8c815732 100644 --- a/mozilla/parser/htmlparser/public/nsIExpatSink.idl +++ b/mozilla/parser/htmlparser/public/nsIExpatSink.idl @@ -38,31 +38,82 @@ #include "nsISupports.idl" +/** + * This interface should be implemented by any content sink that wants + * to get output from expat and do something with it; in other words, + * by any sink that handles some sort of XML dialect. + */ + [scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)] interface nsIExpatSink : nsISupports { + /** + * Called to handle the opening tag of an element. + * @param aName the fully qualified tagname of the element + * @param aAtts the array of attribute names and values. There are + * aAttsCount/2 names and aAttsCount/2 values, so the total number of + * elements in the array is aAttsCount. The names and values + * alternate. Thus, if we number attributes starting with 0, + * aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is + * the value of that attribute Both explicitly specified attributes + * and attributes that are defined to have default values in a DTD are + * present in aAtts. + * @param aAttsCount the number of elements in aAtts. + * @param aIndex If the element has an attribute of type ID, then + * aAtts[aIndex] is the name of that attribute. Otherwise, aIndex + * is -1 + * @param aLineNumber the line number of the start tag in the data stream. + */ void HandleStartElement(in wstring aName, - [array, size_is (aAttsCount)] in wstring aAtts, + [array, size_is(aAttsCount)] in wstring aAtts, in unsigned long aAttsCount, - in unsigned long aIndex, + in long aIndex, in unsigned long aLineNumber); + /** + * Called to handle the closing tag of an element. + * @param aName the fully qualified tagname of the element + */ void HandleEndElement(in wstring aName); - - void HandleComment(in wstring aName); - - void HandleCDataSection(in wstring aData, + + /** + * Called to handle a comment + * @param aCommentText the text of the comment (not including the + * "") + */ + void HandleComment(in wstring aCommentText); + + /** + * Called to handle a CDATA section + * @param aData the text in the CDATA section. This is null-terminated. + * @param aLength the length of the aData string + */ + void HandleCDataSection([size_is(aLength)] in wstring aData, in unsigned long aLength); + /** + * Called to handle the doctype declaration + */ void HandleDoctypeDecl(in AString aSubset, in AString aName, in AString aSystemId, in AString aPublicId, in nsISupports aCatalogData); - void HandleCharacterData(in wstring aData, + /** + * Called to handle character data. Note that this does NOT get + * called for the contents of CDATA sections. + * @param aData the data to handle. aData is NOT NULL-TERMINATED. + * @param aLength the length of the aData string + */ + void HandleCharacterData([size_is(aLength)] in wstring aData, in unsigned long aLength); + /** + * Called to handle a processing instruction + * @param aTarget the PI target (e.g. xml-stylesheet) + * @param aData all the rest of the data in the PI + */ void HandleProcessingInstruction(in wstring aTarget, in wstring aData); @@ -73,7 +124,7 @@ interface nsIExpatSink : nsISupports * @param aLength The length of the declaration from * opening '<' to closing '>'. **/ - void HandleXMLDeclaration(in wstring aData, + void HandleXMLDeclaration([size_is(aLength)] in wstring aData, in unsigned long aLength); void ReportError(in wstring aErrorText, diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index cdffc4e37a6..f0553bf1898 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -346,9 +346,20 @@ nsExpatDriver::HandleStartElement(const PRUnichar *aValue, { NS_ASSERTION(mSink, "content sink not found!"); + // Calculate the total number of elements in aAtts. + // XML_GetSpecifiedAttributeCount will only give us the number of specified + // attrs (twice that number, actually), so we have to check for default attrs + // ourselves. + PRUint32 attrArrayLength; + for (attrArrayLength = XML_GetSpecifiedAttributeCount(mExpatParser); + aAtts[attrArrayLength]; + attrArrayLength += 2) { + // Just looping till we find out what the length is + } + if (mSink){ mSink->HandleStartElement(aValue, aAtts, - XML_GetSpecifiedAttributeCount(mExpatParser) / 2, + attrArrayLength, XML_GetIdAttributeIndex(mExpatParser), XML_GetCurrentLineNumber(mExpatParser)); } diff --git a/mozilla/rdf/base/src/nsRDFContentSink.cpp b/mozilla/rdf/base/src/nsRDFContentSink.cpp index 9a4fa3e6f17..a3f4a83a62e 100644 --- a/mozilla/rdf/base/src/nsRDFContentSink.cpp +++ b/mozilla/rdf/base/src/nsRDFContentSink.cpp @@ -497,7 +497,7 @@ NS_IMETHODIMP RDFContentSinkImpl::HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, PRUint32 aAttsCount, - PRUint32 aIndex, + PRInt32 aIndex, PRUint32 aLineNumber) { FlushText();