Fix fo bug 274964 (Switch to Expat's xml declaration parsing). r/sr=jst.
git-svn-id: svn://10.0.0.236/trunk@166810 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -571,12 +571,14 @@ public:
|
||||
virtual nsIScriptEventManager* GetScriptEventManager() = 0;
|
||||
|
||||
/**
|
||||
* Set and get XML declaration. Notice that if version is empty,
|
||||
* there can be no XML declaration (it is a required part).
|
||||
* Set and get XML declaration. If aVersion is null there is no declaration.
|
||||
* aStandalone takes values -1, 0 and 1 indicating respectively that there
|
||||
* was no standalone parameter in the declaration, that it was given as no,
|
||||
* or that it was given as yes.
|
||||
*/
|
||||
virtual void SetXMLDeclaration(const nsAString& aVersion,
|
||||
const nsAString& aEncoding,
|
||||
const nsAString& Standalone) = 0;
|
||||
virtual void SetXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone) = 0;
|
||||
virtual void GetXMLDeclaration(nsAString& aVersion,
|
||||
nsAString& aEncoding,
|
||||
nsAString& Standalone) = 0;
|
||||
|
||||
@@ -4087,25 +4087,26 @@ nsDocument::GetScriptEventManager()
|
||||
}
|
||||
|
||||
void
|
||||
nsDocument::SetXMLDeclaration(const nsAString& aVersion,
|
||||
const nsAString& aEncoding,
|
||||
const nsAString& aStandalone)
|
||||
nsDocument::SetXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
if (aVersion.IsEmpty()) {
|
||||
if (!aVersion || *aVersion == '\0') {
|
||||
mXMLDeclarationBits = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
mXMLDeclarationBits = XML_DECLARATION_BITS_DECLARATION_EXISTS;
|
||||
|
||||
if (!aEncoding.IsEmpty()) {
|
||||
if (aEncoding && *aEncoding != '\0') {
|
||||
mXMLDeclarationBits |= XML_DECLARATION_BITS_ENCODING_EXISTS;
|
||||
}
|
||||
|
||||
if (aStandalone.EqualsLiteral("yes")) {
|
||||
if (aStandalone == 1) {
|
||||
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS |
|
||||
XML_DECLARATION_BITS_STANDALONE_YES;
|
||||
} else if (aStandalone.EqualsLiteral("no")) {
|
||||
}
|
||||
else if (aStandalone == 0) {
|
||||
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,9 +408,9 @@ public:
|
||||
virtual void AddReference(void *aKey, nsISupports *aReference);
|
||||
virtual already_AddRefed<nsISupports> RemoveReference(void *aKey);
|
||||
virtual nsIScriptEventManager* GetScriptEventManager();
|
||||
virtual void SetXMLDeclaration(const nsAString& aVersion,
|
||||
const nsAString& aEncoding,
|
||||
const nsAString& Standalone);
|
||||
virtual void SetXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone);
|
||||
virtual void GetXMLDeclaration(nsAString& aVersion,
|
||||
nsAString& aEncoding,
|
||||
nsAString& Standalone);
|
||||
|
||||
@@ -191,10 +191,11 @@ nsLoadSaveContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoadSaveContentSink::HandleXMLDeclaration(const PRUnichar* aData,
|
||||
PRUint32 aLength)
|
||||
nsLoadSaveContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
return mExpatSink->HandleXMLDeclaration(aData, aLength);
|
||||
return mExpatSink->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -1232,24 +1232,12 @@ nsXMLContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aData,
|
||||
PRUint32 aLength)
|
||||
nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aData);
|
||||
// strlen("<?xml version='a'?>") == 19, shortest decl
|
||||
NS_ENSURE_TRUE(aLength >= 19, NS_ERROR_INVALID_ARG);
|
||||
mDocument->SetXMLDeclaration(aVersion, aEncoding, aStandalone);
|
||||
|
||||
// <?xml version="a" encoding="a" standalone="yes|no"?>
|
||||
const nsAString& data = Substring(aData + 6, aData + aLength - 2); // strip out "<?xml " and "?>"
|
||||
|
||||
nsAutoString version, encoding, standalone;
|
||||
|
||||
// XXX If this is too slow we need to parse this here
|
||||
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("version"), version);
|
||||
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("encoding"), encoding);
|
||||
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("standalone"), standalone);
|
||||
|
||||
mDocument->SetXMLDeclaration(version, encoding, standalone);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -987,8 +987,9 @@ XULContentSinkImpl::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULContentSinkImpl::HandleXMLDeclaration(const PRUnichar *aData,
|
||||
PRUint32 aLength)
|
||||
XULContentSinkImpl::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -223,8 +223,9 @@ txStylesheetSink::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
txStylesheetSink::HandleXMLDeclaration(const PRUnichar *aData,
|
||||
PRUint32 aLength)
|
||||
txStylesheetSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1425,14 +1425,14 @@ XML_SetEntityDeclHandler(XML_Parser parser,
|
||||
{
|
||||
entityDeclHandler = handler;
|
||||
}
|
||||
#endif
|
||||
/* END MOZILLA CHANGE */
|
||||
|
||||
void XMLCALL
|
||||
XML_SetXmlDeclHandler(XML_Parser parser,
|
||||
XML_XmlDeclHandler handler) {
|
||||
xmlDeclHandler = handler;
|
||||
}
|
||||
#endif
|
||||
/* END MOZILLA CHANGE */
|
||||
|
||||
int XMLCALL
|
||||
XML_SetParamEntityParsing(XML_Parser parser,
|
||||
|
||||
@@ -119,12 +119,15 @@ interface nsIExpatSink : nsISupports
|
||||
/**
|
||||
* Handle the XML Declaration.
|
||||
*
|
||||
* @param aData The string.
|
||||
* @param aLength The length of the declaration from
|
||||
* opening '<' to closing '>'.
|
||||
**/
|
||||
void HandleXMLDeclaration([size_is(aLength)] in wstring aData,
|
||||
in unsigned long aLength);
|
||||
* @param aVersion The version string, can be null if not specified.
|
||||
* @param aEncoding The encoding string, can be null if not specified.
|
||||
* @param aStandalone -1, 0, or 1 indicating respectively that there was no
|
||||
* standalone parameter in the declaration, that it was
|
||||
* given as no, or that it was given as yes.
|
||||
*/
|
||||
void HandleXMLDeclaration(in wstring aVersion,
|
||||
in wstring aEncoding,
|
||||
in long aStandalone);
|
||||
|
||||
void ReportError(in wstring aErrorText,
|
||||
in wstring aSourceText);
|
||||
|
||||
@@ -58,6 +58,19 @@ static const PRUnichar kUTF16[] = { 'U', 'T', 'F', '-', '1', '6', '\0' };
|
||||
/***************************** EXPAT CALL BACKS ******************************/
|
||||
// The callback handlers that get called from the expat parser.
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
Driver_HandleXMLDeclaration(void *aUserData,
|
||||
const XML_Char *aVersion,
|
||||
const XML_Char *aEncoding,
|
||||
int aStandalone)
|
||||
{
|
||||
NS_ASSERTION(aUserData, "expat driver should exist");
|
||||
if (aUserData) {
|
||||
nsExpatDriver* driver = NS_STATIC_CAST(nsExpatDriver*, aUserData);
|
||||
driver->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
|
||||
}
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
Driver_HandleStartElement(void *aUserData,
|
||||
const XML_Char *aName,
|
||||
@@ -145,7 +158,7 @@ Driver_HandleEndCdataSection(void *aUserData)
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
Driver_HandleStartDoctypeDecl(void *aUserData,
|
||||
Driver_HandleStartDoctypeDecl(void *aUserData,
|
||||
const XML_Char *aDoctypeName,
|
||||
const XML_Char *aSysid,
|
||||
const XML_Char *aPubid,
|
||||
@@ -321,7 +334,6 @@ nsExpatDriver::nsExpatDriver()
|
||||
mInCData(PR_FALSE),
|
||||
mInDoctype(PR_FALSE),
|
||||
mInExternalDTD(PR_FALSE),
|
||||
mHandledXMLDeclaration(PR_FALSE),
|
||||
mBytePosition(0),
|
||||
mInternalState(NS_OK),
|
||||
mBytesParsed(0),
|
||||
@@ -427,29 +439,11 @@ nsExpatDriver::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsExpatDriver::HandleXMLDeclaration(const PRUnichar *aValue,
|
||||
const PRUint32 aLength)
|
||||
nsExpatDriver::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
mHandledXMLDeclaration = PR_TRUE;
|
||||
|
||||
// <?xml version='a'?>
|
||||
// 0123456789012345678
|
||||
// ?> can start at position 17 at the earliest
|
||||
PRUint32 i;
|
||||
for (i = 17; i < aLength; ++i) {
|
||||
if (aValue[i] == '?')
|
||||
break;
|
||||
}
|
||||
|
||||
// +1 because index starts from 0
|
||||
// +1 because '>' follows '?'
|
||||
i += 2;
|
||||
|
||||
if (i > aLength) {
|
||||
return NS_OK; // Bad declaration
|
||||
}
|
||||
|
||||
return mSink->HandleXMLDeclaration(aValue, i);
|
||||
return mSink->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -464,14 +458,6 @@ nsExpatDriver::HandleDefault(const PRUnichar *aValue,
|
||||
}
|
||||
}
|
||||
else if (mSink) {
|
||||
if (!mHandledXMLDeclaration && !mBytesParsed) {
|
||||
static const PRUnichar xmlDecl[] = { '<', '?', 'x', 'm', 'l', ' ', '\0' };
|
||||
// strlen("<?xml version='a'?>") == 19, shortest decl
|
||||
if (aLength >= 19 && nsCRT::strncmp(aValue, xmlDecl, 6) == 0) {
|
||||
HandleXMLDeclaration(aValue, aLength);
|
||||
}
|
||||
}
|
||||
|
||||
static const PRUnichar newline[] = { '\n', '\0' };
|
||||
PRUint32 i;
|
||||
for (i = 0; i < aLength && NS_SUCCEEDED(mInternalState); ++i) {
|
||||
@@ -649,8 +635,8 @@ nsExpatDriver::HandleExternalEntityRef(const PRUnichar *openEntityNames,
|
||||
|
||||
int result = 1;
|
||||
if (uniIn) {
|
||||
XML_Parser entParser =
|
||||
XML_ExternalEntityParserCreate(mExpatParser, 0, (const XML_Char*)kUTF16);
|
||||
XML_Parser entParser = XML_ExternalEntityParserCreate(mExpatParser, 0,
|
||||
kUTF16);
|
||||
if (entParser) {
|
||||
XML_SetBase(entParser, absURL.get());
|
||||
|
||||
@@ -812,8 +798,8 @@ nsExpatDriver::HandleError(const char *aBuffer,
|
||||
|
||||
nsAutoString errorText;
|
||||
CreateErrorText(description.get(), XML_GetBase(mExpatParser),
|
||||
XML_GetCurrentLineNumber(mExpatParser),
|
||||
colNumber, errorText);
|
||||
XML_GetCurrentLineNumber(mExpatParser), colNumber,
|
||||
errorText);
|
||||
|
||||
nsAutoString sourceText;
|
||||
CreateSourceText(colNumber, sourceLine.get(), sourceText);
|
||||
@@ -1026,6 +1012,7 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
|
||||
XML_SetBase(mExpatParser, aParserContext.mScanner->GetFilename().get());
|
||||
|
||||
// Set up the callbacks
|
||||
XML_SetXmlDeclHandler(mExpatParser, Driver_HandleXMLDeclaration);
|
||||
XML_SetElementHandler(mExpatParser, Driver_HandleStartElement,
|
||||
Driver_HandleEndElement);
|
||||
XML_SetCharacterDataHandler(mExpatParser, Driver_HandleCharacterData);
|
||||
@@ -1178,7 +1165,6 @@ nsExpatDriver::GetTokenAllocator(void)
|
||||
NS_IMETHODIMP_(void)
|
||||
nsExpatDriver::PrependTokens(nsDeque& aDeque)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -70,7 +70,9 @@ public:
|
||||
nsresult HandleComment(const PRUnichar *aName);
|
||||
nsresult HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
const PRUnichar *aData);
|
||||
nsresult HandleXMLDeclaration(const PRUnichar *aData, const PRUint32 aLength);
|
||||
nsresult HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone);
|
||||
nsresult HandleDefault(const PRUnichar *aData, const PRUint32 aLength);
|
||||
nsresult HandleStartCdataSection();
|
||||
nsresult HandleEndCdataSection();
|
||||
|
||||
@@ -570,8 +570,9 @@ RDFContentSinkImpl::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFContentSinkImpl::HandleXMLDeclaration(const PRUnichar *aData,
|
||||
PRUint32 aLength)
|
||||
RDFContentSinkImpl::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
const PRUnichar *aEncoding,
|
||||
const PRInt32 aStandalone)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user