1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
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 : * Ms2ger <ms2ger@gmail.com>
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 nsIDocument_h___
39 : #define nsIDocument_h___
40 :
41 : #include "nsINode.h"
42 : #include "nsStringGlue.h"
43 : #include "nsIDocumentObserver.h" // for nsUpdateType
44 : #include "nsCOMPtr.h"
45 : #include "nsCOMArray.h"
46 : #include "nsIURI.h"
47 : #include "nsWeakPtr.h"
48 : #include "nsIWeakReferenceUtils.h"
49 : #include "nsILoadGroup.h"
50 : #include "nsCRT.h"
51 : #include "mozFlushType.h"
52 : #include "nsIAtom.h"
53 : #include "nsCompatibility.h"
54 : #include "nsTObserverArray.h"
55 : #include "nsTHashtable.h"
56 : #include "nsHashKeys.h"
57 : #include "nsNodeInfoManager.h"
58 : #include "nsIStreamListener.h"
59 : #include "nsIVariant.h"
60 : #include "nsIObserver.h"
61 : #include "nsGkAtoms.h"
62 : #include "nsAutoPtr.h"
63 : #include "nsPIDOMWindow.h"
64 : #include "nsSMILAnimationController.h"
65 : #include "nsIScriptGlobalObject.h"
66 : #include "nsIDocumentEncoder.h"
67 : #include "nsIFrameRequestCallback.h"
68 : #include "nsEventStates.h"
69 : #include "nsIStructuredCloneContainer.h"
70 : #include "nsIBFCacheEntry.h"
71 :
72 : class nsIContent;
73 : class nsPresContext;
74 : class nsIPresShell;
75 : class nsIDocShell;
76 : class nsStyleSet;
77 : class nsIStyleSheet;
78 : class nsIStyleRule;
79 : class nsCSSStyleSheet;
80 : class nsIViewManager;
81 : class nsIDOMEvent;
82 : class nsIDOMEventTarget;
83 : class nsDeviceContext;
84 : class nsIParser;
85 : class nsIDOMNode;
86 : class nsIDOMElement;
87 : class nsIDOMDocumentFragment;
88 : class nsILineBreaker;
89 : class nsIWordBreaker;
90 : class nsISelection;
91 : class nsIChannel;
92 : class nsIPrincipal;
93 : class nsIDOMDocument;
94 : class nsIDOMDocumentType;
95 : class nsScriptLoader;
96 : class nsIContentSink;
97 : class nsHTMLStyleSheet;
98 : class nsHTMLCSSStyleSheet;
99 : class nsILayoutHistoryState;
100 : class nsIVariant;
101 : class nsIDOMUserDataHandler;
102 : template<class E> class nsCOMArray;
103 : class nsIDocumentObserver;
104 : class nsBindingManager;
105 : class nsIDOMNodeList;
106 : class mozAutoSubtreeModified;
107 : struct JSObject;
108 : class nsFrameLoader;
109 : class nsIBoxObject;
110 : class imgIRequest;
111 : class nsISHEntry;
112 : class nsDOMNavigationTiming;
113 : class nsWindowSizes;
114 :
115 : namespace mozilla {
116 : namespace css {
117 : class Loader;
118 : } // namespace css
119 :
120 : namespace dom {
121 : class Link;
122 : class Element;
123 : } // namespace dom
124 : } // namespace mozilla
125 :
126 : #define NS_IDOCUMENT_IID \
127 : { 0x283ec27d, 0x5b23, 0x49b2, \
128 : { 0x94, 0xd9, 0x9, 0xb5, 0xdb, 0x45, 0x30, 0x73 } }
129 :
130 :
131 : // Flag for AddStyleSheet().
132 : #define NS_STYLESHEET_FROM_CATALOG (1 << 0)
133 :
134 : // Enum for requesting a particular type of document when creating a doc
135 : enum DocumentFlavor {
136 : DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
137 : DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
138 : DocumentFlavorSVG // SVGDocument
139 : };
140 :
141 : // Document states
142 :
143 : // RTL locale: specific to the XUL localedir attribute
144 : #define NS_DOCUMENT_STATE_RTL_LOCALE NS_DEFINE_EVENT_STATE_MACRO(0)
145 : // Window activation status
146 : #define NS_DOCUMENT_STATE_WINDOW_INACTIVE NS_DEFINE_EVENT_STATE_MACRO(1)
147 :
148 : //----------------------------------------------------------------------
149 :
150 : // Document interface. This is implemented by all document objects in
151 : // Gecko.
152 : class nsIDocument : public nsINode
153 : {
154 : public:
155 : typedef mozilla::dom::Element Element;
156 :
157 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
158 5088 : NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
159 :
160 : #ifdef MOZILLA_INTERNAL_API
161 1273 : nsIDocument()
162 : : nsINode(nsnull),
163 1273 : mCharacterSet(NS_LITERAL_CSTRING("ISO-8859-1")),
164 : mNodeInfoManager(nsnull),
165 : mCompatMode(eCompatibility_FullStandards),
166 : mIsInitialDocumentInWindow(false),
167 : mMayStartLayout(true),
168 : mVisible(true),
169 : mRemovedFromDocShell(false),
170 : // mAllowDNSPrefetch starts true, so that we can always reliably && it
171 : // with various values that might disable it. Since we never prefetch
172 : // unless we get a window, and in that case the docshell value will get
173 : // &&-ed in, this is safe.
174 : mAllowDNSPrefetch(true),
175 : mIsBeingUsedAsImage(false),
176 : mHasLinksToUpdate(false),
177 2546 : mPartID(0)
178 : {
179 1273 : SetInDocument();
180 1273 : }
181 : #endif
182 :
183 : /**
184 : * Let the document know that we're starting to load data into it.
185 : * @param aCommand The parser command. Must not be null.
186 : * XXXbz It's odd to have that here.
187 : * @param aChannel The channel the data will come from. The channel must be
188 : * able to report its Content-Type.
189 : * @param aLoadGroup The loadgroup this document should use from now on.
190 : * Note that the document might not be the only thing using
191 : * this loadgroup.
192 : * @param aContainer The container this document is in. This may be null.
193 : * XXXbz maybe we should make it more explicit (eg make the
194 : * container an nsIWebNavigation or nsIDocShell or
195 : * something)?
196 : * @param [out] aDocListener the listener to pump data from the channel into.
197 : * Generally this will be the parser this document
198 : * sets up, or some sort of data-handler for media
199 : * documents.
200 : * @param aReset whether the document should call Reset() on itself. If this
201 : * is false, the document will NOT set its principal to the
202 : * channel's owner, will not clear any event listeners that are
203 : * already set on it, etc.
204 : * @param aSink The content sink to use for the data. If this is null and
205 : * the document needs a content sink, it will create one based
206 : * on whatever it knows about the data it's going to load.
207 : * This MUST be null if the underlying document is an HTML
208 : * document. Even in the XML case, please don't add new calls
209 : * with non-null sink.
210 : *
211 : * Once this has been called, the document will return false for
212 : * MayStartLayout() until SetMayStartLayout(true) is called on it. Making
213 : * sure this happens is the responsibility of the caller of
214 : * StartDocumentLoad().
215 : */
216 : virtual nsresult StartDocumentLoad(const char* aCommand,
217 : nsIChannel* aChannel,
218 : nsILoadGroup* aLoadGroup,
219 : nsISupports* aContainer,
220 : nsIStreamListener **aDocListener,
221 : bool aReset,
222 : nsIContentSink* aSink = nsnull) = 0;
223 : virtual void StopDocumentLoad() = 0;
224 :
225 : /**
226 : * Signal that the document title may have changed
227 : * (see nsDocument::GetTitle).
228 : * @param aBoundTitleElement true if an HTML or SVG <title> element
229 : * has just been bound to the document.
230 : */
231 : virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) = 0;
232 :
233 : /**
234 : * Return the URI for the document. May return null.
235 : *
236 : * The value returned corresponds to the "document's current address" in
237 : * HTML5. As such, it may change over the lifetime of the document, for
238 : * instance as a result of a call to pushState() or replaceState().
239 : */
240 349 : nsIURI* GetDocumentURI() const
241 : {
242 349 : return mDocumentURI;
243 : }
244 :
245 : /**
246 : * Return the original URI of the document. This is the same as the
247 : * document's URI unless history.pushState() or replaceState() is invoked on
248 : * the document.
249 : *
250 : * This method corresponds to the "document's address" in HTML5 and, once
251 : * set, doesn't change over the lifetime of the document.
252 : */
253 0 : nsIURI* GetOriginalURI() const
254 : {
255 0 : return mOriginalURI;
256 : }
257 :
258 : /**
259 : * Set the URI for the document. This also sets the document's original URI,
260 : * if it's null.
261 : */
262 : virtual void SetDocumentURI(nsIURI* aURI) = 0;
263 :
264 : /**
265 : * Set the principal responsible for this document.
266 : */
267 : virtual void SetPrincipal(nsIPrincipal *aPrincipal) = 0;
268 :
269 : /**
270 : * Return the LoadGroup for the document. May return null.
271 : */
272 0 : already_AddRefed<nsILoadGroup> GetDocumentLoadGroup() const
273 : {
274 0 : nsILoadGroup *group = nsnull;
275 0 : if (mDocumentLoadGroup)
276 0 : CallQueryReferent(mDocumentLoadGroup.get(), &group);
277 :
278 0 : return group;
279 : }
280 :
281 : /**
282 : * Return the base URI for relative URIs in the document (the document uri
283 : * unless it's overridden by SetBaseURI, HTML <base> tags, etc.). The
284 : * returned URI could be null if there is no document URI.
285 : */
286 3484 : nsIURI* GetDocBaseURI() const
287 : {
288 3484 : return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
289 : }
290 0 : virtual already_AddRefed<nsIURI> GetBaseURI() const
291 : {
292 0 : nsCOMPtr<nsIURI> uri = GetDocBaseURI();
293 :
294 0 : return uri.forget();
295 : }
296 :
297 : virtual nsresult SetBaseURI(nsIURI* aURI) = 0;
298 :
299 : /**
300 : * Get/Set the base target of a link in a document.
301 : */
302 : virtual void GetBaseTarget(nsAString &aBaseTarget) = 0;
303 0 : void SetBaseTarget(const nsString& aBaseTarget) {
304 0 : mBaseTarget = aBaseTarget;
305 0 : }
306 :
307 : /**
308 : * Return a standard name for the document's character set.
309 : */
310 528 : const nsCString& GetDocumentCharacterSet() const
311 : {
312 528 : return mCharacterSet;
313 : }
314 :
315 : /**
316 : * Set the document's character encoding. |aCharSetID| should be canonical.
317 : * That is, callers are responsible for the charset alias resolution.
318 : */
319 : virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) = 0;
320 :
321 0 : PRInt32 GetDocumentCharacterSetSource() const
322 : {
323 0 : return mCharacterSetSource;
324 : }
325 :
326 : // This method MUST be called before SetDocumentCharacterSet if
327 : // you're planning to call both.
328 0 : void SetDocumentCharacterSetSource(PRInt32 aCharsetSource)
329 : {
330 0 : mCharacterSetSource = aCharsetSource;
331 0 : }
332 :
333 : /**
334 : * Add an observer that gets notified whenever the charset changes.
335 : */
336 : virtual nsresult AddCharSetObserver(nsIObserver* aObserver) = 0;
337 :
338 : /**
339 : * Remove a charset observer.
340 : */
341 : virtual void RemoveCharSetObserver(nsIObserver* aObserver) = 0;
342 :
343 : /**
344 : * This gets fired when the element that an id refers to changes.
345 : * This fires at difficult times. It is generally not safe to do anything
346 : * which could modify the DOM in any way. Use
347 : * nsContentUtils::AddScriptRunner.
348 : * @return true to keep the callback in the callback set, false
349 : * to remove it.
350 : */
351 : typedef bool (* IDTargetObserver)(Element* aOldElement,
352 : Element* aNewelement, void* aData);
353 :
354 : /**
355 : * Add an IDTargetObserver for a specific ID. The IDTargetObserver
356 : * will be fired whenever the content associated with the ID changes
357 : * in the future. If aForImage is true, mozSetImageElement can override
358 : * what content is associated with the ID. In that case the IDTargetObserver
359 : * will be notified at those times when the result of LookupImageElement
360 : * changes.
361 : * At most one (aObserver, aData, aForImage) triple can be
362 : * registered for each ID.
363 : * @return the content currently associated with the ID.
364 : */
365 : virtual Element* AddIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
366 : void* aData, bool aForImage) = 0;
367 : /**
368 : * Remove the (aObserver, aData, aForImage) triple for a specific ID, if
369 : * registered.
370 : */
371 : virtual void RemoveIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
372 : void* aData, bool aForImage) = 0;
373 :
374 : /**
375 : * Get the Content-Type of this document.
376 : * (This will always return NS_OK, but has this signature to be compatible
377 : * with nsIDOMDocument::GetContentType())
378 : */
379 : NS_IMETHOD GetContentType(nsAString& aContentType) = 0;
380 :
381 : /**
382 : * Set the Content-Type of this document.
383 : */
384 : virtual void SetContentType(const nsAString& aContentType) = 0;
385 :
386 : /**
387 : * Return the language of this document.
388 : */
389 0 : void GetContentLanguage(nsAString& aContentLanguage) const
390 : {
391 0 : CopyASCIItoUTF16(mContentLanguage, aContentLanguage);
392 0 : }
393 :
394 : // The states BidiEnabled and MathMLEnabled should persist across multiple views
395 : // (screen, print) of the same document.
396 :
397 : /**
398 : * Check if the document contains bidi data.
399 : * If so, we have to apply the Unicode Bidi Algorithm.
400 : */
401 5 : bool GetBidiEnabled() const
402 : {
403 5 : return mBidiEnabled;
404 : }
405 :
406 : /**
407 : * Indicate the document contains bidi data.
408 : * Currently, we cannot disable bidi, because once bidi is enabled,
409 : * it affects a frame model irreversibly, and plays even though
410 : * the document no longer contains bidi data.
411 : */
412 4 : void SetBidiEnabled()
413 : {
414 4 : mBidiEnabled = true;
415 4 : }
416 :
417 : /**
418 : * Check if the document contains (or has contained) any MathML elements.
419 : */
420 0 : bool GetMathMLEnabled() const
421 : {
422 0 : return mMathMLEnabled;
423 : }
424 :
425 0 : void SetMathMLEnabled()
426 : {
427 0 : mMathMLEnabled = true;
428 0 : }
429 :
430 : /**
431 : * Ask this document whether it's the initial document in its window.
432 : */
433 0 : bool IsInitialDocument() const
434 : {
435 0 : return mIsInitialDocumentInWindow;
436 : }
437 :
438 : /**
439 : * Tell this document that it's the initial document in its window. See
440 : * comments on mIsInitialDocumentInWindow for when this should be called.
441 : */
442 0 : void SetIsInitialDocument(bool aIsInitialDocument)
443 : {
444 0 : mIsInitialDocumentInWindow = aIsInitialDocument;
445 0 : }
446 :
447 :
448 : /**
449 : * Get the bidi options for this document.
450 : * @see nsBidiUtils.h
451 : */
452 0 : PRUint32 GetBidiOptions() const
453 : {
454 0 : return mBidiOptions;
455 : }
456 :
457 : /**
458 : * Set the bidi options for this document. This just sets the bits;
459 : * callers are expected to take action as needed if they want this
460 : * change to actually change anything immediately.
461 : * @see nsBidiUtils.h
462 : */
463 0 : void SetBidiOptions(PRUint32 aBidiOptions)
464 : {
465 0 : mBidiOptions = aBidiOptions;
466 0 : }
467 :
468 : /**
469 : * Access HTTP header data (this may also get set from other
470 : * sources, like HTML META tags).
471 : */
472 : virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
473 : virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
474 :
475 : /**
476 : * Create a new presentation shell that will use aContext for its
477 : * presentation context (presentation contexts <b>must not</b> be
478 : * shared among multiple presentation shells). The caller of this
479 : * method is responsible for calling BeginObservingDocument() on the
480 : * presshell if the presshell should observe document mutations.
481 : */
482 : virtual nsresult CreateShell(nsPresContext* aContext,
483 : nsIViewManager* aViewManager,
484 : nsStyleSet* aStyleSet,
485 : nsIPresShell** aInstancePtrResult) = 0;
486 : virtual void DeleteShell() = 0;
487 :
488 232533 : nsIPresShell* GetShell() const
489 : {
490 232533 : return GetBFCacheEntry() ? nsnull : mPresShell;
491 : }
492 :
493 0 : void SetBFCacheEntry(nsIBFCacheEntry* aEntry)
494 : {
495 0 : mBFCacheEntry = aEntry;
496 0 : }
497 :
498 232533 : nsIBFCacheEntry* GetBFCacheEntry() const
499 : {
500 232533 : return mBFCacheEntry;
501 : }
502 :
503 : /**
504 : * Return the parent document of this document. Will return null
505 : * unless this document is within a compound document and has a
506 : * parent. Note that this parent chain may cross chrome boundaries.
507 : */
508 0 : nsIDocument *GetParentDocument() const
509 : {
510 0 : return mParentDocument;
511 : }
512 :
513 : /**
514 : * Set the parent document of this document.
515 : */
516 0 : void SetParentDocument(nsIDocument* aParent)
517 : {
518 0 : mParentDocument = aParent;
519 0 : }
520 :
521 : /**
522 : * Set the sub document for aContent to aSubDoc.
523 : */
524 : virtual nsresult SetSubDocumentFor(Element* aContent,
525 : nsIDocument* aSubDoc) = 0;
526 :
527 : /**
528 : * Get the sub document for aContent
529 : */
530 : virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
531 :
532 : /**
533 : * Find the content node for which aDocument is a sub document.
534 : */
535 : virtual Element* FindContentForSubDocument(nsIDocument* aDocument) const = 0;
536 :
537 : /**
538 : * Return the root element for this document.
539 : */
540 : Element *GetRootElement() const;
541 :
542 : protected:
543 : virtual Element *GetRootElementInternal() const = 0;
544 :
545 : public:
546 : // Get the root <html> element, or return null if there isn't one (e.g.
547 : // if the root isn't <html>)
548 : Element* GetHtmlElement();
549 : // Returns the first child of GetHtmlContent which has the given tag,
550 : // or nsnull if that doesn't exist.
551 : Element* GetHtmlChildElement(nsIAtom* aTag);
552 : // Get the canonical <body> element, or return null if there isn't one (e.g.
553 : // if the root isn't <html> or if the <body> isn't there)
554 0 : Element* GetBodyElement() {
555 0 : return GetHtmlChildElement(nsGkAtoms::body);
556 : }
557 : // Get the canonical <head> element, or return null if there isn't one (e.g.
558 : // if the root isn't <html> or if the <head> isn't there)
559 0 : Element* GetHeadElement() {
560 0 : return GetHtmlChildElement(nsGkAtoms::head);
561 : }
562 :
563 : /**
564 : * Accessors to the collection of stylesheets owned by this document.
565 : * Style sheets are ordered, most significant last.
566 : */
567 :
568 : /**
569 : * Get the number of stylesheets
570 : *
571 : * @return the number of stylesheets
572 : * @throws no exceptions
573 : */
574 : virtual PRInt32 GetNumberOfStyleSheets() const = 0;
575 :
576 : /**
577 : * Get a particular stylesheet
578 : * @param aIndex the index the stylesheet lives at. This is zero-based
579 : * @return the stylesheet at aIndex. Null if aIndex is out of range.
580 : * @throws no exceptions
581 : */
582 : virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) const = 0;
583 :
584 : /**
585 : * Insert a sheet at a particular spot in the stylesheet list (zero-based)
586 : * @param aSheet the sheet to insert
587 : * @param aIndex the index to insert at. This index will be
588 : * adjusted for the "special" sheets.
589 : * @throws no exceptions
590 : */
591 : virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) = 0;
592 :
593 : /**
594 : * Get the index of a particular stylesheet. This will _always_
595 : * consider the "special" sheets as part of the sheet list.
596 : * @param aSheet the sheet to get the index of
597 : * @return aIndex the index of the sheet in the full list
598 : */
599 : virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const = 0;
600 :
601 : /**
602 : * Replace the stylesheets in aOldSheets with the stylesheets in
603 : * aNewSheets. The two lists must have equal length, and the sheet
604 : * at positon J in the first list will be replaced by the sheet at
605 : * position J in the second list. Some sheets in the second list
606 : * may be null; if so the corresponding sheets in the first list
607 : * will simply be removed.
608 : */
609 : virtual void UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
610 : nsCOMArray<nsIStyleSheet>& aNewSheets) = 0;
611 :
612 : /**
613 : * Add a stylesheet to the document
614 : */
615 : virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
616 :
617 : /**
618 : * Remove a stylesheet from the document
619 : */
620 : virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
621 :
622 : /**
623 : * Notify the document that the applicable state of the sheet changed
624 : * and that observers should be notified and style sets updated
625 : */
626 : virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
627 : bool aApplicable) = 0;
628 :
629 : /**
630 : * Just like the style sheet API, but for "catalog" sheets,
631 : * extra sheets inserted at the UA level.
632 : */
633 : virtual PRInt32 GetNumberOfCatalogStyleSheets() const = 0;
634 : virtual nsIStyleSheet* GetCatalogStyleSheetAt(PRInt32 aIndex) const = 0;
635 : virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet) = 0;
636 : virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI) = 0;
637 :
638 : /**
639 : * Get this document's CSSLoader. This is guaranteed to not return null.
640 : */
641 3184 : mozilla::css::Loader* CSSLoader() const {
642 3184 : return mCSSLoader;
643 : }
644 :
645 : /**
646 : * Get the channel that was passed to StartDocumentLoad or Reset for this
647 : * document. Note that this may be null in some cases (eg if
648 : * StartDocumentLoad or Reset were never called)
649 : */
650 : virtual nsIChannel* GetChannel() const = 0;
651 :
652 : /**
653 : * Get this document's attribute stylesheet. May return null if
654 : * there isn't one.
655 : */
656 : virtual nsHTMLStyleSheet* GetAttributeStyleSheet() const = 0;
657 :
658 : /**
659 : * Get this document's inline style sheet. May return null if there
660 : * isn't one
661 : */
662 : virtual nsHTMLCSSStyleSheet* GetInlineStyleSheet() const = 0;
663 :
664 : /**
665 : * Get/set the object from which a document can get a script context
666 : * and scope. This is the context within which all scripts (during
667 : * document creation and during event handling) will run. Note that
668 : * this is the *inner* window object.
669 : */
670 : virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0;
671 : virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
672 :
673 : /**
674 : * Get/set the object from which the context for the event/script handling can
675 : * be got. Normally GetScriptHandlingObject() returns the same object as
676 : * GetScriptGlobalObject(), but if the document is loaded as data,
677 : * non-null may be returned, even if GetScriptGlobalObject() returns null.
678 : * aHasHadScriptHandlingObject is set true if document has had the object
679 : * for event/script handling. Do not process any events/script if the method
680 : * returns null, but aHasHadScriptHandlingObject is true.
681 : */
682 : nsIScriptGlobalObject*
683 18124 : GetScriptHandlingObject(bool& aHasHadScriptHandlingObject) const
684 : {
685 18124 : aHasHadScriptHandlingObject = mHasHadScriptHandlingObject;
686 0 : return mScriptGlobalObject ? mScriptGlobalObject.get() :
687 18124 : GetScriptHandlingObjectInternal();
688 : }
689 : virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) = 0;
690 :
691 : /**
692 : * Get the object that is used as the scope for all of the content
693 : * wrappers whose owner document is this document. Unlike the script global
694 : * object, this will only return null when the global object for this
695 : * document is truly gone. Use this object when you're trying to find a
696 : * content wrapper in XPConnect.
697 : */
698 : virtual nsIScriptGlobalObject* GetScopeObject() = 0;
699 :
700 : /**
701 : * Return the window containing the document (the outer window).
702 : */
703 7456 : nsPIDOMWindow *GetWindow() const
704 : {
705 7456 : return mWindow ? mWindow->GetOuterWindow() : GetWindowInternal();
706 : }
707 :
708 : /**
709 : * Return the inner window used as the script compilation scope for
710 : * this document. If you're not absolutely sure you need this, use
711 : * GetWindow().
712 : */
713 3638 : nsPIDOMWindow* GetInnerWindow()
714 : {
715 3638 : return mRemovedFromDocShell ? GetInnerWindowInternal() : mWindow;
716 : }
717 :
718 : /**
719 : * Return the outer window ID.
720 : */
721 : PRUint64 OuterWindowID() const
722 : {
723 : nsPIDOMWindow *window = GetWindow();
724 : return window ? window->WindowID() : 0;
725 : }
726 :
727 : /**
728 : * Return the inner window ID.
729 : */
730 5 : PRUint64 InnerWindowID()
731 : {
732 5 : nsPIDOMWindow *window = GetInnerWindow();
733 5 : return window ? window->WindowID() : 0;
734 : }
735 :
736 : /**
737 : * Get the script loader for this document
738 : */
739 : virtual nsScriptLoader* ScriptLoader() = 0;
740 :
741 : /**
742 : * Add/Remove an element to the document's id and name hashes
743 : */
744 : virtual void AddToIdTable(Element* aElement, nsIAtom* aId) = 0;
745 : virtual void RemoveFromIdTable(Element* aElement, nsIAtom* aId) = 0;
746 : virtual void AddToNameTable(Element* aElement, nsIAtom* aName) = 0;
747 : virtual void RemoveFromNameTable(Element* aElement, nsIAtom* aName) = 0;
748 :
749 : /**
750 : * Returns the element which either requested DOM full-screen mode, or
751 : * contains the element which requested DOM full-screen mode if the
752 : * requestee is in a subdocument. Note this element must be *in*
753 : * this document.
754 : */
755 : virtual Element* GetFullScreenElement() = 0;
756 :
757 : /**
758 : * Asynchronously requests that the document make aElement the full-screen
759 : * element, and move into full-screen mode. The current full-screen element
760 : * (if any) is pushed onto the full-screen element stack, and it can be
761 : * returned to full-screen status by calling RestorePreviousFullScreenState().
762 : */
763 : virtual void AsyncRequestFullScreen(Element* aElement) = 0;
764 :
765 : /**
766 : * Restores the previous full-screen element to full-screen status. If there
767 : * is no former full-screen element, this exits full-screen, moving the
768 : * top-level browser window out of full-screen mode.
769 : */
770 : virtual void RestorePreviousFullScreenState() = 0;
771 :
772 : /**
773 : * Returns true if this document is in full-screen mode.
774 : */
775 : virtual bool IsFullScreenDoc() = 0;
776 :
777 : /**
778 : * Exits all documents from DOM full-screen mode, and moves the top-level
779 : * browser window out of full-screen mode. If aRunAsync is true, this runs
780 : * asynchronously.
781 : */
782 : static void ExitFullScreen(bool aRunAsync);
783 :
784 : //----------------------------------------------------------------------
785 :
786 : // Document notification API's
787 :
788 : /**
789 : * Add a new observer of document change notifications. Whenever
790 : * content is changed, appended, inserted or removed the observers are
791 : * informed. An observer that is already observing the document must
792 : * not be added without being removed first.
793 : */
794 : virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
795 :
796 : /**
797 : * Remove an observer of document change notifications. This will
798 : * return false if the observer cannot be found.
799 : */
800 : virtual bool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
801 :
802 : // Observation hooks used to propagate notifications to document observers.
803 : // BeginUpdate must be called before any batch of modifications of the
804 : // content model or of style data, EndUpdate must be called afterward.
805 : // To make this easy and painless, use the mozAutoDocUpdate helper class.
806 : virtual void BeginUpdate(nsUpdateType aUpdateType) = 0;
807 : virtual void EndUpdate(nsUpdateType aUpdateType) = 0;
808 : virtual void BeginLoad() = 0;
809 : virtual void EndLoad() = 0;
810 :
811 : enum ReadyState { READYSTATE_UNINITIALIZED = 0, READYSTATE_LOADING = 1, READYSTATE_INTERACTIVE = 3, READYSTATE_COMPLETE = 4};
812 : virtual void SetReadyStateInternal(ReadyState rs) = 0;
813 : virtual ReadyState GetReadyStateEnum() = 0;
814 :
815 : // notify that a content node changed state. This must happen under
816 : // a scriptblocker but NOT within a begin/end update.
817 : virtual void ContentStateChanged(nsIContent* aContent,
818 : nsEventStates aStateMask) = 0;
819 :
820 : // Notify that a document state has changed.
821 : // This should only be called by callers whose state is also reflected in the
822 : // implementation of nsDocument::GetDocumentState.
823 : virtual void DocumentStatesChanged(nsEventStates aStateMask) = 0;
824 :
825 : // Observation hooks for style data to propagate notifications
826 : // to document observers
827 : virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
828 : nsIStyleRule* aOldStyleRule,
829 : nsIStyleRule* aNewStyleRule) = 0;
830 : virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
831 : nsIStyleRule* aStyleRule) = 0;
832 : virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
833 : nsIStyleRule* aStyleRule) = 0;
834 :
835 : /**
836 : * Flush notifications for this document and its parent documents
837 : * (since those may affect the layout of this one).
838 : */
839 : virtual void FlushPendingNotifications(mozFlushType aType) = 0;
840 :
841 : /**
842 : * Calls FlushPendingNotifications on any external resources this document
843 : * has. If this document has no external resources or is an external resource
844 : * itself this does nothing. This should only be called with
845 : * aType >= Flush_Style.
846 : */
847 : virtual void FlushExternalResources(mozFlushType aType) = 0;
848 :
849 368881 : nsBindingManager* BindingManager() const
850 : {
851 368881 : return mNodeInfoManager->GetBindingManager();
852 : }
853 :
854 : /**
855 : * Only to be used inside Gecko, you can't really do anything with the
856 : * pointer outside Gecko anyway.
857 : */
858 1518 : nsNodeInfoManager* NodeInfoManager() const
859 : {
860 1518 : return mNodeInfoManager;
861 : }
862 :
863 : /**
864 : * Reset the document using the given channel and loadgroup. This works
865 : * like ResetToURI, but also sets the document's channel to aChannel.
866 : * The principal of the document will be set from the channel.
867 : */
868 : virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0;
869 :
870 : /**
871 : * Reset this document to aURI, aLoadGroup, and aPrincipal. aURI must not be
872 : * null. If aPrincipal is null, a codebase principal based on aURI will be
873 : * used.
874 : */
875 : virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup,
876 : nsIPrincipal* aPrincipal) = 0;
877 :
878 : /**
879 : * Set the container (docshell) for this document. Virtual so that
880 : * docshell can call it.
881 : */
882 : virtual void SetContainer(nsISupports *aContainer);
883 :
884 : /**
885 : * Get the container (docshell) for this document.
886 : */
887 0 : already_AddRefed<nsISupports> GetContainer() const
888 : {
889 0 : nsISupports* container = nsnull;
890 0 : if (mDocumentContainer)
891 0 : CallQueryReferent(mDocumentContainer.get(), &container);
892 :
893 0 : return container;
894 : }
895 :
896 : /**
897 : * Set and get XML declaration. If aVersion is null there is no declaration.
898 : * aStandalone takes values -1, 0 and 1 indicating respectively that there
899 : * was no standalone parameter in the declaration, that it was given as no,
900 : * or that it was given as yes.
901 : */
902 : virtual void SetXMLDeclaration(const PRUnichar *aVersion,
903 : const PRUnichar *aEncoding,
904 : const PRInt32 aStandalone) = 0;
905 : virtual void GetXMLDeclaration(nsAString& aVersion,
906 : nsAString& aEncoding,
907 : nsAString& Standalone) = 0;
908 :
909 12179 : bool IsHTML() const
910 : {
911 12179 : return mIsRegularHTML;
912 : }
913 0 : bool IsXUL() const
914 : {
915 0 : return mIsXUL;
916 : }
917 :
918 : virtual bool IsScriptEnabled() = 0;
919 :
920 : virtual void AddXMLEventsContent(nsIContent * aXMLEventsElement) = 0;
921 :
922 : /**
923 : * Create an element with the specified name, prefix and namespace ID.
924 : */
925 : virtual nsresult CreateElem(const nsAString& aName, nsIAtom *aPrefix,
926 : PRInt32 aNamespaceID,
927 : nsIContent** aResult) = 0;
928 :
929 : /**
930 : * Get the security info (i.e. SSL state etc) that the document got
931 : * from the channel/document that created the content of the
932 : * document.
933 : *
934 : * @see nsIChannel
935 : */
936 0 : nsISupports *GetSecurityInfo()
937 : {
938 0 : return mSecurityInfo;
939 : }
940 :
941 : /**
942 : * Returns the default namespace ID used for elements created in this
943 : * document.
944 : */
945 8 : PRInt32 GetDefaultNamespaceID() const
946 : {
947 8 : return mDefaultElementType;
948 : }
949 :
950 : void DeleteAllProperties();
951 : void DeleteAllPropertiesFor(nsINode* aNode);
952 :
953 1541 : nsPropertyTable* PropertyTable(PRUint16 aCategory) {
954 1541 : if (aCategory == 0)
955 1271 : return &mPropertyTable;
956 270 : return GetExtraPropertyTable(aCategory);
957 : }
958 2550 : PRUint32 GetPropertyTableCount()
959 2550 : { return mExtraPropertyTables.Length() + 1; }
960 :
961 : /**
962 : * Sets the ID used to identify this part of the multipart document
963 : */
964 0 : void SetPartID(PRUint32 aID) {
965 0 : mPartID = aID;
966 0 : }
967 :
968 : /**
969 : * Return the ID used to identify this part of the multipart document
970 : */
971 0 : PRUint32 GetPartID() const {
972 0 : return mPartID;
973 : }
974 :
975 : /**
976 : * Sanitize the document by resetting all input elements and forms that have
977 : * autocomplete=off to their default values.
978 : */
979 : virtual nsresult Sanitize() = 0;
980 :
981 : /**
982 : * Enumerate all subdocuments.
983 : * The enumerator callback should return true to continue enumerating, or
984 : * false to stop. This will never get passed a null aDocument.
985 : */
986 : typedef bool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
987 : virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
988 : void *aData) = 0;
989 :
990 : /**
991 : * Check whether it is safe to cache the presentation of this document
992 : * and all of its subdocuments. This method checks the following conditions
993 : * recursively:
994 : * - Some document types, such as plugin documents, cannot be safely cached.
995 : * - If there are any pending requests, we don't allow the presentation
996 : * to be cached. Ideally these requests would be suspended and resumed,
997 : * but that is difficult in some cases, such as XMLHttpRequest.
998 : * - If there are any beforeunload or unload listeners, we must fire them
999 : * for correctness, but this likely puts the document into a state where
1000 : * it would not function correctly if restored.
1001 : *
1002 : * |aNewRequest| should be the request for a new document which will
1003 : * replace this document in the docshell. The new document's request
1004 : * will be ignored when checking for active requests. If there is no
1005 : * request associated with the new document, this parameter may be null.
1006 : */
1007 : virtual bool CanSavePresentation(nsIRequest *aNewRequest) = 0;
1008 :
1009 : /**
1010 : * Notify the document that its associated ContentViewer is being destroyed.
1011 : * This releases circular references so that the document can go away.
1012 : * Destroy() is only called on documents that have a content viewer.
1013 : */
1014 : virtual void Destroy() = 0;
1015 :
1016 : /**
1017 : * Notify the document that its associated ContentViewer is no longer
1018 : * the current viewer for the docshell. The document might still
1019 : * be rendered in "zombie state" until the next document is ready.
1020 : * The document should save form control state.
1021 : */
1022 : virtual void RemovedFromDocShell() = 0;
1023 :
1024 : /**
1025 : * Get the layout history state that should be used to save and restore state
1026 : * for nodes in this document. This may return null; if that happens state
1027 : * saving and restoration is not possible.
1028 : */
1029 : virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const = 0;
1030 :
1031 : /**
1032 : * Methods that can be used to prevent onload firing while an event that
1033 : * should block onload is posted. onload is guaranteed to not fire until
1034 : * either all calls to BlockOnload() have been matched by calls to
1035 : * UnblockOnload() or the load has been stopped altogether (by the user
1036 : * pressing the Stop button, say).
1037 : */
1038 : virtual void BlockOnload() = 0;
1039 : /**
1040 : * @param aFireSync whether to fire onload synchronously. If false,
1041 : * onload will fire asynchronously after all onload blocks have been
1042 : * removed. It will NOT fire from inside UnblockOnload. If true,
1043 : * onload may fire from inside UnblockOnload.
1044 : */
1045 : virtual void UnblockOnload(bool aFireSync) = 0;
1046 :
1047 : /**
1048 : * Notification that the page has been shown, for documents which are loaded
1049 : * into a DOM window. This corresponds to the completion of document load,
1050 : * or to the page's presentation being restored into an existing DOM window.
1051 : * This notification fires applicable DOM events to the content window. See
1052 : * nsIDOMPageTransitionEvent.idl for a description of the |aPersisted|
1053 : * parameter. If aDispatchStartTarget is null, the pageshow event is
1054 : * dispatched on the ScriptGlobalObject for this document, otherwise it's
1055 : * dispatched on aDispatchStartTarget.
1056 : * Note: if aDispatchStartTarget isn't null, the showing state of the
1057 : * document won't be altered.
1058 : */
1059 : virtual void OnPageShow(bool aPersisted,
1060 : nsIDOMEventTarget* aDispatchStartTarget) = 0;
1061 :
1062 : /**
1063 : * Notification that the page has been hidden, for documents which are loaded
1064 : * into a DOM window. This corresponds to the unloading of the document, or
1065 : * to the document's presentation being saved but removed from an existing
1066 : * DOM window. This notification fires applicable DOM events to the content
1067 : * window. See nsIDOMPageTransitionEvent.idl for a description of the
1068 : * |aPersisted| parameter. If aDispatchStartTarget is null, the pagehide
1069 : * event is dispatched on the ScriptGlobalObject for this document,
1070 : * otherwise it's dispatched on aDispatchStartTarget.
1071 : * Note: if aDispatchStartTarget isn't null, the showing state of the
1072 : * document won't be altered.
1073 : */
1074 : virtual void OnPageHide(bool aPersisted,
1075 : nsIDOMEventTarget* aDispatchStartTarget) = 0;
1076 :
1077 : /*
1078 : * We record the set of links in the document that are relevant to
1079 : * style.
1080 : */
1081 : /**
1082 : * Notification that an element is a link that is relevant to style.
1083 : */
1084 : virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) = 0;
1085 : /**
1086 : * Notification that an element is a link and its URI might have been
1087 : * changed or the element removed. If the element is still a link relevant
1088 : * to style, then someone must ensure that AddStyleRelevantLink is
1089 : * (eventually) called on it again.
1090 : */
1091 : virtual void ForgetLink(mozilla::dom::Link* aLink) = 0;
1092 :
1093 : /**
1094 : * Resets and removes a box object from the document's box object cache
1095 : *
1096 : * @param aElement canonical nsIContent pointer of the box object's element
1097 : */
1098 : virtual void ClearBoxObjectFor(nsIContent *aContent) = 0;
1099 :
1100 : /**
1101 : * Get the box object for an element. This is not exposed through a
1102 : * scriptable interface except for XUL documents.
1103 : */
1104 : NS_IMETHOD GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) = 0;
1105 :
1106 : /**
1107 : * Get the compatibility mode for this document
1108 : */
1109 220 : nsCompatibility GetCompatibilityMode() const {
1110 220 : return mCompatMode;
1111 : }
1112 :
1113 : /**
1114 : * Check whether we've ever fired a DOMTitleChanged event for this
1115 : * document.
1116 : */
1117 1038 : bool HaveFiredDOMTitleChange() const {
1118 1038 : return mHaveFiredTitleChange;
1119 : }
1120 :
1121 : /**
1122 : * See GetXBLChildNodesFor on nsBindingManager
1123 : */
1124 : virtual nsresult GetXBLChildNodesFor(nsIContent* aContent,
1125 : nsIDOMNodeList** aResult) = 0;
1126 :
1127 : /**
1128 : * See GetContentListFor on nsBindingManager
1129 : */
1130 : virtual nsresult GetContentListFor(nsIContent* aContent,
1131 : nsIDOMNodeList** aResult) = 0;
1132 :
1133 : /**
1134 : * Helper for nsIDOMDocument::elementFromPoint implementation that allows
1135 : * ignoring the scroll frame and/or avoiding layout flushes.
1136 : *
1137 : * @see nsIDOMWindowUtils::elementFromPoint
1138 : */
1139 : virtual nsresult ElementFromPointHelper(float aX, float aY,
1140 : bool aIgnoreRootScrollFrame,
1141 : bool aFlushLayout,
1142 : nsIDOMElement** aReturn) = 0;
1143 :
1144 : virtual nsresult NodesFromRectHelper(float aX, float aY,
1145 : float aTopSize, float aRightSize,
1146 : float aBottomSize, float aLeftSize,
1147 : bool aIgnoreRootScrollFrame,
1148 : bool aFlushLayout,
1149 : nsIDOMNodeList** aReturn) = 0;
1150 :
1151 : /**
1152 : * See FlushSkinBindings on nsBindingManager
1153 : */
1154 : virtual void FlushSkinBindings() = 0;
1155 :
1156 : /**
1157 : * To batch DOMSubtreeModified, document needs to be informed when
1158 : * a mutation event might be dispatched, even if the event isn't actually
1159 : * created because there are no listeners for it.
1160 : *
1161 : * @param aTarget is the target for the mutation event.
1162 : */
1163 3616 : void MayDispatchMutationEvent(nsINode* aTarget)
1164 : {
1165 3616 : if (mSubtreeModifiedDepth > 0) {
1166 89 : mSubtreeModifiedTargets.AppendObject(aTarget);
1167 : }
1168 3616 : }
1169 :
1170 : /**
1171 : * Marks as not-going-to-be-collected for the given generation of
1172 : * cycle collection.
1173 : */
1174 118 : void MarkUncollectableForCCGeneration(PRUint32 aGeneration)
1175 : {
1176 118 : mMarkedCCGeneration = aGeneration;
1177 118 : }
1178 :
1179 : /**
1180 : * Gets the cycle collector generation this document is marked for.
1181 : */
1182 547052 : PRUint32 GetMarkedCCGeneration()
1183 : {
1184 547052 : return mMarkedCCGeneration;
1185 : }
1186 :
1187 0 : bool IsLoadedAsData()
1188 : {
1189 0 : return mLoadedAsData;
1190 : }
1191 :
1192 0 : bool MayStartLayout()
1193 : {
1194 0 : return mMayStartLayout;
1195 : }
1196 :
1197 1050 : void SetMayStartLayout(bool aMayStartLayout)
1198 : {
1199 1050 : mMayStartLayout = aMayStartLayout;
1200 1050 : }
1201 :
1202 0 : already_AddRefed<nsIDocumentEncoder> GetCachedEncoder()
1203 : {
1204 0 : return mCachedEncoder.forget();
1205 : }
1206 :
1207 0 : void SetCachedEncoder(already_AddRefed<nsIDocumentEncoder> aEncoder)
1208 : {
1209 0 : mCachedEncoder = aEncoder;
1210 0 : }
1211 :
1212 : // In case of failure, the document really can't initialize the frame loader.
1213 : virtual nsresult InitializeFrameLoader(nsFrameLoader* aLoader) = 0;
1214 : // In case of failure, the caller must handle the error, for example by
1215 : // finalizing frame loader asynchronously.
1216 : virtual nsresult FinalizeFrameLoader(nsFrameLoader* aLoader) = 0;
1217 : // Removes the frame loader of aShell from the initialization list.
1218 : virtual void TryCancelFrameLoaderInitialization(nsIDocShell* aShell) = 0;
1219 : // Returns true if the frame loader of aShell is in the finalization list.
1220 : virtual bool FrameLoaderScheduledToBeFinalized(nsIDocShell* aShell) = 0;
1221 :
1222 : /**
1223 : * Check whether this document is a root document that is not an
1224 : * external resource.
1225 : */
1226 0 : bool IsRootDisplayDocument() const
1227 : {
1228 0 : return !mParentDocument && !mDisplayDocument;
1229 : }
1230 :
1231 0 : bool IsBeingUsedAsImage() const {
1232 0 : return mIsBeingUsedAsImage;
1233 : }
1234 :
1235 0 : void SetIsBeingUsedAsImage() {
1236 0 : mIsBeingUsedAsImage = true;
1237 0 : }
1238 :
1239 0 : bool IsResourceDoc() const {
1240 0 : return IsBeingUsedAsImage() || // Are we a helper-doc for an SVG image?
1241 0 : !!mDisplayDocument; // Are we an external resource doc?
1242 : }
1243 :
1244 : /**
1245 : * Get the document for which this document is an external resource. This
1246 : * will be null if this document is not an external resource. Otherwise,
1247 : * GetDisplayDocument() will return a non-null document, and
1248 : * GetDisplayDocument()->GetDisplayDocument() is guaranteed to be null.
1249 : */
1250 8 : nsIDocument* GetDisplayDocument() const
1251 : {
1252 8 : return mDisplayDocument;
1253 : }
1254 :
1255 : /**
1256 : * Set the display document for this document. aDisplayDocument must not be
1257 : * null.
1258 : */
1259 0 : void SetDisplayDocument(nsIDocument* aDisplayDocument)
1260 : {
1261 0 : NS_PRECONDITION(!GetShell() &&
1262 : !nsCOMPtr<nsISupports>(GetContainer()) &&
1263 : !GetWindow() &&
1264 : !GetScriptGlobalObject(),
1265 : "Shouldn't set mDisplayDocument on documents that already "
1266 : "have a presentation or a docshell or a window");
1267 0 : NS_PRECONDITION(aDisplayDocument != this, "Should be different document");
1268 0 : NS_PRECONDITION(!aDisplayDocument->GetDisplayDocument(),
1269 : "Display documents should not nest");
1270 0 : mDisplayDocument = aDisplayDocument;
1271 0 : }
1272 :
1273 : /**
1274 : * A class that represents an external resource load that has begun but
1275 : * doesn't have a document yet. Observers can be registered on this object,
1276 : * and will be notified after the document is created. Observers registered
1277 : * after the document has been created will NOT be notified. When observers
1278 : * are notified, the subject will be the newly-created document, the topic
1279 : * will be "external-resource-document-created", and the data will be null.
1280 : * If document creation fails for some reason, observers will still be
1281 : * notified, with a null document pointer.
1282 : */
1283 : class ExternalResourceLoad : public nsISupports
1284 0 : {
1285 : public:
1286 0 : virtual ~ExternalResourceLoad() {}
1287 :
1288 0 : void AddObserver(nsIObserver* aObserver) {
1289 0 : NS_PRECONDITION(aObserver, "Must have observer");
1290 0 : mObservers.AppendElement(aObserver);
1291 0 : }
1292 :
1293 0 : const nsTArray< nsCOMPtr<nsIObserver> > & Observers() {
1294 0 : return mObservers;
1295 : }
1296 : protected:
1297 : nsAutoTArray< nsCOMPtr<nsIObserver>, 8 > mObservers;
1298 : };
1299 :
1300 : /**
1301 : * Request an external resource document for aURI. This will return the
1302 : * resource document if available. If one is not available yet, it will
1303 : * start loading as needed, and the pending load object will be returned in
1304 : * aPendingLoad so that the caller can register an observer to wait for the
1305 : * load. If this function returns null and doesn't return a pending load,
1306 : * that means that there is no resource document for this URI and won't be
1307 : * one in the future.
1308 : *
1309 : * @param aURI the URI to get
1310 : * @param aRequestingNode the node making the request
1311 : * @param aPendingLoad the pending load for this request, if any
1312 : */
1313 : virtual nsIDocument*
1314 : RequestExternalResource(nsIURI* aURI,
1315 : nsINode* aRequestingNode,
1316 : ExternalResourceLoad** aPendingLoad) = 0;
1317 :
1318 : /**
1319 : * Enumerate the external resource documents associated with this document.
1320 : * The enumerator callback should return true to continue enumerating, or
1321 : * false to stop. This callback will never get passed a null aDocument.
1322 : */
1323 : virtual void EnumerateExternalResources(nsSubDocEnumFunc aCallback,
1324 : void* aData) = 0;
1325 :
1326 : /**
1327 : * Return whether the document is currently showing (in the sense of
1328 : * OnPageShow() having been called already and OnPageHide() not having been
1329 : * called yet.
1330 : */
1331 0 : bool IsShowing() const { return mIsShowing; }
1332 : /**
1333 : * Return whether the document is currently visible (in the sense of
1334 : * OnPageHide having been called and OnPageShow not yet having been called)
1335 : */
1336 0 : bool IsVisible() const { return mVisible; }
1337 : /**
1338 : * Return true when this document is active, i.e., the active document
1339 : * in a content viewer.
1340 : */
1341 0 : bool IsActive() const { return mDocumentContainer && !mRemovedFromDocShell; }
1342 :
1343 : void RegisterFreezableElement(nsIContent* aContent);
1344 : bool UnregisterFreezableElement(nsIContent* aContent);
1345 : typedef void (* FreezableElementEnumerator)(nsIContent*, void*);
1346 : void EnumerateFreezableElements(FreezableElementEnumerator aEnumerator,
1347 : void* aData);
1348 :
1349 : // Indicates whether mAnimationController has been (lazily) initialized.
1350 : // If this returns true, we're promising that GetAnimationController()
1351 : // will have a non-null return value.
1352 0 : bool HasAnimationController() { return !!mAnimationController; }
1353 :
1354 : // Getter for this document's SMIL Animation Controller. Performs lazy
1355 : // initialization, if this document supports animation and if
1356 : // mAnimationController isn't yet initialized.
1357 : virtual nsSMILAnimationController* GetAnimationController() = 0;
1358 :
1359 : // Makes the images on this document capable of having their animation
1360 : // active or suspended. An Image will animate as long as at least one of its
1361 : // owning Documents needs it to animate; otherwise it can suspend.
1362 : virtual void SetImagesNeedAnimating(bool aAnimating) = 0;
1363 :
1364 : /**
1365 : * Prevents user initiated events from being dispatched to the document and
1366 : * subdocuments.
1367 : */
1368 : virtual void SuppressEventHandling(PRUint32 aIncrease = 1) = 0;
1369 :
1370 : /**
1371 : * Unsuppress event handling.
1372 : * @param aFireEvents If true, delayed events (focus/blur) will be fired
1373 : * asynchronously.
1374 : */
1375 : virtual void UnsuppressEventHandlingAndFireEvents(bool aFireEvents) = 0;
1376 :
1377 0 : PRUint32 EventHandlingSuppressed() const { return mEventsSuppressed; }
1378 :
1379 0 : bool IsEventHandlingEnabled() {
1380 0 : return !EventHandlingSuppressed() && mScriptGlobalObject;
1381 : }
1382 :
1383 : /**
1384 : * Increment the number of external scripts being evaluated.
1385 : */
1386 0 : void BeginEvaluatingExternalScript() { ++mExternalScriptsBeingEvaluated; }
1387 :
1388 : /**
1389 : * Decrement the number of external scripts being evaluated.
1390 : */
1391 0 : void EndEvaluatingExternalScript() { --mExternalScriptsBeingEvaluated; }
1392 :
1393 0 : bool IsDNSPrefetchAllowed() const { return mAllowDNSPrefetch; }
1394 :
1395 : /**
1396 : * Returns true if this document is allowed to contain XUL element and
1397 : * use non-builtin XBL bindings.
1398 : */
1399 144 : bool AllowXULXBL() {
1400 : return mAllowXULXBL == eTriTrue ? true :
1401 : mAllowXULXBL == eTriFalse ? false :
1402 144 : InternalAllowXULXBL();
1403 : }
1404 :
1405 539 : void ForceEnableXULXBL() {
1406 539 : mAllowXULXBL = eTriTrue;
1407 539 : }
1408 :
1409 : /**
1410 : * true when this document is a static clone of a normal document.
1411 : * For example print preview and printing use static documents.
1412 : */
1413 0 : bool IsStaticDocument() { return mIsStaticDocument; }
1414 :
1415 : /**
1416 : * Clones the document and subdocuments and stylesheet etc.
1417 : * @param aCloneContainer The container for the clone document.
1418 : */
1419 : virtual already_AddRefed<nsIDocument>
1420 : CreateStaticClone(nsISupports* aCloneContainer);
1421 :
1422 : /**
1423 : * If this document is a static clone, this returns the original
1424 : * document.
1425 : */
1426 0 : nsIDocument* GetOriginalDocument()
1427 : {
1428 0 : MOZ_ASSERT(!mOriginalDocument || !mOriginalDocument->GetOriginalDocument());
1429 0 : return mOriginalDocument;
1430 : }
1431 :
1432 : /**
1433 : * Called by nsParser to preload images. Can be removed and code moved
1434 : * to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
1435 : * parser-module is linked with gklayout-module. aCrossOriginAttr should
1436 : * be a void string if the attr is not present.
1437 : */
1438 : virtual void MaybePreLoadImage(nsIURI* uri,
1439 : const nsAString& aCrossOriginAttr) = 0;
1440 :
1441 : /**
1442 : * Called by nsParser to preload style sheets. Can also be merged into
1443 : * the parser if and when the parser is merged with libgklayout.
1444 : */
1445 : virtual void PreloadStyle(nsIURI* aURI, const nsAString& aCharset) = 0;
1446 :
1447 : /**
1448 : * Called by the chrome registry to load style sheets. Can be put
1449 : * back there if and when when that module is merged with libgklayout.
1450 : *
1451 : * This always does a synchronous load. If aIsAgentSheet is true,
1452 : * it also uses the system principal and enables unsafe rules.
1453 : * DO NOT USE FOR UNTRUSTED CONTENT.
1454 : */
1455 : virtual nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet,
1456 : nsCSSStyleSheet** aSheet) = 0;
1457 :
1458 : /**
1459 : * Returns true if the locale used for the document specifies a direction of
1460 : * right to left. For chrome documents, this comes from the chrome registry.
1461 : * This is used to determine the current state for the :-moz-locale-dir pseudoclass
1462 : * so once can know whether a document is expected to be rendered left-to-right
1463 : * or right-to-left.
1464 : */
1465 0 : virtual bool IsDocumentRightToLeft() { return false; }
1466 :
1467 : enum DocumentTheme {
1468 : Doc_Theme_Uninitialized, // not determined yet
1469 : Doc_Theme_None,
1470 : Doc_Theme_Neutral,
1471 : Doc_Theme_Dark,
1472 : Doc_Theme_Bright
1473 : };
1474 :
1475 : /**
1476 : * Set the document's pending state object (as serialized using structured
1477 : * clone).
1478 : */
1479 0 : void SetStateObject(nsIStructuredCloneContainer *scContainer)
1480 : {
1481 0 : mStateObjectContainer = scContainer;
1482 0 : mStateObjectCached = nsnull;
1483 0 : }
1484 :
1485 : /**
1486 : * Returns Doc_Theme_None if there is no lightweight theme specified,
1487 : * Doc_Theme_Dark for a dark theme, Doc_Theme_Bright for a light theme, and
1488 : * Doc_Theme_Neutral for any other theme. This is used to determine the state
1489 : * of the pseudoclasses :-moz-lwtheme and :-moz-lwtheme-text.
1490 : */
1491 0 : virtual int GetDocumentLWTheme() { return Doc_Theme_None; }
1492 :
1493 : /**
1494 : * Returns the document state.
1495 : * Document state bits have the form NS_DOCUMENT_STATE_* and are declared in
1496 : * nsIDocument.h.
1497 : */
1498 : virtual nsEventStates GetDocumentState() = 0;
1499 :
1500 : virtual nsISupports* GetCurrentContentSink() = 0;
1501 :
1502 : /**
1503 : * Register/Unregister a filedata uri as being "owned" by this document.
1504 : * I.e. that its lifetime is connected with this document. When the document
1505 : * goes away it should "kill" the uri by calling
1506 : * nsBlobProtocolHandler::RemoveFileDataEntry
1507 : */
1508 : virtual void RegisterFileDataUri(const nsACString& aUri) = 0;
1509 : virtual void UnregisterFileDataUri(const nsACString& aUri) = 0;
1510 :
1511 : virtual void SetScrollToRef(nsIURI *aDocumentURI) = 0;
1512 : virtual void ScrollToRef() = 0;
1513 : virtual void ResetScrolledToRefAlready() = 0;
1514 : virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) = 0;
1515 :
1516 : /**
1517 : * This method is similar to GetElementById() from nsIDOMDocument but it
1518 : * returns a mozilla::dom::Element instead of a nsIDOMElement.
1519 : * It prevents converting nsIDOMElement to mozilla::dom::Element which is
1520 : * already converted from mozilla::dom::Element.
1521 : */
1522 : virtual Element* GetElementById(const nsAString& aElementId) = 0;
1523 :
1524 : /**
1525 : * This method returns _all_ the elements in this document which
1526 : * have id aElementId, if there are any. Otherwise it returns null.
1527 : * The entries of the nsSmallVoidArray are Element*
1528 : */
1529 : virtual const nsSmallVoidArray* GetAllElementsForId(const nsAString& aElementId) const = 0;
1530 :
1531 : /**
1532 : * Lookup an image element using its associated ID, which is usually provided
1533 : * by |-moz-element()|. Similar to GetElementById, with the difference that
1534 : * elements set using mozSetImageElement have higher priority.
1535 : * @param aId the ID associated the element we want to lookup
1536 : * @return the element associated with |aId|
1537 : */
1538 : virtual Element* LookupImageElement(const nsAString& aElementId) = 0;
1539 :
1540 : nsresult ScheduleFrameRequestCallback(nsIFrameRequestCallback* aCallback,
1541 : PRInt32 *aHandle);
1542 : void CancelFrameRequestCallback(PRInt32 aHandle);
1543 :
1544 : typedef nsTArray< nsCOMPtr<nsIFrameRequestCallback> > FrameRequestCallbackList;
1545 : /**
1546 : * Put this document's frame request callbacks into the provided
1547 : * list, and forget about them.
1548 : */
1549 : void TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks);
1550 :
1551 : // This returns true when the document tree is being teared down.
1552 0 : bool InUnlinkOrDeletion() { return mInUnlinkOrDeletion; }
1553 :
1554 : /*
1555 : * Image Tracking
1556 : *
1557 : * Style and content images register their imgIRequests with their document
1558 : * so that the document can efficiently tell all descendant images when they
1559 : * are and are not visible. When an image is on-screen, we want to call
1560 : * LockImage() on it so that it doesn't do things like discarding frame data
1561 : * to save memory. The PresShell informs the document whether its images
1562 : * should be locked or not via SetImageLockingState().
1563 : *
1564 : * See bug 512260.
1565 : */
1566 :
1567 : // Add/Remove images from the document image tracker
1568 : virtual nsresult AddImage(imgIRequest* aImage) = 0;
1569 : virtual nsresult RemoveImage(imgIRequest* aImage) = 0;
1570 :
1571 : // Makes the images on this document locked/unlocked. By default, the locking
1572 : // state is unlocked/false.
1573 : virtual nsresult SetImageLockingState(bool aLocked) = 0;
1574 :
1575 : virtual nsresult GetStateObject(nsIVariant** aResult) = 0;
1576 :
1577 : virtual nsDOMNavigationTiming* GetNavigationTiming() const = 0;
1578 :
1579 : virtual nsresult SetNavigationTiming(nsDOMNavigationTiming* aTiming) = 0;
1580 :
1581 : virtual Element* FindImageMap(const nsAString& aNormalizedMapName) = 0;
1582 :
1583 : // Called to notify the document that a listener on the "mozaudioavailable"
1584 : // event has been added. Media elements in the document need to ensure they
1585 : // fire the event.
1586 : virtual void NotifyAudioAvailableListener() = 0;
1587 :
1588 : // Returns true if the document has "mozaudioavailable" event listeners.
1589 : virtual bool HasAudioAvailableListeners() = 0;
1590 :
1591 : // Add aLink to the set of links that need their status resolved.
1592 : void RegisterPendingLinkUpdate(mozilla::dom::Link* aLink);
1593 :
1594 : // Remove aLink from the set of links that need their status resolved.
1595 : // This function must be called when links are removed from the document.
1596 : void UnregisterPendingLinkUpdate(mozilla::dom::Link* aElement);
1597 :
1598 : // Update state on links in mLinksToUpdate. This function must
1599 : // be called prior to selector matching.
1600 : void FlushPendingLinkUpdates();
1601 :
1602 : #define DEPRECATED_OPERATION(_op) e##_op,
1603 : enum DeprecatedOperations {
1604 : #include "nsDeprecatedOperationList.h"
1605 : eDeprecatedOperationCount
1606 : };
1607 : #undef DEPRECATED_OPERATION
1608 : void WarnOnceAbout(DeprecatedOperations aOperation);
1609 :
1610 : virtual void PostVisibilityUpdateEvent() = 0;
1611 :
1612 0 : bool IsSyntheticDocument() { return mIsSyntheticDocument; }
1613 :
1614 0 : void SetNeedLayoutFlush() {
1615 0 : mNeedLayoutFlush = true;
1616 0 : if (mDisplayDocument) {
1617 0 : mDisplayDocument->SetNeedLayoutFlush();
1618 : }
1619 0 : }
1620 :
1621 0 : void SetNeedStyleFlush() {
1622 0 : mNeedStyleFlush = true;
1623 0 : if (mDisplayDocument) {
1624 0 : mDisplayDocument->SetNeedStyleFlush();
1625 : }
1626 0 : }
1627 :
1628 : // Note: nsIDocument is a sub-class of nsINode, which has a
1629 : // SizeOfExcludingThis function. However, because nsIDocument objects can
1630 : // only appear at the top of the DOM tree, we have a specialized measurement
1631 : // function which returns multiple sizes.
1632 : virtual void DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
1633 : // DocSizeOfIncludingThis doesn't need to be overridden by sub-classes
1634 : // because nsIDocument inherits from nsINode; see the comment above the
1635 : // declaration of nsINode::SizeOfIncludingThis.
1636 : virtual void DocSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const;
1637 :
1638 : private:
1639 : PRUint64 mWarnedAbout;
1640 :
1641 : protected:
1642 1271 : ~nsIDocument()
1643 1271 : {
1644 : // XXX The cleanup of mNodeInfoManager (calling DropDocumentReference and
1645 : // releasing it) happens in the nsDocument destructor. We'd prefer to
1646 : // do it here but nsNodeInfoManager is a concrete class that we don't
1647 : // want to expose to users of the nsIDocument API outside of Gecko.
1648 1271 : }
1649 :
1650 : nsPropertyTable* GetExtraPropertyTable(PRUint16 aCategory);
1651 :
1652 : // Never ever call this. Only call GetWindow!
1653 : virtual nsPIDOMWindow *GetWindowInternal() const = 0;
1654 :
1655 : // Never ever call this. Only call GetInnerWindow!
1656 : virtual nsPIDOMWindow *GetInnerWindowInternal() = 0;
1657 :
1658 : // Never ever call this. Only call GetScriptHandlingObject!
1659 : virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const = 0;
1660 :
1661 : // Never ever call this. Only call AllowXULXBL!
1662 : virtual bool InternalAllowXULXBL() = 0;
1663 :
1664 : /**
1665 : * These methods should be called before and after dispatching
1666 : * a mutation event.
1667 : * To make this easy and painless, use the mozAutoSubtreeModified helper class.
1668 : */
1669 : virtual void WillDispatchMutationEvent(nsINode* aTarget) = 0;
1670 : virtual void MutationEventDispatched(nsINode* aTarget) = 0;
1671 : friend class mozAutoSubtreeModified;
1672 :
1673 0 : virtual Element* GetNameSpaceElement()
1674 : {
1675 0 : return GetRootElement();
1676 : }
1677 :
1678 2780 : void SetContentTypeInternal(const nsACString& aType)
1679 : {
1680 2780 : mCachedEncoder = nsnull;
1681 2780 : mContentType = aType;
1682 2780 : }
1683 :
1684 0 : nsCString GetContentTypeInternal() const
1685 : {
1686 0 : return mContentType;
1687 : }
1688 :
1689 : nsCOMPtr<nsIURI> mDocumentURI;
1690 : nsCOMPtr<nsIURI> mOriginalURI;
1691 : nsCOMPtr<nsIURI> mDocumentBaseURI;
1692 :
1693 : nsWeakPtr mDocumentLoadGroup;
1694 :
1695 : nsWeakPtr mDocumentContainer;
1696 :
1697 : nsCString mCharacterSet;
1698 : PRInt32 mCharacterSetSource;
1699 :
1700 : // This is just a weak pointer; the parent document owns its children.
1701 : nsIDocument* mParentDocument;
1702 :
1703 : // A reference to the element last returned from GetRootElement().
1704 : mozilla::dom::Element* mCachedRootElement;
1705 :
1706 : // We'd like these to be nsRefPtrs, but that'd require us to include
1707 : // additional headers that we don't want to expose.
1708 : // The cleanup is handled by the nsDocument destructor.
1709 : nsNodeInfoManager* mNodeInfoManager; // [STRONG]
1710 : mozilla::css::Loader* mCSSLoader; // [STRONG]
1711 :
1712 : // The set of all object, embed, applet, video and audio elements for
1713 : // which this is the owner document. (They might not be in the document.)
1714 : // These are non-owning pointers, the elements are responsible for removing
1715 : // themselves when they go away.
1716 : nsAutoPtr<nsTHashtable<nsPtrHashKey<nsIContent> > > mFreezableElements;
1717 :
1718 : // The set of all links that need their status resolved. Links must add themselves
1719 : // to this set by calling RegisterPendingLinkUpdate when added to a document and must
1720 : // remove themselves by calling UnregisterPendingLinkUpdate when removed from a document.
1721 : nsTHashtable<nsPtrHashKey<mozilla::dom::Link> > mLinksToUpdate;
1722 :
1723 : // SMIL Animation Controller, lazily-initialized in GetAnimationController
1724 : nsRefPtr<nsSMILAnimationController> mAnimationController;
1725 :
1726 : // Table of element properties for this document.
1727 : nsPropertyTable mPropertyTable;
1728 : nsTArray<nsAutoPtr<nsPropertyTable> > mExtraPropertyTables;
1729 :
1730 : // Compatibility mode
1731 : nsCompatibility mCompatMode;
1732 :
1733 : // True if BIDI is enabled.
1734 : bool mBidiEnabled;
1735 : // True if a MathML element has ever been owned by this document.
1736 : bool mMathMLEnabled;
1737 :
1738 : // True if this document is the initial document for a window. This should
1739 : // basically be true only for documents that exist in newly-opened windows or
1740 : // documents created to satisfy a GetDocument() on a window when there's no
1741 : // document in it.
1742 : bool mIsInitialDocumentInWindow;
1743 :
1744 : bool mIsRegularHTML;
1745 : bool mIsXUL;
1746 :
1747 : enum {
1748 : eTriUnset = 0,
1749 : eTriFalse,
1750 : eTriTrue
1751 : } mAllowXULXBL;
1752 :
1753 : // True if we're loaded as data and therefor has any dangerous stuff, such
1754 : // as scripts and plugins, disabled.
1755 : bool mLoadedAsData;
1756 :
1757 : // If true, whoever is creating the document has gotten it to the
1758 : // point where it's safe to start layout on it.
1759 : bool mMayStartLayout;
1760 :
1761 : // True iff we've ever fired a DOMTitleChanged event for this document
1762 : bool mHaveFiredTitleChange;
1763 :
1764 : // True iff IsShowing() should be returning true
1765 : bool mIsShowing;
1766 :
1767 : // True iff the document "page" is not hidden (i.e. currently in the
1768 : // bfcache)
1769 : bool mVisible;
1770 :
1771 : // True if our content viewer has been removed from the docshell
1772 : // (it may still be displayed, but in zombie state). Form control data
1773 : // has been saved.
1774 : bool mRemovedFromDocShell;
1775 :
1776 : // True iff DNS prefetch is allowed for this document. Note that if the
1777 : // document has no window, DNS prefetch won't be performed no matter what.
1778 : bool mAllowDNSPrefetch;
1779 :
1780 : // True when this document is a static clone of a normal document
1781 : bool mIsStaticDocument;
1782 :
1783 : // True while this document is being cloned to a static document.
1784 : bool mCreatingStaticClone;
1785 :
1786 : // True iff the document is being unlinked or deleted.
1787 : bool mInUnlinkOrDeletion;
1788 :
1789 : // True if document has ever had script handling object.
1790 : bool mHasHadScriptHandlingObject;
1791 :
1792 : // True if we're an SVG document being used as an image.
1793 : bool mIsBeingUsedAsImage;
1794 :
1795 : // True is this document is synthetic : stand alone image, video, audio
1796 : // file, etc.
1797 : bool mIsSyntheticDocument;
1798 :
1799 : // True if this document has links whose state needs updating
1800 : bool mHasLinksToUpdate;
1801 :
1802 : // True if a layout flush might not be a no-op
1803 : bool mNeedLayoutFlush;
1804 :
1805 : // True if a style flush might not be a no-op
1806 : bool mNeedStyleFlush;
1807 :
1808 : // The document's script global object, the object from which the
1809 : // document can get its script context and scope. This is the
1810 : // *inner* window object.
1811 : nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
1812 :
1813 : // If mIsStaticDocument is true, mOriginalDocument points to the original
1814 : // document.
1815 : nsCOMPtr<nsIDocument> mOriginalDocument;
1816 :
1817 : // The bidi options for this document. What this bitfield means is
1818 : // defined in nsBidiUtils.h
1819 : PRUint32 mBidiOptions;
1820 :
1821 : nsCString mContentLanguage;
1822 : private:
1823 : nsCString mContentType;
1824 : protected:
1825 :
1826 : // The document's security info
1827 : nsCOMPtr<nsISupports> mSecurityInfo;
1828 :
1829 : // if this document is part of a multipart document,
1830 : // the ID can be used to distinguish it from the other parts.
1831 : PRUint32 mPartID;
1832 :
1833 : // Cycle collector generation in which we're certain that this document
1834 : // won't be collected
1835 : PRUint32 mMarkedCCGeneration;
1836 :
1837 : nsIPresShell* mPresShell;
1838 :
1839 : nsCOMArray<nsINode> mSubtreeModifiedTargets;
1840 : PRUint32 mSubtreeModifiedDepth;
1841 :
1842 : // If we're an external resource document, this will be non-null and will
1843 : // point to our "display document": the one that all resource lookups should
1844 : // go to.
1845 : nsCOMPtr<nsIDocument> mDisplayDocument;
1846 :
1847 : PRUint32 mEventsSuppressed;
1848 :
1849 : /**
1850 : * The number number of external scripts (ones with the src attribute) that
1851 : * have this document as their owner and that are being evaluated right now.
1852 : */
1853 : PRUint32 mExternalScriptsBeingEvaluated;
1854 :
1855 : /**
1856 : * The current frame request callback handle
1857 : */
1858 : PRInt32 mFrameRequestCallbackCounter;
1859 :
1860 : // Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow,
1861 : // updated on every set of mSecriptGlobalObject.
1862 : nsPIDOMWindow *mWindow;
1863 :
1864 : nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
1865 :
1866 0 : struct FrameRequest {
1867 0 : FrameRequest(nsIFrameRequestCallback* aCallback,
1868 : PRInt32 aHandle) :
1869 : mCallback(aCallback),
1870 0 : mHandle(aHandle)
1871 0 : {}
1872 :
1873 : // Conversion operator so that we can append these to a
1874 : // FrameRequestCallbackList
1875 0 : operator nsIFrameRequestCallback* const () const { return mCallback; }
1876 :
1877 : // Comparator operators to allow RemoveElementSorted with an
1878 : // integer argument on arrays of FrameRequest
1879 0 : bool operator==(PRInt32 aHandle) const {
1880 0 : return mHandle == aHandle;
1881 : }
1882 0 : bool operator<(PRInt32 aHandle) const {
1883 0 : return mHandle < aHandle;
1884 : }
1885 :
1886 : nsCOMPtr<nsIFrameRequestCallback> mCallback;
1887 : PRInt32 mHandle;
1888 : };
1889 :
1890 : nsTArray<FrameRequest> mFrameRequestCallbacks;
1891 :
1892 : // This object allows us to evict ourself from the back/forward cache. The
1893 : // pointer is non-null iff we're currently in the bfcache.
1894 : nsIBFCacheEntry *mBFCacheEntry;
1895 :
1896 : // Our base target.
1897 : nsString mBaseTarget;
1898 :
1899 : nsCOMPtr<nsIStructuredCloneContainer> mStateObjectContainer;
1900 : nsCOMPtr<nsIVariant> mStateObjectCached;
1901 :
1902 : PRUint8 mDefaultElementType;
1903 : };
1904 :
1905 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID)
1906 :
1907 : /**
1908 : * mozAutoSubtreeModified batches DOM mutations so that a DOMSubtreeModified
1909 : * event is dispatched, if necessary, when the outermost mozAutoSubtreeModified
1910 : * object is deleted.
1911 : */
1912 : class NS_STACK_CLASS mozAutoSubtreeModified
1913 : {
1914 : public:
1915 : /**
1916 : * @param aSubTreeOwner The document in which a subtree will be modified.
1917 : * @param aTarget The target of the possible DOMSubtreeModified event.
1918 : * Can be nsnull, in which case mozAutoSubtreeModified
1919 : * is just used to batch DOM mutations.
1920 : */
1921 36 : mozAutoSubtreeModified(nsIDocument* aSubtreeOwner, nsINode* aTarget)
1922 36 : {
1923 36 : UpdateTarget(aSubtreeOwner, aTarget);
1924 36 : }
1925 :
1926 36 : ~mozAutoSubtreeModified()
1927 36 : {
1928 36 : UpdateTarget(nsnull, nsnull);
1929 36 : }
1930 :
1931 73 : void UpdateTarget(nsIDocument* aSubtreeOwner, nsINode* aTarget)
1932 : {
1933 73 : if (mSubtreeOwner) {
1934 36 : mSubtreeOwner->MutationEventDispatched(mTarget);
1935 : }
1936 :
1937 73 : mTarget = aTarget;
1938 73 : mSubtreeOwner = aSubtreeOwner;
1939 73 : if (mSubtreeOwner) {
1940 36 : mSubtreeOwner->WillDispatchMutationEvent(mTarget);
1941 : }
1942 73 : }
1943 :
1944 : private:
1945 : nsCOMPtr<nsINode> mTarget;
1946 : nsCOMPtr<nsIDocument> mSubtreeOwner;
1947 : };
1948 :
1949 : // XXX These belong somewhere else
1950 : nsresult
1951 : NS_NewHTMLDocument(nsIDocument** aInstancePtrResult);
1952 :
1953 : nsresult
1954 : NS_NewXMLDocument(nsIDocument** aInstancePtrResult);
1955 :
1956 : nsresult
1957 : NS_NewSVGDocument(nsIDocument** aInstancePtrResult);
1958 :
1959 : nsresult
1960 : NS_NewImageDocument(nsIDocument** aInstancePtrResult);
1961 :
1962 : #ifdef MOZ_MEDIA
1963 : nsresult
1964 : NS_NewVideoDocument(nsIDocument** aInstancePtrResult);
1965 : #endif
1966 :
1967 : nsresult
1968 : NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
1969 : nsNodeInfoManager *aNodeInfoManager);
1970 :
1971 : // Note: it's the caller's responsibility to create or get aPrincipal as needed
1972 : // -- this method will not attempt to get a principal based on aDocumentURI.
1973 : // Also, both aDocumentURI and aBaseURI must not be null.
1974 : nsresult
1975 : NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
1976 : const nsAString& aNamespaceURI,
1977 : const nsAString& aQualifiedName,
1978 : nsIDOMDocumentType* aDoctype,
1979 : nsIURI* aDocumentURI,
1980 : nsIURI* aBaseURI,
1981 : nsIPrincipal* aPrincipal,
1982 : bool aLoadedAsData,
1983 : nsIScriptGlobalObject* aEventObject,
1984 : DocumentFlavor aFlavor);
1985 :
1986 : // This is used only for xbl documents created from the startup cache.
1987 : // Non-cached documents are created in the same manner as xml documents.
1988 : nsresult
1989 : NS_NewXBLDocument(nsIDOMDocument** aInstancePtrResult,
1990 : nsIURI* aDocumentURI,
1991 : nsIURI* aBaseURI,
1992 : nsIPrincipal* aPrincipal);
1993 :
1994 : nsresult
1995 : NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
1996 :
1997 : inline nsIDocument*
1998 535 : nsINode::GetOwnerDocument() const
1999 : {
2000 535 : nsIDocument* ownerDoc = OwnerDoc();
2001 :
2002 535 : return ownerDoc != this ? ownerDoc : nsnull;
2003 : }
2004 :
2005 : #endif /* nsIDocument_h___ */
|