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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or 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 MPL, 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 MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 : #ifndef nsHTMLDocument_h___
39 : #define nsHTMLDocument_h___
40 :
41 : #include "nsDocument.h"
42 : #include "nsIHTMLDocument.h"
43 : #include "nsIDOMHTMLDocument.h"
44 : #include "nsIDOMHTMLBodyElement.h"
45 : #include "nsIDOMHTMLCollection.h"
46 : #include "nsIScriptElement.h"
47 : #include "jsapi.h"
48 : #include "nsTArray.h"
49 :
50 : #include "pldhash.h"
51 : #include "nsIHttpChannel.h"
52 : #include "nsHTMLStyleSheet.h"
53 :
54 : // Document.Write() related
55 : #include "nsIWyciwygChannel.h"
56 : #include "nsILoadGroup.h"
57 : #include "nsNetUtil.h"
58 :
59 : #include "nsICommandManager.h"
60 :
61 : class nsIEditor;
62 : class nsIEditorDocShell;
63 : class nsIParser;
64 : class nsIURI;
65 : class nsIMarkupDocumentViewer;
66 : class nsIDocShell;
67 : class nsICachingChannel;
68 :
69 : class nsHTMLDocument : public nsDocument,
70 : public nsIHTMLDocument,
71 : public nsIDOMHTMLDocument
72 468 : {
73 : public:
74 : using nsDocument::SetDocumentURI;
75 :
76 : nsHTMLDocument();
77 : virtual nsresult Init();
78 :
79 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
80 :
81 : NS_IMETHOD_(nsrefcnt) AddRef(void);
82 : NS_IMETHOD_(nsrefcnt) Release(void);
83 :
84 : virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
85 : virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
86 : nsIPrincipal* aPrincipal);
87 :
88 : virtual nsresult CreateShell(nsPresContext* aContext,
89 : nsIViewManager* aViewManager,
90 : nsStyleSet* aStyleSet,
91 : nsIPresShell** aInstancePtrResult);
92 :
93 : virtual nsresult StartDocumentLoad(const char* aCommand,
94 : nsIChannel* aChannel,
95 : nsILoadGroup* aLoadGroup,
96 : nsISupports* aContainer,
97 : nsIStreamListener **aDocListener,
98 : bool aReset = true,
99 : nsIContentSink* aSink = nsnull);
100 : virtual void StopDocumentLoad();
101 :
102 : virtual void BeginLoad();
103 :
104 : virtual void EndLoad();
105 :
106 : virtual void SetCompatibilityMode(nsCompatibility aMode);
107 :
108 0 : virtual bool IsWriting()
109 : {
110 0 : return mWriteLevel != PRUint32(0);
111 : }
112 :
113 0 : virtual bool GetIsFrameset() { return mIsFrameset; }
114 0 : virtual void SetIsFrameset(bool aFrameset) { mIsFrameset = aFrameset; }
115 :
116 : virtual NS_HIDDEN_(nsContentList*) GetForms();
117 :
118 : virtual NS_HIDDEN_(nsContentList*) GetFormControls();
119 :
120 : // nsIDOMDocument interface
121 468 : NS_FORWARD_NSIDOMDOCUMENT(nsDocument::)
122 :
123 : // nsIDOMNode interface
124 0 : NS_FORWARD_NSIDOMNODE(nsDocument::)
125 :
126 : // nsIDOMHTMLDocument interface
127 : NS_DECL_NSIDOMHTMLDOCUMENT
128 :
129 : /**
130 : * Returns the result of document.all[aID] which can either be a node
131 : * or a nodelist depending on if there are multiple nodes with the same
132 : * id.
133 : */
134 : nsISupports *GetDocumentAllResult(const nsAString& aID,
135 : nsWrapperCache **aCache,
136 : nsresult *aResult);
137 :
138 : nsIContent *GetBody();
139 0 : Element *GetHead() { return GetHeadElement(); }
140 0 : already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
141 : {
142 : return NS_GetFuncStringContentList(this, MatchNameAttribute, nsnull,
143 0 : UseExistingNameString, aName);
144 : }
145 :
146 :
147 : virtual nsresult ResolveName(const nsAString& aName,
148 : nsIContent *aForm,
149 : nsISupports **aResult,
150 : nsWrapperCache **aCache);
151 :
152 : virtual void AddedForm();
153 : virtual void RemovedForm();
154 : virtual PRInt32 GetNumFormsSynchronous();
155 : virtual void TearingDownEditor(nsIEditor *aEditor);
156 234 : virtual void SetIsXHTML(bool aXHTML) { mIsRegularHTML = !aXHTML; }
157 0 : virtual void SetDocWriteDisabled(bool aDisabled)
158 : {
159 0 : mDisableDocWrite = aDisabled;
160 0 : }
161 :
162 : nsresult ChangeContentEditableCount(nsIContent *aElement, PRInt32 aChange);
163 : void DeferredContentEditableCountChange(nsIContent *aElement);
164 :
165 492 : virtual EditingState GetEditingState()
166 : {
167 492 : return mEditingState;
168 : }
169 :
170 0 : virtual void DisableCookieAccess()
171 : {
172 0 : mDisableCookieAccess = true;
173 0 : }
174 :
175 : class nsAutoEditingState {
176 : public:
177 0 : nsAutoEditingState(nsHTMLDocument* aDoc, EditingState aState)
178 0 : : mDoc(aDoc), mSavedState(aDoc->mEditingState)
179 : {
180 0 : aDoc->mEditingState = aState;
181 0 : }
182 0 : ~nsAutoEditingState() {
183 0 : mDoc->mEditingState = mSavedState;
184 0 : }
185 : private:
186 : nsHTMLDocument* mDoc;
187 : EditingState mSavedState;
188 : };
189 : friend class nsAutoEditingState;
190 :
191 : void EndUpdate(nsUpdateType aUpdateType);
192 :
193 4864 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, nsDocument)
194 :
195 : virtual nsresult SetEditingState(EditingState aState);
196 :
197 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
198 :
199 : virtual NS_HIDDEN_(void) RemovedFromDocShell();
200 :
201 0 : virtual mozilla::dom::Element *GetElementById(const nsAString& aElementId)
202 : {
203 0 : return nsDocument::GetElementById(aElementId);
204 : }
205 :
206 : virtual nsXPCClassInfo* GetClassInfo();
207 :
208 : virtual void DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
209 : // DocSizeOfIncludingThis is inherited from nsIDocument.
210 :
211 : protected:
212 : nsresult GetBodySize(PRInt32* aWidth,
213 : PRInt32* aHeight);
214 :
215 : nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
216 :
217 : static bool MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID,
218 : nsIAtom* aAtom, void* aData);
219 : static bool MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID,
220 : nsIAtom* aAtom, void* aData);
221 : static bool MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
222 : nsIAtom* aAtom, void* aData);
223 : static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
224 :
225 : static void DocumentWriteTerminationFunc(nsISupports *aRef);
226 :
227 : void GetDomainURI(nsIURI **uri);
228 :
229 : nsresult WriteCommon(JSContext *cx, const nsAString& aText,
230 : bool aNewlineTerminate);
231 :
232 : nsresult CreateAndAddWyciwygChannel(void);
233 : nsresult RemoveWyciwygChannel(void);
234 :
235 : /**
236 : * Like IsEditingOn(), but will flush as needed first.
237 : */
238 : bool IsEditingOnAfterFlush();
239 :
240 : void *GenerateParserKey(void);
241 :
242 : nsCOMPtr<nsIDOMHTMLCollection> mImages;
243 : nsCOMPtr<nsIDOMHTMLCollection> mApplets;
244 : nsCOMPtr<nsIDOMHTMLCollection> mEmbeds;
245 : nsCOMPtr<nsIDOMHTMLCollection> mLinks;
246 : nsCOMPtr<nsIDOMHTMLCollection> mAnchors;
247 : nsCOMPtr<nsIDOMHTMLCollection> mScripts;
248 : nsRefPtr<nsContentList> mForms;
249 : nsRefPtr<nsContentList> mFormControls;
250 :
251 : /** # of forms in the document, synchronously set */
252 : PRInt32 mNumForms;
253 :
254 : static PRUint32 gWyciwygSessionCnt;
255 :
256 : static bool TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
257 : PRInt32& aCharsetSource,
258 : nsACString& aCharset);
259 : static bool TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
260 : nsIDocShell* aDocShell,
261 : PRInt32& aCharsetSource,
262 : nsACString& aCharset);
263 : static bool TryCacheCharset(nsICachingChannel* aCachingChannel,
264 : PRInt32& aCharsetSource,
265 : nsACString& aCharset);
266 : // aParentDocument could be null.
267 : bool TryParentCharset(nsIDocShell* aDocShell,
268 : nsIDocument* aParentDocument,
269 : PRInt32& charsetSource, nsACString& aCharset);
270 : static bool UseWeakDocTypeDefault(PRInt32& aCharsetSource,
271 : nsACString& aCharset);
272 : static bool TryDefaultCharset(nsIMarkupDocumentViewer* aMarkupDV,
273 : PRInt32& aCharsetSource,
274 : nsACString& aCharset);
275 :
276 : // Override so we can munge the charset on our wyciwyg channel as needed.
277 : virtual void SetDocumentCharacterSet(const nsACString& aCharSetID);
278 :
279 : // Tracks if we are currently processing any document.write calls (either
280 : // implicit or explicit). Note that if a write call writes out something which
281 : // would block the parser, then mWriteLevel will be incorrect until the parser
282 : // finishes processing that script.
283 : PRUint32 mWriteLevel;
284 :
285 : // Load flags of the document's channel
286 : PRUint32 mLoadFlags;
287 :
288 : bool mIsFrameset;
289 :
290 : bool mTooDeepWriteRecursion;
291 :
292 : bool mDisableDocWrite;
293 :
294 : bool mWarnedWidthHeight;
295 :
296 : nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
297 :
298 : /* Midas implementation */
299 : nsresult GetMidasCommandManager(nsICommandManager** aCommandManager);
300 :
301 : nsCOMPtr<nsICommandManager> mMidasCommandManager;
302 :
303 : nsresult TurnEditingOff();
304 : nsresult EditingStateChanged();
305 : void MaybeEditingStateChanged();
306 :
307 : PRUint32 mContentEditableCount;
308 : EditingState mEditingState;
309 :
310 : nsresult DoClipboardSecurityCheck(bool aPaste);
311 : static jsid sCutCopyInternal_id;
312 : static jsid sPasteInternal_id;
313 :
314 : // When false, the .cookies property is completely disabled
315 : bool mDisableCookieAccess;
316 : };
317 :
318 : #define NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
319 : NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
320 : NS_INTERFACE_TABLE_ENTRY(_class, nsIHTMLDocument) \
321 : NS_INTERFACE_TABLE_ENTRY(_class, nsIDOMHTMLDocument)
322 :
323 : #endif /* nsHTMLDocument_h___ */
|