1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
41
#include "CParserContext.h"
44
#include "nsHTMLTokenizer.h"
45
#include "nsExpatDriver.h"
47
MOZ_DECL_CTOR_COUNTER(CParserContext)
50
* Your friendly little constructor. Ok, it's not the friendly, but the only guy
51
* using it is the parser.
57
CParserContext::CParserContext(nsScanner* aScanner,
59
eParserCommands aCommand,
60
nsIRequestObserver* aListener,
62
eAutoDetectResult aStatus,
65
MOZ_COUNT_CTOR(CParserContext);
71
NS_IF_ADDREF(mListener);
72
mDTDMode=eDTDMode_unknown;
73
mAutoDetectStatus=aStatus;
78
mTransferBufferSize=eTransferBufferSize;
79
mStreamListenerState=eNone;
82
mCopyUnused=aCopyUnused;
83
mParserCommand=aCommand;
88
* Your friendly little constructor. Ok, it's not the friendly, but the only guy
89
* using it is the parser.
95
CParserContext::CParserContext(const CParserContext &aContext) : mMimeType() {
96
MOZ_COUNT_CTOR(CParserContext);
98
mScanner=aContext.mScanner;
101
mListener=aContext.mListener;
102
NS_IF_ADDREF(mListener);
104
mDTDMode=aContext.mDTDMode;
105
mAutoDetectStatus=aContext.mAutoDetectStatus;
106
mTransferBuffer=aContext.mTransferBuffer;
110
mTokenizer = aContext.mTokenizer;
111
NS_IF_ADDREF(mTokenizer);
113
mTransferBufferSize=eTransferBufferSize;
114
mStreamListenerState=aContext.mStreamListenerState;
115
mMultipart=aContext.mMultipart;
116
mContextType=aContext.mContextType;
117
mRequest=aContext.mRequest;
118
mParserCommand=aContext.mParserCommand;
119
SetMimeType(aContext.mMimeType);
124
* Destructor for parser context
125
* NOTE: DO NOT destroy the dtd here.
126
* @update gess7/11/98
128
CParserContext::~CParserContext(){
130
MOZ_COUNT_DTOR(CParserContext);
138
delete [] mTransferBuffer;
141
NS_IF_RELEASE(mListener);
142
NS_IF_RELEASE(mTokenizer);
144
//Remember that it's ok to simply ingore the PrevContext.
150
* Set's the mimetype for this context
151
* @update rickg 03.18.2000
153
void CParserContext::SetMimeType(const nsACString& aMimeType){
154
mMimeType.Assign(aMimeType);
158
if(mMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType)))
159
mDocType=eHTML_Strict;
160
else if (mMimeType.Equals(NS_LITERAL_CSTRING(kXMLTextContentType)) ||
161
mMimeType.Equals(NS_LITERAL_CSTRING(kXMLApplicationContentType)) ||
162
mMimeType.Equals(NS_LITERAL_CSTRING(kXHTMLApplicationContentType)) ||
163
mMimeType.Equals(NS_LITERAL_CSTRING(kXULTextContentType)) ||
165
mMimeType.Equals(NS_LITERAL_CSTRING(kSVGTextContentType)) ||
167
mMimeType.Equals(NS_LITERAL_CSTRING(kRDFTextContentType)))
172
CParserContext::GetTokenizer(PRInt32 aType, nsITokenizer*& aTokenizer) {
173
nsresult result = NS_OK;
176
if (aType == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) {
177
result = NS_NewHTMLTokenizer(&mTokenizer,mDTDMode,mDocType,mParserCommand);
178
// Propagate tokenizer state so that information is preserved
179
// between document.write. This fixes bug 99467
180
if (mTokenizer && mPrevContext)
181
mTokenizer->CopyState(mPrevContext->mTokenizer);
183
else if (aType == NS_IPARSER_FLAG_XML)
185
result = CallQueryInterface(mDTD, &mTokenizer);
189
aTokenizer = mTokenizer;