~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/htmlparser/src/CParserContext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
 
 
40
#include "nsIAtom.h"
 
41
#include "CParserContext.h"
 
42
#include "nsToken.h"
 
43
#include "prenv.h"  
 
44
#include "nsHTMLTokenizer.h"
 
45
#include "nsExpatDriver.h"
 
46
 
 
47
MOZ_DECL_CTOR_COUNTER(CParserContext)
 
48
 
 
49
/**
 
50
 * Your friendly little constructor. Ok, it's not the friendly, but the only guy
 
51
 * using it is the parser.
 
52
 * @update      gess7/23/98
 
53
 * @param   aScanner
 
54
 * @param   aKey
 
55
 * @param   aListener
 
56
 */
 
57
CParserContext::CParserContext(nsScanner* aScanner, 
 
58
                               void *aKey, 
 
59
                               eParserCommands aCommand,
 
60
                               nsIRequestObserver* aListener, 
 
61
                               nsIDTD *aDTD, 
 
62
                               eAutoDetectResult aStatus, 
 
63
                               PRBool aCopyUnused)
 
64
 
65
  MOZ_COUNT_CTOR(CParserContext); 
 
66
 
 
67
  mScanner=aScanner; 
 
68
  mKey=aKey; 
 
69
  mPrevContext=0; 
 
70
  mListener=aListener; 
 
71
  NS_IF_ADDREF(mListener); 
 
72
  mDTDMode=eDTDMode_unknown; 
 
73
  mAutoDetectStatus=aStatus; 
 
74
  mTransferBuffer=0; 
 
75
  mDTD=aDTD; 
 
76
  NS_IF_ADDREF(mDTD);
 
77
  mTokenizer = 0;
 
78
  mTransferBufferSize=eTransferBufferSize; 
 
79
  mStreamListenerState=eNone; 
 
80
  mMultipart=PR_TRUE; 
 
81
  mContextType=eCTNone; 
 
82
  mCopyUnused=aCopyUnused; 
 
83
  mParserCommand=aCommand;
 
84
  mRequest=0;
 
85
 
86
 
 
87
/**
 
88
 * Your friendly little constructor. Ok, it's not the friendly, but the only guy
 
89
 * using it is the parser.
 
90
 * @update      gess7/23/98
 
91
 * @param   aScanner
 
92
 * @param   aKey
 
93
 * @param   aListener
 
94
 */
 
95
CParserContext::CParserContext(const CParserContext &aContext) : mMimeType() {
 
96
  MOZ_COUNT_CTOR(CParserContext);
 
97
 
 
98
  mScanner=aContext.mScanner;
 
99
  mKey=aContext.mKey;
 
100
  mPrevContext=0;
 
101
  mListener=aContext.mListener;
 
102
  NS_IF_ADDREF(mListener);
 
103
 
 
104
  mDTDMode=aContext.mDTDMode;
 
105
  mAutoDetectStatus=aContext.mAutoDetectStatus;
 
106
  mTransferBuffer=aContext.mTransferBuffer;
 
107
  mDTD=aContext.mDTD;
 
108
  NS_IF_ADDREF(mDTD);
 
109
 
 
110
  mTokenizer = aContext.mTokenizer;
 
111
  NS_IF_ADDREF(mTokenizer);
 
112
 
 
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);
 
120
}
 
121
 
 
122
 
 
123
/**
 
124
 * Destructor for parser context
 
125
 * NOTE: DO NOT destroy the dtd here.
 
126
 * @update      gess7/11/98
 
127
 */
 
128
CParserContext::~CParserContext(){
 
129
 
 
130
  MOZ_COUNT_DTOR(CParserContext);
 
131
 
 
132
  if(mScanner) {
 
133
    delete mScanner;
 
134
    mScanner=nsnull;
 
135
  }
 
136
 
 
137
  if(mTransferBuffer)
 
138
    delete [] mTransferBuffer;
 
139
 
 
140
  NS_IF_RELEASE(mDTD);
 
141
  NS_IF_RELEASE(mListener);
 
142
  NS_IF_RELEASE(mTokenizer);
 
143
 
 
144
  //Remember that it's ok to simply ingore the PrevContext.
 
145
 
 
146
}
 
147
 
 
148
 
 
149
/**
 
150
 * Set's the mimetype for this context
 
151
 * @update      rickg 03.18.2000
 
152
 */
 
153
void CParserContext::SetMimeType(const nsACString& aMimeType){
 
154
  mMimeType.Assign(aMimeType);
 
155
 
 
156
  mDocType=ePlainText;
 
157
 
 
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))          ||
 
164
#ifdef MOZ_SVG
 
165
           mMimeType.Equals(NS_LITERAL_CSTRING(kSVGTextContentType))          ||
 
166
#endif
 
167
           mMimeType.Equals(NS_LITERAL_CSTRING(kRDFTextContentType)))
 
168
    mDocType=eXML;
 
169
}
 
170
 
 
171
nsresult
 
172
CParserContext::GetTokenizer(PRInt32 aType, nsITokenizer*& aTokenizer) {
 
173
  nsresult result = NS_OK;
 
174
  
 
175
  if(!mTokenizer) {
 
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);
 
182
    }
 
183
    else if (aType == NS_IPARSER_FLAG_XML)
 
184
    {
 
185
      result = CallQueryInterface(mDTD, &mTokenizer);
 
186
    }
 
187
  }
 
188
  
 
189
  aTokenizer = mTokenizer;
 
190
  return result;
 
191
}