2002-01-09 04:37:50 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
#include "nsExpatDriver.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsParserCIID.h"
|
|
|
|
#include "CParserContext.h"
|
|
|
|
#include "nsIExpatSink.h"
|
2006-03-15 20:45:25 +03:00
|
|
|
#include "nsIExtendedExpatSink.h"
|
2002-01-09 04:37:50 +03:00
|
|
|
#include "nsIContentSink.h"
|
|
|
|
#include "nsParserMsgUtils.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIUnicharInputStream.h"
|
2006-07-21 20:28:51 +04:00
|
|
|
#include "nsISimpleUnicharStreamFactory.h"
|
2002-01-09 04:37:50 +03:00
|
|
|
#include "nsNetUtil.h"
|
2014-09-21 20:44:41 +04:00
|
|
|
#include "nsNullPrincipal.h"
|
2002-01-09 04:37:50 +03:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsTextFormatter.h"
|
2003-03-15 04:04:32 +03:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsCRT.h"
|
2005-06-23 05:54:42 +04:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
2008-02-22 14:32:24 +03:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2006-07-21 20:28:51 +04:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
#include "nsUnicharInputStream.h"
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2005-01-23 18:46:11 +03:00
|
|
|
#define kExpatSeparatorChar 0xFFFF
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kUTF16[] = { 'U', 'T', 'F', '-', '1', '6', '\0' };
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2006-01-27 17:47:23 +03:00
|
|
|
#ifdef PR_LOGGING
|
2012-10-30 03:32:10 +04:00
|
|
|
static PRLogModuleInfo *
|
|
|
|
GetExpatDriverLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("expatdriver");
|
|
|
|
return sLog;
|
|
|
|
}
|
2006-01-27 17:47:23 +03:00
|
|
|
#endif
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
/***************************** EXPAT CALL BACKS ******************************/
|
|
|
|
// The callback handlers that get called from the expat parser.
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-12-17 12:17:35 +03:00
|
|
|
Driver_HandleXMLDeclaration(void *aUserData,
|
|
|
|
const XML_Char *aVersion,
|
|
|
|
const XML_Char *aEncoding,
|
|
|
|
int aStandalone)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsExpatDriver* driver = static_cast<nsExpatDriver*>(aUserData);
|
2004-12-17 12:17:35 +03:00
|
|
|
driver->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-05-08 18:07:18 +04:00
|
|
|
Driver_HandleStartElement(void *aUserData,
|
|
|
|
const XML_Char *aName,
|
|
|
|
const XML_Char **aAtts)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->HandleStartElement(aName,
|
2004-12-15 18:37:23 +03:00
|
|
|
aAtts);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-05-08 18:07:18 +04:00
|
|
|
Driver_HandleEndElement(void *aUserData,
|
|
|
|
const XML_Char *aName)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->HandleEndElement(aName);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2002-01-09 04:37:50 +03:00
|
|
|
Driver_HandleCharacterData(void *aUserData,
|
2004-05-08 18:07:18 +04:00
|
|
|
const XML_Char *aData,
|
2002-01-09 04:37:50 +03:00
|
|
|
int aLength)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsExpatDriver* driver = static_cast<nsExpatDriver*>(aUserData);
|
2012-08-22 19:56:38 +04:00
|
|
|
driver->HandleCharacterData(aData, uint32_t(aLength));
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2002-01-09 04:37:50 +03:00
|
|
|
Driver_HandleComment(void *aUserData,
|
2004-05-08 18:07:18 +04:00
|
|
|
const XML_Char *aName)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if(aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->HandleComment(aName);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-05-08 18:07:18 +04:00
|
|
|
Driver_HandleProcessingInstruction(void *aUserData,
|
|
|
|
const XML_Char *aTarget,
|
2002-01-09 04:37:50 +03:00
|
|
|
const XML_Char *aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsExpatDriver* driver = static_cast<nsExpatDriver*>(aUserData);
|
2004-12-15 18:37:23 +03:00
|
|
|
driver->HandleProcessingInstruction(aTarget, aData);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-05-08 18:07:18 +04:00
|
|
|
Driver_HandleDefault(void *aUserData,
|
|
|
|
const XML_Char *aData,
|
|
|
|
int aLength)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsExpatDriver* driver = static_cast<nsExpatDriver*>(aUserData);
|
2012-08-22 19:56:38 +04:00
|
|
|
driver->HandleDefault(aData, uint32_t(aLength));
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2002-01-09 04:37:50 +03:00
|
|
|
Driver_HandleStartCdataSection(void *aUserData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->HandleStartCdataSection();
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2002-01-09 04:37:50 +03:00
|
|
|
Driver_HandleEndCdataSection(void *aUserData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->HandleEndCdataSection();
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-12-17 12:17:35 +03:00
|
|
|
Driver_HandleStartDoctypeDecl(void *aUserData,
|
2004-12-15 18:37:23 +03:00
|
|
|
const XML_Char *aDoctypeName,
|
|
|
|
const XML_Char *aSysid,
|
|
|
|
const XML_Char *aPubid,
|
|
|
|
int aHasInternalSubset)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->
|
2008-09-10 04:42:04 +04:00
|
|
|
HandleStartDoctypeDecl(aDoctypeName, aSysid, aPubid, !!aHasInternalSubset);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2004-05-08 18:07:18 +04:00
|
|
|
Driver_HandleEndDoctypeDecl(void *aUserData)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->HandleEndDoctypeDecl();
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static int
|
2004-05-08 18:07:18 +04:00
|
|
|
Driver_HandleExternalEntityRef(void *aExternalEntityRefHandler,
|
|
|
|
const XML_Char *aOpenEntityNames,
|
|
|
|
const XML_Char *aBase,
|
|
|
|
const XML_Char *aSystemId,
|
|
|
|
const XML_Char *aPublicId)
|
2002-01-15 02:34:37 +03:00
|
|
|
{
|
2002-03-15 12:45:31 +03:00
|
|
|
NS_ASSERTION(aExternalEntityRefHandler, "expat driver should exist");
|
2004-05-08 18:07:18 +04:00
|
|
|
if (!aExternalEntityRefHandler) {
|
|
|
|
return 1;
|
2002-03-15 12:45:31 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
nsExpatDriver* driver = static_cast<nsExpatDriver*>
|
|
|
|
(aExternalEntityRefHandler);
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
return driver->HandleExternalEntityRef(aOpenEntityNames, aBase, aSystemId,
|
|
|
|
aPublicId);
|
2002-03-15 12:45:31 +03:00
|
|
|
}
|
2002-01-15 03:35:11 +03:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2006-03-15 20:45:25 +03:00
|
|
|
Driver_HandleStartNamespaceDecl(void *aUserData,
|
|
|
|
const XML_Char *aPrefix,
|
|
|
|
const XML_Char *aUri)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->
|
2006-03-15 20:45:25 +03:00
|
|
|
HandleStartNamespaceDecl(aPrefix, aUri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2006-03-15 20:45:25 +03:00
|
|
|
Driver_HandleEndNamespaceDecl(void *aUserData,
|
|
|
|
const XML_Char *aPrefix)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aUserData, "expat driver should exist");
|
|
|
|
if (aUserData) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->
|
2006-03-15 20:45:25 +03:00
|
|
|
HandleEndNamespaceDecl(aPrefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2006-03-15 20:45:25 +03:00
|
|
|
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) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->
|
2006-03-15 20:45:25 +03:00
|
|
|
HandleNotationDecl(aNotationName, aBase, aSysid, aPubid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2006-03-15 20:45:25 +03:00
|
|
|
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) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsExpatDriver*>(aUserData)->
|
2006-03-15 20:45:25 +03:00
|
|
|
HandleUnparsedEntityDecl(aEntityName, aBase, aSysid, aPubid,
|
|
|
|
aNotationName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
/***************************** END CALL BACKS ********************************/
|
2002-01-15 02:34:37 +03:00
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
/***************************** CATALOG UTILS *********************************/
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
// Initially added for bug 113400 to switch from the remote "XHTML 1.0 plus
|
|
|
|
// MathML 2.0" DTD to the the lightweight customized version that Mozilla uses.
|
2004-05-08 18:07:18 +04:00
|
|
|
// Since Mozilla is not validating, no need to fetch a *huge* file at each
|
|
|
|
// click.
|
|
|
|
// XXX The cleanest solution here would be to fix Bug 98413: Implement XML
|
|
|
|
// Catalogs.
|
2002-03-15 12:45:31 +03:00
|
|
|
struct nsCatalogData {
|
|
|
|
const char* mPublicID;
|
|
|
|
const char* mLocalDTD;
|
|
|
|
const char* mAgentSheet;
|
|
|
|
};
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
// The order of this table is guestimated to be in the optimum order
|
|
|
|
static const nsCatalogData kCatalogTable[] = {
|
2012-07-30 18:20:58 +04:00
|
|
|
{ "-//W3C//DTD XHTML 1.0 Transitional//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ "-//W3C//DTD XHTML 1.1//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ "-//W3C//DTD XHTML 1.0 Strict//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ "-//W3C//DTD XHTML 1.0 Frameset//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ "-//W3C//DTD XHTML Basic 1.0//EN", "htmlmathml-f.ent", nullptr },
|
2014-05-24 22:46:38 +04:00
|
|
|
{ "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ "-//W3C//DTD MathML 2.0//EN", "htmlmathml-f.ent", nullptr },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ "-//WAPFORUM//DTD XHTML Mobile 1.0//EN", "htmlmathml-f.ent", nullptr },
|
|
|
|
{ nullptr, nullptr, nullptr }
|
2002-03-15 12:45:31 +03:00
|
|
|
};
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
static const nsCatalogData*
|
2014-01-04 19:02:17 +04:00
|
|
|
LookupCatalogData(const char16_t* aPublicID)
|
2002-03-15 12:45:31 +03:00
|
|
|
{
|
2004-05-08 18:07:18 +04:00
|
|
|
nsDependentString publicID(aPublicID);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
// linear search for now since the number of entries is going to
|
|
|
|
// be negligible, and the fix for bug 98413 would get rid of this
|
|
|
|
// code anyway
|
|
|
|
const nsCatalogData* data = kCatalogTable;
|
|
|
|
while (data->mPublicID) {
|
2004-05-08 18:07:18 +04:00
|
|
|
if (publicID.EqualsASCII(data->mPublicID)) {
|
2002-03-15 12:45:31 +03:00
|
|
|
return data;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2002-03-15 12:45:31 +03:00
|
|
|
++data;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2010-04-02 22:32:38 +04:00
|
|
|
// This function provides a resource URI to a local DTD
|
|
|
|
// in resource://gre/res/dtd/ which may or may not exist.
|
|
|
|
// If aCatalogData is provided, it is used to remap the
|
|
|
|
// DTD instead of taking the filename from the URI.
|
|
|
|
static void
|
|
|
|
GetLocalDTDURI(const nsCatalogData* aCatalogData, nsIURI* aDTD,
|
2004-05-08 18:07:18 +04:00
|
|
|
nsIURI** aResult)
|
2002-03-15 12:45:31 +03:00
|
|
|
{
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_ASSERTION(aDTD, "Null parameter.");
|
2002-03-15 12:45:31 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString fileName;
|
2002-03-15 12:45:31 +03:00
|
|
|
if (aCatalogData) {
|
|
|
|
// remap the DTD to a known local DTD
|
|
|
|
fileName.Assign(aCatalogData->mLocalDTD);
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
if (fileName.IsEmpty()) {
|
2004-05-08 18:07:18 +04:00
|
|
|
// Try to see if the user has installed the DTD file -- we extract the
|
2002-03-15 12:45:31 +03:00
|
|
|
// filename.ext of the DTD here. Hence, for any DTD for which we have
|
|
|
|
// no predefined mapping, users just have to copy the DTD file to our
|
2004-05-08 18:07:18 +04:00
|
|
|
// special DTD directory and it will be picked.
|
|
|
|
nsCOMPtr<nsIURL> dtdURL = do_QueryInterface(aDTD);
|
|
|
|
if (!dtdURL) {
|
2010-04-02 22:32:38 +04:00
|
|
|
return;
|
2002-03-15 12:45:31 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
|
|
|
dtdURL->GetFileName(fileName);
|
|
|
|
if (fileName.IsEmpty()) {
|
2010-04-02 22:32:38 +04:00
|
|
|
return;
|
2002-03-15 12:45:31 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-07 17:22:39 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString respath("resource://gre/res/dtd/");
|
2010-04-02 22:32:38 +04:00
|
|
|
respath += fileName;
|
|
|
|
NS_NewURI(aResult, respath);
|
2002-03-15 12:45:31 +03:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
/***************************** END CATALOG UTILS *****************************/
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2008-02-09 01:07:51 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsExpatDriver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITokenizer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDTD)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDTD)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsExpatDriver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsExpatDriver)
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsExpatDriver, mSink, mExtendedSink)
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
nsExpatDriver::nsExpatDriver()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mExpatParser(nullptr),
|
2011-10-17 18:59:28 +04:00
|
|
|
mInCData(false),
|
|
|
|
mInInternalSubset(false),
|
|
|
|
mInExternalDTD(false),
|
|
|
|
mMadeFinalCallToExpat(false),
|
|
|
|
mIsFinalChunk(false),
|
2004-05-08 18:07:18 +04:00
|
|
|
mInternalState(NS_OK),
|
2006-01-27 17:47:23 +03:00
|
|
|
mExpatBuffered(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mCatalogData(nullptr),
|
2011-08-25 00:44:35 +04:00
|
|
|
mInnerWindowID(0)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsExpatDriver::~nsExpatDriver()
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2002-01-09 21:49:45 +03:00
|
|
|
if (mExpatParser) {
|
|
|
|
XML_ParserFree(mExpatParser);
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleStartElement(const char16_t *aValue,
|
|
|
|
const char16_t **aAtts)
|
2004-05-08 18:07:18 +04:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
|
|
|
|
2003-10-30 05:17:50 +03:00
|
|
|
// 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.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t attrArrayLength;
|
2003-10-30 05:17:50 +03:00
|
|
|
for (attrArrayLength = XML_GetSpecifiedAttributeCount(mExpatParser);
|
|
|
|
aAtts[attrArrayLength];
|
|
|
|
attrArrayLength += 2) {
|
|
|
|
// Just looping till we find out what the length is
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
|
|
|
if (mSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->
|
2007-01-31 00:21:06 +03:00
|
|
|
HandleStartElement(aValue, aAtts, attrArrayLength,
|
|
|
|
XML_GetCurrentLineNumber(mExpatParser));
|
2007-11-19 13:57:29 +03:00
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleEndElement(const char16_t *aValue)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
2007-11-19 13:57:29 +03:00
|
|
|
NS_ASSERTION(mInternalState != NS_ERROR_HTMLPARSER_BLOCK,
|
|
|
|
"Shouldn't block from HandleStartElement.");
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2007-11-19 13:57:29 +03:00
|
|
|
if (mSink && mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) {
|
|
|
|
nsresult rv = mSink->HandleEndElement(aValue);
|
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleCharacterData(const char16_t *aValue,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t aLength)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
|
|
|
|
|
|
|
if (mInCData) {
|
2004-05-08 18:07:18 +04:00
|
|
|
mCDataText.Append(aValue, aLength);
|
|
|
|
}
|
|
|
|
else if (mSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->HandleCharacterData(aValue, aLength);
|
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleComment(const char16_t *aValue)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
|
|
|
|
2005-09-01 22:59:46 +04:00
|
|
|
if (mInExternalDTD) {
|
|
|
|
// Ignore comments from external DTDs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-13 23:45:43 +04:00
|
|
|
if (mInInternalSubset) {
|
2005-09-01 22:59:46 +04:00
|
|
|
mInternalSubset.AppendLiteral("<!--");
|
|
|
|
mInternalSubset.Append(aValue);
|
|
|
|
mInternalSubset.AppendLiteral("-->");
|
2002-05-22 04:46:16 +04:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
else if (mSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->HandleComment(aValue);
|
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleProcessingInstruction(const char16_t *aTarget,
|
|
|
|
const char16_t *aData)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
|
|
|
|
2005-09-01 22:59:46 +04:00
|
|
|
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("?>");
|
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
else if (mSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->HandleProcessingInstruction(aTarget, aData);
|
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleXMLDeclaration(const char16_t *aVersion,
|
|
|
|
const char16_t *aEncoding,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aStandalone)
|
2004-12-17 12:17:35 +03:00
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
if (mSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->HandleXMLDeclaration(aVersion, aEncoding, aStandalone);
|
|
|
|
MaybeStopParser(rv);
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-08-13 22:41:16 +04:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleDefault(const char16_t *aValue,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t aLength)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
|
|
|
|
2005-09-01 22:59:46 +04:00
|
|
|
if (mInExternalDTD) {
|
|
|
|
// Ignore newlines in external DTDs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-13 23:45:43 +04:00
|
|
|
if (mInInternalSubset) {
|
2005-09-01 22:59:46 +04:00
|
|
|
mInternalSubset.Append(aValue, aLength);
|
2002-05-22 04:46:16 +04:00
|
|
|
}
|
|
|
|
else if (mSink) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mInternalState;
|
|
|
|
for (i = 0; i < aLength && NS_SUCCEEDED(rv); ++i) {
|
2002-01-09 04:37:50 +03:00
|
|
|
if (aValue[i] == '\n' || aValue[i] == '\r') {
|
2007-11-19 13:57:29 +03:00
|
|
|
rv = mSink->HandleCharacterData(&aValue[i], 1);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-19 13:57:29 +03:00
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2002-01-09 04:37:50 +03:00
|
|
|
nsExpatDriver::HandleStartCdataSection()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mInCData = true;
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2002-01-09 04:37:50 +03:00
|
|
|
nsExpatDriver::HandleEndCdataSection()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInCData = false;
|
2002-01-09 04:37:50 +03:00
|
|
|
if (mSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->HandleCDataSection(mCDataText.get(),
|
|
|
|
mCDataText.Length());
|
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
mCDataText.Truncate();
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-15 20:45:25 +03:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleStartNamespaceDecl(const char16_t* aPrefix,
|
|
|
|
const char16_t* aUri)
|
2006-03-15 20:45:25 +03:00
|
|
|
{
|
|
|
|
if (mExtendedSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mExtendedSink->HandleStartNamespaceDecl(aPrefix, aUri);
|
|
|
|
MaybeStopParser(rv);
|
2006-03-15 20:45:25 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleEndNamespaceDecl(const char16_t* aPrefix)
|
2006-03-15 20:45:25 +03:00
|
|
|
{
|
2007-11-19 13:57:29 +03:00
|
|
|
if (mExtendedSink && mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) {
|
|
|
|
nsresult rv = mExtendedSink->HandleEndNamespaceDecl(aPrefix);
|
|
|
|
MaybeStopParser(rv);
|
2006-03-15 20:45:25 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleNotationDecl(const char16_t* aNotationName,
|
|
|
|
const char16_t* aBase,
|
|
|
|
const char16_t* aSysid,
|
|
|
|
const char16_t* aPubid)
|
2006-03-15 20:45:25 +03:00
|
|
|
{
|
|
|
|
if (mExtendedSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mExtendedSink->HandleNotationDecl(aNotationName, aSysid,
|
|
|
|
aPubid);
|
|
|
|
MaybeStopParser(rv);
|
2006-03-15 20:45:25 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleUnparsedEntityDecl(const char16_t* aEntityName,
|
|
|
|
const char16_t* aBase,
|
|
|
|
const char16_t* aSysid,
|
|
|
|
const char16_t* aPubid,
|
|
|
|
const char16_t* aNotationName)
|
2006-03-15 20:45:25 +03:00
|
|
|
{
|
|
|
|
if (mExtendedSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mExtendedSink->HandleUnparsedEntityDecl(aEntityName,
|
|
|
|
aSysid,
|
|
|
|
aPubid,
|
|
|
|
aNotationName);
|
|
|
|
MaybeStopParser(rv);
|
2006-03-15 20:45:25 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleStartDoctypeDecl(const char16_t* aDoctypeName,
|
|
|
|
const char16_t* aSysid,
|
|
|
|
const char16_t* aPubid,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHasInternalSubset)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2005-05-13 23:45:43 +04:00
|
|
|
mDoctypeName = aDoctypeName;
|
|
|
|
mSystemID = aSysid;
|
|
|
|
mPublicID = aPubid;
|
|
|
|
|
2006-03-15 20:45:25 +03:00
|
|
|
if (mExtendedSink) {
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mExtendedSink->HandleStartDTD(aDoctypeName, aSysid, aPubid);
|
|
|
|
MaybeStopParser(rv);
|
2006-03-15 20:45:25 +03:00
|
|
|
}
|
|
|
|
|
2005-05-13 23:45:43 +04:00
|
|
|
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! ).
|
2011-10-17 18:59:28 +04:00
|
|
|
mInInternalSubset = true;
|
2005-05-13 23:45:43 +04:00
|
|
|
mInternalSubset.SetCapacity(1024);
|
2008-06-14 12:24:13 +04:00
|
|
|
} else {
|
|
|
|
// Distinguish missing internal subset from an empty one
|
2011-10-17 18:59:28 +04:00
|
|
|
mInternalSubset.SetIsVoid(true);
|
2005-05-13 23:45:43 +04:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
|
|
|
nsExpatDriver::HandleEndDoctypeDecl()
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSink, "content sink not found!");
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInInternalSubset = false;
|
2002-05-22 04:46:16 +04:00
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
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)
|
2003-03-08 02:40:51 +03:00
|
|
|
nsCOMPtr<nsIURI> data;
|
2014-05-24 22:46:38 +04:00
|
|
|
#if 0
|
2002-03-15 12:45:31 +03:00
|
|
|
if (mCatalogData && mCatalogData->mAgentSheet) {
|
2003-03-08 02:40:51 +03:00
|
|
|
NS_NewURI(getter_AddRefs(data), mCatalogData->mAgentSheet);
|
2002-03-15 12:45:31 +03:00
|
|
|
}
|
2014-05-24 22:46:38 +04:00
|
|
|
#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");
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2005-05-13 23:45:43 +04:00
|
|
|
// Note: mInternalSubset already doesn't include the [] around it.
|
2007-11-19 13:57:29 +03:00
|
|
|
nsresult rv = mSink->HandleDoctypeDecl(mInternalSubset, mDoctypeName,
|
|
|
|
mSystemID, mPublicID, data);
|
|
|
|
MaybeStopParser(rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2005-05-13 23:45:43 +04:00
|
|
|
|
|
|
|
mInternalSubset.SetCapacity(0);
|
2002-01-25 01:15:58 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-08 00:23:34 +03:00
|
|
|
static NS_METHOD
|
|
|
|
ExternalDTDStreamReaderFunc(nsIUnicharInputStream* aIn,
|
|
|
|
void* aClosure,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aFromSegment,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aToOffset,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t *aWriteCount)
|
2004-02-08 00:23:34 +03:00
|
|
|
{
|
2005-12-18 13:39:23 +03:00
|
|
|
// Pass the buffer to expat for parsing.
|
2004-12-27 14:47:18 +03:00
|
|
|
if (XML_Parse((XML_Parser)aClosure, (const char *)aFromSegment,
|
2014-01-04 19:02:17 +04:00
|
|
|
aCount * sizeof(char16_t), 0) == XML_STATUS_OK) {
|
2004-02-08 00:23:34 +03:00
|
|
|
*aWriteCount = aCount;
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2004-02-08 00:23:34 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2004-02-08 00:23:34 +03:00
|
|
|
*aWriteCount = 0;
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2004-02-08 00:23:34 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
int
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::HandleExternalEntityRef(const char16_t *openEntityNames,
|
|
|
|
const char16_t *base,
|
|
|
|
const char16_t *systemId,
|
|
|
|
const char16_t *publicId)
|
2002-03-15 12:45:31 +03:00
|
|
|
{
|
2005-05-13 23:45:43 +04:00
|
|
|
if (mInInternalSubset && !mInExternalDTD && openEntityNames) {
|
2014-01-04 19:02:17 +04:00
|
|
|
mInternalSubset.Append(char16_t('%'));
|
2005-05-13 23:45:43 +04:00
|
|
|
mInternalSubset.Append(nsDependentString(openEntityNames));
|
2014-01-04 19:02:17 +04:00
|
|
|
mInternalSubset.Append(char16_t(';'));
|
2003-03-08 02:40:51 +03:00
|
|
|
}
|
2002-01-16 01:52:32 +03:00
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
// Load the external entity into a buffer.
|
2002-03-15 12:45:31 +03:00
|
|
|
nsCOMPtr<nsIInputStream> in;
|
|
|
|
nsAutoString absURL;
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult rv = OpenInputStreamFromExternalDTD(publicId, systemId, base,
|
|
|
|
getter_AddRefs(in), absURL);
|
2012-03-26 23:40:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCString message("Failed to open external DTD: publicId \"");
|
|
|
|
AppendUTF16toUTF8(publicId, message);
|
|
|
|
message += "\" systemId \"";
|
|
|
|
AppendUTF16toUTF8(systemId, message);
|
|
|
|
message += "\" base \"";
|
|
|
|
AppendUTF16toUTF8(base, message);
|
|
|
|
message += "\" URL \"";
|
|
|
|
AppendUTF16toUTF8(absURL, message);
|
|
|
|
message += "\"";
|
|
|
|
NS_WARNING(message.get());
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
2002-01-16 01:52:32 +03:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
nsCOMPtr<nsIUnicharInputStream> uniIn;
|
2006-07-21 20:28:51 +04:00
|
|
|
rv = nsSimpleUnicharStreamFactory::GetInstance()->
|
|
|
|
CreateInstanceFromUTF8Stream(in, getter_AddRefs(uniIn));
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
2003-01-31 22:21:24 +03:00
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
int result = 1;
|
2002-03-15 12:45:31 +03:00
|
|
|
if (uniIn) {
|
2004-12-17 12:17:35 +03:00
|
|
|
XML_Parser entParser = XML_ExternalEntityParserCreate(mExpatParser, 0,
|
|
|
|
kUTF16);
|
2002-03-15 12:45:31 +03:00
|
|
|
if (entParser) {
|
2004-12-15 18:37:23 +03:00
|
|
|
XML_SetBase(entParser, absURL.get());
|
2002-03-15 12:45:31 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInExternalDTD = true;
|
2003-01-31 22:21:24 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t totalRead;
|
2004-02-08 00:23:34 +03:00
|
|
|
do {
|
2004-05-08 18:07:18 +04:00
|
|
|
rv = uniIn->ReadSegments(ExternalDTDStreamReaderFunc, entParser,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t(-1), &totalRead);
|
2004-02-08 00:23:34 +03:00
|
|
|
} while (NS_SUCCEEDED(rv) && totalRead > 0);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
result = XML_Parse(entParser, nullptr, 0, 1);
|
2003-01-31 22:21:24 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInExternalDTD = false;
|
2003-01-31 22:21:24 +03:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
XML_ParserFree(entParser);
|
2002-01-16 01:52:32 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-03-15 12:45:31 +03:00
|
|
|
return result;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::OpenInputStreamFromExternalDTD(const char16_t* aFPIStr,
|
|
|
|
const char16_t* aURLStr,
|
|
|
|
const char16_t* aBaseURL,
|
2004-05-08 18:07:18 +04:00
|
|
|
nsIInputStream** aStream,
|
|
|
|
nsAString& aAbsURL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(baseURI),
|
|
|
|
NS_ConvertUTF16toUTF8(aBaseURL));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(aURLStr), nullptr,
|
2004-05-08 18:07:18 +04:00
|
|
|
baseURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// check if it is alright to load this uri
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
2004-05-08 18:07:18 +04:00
|
|
|
uri->SchemeIs("chrome", &isChrome);
|
|
|
|
if (!isChrome) {
|
|
|
|
// since the url is not a chrome url, check to see if we can map the DTD
|
|
|
|
// to a known local DTD, or if a DTD file of the same name exists in the
|
|
|
|
// special DTD directory
|
|
|
|
if (aFPIStr) {
|
|
|
|
// see if the Formal Public Identifier (FPI) maps to a catalog entry
|
|
|
|
mCatalogData = LookupCatalogData(aFPIStr);
|
2004-05-07 16:14:38 +04:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> localURI;
|
2010-04-02 22:32:38 +04:00
|
|
|
GetLocalDTDURI(mCatalogData, uri, getter_AddRefs(localURI));
|
|
|
|
if (!localURI) {
|
2004-05-08 18:07:18 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
localURI.swap(uri);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2008-02-22 14:32:24 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2009-06-24 01:22:17 +04:00
|
|
|
NS_ASSERTION(mSink == nsCOMPtr<nsIExpatSink>(do_QueryInterface(mOriginalSink)),
|
|
|
|
"In nsExpatDriver::OpenInputStreamFromExternalDTD: "
|
|
|
|
"mOriginalSink not the same object as mSink?");
|
|
|
|
if (mOriginalSink)
|
|
|
|
doc = do_QueryInterface(mOriginalSink->GetTarget());
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t shouldLoad = nsIContentPolicy::ACCEPT;
|
2008-03-05 13:29:32 +03:00
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_DTD,
|
2008-02-22 14:32:24 +03:00
|
|
|
uri,
|
2012-07-30 18:20:58 +04:00
|
|
|
(doc ? doc->NodePrincipal() : nullptr),
|
2008-02-22 14:32:24 +03:00
|
|
|
doc,
|
|
|
|
EmptyCString(), //mime guess
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, //extra
|
2008-02-22 14:32:24 +03:00
|
|
|
&shouldLoad);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (NS_CP_REJECTED(shouldLoad)) {
|
|
|
|
// Disallowed by content policy
|
|
|
|
return NS_ERROR_CONTENT_BLOCKED;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString absURL;
|
2004-05-08 18:07:18 +04:00
|
|
|
uri->GetSpec(absURL);
|
|
|
|
|
|
|
|
CopyUTF8toUTF16(absURL, aAbsURL);
|
|
|
|
|
2010-07-07 11:38:56 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2014-09-21 20:44:41 +04:00
|
|
|
if (doc) {
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
|
|
|
doc,
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
|
|
|
nsIContentPolicy::TYPE_DTD);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIPrincipal> nullPrincipal =
|
|
|
|
do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
|
|
|
nullPrincipal,
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
|
|
|
nsIContentPolicy::TYPE_DTD);
|
|
|
|
}
|
2010-07-07 11:38:56 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
channel->SetContentType(NS_LITERAL_CSTRING("application/xml"));
|
|
|
|
return channel->Open(aStream);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
static nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
CreateErrorText(const char16_t* aDescription,
|
|
|
|
const char16_t* aSourceURL,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t aLineNumber,
|
|
|
|
const uint32_t aColNumber,
|
2002-01-09 04:37:50 +03:00
|
|
|
nsString& aErrorString)
|
|
|
|
{
|
|
|
|
aErrorString.Truncate();
|
|
|
|
|
|
|
|
nsAutoString msg;
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsParserMsgUtils::GetLocalizedStringByName(XMLPARSER_PROPERTIES,
|
|
|
|
"XMLParsingError", msg);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2006-07-13 16:50:58 +04:00
|
|
|
// XML Parsing Error: %1$S\nLocation: %2$S\nLine Number %3$u, Column %4$u:
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t *message = nsTextFormatter::smprintf(msg.get(), aDescription,
|
2004-05-08 18:07:18 +04:00
|
|
|
aSourceURL, aLineNumber,
|
|
|
|
aColNumber);
|
2002-01-09 04:37:50 +03:00
|
|
|
if (!message) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
aErrorString.Assign(message);
|
|
|
|
nsTextFormatter::smprintf_free(message);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
static nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
AppendErrorPointer(const int32_t aColNumber,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aSourceLine,
|
2005-09-08 20:43:30 +04:00
|
|
|
nsString& aSourceString)
|
2004-05-08 18:07:18 +04:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
aSourceString.Append(char16_t('\n'));
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2005-01-23 18:46:11 +03:00
|
|
|
// Last character will be '^'.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t last = aColNumber - 1;
|
|
|
|
int32_t i;
|
|
|
|
uint32_t minuses = 0;
|
2005-01-23 18:46:11 +03:00
|
|
|
for (i = 0; i < last; ++i) {
|
|
|
|
if (aSourceLine[i] == '\t') {
|
|
|
|
// Since this uses |white-space: pre;| a tab stop equals 8 spaces.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t add = 8 - (minuses % 8);
|
2005-01-23 18:46:11 +03:00
|
|
|
aSourceString.AppendASCII("--------", add);
|
|
|
|
minuses += add;
|
|
|
|
}
|
|
|
|
else {
|
2014-01-04 19:02:17 +04:00
|
|
|
aSourceString.Append(char16_t('-'));
|
2005-01-23 18:46:11 +03:00
|
|
|
++minuses;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aSourceString.Append(char16_t('^'));
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
nsresult
|
2005-07-26 17:09:19 +04:00
|
|
|
nsExpatDriver::HandleError()
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t code = XML_GetErrorCode(mExpatParser);
|
2006-03-30 22:40:56 +04:00
|
|
|
NS_ASSERTION(code > XML_ERROR_NONE, "unexpected XML error code");
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// Map Expat error code to an error string
|
|
|
|
// XXX Deal with error returns.
|
|
|
|
nsAutoString description;
|
2004-05-08 18:07:18 +04:00
|
|
|
nsParserMsgUtils::GetLocalizedStringByID(XMLPARSER_PROPERTIES, code,
|
|
|
|
description);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
if (code == XML_ERROR_TAG_MISMATCH) {
|
2005-01-23 18:46:11 +03:00
|
|
|
/**
|
|
|
|
* Expat can send the following:
|
|
|
|
* localName
|
|
|
|
* namespaceURI<separator>localName
|
|
|
|
* namespaceURI<separator>localName<separator>prefix
|
|
|
|
*
|
|
|
|
* and we use 0xFFFF for the <separator>.
|
|
|
|
*
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *mismatch = MOZ_XML_GetMismatchedTag(mExpatParser);
|
|
|
|
const char16_t *uriEnd = nullptr;
|
|
|
|
const char16_t *nameEnd = nullptr;
|
|
|
|
const char16_t *pos;
|
2005-01-23 18:46:11 +03:00
|
|
|
for (pos = mismatch; *pos; ++pos) {
|
|
|
|
if (*pos == kExpatSeparatorChar) {
|
|
|
|
if (uriEnd) {
|
|
|
|
nameEnd = pos;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uriEnd = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tagName;
|
|
|
|
if (uriEnd && nameEnd) {
|
2005-07-26 17:09:19 +04:00
|
|
|
// We have a prefix.
|
|
|
|
tagName.Append(nameEnd + 1, pos - nameEnd - 1);
|
2014-01-04 19:02:17 +04:00
|
|
|
tagName.Append(char16_t(':'));
|
2005-01-23 18:46:11 +03:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *nameStart = uriEnd ? uriEnd + 1 : mismatch;
|
2005-01-23 18:46:11 +03:00
|
|
|
tagName.Append(nameStart, (nameEnd ? nameEnd : pos) - nameStart);
|
|
|
|
|
2002-02-20 06:16:14 +03:00
|
|
|
nsAutoString msg;
|
2004-05-08 18:07:18 +04:00
|
|
|
nsParserMsgUtils::GetLocalizedStringByName(XMLPARSER_PROPERTIES,
|
|
|
|
"Expected", msg);
|
2005-01-23 18:46:11 +03:00
|
|
|
|
2002-02-20 06:16:14 +03:00
|
|
|
// . Expected: </%S>.
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t *message = nsTextFormatter::smprintf(msg.get(), tagName.get());
|
2002-02-20 06:16:14 +03:00
|
|
|
if (!message) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-02-20 06:16:14 +03:00
|
|
|
description.Append(message);
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-02-20 06:16:14 +03:00
|
|
|
nsTextFormatter::smprintf_free(message);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// Adjust the column number so that it is one based rather than zero based.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t colNumber = XML_GetCurrentColumnNumber(mExpatParser) + 1;
|
|
|
|
uint32_t lineNumber = XML_GetCurrentLineNumber(mExpatParser);
|
2005-06-23 05:54:42 +04:00
|
|
|
|
2005-07-26 17:09:19 +04:00
|
|
|
nsAutoString errorText;
|
|
|
|
CreateErrorText(description.get(), XML_GetBase(mExpatParser), lineNumber,
|
|
|
|
colNumber, errorText);
|
|
|
|
|
2006-08-25 20:34:57 +04:00
|
|
|
NS_ASSERTION(mSink, "no sink?");
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2005-09-08 20:43:30 +04:00
|
|
|
nsAutoString sourceText(mLastLine);
|
|
|
|
AppendErrorPointer(colNumber, mLastLine.get(), sourceText);
|
|
|
|
|
2006-08-25 20:34:57 +04:00
|
|
|
// Try to create and initialize the script error.
|
|
|
|
nsCOMPtr<nsIScriptError> serr(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (serr) {
|
2012-09-10 03:29:12 +04:00
|
|
|
rv = serr->InitWithWindowID(description,
|
|
|
|
mURISpec,
|
|
|
|
mLastLine,
|
2011-12-22 01:51:29 +04:00
|
|
|
lineNumber, colNumber,
|
|
|
|
nsIScriptError::errorFlag, "malformed-xml",
|
|
|
|
mInnerWindowID);
|
2006-08-25 20:34:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it didn't initialize, we can't do any logging.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldReportError = NS_SUCCEEDED(rv);
|
2006-08-25 20:34:57 +04:00
|
|
|
|
|
|
|
if (mSink && shouldReportError) {
|
|
|
|
rv = mSink->ReportError(errorText.get(),
|
|
|
|
sourceText.get(),
|
|
|
|
serr,
|
|
|
|
&shouldReportError);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
shouldReportError = true;
|
2006-08-25 20:34:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldReportError) {
|
|
|
|
nsCOMPtr<nsIConsoleService> cs
|
|
|
|
(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (cs) {
|
|
|
|
cs->LogMessage(serr);
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_HTMLPARSER_STOPPARSING;
|
|
|
|
}
|
|
|
|
|
2006-01-27 17:47:23 +03:00
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsExpatDriver::ParseBuffer(const char16_t *aBuffer,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsFinal,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *aConsumed)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_ASSERTION((aBuffer && aLength != 0) || (!aBuffer && aLength == 0), "?");
|
2006-01-27 17:47:23 +03:00
|
|
|
NS_ASSERTION(mInternalState != NS_OK || aIsFinal || aBuffer,
|
|
|
|
"Useless call, we won't call Expat");
|
2007-01-31 00:21:06 +03:00
|
|
|
NS_PRECONDITION(!BlockedOrInterrupted() || !aBuffer,
|
2006-01-27 17:47:23 +03:00
|
|
|
"Non-null buffer when resuming");
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_PRECONDITION(XML_GetCurrentByteIndex(mExpatParser) % sizeof(char16_t) == 0,
|
|
|
|
"Consumed part of a char16_t?");
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
if (mExpatParser && (mInternalState == NS_OK || BlockedOrInterrupted())) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t parserBytesBefore = XML_GetCurrentByteIndex(mExpatParser);
|
2006-01-27 17:47:23 +03:00
|
|
|
NS_ASSERTION(parserBytesBefore >= 0, "Unexpected value");
|
|
|
|
|
2005-12-18 13:39:23 +03:00
|
|
|
XML_Status status;
|
2007-01-31 00:21:06 +03:00
|
|
|
if (BlockedOrInterrupted()) {
|
2005-12-18 13:39:23 +03:00
|
|
|
mInternalState = NS_OK; // Resume in case we're blocked.
|
|
|
|
status = XML_ResumeParser(mExpatParser);
|
|
|
|
}
|
|
|
|
else {
|
2006-01-27 17:47:23 +03:00
|
|
|
status = XML_Parse(mExpatParser,
|
2007-07-08 11:08:04 +04:00
|
|
|
reinterpret_cast<const char*>(aBuffer),
|
2014-01-04 19:02:17 +04:00
|
|
|
aLength * sizeof(char16_t), aIsFinal);
|
2005-12-18 13:39:23 +03:00
|
|
|
}
|
2005-07-26 17:09:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t parserBytesConsumed = XML_GetCurrentByteIndex(mExpatParser);
|
2005-07-26 17:09:19 +04:00
|
|
|
|
2006-01-27 17:47:23 +03:00
|
|
|
NS_ASSERTION(parserBytesConsumed >= 0, "Unexpected value");
|
|
|
|
NS_ASSERTION(parserBytesConsumed >= parserBytesBefore,
|
|
|
|
"How'd this happen?");
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(parserBytesConsumed % sizeof(char16_t) == 0,
|
|
|
|
"Consumed part of a char16_t?");
|
2005-07-26 17:09:19 +04:00
|
|
|
|
2006-01-27 17:47:23 +03:00
|
|
|
// Consumed something.
|
2014-01-04 19:02:17 +04:00
|
|
|
*aConsumed = (parserBytesConsumed - parserBytesBefore) / sizeof(char16_t);
|
2006-01-27 17:47:23 +03:00
|
|
|
NS_ASSERTION(*aConsumed <= aLength + mExpatBuffered,
|
|
|
|
"Too many bytes consumed?");
|
2005-07-26 17:09:19 +04:00
|
|
|
|
2007-11-19 13:57:29 +03:00
|
|
|
NS_ASSERTION(status != XML_STATUS_SUSPENDED || BlockedOrInterrupted(),
|
2007-01-31 00:21:06 +03:00
|
|
|
"Inconsistent expat suspension state.");
|
|
|
|
|
|
|
|
if (status == XML_STATUS_ERROR) {
|
2005-12-18 13:39:23 +03:00
|
|
|
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
2006-01-25 23:07:33 +03:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-01-27 17:47:23 +03:00
|
|
|
else {
|
|
|
|
*aConsumed = 0;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsExpatDriver::ConsumeToken(nsScanner& aScanner, bool& aFlushTokens)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2006-01-27 17:47:23 +03:00
|
|
|
// We keep the scanner pointing to the position where Expat will start
|
|
|
|
// parsing.
|
|
|
|
nsScannerIterator currentExpatPosition;
|
|
|
|
aScanner.CurrentPosition(currentExpatPosition);
|
|
|
|
|
|
|
|
// This is the start of the first buffer that we need to pass to Expat.
|
|
|
|
nsScannerIterator start = currentExpatPosition;
|
|
|
|
start.advance(mExpatBuffered);
|
|
|
|
|
|
|
|
// This is the end of the last buffer (at this point, more data could come in
|
|
|
|
// later).
|
|
|
|
nsScannerIterator end;
|
2006-01-25 23:07:33 +03:00
|
|
|
aScanner.EndReading(end);
|
2006-01-25 15:53:00 +03:00
|
|
|
|
2012-10-30 03:32:10 +04:00
|
|
|
PR_LOG(GetExpatDriverLog(), PR_LOG_DEBUG,
|
2006-01-27 17:47:23 +03:00
|
|
|
("Remaining in expat's buffer: %i, remaining in scanner: %i.",
|
|
|
|
mExpatBuffered, Distance(start, end)));
|
|
|
|
|
2006-03-08 17:34:50 +03:00
|
|
|
// We want to call Expat if we have more buffers, or if we know there won't
|
|
|
|
// be more buffers (and so we want to flush the remaining data), or if we're
|
|
|
|
// currently blocked and there's data in Expat's buffer.
|
2009-03-16 03:53:09 +03:00
|
|
|
while (start != end || (mIsFinalChunk && !mMadeFinalCallToExpat) ||
|
2007-01-31 00:21:06 +03:00
|
|
|
(BlockedOrInterrupted() && mExpatBuffered > 0)) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool noMoreBuffers = start == end && mIsFinalChunk;
|
|
|
|
bool blocked = BlockedOrInterrupted();
|
2006-03-08 17:34:50 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *buffer;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length;
|
2006-03-08 17:34:50 +03:00
|
|
|
if (blocked || noMoreBuffers) {
|
2006-01-27 17:47:23 +03:00
|
|
|
// If we're blocked we just resume Expat so we don't need a buffer, if
|
|
|
|
// there aren't any more buffers we pass a null buffer to Expat.
|
2012-07-30 18:20:58 +04:00
|
|
|
buffer = nullptr;
|
2006-01-27 17:47:23 +03:00
|
|
|
length = 0;
|
2006-01-25 15:53:00 +03:00
|
|
|
|
2009-03-16 03:53:09 +03:00
|
|
|
#if defined(PR_LOGGING) || defined (DEBUG)
|
2006-03-08 17:34:50 +03:00
|
|
|
if (blocked) {
|
2012-10-30 03:32:10 +04:00
|
|
|
PR_LOG(GetExpatDriverLog(), PR_LOG_DEBUG,
|
2006-01-27 17:47:23 +03:00
|
|
|
("Resuming Expat, will parse data remaining in Expat's "
|
|
|
|
"buffer.\nContent of Expat's buffer:\n-----\n%s\n-----\n",
|
|
|
|
NS_ConvertUTF16toUTF8(currentExpatPosition.get(),
|
|
|
|
mExpatBuffered).get()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(mExpatBuffered == Distance(currentExpatPosition, end),
|
|
|
|
"Didn't pass all the data to Expat?");
|
2012-10-30 03:32:10 +04:00
|
|
|
PR_LOG(GetExpatDriverLog(), PR_LOG_DEBUG,
|
2006-01-27 17:47:23 +03:00
|
|
|
("Last call to Expat, will parse data remaining in Expat's "
|
|
|
|
"buffer.\nContent of Expat's buffer:\n-----\n%s\n-----\n",
|
|
|
|
NS_ConvertUTF16toUTF8(currentExpatPosition.get(),
|
|
|
|
mExpatBuffered).get()));
|
|
|
|
}
|
2009-03-16 03:53:09 +03:00
|
|
|
#endif
|
2006-01-27 17:47:23 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
buffer = start.get();
|
2012-08-22 19:56:38 +04:00
|
|
|
length = uint32_t(start.size_forward());
|
2006-01-27 17:47:23 +03:00
|
|
|
|
2012-10-30 03:32:10 +04:00
|
|
|
PR_LOG(GetExpatDriverLog(), PR_LOG_DEBUG,
|
2006-01-27 17:47:23 +03:00
|
|
|
("Calling Expat, will parse data remaining in Expat's buffer and "
|
|
|
|
"new data.\nContent of Expat's buffer:\n-----\n%s\n-----\nNew "
|
|
|
|
"data:\n-----\n%s\n-----\n",
|
|
|
|
NS_ConvertUTF16toUTF8(currentExpatPosition.get(),
|
|
|
|
mExpatBuffered).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(start.get(), length).get()));
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t consumed;
|
2006-03-08 17:34:50 +03:00
|
|
|
ParseBuffer(buffer, length, noMoreBuffers, &consumed);
|
2006-01-27 17:47:23 +03:00
|
|
|
if (consumed > 0) {
|
|
|
|
nsScannerIterator oldExpatPosition = currentExpatPosition;
|
|
|
|
currentExpatPosition.advance(consumed);
|
|
|
|
|
|
|
|
// We consumed some data, we want to store the last line of data that
|
|
|
|
// was consumed in case we run into an error (to show the line in which
|
|
|
|
// the error occurred).
|
|
|
|
|
|
|
|
// The length of the last line that Expat has parsed.
|
2006-07-13 16:50:58 +04:00
|
|
|
XML_Size lastLineLength = XML_GetCurrentColumnNumber(mExpatParser);
|
2006-01-27 17:47:23 +03:00
|
|
|
|
|
|
|
if (lastLineLength <= consumed) {
|
|
|
|
// The length of the last line was less than what expat consumed, so
|
|
|
|
// there was at least one line break in the consumed data. Store the
|
|
|
|
// last line until the point where we stopped parsing.
|
|
|
|
nsScannerIterator startLastLine = currentExpatPosition;
|
2006-07-13 16:50:58 +04:00
|
|
|
startLastLine.advance(-((ptrdiff_t)lastLineLength));
|
2006-01-27 17:47:23 +03:00
|
|
|
CopyUnicodeTo(startLastLine, currentExpatPosition, mLastLine);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// There was no line break in the consumed data, append the consumed
|
|
|
|
// data.
|
|
|
|
AppendUnicodeTo(oldExpatPosition, currentExpatPosition, mLastLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mExpatBuffered += length - consumed;
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
if (BlockedOrInterrupted()) {
|
2012-10-30 03:32:10 +04:00
|
|
|
PR_LOG(GetExpatDriverLog(), PR_LOG_DEBUG,
|
2007-01-31 00:21:06 +03:00
|
|
|
("Blocked or interrupted parser (probably for loading linked "
|
|
|
|
"stylesheets or scripts)."));
|
2006-01-27 17:47:23 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aScanner.SetPosition(currentExpatPosition, true);
|
2006-01-27 17:47:23 +03:00
|
|
|
aScanner.Mark();
|
|
|
|
|
|
|
|
return mInternalState;
|
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2009-03-16 03:53:09 +03:00
|
|
|
if (noMoreBuffers && mExpatBuffered == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mMadeFinalCallToExpat = true;
|
2009-03-16 03:53:09 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
if (NS_FAILED(mInternalState)) {
|
2006-01-27 17:47:23 +03:00
|
|
|
if (XML_GetErrorCode(mExpatParser) != XML_ERROR_NONE) {
|
|
|
|
NS_ASSERTION(mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING,
|
|
|
|
"Unexpected error");
|
|
|
|
|
|
|
|
// Look for the next newline after the last one we consumed
|
|
|
|
nsScannerIterator lastLine = currentExpatPosition;
|
|
|
|
while (lastLine != end) {
|
2012-08-22 19:56:38 +04:00
|
|
|
length = uint32_t(lastLine.size_forward());
|
|
|
|
uint32_t endOffset = 0;
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *buffer = lastLine.get();
|
2006-01-27 17:47:23 +03:00
|
|
|
while (endOffset < length && buffer[endOffset] != '\n' &&
|
|
|
|
buffer[endOffset] != '\r') {
|
|
|
|
++endOffset;
|
|
|
|
}
|
|
|
|
mLastLine.Append(Substring(buffer, buffer + endOffset));
|
|
|
|
if (endOffset < length) {
|
|
|
|
// We found a newline.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastLine.advance(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleError();
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return mInternalState;
|
|
|
|
}
|
|
|
|
|
2006-03-08 17:34:50 +03:00
|
|
|
// Either we have more buffers, or we were blocked (and we'll flush in the
|
|
|
|
// next iteration), or we should have emptied Expat's buffer.
|
|
|
|
NS_ASSERTION(!noMoreBuffers || blocked ||
|
|
|
|
(mExpatBuffered == 0 && currentExpatPosition == end),
|
|
|
|
"Unreachable data left in Expat's buffer");
|
2006-01-27 17:47:23 +03:00
|
|
|
|
|
|
|
start.advance(length);
|
2009-02-26 04:38:28 +03:00
|
|
|
|
|
|
|
// It's possible for start to have passed end if we received more data
|
|
|
|
// (e.g. if we spun the event loop in an inline script). Reload end now
|
|
|
|
// to compensate.
|
|
|
|
aScanner.EndReading(end);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aScanner.SetPosition(currentExpatPosition, true);
|
2006-01-27 17:47:23 +03:00
|
|
|
aScanner.Mark();
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2012-10-30 03:32:10 +04:00
|
|
|
PR_LOG(GetExpatDriverLog(), PR_LOG_DEBUG,
|
2006-01-27 17:47:23 +03:00
|
|
|
("Remaining in expat's buffer: %i, remaining in scanner: %i.",
|
|
|
|
mExpatBuffered, Distance(currentExpatPosition, end)));
|
|
|
|
|
2007-06-27 04:21:47 +04:00
|
|
|
return NS_SUCCEEDED(mInternalState) ? kEOF : NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_IMETHODIMP
|
2002-04-11 02:16:46 +04:00
|
|
|
nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
|
|
|
|
nsITokenizer* aTokenizer,
|
2002-01-09 04:37:50 +03:00
|
|
|
nsIContentSink* aSink)
|
|
|
|
{
|
2004-05-08 18:07:18 +04:00
|
|
|
mSink = do_QueryInterface(aSink);
|
2005-08-31 21:33:54 +04:00
|
|
|
if (!mSink) {
|
|
|
|
NS_ERROR("nsExpatDriver didn't get an nsIExpatSink");
|
|
|
|
// Make sure future calls to us bail out as needed
|
|
|
|
mInternalState = NS_ERROR_UNEXPECTED;
|
|
|
|
return mInternalState;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2009-06-24 01:22:17 +04:00
|
|
|
mOriginalSink = aSink;
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
static const XML_Memory_Handling_Suite memsuite =
|
2004-12-15 20:35:52 +03:00
|
|
|
{
|
|
|
|
(void *(*)(size_t))PR_Malloc,
|
|
|
|
(void *(*)(void *, size_t))PR_Realloc,
|
|
|
|
PR_Free
|
|
|
|
};
|
2004-12-15 18:37:23 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t kExpatSeparator[] = { kExpatSeparatorChar, '\0' };
|
2004-12-15 18:37:23 +03:00
|
|
|
|
|
|
|
mExpatParser = XML_ParserCreate_MM(kUTF16, &memsuite, kExpatSeparator);
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_ENSURE_TRUE(mExpatParser, NS_ERROR_FAILURE);
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
XML_SetReturnNSTriplet(mExpatParser, XML_TRUE);
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
#ifdef XML_DTD
|
2004-05-08 18:07:18 +04:00
|
|
|
XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
2002-01-09 04:37:50 +03:00
|
|
|
#endif
|
2004-05-08 18:07:18 +04:00
|
|
|
|
2005-06-23 05:54:42 +04:00
|
|
|
mURISpec = aParserContext.mScanner->GetFilename();
|
|
|
|
|
|
|
|
XML_SetBase(mExpatParser, mURISpec.get());
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2010-12-20 19:21:58 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mOriginalSink->GetTarget());
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = doc->GetWindow();
|
|
|
|
if (!win) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHasHadScriptHandlingObject;
|
2010-12-20 19:21:58 +03:00
|
|
|
nsIScriptGlobalObject *global =
|
|
|
|
doc->GetScriptHandlingObject(aHasHadScriptHandlingObject);
|
|
|
|
if (global) {
|
|
|
|
win = do_QueryInterface(global);
|
|
|
|
}
|
|
|
|
}
|
2011-08-25 00:44:35 +04:00
|
|
|
if (win && !win->IsInnerWindow()) {
|
|
|
|
win = win->GetCurrentInnerWindow();
|
|
|
|
}
|
2010-12-20 19:21:58 +03:00
|
|
|
if (win) {
|
2011-08-25 00:44:35 +04:00
|
|
|
mInnerWindowID = win->WindowID();
|
2010-12-20 19:21:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// Set up the callbacks
|
2004-12-17 12:17:35 +03:00
|
|
|
XML_SetXmlDeclHandler(mExpatParser, Driver_HandleXMLDeclaration);
|
2004-05-08 18:07:18 +04:00
|
|
|
XML_SetElementHandler(mExpatParser, Driver_HandleStartElement,
|
|
|
|
Driver_HandleEndElement);
|
2002-01-09 04:37:50 +03:00
|
|
|
XML_SetCharacterDataHandler(mExpatParser, Driver_HandleCharacterData);
|
2004-05-08 18:07:18 +04:00
|
|
|
XML_SetProcessingInstructionHandler(mExpatParser,
|
|
|
|
Driver_HandleProcessingInstruction);
|
2002-01-09 04:37:50 +03:00
|
|
|
XML_SetDefaultHandlerExpand(mExpatParser, Driver_HandleDefault);
|
2004-05-08 18:07:18 +04:00
|
|
|
XML_SetExternalEntityRefHandler(mExpatParser,
|
2004-12-15 18:37:23 +03:00
|
|
|
(XML_ExternalEntityRefHandler)
|
|
|
|
Driver_HandleExternalEntityRef);
|
2002-03-15 12:45:31 +03:00
|
|
|
XML_SetExternalEntityRefHandlerArg(mExpatParser, this);
|
2002-01-09 04:37:50 +03:00
|
|
|
XML_SetCommentHandler(mExpatParser, Driver_HandleComment);
|
|
|
|
XML_SetCdataSectionHandler(mExpatParser, Driver_HandleStartCdataSection,
|
|
|
|
Driver_HandleEndCdataSection);
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
XML_SetParamEntityParsing(mExpatParser,
|
|
|
|
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
|
|
|
|
XML_SetDoctypeDeclHandler(mExpatParser, Driver_HandleStartDoctypeDecl,
|
|
|
|
Driver_HandleEndDoctypeDecl);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2006-03-15 20:45:25 +03:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// Set up the user data.
|
|
|
|
XML_SetUserData(mExpatParser, this);
|
|
|
|
|
2009-02-16 15:22:47 +03:00
|
|
|
// XML must detect invalid character convertion
|
|
|
|
aParserContext.mScanner->OverrideReplacementCharacter(0xffff);
|
|
|
|
|
2009-06-24 01:22:16 +04:00
|
|
|
return mInternalState;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_IMETHODIMP
|
2013-08-12 19:28:41 +04:00
|
|
|
nsExpatDriver::BuildModel(nsITokenizer* aTokenizer, nsIContentSink* aSink)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
return mInternalState;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_IMETHODIMP
|
2009-06-24 01:22:17 +04:00
|
|
|
nsExpatDriver::DidBuildModel(nsresult anErrorCode)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mOriginalSink = nullptr;
|
|
|
|
mSink = nullptr;
|
|
|
|
mExtendedSink = nullptr;
|
2009-06-24 01:22:16 +04:00
|
|
|
return NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
NS_IMETHODIMP
|
2013-08-12 19:28:41 +04:00
|
|
|
nsExpatDriver::WillTokenize(bool aIsFinalChunk)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2006-03-08 17:34:50 +03:00
|
|
|
mIsFinalChunk = aIsFinalChunk;
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-15 02:45:20 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsExpatDriver::Terminate()
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2004-12-15 18:37:23 +03:00
|
|
|
// XXX - not sure what happens to the unparsed data.
|
2004-05-22 01:32:11 +04:00
|
|
|
if (mExpatParser) {
|
2005-12-18 13:39:23 +03:00
|
|
|
XML_StopParser(mExpatParser, XML_FALSE);
|
2004-05-22 01:32:11 +04:00
|
|
|
}
|
2002-02-15 02:45:20 +03:00
|
|
|
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP_(int32_t)
|
2002-04-11 02:16:46 +04:00
|
|
|
nsExpatDriver::GetType()
|
|
|
|
{
|
|
|
|
return NS_IPARSER_FLAG_XML;
|
|
|
|
}
|
|
|
|
|
2009-06-24 01:22:16 +04:00
|
|
|
NS_IMETHODIMP_(nsDTDMode)
|
|
|
|
nsExpatDriver::GetMode() const
|
|
|
|
{
|
|
|
|
return eDTDMode_full_standards;
|
|
|
|
}
|
|
|
|
|
2004-05-08 18:07:18 +04:00
|
|
|
/*************************** Unused methods **********************************/
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-08-22 19:56:38 +04:00
|
|
|
nsExpatDriver::IsContainer(int32_t aTag) const
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-08-22 19:56:38 +04:00
|
|
|
nsExpatDriver::CanContain(int32_t aParent,int32_t aChild) const
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
|
|
|
|
void
|
2007-11-19 13:57:29 +03:00
|
|
|
nsExpatDriver::MaybeStopParser(nsresult aState)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(aState)) {
|
|
|
|
// If we had a failure we want to override NS_ERROR_HTMLPARSER_INTERRUPTED
|
|
|
|
// and we want to override NS_ERROR_HTMLPARSER_BLOCK but not with
|
|
|
|
// NS_ERROR_HTMLPARSER_INTERRUPTED.
|
|
|
|
if (NS_SUCCEEDED(mInternalState) ||
|
|
|
|
mInternalState == NS_ERROR_HTMLPARSER_INTERRUPTED ||
|
|
|
|
(mInternalState == NS_ERROR_HTMLPARSER_BLOCK &&
|
|
|
|
aState != NS_ERROR_HTMLPARSER_INTERRUPTED)) {
|
2010-10-05 05:25:44 +04:00
|
|
|
mInternalState = (aState == NS_ERROR_HTMLPARSER_INTERRUPTED ||
|
|
|
|
aState == NS_ERROR_HTMLPARSER_BLOCK) ?
|
|
|
|
aState :
|
|
|
|
NS_ERROR_HTMLPARSER_STOPPARSING;
|
2007-11-19 13:57:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we get an error then we need to stop Expat (by calling XML_StopParser
|
2011-10-17 18:59:28 +04:00
|
|
|
// with false as the last argument). If the parser should be blocked or
|
2007-11-19 13:57:29 +03:00
|
|
|
// interrupted we need to pause Expat (by calling XML_StopParser with
|
2011-10-17 18:59:28 +04:00
|
|
|
// true as the last argument).
|
2007-11-19 13:57:29 +03:00
|
|
|
XML_StopParser(mExpatParser, BlockedOrInterrupted());
|
|
|
|
}
|
|
|
|
else if (NS_SUCCEEDED(mInternalState)) {
|
|
|
|
// Only clobber mInternalState with the success code if we didn't block or
|
|
|
|
// interrupt before.
|
|
|
|
mInternalState = aState;
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
}
|