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

« back to all changes in this revision

Viewing changes to mozilla/content/base/src/mozSanitizingSerializer.h

  • 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 HTML Sanitizer code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Ben Bucksch <mozilla@bucksch.org>.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2002
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *     Netscape
 
24
 *
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the NPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the NPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
#ifndef mozSanitizingSerializer_h__
 
41
#define mozSanitizingSerializer_h__
 
42
 
 
43
#include "mozISanitizingSerializer.h"
 
44
#include "nsIContentSerializer.h"
 
45
#include "nsIHTMLContentSink.h"
 
46
#include "nsHTMLTags.h"
 
47
#include "nsCOMPtr.h"
 
48
#include "nsIParserService.h"
 
49
#include "nsIContent.h"
 
50
#include "nsIAtom.h"
 
51
#include "nsIDocumentEncoder.h"
 
52
#include "nsString.h"
 
53
 
 
54
 
 
55
class mozSanitizingHTMLSerializer : public nsIContentSerializer,
 
56
                                    public nsIHTMLContentSink,
 
57
                                    public mozISanitizingHTMLSerializer
 
58
{
 
59
public:
 
60
  mozSanitizingHTMLSerializer();
 
61
  virtual ~mozSanitizingHTMLSerializer();
 
62
  static PRBool PR_CALLBACK ReleaseProperties(nsHashKey* key, void* data,
 
63
                                              void* closure);
 
64
 
 
65
  NS_DECL_ISUPPORTS
 
66
 
 
67
  // nsIContentSerializer
 
68
  NS_IMETHOD Init(PRUint32 flags, PRUint32 dummy, const char* aCharSet, 
 
69
                  PRBool aIsCopying);
 
70
 
 
71
  NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
 
72
                        PRInt32 aEndOffset, nsAString& aStr);
 
73
  NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection,
 
74
                                PRInt32 aStartOffset, PRInt32 aEndOffset,
 
75
                                nsAString& aStr)
 
76
                      { return NS_OK; }
 
77
  NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI,
 
78
                                         PRInt32 aStartOffset,
 
79
                                         PRInt32 aEndOffset,
 
80
                                         nsAString& aStr)
 
81
                      { return NS_OK; }
 
82
  NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset,
 
83
                           PRInt32 aEndOffset, nsAString& aStr)
 
84
                      { return NS_OK; }
 
85
  NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, nsAString& aStr)
 
86
                      { return NS_OK; }
 
87
  NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, PRBool aHasChildren,
 
88
                                nsAString& aStr); 
 
89
  NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, nsAString& aStr);
 
90
  NS_IMETHOD Flush(nsAString& aStr);
 
91
 
 
92
  NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument,
 
93
                                 nsAString& aStr);
 
94
 
 
95
  NS_IMETHOD PreserveSelection(nsIDOMNode * aStartContainer,
 
96
                               PRInt32 aStartOffset,
 
97
                               nsIDOMNode * aEndContainer,
 
98
                               PRInt32 aEndOffset);
 
99
 
 
100
  // nsIContentSink
 
101
  NS_IMETHOD WillBuildModel(void) { return NS_OK; }
 
102
  NS_IMETHOD DidBuildModel(void) { return NS_OK; }
 
103
  NS_IMETHOD WillInterrupt(void) { return NS_OK; }
 
104
  NS_IMETHOD WillResume(void) { return NS_OK; }
 
105
  NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }
 
106
  NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
 
107
  NS_IMETHOD CloseContainer(const nsHTMLTag aTag);
 
108
  NS_IMETHOD AddHeadContent(const nsIParserNode& aNode);
 
109
  NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
 
110
  NS_IMETHOD AddComment(const nsIParserNode& aNode) { return NS_OK; }
 
111
  NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode)
 
112
                                                    { return NS_OK; }
 
113
  NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
 
114
  NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
 
115
  NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
 
116
  virtual nsISupports *GetTarget() { return nsnull; }
 
117
 
 
118
  // nsIHTMLContentSink
 
119
  NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
 
120
  NS_IMETHOD CloseHTML();
 
121
  NS_IMETHOD OpenHead(const nsIParserNode& aNode);
 
122
  NS_IMETHOD CloseHead();
 
123
  NS_IMETHOD SetTitle(const nsString& aValue);
 
124
  NS_IMETHOD OpenBody(const nsIParserNode& aNode);
 
125
  NS_IMETHOD CloseBody();
 
126
  NS_IMETHOD OpenForm(const nsIParserNode& aNode);
 
127
  NS_IMETHOD CloseForm();
 
128
  NS_IMETHOD OpenMap(const nsIParserNode& aNode);
 
129
  NS_IMETHOD CloseMap();
 
130
  NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
 
131
  NS_IMETHOD CloseFrameset();
 
132
  NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn);
 
133
  NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) { return NS_OK; }
 
134
  NS_IMETHOD_(PRBool) IsFormOnStack() { return PR_FALSE; }
 
135
  NS_IMETHOD BeginContext(PRInt32 aPosition) { return NS_OK; }
 
136
  NS_IMETHOD EndContext(PRInt32 aPosition) { return NS_OK; }
 
137
  NS_IMETHOD WillProcessTokens(void) { return NS_OK; }
 
138
  NS_IMETHOD DidProcessTokens(void) { return NS_OK; }
 
139
  NS_IMETHOD WillProcessAToken(void) { return NS_OK; }
 
140
  NS_IMETHOD DidProcessAToken(void) { return NS_OK; }
 
141
 
 
142
  // nsISanitizingHTMLSerializer
 
143
  NS_IMETHOD Initialize(nsAString* aOutString,
 
144
                        PRUint32 aFlags, const nsAString& allowedTags);
 
145
 
 
146
protected:
 
147
  nsresult ParsePrefs(const nsAString& aPref);
 
148
  nsresult ParseTagPref(const nsCAutoString& tagpref);
 
149
  PRBool IsAllowedTag(nsHTMLTag aTag);
 
150
  PRBool IsAllowedAttribute(nsHTMLTag aTag, const nsAString& anAttributeName);
 
151
  nsresult SanitizeAttrValue(nsHTMLTag aTag, const nsAString& attr_name,
 
152
                             nsString& value /*inout*/);
 
153
  nsresult SanitizeTextNode(nsString& value /*inout*/);
 
154
  PRBool IsContainer(PRInt32 aId);
 
155
  static PRInt32 GetIdForContent(nsIContent* aContent);
 
156
  nsresult GetParserService(nsIParserService** aParserService);
 
157
  nsresult DoOpenContainer(PRInt32 aTag);
 
158
  nsresult DoCloseContainer(PRInt32 aTag);
 
159
  nsresult DoAddLeaf(PRInt32 aTag, const nsAString& aText);
 
160
  void Write(const nsAString& aString);
 
161
 
 
162
protected:
 
163
  PRInt32                      mFlags;
 
164
  nsHashtable                  mAllowedTags;
 
165
 
 
166
  nsCOMPtr<nsIContent>         mContent;
 
167
  nsAString*                   mOutputString;
 
168
  nsIParserNode*               mParserNode;
 
169
  nsCOMPtr<nsIParserService>   mParserService;
 
170
};
 
171
 
 
172
nsresult
 
173
NS_NewSanitizingHTMLSerializer(nsIContentSerializer** aSerializer);
 
174
 
 
175
#endif