Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 sw=2 et tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIAtom.h" |
michael@0 | 9 | #include "CParserContext.h" |
michael@0 | 10 | #include "nsToken.h" |
michael@0 | 11 | #include "prenv.h" |
michael@0 | 12 | #include "nsIHTMLContentSink.h" |
michael@0 | 13 | #include "nsHTMLTokenizer.h" |
michael@0 | 14 | #include "nsMimeTypes.h" |
michael@0 | 15 | #include "nsHTMLTokenizer.h" |
michael@0 | 16 | |
michael@0 | 17 | CParserContext::CParserContext(CParserContext* aPrevContext, |
michael@0 | 18 | nsScanner* aScanner, |
michael@0 | 19 | void *aKey, |
michael@0 | 20 | eParserCommands aCommand, |
michael@0 | 21 | nsIRequestObserver* aListener, |
michael@0 | 22 | eAutoDetectResult aStatus, |
michael@0 | 23 | bool aCopyUnused) |
michael@0 | 24 | : mListener(aListener), |
michael@0 | 25 | mKey(aKey), |
michael@0 | 26 | mPrevContext(aPrevContext), |
michael@0 | 27 | mScanner(aScanner), |
michael@0 | 28 | mDTDMode(eDTDMode_unknown), |
michael@0 | 29 | mStreamListenerState(eNone), |
michael@0 | 30 | mContextType(eCTNone), |
michael@0 | 31 | mAutoDetectStatus(aStatus), |
michael@0 | 32 | mParserCommand(aCommand), |
michael@0 | 33 | mMultipart(true), |
michael@0 | 34 | mCopyUnused(aCopyUnused) |
michael@0 | 35 | { |
michael@0 | 36 | MOZ_COUNT_CTOR(CParserContext); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | CParserContext::~CParserContext() |
michael@0 | 40 | { |
michael@0 | 41 | // It's ok to simply ingore the PrevContext. |
michael@0 | 42 | MOZ_COUNT_DTOR(CParserContext); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void |
michael@0 | 46 | CParserContext::SetMimeType(const nsACString& aMimeType) |
michael@0 | 47 | { |
michael@0 | 48 | mMimeType.Assign(aMimeType); |
michael@0 | 49 | |
michael@0 | 50 | mDocType = ePlainText; |
michael@0 | 51 | |
michael@0 | 52 | if (mMimeType.EqualsLiteral(TEXT_HTML)) |
michael@0 | 53 | mDocType = eHTML_Strict; |
michael@0 | 54 | else if (mMimeType.EqualsLiteral(TEXT_XML) || |
michael@0 | 55 | mMimeType.EqualsLiteral(APPLICATION_XML) || |
michael@0 | 56 | mMimeType.EqualsLiteral(APPLICATION_XHTML_XML) || |
michael@0 | 57 | mMimeType.EqualsLiteral(TEXT_XUL) || |
michael@0 | 58 | mMimeType.EqualsLiteral(IMAGE_SVG_XML) || |
michael@0 | 59 | mMimeType.EqualsLiteral(APPLICATION_MATHML_XML) || |
michael@0 | 60 | mMimeType.EqualsLiteral(APPLICATION_RDF_XML) || |
michael@0 | 61 | mMimeType.EqualsLiteral(TEXT_RDF)) |
michael@0 | 62 | mDocType = eXML; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | nsresult |
michael@0 | 66 | CParserContext::GetTokenizer(nsIDTD* aDTD, |
michael@0 | 67 | nsIContentSink* aSink, |
michael@0 | 68 | nsITokenizer*& aTokenizer) |
michael@0 | 69 | { |
michael@0 | 70 | nsresult result = NS_OK; |
michael@0 | 71 | int32_t type = aDTD ? aDTD->GetType() : NS_IPARSER_FLAG_HTML; |
michael@0 | 72 | |
michael@0 | 73 | if (!mTokenizer) { |
michael@0 | 74 | if (type == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) { |
michael@0 | 75 | mTokenizer = new nsHTMLTokenizer; |
michael@0 | 76 | } |
michael@0 | 77 | else if (type == NS_IPARSER_FLAG_XML) { |
michael@0 | 78 | mTokenizer = do_QueryInterface(aDTD, &result); |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | aTokenizer = mTokenizer; |
michael@0 | 83 | |
michael@0 | 84 | return result; |
michael@0 | 85 | } |