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"
|
2018-06-14 00:08:27 +03: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,
|
2018-06-14 00:08:27 +03:00
|
|
|
nsScanner* aScanner, void* aKey,
|
2000-03-25 06:35:50 +03:00
|
|
|
eParserCommands aCommand,
|
2018-06-14 00:08:27 +03:00
|
|
|
nsIRequestObserver* aListener,
|
|
|
|
eAutoDetectResult aStatus, bool aCopyUnused)
|
|
|
|
: mListener(aListener),
|
|
|
|
mKey(aKey),
|
|
|
|
mPrevContext(aPrevContext),
|
|
|
|
mScanner(aScanner),
|
|
|
|
mDTDMode(eDTDMode_unknown),
|
|
|
|
mDocType(static_cast<eParserDocType>(0)),
|
|
|
|
mStreamListenerState(eNone),
|
|
|
|
mContextType(eCTNone),
|
|
|
|
mAutoDetectStatus(aStatus),
|
|
|
|
mParserCommand(aCommand),
|
|
|
|
mMultipart(true),
|
|
|
|
mCopyUnused(aCopyUnused) {
|
|
|
|
MOZ_COUNT_CTOR(CParserContext);
|
|
|
|
}
|
2000-03-17 07:12:17 +03:00
|
|
|
|
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
|
|
|
|
2009-03-24 12:43:42 +03:00
|
|
|
nsresult CParserContext::GetTokenizer(nsIDTD* aDTD, nsIContentSink* aSink,
|
|
|
|
nsITokenizer*& aTokenizer) {
|
|
|
|
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
|
|
|
}
|