1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "CParserContext.h"
10 #include "nsIHTMLContentSink.h"
11 #include "nsHTMLTokenizer.h"
12 #include "nsMimeTypes.h"
13 #include "nsHTMLTokenizer.h"
15 CParserContext::CParserContext(CParserContext
* aPrevContext
,
16 nsScanner
* aScanner
, void* aKey
,
17 eParserCommands aCommand
,
18 nsIRequestObserver
* aListener
,
19 eAutoDetectResult aStatus
, bool aCopyUnused
)
20 : mListener(aListener
),
22 mPrevContext(aPrevContext
),
23 mScanner(mozilla::WrapUnique(aScanner
)),
24 mDTDMode(eDTDMode_unknown
),
25 mDocType(static_cast<eParserDocType
>(0)),
26 mStreamListenerState(eNone
),
27 mContextType(eCTNone
),
28 mAutoDetectStatus(aStatus
),
29 mParserCommand(aCommand
),
31 mCopyUnused(aCopyUnused
) {
32 MOZ_COUNT_CTOR(CParserContext
);
35 CParserContext::~CParserContext() {
36 // It's ok to simply ingore the PrevContext.
37 MOZ_COUNT_DTOR(CParserContext
);
40 void CParserContext::SetMimeType(const nsACString
& aMimeType
) {
41 mMimeType
.Assign(aMimeType
);
43 mDocType
= ePlainText
;
45 if (mMimeType
.EqualsLiteral(TEXT_HTML
))
46 mDocType
= eHTML_Strict
;
47 else if (mMimeType
.EqualsLiteral(TEXT_XML
) ||
48 mMimeType
.EqualsLiteral(APPLICATION_XML
) ||
49 mMimeType
.EqualsLiteral(APPLICATION_XHTML_XML
) ||
50 mMimeType
.EqualsLiteral(IMAGE_SVG_XML
) ||
51 mMimeType
.EqualsLiteral(APPLICATION_MATHML_XML
) ||
52 mMimeType
.EqualsLiteral(APPLICATION_RDF_XML
) ||
53 mMimeType
.EqualsLiteral(APPLICATION_WAPXHTML_XML
) ||
54 mMimeType
.EqualsLiteral(TEXT_RDF
))
58 nsresult
CParserContext::GetTokenizer(nsIDTD
* aDTD
, nsIContentSink
* aSink
,
59 nsITokenizer
*& aTokenizer
) {
60 nsresult result
= NS_OK
;
61 int32_t type
= aDTD
? aDTD
->GetType() : NS_IPARSER_FLAG_HTML
;
64 if (type
== NS_IPARSER_FLAG_HTML
|| mParserCommand
== eViewSource
) {
65 mTokenizer
= new nsHTMLTokenizer
;
66 } else if (type
== NS_IPARSER_FLAG_XML
) {
67 mTokenizer
= do_QueryInterface(aDTD
, &result
);
71 aTokenizer
= mTokenizer
;