nsresult nsExpatDriver::HandleStartDoctypeDecl(const PRUnichar* aDoctypeName, const PRUnichar* aSysid, const PRUnichar* aPubid, PRBool aHasInternalSubset) { mDoctypeName = aDoctypeName; mSystemID = aSysid; mPublicID = aPubid; if (mExtendedSink) { nsresult rv = mExtendedSink->HandleStartDTD(aDoctypeName, aSysid, aPubid); MaybeStopParser(rv); } if (aHasInternalSubset) { // Consuming a huge internal subset translates to numerous // allocations. In an effort to avoid too many allocations // setting mInternalSubset's capacity to be 1K ( just a guesstimate! ). mInInternalSubset = PR_TRUE; mInternalSubset.SetCapacity(1024); } else { // Distinguish missing internal subset from an empty one mInternalSubset.SetIsVoid(PR_TRUE); } return NS_OK; }
nsresult nsExpatDriver::HandleEndDoctypeDecl() { NS_ASSERTION(mSink, "content sink not found!"); mInInternalSubset = PR_FALSE; if (mSink) { // let the sink know any additional knowledge that we have about the // document (currently, from bug 124570, we only expect to pass additional // agent sheets needed to layout the XML vocabulary of the document) nsCOMPtr<nsIURI> data; if (mCatalogData && mCatalogData->mAgentSheet) { NS_NewURI(getter_AddRefs(data), mCatalogData->mAgentSheet); } // Note: mInternalSubset already doesn't include the [] around it. nsresult rv = mSink->HandleDoctypeDecl(mInternalSubset, mDoctypeName, mSystemID, mPublicID, data); MaybeStopParser(rv); } mInternalSubset.SetCapacity(0); return NS_OK; }
nsresult nsExpatDriver::HandleStartElement(const PRUnichar *aValue, const PRUnichar **aAtts) { 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) { nsresult rv = mSink-> HandleStartElement(aValue, aAtts, attrArrayLength, XML_GetIdAttributeIndex(mExpatParser), XML_GetCurrentLineNumber(mExpatParser)); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleDefault(const PRUnichar *aValue, const PRUint32 aLength) { NS_ASSERTION(mSink, "content sink not found!"); if (mInExternalDTD) { // Ignore newlines in external DTDs return NS_OK; } if (mInInternalSubset) { mInternalSubset.Append(aValue, aLength); } else if (mSink) { PRUint32 i; nsresult rv = mInternalState; for (i = 0; i < aLength && NS_SUCCEEDED(rv); ++i) { if (aValue[i] == '\n' || aValue[i] == '\r') { rv = mSink->HandleCharacterData(&aValue[i], 1); } } MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleProcessingInstruction(const PRUnichar *aTarget, const PRUnichar *aData) { NS_ASSERTION(mSink, "content sink not found!"); if (mInExternalDTD) { // Ignore PIs in external DTDs for now. Eventually we want to // pass them to the sink in a way that doesn't put them in the DOM return NS_OK; } if (mInInternalSubset) { mInternalSubset.AppendLiteral("<?"); mInternalSubset.Append(aTarget); mInternalSubset.Append(' '); mInternalSubset.Append(aData); mInternalSubset.AppendLiteral("?>"); } else if (mSink) { nsresult rv = mSink->HandleProcessingInstruction(aTarget, aData); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleEndDoctypeDecl() { NS_ASSERTION(mSink, "content sink not found!"); mInInternalSubset = false; if (mSink) { // let the sink know any additional knowledge that we have about the // document (currently, from bug 124570, we only expect to pass additional // agent sheets needed to layout the XML vocabulary of the document) nsCOMPtr<nsIURI> data; #if 0 if (mCatalogData && mCatalogData->mAgentSheet) { NS_NewURI(getter_AddRefs(data), mCatalogData->mAgentSheet); } #endif // The unused support for "catalog style sheets" was removed. It doesn't // look like we'll ever fix bug 98413 either. MOZ_ASSERT(!mCatalogData || !mCatalogData->mAgentSheet, "Need to add back support for catalog style sheets"); // Note: mInternalSubset already doesn't include the [] around it. nsresult rv = mSink->HandleDoctypeDecl(mInternalSubset, mDoctypeName, mSystemID, mPublicID, data); MaybeStopParser(rv); } mInternalSubset.SetCapacity(0); return NS_OK; }
nsresult nsExpatDriver::HandleEndNamespaceDecl(const PRUnichar* aPrefix) { if (mExtendedSink && mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) { nsresult rv = mExtendedSink->HandleEndNamespaceDecl(aPrefix); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleStartNamespaceDecl(const PRUnichar* aPrefix, const PRUnichar* aUri) { if (mExtendedSink) { nsresult rv = mExtendedSink->HandleStartNamespaceDecl(aPrefix, aUri); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleXMLDeclaration(const PRUnichar *aVersion, const PRUnichar *aEncoding, PRInt32 aStandalone) { if (mSink) { nsresult rv = mSink->HandleXMLDeclaration(aVersion, aEncoding, aStandalone); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleNotationDecl(const PRUnichar* aNotationName, const PRUnichar* aBase, const PRUnichar* aSysid, const PRUnichar* aPubid) { if (mExtendedSink) { nsresult rv = mExtendedSink->HandleNotationDecl(aNotationName, aSysid, aPubid); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleEndElement(const PRUnichar *aValue) { NS_ASSERTION(mSink, "content sink not found!"); NS_ASSERTION(mInternalState != NS_ERROR_HTMLPARSER_BLOCK, "Shouldn't block from HandleStartElement."); if (mSink && mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) { nsresult rv = mSink->HandleEndElement(aValue); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleEndCdataSection() { NS_ASSERTION(mSink, "content sink not found!"); mInCData = PR_FALSE; if (mSink) { nsresult rv = mSink->HandleCDataSection(mCDataText.get(), mCDataText.Length()); MaybeStopParser(rv); } mCDataText.Truncate(); return NS_OK; }
nsresult nsExpatDriver::HandleCharacterData(const PRUnichar *aValue, const PRUint32 aLength) { NS_ASSERTION(mSink, "content sink not found!"); if (mInCData) { mCDataText.Append(aValue, aLength); } else if (mSink) { nsresult rv = mSink->HandleCharacterData(aValue, aLength); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleUnparsedEntityDecl(const char16_t* aEntityName, const char16_t* aBase, const char16_t* aSysid, const char16_t* aPubid, const char16_t* aNotationName) { if (mExtendedSink) { nsresult rv = mExtendedSink->HandleUnparsedEntityDecl(aEntityName, aSysid, aPubid, aNotationName); MaybeStopParser(rv); } return NS_OK; }
nsresult nsExpatDriver::HandleComment(const PRUnichar *aValue) { NS_ASSERTION(mSink, "content sink not found!"); if (mInExternalDTD) { // Ignore comments from external DTDs return NS_OK; } if (mInInternalSubset) { mInternalSubset.AppendLiteral("<!--"); mInternalSubset.Append(aValue); mInternalSubset.AppendLiteral("-->"); } else if (mSink) { nsresult rv = mSink->HandleComment(aValue); MaybeStopParser(rv); } return NS_OK; }