1998-07-14 01:13:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-11-11 22:11:36 +03:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
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/. */
|
1998-07-14 01:13:09 +04:00
|
|
|
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
1998-07-14 01:13:09 +04:00
|
|
|
#include "CParserContext.h"
|
2000-04-17 10:33:31 +04:00
|
|
|
#include "prenv.h"
|
2004-12-01 07:37:36 +03:00
|
|
|
#include "nsIHTMLContentSink.h"
|
2002-04-11 02:16:46 +04:00
|
|
|
#include "nsHTMLTokenizer.h"
|
2009-11-21 02:12:42 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2013-08-12 19:28:41 +04:00
|
|
|
#include "nsHTMLTokenizer.h"
|
1998-07-14 01:13:09 +04:00
|
|
|
|
2009-03-24 04:26:46 +03:00
|
|
|
CParserContext::CParserContext(CParserContext* aPrevContext,
|
|
|
|
nsScanner* aScanner,
|
2000-03-17 07:12:17 +03:00
|
|
|
void *aKey,
|
2000-03-25 06:35:50 +03:00
|
|
|
eParserCommands aCommand,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsIRequestObserver* aListener,
|
2000-03-17 07:12:17 +03:00
|
|
|
eAutoDetectResult aStatus,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCopyUnused)
|
2009-03-24 04:26:46 +03:00
|
|
|
: mListener(aListener),
|
2006-01-13 17:45:32 +03:00
|
|
|
mKey(aKey),
|
2009-03-24 04:26:46 +03:00
|
|
|
mPrevContext(aPrevContext),
|
2006-01-13 17:45:32 +03:00
|
|
|
mScanner(aScanner),
|
|
|
|
mDTDMode(eDTDMode_unknown),
|
|
|
|
mStreamListenerState(eNone),
|
|
|
|
mContextType(eCTNone),
|
|
|
|
mAutoDetectStatus(aStatus),
|
|
|
|
mParserCommand(aCommand),
|
2011-10-17 18:59:28 +04:00
|
|
|
mMultipart(true),
|
2013-09-20 18:26:43 +04:00
|
|
|
mCopyUnused(aCopyUnused)
|
2000-03-17 07:12:17 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(CParserContext);
|
|
|
|
}
|
|
|
|
|
2005-11-11 22:11:36 +03:00
|
|
|
CParserContext::~CParserContext()
|
|
|
|
{
|
2006-01-13 17:45:32 +03:00
|
|
|
// It's ok to simply ingore the PrevContext.
|
1999-10-15 03:37:21 +04:00
|
|
|
MOZ_COUNT_DTOR(CParserContext);
|
1998-07-14 01:13:09 +04:00
|
|
|
}
|
|
|
|
|
2006-01-13 17:45:32 +03:00
|
|
|
void
|
|
|
|
CParserContext::SetMimeType(const nsACString& aMimeType)
|
|
|
|
{
|
2000-04-03 12:04:52 +04:00
|
|
|
mMimeType.Assign(aMimeType);
|
2000-03-25 06:35:50 +03:00
|
|
|
|
2006-01-13 17:45:32 +03:00
|
|
|
mDocType = ePlainText;
|
2000-03-25 06:35:50 +03:00
|
|
|
|
2009-11-21 02:12:42 +03:00
|
|
|
if (mMimeType.EqualsLiteral(TEXT_HTML))
|
2006-01-13 17:45:32 +03:00
|
|
|
mDocType = eHTML_Strict;
|
2009-11-21 02:12:42 +03:00
|
|
|
else if (mMimeType.EqualsLiteral(TEXT_XML) ||
|
|
|
|
mMimeType.EqualsLiteral(APPLICATION_XML) ||
|
|
|
|
mMimeType.EqualsLiteral(APPLICATION_XHTML_XML) ||
|
|
|
|
mMimeType.EqualsLiteral(TEXT_XUL) ||
|
|
|
|
mMimeType.EqualsLiteral(IMAGE_SVG_XML) ||
|
2009-11-30 01:18:53 +03:00
|
|
|
mMimeType.EqualsLiteral(APPLICATION_MATHML_XML) ||
|
2009-11-21 02:12:42 +03:00
|
|
|
mMimeType.EqualsLiteral(APPLICATION_RDF_XML) ||
|
2016-09-28 17:48:17 +03:00
|
|
|
mMimeType.EqualsLiteral(APPLICATION_WAPXHTML_XML) ||
|
2009-11-21 02:12:42 +03:00
|
|
|
mMimeType.EqualsLiteral(TEXT_RDF))
|
2006-01-13 17:45:32 +03:00
|
|
|
mDocType = eXML;
|
2000-04-17 10:33:31 +04:00
|
|
|
}
|
2002-04-11 02:16:46 +04:00
|
|
|
|
|
|
|
nsresult
|
2009-03-24 12:43:42 +03:00
|
|
|
CParserContext::GetTokenizer(nsIDTD* aDTD,
|
|
|
|
nsIContentSink* aSink,
|
|
|
|
nsITokenizer*& aTokenizer)
|
2005-11-11 22:11:36 +03:00
|
|
|
{
|
2009-03-24 12:43:42 +03:00
|
|
|
nsresult result = NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t type = aDTD ? aDTD->GetType() : NS_IPARSER_FLAG_HTML;
|
2009-03-24 12:43:42 +03:00
|
|
|
|
|
|
|
if (!mTokenizer) {
|
|
|
|
if (type == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) {
|
2013-08-17 15:27:09 +04:00
|
|
|
mTokenizer = new nsHTMLTokenizer;
|
2009-03-24 12:43:42 +03:00
|
|
|
}
|
|
|
|
else if (type == NS_IPARSER_FLAG_XML) {
|
|
|
|
mTokenizer = do_QueryInterface(aDTD, &result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aTokenizer = mTokenizer;
|
|
|
|
|
|
|
|
return result;
|
2002-04-11 02:16:46 +04:00
|
|
|
}
|