Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 : #ifndef nsIDocument_h___
7 : #define nsIDocument_h___
8 :
9 : #include "mozilla/FlushType.h" // for enum
10 : #include "nsAutoPtr.h" // for member
11 : #include "nsCOMArray.h" // for member
12 : #include "nsCompatibility.h" // for member
13 : #include "nsCOMPtr.h" // for member
14 : #include "nsGkAtoms.h" // for static class members
15 : #include "nsIDocumentObserver.h" // for typedef (nsUpdateType)
16 : #include "nsILoadGroup.h" // for member (in nsCOMPtr)
17 : #include "nsINode.h" // for base class
18 : #include "nsIParser.h"
19 : #include "nsIScriptGlobalObject.h" // for member (in nsCOMPtr)
20 : #include "nsIServiceManager.h"
21 : #include "nsIUUIDGenerator.h"
22 : #include "nsPIDOMWindow.h" // for use in inline functions
23 : #include "nsPropertyTable.h" // for member
24 : #include "nsDataHashtable.h" // for member
25 : #include "nsURIHashKey.h" // for member
26 : #include "mozilla/net/ReferrerPolicy.h" // for member
27 : #include "nsWeakReference.h"
28 : #include "mozilla/UseCounter.h"
29 : #include "mozilla/WeakPtr.h"
30 : #include "Units.h"
31 : #include "nsContentListDeclarations.h"
32 : #include "nsExpirationTracker.h"
33 : #include "nsClassHashtable.h"
34 : #include "mozilla/CORSMode.h"
35 : #include "mozilla/dom/DispatcherTrait.h"
36 : #include "mozilla/LinkedList.h"
37 : #include "mozilla/NotNull.h"
38 : #include "mozilla/SegmentedVector.h"
39 : #include "mozilla/StyleBackendType.h"
40 : #include "mozilla/StyleSheet.h"
41 : #include "mozilla/TimeStamp.h"
42 : #include "mozilla/UniquePtr.h"
43 : #include <bitset> // for member
44 :
45 : #ifdef MOZILLA_INTERNAL_API
46 : #include "mozilla/dom/DocumentBinding.h"
47 : #else
48 : namespace mozilla {
49 : namespace dom {
50 : class ElementCreationOptionsOrString;
51 : } // namespace dom
52 : } // namespace mozilla
53 : #endif // MOZILLA_INTERNAL_API
54 :
55 : class gfxUserFontSet;
56 : class imgIRequest;
57 : class nsAString;
58 : class nsBindingManager;
59 : class nsIDocShell;
60 : class nsDocShell;
61 : class nsDOMNavigationTiming;
62 : class nsFrameLoader;
63 : class nsHTMLCSSStyleSheet;
64 : class nsHTMLDocument;
65 : class nsHTMLStyleSheet;
66 : class nsIAtom;
67 : class nsIBFCacheEntry;
68 : class nsIChannel;
69 : class nsIContent;
70 : class nsIContentSink;
71 : class nsIDocShell;
72 : class nsIDocShellTreeItem;
73 : class nsIDocumentEncoder;
74 : class nsIDocumentObserver;
75 : class nsIDOMDocument;
76 : class nsIDOMDocumentType;
77 : class nsIDOMElement;
78 : class nsIDOMNodeFilter;
79 : class nsIDOMNodeList;
80 : class nsIHTMLCollection;
81 : class nsILayoutHistoryState;
82 : class nsILoadContext;
83 : class nsIObjectLoadingContent;
84 : class nsIObserver;
85 : class nsIPresShell;
86 : class nsIPrincipal;
87 : class nsIRequest;
88 : class nsIRunnable;
89 : class nsIStreamListener;
90 : class nsIStructuredCloneContainer;
91 : class nsIURI;
92 : class nsIVariant;
93 : class nsViewManager;
94 : class nsPresContext;
95 : class nsRange;
96 : class nsSMILAnimationController;
97 : class nsSVGElement;
98 : class nsTextNode;
99 : class nsWindowSizes;
100 : class nsDOMCaretPosition;
101 : class nsViewportInfo;
102 : class nsIGlobalObject;
103 : struct nsCSSSelectorList;
104 :
105 : namespace mozilla {
106 : class AbstractThread;
107 : class CSSStyleSheet;
108 : class Encoding;
109 : class ErrorResult;
110 : class EventStates;
111 : class PendingAnimationTracker;
112 : class StyleSetHandle;
113 : template<typename> class OwningNonNull;
114 : struct URLExtraData;
115 :
116 : namespace css {
117 : class Loader;
118 : class ImageLoader;
119 : class Rule;
120 : } // namespace css
121 :
122 : namespace dom {
123 : class Animation;
124 : class AnonymousContent;
125 : class Attr;
126 : class BoxObject;
127 : class CDATASection;
128 : class Comment;
129 : struct CustomElementDefinition;
130 : class DocGroup;
131 : class DocumentFragment;
132 : class DocumentTimeline;
133 : class DocumentType;
134 : class DOMImplementation;
135 : class DOMIntersectionObserver;
136 : class DOMStringList;
137 : class Element;
138 : struct ElementCreationOptions;
139 : struct ElementRegistrationOptions;
140 : class Event;
141 : class EventTarget;
142 : class FontFaceSet;
143 : class FrameRequestCallback;
144 : struct FullscreenRequest;
145 : class ImageTracker;
146 : class HTMLBodyElement;
147 : struct LifecycleCallbackArgs;
148 : class Link;
149 : class Location;
150 : class MediaQueryList;
151 : class GlobalObject;
152 : class NodeFilter;
153 : class NodeIterator;
154 : enum class OrientationType : uint8_t;
155 : class ProcessingInstruction;
156 : class Promise;
157 : class ScriptLoader;
158 : class StyleSheetList;
159 : class SVGDocument;
160 : class SVGSVGElement;
161 : class Touch;
162 : class TouchList;
163 : class TreeWalker;
164 : class XPathEvaluator;
165 : class XPathExpression;
166 : class XPathNSResolver;
167 : class XPathResult;
168 : template<typename> class Sequence;
169 :
170 : template<typename, typename> class CallbackObjectHolder;
171 : typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
172 :
173 : enum class CallerType : uint32_t;
174 :
175 : } // namespace dom
176 : } // namespace mozilla
177 :
178 : #define NS_IDOCUMENT_IID \
179 : { 0xce1f7627, 0x7109, 0x4977, \
180 : { 0xba, 0x77, 0x49, 0x0f, 0xfd, 0xe0, 0x7a, 0xaa } }
181 :
182 : // Enum for requesting a particular type of document when creating a doc
183 : enum DocumentFlavor {
184 : DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
185 : DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
186 : DocumentFlavorSVG, // SVGDocument
187 : DocumentFlavorPlain, // Just a Document
188 : };
189 :
190 : // Enum for HSTS priming states
191 : enum class HSTSPrimingState {
192 : eNO_HSTS_PRIMING = 0, // don't do HSTS Priming
193 : eHSTS_PRIMING_ALLOW = 1, // if HSTS priming fails, allow the load to proceed
194 : eHSTS_PRIMING_BLOCK = 2 // if HSTS priming fails, block the load
195 : };
196 :
197 : // Document states
198 :
199 : // RTL locale: specific to the XUL localedir attribute
200 : #define NS_DOCUMENT_STATE_RTL_LOCALE NS_DEFINE_EVENT_STATE_MACRO(0)
201 : // Window activation status
202 : #define NS_DOCUMENT_STATE_WINDOW_INACTIVE NS_DEFINE_EVENT_STATE_MACRO(1)
203 :
204 : // Some function forward-declarations
205 : class nsContentList;
206 :
207 : //----------------------------------------------------------------------
208 :
209 : // Document interface. This is implemented by all document objects in
210 : // Gecko.
211 : class nsIDocument : public nsINode,
212 : public mozilla::dom::DispatcherTrait
213 : {
214 : typedef mozilla::dom::GlobalObject GlobalObject;
215 :
216 : protected:
217 : using Encoding = mozilla::Encoding;
218 : template <typename T> using NotNull = mozilla::NotNull<T>;
219 :
220 : public:
221 : typedef mozilla::net::ReferrerPolicy ReferrerPolicyEnum;
222 : typedef mozilla::dom::Element Element;
223 : typedef mozilla::dom::FullscreenRequest FullscreenRequest;
224 :
225 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
226 :
227 : #ifdef MOZILLA_INTERNAL_API
228 : nsIDocument();
229 : #endif
230 :
231 : // This helper class must be set when we dispatch beforeunload and unload
232 : // events in order to avoid unterminate sync XHRs.
233 : class MOZ_RAII PageUnloadingEventTimeStamp
234 : {
235 : nsCOMPtr<nsIDocument> mDocument;
236 : bool mSet;
237 :
238 : public:
239 13 : explicit PageUnloadingEventTimeStamp(nsIDocument* aDocument)
240 13 : : mDocument(aDocument)
241 13 : , mSet(false)
242 : {
243 13 : MOZ_ASSERT(aDocument);
244 13 : if (mDocument->mPageUnloadingEventTimeStamp.IsNull()) {
245 13 : mDocument->SetPageUnloadingEventTimeStamp();
246 13 : mSet = true;
247 : }
248 13 : }
249 :
250 13 : ~PageUnloadingEventTimeStamp()
251 13 : {
252 13 : if (mSet) {
253 13 : mDocument->CleanUnloadEventsTimeStamp();
254 : }
255 13 : }
256 : };
257 :
258 : /**
259 : * Let the document know that we're starting to load data into it.
260 : * @param aCommand The parser command. Must not be null.
261 : * XXXbz It's odd to have that here.
262 : * @param aChannel The channel the data will come from. The channel must be
263 : * able to report its Content-Type.
264 : * @param aLoadGroup The loadgroup this document should use from now on.
265 : * Note that the document might not be the only thing using
266 : * this loadgroup.
267 : * @param aContainer The container this document is in. This may be null.
268 : * XXXbz maybe we should make it more explicit (eg make the
269 : * container an nsIWebNavigation or nsIDocShell or
270 : * something)?
271 : * @param [out] aDocListener the listener to pump data from the channel into.
272 : * Generally this will be the parser this document
273 : * sets up, or some sort of data-handler for media
274 : * documents.
275 : * @param aReset whether the document should call Reset() on itself. If this
276 : * is false, the document will NOT set its principal to the
277 : * channel's owner, will not clear any event listeners that are
278 : * already set on it, etc.
279 : * @param aSink The content sink to use for the data. If this is null and
280 : * the document needs a content sink, it will create one based
281 : * on whatever it knows about the data it's going to load.
282 : * This MUST be null if the underlying document is an HTML
283 : * document. Even in the XML case, please don't add new calls
284 : * with non-null sink.
285 : *
286 : * Once this has been called, the document will return false for
287 : * MayStartLayout() until SetMayStartLayout(true) is called on it. Making
288 : * sure this happens is the responsibility of the caller of
289 : * StartDocumentLoad().
290 : */
291 : virtual nsresult StartDocumentLoad(const char* aCommand,
292 : nsIChannel* aChannel,
293 : nsILoadGroup* aLoadGroup,
294 : nsISupports* aContainer,
295 : nsIStreamListener **aDocListener,
296 : bool aReset,
297 : nsIContentSink* aSink = nullptr) = 0;
298 : virtual void StopDocumentLoad() = 0;
299 :
300 0 : virtual void SetSuppressParserErrorElement(bool aSuppress) {}
301 0 : virtual bool SuppressParserErrorElement() { return false; }
302 :
303 0 : virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {}
304 0 : virtual bool SuppressParserErrorConsoleMessages() { return false; }
305 :
306 : /**
307 : * Signal that the document title may have changed
308 : * (see nsDocument::GetTitle).
309 : * @param aBoundTitleElement true if an HTML or SVG <title> element
310 : * has just been bound to the document.
311 : */
312 : virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) = 0;
313 :
314 : /**
315 : * Return the URI for the document. May return null.
316 : *
317 : * The value returned corresponds to the "document's address" in
318 : * HTML5. As such, it may change over the lifetime of the document, for
319 : * instance as a result of the user navigating to a fragment identifier on
320 : * the page, or as a result to a call to pushState() or replaceState().
321 : *
322 : * https://html.spec.whatwg.org/multipage/dom.html#the-document%27s-address
323 : */
324 2898 : nsIURI* GetDocumentURI() const
325 : {
326 2898 : return mDocumentURI;
327 : }
328 :
329 : /**
330 : * Return the original URI of the document. This is the same as the
331 : * document's URI unless that has changed from its original value (for
332 : * example, due to history.pushState() or replaceState() being invoked on the
333 : * document).
334 : *
335 : * This method corresponds to the "creation URL" in HTML5 and, once set,
336 : * doesn't change over the lifetime of the document.
337 : *
338 : * https://html.spec.whatwg.org/multipage/webappapis.html#creation-url
339 : */
340 12 : nsIURI* GetOriginalURI() const
341 : {
342 12 : return mOriginalURI;
343 : }
344 :
345 : /**
346 : * Set the URI for the document. This also sets the document's original URI,
347 : * if it's null.
348 : */
349 : virtual void SetDocumentURI(nsIURI* aURI) = 0;
350 :
351 : /**
352 : * Set the URI for the document loaded via XHR, when accessed from
353 : * chrome privileged script.
354 : */
355 : virtual void SetChromeXHRDocURI(nsIURI* aURI) = 0;
356 :
357 : /**
358 : * Set the base URI for the document loaded via XHR, when accessed from
359 : * chrome privileged script.
360 : */
361 : virtual void SetChromeXHRDocBaseURI(nsIURI* aURI) = 0;
362 :
363 : /**
364 : * Set referrer policy and upgrade-insecure-requests flags
365 : */
366 : virtual void ApplySettingsFromCSP(bool aSpeculative) = 0;
367 :
368 : virtual already_AddRefed<nsIParser> CreatorParserOrNull() = 0;
369 :
370 : /**
371 : * Return the referrer policy of the document. Return "default" if there's no
372 : * valid meta referrer tag found in the document.
373 : */
374 62 : ReferrerPolicyEnum GetReferrerPolicy() const
375 : {
376 62 : return mReferrerPolicy;
377 : }
378 :
379 : /**
380 : * GetReferrerPolicy() for Document.webidl.
381 : */
382 0 : uint32_t ReferrerPolicy() const
383 : {
384 0 : return GetReferrerPolicy();
385 : }
386 :
387 : /**
388 : * If true, this flag indicates that all mixed content subresource
389 : * loads for this document (and also embeded browsing contexts) will
390 : * be blocked.
391 : */
392 2 : bool GetBlockAllMixedContent(bool aPreload) const
393 : {
394 2 : if (aPreload) {
395 1 : return mBlockAllMixedContentPreloads;
396 : }
397 1 : return mBlockAllMixedContent;
398 : }
399 :
400 : /**
401 : * If true, this flag indicates that all subresource loads for this
402 : * document need to be upgraded from http to https.
403 : * This flag becomes true if the CSP of the document itself, or any
404 : * of the document's ancestors up to the toplevel document makes use
405 : * of the CSP directive 'upgrade-insecure-requests'.
406 : */
407 61 : bool GetUpgradeInsecureRequests(bool aPreload) const
408 : {
409 61 : if (aPreload) {
410 5 : return mUpgradeInsecurePreloads;
411 : }
412 56 : return mUpgradeInsecureRequests;
413 : }
414 :
415 0 : void SetReferrer(const nsACString& aReferrer) {
416 0 : mReferrer = aReferrer;
417 0 : }
418 :
419 : /**
420 : * Check to see if a subresource we want to load requires HSTS priming
421 : * to be done.
422 : */
423 7 : HSTSPrimingState GetHSTSPrimingStateForLocation(nsIURI* aContentLocation) const
424 : {
425 : HSTSPrimingState state;
426 7 : if (mHSTSPrimingURIList.Get(aContentLocation, &state)) {
427 0 : return state;
428 : }
429 7 : return HSTSPrimingState::eNO_HSTS_PRIMING;
430 : }
431 :
432 : /**
433 : * Add a subresource to the HSTS priming list. If this URI is
434 : * not in the HSTS cache, it will trigger an HSTS priming request
435 : * when we try to load it.
436 : */
437 0 : void AddHSTSPrimingLocation(nsIURI* aContentLocation, HSTSPrimingState aState)
438 : {
439 0 : mHSTSPrimingURIList.Put(aContentLocation, aState);
440 0 : }
441 :
442 0 : void ClearHSTSPrimingLocation(nsIURI* aContentLocation)
443 : {
444 0 : mHSTSPrimingURIList.Remove(aContentLocation);
445 0 : }
446 :
447 : /**
448 : * Set the principal responsible for this document.
449 : */
450 : virtual void SetPrincipal(nsIPrincipal *aPrincipal) = 0;
451 :
452 : /**
453 : * Return the LoadGroup for the document. May return null.
454 : */
455 191 : already_AddRefed<nsILoadGroup> GetDocumentLoadGroup() const
456 : {
457 382 : nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
458 382 : return group.forget();
459 : }
460 :
461 : /**
462 : * Return the fallback base URL for this document, as defined in the HTML
463 : * specification. Note that this can return null if there is no document URI.
464 : *
465 : * XXXbz: This doesn't implement the bits for about:blank yet.
466 : */
467 380 : nsIURI* GetFallbackBaseURI() const
468 : {
469 380 : if (mIsSrcdocDocument && mParentDocument) {
470 0 : return mParentDocument->GetDocBaseURI();
471 : }
472 380 : return mDocumentURI;
473 : }
474 :
475 : /**
476 : * Return the base URI for relative URIs in the document (the document uri
477 : * unless it's overridden by SetBaseURI, HTML <base> tags, etc.). The
478 : * returned URI could be null if there is no document URI. If the document is
479 : * a srcdoc document and has no explicit base URL, return the parent
480 : * document's base URL.
481 : */
482 380 : nsIURI* GetDocBaseURI() const
483 : {
484 380 : if (mDocumentBaseURI) {
485 0 : return mDocumentBaseURI;
486 : }
487 380 : return GetFallbackBaseURI();
488 : }
489 : virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override;
490 :
491 : virtual void SetBaseURI(nsIURI* aURI) = 0;
492 :
493 : /**
494 : * Return the URL data which style system needs for resolving url value.
495 : * This method attempts to use the cached object in mCachedURLData, but
496 : * if the base URI, document URI, or principal has changed since last
497 : * call to this function, or the function is called the first time for
498 : * the document, a new one is created.
499 : */
500 : mozilla::URLExtraData* DefaultStyleAttrURLData();
501 :
502 : /**
503 : * Get/Set the base target of a link in a document.
504 : */
505 : virtual void GetBaseTarget(nsAString &aBaseTarget) = 0;
506 0 : void SetBaseTarget(const nsString& aBaseTarget) {
507 0 : mBaseTarget = aBaseTarget;
508 0 : }
509 :
510 : /**
511 : * Return a standard name for the document's character set.
512 : */
513 117 : NotNull<const Encoding*> GetDocumentCharacterSet() const
514 : {
515 117 : return mCharacterSet;
516 : }
517 :
518 : /**
519 : * Set the document's character encoding.
520 : */
521 : virtual void SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) = 0;
522 :
523 0 : int32_t GetDocumentCharacterSetSource() const
524 : {
525 0 : return mCharacterSetSource;
526 : }
527 :
528 : // This method MUST be called before SetDocumentCharacterSet if
529 : // you're planning to call both.
530 9 : void SetDocumentCharacterSetSource(int32_t aCharsetSource)
531 : {
532 9 : mCharacterSetSource = aCharsetSource;
533 9 : }
534 :
535 : /**
536 : * Add an observer that gets notified whenever the charset changes.
537 : */
538 : virtual nsresult AddCharSetObserver(nsIObserver* aObserver) = 0;
539 :
540 : /**
541 : * Remove a charset observer.
542 : */
543 : virtual void RemoveCharSetObserver(nsIObserver* aObserver) = 0;
544 :
545 : /**
546 : * This gets fired when the element that an id refers to changes.
547 : * This fires at difficult times. It is generally not safe to do anything
548 : * which could modify the DOM in any way. Use
549 : * nsContentUtils::AddScriptRunner.
550 : * @return true to keep the callback in the callback set, false
551 : * to remove it.
552 : */
553 : typedef bool (* IDTargetObserver)(Element* aOldElement,
554 : Element* aNewelement, void* aData);
555 :
556 : /**
557 : * Add an IDTargetObserver for a specific ID. The IDTargetObserver
558 : * will be fired whenever the content associated with the ID changes
559 : * in the future. If aForImage is true, mozSetImageElement can override
560 : * what content is associated with the ID. In that case the IDTargetObserver
561 : * will be notified at those times when the result of LookupImageElement
562 : * changes.
563 : * At most one (aObserver, aData, aForImage) triple can be
564 : * registered for each ID.
565 : * @return the content currently associated with the ID.
566 : */
567 : virtual Element* AddIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
568 : void* aData, bool aForImage) = 0;
569 : /**
570 : * Remove the (aObserver, aData, aForImage) triple for a specific ID, if
571 : * registered.
572 : */
573 : virtual void RemoveIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
574 : void* aData, bool aForImage) = 0;
575 :
576 : /**
577 : * Get the Content-Type of this document.
578 : * (This will always return NS_OK, but has this signature to be compatible
579 : * with nsIDOMDocument::GetContentType())
580 : */
581 : NS_IMETHOD GetContentType(nsAString& aContentType) = 0;
582 :
583 : /**
584 : * Set the Content-Type of this document.
585 : */
586 : virtual void SetContentType(const nsAString& aContentType) = 0;
587 :
588 : /**
589 : * Return the language of this document.
590 : */
591 128 : void GetContentLanguage(nsAString& aContentLanguage) const
592 : {
593 128 : CopyASCIItoUTF16(mContentLanguage, aContentLanguage);
594 128 : }
595 :
596 : // The states BidiEnabled and MathMLEnabled should persist across multiple views
597 : // (screen, print) of the same document.
598 :
599 : /**
600 : * Check if the document contains bidi data.
601 : * If so, we have to apply the Unicode Bidi Algorithm.
602 : */
603 387 : bool GetBidiEnabled() const
604 : {
605 387 : return mBidiEnabled;
606 : }
607 :
608 : /**
609 : * Indicate the document contains bidi data.
610 : * Currently, we cannot disable bidi, because once bidi is enabled,
611 : * it affects a frame model irreversibly, and plays even though
612 : * the document no longer contains bidi data.
613 : */
614 0 : void SetBidiEnabled()
615 : {
616 0 : mBidiEnabled = true;
617 0 : }
618 :
619 : /**
620 : * Check if the document contains (or has contained) any MathML elements.
621 : */
622 652 : bool GetMathMLEnabled() const
623 : {
624 652 : return mMathMLEnabled;
625 : }
626 :
627 0 : void SetMathMLEnabled()
628 : {
629 0 : mMathMLEnabled = true;
630 0 : }
631 :
632 : /**
633 : * Ask this document whether it's the initial document in its window.
634 : */
635 5 : bool IsInitialDocument() const
636 : {
637 5 : return mIsInitialDocumentInWindow;
638 : }
639 :
640 : /**
641 : * Tell this document that it's the initial document in its window. See
642 : * comments on mIsInitialDocumentInWindow for when this should be called.
643 : */
644 5 : void SetIsInitialDocument(bool aIsInitialDocument)
645 : {
646 5 : mIsInitialDocumentInWindow = aIsInitialDocument;
647 5 : }
648 :
649 : /**
650 : * Normally we assert if a runnable labeled with one DocGroup touches data
651 : * from another DocGroup. Calling IgnoreDocGroupMismatches() on a document
652 : * means that we can touch that document from any DocGroup without asserting.
653 : */
654 2 : void IgnoreDocGroupMismatches()
655 : {
656 2 : mIgnoreDocGroupMismatches = true;
657 2 : }
658 :
659 : /**
660 : * Get the bidi options for this document.
661 : * @see nsBidiUtils.h
662 : */
663 357 : uint32_t GetBidiOptions() const
664 : {
665 357 : return mBidiOptions;
666 : }
667 :
668 : /**
669 : * Set the bidi options for this document. This just sets the bits;
670 : * callers are expected to take action as needed if they want this
671 : * change to actually change anything immediately.
672 : * @see nsBidiUtils.h
673 : */
674 0 : void SetBidiOptions(uint32_t aBidiOptions)
675 : {
676 0 : mBidiOptions = aBidiOptions;
677 0 : }
678 :
679 : /**
680 : * Get the has mixed active content loaded flag for this document.
681 : */
682 4 : bool GetHasMixedActiveContentLoaded()
683 : {
684 4 : return mHasMixedActiveContentLoaded;
685 : }
686 :
687 : /**
688 : * Set the has mixed active content loaded flag for this document.
689 : */
690 0 : void SetHasMixedActiveContentLoaded(bool aHasMixedActiveContentLoaded)
691 : {
692 0 : mHasMixedActiveContentLoaded = aHasMixedActiveContentLoaded;
693 0 : }
694 :
695 : /**
696 : * Get mixed active content blocked flag for this document.
697 : */
698 2 : bool GetHasMixedActiveContentBlocked()
699 : {
700 2 : return mHasMixedActiveContentBlocked;
701 : }
702 :
703 : /**
704 : * Set the mixed active content blocked flag for this document.
705 : */
706 0 : void SetHasMixedActiveContentBlocked(bool aHasMixedActiveContentBlocked)
707 : {
708 0 : mHasMixedActiveContentBlocked = aHasMixedActiveContentBlocked;
709 0 : }
710 :
711 : /**
712 : * Get the has mixed display content loaded flag for this document.
713 : */
714 2 : bool GetHasMixedDisplayContentLoaded()
715 : {
716 2 : return mHasMixedDisplayContentLoaded;
717 : }
718 :
719 : /**
720 : * Set the has mixed display content loaded flag for this document.
721 : */
722 0 : void SetHasMixedDisplayContentLoaded(bool aHasMixedDisplayContentLoaded)
723 : {
724 0 : mHasMixedDisplayContentLoaded = aHasMixedDisplayContentLoaded;
725 0 : }
726 :
727 : /**
728 : * Get mixed display content blocked flag for this document.
729 : */
730 2 : bool GetHasMixedDisplayContentBlocked()
731 : {
732 2 : return mHasMixedDisplayContentBlocked;
733 : }
734 :
735 : /**
736 : * Set referrer policy CSP flag for this document.
737 : */
738 0 : void SetHasReferrerPolicyCSP(bool aHasReferrerPolicyCSP)
739 : {
740 0 : mHasReferrerPolicyCSP = aHasReferrerPolicyCSP;
741 0 : }
742 :
743 : /**
744 : * Set the mixed display content blocked flag for this document.
745 : */
746 0 : void SetHasMixedDisplayContentBlocked(bool aHasMixedDisplayContentBlocked)
747 : {
748 0 : mHasMixedDisplayContentBlocked = aHasMixedDisplayContentBlocked;
749 0 : }
750 :
751 : /**
752 : * Set the mixed content object subrequest flag for this document.
753 : */
754 0 : void SetHasMixedContentObjectSubrequest(bool aHasMixedContentObjectSubrequest)
755 : {
756 0 : mHasMixedContentObjectSubrequest = aHasMixedContentObjectSubrequest;
757 0 : }
758 :
759 : /**
760 : * Set CSP flag for this document.
761 : */
762 0 : void SetHasCSP(bool aHasCSP)
763 : {
764 0 : mHasCSP = aHasCSP;
765 0 : }
766 :
767 : /**
768 : * Set unsafe-inline CSP flag for this document.
769 : */
770 0 : void SetHasUnsafeInlineCSP(bool aHasUnsafeInlineCSP)
771 : {
772 0 : mHasUnsafeInlineCSP = aHasUnsafeInlineCSP;
773 0 : }
774 :
775 : /**
776 : * Set unsafe-eval CSP flag for this document.
777 : */
778 0 : void SetHasUnsafeEvalCSP(bool aHasUnsafeEvalCSP)
779 : {
780 0 : mHasUnsafeEvalCSP = aHasUnsafeEvalCSP;
781 0 : }
782 :
783 : /**
784 : * Get tracking content blocked flag for this document.
785 : */
786 2 : bool GetHasTrackingContentBlocked()
787 : {
788 2 : return mHasTrackingContentBlocked;
789 : }
790 :
791 : /**
792 : * Set the tracking content blocked flag for this document.
793 : */
794 0 : void SetHasTrackingContentBlocked(bool aHasTrackingContentBlocked)
795 : {
796 0 : mHasTrackingContentBlocked = aHasTrackingContentBlocked;
797 0 : }
798 :
799 : /**
800 : * Get tracking content loaded flag for this document.
801 : */
802 2 : bool GetHasTrackingContentLoaded()
803 : {
804 2 : return mHasTrackingContentLoaded;
805 : }
806 :
807 : /**
808 : * Set the tracking content loaded flag for this document.
809 : */
810 0 : void SetHasTrackingContentLoaded(bool aHasTrackingContentLoaded)
811 : {
812 0 : mHasTrackingContentLoaded = aHasTrackingContentLoaded;
813 0 : }
814 :
815 : /**
816 : * Get the sandbox flags for this document.
817 : * @see nsSandboxFlags.h for the possible flags
818 : */
819 16 : uint32_t GetSandboxFlags() const
820 : {
821 16 : return mSandboxFlags;
822 : }
823 :
824 : /**
825 : * Get string representation of sandbox flags (null if no flags are set)
826 : */
827 : void GetSandboxFlagsAsString(nsAString& aFlags);
828 :
829 : /**
830 : * Set the sandbox flags for this document.
831 : * @see nsSandboxFlags.h for the possible flags
832 : */
833 4 : void SetSandboxFlags(uint32_t sandboxFlags)
834 : {
835 4 : mSandboxFlags = sandboxFlags;
836 4 : }
837 :
838 : /**
839 : * Access HTTP header data (this may also get set from other
840 : * sources, like HTML META tags).
841 : */
842 : virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
843 : virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
844 :
845 : /**
846 : * Create a new presentation shell that will use aContext for its
847 : * presentation context (presentation contexts <b>must not</b> be
848 : * shared among multiple presentation shells). The caller of this
849 : * method is responsible for calling BeginObservingDocument() on the
850 : * presshell if the presshell should observe document mutations.
851 : */
852 : virtual already_AddRefed<nsIPresShell> CreateShell(
853 : nsPresContext* aContext,
854 : nsViewManager* aViewManager,
855 : mozilla::StyleSetHandle aStyleSet) = 0;
856 : virtual void DeleteShell() = 0;
857 :
858 3627 : nsIPresShell* GetShell() const
859 : {
860 3627 : return GetBFCacheEntry() ? nullptr : mPresShell;
861 : }
862 :
863 : // Instead using this method, what you probably want is
864 : // RemoveFromBFCacheSync() as we do in MessagePort and BroadcastChannel.
865 0 : void DisallowBFCaching()
866 : {
867 0 : NS_ASSERTION(!mBFCacheEntry, "We're already in the bfcache!");
868 0 : mBFCacheDisallowed = true;
869 0 : }
870 :
871 0 : bool IsBFCachingAllowed() const
872 : {
873 0 : return !mBFCacheDisallowed;
874 : }
875 :
876 0 : void SetBFCacheEntry(nsIBFCacheEntry* aEntry)
877 : {
878 0 : NS_ASSERTION(IsBFCachingAllowed() || !aEntry,
879 : "You should have checked!");
880 :
881 0 : mBFCacheEntry = aEntry;
882 0 : }
883 :
884 3655 : nsIBFCacheEntry* GetBFCacheEntry() const
885 : {
886 3655 : return mBFCacheEntry;
887 : }
888 :
889 : /**
890 : * Return the parent document of this document. Will return null
891 : * unless this document is within a compound document and has a
892 : * parent. Note that this parent chain may cross chrome boundaries.
893 : */
894 57 : nsIDocument *GetParentDocument() const
895 : {
896 57 : return mParentDocument;
897 : }
898 :
899 : /**
900 : * Set the parent document of this document.
901 : */
902 3 : void SetParentDocument(nsIDocument* aParent)
903 : {
904 3 : mParentDocument = aParent;
905 3 : if (aParent) {
906 2 : mIgnoreDocGroupMismatches = aParent->mIgnoreDocGroupMismatches;
907 : }
908 3 : }
909 :
910 : /**
911 : * Are plugins allowed in this document ?
912 : */
913 : virtual bool GetAllowPlugins () = 0;
914 :
915 : /**
916 : * Set the sub document for aContent to aSubDoc.
917 : */
918 : virtual nsresult SetSubDocumentFor(Element* aContent,
919 : nsIDocument* aSubDoc) = 0;
920 :
921 : /**
922 : * Get the sub document for aContent
923 : */
924 : virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
925 :
926 : /**
927 : * Find the content node for which aDocument is a sub document.
928 : */
929 : virtual Element* FindContentForSubDocument(nsIDocument* aDocument) const = 0;
930 :
931 : /**
932 : * Return the doctype for this document.
933 : */
934 : mozilla::dom::DocumentType* GetDoctype() const;
935 :
936 : /**
937 : * Return the root element for this document.
938 : */
939 : Element* GetRootElement() const;
940 :
941 : /**
942 : * Retrieve information about the viewport as a data structure.
943 : * This will return information in the viewport META data section
944 : * of the document. This can be used in lieu of ProcessViewportInfo(),
945 : * which places the viewport information in the document header instead
946 : * of returning it directly.
947 : *
948 : * @param aDisplaySize size of the on-screen display area for this
949 : * document, in device pixels.
950 : *
951 : * NOTE: If the site is optimized for mobile (via the doctype), this
952 : * will return viewport information that specifies default information.
953 : */
954 : virtual nsViewportInfo GetViewportInfo(const mozilla::ScreenIntSize& aDisplaySize) = 0;
955 :
956 : /**
957 : * True iff this doc will ignore manual character encoding overrides.
958 : */
959 0 : virtual bool WillIgnoreCharsetOverride() {
960 0 : return true;
961 : }
962 :
963 : /**
964 : * Return whether the document was created by a srcdoc iframe.
965 : */
966 0 : bool IsSrcdocDocument() const {
967 0 : return mIsSrcdocDocument;
968 : }
969 :
970 : /**
971 : * Sets whether the document was created by a srcdoc iframe.
972 : */
973 : void SetIsSrcdocDocument(bool aIsSrcdocDocument) {
974 : mIsSrcdocDocument = aIsSrcdocDocument;
975 : }
976 :
977 : /*
978 : * Gets the srcdoc string from within the channel (assuming both exist).
979 : * Returns a void string if this isn't a srcdoc document or if
980 : * the channel has not been set.
981 : */
982 : nsresult GetSrcdocData(nsAString& aSrcdocData);
983 :
984 3512 : bool DidDocumentOpen() {
985 3512 : return mDidDocumentOpen;
986 : }
987 :
988 : already_AddRefed<mozilla::dom::AnonymousContent>
989 : InsertAnonymousContent(mozilla::dom::Element& aElement,
990 : mozilla::ErrorResult& aError);
991 : void RemoveAnonymousContent(mozilla::dom::AnonymousContent& aContent,
992 : mozilla::ErrorResult& aError);
993 : /**
994 : * If aNode is a descendant of anonymous content inserted by
995 : * InsertAnonymousContent, this method returns the root element of the
996 : * inserted anonymous content (in other words, the clone of the aElement
997 : * that was passed to InsertAnonymousContent).
998 : */
999 : Element* GetAnonRootIfInAnonymousContentContainer(nsINode* aNode) const;
1000 23 : nsTArray<RefPtr<mozilla::dom::AnonymousContent>>& GetAnonymousContents() {
1001 23 : return mAnonymousContents;
1002 : }
1003 :
1004 : static nsresult GenerateDocumentId(nsAString& aId);
1005 : nsresult GetOrCreateId(nsAString& aId);
1006 : void SetId(const nsAString& aId);
1007 :
1008 0 : mozilla::TimeStamp GetPageUnloadingEventTimeStamp() const
1009 : {
1010 0 : if (!mParentDocument) {
1011 0 : return mPageUnloadingEventTimeStamp;
1012 : }
1013 :
1014 0 : mozilla::TimeStamp parentTimeStamp(mParentDocument->GetPageUnloadingEventTimeStamp());
1015 0 : if (parentTimeStamp.IsNull()) {
1016 0 : return mPageUnloadingEventTimeStamp;
1017 : }
1018 :
1019 0 : if (!mPageUnloadingEventTimeStamp ||
1020 0 : parentTimeStamp < mPageUnloadingEventTimeStamp) {
1021 0 : return parentTimeStamp;
1022 : }
1023 :
1024 0 : return mPageUnloadingEventTimeStamp;
1025 : }
1026 :
1027 : virtual void NotifyLayerManagerRecreated() = 0;
1028 :
1029 : /**
1030 : * Add an SVG element to the list of elements that need
1031 : * their mapped attributes resolved to a Servo declaration block.
1032 : *
1033 : * These are weak pointers, please manually unschedule them when an element
1034 : * is removed.
1035 : */
1036 : virtual void ScheduleSVGForPresAttrEvaluation(nsSVGElement* aSVG) = 0;
1037 : // Unschedule an element scheduled by ScheduleFrameRequestCallback (e.g. for when it is destroyed)
1038 : virtual void UnscheduleSVGForPresAttrEvaluation(nsSVGElement* aSVG) = 0;
1039 :
1040 : // Resolve all SVG pres attrs scheduled in ScheduleSVGForPresAttrEvaluation
1041 : virtual void ResolveScheduledSVGPresAttrs() = 0;
1042 :
1043 : protected:
1044 : virtual Element *GetRootElementInternal() const = 0;
1045 :
1046 13 : void SetPageUnloadingEventTimeStamp()
1047 : {
1048 13 : MOZ_ASSERT(!mPageUnloadingEventTimeStamp);
1049 13 : mPageUnloadingEventTimeStamp = mozilla::TimeStamp::NowLoRes();
1050 13 : }
1051 :
1052 13 : void CleanUnloadEventsTimeStamp()
1053 : {
1054 13 : MOZ_ASSERT(mPageUnloadingEventTimeStamp);
1055 13 : mPageUnloadingEventTimeStamp = mozilla::TimeStamp();
1056 13 : }
1057 :
1058 : private:
1059 : class SelectorCacheKey
1060 : {
1061 : public:
1062 7 : explicit SelectorCacheKey(const nsAString& aString) : mKey(aString)
1063 : {
1064 7 : MOZ_COUNT_CTOR(SelectorCacheKey);
1065 7 : }
1066 :
1067 : nsString mKey;
1068 : nsExpirationState mState;
1069 :
1070 7 : nsExpirationState* GetExpirationState() { return &mState; }
1071 :
1072 0 : ~SelectorCacheKey()
1073 0 : {
1074 0 : MOZ_COUNT_DTOR(SelectorCacheKey);
1075 0 : }
1076 : };
1077 :
1078 : class SelectorCacheKeyDeleter;
1079 :
1080 : public:
1081 : class SelectorCache final
1082 : : public nsExpirationTracker<SelectorCacheKey, 4>
1083 : {
1084 : public:
1085 : explicit SelectorCache(nsIEventTarget* aEventTarget);
1086 :
1087 : // CacheList takes ownership of aSelectorList.
1088 : void CacheList(const nsAString& aSelector, nsCSSSelectorList* aSelectorList);
1089 :
1090 : virtual void NotifyExpired(SelectorCacheKey* aSelector) override;
1091 :
1092 : // We do not call MarkUsed because it would just slow down lookups and
1093 : // because we're OK expiring things after a few seconds even if they're
1094 : // being used. Returns whether we actually had an entry for aSelector.
1095 : // If we have an entry and *aList is null, that indicates that aSelector
1096 : // has already been parsed and is not a syntactically valid selector.
1097 9 : bool GetList(const nsAString& aSelector, nsCSSSelectorList** aList)
1098 : {
1099 9 : return mTable.Get(aSelector, aList);
1100 : }
1101 :
1102 : ~SelectorCache();
1103 :
1104 : private:
1105 : nsClassHashtable<nsStringHashKey, nsCSSSelectorList> mTable;
1106 : };
1107 :
1108 9 : SelectorCache& GetSelectorCache() {
1109 9 : if (!mSelectorCache) {
1110 : mSelectorCache =
1111 4 : new SelectorCache(EventTargetFor(mozilla::TaskCategory::Other));
1112 : }
1113 9 : return *mSelectorCache;
1114 : }
1115 : // Get the root <html> element, or return null if there isn't one (e.g.
1116 : // if the root isn't <html>)
1117 : Element* GetHtmlElement() const;
1118 : // Returns the first child of GetHtmlContent which has the given tag,
1119 : // or nullptr if that doesn't exist.
1120 : Element* GetHtmlChildElement(nsIAtom* aTag);
1121 : // Get the canonical <body> element, or return null if there isn't one (e.g.
1122 : // if the root isn't <html> or if the <body> isn't there)
1123 : mozilla::dom::HTMLBodyElement* GetBodyElement();
1124 : // Get the canonical <head> element, or return null if there isn't one (e.g.
1125 : // if the root isn't <html> or if the <head> isn't there)
1126 0 : Element* GetHeadElement() {
1127 0 : return GetHtmlChildElement(nsGkAtoms::head);
1128 : }
1129 :
1130 : /**
1131 : * Accessors to the collection of stylesheets owned by this document.
1132 : * Style sheets are ordered, most significant last.
1133 : */
1134 :
1135 : /**
1136 : * These exists to allow us to on-demand load user-agent style sheets that
1137 : * would otherwise be loaded by nsDocumentViewer::CreateStyleSet. This allows
1138 : * us to keep the memory used by a document's rule cascade data (the stuff in
1139 : * its nsStyleSet's nsCSSRuleProcessors) - which can be considerable - lower
1140 : * than it would be if we loaded all built-in user-agent style sheets up
1141 : * front.
1142 : *
1143 : * By "built-in" user-agent style sheets we mean the user-agent style sheets
1144 : * that gecko itself supplies (such as html.css and svg.css) as opposed to
1145 : * user-agent level style sheets inserted by add-ons or the like.
1146 : *
1147 : * This function prepends the given style sheet to the document's style set
1148 : * in order to make sure that it does not override user-agent style sheets
1149 : * supplied by add-ons or by the app (Firefox OS or Firefox Mobile, for
1150 : * example), since their sheets should override built-in sheets.
1151 : *
1152 : * TODO We can get rid of the whole concept of delayed loading if we fix
1153 : * bug 77999.
1154 : */
1155 : virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) = 0;
1156 :
1157 : /**
1158 : * Get the number of (document) stylesheets
1159 : *
1160 : * @return the number of stylesheets
1161 : * @throws no exceptions
1162 : */
1163 : virtual int32_t GetNumberOfStyleSheets() const = 0;
1164 :
1165 : /**
1166 : * Get a particular stylesheet
1167 : * @param aIndex the index the stylesheet lives at. This is zero-based
1168 : * @return the stylesheet at aIndex. Null if aIndex is out of range.
1169 : * @throws no exceptions
1170 : */
1171 : virtual mozilla::StyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0;
1172 :
1173 : /**
1174 : * Insert a sheet at a particular spot in the stylesheet list (zero-based)
1175 : * @param aSheet the sheet to insert
1176 : * @param aIndex the index to insert at. This index will be
1177 : * adjusted for the "special" sheets.
1178 : * @throws no exceptions
1179 : */
1180 : virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
1181 : int32_t aIndex) = 0;
1182 :
1183 : /**
1184 : * Get the index of a particular stylesheet. This will _always_
1185 : * consider the "special" sheets as part of the sheet list.
1186 : * @param aSheet the sheet to get the index of
1187 : * @return aIndex the index of the sheet in the full list
1188 : */
1189 : virtual int32_t GetIndexOfStyleSheet(
1190 : const mozilla::StyleSheet* aSheet) const = 0;
1191 :
1192 : /**
1193 : * Replace the stylesheets in aOldSheets with the stylesheets in
1194 : * aNewSheets. The two lists must have equal length, and the sheet
1195 : * at positon J in the first list will be replaced by the sheet at
1196 : * position J in the second list. Some sheets in the second list
1197 : * may be null; if so the corresponding sheets in the first list
1198 : * will simply be removed.
1199 : */
1200 : virtual void UpdateStyleSheets(
1201 : nsTArray<RefPtr<mozilla::StyleSheet>>& aOldSheets,
1202 : nsTArray<RefPtr<mozilla::StyleSheet>>& aNewSheets) = 0;
1203 :
1204 : /**
1205 : * Add a stylesheet to the document
1206 : */
1207 : virtual void AddStyleSheet(mozilla::StyleSheet* aSheet) = 0;
1208 :
1209 : /**
1210 : * Remove a stylesheet from the document
1211 : */
1212 : virtual void RemoveStyleSheet(mozilla::StyleSheet* aSheet) = 0;
1213 :
1214 : /**
1215 : * Notify the document that the applicable state of the sheet changed
1216 : * and that observers should be notified and style sets updated
1217 : */
1218 : virtual void SetStyleSheetApplicableState(mozilla::StyleSheet* aSheet,
1219 : bool aApplicable) = 0;
1220 :
1221 : enum additionalSheetType {
1222 : eAgentSheet,
1223 : eUserSheet,
1224 : eAuthorSheet,
1225 : AdditionalSheetTypeCount
1226 : };
1227 :
1228 : virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType,
1229 : nsIURI* aSheetURI) = 0;
1230 : virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType,
1231 : mozilla::StyleSheet* aSheet) = 0;
1232 : virtual void RemoveAdditionalStyleSheet(additionalSheetType aType,
1233 : nsIURI* sheetURI) = 0;
1234 : virtual mozilla::StyleSheet* GetFirstAdditionalAuthorSheet() = 0;
1235 :
1236 : /**
1237 : * Assuming that aDocSheets is an array of document-level style
1238 : * sheets for this document, returns the index that aSheet should
1239 : * be inserted at to maintain document ordering.
1240 : *
1241 : * Type T has to cast to StyleSheet*.
1242 : *
1243 : * Defined in nsIDocumentInlines.h.
1244 : */
1245 : template<typename T>
1246 : size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
1247 : mozilla::StyleSheet* aSheet);
1248 :
1249 : /**
1250 : * Get this document's CSSLoader. This is guaranteed to not return null.
1251 : */
1252 346 : mozilla::css::Loader* CSSLoader() const {
1253 346 : return mCSSLoader;
1254 : }
1255 :
1256 1797 : mozilla::StyleBackendType GetStyleBackendType() const {
1257 1797 : if (mStyleBackendType == mozilla::StyleBackendType::None) {
1258 28 : const_cast<nsIDocument*>(this)->UpdateStyleBackendType();
1259 : }
1260 1797 : MOZ_ASSERT(mStyleBackendType != mozilla::StyleBackendType::None);
1261 1797 : return mStyleBackendType;
1262 : }
1263 :
1264 : /**
1265 : * Documents generally decide their style backend type themselves, and
1266 : * this is only used for XBL documents to set their style backend type to
1267 : * their bounding document's.
1268 : */
1269 26 : void SetStyleBackendType(mozilla::StyleBackendType aStyleBackendType) {
1270 : // We cannot assert mStyleBackendType == mozilla::StyleBackendType::None
1271 : // because NS_NewXBLDocument() might result GetStyleBackendType() being
1272 : // called.
1273 26 : MOZ_ASSERT(aStyleBackendType != mozilla::StyleBackendType::None,
1274 : "The StyleBackendType should be set to either Gecko or Servo!");
1275 26 : mStyleBackendType = aStyleBackendType;
1276 26 : }
1277 :
1278 : /**
1279 : * Decide this document's own style backend type.
1280 : */
1281 : void UpdateStyleBackendType();
1282 :
1283 126 : bool IsStyledByServo() const {
1284 126 : return GetStyleBackendType() == mozilla::StyleBackendType::Servo;
1285 : }
1286 :
1287 : /**
1288 : * Get this document's StyleImageLoader. This is guaranteed to not return null.
1289 : */
1290 4120 : mozilla::css::ImageLoader* StyleImageLoader() const {
1291 4120 : return mStyleImageLoader;
1292 : }
1293 :
1294 : /**
1295 : * Get the channel that was passed to StartDocumentLoad or Reset for this
1296 : * document. Note that this may be null in some cases (eg if
1297 : * StartDocumentLoad or Reset were never called)
1298 : */
1299 : virtual nsIChannel* GetChannel() const = 0;
1300 :
1301 : /**
1302 : * Get this document's attribute stylesheet. May return null if
1303 : * there isn't one.
1304 : */
1305 64 : nsHTMLStyleSheet* GetAttributeStyleSheet() const {
1306 64 : return mAttrStyleSheet;
1307 : }
1308 :
1309 : /**
1310 : * Get this document's inline style sheet. May return null if there
1311 : * isn't one
1312 : */
1313 28 : nsHTMLCSSStyleSheet* GetInlineStyleSheet() const {
1314 28 : return mStyleAttrStyleSheet;
1315 : }
1316 :
1317 : virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
1318 :
1319 : /**
1320 : * Get/set the object from which the context for the event/script handling can
1321 : * be got. Normally GetScriptHandlingObject() returns the same object as
1322 : * GetScriptGlobalObject(), but if the document is loaded as data,
1323 : * non-null may be returned, even if GetScriptGlobalObject() returns null.
1324 : * aHasHadScriptHandlingObject is set true if document has had the object
1325 : * for event/script handling. Do not process any events/script if the method
1326 : * returns null, but aHasHadScriptHandlingObject is true.
1327 : */
1328 : nsIScriptGlobalObject*
1329 1538 : GetScriptHandlingObject(bool& aHasHadScriptHandlingObject) const
1330 : {
1331 1538 : aHasHadScriptHandlingObject = mHasHadScriptHandlingObject;
1332 1626 : return mScriptGlobalObject ? mScriptGlobalObject.get() :
1333 3164 : GetScriptHandlingObjectInternal();
1334 : }
1335 : virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) = 0;
1336 :
1337 : /**
1338 : * Get the object that is used as the scope for all of the content
1339 : * wrappers whose owner document is this document. Unlike the script global
1340 : * object, this will only return null when the global object for this
1341 : * document is truly gone. Use this object when you're trying to find a
1342 : * content wrapper in XPConnect.
1343 : */
1344 : virtual nsIGlobalObject* GetScopeObject() const = 0;
1345 : virtual void SetScopeObject(nsIGlobalObject* aGlobal) = 0;
1346 :
1347 : /**
1348 : * Return the window containing the document (the outer window).
1349 : */
1350 1326 : nsPIDOMWindowOuter *GetWindow() const
1351 : {
1352 1326 : return mWindow ? mWindow->GetOuterWindow() : GetWindowInternal();
1353 : }
1354 :
1355 66 : bool IsInBackgroundWindow() const
1356 : {
1357 66 : auto* outer = mWindow ? mWindow->GetOuterWindow() : nullptr;
1358 66 : return outer && outer->IsBackground();
1359 : }
1360 :
1361 : /**
1362 : * Return the inner window used as the script compilation scope for
1363 : * this document. If you're not absolutely sure you need this, use
1364 : * GetWindow().
1365 : */
1366 1279 : nsPIDOMWindowInner* GetInnerWindow() const
1367 : {
1368 1279 : return mRemovedFromDocShell ? nullptr : mWindow;
1369 : }
1370 :
1371 : /**
1372 : * Return the outer window ID.
1373 : */
1374 3 : uint64_t OuterWindowID() const
1375 : {
1376 3 : nsPIDOMWindowOuter* window = GetWindow();
1377 3 : return window ? window->WindowID() : 0;
1378 : }
1379 :
1380 : /**
1381 : * Return the inner window ID.
1382 : */
1383 99 : uint64_t InnerWindowID() const
1384 : {
1385 99 : nsPIDOMWindowInner* window = GetInnerWindow();
1386 99 : return window ? window->WindowID() : 0;
1387 : }
1388 :
1389 : /**
1390 : * Get the script loader for this document
1391 : */
1392 : virtual mozilla::dom::ScriptLoader* ScriptLoader() = 0;
1393 :
1394 : /**
1395 : * Add/Remove an element to the document's id and name hashes
1396 : */
1397 : virtual void AddToIdTable(Element* aElement, nsIAtom* aId) = 0;
1398 : virtual void RemoveFromIdTable(Element* aElement, nsIAtom* aId) = 0;
1399 : virtual void AddToNameTable(Element* aElement, nsIAtom* aName) = 0;
1400 : virtual void RemoveFromNameTable(Element* aElement, nsIAtom* aName) = 0;
1401 :
1402 : /**
1403 : * Returns all elements in the fullscreen stack in the insertion order.
1404 : */
1405 : virtual nsTArray<Element*> GetFullscreenStack() const = 0;
1406 :
1407 : /**
1408 : * Asynchronously requests that the document make aElement the fullscreen
1409 : * element, and move into fullscreen mode. The current fullscreen element
1410 : * (if any) is pushed onto the fullscreen element stack, and it can be
1411 : * returned to fullscreen status by calling RestorePreviousFullScreenState().
1412 : *
1413 : * Note that requesting fullscreen in a document also makes the element which
1414 : * contains this document in this document's parent document fullscreen. i.e.
1415 : * the <iframe> or <browser> that contains this document is also mode
1416 : * fullscreen. This happens recursively in all ancestor documents.
1417 : */
1418 : virtual void AsyncRequestFullScreen(
1419 : mozilla::UniquePtr<FullscreenRequest>&& aRequest) = 0;
1420 :
1421 : /**
1422 : * Called when a frame in a child process has entered fullscreen or when a
1423 : * fullscreen frame in a child process changes to another origin.
1424 : * aFrameElement is the frame element which contains the child-process
1425 : * fullscreen document.
1426 : */
1427 : virtual nsresult
1428 : RemoteFrameFullscreenChanged(nsIDOMElement* aFrameElement) = 0;
1429 :
1430 : /**
1431 : * Called when a frame in a remote child document has rolled back fullscreen
1432 : * so that all its fullscreen element stacks are empty; we must continue the
1433 : * rollback in this parent process' doc tree branch which is fullscreen.
1434 : * Note that only one branch of the document tree can have its documents in
1435 : * fullscreen state at one time. We're in inconsistent state if a
1436 : * fullscreen document has a parent and that parent isn't fullscreen. We
1437 : * preserve this property across process boundaries.
1438 : */
1439 : virtual nsresult RemoteFrameFullscreenReverted() = 0;
1440 :
1441 : /**
1442 : * Restores the previous full-screen element to full-screen status. If there
1443 : * is no former full-screen element, this exits full-screen, moving the
1444 : * top-level browser window out of full-screen mode.
1445 : */
1446 : virtual void RestorePreviousFullScreenState() = 0;
1447 :
1448 : /**
1449 : * Returns true if this document is a fullscreen leaf document, i.e. it
1450 : * is in fullscreen mode and has no fullscreen children.
1451 : */
1452 : virtual bool IsFullscreenLeaf() = 0;
1453 :
1454 : /**
1455 : * Returns the document which is at the root of this document's branch
1456 : * in the in-process document tree. Returns nullptr if the document isn't
1457 : * fullscreen.
1458 : */
1459 : virtual nsIDocument* GetFullscreenRoot() = 0;
1460 :
1461 : /**
1462 : * Sets the fullscreen root to aRoot. This stores a weak reference to aRoot
1463 : * in this document.
1464 : */
1465 : virtual void SetFullscreenRoot(nsIDocument* aRoot) = 0;
1466 :
1467 : /**
1468 : * Synchronously cleans up the fullscreen state on the given document.
1469 : *
1470 : * Calling this without performing fullscreen transition could lead
1471 : * to undesired effect (the transition happens after document state
1472 : * flips), hence it should only be called either by nsGlobalWindow
1473 : * when we have performed the transition, or when it is necessary to
1474 : * clean up the state immediately. Otherwise, AsyncExitFullscreen()
1475 : * should be called instead.
1476 : *
1477 : * aDocument must not be null.
1478 : */
1479 : static void ExitFullscreenInDocTree(nsIDocument* aDocument);
1480 :
1481 : /**
1482 : * Ask the document to exit fullscreen state asynchronously.
1483 : *
1484 : * Different from ExitFullscreenInDocTree(), this allows the window
1485 : * to perform fullscreen transition first if any.
1486 : *
1487 : * If aDocument is null, it will exit fullscreen from all documents
1488 : * in all windows.
1489 : */
1490 : static void AsyncExitFullscreen(nsIDocument* aDocument);
1491 :
1492 : /**
1493 : * Handles any pending fullscreen in aDocument or its subdocuments.
1494 : *
1495 : * Returns whether there is any fullscreen request handled.
1496 : */
1497 : static bool HandlePendingFullscreenRequests(nsIDocument* aDocument);
1498 :
1499 : /**
1500 : * Dispatch fullscreenerror event and report the failure message to
1501 : * the console.
1502 : */
1503 : void DispatchFullscreenError(const char* aMessage);
1504 :
1505 : virtual void RequestPointerLock(Element* aElement,
1506 : mozilla::dom::CallerType aCallerType) = 0;
1507 :
1508 : static void UnlockPointer(nsIDocument* aDoc = nullptr);
1509 :
1510 : // ScreenOrientation related APIs
1511 :
1512 : virtual void SetCurrentOrientation(mozilla::dom::OrientationType aType,
1513 : uint16_t aAngle) = 0;
1514 : virtual uint16_t CurrentOrientationAngle() const = 0;
1515 : virtual mozilla::dom::OrientationType CurrentOrientationType() const = 0;
1516 : virtual void SetOrientationPendingPromise(mozilla::dom::Promise* aPromise) = 0;
1517 : virtual mozilla::dom::Promise* GetOrientationPendingPromise() const = 0;
1518 :
1519 : //----------------------------------------------------------------------
1520 :
1521 : // Document notification API's
1522 :
1523 : /**
1524 : * Add a new observer of document change notifications. Whenever
1525 : * content is changed, appended, inserted or removed the observers are
1526 : * informed. An observer that is already observing the document must
1527 : * not be added without being removed first.
1528 : */
1529 : virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
1530 :
1531 : /**
1532 : * Remove an observer of document change notifications. This will
1533 : * return false if the observer cannot be found.
1534 : */
1535 : virtual bool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
1536 :
1537 : // Observation hooks used to propagate notifications to document observers.
1538 : // BeginUpdate must be called before any batch of modifications of the
1539 : // content model or of style data, EndUpdate must be called afterward.
1540 : // To make this easy and painless, use the mozAutoDocUpdate helper class.
1541 : virtual void BeginUpdate(nsUpdateType aUpdateType) = 0;
1542 : virtual void EndUpdate(nsUpdateType aUpdateType) = 0;
1543 : virtual void BeginLoad() = 0;
1544 : virtual void EndLoad() = 0;
1545 :
1546 : enum ReadyState { READYSTATE_UNINITIALIZED = 0, READYSTATE_LOADING = 1, READYSTATE_INTERACTIVE = 3, READYSTATE_COMPLETE = 4};
1547 : virtual void SetReadyStateInternal(ReadyState rs) = 0;
1548 87 : ReadyState GetReadyStateEnum()
1549 : {
1550 87 : return mReadyState;
1551 : }
1552 :
1553 : // notify that a content node changed state. This must happen under
1554 : // a scriptblocker but NOT within a begin/end update.
1555 : virtual void ContentStateChanged(nsIContent* aContent,
1556 : mozilla::EventStates aStateMask) = 0;
1557 :
1558 : // Notify that a document state has changed.
1559 : // This should only be called by callers whose state is also reflected in the
1560 : // implementation of nsDocument::GetDocumentState.
1561 : virtual void DocumentStatesChanged(mozilla::EventStates aStateMask) = 0;
1562 :
1563 : // Observation hooks for style data to propagate notifications
1564 : // to document observers
1565 : virtual void StyleRuleChanged(mozilla::StyleSheet* aStyleSheet,
1566 : mozilla::css::Rule* aStyleRule) = 0;
1567 : virtual void StyleRuleAdded(mozilla::StyleSheet* aStyleSheet,
1568 : mozilla::css::Rule* aStyleRule) = 0;
1569 : virtual void StyleRuleRemoved(mozilla::StyleSheet* aStyleSheet,
1570 : mozilla::css::Rule* aStyleRule) = 0;
1571 :
1572 : /**
1573 : * Flush notifications for this document and its parent documents
1574 : * (since those may affect the layout of this one).
1575 : */
1576 : virtual void FlushPendingNotifications(mozilla::FlushType aType) = 0;
1577 :
1578 : /**
1579 : * Calls FlushPendingNotifications on any external resources this document
1580 : * has. If this document has no external resources or is an external resource
1581 : * itself this does nothing. This should only be called with
1582 : * aType >= FlushType::Style.
1583 : */
1584 : virtual void FlushExternalResources(mozilla::FlushType aType) = 0;
1585 :
1586 5773 : nsBindingManager* BindingManager() const
1587 : {
1588 5773 : return mNodeInfoManager->GetBindingManager();
1589 : }
1590 :
1591 : /**
1592 : * Only to be used inside Gecko, you can't really do anything with the
1593 : * pointer outside Gecko anyway.
1594 : */
1595 2038 : nsNodeInfoManager* NodeInfoManager() const
1596 : {
1597 2038 : return mNodeInfoManager;
1598 : }
1599 :
1600 : /**
1601 : * Reset the document using the given channel and loadgroup. This works
1602 : * like ResetToURI, but also sets the document's channel to aChannel.
1603 : * The principal of the document will be set from the channel.
1604 : */
1605 : virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0;
1606 :
1607 : /**
1608 : * Reset this document to aURI, aLoadGroup, and aPrincipal. aURI must not be
1609 : * null. If aPrincipal is null, a codebase principal based on aURI will be
1610 : * used.
1611 : */
1612 : virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup,
1613 : nsIPrincipal* aPrincipal) = 0;
1614 :
1615 : /**
1616 : * Set the container (docshell) for this document. Virtual so that
1617 : * docshell can call it.
1618 : */
1619 : virtual void SetContainer(nsDocShell* aContainer);
1620 :
1621 : /**
1622 : * Get the container (docshell) for this document.
1623 : */
1624 : virtual nsISupports* GetContainer() const;
1625 :
1626 : /**
1627 : * Get the container's load context for this document.
1628 : */
1629 : nsILoadContext* GetLoadContext() const;
1630 :
1631 : /**
1632 : * Get docshell the for this document.
1633 : */
1634 : nsIDocShell* GetDocShell() const;
1635 :
1636 : /**
1637 : * Set and get XML declaration. If aVersion is null there is no declaration.
1638 : * aStandalone takes values -1, 0 and 1 indicating respectively that there
1639 : * was no standalone parameter in the declaration, that it was given as no,
1640 : * or that it was given as yes.
1641 : */
1642 : virtual void SetXMLDeclaration(const char16_t *aVersion,
1643 : const char16_t *aEncoding,
1644 : const int32_t aStandalone) = 0;
1645 : virtual void GetXMLDeclaration(nsAString& aVersion,
1646 : nsAString& aEncoding,
1647 : nsAString& Standalone) = 0;
1648 :
1649 : /**
1650 : * Returns true if this is what HTML 5 calls an "HTML document" (for example
1651 : * regular HTML document with Content-Type "text/html", image documents and
1652 : * media documents). Returns false for XHTML and any other documents parsed
1653 : * by the XML parser.
1654 : */
1655 2799 : bool IsHTMLDocument() const
1656 : {
1657 2799 : return mType == eHTML;
1658 : }
1659 127 : bool IsHTMLOrXHTML() const
1660 : {
1661 127 : return mType == eHTML || mType == eXHTML;
1662 : }
1663 : bool IsXMLDocument() const
1664 : {
1665 : return !IsHTMLDocument();
1666 : }
1667 60 : bool IsSVGDocument() const
1668 : {
1669 60 : return mType == eSVG;
1670 : }
1671 2294 : bool IsXULDocument() const
1672 : {
1673 2294 : return mType == eXUL;
1674 : }
1675 30 : bool IsUnstyledDocument()
1676 : {
1677 30 : return IsLoadedAsData() || IsLoadedAsInteractiveData();
1678 : }
1679 2258 : bool LoadsFullXULStyleSheetUpFront()
1680 : {
1681 2258 : return IsXULDocument() || AllowXULXBL();
1682 : }
1683 :
1684 : virtual bool IsScriptEnabled() = 0;
1685 :
1686 27 : bool IsTopLevelContentDocument() const { return mIsTopLevelContentDocument; }
1687 3 : void SetIsTopLevelContentDocument(bool aIsTopLevelContentDocument)
1688 : {
1689 3 : mIsTopLevelContentDocument = aIsTopLevelContentDocument;
1690 3 : }
1691 :
1692 27 : bool IsContentDocument() const { return mIsContentDocument; }
1693 3 : void SetIsContentDocument(bool aIsContentDocument)
1694 : {
1695 3 : mIsContentDocument = aIsContentDocument;
1696 3 : }
1697 :
1698 : /**
1699 : * Create an element with the specified name, prefix and namespace ID.
1700 : * Returns null if element name parsing failed.
1701 : */
1702 : virtual already_AddRefed<Element> CreateElem(const nsAString& aName,
1703 : nsIAtom* aPrefix,
1704 : int32_t aNamespaceID,
1705 : const nsAString* aIs = nullptr) = 0;
1706 :
1707 : /**
1708 : * Get the security info (i.e. SSL state etc) that the document got
1709 : * from the channel/document that created the content of the
1710 : * document.
1711 : *
1712 : * @see nsIChannel
1713 : */
1714 0 : nsISupports *GetSecurityInfo()
1715 : {
1716 0 : return mSecurityInfo;
1717 : }
1718 :
1719 : /**
1720 : * Get the channel that failed to load and resulted in an error page, if it
1721 : * exists. This is only relevant to error pages.
1722 : */
1723 : virtual nsIChannel* GetFailedChannel() const = 0;
1724 :
1725 : /**
1726 : * Set the channel that failed to load and resulted in an error page.
1727 : * This is only relevant to error pages.
1728 : */
1729 : virtual void SetFailedChannel(nsIChannel* aChannel) = 0;
1730 :
1731 : /**
1732 : * Returns the default namespace ID used for elements created in this
1733 : * document.
1734 : */
1735 192 : int32_t GetDefaultNamespaceID() const
1736 : {
1737 192 : return mDefaultElementType;
1738 : }
1739 :
1740 : void DeleteAllProperties();
1741 : void DeleteAllPropertiesFor(nsINode* aNode);
1742 :
1743 5350 : nsPropertyTable* PropertyTable(uint16_t aCategory) {
1744 5350 : if (aCategory == 0)
1745 5349 : return &mPropertyTable;
1746 1 : return GetExtraPropertyTable(aCategory);
1747 : }
1748 0 : uint32_t GetPropertyTableCount()
1749 0 : { return mExtraPropertyTables.Length() + 1; }
1750 :
1751 : /**
1752 : * Sets the ID used to identify this part of the multipart document
1753 : */
1754 0 : void SetPartID(uint32_t aID) {
1755 0 : mPartID = aID;
1756 0 : }
1757 :
1758 : /**
1759 : * Return the ID used to identify this part of the multipart document
1760 : */
1761 10 : uint32_t GetPartID() const {
1762 10 : return mPartID;
1763 : }
1764 :
1765 : /**
1766 : * Sanitize the document by resetting all input elements and forms that have
1767 : * autocomplete=off to their default values.
1768 : */
1769 : virtual void Sanitize() = 0;
1770 :
1771 : /**
1772 : * Enumerate all subdocuments.
1773 : * The enumerator callback should return true to continue enumerating, or
1774 : * false to stop. This will never get passed a null aDocument.
1775 : */
1776 : typedef bool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
1777 : virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
1778 : void *aData) = 0;
1779 :
1780 : /**
1781 : * Check whether it is safe to cache the presentation of this document
1782 : * and all of its subdocuments. This method checks the following conditions
1783 : * recursively:
1784 : * - Some document types, such as plugin documents, cannot be safely cached.
1785 : * - If there are any pending requests, we don't allow the presentation
1786 : * to be cached. Ideally these requests would be suspended and resumed,
1787 : * but that is difficult in some cases, such as XMLHttpRequest.
1788 : * - If there are any beforeunload or unload listeners, we must fire them
1789 : * for correctness, but this likely puts the document into a state where
1790 : * it would not function correctly if restored.
1791 : *
1792 : * |aNewRequest| should be the request for a new document which will
1793 : * replace this document in the docshell. The new document's request
1794 : * will be ignored when checking for active requests. If there is no
1795 : * request associated with the new document, this parameter may be null.
1796 : */
1797 : virtual bool CanSavePresentation(nsIRequest *aNewRequest) = 0;
1798 :
1799 : /**
1800 : * Notify the document that its associated ContentViewer is being destroyed.
1801 : * This releases circular references so that the document can go away.
1802 : * Destroy() is only called on documents that have a content viewer.
1803 : */
1804 : virtual void Destroy() = 0;
1805 :
1806 : /**
1807 : * Notify the document that its associated ContentViewer is no longer
1808 : * the current viewer for the docshell. The document might still
1809 : * be rendered in "zombie state" until the next document is ready.
1810 : * The document should save form control state.
1811 : */
1812 : virtual void RemovedFromDocShell() = 0;
1813 :
1814 : /**
1815 : * Get the layout history state that should be used to save and restore state
1816 : * for nodes in this document. This may return null; if that happens state
1817 : * saving and restoration is not possible.
1818 : */
1819 : virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const = 0;
1820 :
1821 : /**
1822 : * Methods that can be used to prevent onload firing while an event that
1823 : * should block onload is posted. onload is guaranteed to not fire until
1824 : * either all calls to BlockOnload() have been matched by calls to
1825 : * UnblockOnload() or the load has been stopped altogether (by the user
1826 : * pressing the Stop button, say).
1827 : */
1828 : virtual void BlockOnload() = 0;
1829 : /**
1830 : * @param aFireSync whether to fire onload synchronously. If false,
1831 : * onload will fire asynchronously after all onload blocks have been
1832 : * removed. It will NOT fire from inside UnblockOnload. If true,
1833 : * onload may fire from inside UnblockOnload.
1834 : */
1835 : virtual void UnblockOnload(bool aFireSync) = 0;
1836 :
1837 25 : void BlockDOMContentLoaded()
1838 : {
1839 25 : ++mBlockDOMContentLoaded;
1840 25 : }
1841 :
1842 : virtual void UnblockDOMContentLoaded() = 0;
1843 :
1844 : /**
1845 : * Notification that the page has been shown, for documents which are loaded
1846 : * into a DOM window. This corresponds to the completion of document load,
1847 : * or to the page's presentation being restored into an existing DOM window.
1848 : * This notification fires applicable DOM events to the content window. See
1849 : * PageTransitionEvent.webidl for a description of the |aPersisted|
1850 : * parameter. If aDispatchStartTarget is null, the pageshow event is
1851 : * dispatched on the ScriptGlobalObject for this document, otherwise it's
1852 : * dispatched on aDispatchStartTarget.
1853 : * Note: if aDispatchStartTarget isn't null, the showing state of the
1854 : * document won't be altered.
1855 : */
1856 : virtual void OnPageShow(bool aPersisted,
1857 : mozilla::dom::EventTarget* aDispatchStartTarget) = 0;
1858 :
1859 : /**
1860 : * Notification that the page has been hidden, for documents which are loaded
1861 : * into a DOM window. This corresponds to the unloading of the document, or
1862 : * to the document's presentation being saved but removed from an existing
1863 : * DOM window. This notification fires applicable DOM events to the content
1864 : * window. See PageTransitionEvent.webidl for a description of the
1865 : * |aPersisted| parameter. If aDispatchStartTarget is null, the pagehide
1866 : * event is dispatched on the ScriptGlobalObject for this document,
1867 : * otherwise it's dispatched on aDispatchStartTarget.
1868 : * Note: if aDispatchStartTarget isn't null, the showing state of the
1869 : * document won't be altered.
1870 : */
1871 : virtual void OnPageHide(bool aPersisted,
1872 : mozilla::dom::EventTarget* aDispatchStartTarget) = 0;
1873 :
1874 : /*
1875 : * We record the set of links in the document that are relevant to
1876 : * style.
1877 : */
1878 : /**
1879 : * Notification that an element is a link that is relevant to style.
1880 : */
1881 : virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) = 0;
1882 : /**
1883 : * Notification that an element is a link and its URI might have been
1884 : * changed or the element removed. If the element is still a link relevant
1885 : * to style, then someone must ensure that AddStyleRelevantLink is
1886 : * (eventually) called on it again.
1887 : */
1888 : virtual void ForgetLink(mozilla::dom::Link* aLink) = 0;
1889 :
1890 : /**
1891 : * Resets and removes a box object from the document's box object cache
1892 : *
1893 : * @param aElement canonical nsIContent pointer of the box object's element
1894 : */
1895 : virtual void ClearBoxObjectFor(nsIContent *aContent) = 0;
1896 :
1897 : /**
1898 : * Get the box object for an element. This is not exposed through a
1899 : * scriptable interface except for XUL documents.
1900 : */
1901 : virtual already_AddRefed<mozilla::dom::BoxObject>
1902 : GetBoxObjectFor(mozilla::dom::Element* aElement,
1903 : mozilla::ErrorResult& aRv) = 0;
1904 :
1905 : /**
1906 : * Support for window.matchMedia()
1907 : */
1908 :
1909 : already_AddRefed<mozilla::dom::MediaQueryList>
1910 : MatchMedia(const nsAString& aMediaQueryList);
1911 :
1912 24 : mozilla::LinkedList<mozilla::dom::MediaQueryList>& MediaQueryLists() {
1913 24 : return mDOMMediaQueryLists;
1914 : }
1915 :
1916 : /**
1917 : * Get the compatibility mode for this document
1918 : */
1919 2788 : nsCompatibility GetCompatibilityMode() const {
1920 2788 : return mCompatMode;
1921 : }
1922 :
1923 : /**
1924 : * Check whether we've ever fired a DOMTitleChanged event for this
1925 : * document.
1926 : */
1927 25 : bool HaveFiredDOMTitleChange() const {
1928 25 : return mHaveFiredTitleChange;
1929 : }
1930 :
1931 : /**
1932 : * See GetAnonymousElementByAttribute on nsIDOMDocumentXBL.
1933 : */
1934 : virtual Element*
1935 : GetAnonymousElementByAttribute(nsIContent* aElement,
1936 : nsIAtom* aAttrName,
1937 : const nsAString& aAttrValue) const = 0;
1938 :
1939 : /**
1940 : * Helper for nsIDOMDocument::elementFromPoint implementation that allows
1941 : * ignoring the scroll frame and/or avoiding layout flushes.
1942 : *
1943 : * @see nsIDOMWindowUtils::elementFromPoint
1944 : */
1945 : virtual Element* ElementFromPointHelper(float aX, float aY,
1946 : bool aIgnoreRootScrollFrame,
1947 : bool aFlushLayout) = 0;
1948 :
1949 : enum ElementsFromPointFlags {
1950 : IGNORE_ROOT_SCROLL_FRAME = 1,
1951 : FLUSH_LAYOUT = 2,
1952 : IS_ELEMENT_FROM_POINT = 4
1953 : };
1954 :
1955 : virtual void ElementsFromPointHelper(float aX, float aY,
1956 : uint32_t aFlags,
1957 : nsTArray<RefPtr<mozilla::dom::Element>>& aElements) = 0;
1958 :
1959 : virtual nsresult NodesFromRectHelper(float aX, float aY,
1960 : float aTopSize, float aRightSize,
1961 : float aBottomSize, float aLeftSize,
1962 : bool aIgnoreRootScrollFrame,
1963 : bool aFlushLayout,
1964 : nsIDOMNodeList** aReturn) = 0;
1965 :
1966 : /**
1967 : * See FlushSkinBindings on nsBindingManager
1968 : */
1969 : virtual void FlushSkinBindings() = 0;
1970 :
1971 : /**
1972 : * To batch DOMSubtreeModified, document needs to be informed when
1973 : * a mutation event might be dispatched, even if the event isn't actually
1974 : * created because there are no listeners for it.
1975 : *
1976 : * @param aTarget is the target for the mutation event.
1977 : */
1978 88 : void MayDispatchMutationEvent(nsINode* aTarget)
1979 : {
1980 88 : if (mSubtreeModifiedDepth > 0) {
1981 0 : mSubtreeModifiedTargets.AppendObject(aTarget);
1982 : }
1983 88 : }
1984 :
1985 : /**
1986 : * Marks as not-going-to-be-collected for the given generation of
1987 : * cycle collection.
1988 : */
1989 0 : void MarkUncollectableForCCGeneration(uint32_t aGeneration)
1990 : {
1991 0 : mMarkedCCGeneration = aGeneration;
1992 0 : }
1993 :
1994 : /**
1995 : * Gets the cycle collector generation this document is marked for.
1996 : */
1997 1 : uint32_t GetMarkedCCGeneration()
1998 : {
1999 1 : return mMarkedCCGeneration;
2000 : }
2001 :
2002 1222 : bool IsLoadedAsData()
2003 : {
2004 1222 : return mLoadedAsData;
2005 : }
2006 :
2007 1735 : bool IsLoadedAsInteractiveData()
2008 : {
2009 1735 : return mLoadedAsInteractiveData;
2010 : }
2011 :
2012 0 : bool MayStartLayout()
2013 : {
2014 0 : return mMayStartLayout;
2015 : }
2016 :
2017 25 : virtual void SetMayStartLayout(bool aMayStartLayout)
2018 : {
2019 25 : mMayStartLayout = aMayStartLayout;
2020 25 : }
2021 :
2022 : already_AddRefed<nsIDocumentEncoder> GetCachedEncoder();
2023 :
2024 : void SetCachedEncoder(already_AddRefed<nsIDocumentEncoder> aEncoder);
2025 :
2026 : // In case of failure, the document really can't initialize the frame loader.
2027 : virtual nsresult InitializeFrameLoader(nsFrameLoader* aLoader) = 0;
2028 : // In case of failure, the caller must handle the error, for example by
2029 : // finalizing frame loader asynchronously.
2030 : virtual nsresult FinalizeFrameLoader(nsFrameLoader* aLoader, nsIRunnable* aFinalizer) = 0;
2031 : // Removes the frame loader of aShell from the initialization list.
2032 : virtual void TryCancelFrameLoaderInitialization(nsIDocShell* aShell) = 0;
2033 :
2034 : /**
2035 : * Check whether this document is a root document that is not an
2036 : * external resource.
2037 : */
2038 45 : bool IsRootDisplayDocument() const
2039 : {
2040 45 : return !mParentDocument && !mDisplayDocument;
2041 : }
2042 :
2043 2451 : bool IsBeingUsedAsImage() const {
2044 2451 : return mIsBeingUsedAsImage;
2045 : }
2046 :
2047 21 : void SetIsBeingUsedAsImage() {
2048 21 : mIsBeingUsedAsImage = true;
2049 21 : }
2050 :
2051 1163 : bool IsResourceDoc() const {
2052 1717 : return IsBeingUsedAsImage() || // Are we a helper-doc for an SVG image?
2053 1717 : mHasDisplayDocument; // Are we an external resource doc?
2054 : }
2055 :
2056 : /**
2057 : * Get the document for which this document is an external resource. This
2058 : * will be null if this document is not an external resource. Otherwise,
2059 : * GetDisplayDocument() will return a non-null document, and
2060 : * GetDisplayDocument()->GetDisplayDocument() is guaranteed to be null.
2061 : */
2062 1202 : nsIDocument* GetDisplayDocument() const
2063 : {
2064 1202 : return mDisplayDocument;
2065 : }
2066 :
2067 : /**
2068 : * Set the display document for this document. aDisplayDocument must not be
2069 : * null.
2070 : */
2071 0 : void SetDisplayDocument(nsIDocument* aDisplayDocument)
2072 : {
2073 0 : MOZ_ASSERT(!GetShell() &&
2074 : !GetContainer() &&
2075 : !GetWindow(),
2076 : "Shouldn't set mDisplayDocument on documents that already "
2077 : "have a presentation or a docshell or a window");
2078 0 : MOZ_ASSERT(aDisplayDocument, "Must not be null");
2079 0 : MOZ_ASSERT(aDisplayDocument != this, "Should be different document");
2080 0 : MOZ_ASSERT(!aDisplayDocument->GetDisplayDocument(),
2081 : "Display documents should not nest");
2082 0 : mDisplayDocument = aDisplayDocument;
2083 0 : mHasDisplayDocument = !!aDisplayDocument;
2084 0 : }
2085 :
2086 : /**
2087 : * A class that represents an external resource load that has begun but
2088 : * doesn't have a document yet. Observers can be registered on this object,
2089 : * and will be notified after the document is created. Observers registered
2090 : * after the document has been created will NOT be notified. When observers
2091 : * are notified, the subject will be the newly-created document, the topic
2092 : * will be "external-resource-document-created", and the data will be null.
2093 : * If document creation fails for some reason, observers will still be
2094 : * notified, with a null document pointer.
2095 : */
2096 0 : class ExternalResourceLoad : public nsISupports
2097 : {
2098 : public:
2099 0 : virtual ~ExternalResourceLoad() {}
2100 :
2101 0 : void AddObserver(nsIObserver* aObserver) {
2102 0 : MOZ_ASSERT(aObserver, "Must have observer");
2103 0 : mObservers.AppendElement(aObserver);
2104 0 : }
2105 :
2106 0 : const nsTArray< nsCOMPtr<nsIObserver> > & Observers() {
2107 0 : return mObservers;
2108 : }
2109 : protected:
2110 : AutoTArray< nsCOMPtr<nsIObserver>, 8 > mObservers;
2111 : };
2112 :
2113 : /**
2114 : * Request an external resource document for aURI. This will return the
2115 : * resource document if available. If one is not available yet, it will
2116 : * start loading as needed, and the pending load object will be returned in
2117 : * aPendingLoad so that the caller can register an observer to wait for the
2118 : * load. If this function returns null and doesn't return a pending load,
2119 : * that means that there is no resource document for this URI and won't be
2120 : * one in the future.
2121 : *
2122 : * @param aURI the URI to get
2123 : * @param aRequestingNode the node making the request
2124 : * @param aPendingLoad the pending load for this request, if any
2125 : */
2126 : virtual nsIDocument*
2127 : RequestExternalResource(nsIURI* aURI,
2128 : nsINode* aRequestingNode,
2129 : ExternalResourceLoad** aPendingLoad) = 0;
2130 :
2131 : /**
2132 : * Enumerate the external resource documents associated with this document.
2133 : * The enumerator callback should return true to continue enumerating, or
2134 : * false to stop. This callback will never get passed a null aDocument.
2135 : */
2136 : virtual void EnumerateExternalResources(nsSubDocEnumFunc aCallback,
2137 : void* aData) = 0;
2138 :
2139 : /**
2140 : * Return whether the document is currently showing (in the sense of
2141 : * OnPageShow() having been called already and OnPageHide() not having been
2142 : * called yet.
2143 : */
2144 0 : bool IsShowing() const { return mIsShowing; }
2145 : /**
2146 : * Return whether the document is currently visible (in the sense of
2147 : * OnPageHide having been called and OnPageShow not yet having been called)
2148 : */
2149 29 : bool IsVisible() const { return mVisible; }
2150 :
2151 : /**
2152 : * Return whether the document and all its ancestors are visible in the sense of
2153 : * pageshow / hide.
2154 : */
2155 : bool IsVisibleConsideringAncestors() const;
2156 :
2157 : /**
2158 : * Return true when this document is active, i.e., an active document
2159 : * in a content viewer. Note that this will return true for bfcached
2160 : * documents, so this does NOT match the "active document" concept in
2161 : * the WHATWG spec - see IsCurrentActiveDocument.
2162 : */
2163 9 : bool IsActive() const { return mDocumentContainer && !mRemovedFromDocShell; }
2164 :
2165 : /**
2166 : * Return true if this is the current active document for its
2167 : * docshell. Note that a docshell may have multiple active documents
2168 : * due to the bfcache -- this should be used when you need to
2169 : * differentiate the *current* active document from any active
2170 : * documents.
2171 : */
2172 6 : bool IsCurrentActiveDocument() const
2173 : {
2174 6 : nsPIDOMWindowInner* inner = GetInnerWindow();
2175 6 : return inner && inner->IsCurrentInnerWindow() && inner->GetDoc() == this;
2176 : }
2177 :
2178 : /**
2179 : * Register/Unregister the ActivityObserver into mActivityObservers to listen
2180 : * the document's activity changes such as OnPageHide, visibility, activity.
2181 : * The ActivityObserver objects can be nsIObjectLoadingContent or
2182 : * nsIDocumentActivity or HTMLMEdiaElement.
2183 : */
2184 : void RegisterActivityObserver(nsISupports* aSupports);
2185 : bool UnregisterActivityObserver(nsISupports* aSupports);
2186 : // Enumerate all the observers in mActivityObservers by the aEnumerator.
2187 : typedef void (* ActivityObserverEnumerator)(nsISupports*, void*);
2188 : void EnumerateActivityObservers(ActivityObserverEnumerator aEnumerator,
2189 : void* aData);
2190 :
2191 : // Indicates whether mAnimationController has been (lazily) initialized.
2192 : // If this returns true, we're promising that GetAnimationController()
2193 : // will have a non-null return value.
2194 337 : bool HasAnimationController() { return !!mAnimationController; }
2195 :
2196 : // Getter for this document's SMIL Animation Controller. Performs lazy
2197 : // initialization, if this document supports animation and if
2198 : // mAnimationController isn't yet initialized.
2199 : virtual nsSMILAnimationController* GetAnimationController() = 0;
2200 :
2201 : // Gets the tracker for animations that are waiting to start.
2202 : // Returns nullptr if there is no pending animation tracker for this document
2203 : // which will be the case if there have never been any CSS animations or
2204 : // transitions on elements in the document.
2205 : virtual mozilla::PendingAnimationTracker* GetPendingAnimationTracker() = 0;
2206 :
2207 : // Gets the tracker for animations that are waiting to start and
2208 : // creates it if it doesn't already exist. As a result, the return value
2209 : // will never be nullptr.
2210 : virtual mozilla::PendingAnimationTracker*
2211 : GetOrCreatePendingAnimationTracker() = 0;
2212 :
2213 : /**
2214 : * Prevents user initiated events from being dispatched to the document and
2215 : * subdocuments.
2216 : */
2217 : virtual void SuppressEventHandling(uint32_t aIncrease = 1) = 0;
2218 :
2219 : /**
2220 : * Unsuppress event handling.
2221 : * @param aFireEvents If true, delayed events (focus/blur) will be fired
2222 : * asynchronously.
2223 : */
2224 : virtual void UnsuppressEventHandlingAndFireEvents(bool aFireEvents) = 0;
2225 :
2226 61 : uint32_t EventHandlingSuppressed() const { return mEventsSuppressed; }
2227 :
2228 35 : bool IsEventHandlingEnabled() {
2229 35 : return !EventHandlingSuppressed() && mScriptGlobalObject;
2230 : }
2231 :
2232 : /**
2233 : * Increment the number of external scripts being evaluated.
2234 : */
2235 4 : void BeginEvaluatingExternalScript() { ++mExternalScriptsBeingEvaluated; }
2236 :
2237 : /**
2238 : * Decrement the number of external scripts being evaluated.
2239 : */
2240 4 : void EndEvaluatingExternalScript() { --mExternalScriptsBeingEvaluated; }
2241 :
2242 0 : bool IsDNSPrefetchAllowed() const { return mAllowDNSPrefetch; }
2243 :
2244 : /**
2245 : * Returns true if this document is allowed to contain XUL element and
2246 : * use non-builtin XBL bindings.
2247 : */
2248 1793 : bool AllowXULXBL() {
2249 1848 : return mAllowXULXBL == eTriTrue ? true :
2250 80 : mAllowXULXBL == eTriFalse ? false :
2251 1818 : InternalAllowXULXBL();
2252 : }
2253 :
2254 0 : void ForceEnableXULXBL() {
2255 0 : mAllowXULXBL = eTriTrue;
2256 0 : }
2257 :
2258 : /**
2259 : * Returns the template content owner document that owns the content of
2260 : * HTMLTemplateElement.
2261 : */
2262 : virtual nsIDocument* GetTemplateContentsOwner() = 0;
2263 :
2264 : /**
2265 : * Returns true if this document is a static clone of a normal document.
2266 : *
2267 : * We create static clones for print preview and printing (possibly other
2268 : * things in future).
2269 : *
2270 : * Note that static documents are also "loaded as data" (if this method
2271 : * returns true, IsLoadedAsData() will also return true).
2272 : */
2273 663 : bool IsStaticDocument() { return mIsStaticDocument; }
2274 :
2275 : /**
2276 : * Clones the document along with any subdocuments, stylesheet, etc.
2277 : *
2278 : * The resulting document and everything it contains (including any
2279 : * sub-documents) are created purely via cloning. The returned documents and
2280 : * any sub-documents are "loaded as data" documents to preserve the state as
2281 : * it was during the clone process (we don't want external resources to load
2282 : * and replace the cloned resources).
2283 : *
2284 : * @param aCloneContainer The container for the clone document.
2285 : */
2286 : virtual already_AddRefed<nsIDocument>
2287 : CreateStaticClone(nsIDocShell* aCloneContainer);
2288 :
2289 : /**
2290 : * If this document is a static clone, this returns the original
2291 : * document.
2292 : */
2293 40 : nsIDocument* GetOriginalDocument()
2294 : {
2295 40 : MOZ_ASSERT(!mOriginalDocument || !mOriginalDocument->GetOriginalDocument());
2296 40 : return mOriginalDocument;
2297 : }
2298 :
2299 : /**
2300 : * If this document is a static clone, let the original document know that
2301 : * we're going away and then release our reference to it.
2302 : */
2303 : void UnlinkOriginalDocumentIfStatic();
2304 :
2305 : /**
2306 : * These are called by the parser as it encounters <picture> tags, the end of
2307 : * said tags, and possible picture <source srcset> sources respectively. These
2308 : * are used to inform ResolvePreLoadImage() calls. Unset attributes are
2309 : * expected to be marked void.
2310 : *
2311 : * NOTE that the parser does not attempt to track the current picture nesting
2312 : * level or whether the given <source> tag is within a picture -- it is only
2313 : * guaranteed to order these calls properly with respect to
2314 : * ResolvePreLoadImage.
2315 : */
2316 :
2317 : virtual void PreloadPictureOpened() = 0;
2318 :
2319 : virtual void PreloadPictureClosed() = 0;
2320 :
2321 : virtual void PreloadPictureImageSource(const nsAString& aSrcsetAttr,
2322 : const nsAString& aSizesAttr,
2323 : const nsAString& aTypeAttr,
2324 : const nsAString& aMediaAttr) = 0;
2325 :
2326 : /**
2327 : * Called by the parser to resolve an image for preloading. The parser will
2328 : * call the PreloadPicture* functions to inform us of possible <picture>
2329 : * nesting and possible sources, which are used to inform URL selection
2330 : * responsive <picture> or <img srcset> images. Unset attributes are expected
2331 : * to be marked void.
2332 : */
2333 : virtual already_AddRefed<nsIURI>
2334 : ResolvePreloadImage(nsIURI *aBaseURI,
2335 : const nsAString& aSrcAttr,
2336 : const nsAString& aSrcsetAttr,
2337 : const nsAString& aSizesAttr) = 0;
2338 : /**
2339 : * Called by nsParser to preload images. Can be removed and code moved
2340 : * to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
2341 : * parser-module is linked with gklayout-module. aCrossOriginAttr should
2342 : * be a void string if the attr is not present.
2343 : */
2344 : virtual void MaybePreLoadImage(nsIURI* uri,
2345 : const nsAString& aCrossOriginAttr,
2346 : ReferrerPolicyEnum aReferrerPolicy) = 0;
2347 :
2348 : /**
2349 : * Called by images to forget an image preload when they start doing
2350 : * the real load.
2351 : */
2352 : virtual void ForgetImagePreload(nsIURI* aURI) = 0;
2353 :
2354 : /**
2355 : * Called by nsParser to preload style sheets. Can also be merged into the
2356 : * parser if and when the parser is merged with libgklayout. aCrossOriginAttr
2357 : * should be a void string if the attr is not present.
2358 : */
2359 : virtual void PreloadStyle(nsIURI* aURI, const nsAString& aCharset,
2360 : const nsAString& aCrossOriginAttr,
2361 : ReferrerPolicyEnum aReferrerPolicy,
2362 : const nsAString& aIntegrity) = 0;
2363 :
2364 : /**
2365 : * Called by the chrome registry to load style sheets. Can be put
2366 : * back there if and when when that module is merged with libgklayout.
2367 : *
2368 : * This always does a synchronous load. If aIsAgentSheet is true,
2369 : * it also uses the system principal and enables unsafe rules.
2370 : * DO NOT USE FOR UNTRUSTED CONTENT.
2371 : */
2372 : virtual nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet,
2373 : RefPtr<mozilla::StyleSheet>* aSheet) = 0;
2374 :
2375 : /**
2376 : * Returns true if the locale used for the document specifies a direction of
2377 : * right to left. For chrome documents, this comes from the chrome registry.
2378 : * This is used to determine the current state for the :-moz-locale-dir pseudoclass
2379 : * so once can know whether a document is expected to be rendered left-to-right
2380 : * or right-to-left.
2381 : */
2382 0 : virtual bool IsDocumentRightToLeft() { return false; }
2383 :
2384 : /**
2385 : * Called by Parser for link rel=preconnect
2386 : */
2387 : virtual void MaybePreconnect(nsIURI* uri,
2388 : mozilla::CORSMode aCORSMode) = 0;
2389 :
2390 : enum DocumentTheme {
2391 : Doc_Theme_Uninitialized, // not determined yet
2392 : Doc_Theme_None,
2393 : Doc_Theme_Neutral,
2394 : Doc_Theme_Dark,
2395 : Doc_Theme_Bright
2396 : };
2397 :
2398 : /**
2399 : * Set the document's pending state object (as serialized using structured
2400 : * clone).
2401 : */
2402 : void SetStateObject(nsIStructuredCloneContainer *scContainer);
2403 :
2404 : /**
2405 : * Returns Doc_Theme_None if there is no lightweight theme specified,
2406 : * Doc_Theme_Dark for a dark theme, Doc_Theme_Bright for a light theme, and
2407 : * Doc_Theme_Neutral for any other theme. This is used to determine the state
2408 : * of the pseudoclasses :-moz-lwtheme and :-moz-lwtheme-text.
2409 : */
2410 0 : virtual DocumentTheme GetDocumentLWTheme() { return Doc_Theme_None; }
2411 0 : virtual DocumentTheme ThreadSafeGetDocumentLWTheme() const { return Doc_Theme_None; }
2412 :
2413 : /**
2414 : * Returns the document state.
2415 : * Document state bits have the form NS_DOCUMENT_STATE_* and are declared in
2416 : * nsIDocument.h.
2417 : */
2418 : virtual mozilla::EventStates GetDocumentState() = 0;
2419 : virtual mozilla::EventStates ThreadSafeGetDocumentState() const = 0;
2420 :
2421 : virtual nsISupports* GetCurrentContentSink() = 0;
2422 :
2423 : virtual void SetScrollToRef(nsIURI *aDocumentURI) = 0;
2424 : virtual void ScrollToRef() = 0;
2425 : virtual void ResetScrolledToRefAlready() = 0;
2426 : virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) = 0;
2427 :
2428 : /**
2429 : * This method is similar to GetElementById() from nsIDOMDocument but it
2430 : * returns a mozilla::dom::Element instead of a nsIDOMElement.
2431 : * It prevents converting nsIDOMElement to mozilla::dom::Element which is
2432 : * already converted from mozilla::dom::Element.
2433 : */
2434 : virtual Element* GetElementById(const nsAString& aElementId) = 0;
2435 :
2436 : /**
2437 : * This method returns _all_ the elements in this document which
2438 : * have id aElementId, if there are any. Otherwise it returns null.
2439 : */
2440 : virtual const nsTArray<Element*>* GetAllElementsForId(const nsAString& aElementId) const = 0;
2441 :
2442 : /**
2443 : * Lookup an image element using its associated ID, which is usually provided
2444 : * by |-moz-element()|. Similar to GetElementById, with the difference that
2445 : * elements set using mozSetImageElement have higher priority.
2446 : * @param aId the ID associated the element we want to lookup
2447 : * @return the element associated with |aId|
2448 : */
2449 : virtual Element* LookupImageElement(const nsAString& aElementId) = 0;
2450 :
2451 : virtual mozilla::dom::DocumentTimeline* Timeline() = 0;
2452 : virtual mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines() = 0;
2453 :
2454 : virtual void GetAnimations(
2455 : nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations) = 0;
2456 :
2457 : mozilla::dom::SVGSVGElement* GetSVGRootElement() const;
2458 :
2459 : nsresult ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback,
2460 : int32_t *aHandle);
2461 : void CancelFrameRequestCallback(int32_t aHandle);
2462 :
2463 : typedef nsTArray<RefPtr<mozilla::dom::FrameRequestCallback>> FrameRequestCallbackList;
2464 : /**
2465 : * Put this document's frame request callbacks into the provided
2466 : * list, and forget about them.
2467 : */
2468 : void TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks);
2469 :
2470 : /**
2471 : * @return true if this document's frame request callbacks should be
2472 : * throttled. We throttle requestAnimationFrame for documents which aren't
2473 : * visible (e.g. scrolled out of the viewport).
2474 : */
2475 : bool ShouldThrottleFrameRequests();
2476 :
2477 : // This returns true when the document tree is being teared down.
2478 0 : bool InUnlinkOrDeletion() { return mInUnlinkOrDeletion; }
2479 :
2480 : mozilla::dom::ImageTracker* ImageTracker();
2481 :
2482 : virtual nsresult AddPlugin(nsIObjectLoadingContent* aPlugin) = 0;
2483 : virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) = 0;
2484 : virtual void GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins) = 0;
2485 :
2486 : virtual nsresult AddResponsiveContent(nsIContent* aContent) = 0;
2487 : virtual void RemoveResponsiveContent(nsIContent* aContent) = 0;
2488 : virtual void NotifyMediaFeatureValuesChanged() = 0;
2489 :
2490 : virtual nsresult GetStateObject(nsIVariant** aResult) = 0;
2491 :
2492 : virtual nsDOMNavigationTiming* GetNavigationTiming() const = 0;
2493 :
2494 : virtual nsresult SetNavigationTiming(nsDOMNavigationTiming* aTiming) = 0;
2495 :
2496 : virtual Element* FindImageMap(const nsAString& aNormalizedMapName) = 0;
2497 :
2498 : // Add aLink to the set of links that need their status resolved.
2499 : void RegisterPendingLinkUpdate(mozilla::dom::Link* aLink);
2500 :
2501 : // Update state on links in mLinksToUpdate. This function must be called
2502 : // prior to selector matching that needs to differentiate between :link and
2503 : // :visited. In particular, it does _not_ need to be called before doing any
2504 : // selector matching that uses TreeMatchContext::eNeverMatchVisited. The only
2505 : // reason we haven't moved all calls to this function entirely inside the
2506 : // TreeMatchContext constructor is to not call it all the time during various
2507 : // style system and frame construction operations (though it would likely be a
2508 : // no-op for all but the first call).
2509 : //
2510 : // XXXbz Does this really need to be called before selector matching? All it
2511 : // will do is ensure all the links involved are registered to observe history,
2512 : // which won't synchronously change their state to :visited anyway! So
2513 : // calling this won't affect selector matching done immediately afterward, as
2514 : // far as I can tell.
2515 : void FlushPendingLinkUpdates();
2516 :
2517 : void FlushPendingLinkUpdatesFromRunnable();
2518 :
2519 : #define DEPRECATED_OPERATION(_op) e##_op,
2520 : enum DeprecatedOperations {
2521 : #include "nsDeprecatedOperationList.h"
2522 : eDeprecatedOperationCount
2523 : };
2524 : #undef DEPRECATED_OPERATION
2525 : bool HasWarnedAbout(DeprecatedOperations aOperation) const;
2526 : void WarnOnceAbout(DeprecatedOperations aOperation,
2527 : bool asError = false) const;
2528 :
2529 : #define DOCUMENT_WARNING(_op) e##_op,
2530 : enum DocumentWarnings {
2531 : #include "nsDocumentWarningList.h"
2532 : eDocumentWarningCount
2533 : };
2534 : #undef DOCUMENT_WARNING
2535 : bool HasWarnedAbout(DocumentWarnings aWarning) const;
2536 : void WarnOnceAbout(DocumentWarnings aWarning,
2537 : bool asError = false,
2538 : const char16_t **aParams = nullptr,
2539 : uint32_t aParamsLength = 0) const;
2540 :
2541 : virtual void PostVisibilityUpdateEvent() = 0;
2542 :
2543 27 : bool IsSyntheticDocument() const { return mIsSyntheticDocument; }
2544 :
2545 : // Note: nsIDocument is a sub-class of nsINode, which has a
2546 : // SizeOfExcludingThis function. However, because nsIDocument objects can
2547 : // only appear at the top of the DOM tree, we have a specialized measurement
2548 : // function which returns multiple sizes.
2549 : virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
2550 : // DocAddSizeOfIncludingThis doesn't need to be overridden by sub-classes
2551 : // because nsIDocument inherits from nsINode; see the comment above the
2552 : // declaration of nsINode::SizeOfIncludingThis.
2553 : virtual void DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const;
2554 :
2555 1718 : bool MayHaveDOMMutationObservers()
2556 : {
2557 1718 : return mMayHaveDOMMutationObservers;
2558 : }
2559 :
2560 1 : void SetMayHaveDOMMutationObservers()
2561 : {
2562 1 : mMayHaveDOMMutationObservers = true;
2563 1 : }
2564 :
2565 6 : bool MayHaveAnimationObservers()
2566 : {
2567 6 : return mMayHaveAnimationObservers;
2568 : }
2569 :
2570 0 : void SetMayHaveAnimationObservers()
2571 : {
2572 0 : mMayHaveAnimationObservers = true;
2573 0 : }
2574 :
2575 0 : bool IsInSyncOperation()
2576 : {
2577 0 : return mInSyncOperationCount != 0;
2578 : }
2579 :
2580 0 : void SetIsInSyncOperation(bool aSync)
2581 : {
2582 0 : if (aSync) {
2583 0 : ++mInSyncOperationCount;
2584 : } else {
2585 0 : --mInSyncOperationCount;
2586 : }
2587 0 : }
2588 :
2589 : bool CreatingStaticClone() const
2590 : {
2591 : return mCreatingStaticClone;
2592 : }
2593 :
2594 : /**
2595 : * Creates a new element in the HTML namespace with a local name given by
2596 : * aTag.
2597 : */
2598 : already_AddRefed<Element> CreateHTMLElement(nsIAtom* aTag);
2599 :
2600 : // WebIDL API
2601 30 : nsIGlobalObject* GetParentObject() const
2602 : {
2603 30 : return GetScopeObject();
2604 : }
2605 : static already_AddRefed<nsIDocument>
2606 : Constructor(const GlobalObject& aGlobal,
2607 : mozilla::ErrorResult& rv);
2608 : virtual mozilla::dom::DOMImplementation*
2609 : GetImplementation(mozilla::ErrorResult& rv) = 0;
2610 : MOZ_MUST_USE nsresult GetURL(nsString& retval) const;
2611 : MOZ_MUST_USE nsresult GetDocumentURI(nsString& retval) const;
2612 : // Return the URI for the document.
2613 : // The returned value may differ if the document is loaded via XHR, and
2614 : // when accessed from chrome privileged script and
2615 : // from content privileged script for compatibility.
2616 : void GetDocumentURIFromJS(nsString& aDocumentURI,
2617 : mozilla::dom::CallerType aCallerType,
2618 : mozilla::ErrorResult& aRv) const;
2619 : void GetCompatMode(nsString& retval) const;
2620 : void GetCharacterSet(nsAString& retval) const;
2621 : // Skip GetContentType, because our NS_IMETHOD version above works fine here.
2622 : // GetDoctype defined above
2623 89 : Element* GetDocumentElement() const
2624 : {
2625 89 : return GetRootElement();
2626 : }
2627 :
2628 : enum ElementCallbackType {
2629 : eCreated,
2630 : eAttached,
2631 : eDetached,
2632 : eAttributeChanged
2633 : };
2634 :
2635 : nsIDocument* GetTopLevelContentDocument();
2636 :
2637 : virtual void
2638 : RegisterElement(JSContext* aCx, const nsAString& aName,
2639 : const mozilla::dom::ElementRegistrationOptions& aOptions,
2640 : JS::MutableHandle<JSObject*> aRetval,
2641 : mozilla::ErrorResult& rv) = 0;
2642 : virtual already_AddRefed<mozilla::dom::CustomElementRegistry>
2643 : GetCustomElementRegistry() = 0;
2644 :
2645 : already_AddRefed<nsContentList>
2646 0 : GetElementsByTagName(const nsAString& aTagName)
2647 : {
2648 0 : return NS_GetContentList(this, kNameSpaceID_Unknown, aTagName);
2649 : }
2650 : already_AddRefed<nsContentList>
2651 : GetElementsByTagNameNS(const nsAString& aNamespaceURI,
2652 : const nsAString& aLocalName,
2653 : mozilla::ErrorResult& aResult);
2654 : already_AddRefed<nsContentList>
2655 : GetElementsByClassName(const nsAString& aClasses);
2656 : // GetElementById defined above
2657 : virtual already_AddRefed<Element>
2658 : CreateElement(const nsAString& aTagName,
2659 : const mozilla::dom::ElementCreationOptionsOrString& aOptions,
2660 : mozilla::ErrorResult& rv) = 0;
2661 : virtual already_AddRefed<Element>
2662 : CreateElementNS(const nsAString& aNamespaceURI,
2663 : const nsAString& aQualifiedName,
2664 : const mozilla::dom::ElementCreationOptionsOrString& aOptions,
2665 : mozilla::ErrorResult& rv) = 0;
2666 : already_AddRefed<mozilla::dom::DocumentFragment>
2667 : CreateDocumentFragment() const;
2668 : already_AddRefed<nsTextNode> CreateTextNode(const nsAString& aData) const;
2669 : already_AddRefed<mozilla::dom::Comment>
2670 : CreateComment(const nsAString& aData) const;
2671 : already_AddRefed<mozilla::dom::ProcessingInstruction>
2672 : CreateProcessingInstruction(const nsAString& target, const nsAString& data,
2673 : mozilla::ErrorResult& rv) const;
2674 : already_AddRefed<nsINode>
2675 : ImportNode(nsINode& aNode, bool aDeep, mozilla::ErrorResult& rv) const;
2676 : nsINode* AdoptNode(nsINode& aNode, mozilla::ErrorResult& rv);
2677 : already_AddRefed<mozilla::dom::Event>
2678 : CreateEvent(const nsAString& aEventType,
2679 : mozilla::dom::CallerType aCallerType,
2680 : mozilla::ErrorResult& rv) const;
2681 : already_AddRefed<nsRange> CreateRange(mozilla::ErrorResult& rv);
2682 : already_AddRefed<mozilla::dom::NodeIterator>
2683 : CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
2684 : mozilla::dom::NodeFilter* aFilter,
2685 : mozilla::ErrorResult& rv) const;
2686 : already_AddRefed<mozilla::dom::NodeIterator>
2687 : CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
2688 : mozilla::dom::NodeFilterHolder aFilter,
2689 : mozilla::ErrorResult& rv) const;
2690 : already_AddRefed<mozilla::dom::TreeWalker>
2691 : CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
2692 : mozilla::dom::NodeFilter* aFilter, mozilla::ErrorResult& rv) const;
2693 : already_AddRefed<mozilla::dom::TreeWalker>
2694 : CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
2695 : mozilla::dom::NodeFilterHolder aFilter,
2696 : mozilla::ErrorResult& rv) const;
2697 :
2698 : // Deprecated WebIDL bits
2699 : already_AddRefed<mozilla::dom::CDATASection>
2700 : CreateCDATASection(const nsAString& aData, mozilla::ErrorResult& rv);
2701 : already_AddRefed<mozilla::dom::Attr>
2702 : CreateAttribute(const nsAString& aName, mozilla::ErrorResult& rv);
2703 : already_AddRefed<mozilla::dom::Attr>
2704 : CreateAttributeNS(const nsAString& aNamespaceURI,
2705 : const nsAString& aQualifiedName,
2706 : mozilla::ErrorResult& rv);
2707 : void GetInputEncoding(nsAString& aInputEncoding) const;
2708 : already_AddRefed<mozilla::dom::Location> GetLocation() const;
2709 : void GetReferrer(nsAString& aReferrer) const;
2710 : void GetLastModified(nsAString& aLastModified) const;
2711 : void GetReadyState(nsAString& aReadyState) const;
2712 : // Not const because otherwise the compiler can't figure out whether to call
2713 : // this GetTitle or the nsAString version from non-const methods, since
2714 : // neither is an exact match.
2715 : virtual void GetTitle(nsString& aTitle) = 0;
2716 : virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) = 0;
2717 : void GetDir(nsAString& aDirection) const;
2718 : void SetDir(const nsAString& aDirection);
2719 17 : nsPIDOMWindowOuter* GetDefaultView() const
2720 : {
2721 17 : return GetWindow();
2722 : }
2723 : Element* GetActiveElement();
2724 : bool HasFocus(mozilla::ErrorResult& rv) const;
2725 : mozilla::TimeStamp LastFocusTime() const;
2726 : void SetLastFocusTime(const mozilla::TimeStamp& aFocusTime);
2727 : // Event handlers are all on nsINode already
2728 3 : bool MozSyntheticDocument() const
2729 : {
2730 3 : return IsSyntheticDocument();
2731 : }
2732 : Element* GetCurrentScript();
2733 : void ReleaseCapture() const;
2734 : virtual void MozSetImageElement(const nsAString& aImageElementId,
2735 : Element* aElement) = 0;
2736 : nsIURI* GetDocumentURIObject() const;
2737 : // Not const because all the full-screen goop is not const
2738 : virtual bool FullscreenEnabled(mozilla::dom::CallerType aCallerType) = 0;
2739 : virtual Element* GetFullscreenElement() = 0;
2740 1 : bool Fullscreen()
2741 : {
2742 1 : return !!GetFullscreenElement();
2743 : }
2744 : void ExitFullscreen();
2745 : Element* GetPointerLockElement();
2746 4 : void ExitPointerLock()
2747 : {
2748 4 : UnlockPointer(this);
2749 4 : }
2750 : #ifdef MOZILLA_INTERNAL_API
2751 8 : bool Hidden() const
2752 : {
2753 8 : return mVisibilityState != mozilla::dom::VisibilityState::Visible;
2754 : }
2755 0 : mozilla::dom::VisibilityState VisibilityState() const
2756 : {
2757 0 : return mVisibilityState;
2758 : }
2759 : #endif
2760 : virtual mozilla::dom::StyleSheetList* StyleSheets() = 0;
2761 : void GetSelectedStyleSheetSet(nsAString& aSheetSet);
2762 : virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) = 0;
2763 : virtual void GetLastStyleSheetSet(nsString& aSheetSet) = 0;
2764 : void GetPreferredStyleSheetSet(nsAString& aSheetSet);
2765 : virtual mozilla::dom::DOMStringList* StyleSheetSets() = 0;
2766 : virtual void EnableStyleSheetsForSet(const nsAString& aSheetSet) = 0;
2767 : Element* ElementFromPoint(float aX, float aY);
2768 : void ElementsFromPoint(float aX,
2769 : float aY,
2770 : nsTArray<RefPtr<mozilla::dom::Element>>& aElements);
2771 :
2772 : /**
2773 : * Retrieve the location of the caret position (DOM node and character
2774 : * offset within that node), given a point.
2775 : *
2776 : * @param aX Horizontal point at which to determine the caret position, in
2777 : * page coordinates.
2778 : * @param aY Vertical point at which to determine the caret position, in
2779 : * page coordinates.
2780 : */
2781 : already_AddRefed<nsDOMCaretPosition>
2782 : CaretPositionFromPoint(float aX, float aY);
2783 :
2784 : Element* GetScrollingElement();
2785 : // A way to check whether a given element is what would get returned from
2786 : // GetScrollingElement. It can be faster than comparing to the return value
2787 : // of GetScrollingElement() due to being able to avoid flushes in various
2788 : // cases. This method assumes that null is NOT passed.
2789 : bool IsScrollingElement(Element* aElement);
2790 :
2791 : // QuerySelector and QuerySelectorAll already defined on nsINode
2792 : nsINodeList* GetAnonymousNodes(Element& aElement);
2793 : Element* GetAnonymousElementByAttribute(Element& aElement,
2794 : const nsAString& aAttrName,
2795 : const nsAString& aAttrValue);
2796 : Element* GetBindingParent(nsINode& aNode);
2797 : void LoadBindingDocument(const nsAString& aURI,
2798 : nsIPrincipal& aSubjectPrincipal,
2799 : mozilla::ErrorResult& rv);
2800 : void LoadBindingDocument(const nsAString& aURI,
2801 : const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal,
2802 : mozilla::ErrorResult& rv);
2803 : mozilla::dom::XPathExpression*
2804 : CreateExpression(const nsAString& aExpression,
2805 : mozilla::dom::XPathNSResolver* aResolver,
2806 : mozilla::ErrorResult& rv);
2807 : nsINode* CreateNSResolver(nsINode& aNodeResolver);
2808 : already_AddRefed<mozilla::dom::XPathResult>
2809 : Evaluate(JSContext* aCx, const nsAString& aExpression, nsINode& aContextNode,
2810 : mozilla::dom::XPathNSResolver* aResolver, uint16_t aType,
2811 : JS::Handle<JSObject*> aResult, mozilla::ErrorResult& rv);
2812 : // Touch event handlers already on nsINode
2813 : already_AddRefed<mozilla::dom::Touch>
2814 : CreateTouch(nsGlobalWindow* aView, mozilla::dom::EventTarget* aTarget,
2815 : int32_t aIdentifier, int32_t aPageX, int32_t aPageY,
2816 : int32_t aScreenX, int32_t aScreenY, int32_t aClientX,
2817 : int32_t aClientY, int32_t aRadiusX, int32_t aRadiusY,
2818 : float aRotationAngle, float aForce);
2819 : already_AddRefed<mozilla::dom::TouchList> CreateTouchList();
2820 : already_AddRefed<mozilla::dom::TouchList>
2821 : CreateTouchList(mozilla::dom::Touch& aTouch,
2822 : const mozilla::dom::Sequence<mozilla::OwningNonNull<mozilla::dom::Touch> >& aTouches);
2823 : already_AddRefed<mozilla::dom::TouchList>
2824 : CreateTouchList(const mozilla::dom::Sequence<mozilla::OwningNonNull<mozilla::dom::Touch> >& aTouches);
2825 :
2826 0 : void SetStyleSheetChangeEventsEnabled(bool aValue)
2827 : {
2828 0 : mStyleSheetChangeEventsEnabled = aValue;
2829 0 : }
2830 :
2831 59 : bool StyleSheetChangeEventsEnabled() const
2832 : {
2833 59 : return mStyleSheetChangeEventsEnabled;
2834 : }
2835 :
2836 : void ObsoleteSheet(nsIURI *aSheetURI, mozilla::ErrorResult& rv);
2837 :
2838 : void ObsoleteSheet(const nsAString& aSheetURI, mozilla::ErrorResult& rv);
2839 :
2840 : already_AddRefed<mozilla::dom::Promise> BlockParsing(mozilla::dom::Promise& aPromise,
2841 : mozilla::ErrorResult& aRv);
2842 :
2843 : already_AddRefed<nsIURI> GetMozDocumentURIIfNotForErrorPages();
2844 :
2845 : // ParentNode
2846 : nsIHTMLCollection* Children();
2847 : uint32_t ChildElementCount();
2848 :
2849 1 : virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; }
2850 0 : virtual mozilla::dom::SVGDocument* AsSVGDocument() { return nullptr; }
2851 :
2852 : /*
2853 : * Given a node, get a weak reference to it and append that reference to
2854 : * mBlockedTrackingNodes. Can be used later on to look up a node in it.
2855 : * (e.g., by the UI)
2856 : */
2857 0 : void AddBlockedTrackingNode(nsINode *node)
2858 : {
2859 0 : if (!node) {
2860 0 : return;
2861 : }
2862 :
2863 0 : nsWeakPtr weakNode = do_GetWeakReference(node);
2864 :
2865 0 : if (weakNode) {
2866 0 : mBlockedTrackingNodes.AppendElement(weakNode);
2867 : }
2868 : }
2869 :
2870 : gfxUserFontSet* GetUserFontSet(bool aFlushUserFontSet = true);
2871 : void FlushUserFontSet();
2872 : void RebuildUserFontSet(); // asynchronously
2873 41 : mozilla::dom::FontFaceSet* GetFonts() { return mFontFaceSet; }
2874 :
2875 : // FontFaceSource
2876 : mozilla::dom::FontFaceSet* Fonts();
2877 :
2878 0 : bool DidFireDOMContentLoaded() const { return mDidFireDOMContentLoaded; }
2879 :
2880 115 : void SetDocumentUseCounter(mozilla::UseCounter aUseCounter)
2881 : {
2882 115 : if (!mUseCounters[aUseCounter]) {
2883 26 : mUseCounters[aUseCounter] = true;
2884 : }
2885 115 : }
2886 :
2887 : void SetPageUseCounter(mozilla::UseCounter aUseCounter);
2888 :
2889 115 : void SetDocumentAndPageUseCounter(mozilla::UseCounter aUseCounter)
2890 : {
2891 115 : SetDocumentUseCounter(aUseCounter);
2892 115 : SetPageUseCounter(aUseCounter);
2893 115 : }
2894 :
2895 : void PropagateUseCounters(nsIDocument* aParentDocument);
2896 :
2897 5 : void SetDocumentIncCounter(mozilla::IncCounter aIncCounter, uint32_t inc = 1)
2898 : {
2899 5 : mIncCounters[aIncCounter] += inc;
2900 5 : }
2901 :
2902 0 : void SetUserHasInteracted(bool aUserHasInteracted)
2903 : {
2904 0 : mUserHasInteracted = aUserHasInteracted;
2905 0 : }
2906 :
2907 5 : bool UserHasInteracted()
2908 : {
2909 5 : return mUserHasInteracted;
2910 : }
2911 :
2912 : bool HasScriptsBlockedBySandbox();
2913 :
2914 : bool InlineScriptAllowedByCSP();
2915 :
2916 : void ReportHasScrollLinkedEffect();
2917 0 : bool HasScrollLinkedEffect() const
2918 : {
2919 0 : return mHasScrollLinkedEffect;
2920 : }
2921 :
2922 : mozilla::dom::DocGroup* GetDocGroup() const;
2923 :
2924 : virtual void AddIntersectionObserver(
2925 : mozilla::dom::DOMIntersectionObserver* aObserver) = 0;
2926 : virtual void RemoveIntersectionObserver(
2927 : mozilla::dom::DOMIntersectionObserver* aObserver) = 0;
2928 :
2929 : virtual void UpdateIntersectionObservations() = 0;
2930 : virtual void ScheduleIntersectionObserverNotification() = 0;
2931 : virtual void NotifyIntersectionObservers() = 0;
2932 :
2933 : // Dispatch a runnable related to the document.
2934 : virtual nsresult Dispatch(const char* aName,
2935 : mozilla::TaskCategory aCategory,
2936 : already_AddRefed<nsIRunnable>&& aRunnable) override;
2937 :
2938 : virtual nsISerialEventTarget*
2939 : EventTargetFor(mozilla::TaskCategory aCategory) const override;
2940 :
2941 : virtual mozilla::AbstractThread*
2942 : AbstractMainThreadFor(mozilla::TaskCategory aCategory) override;
2943 :
2944 : // The URLs passed to these functions should match what
2945 : // JS::DescribeScriptedCaller() returns, since these APIs are used to
2946 : // determine whether some code is being called from a tracking script.
2947 : void NoteScriptTrackingStatus(const nsACString& aURL, bool isTracking);
2948 : bool IsScriptTracking(const nsACString& aURL) const;
2949 :
2950 : bool PrerenderHref(nsIURI* aHref);
2951 :
2952 : // For more information on Flash classification, see
2953 : // toolkit/components/url-classifier/flash-block-lists.rst
2954 : virtual mozilla::dom::FlashClassification DocumentFlashClassification() = 0;
2955 : virtual bool IsThirdParty() = 0;
2956 :
2957 : bool IsScopedStyleEnabled();
2958 :
2959 : protected:
2960 0 : bool GetUseCounter(mozilla::UseCounter aUseCounter)
2961 : {
2962 0 : return mUseCounters[aUseCounter];
2963 : }
2964 :
2965 0 : void SetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
2966 : {
2967 0 : if (!mChildDocumentUseCounters[aUseCounter]) {
2968 0 : mChildDocumentUseCounters[aUseCounter] = true;
2969 : }
2970 0 : }
2971 :
2972 0 : bool GetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
2973 : {
2974 0 : return mChildDocumentUseCounters[aUseCounter];
2975 : }
2976 :
2977 : private:
2978 : mutable std::bitset<eDeprecatedOperationCount> mDeprecationWarnedAbout;
2979 : mutable std::bitset<eDocumentWarningCount> mDocWarningWarnedAbout;
2980 : // Lazy-initialization to have mDocGroup initialized in prior to mSelectorCache.
2981 : nsAutoPtr<SelectorCache> mSelectorCache;
2982 :
2983 : protected:
2984 : ~nsIDocument();
2985 : nsPropertyTable* GetExtraPropertyTable(uint16_t aCategory);
2986 :
2987 : // Never ever call this. Only call GetWindow!
2988 : virtual nsPIDOMWindowOuter* GetWindowInternal() const = 0;
2989 :
2990 : // Never ever call this. Only call GetScriptHandlingObject!
2991 : virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const = 0;
2992 :
2993 : // Never ever call this. Only call AllowXULXBL!
2994 : virtual bool InternalAllowXULXBL() = 0;
2995 :
2996 : /**
2997 : * These methods should be called before and after dispatching
2998 : * a mutation event.
2999 : * To make this easy and painless, use the mozAutoSubtreeModified helper class.
3000 : */
3001 : virtual void WillDispatchMutationEvent(nsINode* aTarget) = 0;
3002 : virtual void MutationEventDispatched(nsINode* aTarget) = 0;
3003 : friend class mozAutoSubtreeModified;
3004 :
3005 0 : virtual Element* GetNameSpaceElement() override
3006 : {
3007 0 : return GetRootElement();
3008 : }
3009 :
3010 : void SetContentTypeInternal(const nsACString& aType);
3011 :
3012 9 : nsCString GetContentTypeInternal() const
3013 : {
3014 9 : return mContentType;
3015 : }
3016 :
3017 : mozilla::dom::XPathEvaluator* XPathEvaluator();
3018 :
3019 6 : void HandleRebuildUserFontSet() {
3020 6 : mPostedFlushUserFontSet = false;
3021 6 : FlushUserFontSet();
3022 6 : }
3023 :
3024 4 : const nsString& GetId() const
3025 : {
3026 4 : return mId;
3027 : }
3028 :
3029 : // Update our frame request callback scheduling state, if needed. This will
3030 : // schedule or unschedule them, if necessary, and update
3031 : // mFrameRequestCallbacksScheduled. aOldShell should only be passed when
3032 : // mPresShell is becoming null; in that case it will be used to get hold of
3033 : // the relevant refresh driver.
3034 : void UpdateFrameRequestCallbackSchedulingState(nsIPresShell* aOldShell = nullptr);
3035 :
3036 : // Helper for GetScrollingElement/IsScrollingElement.
3037 : bool IsPotentiallyScrollable(mozilla::dom::HTMLBodyElement* aBody);
3038 :
3039 : nsCString mReferrer;
3040 : nsString mLastModified;
3041 :
3042 : nsCOMPtr<nsIURI> mDocumentURI;
3043 : nsCOMPtr<nsIURI> mOriginalURI;
3044 : nsCOMPtr<nsIURI> mChromeXHRDocURI;
3045 : nsCOMPtr<nsIURI> mDocumentBaseURI;
3046 : nsCOMPtr<nsIURI> mChromeXHRDocBaseURI;
3047 :
3048 : #ifdef MOZ_STYLO
3049 : // A lazily-constructed URL data for style system to resolve URL value.
3050 : RefPtr<mozilla::URLExtraData> mCachedURLData;
3051 : #endif
3052 :
3053 : nsWeakPtr mDocumentLoadGroup;
3054 :
3055 : bool mReferrerPolicySet;
3056 : ReferrerPolicyEnum mReferrerPolicy;
3057 :
3058 : bool mBlockAllMixedContent;
3059 : bool mBlockAllMixedContentPreloads;
3060 : bool mUpgradeInsecureRequests;
3061 : bool mUpgradeInsecurePreloads;
3062 :
3063 : // if nsMixedContentBlocker requires sending an HSTS priming request,
3064 : // temporarily store that in the document so that it can be propogated to the
3065 : // LoadInfo and eventually the HTTP Channel
3066 : nsDataHashtable<nsURIHashKey, HSTSPrimingState> mHSTSPrimingURIList;
3067 :
3068 : mozilla::WeakPtr<nsDocShell> mDocumentContainer;
3069 :
3070 : NotNull<const Encoding*> mCharacterSet;
3071 : int32_t mCharacterSetSource;
3072 :
3073 : // This is just a weak pointer; the parent document owns its children.
3074 : nsIDocument* mParentDocument;
3075 :
3076 : // A reference to the element last returned from GetRootElement().
3077 : mozilla::dom::Element* mCachedRootElement;
3078 :
3079 : // This is a weak reference, but we hold a strong reference to mNodeInfo,
3080 : // which in turn holds a strong reference to this mNodeInfoManager.
3081 : nsNodeInfoManager* mNodeInfoManager;
3082 : RefPtr<mozilla::css::Loader> mCSSLoader;
3083 : RefPtr<mozilla::css::ImageLoader> mStyleImageLoader;
3084 : RefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
3085 : RefPtr<nsHTMLCSSStyleSheet> mStyleAttrStyleSheet;
3086 :
3087 : // Tracking for images in the document.
3088 : RefPtr<mozilla::dom::ImageTracker> mImageTracker;
3089 :
3090 : // The set of all object, embed, applet, video/audio elements or
3091 : // nsIObjectLoadingContent or nsIDocumentActivity for which this is the
3092 : // owner document. (They might not be in the document.)
3093 : // These are non-owning pointers, the elements are responsible for removing
3094 : // themselves when they go away.
3095 : nsAutoPtr<nsTHashtable<nsPtrHashKey<nsISupports> > > mActivityObservers;
3096 :
3097 : // The array of all links that need their status resolved. Links must add themselves
3098 : // to this set by calling RegisterPendingLinkUpdate when added to a document.
3099 : static const size_t kSegmentSize = 128;
3100 : mozilla::SegmentedVector<nsCOMPtr<mozilla::dom::Link>,
3101 : kSegmentSize,
3102 : InfallibleAllocPolicy>
3103 : mLinksToUpdate;
3104 :
3105 : // SMIL Animation Controller, lazily-initialized in GetAnimationController
3106 : RefPtr<nsSMILAnimationController> mAnimationController;
3107 :
3108 : // Table of element properties for this document.
3109 : nsPropertyTable mPropertyTable;
3110 : nsTArray<nsAutoPtr<nsPropertyTable> > mExtraPropertyTables;
3111 :
3112 : // Our cached .children collection
3113 : nsCOMPtr<nsIHTMLCollection> mChildrenCollection;
3114 :
3115 : // container for per-context fonts (downloadable, SVG, etc.)
3116 : RefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
3117 :
3118 : // Last time this document or a one of its sub-documents was focused. If
3119 : // focus has never occurred then mLastFocusTime.IsNull() will be true.
3120 : mozilla::TimeStamp mLastFocusTime;
3121 :
3122 : // True if BIDI is enabled.
3123 : bool mBidiEnabled : 1;
3124 : // True if a MathML element has ever been owned by this document.
3125 : bool mMathMLEnabled : 1;
3126 :
3127 : // True if this document is the initial document for a window. This should
3128 : // basically be true only for documents that exist in newly-opened windows or
3129 : // documents created to satisfy a GetDocument() on a window when there's no
3130 : // document in it.
3131 : bool mIsInitialDocumentInWindow : 1;
3132 :
3133 : bool mIgnoreDocGroupMismatches : 1;
3134 :
3135 : // True if we're loaded as data and therefor has any dangerous stuff, such
3136 : // as scripts and plugins, disabled.
3137 : bool mLoadedAsData : 1;
3138 :
3139 : // This flag is only set in XMLDocument, for e.g. documents used in XBL. We
3140 : // don't want animations to play in such documents, so we need to store the
3141 : // flag here so that we can check it in nsDocument::GetAnimationController.
3142 : bool mLoadedAsInteractiveData : 1;
3143 :
3144 : // If true, whoever is creating the document has gotten it to the
3145 : // point where it's safe to start layout on it.
3146 : bool mMayStartLayout : 1;
3147 :
3148 : // True iff we've ever fired a DOMTitleChanged event for this document
3149 : bool mHaveFiredTitleChange : 1;
3150 :
3151 : // State for IsShowing(). mIsShowing starts off false. It becomes true when
3152 : // OnPageShow happens and becomes false when OnPageHide happens. So it's false
3153 : // before the initial load completes and when we're in bfcache or unloaded,
3154 : // true otherwise.
3155 : bool mIsShowing : 1;
3156 :
3157 : // State for IsVisible(). mVisible starts off true. It becomes false when
3158 : // OnPageHide happens, and becomes true again when OnPageShow happens. So
3159 : // it's false only when we're in bfcache or unloaded.
3160 : bool mVisible : 1;
3161 :
3162 : // True if a document load has a CSP with referrer attached.
3163 : bool mHasReferrerPolicyCSP : 1;
3164 :
3165 : // True if our content viewer has been removed from the docshell
3166 : // (it may still be displayed, but in zombie state). Form control data
3167 : // has been saved.
3168 : bool mRemovedFromDocShell : 1;
3169 :
3170 : // True iff DNS prefetch is allowed for this document. Note that if the
3171 : // document has no window, DNS prefetch won't be performed no matter what.
3172 : bool mAllowDNSPrefetch : 1;
3173 :
3174 : // True when this document is a static clone of a normal document
3175 : bool mIsStaticDocument : 1;
3176 :
3177 : // True while this document is being cloned to a static document.
3178 : bool mCreatingStaticClone : 1;
3179 :
3180 : // True iff the document is being unlinked or deleted.
3181 : bool mInUnlinkOrDeletion : 1;
3182 :
3183 : // True if document has ever had script handling object.
3184 : bool mHasHadScriptHandlingObject : 1;
3185 :
3186 : // True if we're an SVG document being used as an image.
3187 : bool mIsBeingUsedAsImage : 1;
3188 :
3189 : // True is this document is synthetic : stand alone image, video, audio
3190 : // file, etc.
3191 : bool mIsSyntheticDocument : 1;
3192 :
3193 : // True if this document has links whose state needs updating
3194 : bool mHasLinksToUpdate : 1;
3195 :
3196 : // True is there is a pending runnable which will call FlushPendingLinkUpdates().
3197 : bool mHasLinksToUpdateRunnable : 1;
3198 :
3199 : // True if a DOMMutationObserver is perhaps attached to a node in the document.
3200 : bool mMayHaveDOMMutationObservers : 1;
3201 :
3202 : // True if an nsIAnimationObserver is perhaps attached to a node in the document.
3203 : bool mMayHaveAnimationObservers : 1;
3204 :
3205 : // True if a document has loaded Mixed Active Script (see nsMixedContentBlocker.cpp)
3206 : bool mHasMixedActiveContentLoaded : 1;
3207 :
3208 : // True if a document has blocked Mixed Active Script (see nsMixedContentBlocker.cpp)
3209 : bool mHasMixedActiveContentBlocked : 1;
3210 :
3211 : // True if a document has loaded Mixed Display/Passive Content (see nsMixedContentBlocker.cpp)
3212 : bool mHasMixedDisplayContentLoaded : 1;
3213 :
3214 : // True if a document has blocked Mixed Display/Passive Content (see nsMixedContentBlocker.cpp)
3215 : bool mHasMixedDisplayContentBlocked : 1;
3216 :
3217 : // True if a document loads a plugin object that attempts to load mixed content subresources through necko(see nsMixedContentBlocker.cpp)
3218 : bool mHasMixedContentObjectSubrequest : 1;
3219 :
3220 : // True if a document load has a CSP attached.
3221 : bool mHasCSP : 1;
3222 :
3223 : // True if a document load has a CSP with unsafe-eval attached.
3224 : bool mHasUnsafeEvalCSP : 1;
3225 :
3226 : // True if a document load has a CSP with unsafe-inline attached.
3227 : bool mHasUnsafeInlineCSP : 1;
3228 :
3229 : // True if a document has blocked Tracking Content
3230 : bool mHasTrackingContentBlocked : 1;
3231 :
3232 : // True if a document has loaded Tracking Content
3233 : bool mHasTrackingContentLoaded : 1;
3234 :
3235 : // True if DisallowBFCaching has been called on this document.
3236 : bool mBFCacheDisallowed : 1;
3237 :
3238 : bool mHasHadDefaultView : 1;
3239 :
3240 : // Whether style sheet change events will be dispatched for this document
3241 : bool mStyleSheetChangeEventsEnabled : 1;
3242 :
3243 : // Whether the document was created by a srcdoc iframe.
3244 : bool mIsSrcdocDocument : 1;
3245 :
3246 : // Records whether we've done a document.open. If this is true, it's possible
3247 : // for nodes from this document to have outdated wrappers in their wrapper
3248 : // caches.
3249 : bool mDidDocumentOpen : 1;
3250 :
3251 : // Whether this document has a display document and thus is considered to
3252 : // be a resource document. Normally this is the same as !!mDisplayDocument,
3253 : // but mDisplayDocument is cleared during Unlink. mHasDisplayDocument is
3254 : // valid in the document's destructor.
3255 : bool mHasDisplayDocument : 1;
3256 :
3257 : // Is the current mFontFaceSet valid?
3258 : bool mFontFaceSetDirty : 1;
3259 :
3260 : // Has GetUserFontSet() been called?
3261 : bool mGetUserFontSetCalled : 1;
3262 :
3263 : // Do we currently have an event posted to call FlushUserFontSet?
3264 : bool mPostedFlushUserFontSet : 1;
3265 :
3266 : // True if we have fired the DOMContentLoaded event, or don't plan to fire one
3267 : // (e.g. we're not being parsed at all).
3268 : bool mDidFireDOMContentLoaded : 1;
3269 :
3270 : // True if ReportHasScrollLinkedEffect() has been called.
3271 : bool mHasScrollLinkedEffect : 1;
3272 :
3273 : // True if we have frame request callbacks scheduled with the refresh driver.
3274 : // This should generally be updated only via
3275 : // UpdateFrameRequestCallbackSchedulingState.
3276 : bool mFrameRequestCallbacksScheduled : 1;
3277 :
3278 : bool mIsTopLevelContentDocument : 1;
3279 :
3280 : bool mIsContentDocument : 1;
3281 :
3282 : // Whether <style scoped> support is enabled in this document.
3283 : enum { eScopedStyle_Unknown, eScopedStyle_Disabled, eScopedStyle_Enabled };
3284 : unsigned int mIsScopedStyleEnabled : 2;
3285 :
3286 : // Compatibility mode
3287 : nsCompatibility mCompatMode;
3288 :
3289 : // Our readyState
3290 : ReadyState mReadyState;
3291 :
3292 : // Whether this document has (or will have, once we have a pres shell) a
3293 : // Gecko- or Servo-backed style system.
3294 : mozilla::StyleBackendType mStyleBackendType;
3295 :
3296 : #ifdef MOZILLA_INTERNAL_API
3297 : // Our visibility state
3298 : mozilla::dom::VisibilityState mVisibilityState;
3299 : static_assert(sizeof(mozilla::dom::VisibilityState) == sizeof(uint8_t),
3300 : "Error size of mVisibilityState and mDummy");
3301 : #else
3302 : uint8_t mDummy;
3303 : #endif
3304 :
3305 : enum Type {
3306 : eUnknown, // should never be used
3307 : eHTML,
3308 : eXHTML,
3309 : eGenericXML,
3310 : eSVG,
3311 : eXUL
3312 : };
3313 :
3314 : Type mType;
3315 :
3316 : uint8_t mDefaultElementType;
3317 :
3318 : enum Tri {
3319 : eTriUnset = 0,
3320 : eTriFalse,
3321 : eTriTrue
3322 : };
3323 :
3324 : Tri mAllowXULXBL;
3325 :
3326 : #ifdef DEBUG
3327 : /**
3328 : * This is true while FlushPendingLinkUpdates executes. Calls to
3329 : * [Un]RegisterPendingLinkUpdate will assert when this is true.
3330 : */
3331 : bool mIsLinkUpdateRegistrationsForbidden;
3332 : #endif
3333 :
3334 : // The document's script global object, the object from which the
3335 : // document can get its script context and scope. This is the
3336 : // *inner* window object.
3337 : nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
3338 :
3339 : // If mIsStaticDocument is true, mOriginalDocument points to the original
3340 : // document.
3341 : nsCOMPtr<nsIDocument> mOriginalDocument;
3342 :
3343 : // The bidi options for this document. What this bitfield means is
3344 : // defined in nsBidiUtils.h
3345 : uint32_t mBidiOptions;
3346 :
3347 : // The sandbox flags on the document. These reflect the value of the sandbox attribute of the
3348 : // associated IFRAME or CSP-protectable content, if existent. These are set at load time and
3349 : // are immutable - see nsSandboxFlags.h for the possible flags.
3350 : uint32_t mSandboxFlags;
3351 :
3352 : nsCString mContentLanguage;
3353 :
3354 : // The channel that got passed to nsDocument::StartDocumentLoad(), if any.
3355 : nsCOMPtr<nsIChannel> mChannel;
3356 : private:
3357 : nsCString mContentType;
3358 : nsString mId;
3359 : protected:
3360 :
3361 : // The document's security info
3362 : nsCOMPtr<nsISupports> mSecurityInfo;
3363 :
3364 : // The channel that failed to load and resulted in an error page.
3365 : // This only applies to error pages. Might be null.
3366 : nsCOMPtr<nsIChannel> mFailedChannel;
3367 :
3368 : // if this document is part of a multipart document,
3369 : // the ID can be used to distinguish it from the other parts.
3370 : uint32_t mPartID;
3371 :
3372 : // Cycle collector generation in which we're certain that this document
3373 : // won't be collected
3374 : uint32_t mMarkedCCGeneration;
3375 :
3376 : nsIPresShell* mPresShell;
3377 :
3378 : nsCOMArray<nsINode> mSubtreeModifiedTargets;
3379 : uint32_t mSubtreeModifiedDepth;
3380 :
3381 : // If we're an external resource document, this will be non-null and will
3382 : // point to our "display document": the one that all resource lookups should
3383 : // go to.
3384 : nsCOMPtr<nsIDocument> mDisplayDocument;
3385 :
3386 : uint32_t mEventsSuppressed;
3387 :
3388 : /**
3389 : * The number number of external scripts (ones with the src attribute) that
3390 : * have this document as their owner and that are being evaluated right now.
3391 : */
3392 : uint32_t mExternalScriptsBeingEvaluated;
3393 :
3394 : /**
3395 : * The current frame request callback handle
3396 : */
3397 : int32_t mFrameRequestCallbackCounter;
3398 :
3399 : // Count of live static clones of this document.
3400 : uint32_t mStaticCloneCount;
3401 :
3402 : // Array of nodes that have been blocked to prevent user tracking.
3403 : // They most likely have had their nsIChannel canceled by the URL
3404 : // classifier. (Safebrowsing)
3405 : //
3406 : // Weak nsINode pointers are used to allow nodes to disappear.
3407 : nsTArray<nsWeakPtr> mBlockedTrackingNodes;
3408 :
3409 : // Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow,
3410 : // updated on every set of mScriptGlobalObject.
3411 : nsPIDOMWindowInner* mWindow;
3412 :
3413 : nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
3414 :
3415 : struct FrameRequest;
3416 :
3417 : nsTArray<FrameRequest> mFrameRequestCallbacks;
3418 :
3419 : // This object allows us to evict ourself from the back/forward cache. The
3420 : // pointer is non-null iff we're currently in the bfcache.
3421 : nsIBFCacheEntry *mBFCacheEntry;
3422 :
3423 : // Our base target.
3424 : nsString mBaseTarget;
3425 :
3426 : nsCOMPtr<nsIStructuredCloneContainer> mStateObjectContainer;
3427 : nsCOMPtr<nsIVariant> mStateObjectCached;
3428 :
3429 : uint32_t mInSyncOperationCount;
3430 :
3431 : RefPtr<mozilla::dom::XPathEvaluator> mXPathEvaluator;
3432 :
3433 : nsTArray<RefPtr<mozilla::dom::AnonymousContent>> mAnonymousContents;
3434 :
3435 : uint32_t mBlockDOMContentLoaded;
3436 :
3437 : // Our live MediaQueryLists
3438 : mozilla::LinkedList<mozilla::dom::MediaQueryList> mDOMMediaQueryLists;
3439 :
3440 : // Flags for use counters used directly by this document.
3441 : std::bitset<mozilla::eUseCounter_Count> mUseCounters;
3442 : // Flags for use counters used by any child documents of this document.
3443 : std::bitset<mozilla::eUseCounter_Count> mChildDocumentUseCounters;
3444 : // Flags for whether we've notified our top-level "page" of a use counter
3445 : // for this child document.
3446 : std::bitset<mozilla::eUseCounter_Count> mNotifiedPageForUseCounter;
3447 :
3448 : // Count the number of times something is seen in a document.
3449 : mozilla::Array<uint16_t, mozilla::eIncCounter_Count> mIncCounters;
3450 :
3451 : // Whether the user has interacted with the document or not:
3452 : bool mUserHasInteracted;
3453 :
3454 : mozilla::TimeStamp mPageUnloadingEventTimeStamp;
3455 :
3456 : RefPtr<mozilla::dom::DocGroup> mDocGroup;
3457 :
3458 : // The set of all the tracking script URLs. URLs are added to this set by
3459 : // calling NoteScriptTrackingStatus(). Currently we assume that a URL not
3460 : // existing in the set means the corresponding script isn't a tracking script.
3461 : nsTHashtable<nsCStringHashKey> mTrackingScripts;
3462 : };
3463 :
3464 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID)
3465 :
3466 : /**
3467 : * mozAutoSubtreeModified batches DOM mutations so that a DOMSubtreeModified
3468 : * event is dispatched, if necessary, when the outermost mozAutoSubtreeModified
3469 : * object is deleted.
3470 : */
3471 : class MOZ_STACK_CLASS mozAutoSubtreeModified
3472 : {
3473 : public:
3474 : /**
3475 : * @param aSubTreeOwner The document in which a subtree will be modified.
3476 : * @param aTarget The target of the possible DOMSubtreeModified event.
3477 : * Can be nullptr, in which case mozAutoSubtreeModified
3478 : * is just used to batch DOM mutations.
3479 : */
3480 2 : mozAutoSubtreeModified(nsIDocument* aSubtreeOwner, nsINode* aTarget)
3481 2 : {
3482 2 : UpdateTarget(aSubtreeOwner, aTarget);
3483 2 : }
3484 :
3485 2 : ~mozAutoSubtreeModified()
3486 2 : {
3487 2 : UpdateTarget(nullptr, nullptr);
3488 2 : }
3489 :
3490 4 : void UpdateTarget(nsIDocument* aSubtreeOwner, nsINode* aTarget)
3491 : {
3492 4 : if (mSubtreeOwner) {
3493 0 : mSubtreeOwner->MutationEventDispatched(mTarget);
3494 : }
3495 :
3496 4 : mTarget = aTarget;
3497 4 : mSubtreeOwner = aSubtreeOwner;
3498 4 : if (mSubtreeOwner) {
3499 0 : mSubtreeOwner->WillDispatchMutationEvent(mTarget);
3500 : }
3501 4 : }
3502 :
3503 : private:
3504 : nsCOMPtr<nsINode> mTarget;
3505 : nsCOMPtr<nsIDocument> mSubtreeOwner;
3506 : };
3507 :
3508 : class MOZ_STACK_CLASS nsAutoSyncOperation
3509 : {
3510 : public:
3511 : explicit nsAutoSyncOperation(nsIDocument* aDocument);
3512 : ~nsAutoSyncOperation();
3513 : private:
3514 : nsCOMArray<nsIDocument> mDocuments;
3515 : uint32_t mMicroTaskLevel;
3516 : };
3517 :
3518 : // XXX These belong somewhere else
3519 : nsresult
3520 : NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
3521 :
3522 : nsresult
3523 : NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false,
3524 : bool aIsPlainDocument = false);
3525 :
3526 : nsresult
3527 : NS_NewSVGDocument(nsIDocument** aInstancePtrResult);
3528 :
3529 : nsresult
3530 : NS_NewImageDocument(nsIDocument** aInstancePtrResult);
3531 :
3532 : nsresult
3533 : NS_NewVideoDocument(nsIDocument** aInstancePtrResult);
3534 :
3535 : // Note: it's the caller's responsibility to create or get aPrincipal as needed
3536 : // -- this method will not attempt to get a principal based on aDocumentURI.
3537 : // Also, both aDocumentURI and aBaseURI must not be null.
3538 : nsresult
3539 : NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
3540 : const nsAString& aNamespaceURI,
3541 : const nsAString& aQualifiedName,
3542 : nsIDOMDocumentType* aDoctype,
3543 : nsIURI* aDocumentURI,
3544 : nsIURI* aBaseURI,
3545 : nsIPrincipal* aPrincipal,
3546 : bool aLoadedAsData,
3547 : nsIGlobalObject* aEventObject,
3548 : DocumentFlavor aFlavor);
3549 :
3550 : // This is used only for xbl documents created from the startup cache.
3551 : // Non-cached documents are created in the same manner as xml documents.
3552 : nsresult
3553 : NS_NewXBLDocument(nsIDOMDocument** aInstancePtrResult,
3554 : nsIURI* aDocumentURI,
3555 : nsIURI* aBaseURI,
3556 : nsIPrincipal* aPrincipal);
3557 :
3558 : nsresult
3559 : NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
3560 :
3561 : inline nsIDocument*
3562 14 : nsINode::GetOwnerDocument() const
3563 : {
3564 14 : nsIDocument* ownerDoc = OwnerDoc();
3565 :
3566 14 : return ownerDoc != this ? ownerDoc : nullptr;
3567 : }
3568 :
3569 : inline nsINode*
3570 0 : nsINode::OwnerDocAsNode() const
3571 : {
3572 0 : return OwnerDoc();
3573 : }
3574 :
3575 : inline mozilla::dom::ParentObject
3576 400 : nsINode::GetParentObject() const
3577 : {
3578 400 : mozilla::dom::ParentObject p(OwnerDoc());
3579 : // Note that mUseXBLScope is a no-op for chrome, and other places where we
3580 : // don't use XBL scopes.
3581 400 : p.mUseXBLScope = IsInAnonymousSubtree() && !IsAnonymousContentInSVGUseSubtree();
3582 400 : return p;
3583 : }
3584 :
3585 : #endif /* nsIDocument_h___ */
|