LCOV - code coverage report
Current view: top level - dom/base - nsIDocument.h (source / functions) Hit Total Coverage
Test: output.info Lines: 16 174 9.2 %
Date: 2018-08-07 16:42:27 Functions: 0 0 -
Legend: Lines: hit not hit

          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 "nsAttrAndChildArray.h"
      11             : #include "nsAutoPtr.h"                   // for member
      12             : #include "nsCOMArray.h"                  // for member
      13             : #include "nsCompatibility.h"             // for member
      14             : #include "nsCOMPtr.h"                    // for member
      15             : #include "nsGkAtoms.h"                   // for static class members
      16             : #include "nsIApplicationCache.h"
      17             : #include "nsIApplicationCacheContainer.h"
      18             : #include "nsIContentViewer.h"
      19             : #include "nsIInterfaceRequestor.h"
      20             : #include "nsILoadContext.h"
      21             : #include "nsILoadGroup.h"                // for member (in nsCOMPtr)
      22             : #include "nsINode.h"                     // for base class
      23             : #include "nsIParser.h"
      24             : #include "nsIPresShell.h"
      25             : #include "nsIChannelEventSink.h"
      26             : #include "nsIProgressEventSink.h"
      27             : #include "nsISecurityEventSink.h"
      28             : #include "nsIScriptGlobalObject.h"       // for member (in nsCOMPtr)
      29             : #include "nsIServiceManager.h"
      30             : #include "nsIURI.h"                      // for use in inline functions
      31             : #include "nsIUUIDGenerator.h"
      32             : #include "nsPIDOMWindow.h"               // for use in inline functions
      33             : #include "nsPropertyTable.h"             // for member
      34             : #include "nsStringFwd.h"
      35             : #include "nsTHashtable.h"                // for member
      36             : #include "nsURIHashKey.h"
      37             : #include "mozilla/net/ReferrerPolicy.h"  // for member
      38             : #include "nsWeakReference.h"
      39             : #include "mozilla/UseCounter.h"
      40             : #include "mozilla/WeakPtr.h"
      41             : #include "Units.h"
      42             : #include "nsContentListDeclarations.h"
      43             : #include "nsExpirationTracker.h"
      44             : #include "nsClassHashtable.h"
      45             : #include "mozilla/CORSMode.h"
      46             : #include "mozilla/dom/DispatcherTrait.h"
      47             : #include "mozilla/dom/DocumentOrShadowRoot.h"
      48             : #include "mozilla/LinkedList.h"
      49             : #include "mozilla/NotNull.h"
      50             : #include "mozilla/SegmentedVector.h"
      51             : #include "mozilla/ServoBindingTypes.h"
      52             : #include "mozilla/StyleSheet.h"
      53             : #include "mozilla/TimeStamp.h"
      54             : #include "mozilla/UniquePtr.h"
      55             : #include <bitset>                        // for member
      56             : 
      57             : // windows.h #defines CreateEvent
      58             : #ifdef CreateEvent
      59             : #undef CreateEvent
      60             : #endif
      61             : 
      62             : #ifdef MOZILLA_INTERNAL_API
      63             : #include "mozilla/dom/DocumentBinding.h"
      64             : #else
      65             : namespace mozilla {
      66             : namespace dom {
      67             : class ElementCreationOptionsOrString;
      68             : } // namespace dom
      69             : } // namespace mozilla
      70             : #endif // MOZILLA_INTERNAL_API
      71             : 
      72             : class gfxUserFontSet;
      73             : class imgIRequest;
      74             : class nsBindingManager;
      75             : class nsCachableElementsByNameNodeList;
      76             : class nsIDocShell;
      77             : class nsDocShell;
      78             : class nsDOMNavigationTiming;
      79             : class nsDOMStyleSheetSetList;
      80             : class nsFrameLoader;
      81             : class nsGlobalWindowInner;
      82             : class nsHTMLCSSStyleSheet;
      83             : class nsHTMLDocument;
      84             : class nsHTMLStyleSheet;
      85             : class nsGenericHTMLElement;
      86             : class nsAtom;
      87             : class nsIBFCacheEntry;
      88             : class nsIChannel;
      89             : class nsIContent;
      90             : class nsIContentSink;
      91             : class nsIDocShell;
      92             : class nsIDocShellTreeItem;
      93             : class nsIDocumentEncoder;
      94             : class nsIDocumentObserver;
      95             : class nsIHTMLCollection;
      96             : class nsILayoutHistoryState;
      97             : class nsILoadContext;
      98             : class nsIObjectLoadingContent;
      99             : class nsIObserver;
     100             : class nsIPrincipal;
     101             : class nsIRequest;
     102             : class nsIRunnable;
     103             : class nsISecurityConsoleMessage;
     104             : class nsIStreamListener;
     105             : class nsIStructuredCloneContainer;
     106             : class nsIURI;
     107             : class nsIVariant;
     108             : class nsViewManager;
     109             : class nsPresContext;
     110             : class nsRange;
     111             : class nsSMILAnimationController;
     112             : class nsSVGElement;
     113             : class nsTextNode;
     114             : class nsUnblockOnloadEvent;
     115             : class nsWindowSizes;
     116             : class nsDOMCaretPosition;
     117             : class nsViewportInfo;
     118             : class nsIGlobalObject;
     119             : class nsIXULWindow;
     120             : 
     121             : namespace mozilla {
     122             : class AbstractThread;
     123             : class CSSStyleSheet;
     124             : class Encoding;
     125             : class ErrorResult;
     126             : class EventStates;
     127             : class EventListenerManager;
     128             : class PendingAnimationTracker;
     129             : class ServoStyleSet;
     130             : template<typename> class OwningNonNull;
     131             : struct URLExtraData;
     132             : 
     133             : namespace css {
     134             : class Loader;
     135             : class ImageLoader;
     136             : class Rule;
     137             : } // namespace css
     138             : 
     139             : namespace dom {
     140             : class Animation;
     141             : class AnonymousContent;
     142             : class Attr;
     143             : class BoxObject;
     144             : class ClientInfo;
     145             : class ClientState;
     146             : class CDATASection;
     147             : class Comment;
     148             : struct CustomElementDefinition;
     149             : class DocGroup;
     150             : class DocumentFragment;
     151             : class DocumentTimeline;
     152             : class DocumentType;
     153             : class DOMImplementation;
     154             : class DOMIntersectionObserver;
     155             : class DOMStringList;
     156             : class Element;
     157             : struct ElementCreationOptions;
     158             : class Event;
     159             : class EventTarget;
     160             : class FontFaceSet;
     161             : class FrameRequestCallback;
     162             : struct FullscreenRequest;
     163             : class ImageTracker;
     164             : class HTMLBodyElement;
     165             : class HTMLSharedElement;
     166             : class HTMLImageElement;
     167             : struct LifecycleCallbackArgs;
     168             : class Link;
     169             : class Location;
     170             : class MediaQueryList;
     171             : class GlobalObject;
     172             : class NodeFilter;
     173             : class NodeIterator;
     174             : enum class OrientationType : uint8_t;
     175             : class ProcessingInstruction;
     176             : class Promise;
     177             : class ScriptLoader;
     178             : class Selection;
     179             : class ServiceWorkerDescriptor;
     180             : class StyleSheetList;
     181             : class SVGDocument;
     182             : class SVGSVGElement;
     183             : class Touch;
     184             : class TouchList;
     185             : class TreeWalker;
     186             : class XPathEvaluator;
     187             : class XPathExpression;
     188             : class XPathNSResolver;
     189             : class XPathResult;
     190             : class XULDocument;
     191             : template<typename> class Sequence;
     192             : 
     193             : template<typename, typename> class CallbackObjectHolder;
     194             : 
     195             : enum class CallerType : uint32_t;
     196             : 
     197             : } // namespace dom
     198             : } // namespace mozilla
     199             : 
     200             : // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
     201             : #define NS_IDOCUMENT_IID \
     202             : { 0xce1f7627, 0x7109, 0x4977, \
     203             :   { 0xba, 0x77, 0x49, 0x0f, 0xfd, 0xe0, 0x7a, 0xaa } }
     204             : 
     205             : // Enum for requesting a particular type of document when creating a doc
     206             : enum DocumentFlavor {
     207             :   DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
     208             :   DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
     209             :   DocumentFlavorSVG, // SVGDocument
     210             :   DocumentFlavorPlain, // Just a Document
     211             : };
     212             : 
     213             : // Document states
     214             : 
     215             : // RTL locale: specific to the XUL localedir attribute
     216             : #define NS_DOCUMENT_STATE_RTL_LOCALE              NS_DEFINE_EVENT_STATE_MACRO(0)
     217             : // Window activation status
     218             : #define NS_DOCUMENT_STATE_WINDOW_INACTIVE         NS_DEFINE_EVENT_STATE_MACRO(1)
     219             : 
     220             : // Some function forward-declarations
     221             : class nsContentList;
     222             : class nsDocumentOnStack;
     223             : 
     224             : class nsDocHeaderData
     225             : {
     226             : public:
     227             :   nsDocHeaderData(nsAtom* aField, const nsAString& aData)
     228             :     : mField(aField), mData(aData), mNext(nullptr)
     229             :   {
     230             :   }
     231             : 
     232             :   ~nsDocHeaderData(void)
     233             :   {
     234             :     delete mNext;
     235             :   }
     236             : 
     237             :   RefPtr<nsAtom> mField;
     238             :   nsString mData;
     239             :   nsDocHeaderData* mNext;
     240             : };
     241             : 
     242             : class nsExternalResourceMap
     243             : {
     244             :   typedef bool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
     245             : 
     246             : public:
     247             :   /**
     248             :    * A class that represents an external resource load that has begun but
     249             :    * doesn't have a document yet.  Observers can be registered on this object,
     250             :    * and will be notified after the document is created.  Observers registered
     251             :    * after the document has been created will NOT be notified.  When observers
     252             :    * are notified, the subject will be the newly-created document, the topic
     253             :    * will be "external-resource-document-created", and the data will be null.
     254             :    * If document creation fails for some reason, observers will still be
     255             :    * notified, with a null document pointer.
     256             :    */
     257             :   class ExternalResourceLoad : public nsISupports
     258             :   {
     259             :   public:
     260             :     virtual ~ExternalResourceLoad() {}
     261             : 
     262             :     void AddObserver(nsIObserver* aObserver)
     263             :     {
     264             :       MOZ_ASSERT(aObserver, "Must have observer");
     265             :       mObservers.AppendElement(aObserver);
     266             :     }
     267             : 
     268             :     const nsTArray<nsCOMPtr<nsIObserver>> & Observers()
     269             :     {
     270             :       return mObservers;
     271             :     }
     272             :   protected:
     273             :     AutoTArray<nsCOMPtr<nsIObserver>, 8> mObservers;
     274             :   };
     275             : 
     276             :   nsExternalResourceMap();
     277             : 
     278             :   /**
     279             :    * Request an external resource document.  This does exactly what
     280             :    * nsIDocument::RequestExternalResource is documented to do.
     281             :    */
     282             :   nsIDocument* RequestResource(nsIURI* aURI,
     283             :                                nsINode* aRequestingNode,
     284             :                                nsIDocument* aDisplayDocument,
     285             :                                ExternalResourceLoad** aPendingLoad);
     286             : 
     287             :   /**
     288             :    * Enumerate the resource documents.  See
     289             :    * nsIDocument::EnumerateExternalResources.
     290             :    */
     291             :   void EnumerateResources(nsSubDocEnumFunc aCallback, void* aData);
     292             : 
     293             :   /**
     294             :    * Traverse ourselves for cycle-collection
     295             :    */
     296             :   void Traverse(nsCycleCollectionTraversalCallback* aCallback) const;
     297             : 
     298             :   /**
     299             :    * Shut ourselves down (used for cycle-collection unlink), as well
     300             :    * as for document destruction.
     301             :    */
     302             :   void Shutdown()
     303             :   {
     304             :     mPendingLoads.Clear();
     305             :     mMap.Clear();
     306             :     mHaveShutDown = true;
     307             :   }
     308             : 
     309             :   bool HaveShutDown() const
     310             :   {
     311             :     return mHaveShutDown;
     312             :   }
     313             : 
     314             :   // Needs to be public so we can traverse them sanely
     315             :   struct ExternalResource
     316             :   {
     317             :     ~ExternalResource();
     318             :     nsCOMPtr<nsIDocument> mDocument;
     319             :     nsCOMPtr<nsIContentViewer> mViewer;
     320             :     nsCOMPtr<nsILoadGroup> mLoadGroup;
     321             :   };
     322             : 
     323             :   // Hide all our viewers
     324             :   void HideViewers();
     325             : 
     326             :   // Show all our viewers
     327             :   void ShowViewers();
     328             : 
     329             : protected:
     330             :   class PendingLoad : public ExternalResourceLoad,
     331             :                       public nsIStreamListener
     332             :   {
     333             :     ~PendingLoad() {}
     334             : 
     335             :   public:
     336             :     explicit PendingLoad(nsIDocument* aDisplayDocument) :
     337             :       mDisplayDocument(aDisplayDocument)
     338             :     {}
     339             : 
     340             :     NS_DECL_ISUPPORTS
     341             :     NS_DECL_NSISTREAMLISTENER
     342             :     NS_DECL_NSIREQUESTOBSERVER
     343             : 
     344             :     /**
     345             :      * Start aURI loading.  This will perform the necessary security checks and
     346             :      * so forth.
     347             :      */
     348             :     nsresult StartLoad(nsIURI* aURI, nsINode* aRequestingNode);
     349             : 
     350             :     /**
     351             :      * Set up an nsIContentViewer based on aRequest.  This is guaranteed to
     352             :      * put null in *aViewer and *aLoadGroup on all failures.
     353             :      */
     354             :     nsresult SetupViewer(nsIRequest* aRequest, nsIContentViewer** aViewer,
     355             :                          nsILoadGroup** aLoadGroup);
     356             : 
     357             :   private:
     358             :     nsCOMPtr<nsIDocument> mDisplayDocument;
     359             :     nsCOMPtr<nsIStreamListener> mTargetListener;
     360             :     nsCOMPtr<nsIURI> mURI;
     361             :   };
     362             :   friend class PendingLoad;
     363             : 
     364             :   class LoadgroupCallbacks final : public nsIInterfaceRequestor
     365             :   {
     366             :     ~LoadgroupCallbacks() {}
     367             :   public:
     368             :     explicit LoadgroupCallbacks(nsIInterfaceRequestor* aOtherCallbacks)
     369             :       : mCallbacks(aOtherCallbacks)
     370             :     {}
     371             :     NS_DECL_ISUPPORTS
     372             :     NS_DECL_NSIINTERFACEREQUESTOR
     373             :   private:
     374             :     // The only reason it's safe to hold a strong ref here without leaking is
     375             :     // that the notificationCallbacks on a loadgroup aren't the docshell itself
     376             :     // but a shim that holds a weak reference to the docshell.
     377             :     nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
     378             : 
     379             :     // Use shims for interfaces that docshell implements directly so that we
     380             :     // don't hand out references to the docshell.  The shims should all allow
     381             :     // getInterface back on us, but other than that each one should only
     382             :     // implement one interface.
     383             : 
     384             :     // XXXbz I wish we could just derive the _allcaps thing from _i
     385             : #define DECL_SHIM(_i, _allcaps)                                              \
     386             :     class _i##Shim final : public nsIInterfaceRequestor,                     \
     387             :                            public _i                                         \
     388             :     {                                                                        \
     389             :       ~_i##Shim() {}                                                         \
     390             :     public:                                                                  \
     391             :       _i##Shim(nsIInterfaceRequestor* aIfreq, _i* aRealPtr)                  \
     392             :         : mIfReq(aIfreq), mRealPtr(aRealPtr)                                 \
     393             :       {                                                                      \
     394             :         NS_ASSERTION(mIfReq, "Expected non-null here");                      \
     395             :         NS_ASSERTION(mRealPtr, "Expected non-null here");                    \
     396             :       }                                                                      \
     397             :       NS_DECL_ISUPPORTS                                                      \
     398             :       NS_FORWARD_NSIINTERFACEREQUESTOR(mIfReq->)                             \
     399             :       NS_FORWARD_##_allcaps(mRealPtr->)                                      \
     400             :     private:                                                                 \
     401             :       nsCOMPtr<nsIInterfaceRequestor> mIfReq;                                \
     402             :       nsCOMPtr<_i> mRealPtr;                                                 \
     403             :     };
     404             : 
     405           0 :     DECL_SHIM(nsILoadContext, NSILOADCONTEXT)
     406           0 :     DECL_SHIM(nsIProgressEventSink, NSIPROGRESSEVENTSINK)
     407           0 :     DECL_SHIM(nsIChannelEventSink, NSICHANNELEVENTSINK)
     408           0 :     DECL_SHIM(nsISecurityEventSink, NSISECURITYEVENTSINK)
     409           0 :     DECL_SHIM(nsIApplicationCacheContainer, NSIAPPLICATIONCACHECONTAINER)
     410             : #undef DECL_SHIM
     411             :   };
     412             : 
     413             :   /**
     414             :    * Add an ExternalResource for aURI.  aViewer and aLoadGroup might be null
     415             :    * when this is called if the URI didn't result in an XML document.  This
     416             :    * function makes sure to remove the pending load for aURI, if any, from our
     417             :    * hashtable, and to notify its observers, if any.
     418             :    */
     419             :   nsresult AddExternalResource(nsIURI* aURI, nsIContentViewer* aViewer,
     420             :                                nsILoadGroup* aLoadGroup,
     421             :                                nsIDocument* aDisplayDocument);
     422             : 
     423             :   nsClassHashtable<nsURIHashKey, ExternalResource> mMap;
     424             :   nsRefPtrHashtable<nsURIHashKey, PendingLoad> mPendingLoads;
     425             :   bool mHaveShutDown;
     426             : };
     427             : 
     428             : //----------------------------------------------------------------------
     429             : 
     430             : // For classifying a flash document based on its principal.
     431             : class PrincipalFlashClassifier;
     432             : 
     433             : // Document interface.  This is implemented by all document objects in
     434             : // Gecko.
     435             : class nsIDocument : public nsINode,
     436             :                     public mozilla::dom::DocumentOrShadowRoot,
     437             :                     public mozilla::dom::DispatcherTrait
     438             : {
     439             :   typedef mozilla::dom::GlobalObject GlobalObject;
     440             : 
     441             : protected:
     442             :   using Encoding = mozilla::Encoding;
     443             :   template <typename T> using NotNull = mozilla::NotNull<T>;
     444             : 
     445             : public:
     446             :   typedef nsExternalResourceMap::ExternalResourceLoad ExternalResourceLoad;
     447             :   typedef mozilla::net::ReferrerPolicy ReferrerPolicyEnum;
     448             :   typedef mozilla::dom::Element Element;
     449             :   typedef mozilla::dom::FullscreenRequest FullscreenRequest;
     450             : 
     451             :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
     452             : 
     453             : #ifdef MOZILLA_INTERNAL_API
     454             :   nsIDocument();
     455             : #endif
     456             : 
     457             :   // This helper class must be set when we dispatch beforeunload and unload
     458             :   // events in order to avoid unterminate sync XHRs.
     459             :   class MOZ_RAII PageUnloadingEventTimeStamp
     460             :   {
     461             :     nsCOMPtr<nsIDocument> mDocument;
     462             :     bool mSet;
     463             : 
     464             :   public:
     465             :     explicit PageUnloadingEventTimeStamp(nsIDocument* aDocument)
     466             :       : mDocument(aDocument)
     467             :       , mSet(false)
     468             :     {
     469             :       MOZ_ASSERT(aDocument);
     470             :       if (mDocument->mPageUnloadingEventTimeStamp.IsNull()) {
     471             :         mDocument->SetPageUnloadingEventTimeStamp();
     472             :         mSet = true;
     473             :       }
     474             :     }
     475             : 
     476             :     ~PageUnloadingEventTimeStamp()
     477             :     {
     478             :       if (mSet) {
     479             :         mDocument->CleanUnloadEventsTimeStamp();
     480             :       }
     481             :     }
     482             :   };
     483             : 
     484             :   /**
     485             :    * Let the document know that we're starting to load data into it.
     486             :    * @param aCommand The parser command. Must not be null.
     487             :    *                 XXXbz It's odd to have that here.
     488             :    * @param aChannel The channel the data will come from. The channel must be
     489             :    *                 able to report its Content-Type.
     490             :    * @param aLoadGroup The loadgroup this document should use from now on.
     491             :    *                   Note that the document might not be the only thing using
     492             :    *                   this loadgroup.
     493             :    * @param aContainer The container this document is in.  This may be null.
     494             :    *                   XXXbz maybe we should make it more explicit (eg make the
     495             :    *                   container an nsIWebNavigation or nsIDocShell or
     496             :    *                   something)?
     497             :    * @param [out] aDocListener the listener to pump data from the channel into.
     498             :    *                           Generally this will be the parser this document
     499             :    *                           sets up, or some sort of data-handler for media
     500             :    *                           documents.
     501             :    * @param aReset whether the document should call Reset() on itself.  If this
     502             :    *               is false, the document will NOT set its principal to the
     503             :    *               channel's owner, will not clear any event listeners that are
     504             :    *               already set on it, etc.
     505             :    * @param aSink The content sink to use for the data.  If this is null and
     506             :    *              the document needs a content sink, it will create one based
     507             :    *              on whatever it knows about the data it's going to load.
     508             :    *              This MUST be null if the underlying document is an HTML
     509             :    *              document. Even in the XML case, please don't add new calls
     510             :    *              with non-null sink.
     511             :    *
     512             :    * Once this has been called, the document will return false for
     513             :    * MayStartLayout() until SetMayStartLayout(true) is called on it.  Making
     514             :    * sure this happens is the responsibility of the caller of
     515             :    * StartDocumentLoad().
     516             :    */
     517             :   virtual nsresult StartDocumentLoad(const char* aCommand,
     518             :                                      nsIChannel* aChannel,
     519             :                                      nsILoadGroup* aLoadGroup,
     520             :                                      nsISupports* aContainer,
     521             :                                      nsIStreamListener **aDocListener,
     522             :                                      bool aReset,
     523             :                                      nsIContentSink* aSink = nullptr) = 0;
     524             :   virtual void StopDocumentLoad() = 0;
     525             : 
     526           0 :   virtual void SetSuppressParserErrorElement(bool aSuppress) {}
     527           0 :   virtual bool SuppressParserErrorElement() { return false; }
     528             : 
     529           0 :   virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {}
     530           0 :   virtual bool SuppressParserErrorConsoleMessages() { return false; }
     531             : 
     532             :   // nsINode
     533             :   bool IsNodeOfType(uint32_t aFlags) const final;
     534           0 :   nsIContent* GetChildAt_Deprecated(uint32_t aIndex) const final
     535             :   {
     536           0 :     return mChildren.GetSafeChildAt(aIndex);
     537             :   }
     538             : 
     539           0 :   int32_t ComputeIndexOf(const nsINode* aPossibleChild) const final
     540             :   {
     541           0 :     return mChildren.IndexOfChild(aPossibleChild);
     542             :   }
     543             : 
     544           0 :   uint32_t GetChildCount() const final
     545             :   {
     546           0 :     return mChildren.ChildCount();
     547             :   }
     548             : 
     549             :   nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
     550             :                              bool aNotify) override;
     551             :   nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
     552             :                                     bool aNotify) override;
     553             :   void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) final;
     554             :   void RemoveChildNode(nsIContent* aKid, bool aNotify) final;
     555             :   nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo,
     556             :                  nsINode **aResult,
     557             :                  bool aPreallocateChildren) const override
     558             :   {
     559             :     return NS_ERROR_NOT_IMPLEMENTED;
     560             :   }
     561             : 
     562             :   /**
     563             :    * Signal that the document title may have changed
     564             :    * (see nsDocument::GetTitle).
     565             :    * @param aBoundTitleElement true if an HTML or SVG <title> element
     566             :    * has just been bound to the document.
     567             :    */
     568             :   void NotifyPossibleTitleChange(bool aBoundTitleElement);
     569             : 
     570             :   /**
     571             :    * Return the URI for the document. May return null.
     572             :    *
     573             :    * The value returned corresponds to the "document's address" in
     574             :    * HTML5.  As such, it may change over the lifetime of the document, for
     575             :    * instance as a result of the user navigating to a fragment identifier on
     576             :    * the page, or as a result to a call to pushState() or replaceState().
     577             :    *
     578             :    * https://html.spec.whatwg.org/multipage/dom.html#the-document%27s-address
     579             :    */
     580             :   nsIURI* GetDocumentURI() const
     581             :   {
     582           0 :     return mDocumentURI;
     583             :   }
     584             : 
     585             :   /**
     586             :    * Return the original URI of the document.  This is the same as the
     587             :    * document's URI unless that has changed from its original value (for
     588             :    * example, due to history.pushState() or replaceState() being invoked on the
     589             :    * document).
     590             :    *
     591             :    * This method corresponds to the "creation URL" in HTML5 and, once set,
     592             :    * doesn't change over the lifetime of the document.
     593             :    *
     594             :    * https://html.spec.whatwg.org/multipage/webappapis.html#creation-url
     595             :    */
     596             :   nsIURI* GetOriginalURI() const
     597             :   {
     598           0 :     return mOriginalURI;
     599             :   }
     600             : 
     601             :   /**
     602             :    * Set the URI for the document.  This also sets the document's original URI,
     603             :    * if it's null.
     604             :    */
     605             :   void SetDocumentURI(nsIURI* aURI);
     606             : 
     607             :   /**
     608             :    * Set the URI for the document loaded via XHR, when accessed from
     609             :    * chrome privileged script.
     610             :    */
     611             :   void SetChromeXHRDocURI(nsIURI* aURI)
     612             :   {
     613             :     mChromeXHRDocURI = aURI;
     614             :   }
     615             : 
     616             :   /**
     617             :    * Set the base URI for the document loaded via XHR, when accessed from
     618             :    * chrome privileged script.
     619             :    */
     620             :   void SetChromeXHRDocBaseURI(nsIURI* aURI)
     621             :   {
     622           0 :     mChromeXHRDocBaseURI = aURI;
     623             :   }
     624             : 
     625             :   /**
     626             :    * Set referrer policy and upgrade-insecure-requests flags
     627             :    */
     628             :   void ApplySettingsFromCSP(bool aSpeculative);
     629             : 
     630             :   already_AddRefed<nsIParser> CreatorParserOrNull()
     631             :   {
     632             :     nsCOMPtr<nsIParser> parser = mParser;
     633             :     return parser.forget();
     634             :   }
     635             : 
     636             :   /**
     637             :    * Return the referrer policy of the document. Return "default" if there's no
     638             :    * valid meta referrer tag found in the document.
     639             :    */
     640             :   ReferrerPolicyEnum GetReferrerPolicy() const
     641             :   {
     642             :     return mReferrerPolicy;
     643             :   }
     644             : 
     645             :   /**
     646             :    * GetReferrerPolicy() for Document.webidl.
     647             :    */
     648             :   uint32_t ReferrerPolicy() const
     649             :   {
     650             :     return GetReferrerPolicy();
     651             :   }
     652             : 
     653             :   /**
     654             :    * If true, this flag indicates that all mixed content subresource
     655             :    * loads for this document (and also embeded browsing contexts) will
     656             :    * be blocked.
     657             :    */
     658             :   bool GetBlockAllMixedContent(bool aPreload) const
     659             :   {
     660           0 :     if (aPreload) {
     661           0 :       return mBlockAllMixedContentPreloads;
     662             :     }
     663           0 :     return mBlockAllMixedContent;
     664             :   }
     665             : 
     666             :   /**
     667             :    * If true, this flag indicates that all subresource loads for this
     668             :    * document need to be upgraded from http to https.
     669             :    * This flag becomes true if the CSP of the document itself, or any
     670             :    * of the document's ancestors up to the toplevel document makes use
     671             :    * of the CSP directive 'upgrade-insecure-requests'.
     672             :    */
     673             :   bool GetUpgradeInsecureRequests(bool aPreload) const
     674             :   {
     675           0 :     if (aPreload) {
     676           0 :       return mUpgradeInsecurePreloads;
     677             :     }
     678           0 :     return mUpgradeInsecureRequests;
     679             :   }
     680             : 
     681             :   void SetReferrer(const nsACString& aReferrer) {
     682             :     mReferrer = aReferrer;
     683             :   }
     684             : 
     685             :   /**
     686             :    * Set the principal responsible for this document.  Chances are,
     687             :    * you do not want to be using this.
     688             :    */
     689             :   void SetPrincipal(nsIPrincipal* aPrincipal);
     690             : 
     691             :   /**
     692             :    * Get the list of ancestor principals for a document.  This is the same as
     693             :    * the ancestor list for the document's docshell the last time SetContainer()
     694             :    * was called with a non-null argument. See the documentation for the
     695             :    * corresponding getter in docshell for how this list is determined.  We store
     696             :    * a copy of the list, because we may lose the ability to reach our docshell
     697             :    * before people stop asking us for this information.
     698             :    */
     699             :   const nsTArray<nsCOMPtr<nsIPrincipal>>& AncestorPrincipals() const
     700             :   {
     701             :     return mAncestorPrincipals;
     702             :   }
     703             : 
     704             :   /**
     705             :    * Get the list of ancestor outerWindowIDs for a document that correspond to
     706             :    * the ancestor principals (see above for more details).
     707             :    */
     708             :   const nsTArray<uint64_t>& AncestorOuterWindowIDs() const
     709             :   {
     710             :     return mAncestorOuterWindowIDs;
     711             :   }
     712             : 
     713             :   /**
     714             :    * Return the LoadGroup for the document. May return null.
     715             :    */
     716           0 :   already_AddRefed<nsILoadGroup> GetDocumentLoadGroup() const
     717             :   {
     718           0 :     nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
     719           0 :     return group.forget();
     720             :   }
     721             : 
     722             :   /**
     723             :    * Return the fallback base URL for this document, as defined in the HTML
     724             :    * specification.  Note that this can return null if there is no document URI.
     725             :    *
     726             :    * XXXbz: This doesn't implement the bits for about:blank yet.
     727             :    */
     728           0 :   nsIURI* GetFallbackBaseURI() const
     729             :   {
     730           0 :     if (mIsSrcdocDocument && mParentDocument) {
     731           0 :       return mParentDocument->GetDocBaseURI();
     732             :     }
     733           0 :     return mDocumentURI;
     734             :   }
     735             : 
     736             :   /**
     737             :    * Return the base URI for relative URIs in the document (the document uri
     738             :    * unless it's overridden by SetBaseURI, HTML <base> tags, etc.).  The
     739             :    * returned URI could be null if there is no document URI.  If the document is
     740             :    * a srcdoc document and has no explicit base URL, return the parent
     741             :    * document's base URL.
     742             :    */
     743           0 :   nsIURI* GetDocBaseURI() const
     744             :   {
     745           0 :     if (mDocumentBaseURI) {
     746             :       return mDocumentBaseURI;
     747             :     }
     748           0 :     return GetFallbackBaseURI();
     749             :   }
     750             : 
     751             :   already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const final;
     752             : 
     753             :   void SetBaseURI(nsIURI* aURI);
     754             : 
     755             :   /**
     756             :    * Return the URL data which style system needs for resolving url value.
     757             :    * This method attempts to use the cached object in mCachedURLData, but
     758             :    * if the base URI, document URI, or principal has changed since last
     759             :    * call to this function, or the function is called the first time for
     760             :    * the document, a new one is created.
     761             :    */
     762             :   mozilla::URLExtraData* DefaultStyleAttrURLData();
     763             : 
     764             :   /**
     765             :    * Get/Set the base target of a link in a document.
     766             :    */
     767             :   void GetBaseTarget(nsAString& aBaseTarget) const
     768             :   {
     769           0 :     aBaseTarget = mBaseTarget;
     770             :   }
     771             : 
     772             :   void SetBaseTarget(const nsString& aBaseTarget) {
     773           0 :     mBaseTarget = aBaseTarget;
     774             :   }
     775             : 
     776             :   /**
     777             :    * Return a standard name for the document's character set.
     778             :    */
     779             :   NotNull<const Encoding*> GetDocumentCharacterSet() const
     780             :   {
     781             :     return mCharacterSet;
     782             :   }
     783             : 
     784             :   /**
     785             :    * Set the document's character encoding.
     786             :    */
     787             :   virtual void SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding);
     788             : 
     789             :   int32_t GetDocumentCharacterSetSource() const
     790             :   {
     791             :     return mCharacterSetSource;
     792             :   }
     793             : 
     794             :   // This method MUST be called before SetDocumentCharacterSet if
     795             :   // you're planning to call both.
     796             :   void SetDocumentCharacterSetSource(int32_t aCharsetSource)
     797             :   {
     798           0 :     mCharacterSetSource = aCharsetSource;
     799             :   }
     800             : 
     801             :   /**
     802             :    * Get the Content-Type of this document.
     803             :    */
     804             :   void GetContentType(nsAString& aContentType);
     805             : 
     806             :   /**
     807             :    * Set the Content-Type of this document.
     808             :    */
     809             :   virtual void SetContentType(const nsAString& aContentType);
     810             : 
     811             :   /**
     812             :    * Return the language of this document.
     813             :    */
     814             :   void GetContentLanguage(nsAString& aContentLanguage) const
     815             :   {
     816           0 :     CopyASCIItoUTF16(mContentLanguage, aContentLanguage);
     817             :   }
     818             : 
     819             :   // The states BidiEnabled and MathMLEnabled should persist across multiple views
     820             :   // (screen, print) of the same document.
     821             : 
     822             :   /**
     823             :    * Check if the document contains bidi data.
     824             :    * If so, we have to apply the Unicode Bidi Algorithm.
     825             :    */
     826             :   bool GetBidiEnabled() const
     827             :   {
     828             :     return mBidiEnabled;
     829             :   }
     830             : 
     831             :   /**
     832             :    * Indicate the document contains bidi data.
     833             :    * Currently, we cannot disable bidi, because once bidi is enabled,
     834             :    * it affects a frame model irreversibly, and plays even though
     835             :    * the document no longer contains bidi data.
     836             :    */
     837             :   void SetBidiEnabled()
     838             :   {
     839             :     mBidiEnabled = true;
     840             :   }
     841             : 
     842             :   /**
     843             :    * Check if the document contains (or has contained) any MathML elements.
     844             :    */
     845             :   bool GetMathMLEnabled() const
     846             :   {
     847           0 :     return mMathMLEnabled;
     848             :   }
     849             : 
     850             :   void SetMathMLEnabled()
     851             :   {
     852           0 :     mMathMLEnabled = true;
     853             :   }
     854             : 
     855             :   /**
     856             :    * Ask this document whether it's the initial document in its window.
     857             :    */
     858             :   bool IsInitialDocument() const
     859             :   {
     860           0 :     return mIsInitialDocumentInWindow;
     861             :   }
     862             : 
     863             :   /**
     864             :    * Tell this document that it's the initial document in its window.  See
     865             :    * comments on mIsInitialDocumentInWindow for when this should be called.
     866             :    */
     867             :   void SetIsInitialDocument(bool aIsInitialDocument)
     868             :   {
     869           0 :     mIsInitialDocumentInWindow = aIsInitialDocument;
     870             :   }
     871             : 
     872             :   /**
     873             :    * Normally we assert if a runnable labeled with one DocGroup touches data
     874             :    * from another DocGroup. Calling IgnoreDocGroupMismatches() on a document
     875             :    * means that we can touch that document from any DocGroup without asserting.
     876             :    */
     877             :   void IgnoreDocGroupMismatches()
     878             :   {
     879             :     mIgnoreDocGroupMismatches = true;
     880             :   }
     881             : 
     882             :   /**
     883             :    * Get the bidi options for this document.
     884             :    * @see nsBidiUtils.h
     885             :    */
     886             :   uint32_t GetBidiOptions() const
     887             :   {
     888             :     return mBidiOptions;
     889             :   }
     890             : 
     891             :   /**
     892             :    * Set the bidi options for this document.  This just sets the bits;
     893             :    * callers are expected to take action as needed if they want this
     894             :    * change to actually change anything immediately.
     895             :    * @see nsBidiUtils.h
     896             :    */
     897             :   void SetBidiOptions(uint32_t aBidiOptions)
     898             :   {
     899             :     mBidiOptions = aBidiOptions;
     900             :   }
     901             : 
     902             :   /**
     903             :    * Get the has mixed active content loaded flag for this document.
     904             :    */
     905             :   bool GetHasMixedActiveContentLoaded()
     906             :   {
     907           0 :     return mHasMixedActiveContentLoaded;
     908             :   }
     909             : 
     910             :   /**
     911             :    * Set the has mixed active content loaded flag for this document.
     912             :    */
     913             :   void SetHasMixedActiveContentLoaded(bool aHasMixedActiveContentLoaded)
     914             :   {
     915           0 :     mHasMixedActiveContentLoaded = aHasMixedActiveContentLoaded;
     916             :   }
     917             : 
     918             :   /**
     919             :    * Get mixed active content blocked flag for this document.
     920             :    */
     921             :   bool GetHasMixedActiveContentBlocked()
     922             :   {
     923           0 :     return mHasMixedActiveContentBlocked;
     924             :   }
     925             : 
     926             :   /**
     927             :    * Set the mixed active content blocked flag for this document.
     928             :    */
     929             :   void SetHasMixedActiveContentBlocked(bool aHasMixedActiveContentBlocked)
     930             :   {
     931           0 :     mHasMixedActiveContentBlocked = aHasMixedActiveContentBlocked;
     932             :   }
     933             : 
     934             :   /**
     935             :    * Get the has mixed display content loaded flag for this document.
     936             :    */
     937             :   bool GetHasMixedDisplayContentLoaded()
     938             :   {
     939           0 :     return mHasMixedDisplayContentLoaded;
     940             :   }
     941             : 
     942             :   /**
     943             :    * Set the has mixed display content loaded flag for this document.
     944             :    */
     945             :   void SetHasMixedDisplayContentLoaded(bool aHasMixedDisplayContentLoaded)
     946             :   {
     947           0 :     mHasMixedDisplayContentLoaded = aHasMixedDisplayContentLoaded;
     948             :   }
     949             : 
     950             :   /**
     951             :    * Get mixed display content blocked flag for this document.
     952             :    */
     953             :   bool GetHasMixedDisplayContentBlocked()
     954             :   {
     955           0 :     return mHasMixedDisplayContentBlocked;
     956             :   }
     957             : 
     958             :   /**
     959             :    * Set the mixed display content blocked flag for this document.
     960             :    */
     961             :   void SetHasMixedDisplayContentBlocked(bool aHasMixedDisplayContentBlocked)
     962             :   {
     963           0 :     mHasMixedDisplayContentBlocked = aHasMixedDisplayContentBlocked;
     964             :   }
     965             : 
     966             :   /**
     967             :    * Set the mixed content object subrequest flag for this document.
     968             :    */
     969             :   void SetHasMixedContentObjectSubrequest(bool aHasMixedContentObjectSubrequest)
     970             :   {
     971           0 :     mHasMixedContentObjectSubrequest = aHasMixedContentObjectSubrequest;
     972             :   }
     973             : 
     974             :   /**
     975             :    * Set CSP flag for this document.
     976             :    */
     977             :   void SetHasCSP(bool aHasCSP)
     978             :   {
     979           4 :     mHasCSP = aHasCSP;
     980             :   }
     981             : 
     982             :   /**
     983             :    * Set unsafe-inline CSP flag for this document.
     984             :    */
     985             :   void SetHasUnsafeInlineCSP(bool aHasUnsafeInlineCSP)
     986             :   {
     987           4 :     mHasUnsafeInlineCSP = aHasUnsafeInlineCSP;
     988             :   }
     989             : 
     990             :   /**
     991             :    * Set unsafe-eval CSP flag for this document.
     992             :    */
     993             :   void SetHasUnsafeEvalCSP(bool aHasUnsafeEvalCSP)
     994             :   {
     995           4 :     mHasUnsafeEvalCSP = aHasUnsafeEvalCSP;
     996             :   }
     997             : 
     998             :   /**
     999             :    * Get tracking content blocked flag for this document.
    1000             :    */
    1001             :   bool GetHasTrackingContentBlocked()
    1002             :   {
    1003             :     return mHasTrackingContentBlocked;
    1004             :   }
    1005             : 
    1006             :   /**
    1007             :    * Set the tracking content blocked flag for this document.
    1008             :    */
    1009             :   void SetHasTrackingContentBlocked(bool aHasTrackingContentBlocked)
    1010             :   {
    1011             :     mHasTrackingContentBlocked = aHasTrackingContentBlocked;
    1012             :   }
    1013             : 
    1014             :   /**
    1015             :    * Get tracking content loaded flag for this document.
    1016             :    */
    1017             :   bool GetHasTrackingContentLoaded()
    1018             :   {
    1019             :     return mHasTrackingContentLoaded;
    1020             :   }
    1021             : 
    1022             :   /**
    1023             :    * Set the tracking content loaded flag for this document.
    1024             :    */
    1025             :   void SetHasTrackingContentLoaded(bool aHasTrackingContentLoaded)
    1026             :   {
    1027             :     mHasTrackingContentLoaded = aHasTrackingContentLoaded;
    1028             :   }
    1029             : 
    1030             :   /**
    1031             :    * Get the sandbox flags for this document.
    1032             :    * @see nsSandboxFlags.h for the possible flags
    1033             :    */
    1034             :   uint32_t GetSandboxFlags() const
    1035             :   {
    1036             :     return mSandboxFlags;
    1037             :   }
    1038             : 
    1039             :   /**
    1040             :    * Get string representation of sandbox flags (null if no flags are set)
    1041             :    */
    1042             :   void GetSandboxFlagsAsString(nsAString& aFlags);
    1043             : 
    1044             :   /**
    1045             :    * Set the sandbox flags for this document.
    1046             :    * @see nsSandboxFlags.h for the possible flags
    1047             :    */
    1048             :   void SetSandboxFlags(uint32_t sandboxFlags)
    1049             :   {
    1050             :     mSandboxFlags = sandboxFlags;
    1051             :   }
    1052             : 
    1053             :   /**
    1054             :    * Called when the document was decoded as UTF-8 and decoder encountered no
    1055             :    * errors.
    1056             :    */
    1057             :   void EnableEncodingMenu()
    1058             :   {
    1059             :     mEncodingMenuDisabled = false;
    1060             :   }
    1061             : 
    1062             :   /**
    1063             :    * Access HTTP header data (this may also get set from other
    1064             :    * sources, like HTML META tags).
    1065             :    */
    1066             :   void GetHeaderData(nsAtom* aHeaderField, nsAString& aData) const;
    1067             :   void SetHeaderData(nsAtom* aheaderField, const nsAString& aData);
    1068             : 
    1069             :   /**
    1070             :    * Create a new presentation shell that will use aContext for its
    1071             :    * presentation context (presentation contexts <b>must not</b> be
    1072             :    * shared among multiple presentation shells). The caller of this
    1073             :    * method is responsible for calling BeginObservingDocument() on the
    1074             :    * presshell if the presshell should observe document mutations.
    1075             :    */
    1076             :   already_AddRefed<nsIPresShell> CreateShell(
    1077             :     nsPresContext* aContext,
    1078             :     nsViewManager* aViewManager,
    1079             :     mozilla::UniquePtr<mozilla::ServoStyleSet> aStyleSet);
    1080             :   void DeleteShell();
    1081             : 
    1082             :   nsIPresShell* GetShell() const
    1083             :   {
    1084           0 :     return GetBFCacheEntry() ? nullptr : mPresShell;
    1085             :   }
    1086             : 
    1087             :   nsIPresShell* GetObservingShell() const
    1088             :   {
    1089             :     return mPresShell && mPresShell->IsObservingDocument()
    1090             :       ? mPresShell : nullptr;
    1091             :   }
    1092             : 
    1093             :   // Return whether the presshell for this document is safe to flush.
    1094             :   bool IsSafeToFlush() const;
    1095             : 
    1096           0 :   nsPresContext* GetPresContext() const
    1097             :   {
    1098           0 :     nsIPresShell* shell = GetShell();
    1099           2 :     return shell ? shell->GetPresContext() : nullptr;
    1100             :   }
    1101             : 
    1102             :   bool HasShellOrBFCacheEntry() const
    1103             :   {
    1104             :     return mPresShell || mBFCacheEntry;
    1105             :   }
    1106             : 
    1107             :   // Instead using this method, what you probably want is
    1108             :   // RemoveFromBFCacheSync() as we do in MessagePort and BroadcastChannel.
    1109           0 :   void DisallowBFCaching()
    1110             :   {
    1111           0 :     NS_ASSERTION(!mBFCacheEntry, "We're already in the bfcache!");
    1112           0 :     mBFCacheDisallowed = true;
    1113           0 :   }
    1114             : 
    1115             :   bool IsBFCachingAllowed() const
    1116             :   {
    1117             :     return !mBFCacheDisallowed;
    1118             :   }
    1119             : 
    1120             :   // Accepts null to clear the BFCache entry too.
    1121             :   void SetBFCacheEntry(nsIBFCacheEntry* aEntry);
    1122             : 
    1123             :   nsIBFCacheEntry* GetBFCacheEntry() const
    1124             :   {
    1125             :     return mBFCacheEntry;
    1126             :   }
    1127             : 
    1128             :   /**
    1129             :    * Return the parent document of this document. Will return null
    1130             :    * unless this document is within a compound document and has a
    1131             :    * parent. Note that this parent chain may cross chrome boundaries.
    1132             :    */
    1133             :   nsIDocument *GetParentDocument() const
    1134             :   {
    1135             :     return mParentDocument;
    1136             :   }
    1137             : 
    1138             :   /**
    1139             :    * Set the parent document of this document.
    1140             :    */
    1141             :   void SetParentDocument(nsIDocument* aParent)
    1142             :   {
    1143             :     mParentDocument = aParent;
    1144             :     if (aParent) {
    1145             :       mIgnoreDocGroupMismatches = aParent->mIgnoreDocGroupMismatches;
    1146             :     }
    1147             :   }
    1148             : 
    1149             :   /**
    1150             :    * Are plugins allowed in this document ?
    1151             :    */
    1152             :   bool GetAllowPlugins();
    1153             : 
    1154             :   /**
    1155             :    * Set the sub document for aContent to aSubDoc.
    1156             :    */
    1157             :   nsresult SetSubDocumentFor(Element* aContent, nsIDocument* aSubDoc);
    1158             : 
    1159             :   /**
    1160             :    * Get the sub document for aContent
    1161             :    */
    1162             :   nsIDocument* GetSubDocumentFor(nsIContent* aContent) const;
    1163             : 
    1164             :   /**
    1165             :    * Find the content node for which aDocument is a sub document.
    1166             :    */
    1167             :   Element* FindContentForSubDocument(nsIDocument* aDocument) const;
    1168             : 
    1169             :   /**
    1170             :    * Return the doctype for this document.
    1171             :    */
    1172             :   mozilla::dom::DocumentType* GetDoctype() const;
    1173             : 
    1174             :   /**
    1175             :    * Return the root element for this document.
    1176             :    */
    1177             :   Element* GetRootElement() const;
    1178             : 
    1179             :   mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aRv);
    1180             : 
    1181             :   /**
    1182             :    * Gets the event target to dispatch key events to if there is no focused
    1183             :    * content in the document.
    1184             :    */
    1185             :   virtual nsIContent* GetUnfocusedKeyEventTarget();
    1186             : 
    1187             :   /**
    1188             :    * Retrieve information about the viewport as a data structure.
    1189             :    * This will return information in the viewport META data section
    1190             :    * of the document. This can be used in lieu of ProcessViewportInfo(),
    1191             :    * which places the viewport information in the document header instead
    1192             :    * of returning it directly.
    1193             :    *
    1194             :    * @param aDisplaySize size of the on-screen display area for this
    1195             :    * document, in device pixels.
    1196             :    *
    1197             :    * NOTE: If the site is optimized for mobile (via the doctype), this
    1198             :    * will return viewport information that specifies default information.
    1199             :    */
    1200             :   nsViewportInfo GetViewportInfo(const mozilla::ScreenIntSize& aDisplaySize);
    1201             : 
    1202             :   /**
    1203             :    * It updates the viewport overflow type with the given two widths
    1204             :    * and the viewport setting of the document.
    1205             :    * This should only be called when there is out-of-reach overflow
    1206             :    * happens on the viewport, i.e. the viewport should be using
    1207             :    * `overflow: hidden`. And it should only be called on a top level
    1208             :    * content document.
    1209             :    */
    1210             :   void UpdateViewportOverflowType(nscoord aScrolledWidth,
    1211             :                                   nscoord aScrollportWidth);
    1212             : 
    1213             :   /**
    1214             :    * True iff this doc will ignore manual character encoding overrides.
    1215             :    */
    1216           0 :   virtual bool WillIgnoreCharsetOverride() {
    1217           0 :     return true;
    1218             :   }
    1219             : 
    1220             :   /**
    1221             :    * Return whether the document was created by a srcdoc iframe.
    1222             :    */
    1223             :   bool IsSrcdocDocument() const {
    1224             :     return mIsSrcdocDocument;
    1225             :   }
    1226             : 
    1227             :   /**
    1228             :    * Sets whether the document was created by a srcdoc iframe.
    1229             :    */
    1230             :   void SetIsSrcdocDocument(bool aIsSrcdocDocument) {
    1231             :     mIsSrcdocDocument = aIsSrcdocDocument;
    1232             :   }
    1233             : 
    1234             :   /*
    1235             :    * Gets the srcdoc string from within the channel (assuming both exist).
    1236             :    * Returns a void string if this isn't a srcdoc document or if
    1237             :    * the channel has not been set.
    1238             :    */
    1239             :   nsresult GetSrcdocData(nsAString& aSrcdocData);
    1240             : 
    1241             :   bool DidDocumentOpen() {
    1242             :     return mDidDocumentOpen;
    1243             :   }
    1244             : 
    1245             :   already_AddRefed<mozilla::dom::AnonymousContent>
    1246             :   InsertAnonymousContent(mozilla::dom::Element& aElement,
    1247             :                          mozilla::ErrorResult& aError);
    1248             :   void RemoveAnonymousContent(mozilla::dom::AnonymousContent& aContent,
    1249             :                               mozilla::ErrorResult& aError);
    1250             :   /**
    1251             :    * If aNode is a descendant of anonymous content inserted by
    1252             :    * InsertAnonymousContent, this method returns the root element of the
    1253             :    * inserted anonymous content (in other words, the clone of the aElement
    1254             :    * that was passed to InsertAnonymousContent).
    1255             :    */
    1256             :   Element* GetAnonRootIfInAnonymousContentContainer(nsINode* aNode) const;
    1257             :   nsTArray<RefPtr<mozilla::dom::AnonymousContent>>& GetAnonymousContents() {
    1258             :     return mAnonymousContents;
    1259             :   }
    1260             : 
    1261             :   mozilla::TimeStamp GetPageUnloadingEventTimeStamp() const
    1262             :   {
    1263             :     if (!mParentDocument) {
    1264             :       return mPageUnloadingEventTimeStamp;
    1265             :     }
    1266             : 
    1267             :     mozilla::TimeStamp parentTimeStamp(mParentDocument->GetPageUnloadingEventTimeStamp());
    1268             :     if (parentTimeStamp.IsNull()) {
    1269             :       return mPageUnloadingEventTimeStamp;
    1270             :     }
    1271             : 
    1272             :     if (!mPageUnloadingEventTimeStamp ||
    1273             :         parentTimeStamp < mPageUnloadingEventTimeStamp) {
    1274             :       return parentTimeStamp;
    1275             :     }
    1276             : 
    1277             :     return mPageUnloadingEventTimeStamp;
    1278             :   }
    1279             : 
    1280             :   void NotifyLayerManagerRecreated();
    1281             : 
    1282             :   /**
    1283             :    * Add an SVG element to the list of elements that need
    1284             :    * their mapped attributes resolved to a Servo declaration block.
    1285             :    *
    1286             :    * These are weak pointers, please manually unschedule them when an element
    1287             :    * is removed.
    1288             :    */
    1289             :   void ScheduleSVGForPresAttrEvaluation(nsSVGElement* aSVG)
    1290             :   {
    1291             :     mLazySVGPresElements.PutEntry(aSVG);
    1292             :   }
    1293             : 
    1294             :   // Unschedule an element scheduled by ScheduleFrameRequestCallback (e.g. for
    1295             :   // when it is destroyed)
    1296             :   void UnscheduleSVGForPresAttrEvaluation(nsSVGElement* aSVG)
    1297             :   {
    1298             :     mLazySVGPresElements.RemoveEntry(aSVG);
    1299             :   }
    1300             : 
    1301             :   // Resolve all SVG pres attrs scheduled in ScheduleSVGForPresAttrEvaluation
    1302             :   void ResolveScheduledSVGPresAttrs();
    1303             : 
    1304             :   mozilla::Maybe<mozilla::dom::ClientInfo> GetClientInfo() const;
    1305             :   mozilla::Maybe<mozilla::dom::ClientState> GetClientState() const;
    1306             :   mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController() const;
    1307             : 
    1308             :   // Returns the size of the mBlockedTrackingNodes array.
    1309             :   //
    1310             :   // This array contains nodes that have been blocked to prevent
    1311             :   // user tracking. They most likely have had their nsIChannel
    1312             :   // canceled by the URL classifier (Safebrowsing).
    1313             :   //
    1314             :   // A script can subsequently use GetBlockedTrackingNodes()
    1315             :   // to get a list of references to these nodes.
    1316             :   //
    1317             :   // Note:
    1318             :   // This expresses how many tracking nodes have been blocked for this
    1319             :   // document since its beginning, not how many of them are still around
    1320             :   // in the DOM tree. Weak references to blocked nodes are added in the
    1321             :   // mBlockedTrackingNodesArray but they are not removed when those nodes
    1322             :   // are removed from the tree or even garbage collected.
    1323             :   long BlockedTrackingNodeCount() const
    1324             :   {
    1325             :     return mBlockedTrackingNodes.Length();
    1326             :   }
    1327             : 
    1328             :   //
    1329             :   // Returns strong references to mBlockedTrackingNodes. (nsIDocument.h)
    1330             :   //
    1331             :   // This array contains nodes that have been blocked to prevent
    1332             :   // user tracking. They most likely have had their nsIChannel
    1333             :   // canceled by the URL classifier (Safebrowsing).
    1334             :   //
    1335             :   already_AddRefed<nsSimpleContentList> BlockedTrackingNodes() const;
    1336             : 
    1337             : protected:
    1338             :   friend class nsUnblockOnloadEvent;
    1339             : 
    1340             :   nsresult InitCSP(nsIChannel* aChannel);
    1341             : 
    1342             :   void PostUnblockOnloadEvent();
    1343             : 
    1344             :   void DoUnblockOnload();
    1345             : 
    1346             :   void ClearAllBoxObjects();
    1347             : 
    1348             :   void MaybeEndOutermostXBLUpdate();
    1349             : 
    1350             :   void DispatchContentLoadedEvents();
    1351             : 
    1352             :   void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget,
    1353             :                               const nsAString& aType,
    1354             :                               bool aPersisted);
    1355             : 
    1356             :   // Call this before the document does something that will unbind all content.
    1357             :   // That will stop us from doing a lot of work as each element is removed.
    1358             :   void DestroyElementMaps();
    1359             : 
    1360             :   Element* GetRootElementInternal() const;
    1361             :   void DoNotifyPossibleTitleChange();
    1362             : 
    1363             :   void SetPageUnloadingEventTimeStamp()
    1364             :   {
    1365             :     MOZ_ASSERT(!mPageUnloadingEventTimeStamp);
    1366             :     mPageUnloadingEventTimeStamp = mozilla::TimeStamp::NowLoRes();
    1367             :   }
    1368             : 
    1369             :   void CleanUnloadEventsTimeStamp()
    1370             :   {
    1371             :     MOZ_ASSERT(mPageUnloadingEventTimeStamp);
    1372             :     mPageUnloadingEventTimeStamp = mozilla::TimeStamp();
    1373             :   }
    1374             : 
    1375             :   /**
    1376             :    * Clears any Servo element data stored on Elements in the document.
    1377             :    */
    1378             :   void ClearStaleServoData();
    1379             : 
    1380             : private:
    1381             :   class SelectorCacheKey
    1382             :   {
    1383             :     public:
    1384             :       explicit SelectorCacheKey(const nsAString& aString) : mKey(aString)
    1385             :       {
    1386             :         MOZ_COUNT_CTOR(SelectorCacheKey);
    1387             :       }
    1388             : 
    1389             :       nsString mKey;
    1390             :       nsExpirationState mState;
    1391             : 
    1392             :       nsExpirationState* GetExpirationState() { return &mState; }
    1393             : 
    1394             :       ~SelectorCacheKey()
    1395             :       {
    1396             :         MOZ_COUNT_DTOR(SelectorCacheKey);
    1397             :       }
    1398             :   };
    1399             : 
    1400             :   class SelectorCacheKeyDeleter;
    1401             : 
    1402             : public:
    1403             :   class SelectorCache final
    1404             :     : public nsExpirationTracker<SelectorCacheKey, 4>
    1405             :   {
    1406             :   public:
    1407             :     using SelectorList = mozilla::UniquePtr<RawServoSelectorList>;
    1408             : 
    1409             :     explicit SelectorCache(nsIEventTarget* aEventTarget);
    1410             : 
    1411             :     void CacheList(const nsAString& aSelector, SelectorList aSelectorList)
    1412             :     {
    1413             :       MOZ_ASSERT(NS_IsMainThread());
    1414             :       SelectorCacheKey* key = new SelectorCacheKey(aSelector);
    1415             :       mTable.Put(key->mKey, std::move(aSelectorList));
    1416             :       AddObject(key);
    1417             :     }
    1418             : 
    1419             :     void NotifyExpired(SelectorCacheKey* aSelector) final;
    1420             : 
    1421             :     // We do not call MarkUsed because it would just slow down lookups and
    1422             :     // because we're OK expiring things after a few seconds even if they're
    1423             :     // being used.  Returns whether we actually had an entry for aSelector.
    1424             :     //
    1425             :     // If we have an entry and the selector list returned has a null
    1426             :     // RawServoSelectorList*, that indicates that aSelector has already been
    1427             :     // parsed and is not a syntactically valid selector.
    1428             :     SelectorList* GetList(const nsAString& aSelector)
    1429             :     {
    1430             :       return mTable.GetValue(aSelector);
    1431             :     }
    1432             : 
    1433             :     ~SelectorCache();
    1434             : 
    1435             :   private:
    1436             :     nsDataHashtable<nsStringHashKey, SelectorList> mTable;
    1437             :   };
    1438             : 
    1439             :   SelectorCache& GetSelectorCache() {
    1440             :     if (!mSelectorCache) {
    1441             :       mSelectorCache =
    1442             :         mozilla::MakeUnique<SelectorCache>(
    1443             :           EventTargetFor(mozilla::TaskCategory::Other));
    1444             :     }
    1445             :     return *mSelectorCache;
    1446             :   }
    1447             :   // Get the root <html> element, or return null if there isn't one (e.g.
    1448             :   // if the root isn't <html>)
    1449             :   Element* GetHtmlElement() const;
    1450             :   // Returns the first child of GetHtmlContent which has the given tag,
    1451             :   // or nullptr if that doesn't exist.
    1452             :   Element* GetHtmlChildElement(nsAtom* aTag);
    1453             :   // Get the canonical <body> element, or return null if there isn't one (e.g.
    1454             :   // if the root isn't <html> or if the <body> isn't there)
    1455             :   mozilla::dom::HTMLBodyElement* GetBodyElement();
    1456             :   // Get the canonical <head> element, or return null if there isn't one (e.g.
    1457             :   // if the root isn't <html> or if the <head> isn't there)
    1458           0 :   Element* GetHeadElement() {
    1459           0 :     return GetHtmlChildElement(nsGkAtoms::head);
    1460             :   }
    1461             :   // Get the "body" in the sense of document.body: The first <body> or
    1462             :   // <frameset> that's a child of a root <html>
    1463             :   nsGenericHTMLElement* GetBody();
    1464             :   // Set the "body" in the sense of document.body.
    1465             :   void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv);
    1466             :   // Get the "head" element in the sense of document.head.
    1467             :   mozilla::dom::HTMLSharedElement* GetHead();
    1468             : 
    1469             :   /**
    1470             :    * Accessors to the collection of stylesheets owned by this document.
    1471             :    * Style sheets are ordered, most significant last.
    1472             :    */
    1473             : 
    1474             :   /**
    1475             :    * These exists to allow us to on-demand load user-agent style sheets that
    1476             :    * would otherwise be loaded by nsDocumentViewer::CreateStyleSet. This allows
    1477             :    * us to keep the memory used by a document's rule cascade data (the stuff in
    1478             :    * its nsStyleSet's nsCSSRuleProcessors) - which can be considerable - lower
    1479             :    * than it would be if we loaded all built-in user-agent style sheets up
    1480             :    * front.
    1481             :    *
    1482             :    * By "built-in" user-agent style sheets we mean the user-agent style sheets
    1483             :    * that gecko itself supplies (such as html.css and svg.css) as opposed to
    1484             :    * user-agent level style sheets inserted by add-ons or the like.
    1485             :    *
    1486             :    * This function prepends the given style sheet to the document's style set
    1487             :    * in order to make sure that it does not override user-agent style sheets
    1488             :    * supplied by add-ons or by the app (Firefox OS or Firefox Mobile, for
    1489             :    * example), since their sheets should override built-in sheets.
    1490             :    *
    1491             :    * TODO We can get rid of the whole concept of delayed loading if we fix
    1492             :    * bug 77999.
    1493             :    */
    1494             :   void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
    1495             : 
    1496             :   mozilla::dom::StyleSheetList* StyleSheets()
    1497             :   {
    1498             :     return &DocumentOrShadowRoot::EnsureDOMStyleSheets();
    1499             :   }
    1500             : 
    1501             :   /**
    1502             :    * Insert a sheet at a particular spot in the stylesheet list (zero-based)
    1503             :    * @param aSheet the sheet to insert
    1504             :    * @param aIndex the index to insert at.
    1505             :    * @throws no exceptions
    1506             :    */
    1507             :   void InsertStyleSheetAt(mozilla::StyleSheet* aSheet, size_t aIndex);
    1508             : 
    1509             : 
    1510             :   /**
    1511             :    * Replace the stylesheets in aOldSheets with the stylesheets in
    1512             :    * aNewSheets. The two lists must have equal length, and the sheet
    1513             :    * at positon J in the first list will be replaced by the sheet at
    1514             :    * position J in the second list.  Some sheets in the second list
    1515             :    * may be null; if so the corresponding sheets in the first list
    1516             :    * will simply be removed.
    1517             :    */
    1518             :   void UpdateStyleSheets(
    1519             :       nsTArray<RefPtr<mozilla::StyleSheet>>& aOldSheets,
    1520             :       nsTArray<RefPtr<mozilla::StyleSheet>>& aNewSheets);
    1521             : 
    1522             :   /**
    1523             :    * Add a stylesheet to the document
    1524             :    */
    1525             :   void AddStyleSheet(mozilla::StyleSheet* aSheet);
    1526             : 
    1527             :   /**
    1528             :    * Remove a stylesheet from the document
    1529             :    */
    1530             :   void RemoveStyleSheet(mozilla::StyleSheet* aSheet);
    1531             : 
    1532             :   /**
    1533             :    * Notify the document that the applicable state of the sheet changed
    1534             :    * and that observers should be notified and style sets updated
    1535             :    */
    1536             :   void SetStyleSheetApplicableState(mozilla::StyleSheet* aSheet,
    1537             :                                     bool aApplicable);
    1538             : 
    1539             :   enum additionalSheetType {
    1540             :     eAgentSheet,
    1541             :     eUserSheet,
    1542             :     eAuthorSheet,
    1543             :     AdditionalSheetTypeCount
    1544             :   };
    1545             : 
    1546             :   nsresult LoadAdditionalStyleSheet(additionalSheetType aType,
    1547             :                                     nsIURI* aSheetURI);
    1548             :   nsresult AddAdditionalStyleSheet(additionalSheetType aType,
    1549             :                                    mozilla::StyleSheet* aSheet);
    1550             :   void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI);
    1551             : 
    1552             :   mozilla::StyleSheet* GetFirstAdditionalAuthorSheet()
    1553             :   {
    1554             :     return mAdditionalSheets[eAuthorSheet].SafeElementAt(0);
    1555             :   }
    1556             : 
    1557             :   /**
    1558             :    * Assuming that aDocSheets is an array of document-level style
    1559             :    * sheets for this document, returns the index that aSheet should
    1560             :    * be inserted at to maintain document ordering.
    1561             :    *
    1562             :    * Type T has to cast to StyleSheet*.
    1563             :    *
    1564             :    * Defined in nsIDocumentInlines.h.
    1565             :    */
    1566             :   template<typename T>
    1567             :   size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
    1568             :                                          const mozilla::StyleSheet& aSheet);
    1569             : 
    1570             :   /**
    1571             :    * Get this document's CSSLoader.  This is guaranteed to not return null.
    1572             :    */
    1573             :   mozilla::css::Loader* CSSLoader() const {
    1574           0 :     return mCSSLoader;
    1575             :   }
    1576             : 
    1577             :   /**
    1578             :    * Get this document's StyleImageLoader.  This is guaranteed to not return null.
    1579             :    */
    1580             :   mozilla::css::ImageLoader* StyleImageLoader() const {
    1581             :     return mStyleImageLoader;
    1582             :   }
    1583             : 
    1584             :   /**
    1585             :    * Get the channel that was passed to StartDocumentLoad or Reset for this
    1586             :    * document.  Note that this may be null in some cases (eg if
    1587             :    * StartDocumentLoad or Reset were never called)
    1588             :    */
    1589             :   nsIChannel* GetChannel() const
    1590             :   {
    1591           0 :     return mChannel;
    1592             :   }
    1593             : 
    1594             :   /**
    1595             :    * Get this document's attribute stylesheet.  May return null if
    1596             :    * there isn't one.
    1597             :    */
    1598             :   nsHTMLStyleSheet* GetAttributeStyleSheet() const {
    1599           0 :     return mAttrStyleSheet;
    1600             :   }
    1601             : 
    1602             :   /**
    1603             :    * Get this document's inline style sheet.  May return null if there
    1604             :    * isn't one
    1605             :    */
    1606             :   nsHTMLCSSStyleSheet* GetInlineStyleSheet() const {
    1607             :     return mStyleAttrStyleSheet;
    1608             :   }
    1609             : 
    1610             :   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject);
    1611             : 
    1612             :   /**
    1613             :    * Get/set the object from which the context for the event/script handling can
    1614             :    * be got. Normally GetScriptHandlingObject() returns the same object as
    1615             :    * GetScriptGlobalObject(), but if the document is loaded as data,
    1616             :    * non-null may be returned, even if GetScriptGlobalObject() returns null.
    1617             :    * aHasHadScriptHandlingObject is set true if document has had the object
    1618             :    * for event/script handling. Do not process any events/script if the method
    1619             :    * returns null, but aHasHadScriptHandlingObject is true.
    1620             :    */
    1621             :   nsIScriptGlobalObject*
    1622           0 :     GetScriptHandlingObject(bool& aHasHadScriptHandlingObject) const
    1623             :   {
    1624           0 :     aHasHadScriptHandlingObject = mHasHadScriptHandlingObject;
    1625           0 :     return mScriptGlobalObject ? mScriptGlobalObject.get() :
    1626           0 :                                  GetScriptHandlingObjectInternal();
    1627             :   }
    1628             :   void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject);
    1629             : 
    1630             :   /**
    1631             :    * Get the object that is used as the scope for all of the content
    1632             :    * wrappers whose owner document is this document. Unlike the script global
    1633             :    * object, this will only return null when the global object for this
    1634             :    * document is truly gone. Use this object when you're trying to find a
    1635             :    * content wrapper in XPConnect.
    1636             :    */
    1637             :   nsIGlobalObject* GetScopeObject() const;
    1638             :   void SetScopeObject(nsIGlobalObject* aGlobal);
    1639             : 
    1640             :   /**
    1641             :    * Return the window containing the document (the outer window).
    1642             :    */
    1643           0 :   nsPIDOMWindowOuter *GetWindow() const
    1644             :   {
    1645           0 :     return mWindow ? mWindow->GetOuterWindow() : GetWindowInternal();
    1646             :   }
    1647             : 
    1648             :   bool IsInBackgroundWindow() const
    1649             :   {
    1650             :     auto* outer = mWindow ? mWindow->GetOuterWindow() : nullptr;
    1651             :     return outer && outer->IsBackground();
    1652             :   }
    1653             : 
    1654             :   /**
    1655             :    * Return the inner window used as the script compilation scope for
    1656             :    * this document. If you're not absolutely sure you need this, use
    1657             :    * GetWindow().
    1658             :    */
    1659             :   nsPIDOMWindowInner* GetInnerWindow() const
    1660             :   {
    1661           0 :     return mRemovedFromDocShell ? nullptr : mWindow;
    1662             :   }
    1663             : 
    1664             :   /**
    1665             :    * Return the outer window ID.
    1666             :    */
    1667             :   uint64_t OuterWindowID() const
    1668             :   {
    1669             :     nsPIDOMWindowOuter* window = GetWindow();
    1670             :     return window ? window->WindowID() : 0;
    1671             :   }
    1672             : 
    1673             :   /**
    1674             :    * Return the inner window ID.
    1675             :    */
    1676           0 :   uint64_t InnerWindowID() const
    1677             :   {
    1678           0 :     nsPIDOMWindowInner* window = GetInnerWindow();
    1679           2 :     return window ? window->WindowID() : 0;
    1680             :   }
    1681             : 
    1682             :   bool IsTopLevelWindowInactive() const;
    1683             : 
    1684             :   /**
    1685             :    * Get the script loader for this document
    1686             :    */
    1687             :   mozilla::dom::ScriptLoader* ScriptLoader()
    1688             :   {
    1689           0 :     return mScriptLoader;
    1690             :   }
    1691             : 
    1692             :   /**
    1693             :    * Add/Remove an element to the document's id and name hashes
    1694             :    */
    1695             :   void AddToIdTable(Element* aElement, nsAtom* aId);
    1696             :   void RemoveFromIdTable(Element* aElement, nsAtom* aId);
    1697             :   void AddToNameTable(Element* aElement, nsAtom* aName);
    1698             :   void RemoveFromNameTable(Element* aElement, nsAtom* aName);
    1699             : 
    1700             :   /**
    1701             :    * Returns all elements in the fullscreen stack in the insertion order.
    1702             :    */
    1703             :   nsTArray<Element*> GetFullscreenStack() const;
    1704             : 
    1705             :   /**
    1706             :    * Asynchronously requests that the document make aElement the fullscreen
    1707             :    * element, and move into fullscreen mode. The current fullscreen element
    1708             :    * (if any) is pushed onto the fullscreen element stack, and it can be
    1709             :    * returned to fullscreen status by calling RestorePreviousFullScreenState().
    1710             :    *
    1711             :    * Note that requesting fullscreen in a document also makes the element which
    1712             :    * contains this document in this document's parent document fullscreen. i.e.
    1713             :    * the <iframe> or <browser> that contains this document is also mode
    1714             :    * fullscreen. This happens recursively in all ancestor documents.
    1715             :    */
    1716             :   void AsyncRequestFullScreen(mozilla::UniquePtr<FullscreenRequest>&&);
    1717             : 
    1718             :   // Do the "fullscreen element ready check" from the fullscreen spec.
    1719             :   // It returns true if the given element is allowed to go into fullscreen.
    1720             :   bool FullscreenElementReadyCheck(Element* aElement, bool aWasCallerChrome);
    1721             : 
    1722             :   // This is called asynchronously by nsIDocument::AsyncRequestFullScreen()
    1723             :   // to move this document into full-screen mode if allowed.
    1724             :   void RequestFullScreen(mozilla::UniquePtr<FullscreenRequest>&& aRequest);
    1725             : 
    1726             :   // Removes all elements from the full-screen stack, removing full-scren
    1727             :   // styles from the top element in the stack.
    1728             :   void CleanupFullscreenState();
    1729             : 
    1730             :   // Pushes aElement onto the full-screen stack, and removes full-screen styles
    1731             :   // from the former full-screen stack top, and its ancestors, and applies the
    1732             :   // styles to aElement. aElement becomes the new "full-screen element".
    1733             :   bool FullScreenStackPush(Element* aElement);
    1734             : 
    1735             :   // Remove the top element from the full-screen stack. Removes the full-screen
    1736             :   // styles from the former top element, and applies them to the new top
    1737             :   // element, if there is one.
    1738             :   void FullScreenStackPop();
    1739             : 
    1740             :   /**
    1741             :    * Called when a frame in a child process has entered fullscreen or when a
    1742             :    * fullscreen frame in a child process changes to another origin.
    1743             :    * aFrameElement is the frame element which contains the child-process
    1744             :    * fullscreen document.
    1745             :    */
    1746             :   nsresult RemoteFrameFullscreenChanged(mozilla::dom::Element* aFrameElement);
    1747             : 
    1748             :   /**
    1749             :    * Called when a frame in a remote child document has rolled back fullscreen
    1750             :    * so that all its fullscreen element stacks are empty; we must continue the
    1751             :    * rollback in this parent process' doc tree branch which is fullscreen.
    1752             :    * Note that only one branch of the document tree can have its documents in
    1753             :    * fullscreen state at one time. We're in inconsistent state if a
    1754             :    * fullscreen document has a parent and that parent isn't fullscreen. We
    1755             :    * preserve this property across process boundaries.
    1756             :    */
    1757             :    nsresult RemoteFrameFullscreenReverted();
    1758             : 
    1759             :   /**
    1760             :    * Restores the previous full-screen element to full-screen status. If there
    1761             :    * is no former full-screen element, this exits full-screen, moving the
    1762             :    * top-level browser window out of full-screen mode.
    1763             :    */
    1764             :   void RestorePreviousFullScreenState();
    1765             : 
    1766             :   /**
    1767             :    * Returns true if this document is a fullscreen leaf document, i.e. it
    1768             :    * is in fullscreen mode and has no fullscreen children.
    1769             :    */
    1770             :   bool IsFullscreenLeaf();
    1771             : 
    1772             :   /**
    1773             :    * Returns the document which is at the root of this document's branch
    1774             :    * in the in-process document tree. Returns nullptr if the document isn't
    1775             :    * fullscreen.
    1776             :    */
    1777             :   nsIDocument* GetFullscreenRoot();
    1778             : 
    1779             :   /**
    1780             :    * Sets the fullscreen root to aRoot. This stores a weak reference to aRoot
    1781             :    * in this document.
    1782             :    */
    1783             :   void SetFullscreenRoot(nsIDocument* aRoot);
    1784             : 
    1785             :   /**
    1786             :    * Synchronously cleans up the fullscreen state on the given document.
    1787             :    *
    1788             :    * Calling this without performing fullscreen transition could lead
    1789             :    * to undesired effect (the transition happens after document state
    1790             :    * flips), hence it should only be called either by nsGlobalWindow
    1791             :    * when we have performed the transition, or when it is necessary to
    1792             :    * clean up the state immediately. Otherwise, AsyncExitFullscreen()
    1793             :    * should be called instead.
    1794             :    *
    1795             :    * aDocument must not be null.
    1796             :    */
    1797             :   static void ExitFullscreenInDocTree(nsIDocument* aDocument);
    1798             : 
    1799             :   /**
    1800             :    * Ask the document to exit fullscreen state asynchronously.
    1801             :    *
    1802             :    * Different from ExitFullscreenInDocTree(), this allows the window
    1803             :    * to perform fullscreen transition first if any.
    1804             :    *
    1805             :    * If aDocument is null, it will exit fullscreen from all documents
    1806             :    * in all windows.
    1807             :    */
    1808             :   static void AsyncExitFullscreen(nsIDocument* aDocument);
    1809             : 
    1810             :   /**
    1811             :    * Handles any pending fullscreen in aDocument or its subdocuments.
    1812             :    *
    1813             :    * Returns whether there is any fullscreen request handled.
    1814             :    */
    1815             :   static bool HandlePendingFullscreenRequests(nsIDocument* aDocument);
    1816             : 
    1817             :   /**
    1818             :    * Dispatch fullscreenerror event and report the failure message to
    1819             :    * the console.
    1820             :    */
    1821             :   void DispatchFullscreenError(const char* aMessage);
    1822             : 
    1823             :   void RequestPointerLock(Element* aElement, mozilla::dom::CallerType);
    1824             :   bool SetPointerLock(Element* aElement, int aCursorStyle);
    1825             : 
    1826             :   static void UnlockPointer(nsIDocument* aDoc = nullptr);
    1827             : 
    1828             :   // ScreenOrientation related APIs
    1829             : 
    1830             :   void SetCurrentOrientation(mozilla::dom::OrientationType aType,
    1831             :                              uint16_t aAngle)
    1832             :   {
    1833             :     mCurrentOrientationType = aType;
    1834             :     mCurrentOrientationAngle = aAngle;
    1835             :   }
    1836             : 
    1837             :   uint16_t CurrentOrientationAngle() const
    1838             :   {
    1839             :     return mCurrentOrientationAngle;
    1840             :   }
    1841             :   mozilla::dom::OrientationType CurrentOrientationType() const
    1842             :   {
    1843             :     return mCurrentOrientationType;
    1844             :   }
    1845             :   void SetOrientationPendingPromise(mozilla::dom::Promise* aPromise);
    1846             :   mozilla::dom::Promise* GetOrientationPendingPromise() const
    1847             :   {
    1848             :     return mOrientationPendingPromise;
    1849             :   }
    1850             : 
    1851             :   //----------------------------------------------------------------------
    1852             : 
    1853             :   // Document notification API's
    1854             : 
    1855             :   /**
    1856             :    * Add a new observer of document change notifications. Whenever
    1857             :    * content is changed, appended, inserted or removed the observers are
    1858             :    * informed.  An observer that is already observing the document must
    1859             :    * not be added without being removed first.
    1860             :    */
    1861             :   void AddObserver(nsIDocumentObserver* aObserver);
    1862             : 
    1863             :   /**
    1864             :    * Remove an observer of document change notifications. This will
    1865             :    * return false if the observer cannot be found.
    1866             :    */
    1867             :   bool RemoveObserver(nsIDocumentObserver* aObserver);
    1868             : 
    1869             :   // Observation hooks used to propagate notifications to document observers.
    1870             :   // BeginUpdate must be called before any batch of modifications of the
    1871             :   // content model or of style data, EndUpdate must be called afterward.
    1872             :   // To make this easy and painless, use the mozAutoDocUpdate helper class.
    1873             :   void BeginUpdate();
    1874             :   virtual void EndUpdate() = 0;
    1875             : 
    1876             :   virtual void BeginLoad() = 0;
    1877             :   virtual void EndLoad() = 0;
    1878             : 
    1879             :   enum ReadyState { READYSTATE_UNINITIALIZED = 0, READYSTATE_LOADING = 1, READYSTATE_INTERACTIVE = 3, READYSTATE_COMPLETE = 4};
    1880             :   void SetReadyStateInternal(ReadyState rs);
    1881             :   ReadyState GetReadyStateEnum()
    1882             :   {
    1883             :     return mReadyState;
    1884             :   }
    1885             : 
    1886             :   // notify that a content node changed state.  This must happen under
    1887             :   // a scriptblocker but NOT within a begin/end update.
    1888             :   void ContentStateChanged(
    1889             :       nsIContent* aContent, mozilla::EventStates aStateMask);
    1890             : 
    1891             :   // Notify that a document state has changed.
    1892             :   // This should only be called by callers whose state is also reflected in the
    1893             :   // implementation of nsDocument::GetDocumentState.
    1894             :   void DocumentStatesChanged(mozilla::EventStates aStateMask);
    1895             : 
    1896             :   // Observation hooks for style data to propagate notifications
    1897             :   // to document observers
    1898             :   void StyleRuleChanged(mozilla::StyleSheet* aStyleSheet,
    1899             :                         mozilla::css::Rule* aStyleRule);
    1900             :   void StyleRuleAdded(mozilla::StyleSheet* aStyleSheet,
    1901             :                       mozilla::css::Rule* aStyleRule);
    1902             :   void StyleRuleRemoved(mozilla::StyleSheet* aStyleSheet,
    1903             :                         mozilla::css::Rule* aStyleRule);
    1904             : 
    1905             :   /**
    1906             :    * Flush notifications for this document and its parent documents
    1907             :    * (since those may affect the layout of this one).
    1908             :    */
    1909             :   void FlushPendingNotifications(mozilla::FlushType aType);
    1910             : 
    1911             :   /**
    1912             :    * Another variant of the above FlushPendingNotifications.  This function
    1913             :    * takes a ChangesToFlush to specify whether throttled animations are flushed
    1914             :    * or not.
    1915             :    * If in doublt, use the above FlushPendingNotifications.
    1916             :    */
    1917             :   void FlushPendingNotifications(mozilla::ChangesToFlush aFlush);
    1918             : 
    1919             :   /**
    1920             :    * Calls FlushPendingNotifications on any external resources this document
    1921             :    * has. If this document has no external resources or is an external resource
    1922             :    * itself this does nothing. This should only be called with
    1923             :    * aType >= FlushType::Style.
    1924             :    */
    1925             :   void FlushExternalResources(mozilla::FlushType aType);
    1926             : 
    1927             :   nsBindingManager* BindingManager() const
    1928             :   {
    1929           0 :     return mNodeInfoManager->GetBindingManager();
    1930             :   }
    1931             : 
    1932             :   /**
    1933             :    * Only to be used inside Gecko, you can't really do anything with the
    1934             :    * pointer outside Gecko anyway.
    1935             :    */
    1936             :   nsNodeInfoManager* NodeInfoManager() const
    1937             :   {
    1938             :     return mNodeInfoManager;
    1939             :   }
    1940             : 
    1941             :   /**
    1942             :    * Reset the document using the given channel and loadgroup.  This works
    1943             :    * like ResetToURI, but also sets the document's channel to aChannel.
    1944             :    * The principal of the document will be set from the channel.
    1945             :    */
    1946             :   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
    1947             : 
    1948             :   /**
    1949             :    * Reset this document to aURI, aLoadGroup, and aPrincipal.  aURI must not be
    1950             :    * null.  If aPrincipal is null, a codebase principal based on aURI will be
    1951             :    * used.
    1952             :    */
    1953             :   virtual void ResetToURI(nsIURI* aURI,
    1954             :                           nsILoadGroup* aLoadGroup,
    1955             :                           nsIPrincipal* aPrincipal);
    1956             : 
    1957             :   /**
    1958             :    * Set the container (docshell) for this document. Virtual so that
    1959             :    * docshell can call it.
    1960             :    */
    1961             :   virtual void SetContainer(nsDocShell* aContainer);
    1962             : 
    1963             :   /**
    1964             :    * Get the container (docshell) for this document.
    1965             :    */
    1966             :   virtual nsISupports* GetContainer() const;
    1967             : 
    1968             :   /**
    1969             :    * Get the container's load context for this document.
    1970             :    */
    1971             :   nsILoadContext* GetLoadContext() const;
    1972             : 
    1973             :   /**
    1974             :    * Get docshell the for this document.
    1975             :    */
    1976             :   nsIDocShell* GetDocShell() const;
    1977             : 
    1978             :   /**
    1979             :    * Set and get XML declaration. If aVersion is null there is no declaration.
    1980             :    * aStandalone takes values -1, 0 and 1 indicating respectively that there
    1981             :    * was no standalone parameter in the declaration, that it was given as no,
    1982             :    * or that it was given as yes.
    1983             :    */
    1984             :   void SetXMLDeclaration(const char16_t* aVersion,
    1985             :                          const char16_t* aEncoding,
    1986             :                          const int32_t aStandalone);
    1987             :   void GetXMLDeclaration(nsAString& aVersion,
    1988             :                          nsAString& aEncoding,
    1989             :                          nsAString& Standalone);
    1990             : 
    1991             :   /**
    1992             :    * Returns true if this is what HTML 5 calls an "HTML document" (for example
    1993             :    * regular HTML document with Content-Type "text/html", image documents and
    1994             :    * media documents).  Returns false for XHTML and any other documents parsed
    1995             :    * by the XML parser.
    1996             :    */
    1997             :   bool IsHTMLDocument() const
    1998             :   {
    1999           0 :     return mType == eHTML;
    2000             :   }
    2001             :   bool IsHTMLOrXHTML() const
    2002             :   {
    2003           0 :     return mType == eHTML || mType == eXHTML;
    2004             :   }
    2005             :   bool IsXMLDocument() const
    2006             :   {
    2007             :     return !IsHTMLDocument();
    2008             :   }
    2009             :   bool IsSVGDocument() const
    2010             :   {
    2011             :     return mType == eSVG;
    2012             :   }
    2013             :   bool IsXULDocument() const
    2014             :   {
    2015             :     return mType == eXUL;
    2016             :   }
    2017             :   bool IsUnstyledDocument()
    2018             :   {
    2019             :     return IsLoadedAsData() || IsLoadedAsInteractiveData();
    2020             :   }
    2021             :   bool LoadsFullXULStyleSheetUpFront()
    2022             :   {
    2023             :     return IsXULDocument() || AllowXULXBL();
    2024             :   }
    2025             : 
    2026             :   bool IsScriptEnabled();
    2027             : 
    2028             :   bool IsTopLevelContentDocument() const { return mIsTopLevelContentDocument; }
    2029             :   void SetIsTopLevelContentDocument(bool aIsTopLevelContentDocument)
    2030             :   {
    2031             :     mIsTopLevelContentDocument = aIsTopLevelContentDocument;
    2032             :     // When a document is set as TopLevelContentDocument, it must be
    2033             :     // allowpaymentrequest. We handle the false case while a document is appended
    2034             :     // in SetSubDocumentFor
    2035             :     if (aIsTopLevelContentDocument) {
    2036             :       SetAllowPaymentRequest(true);
    2037             :     }
    2038             :   }
    2039             : 
    2040             :   bool IsContentDocument() const { return mIsContentDocument; }
    2041             :   void SetIsContentDocument(bool aIsContentDocument)
    2042             :   {
    2043             :     mIsContentDocument = aIsContentDocument;
    2044             :   }
    2045             : 
    2046             :   /**
    2047             :    * Create an element with the specified name, prefix and namespace ID.
    2048             :    * Returns null if element name parsing failed.
    2049             :    */
    2050             :   already_AddRefed<Element> CreateElem(const nsAString& aName,
    2051             :                                        nsAtom* aPrefix,
    2052             :                                        int32_t aNamespaceID,
    2053             :                                        const nsAString* aIs = nullptr);
    2054             : 
    2055             :   /**
    2056             :    * Get the security info (i.e. SSL state etc) that the document got
    2057             :    * from the channel/document that created the content of the
    2058             :    * document.
    2059             :    *
    2060             :    * @see nsIChannel
    2061             :    */
    2062             :   nsISupports *GetSecurityInfo()
    2063             :   {
    2064           0 :     return mSecurityInfo;
    2065             :   }
    2066             : 
    2067             :   /**
    2068             :    * Get the channel that failed to load and resulted in an error page, if it
    2069             :    * exists. This is only relevant to error pages.
    2070             :    */
    2071             :   nsIChannel* GetFailedChannel() const
    2072             :   {
    2073             :     return mFailedChannel;
    2074             :   }
    2075             : 
    2076             :   /**
    2077             :    * Set the channel that failed to load and resulted in an error page.
    2078             :    * This is only relevant to error pages.
    2079             :    */
    2080             :   void SetFailedChannel(nsIChannel* aChannel)
    2081             :   {
    2082             :     mFailedChannel = aChannel;
    2083             :   }
    2084             : 
    2085             :   /**
    2086             :    * Returns the default namespace ID used for elements created in this
    2087             :    * document.
    2088             :    */
    2089             :   int32_t GetDefaultNamespaceID() const
    2090             :   {
    2091             :     return mDefaultElementType;
    2092             :   }
    2093             : 
    2094             :   void DeleteAllProperties();
    2095             :   void DeleteAllPropertiesFor(nsINode* aNode);
    2096             : 
    2097             :   nsPropertyTable& PropertyTable()
    2098             :   {
    2099             :     return mPropertyTable;
    2100             :   }
    2101             : 
    2102             :   /**
    2103             :    * Sets the ID used to identify this part of the multipart document
    2104             :    */
    2105             :   void SetPartID(uint32_t aID) {
    2106             :     mPartID = aID;
    2107             :   }
    2108             : 
    2109             :   /**
    2110             :    * Return the ID used to identify this part of the multipart document
    2111             :    */
    2112             :   uint32_t GetPartID() const {
    2113             :     return mPartID;
    2114             :   }
    2115             : 
    2116             :   /**
    2117             :    * Sanitize the document by resetting all input elements and forms that have
    2118             :    * autocomplete=off to their default values.
    2119             :    */
    2120             :   void Sanitize();
    2121             : 
    2122             :   /**
    2123             :    * Enumerate all subdocuments.
    2124             :    * The enumerator callback should return true to continue enumerating, or
    2125             :    * false to stop.  This will never get passed a null aDocument.
    2126             :    */
    2127             :   typedef bool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
    2128             :   void EnumerateSubDocuments(nsSubDocEnumFunc aCallback, void *aData);
    2129             : 
    2130             :   /**
    2131             :    * Collect all the descendant documents for which |aCalback| returns true.
    2132             :    * The callback function must not mutate any state for the given document.
    2133             :    */
    2134             :   typedef bool (*nsDocTestFunc)(const nsIDocument* aDocument);
    2135             :   void CollectDescendantDocuments(
    2136             :     nsTArray<nsCOMPtr<nsIDocument>>& aDescendants,
    2137             :     nsDocTestFunc aCallback) const;
    2138             : 
    2139             :   /**
    2140             :    * Check whether it is safe to cache the presentation of this document
    2141             :    * and all of its subdocuments. This method checks the following conditions
    2142             :    * recursively:
    2143             :    *  - Some document types, such as plugin documents, cannot be safely cached.
    2144             :    *  - If there are any pending requests, we don't allow the presentation
    2145             :    *    to be cached.  Ideally these requests would be suspended and resumed,
    2146             :    *    but that is difficult in some cases, such as XMLHttpRequest.
    2147             :    *  - If there are any beforeunload or unload listeners, we must fire them
    2148             :    *    for correctness, but this likely puts the document into a state where
    2149             :    *    it would not function correctly if restored.
    2150             :    *
    2151             :    * |aNewRequest| should be the request for a new document which will
    2152             :    * replace this document in the docshell.  The new document's request
    2153             :    * will be ignored when checking for active requests.  If there is no
    2154             :    * request associated with the new document, this parameter may be null.
    2155             :    */
    2156             :   virtual bool CanSavePresentation(nsIRequest* aNewRequest);
    2157             : 
    2158             :   /**
    2159             :    * Notify the document that its associated ContentViewer is being destroyed.
    2160             :    * This releases circular references so that the document can go away.
    2161             :    * Destroy() is only called on documents that have a content viewer.
    2162             :    */
    2163             :   virtual void Destroy() = 0;
    2164             : 
    2165             :   /**
    2166             :    * Notify the document that its associated ContentViewer is no longer
    2167             :    * the current viewer for the docshell. The document might still
    2168             :    * be rendered in "zombie state" until the next document is ready.
    2169             :    * The document should save form control state.
    2170             :    */
    2171             :   virtual void RemovedFromDocShell() = 0;
    2172             : 
    2173             :   /**
    2174             :    * Get the layout history state that should be used to save and restore state
    2175             :    * for nodes in this document.  This may return null; if that happens state
    2176             :    * saving and restoration is not possible.
    2177             :    */
    2178             :   already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const;
    2179             : 
    2180             :   /**
    2181             :    * Methods that can be used to prevent onload firing while an event that
    2182             :    * should block onload is posted.  onload is guaranteed to not fire until
    2183             :    * either all calls to BlockOnload() have been matched by calls to
    2184             :    * UnblockOnload() or the load has been stopped altogether (by the user
    2185             :    * pressing the Stop button, say).
    2186             :    */
    2187             :   virtual void BlockOnload() = 0;
    2188             :   /**
    2189             :    * @param aFireSync whether to fire onload synchronously.  If false,
    2190             :    * onload will fire asynchronously after all onload blocks have been
    2191             :    * removed.  It will NOT fire from inside UnblockOnload.  If true,
    2192             :    * onload may fire from inside UnblockOnload.
    2193             :    */
    2194             :   virtual void UnblockOnload(bool aFireSync) = 0;
    2195             : 
    2196             :   void BlockDOMContentLoaded()
    2197             :   {
    2198             :     ++mBlockDOMContentLoaded;
    2199             :   }
    2200             : 
    2201             :   void UnblockDOMContentLoaded();
    2202             : 
    2203             :   /**
    2204             :    * Notification that the page has been shown, for documents which are loaded
    2205             :    * into a DOM window.  This corresponds to the completion of document load,
    2206             :    * or to the page's presentation being restored into an existing DOM window.
    2207             :    * This notification fires applicable DOM events to the content window.  See
    2208             :    * PageTransitionEvent.webidl for a description of the |aPersisted|
    2209             :    * parameter. If aDispatchStartTarget is null, the pageshow event is
    2210             :    * dispatched on the ScriptGlobalObject for this document, otherwise it's
    2211             :    * dispatched on aDispatchStartTarget.
    2212             :    * Note: if aDispatchStartTarget isn't null, the showing state of the
    2213             :    * document won't be altered.
    2214             :    */
    2215             :   virtual void OnPageShow(bool aPersisted,
    2216             :                           mozilla::dom::EventTarget* aDispatchStartTarget);
    2217             : 
    2218             :   /**
    2219             :    * Notification that the page has been hidden, for documents which are loaded
    2220             :    * into a DOM window.  This corresponds to the unloading of the document, or
    2221             :    * to the document's presentation being saved but removed from an existing
    2222             :    * DOM window.  This notification fires applicable DOM events to the content
    2223             :    * window.  See PageTransitionEvent.webidl for a description of the
    2224             :    * |aPersisted| parameter. If aDispatchStartTarget is null, the pagehide
    2225             :    * event is dispatched on the ScriptGlobalObject for this document,
    2226             :    * otherwise it's dispatched on aDispatchStartTarget.
    2227             :    * Note: if aDispatchStartTarget isn't null, the showing state of the
    2228             :    * document won't be altered.
    2229             :    */
    2230             :   void OnPageHide(bool aPersisted,
    2231             :                   mozilla::dom::EventTarget* aDispatchStartTarget);
    2232             : 
    2233             :   /*
    2234             :    * We record the set of links in the document that are relevant to
    2235             :    * style.
    2236             :    */
    2237             :   /**
    2238             :    * Notification that an element is a link that is relevant to style.
    2239             :    */
    2240             :   void AddStyleRelevantLink(mozilla::dom::Link* aLink)
    2241             :   {
    2242             :     NS_ASSERTION(aLink, "Passing in a null link.  Expect crashes RSN!");
    2243             : #ifdef DEBUG
    2244             :     nsPtrHashKey<mozilla::dom::Link>* entry = mStyledLinks.GetEntry(aLink);
    2245             :     NS_ASSERTION(!entry, "Document already knows about this Link!");
    2246             :     mStyledLinksCleared = false;
    2247             : #endif
    2248             :     mStyledLinks.PutEntry(aLink);
    2249             :   }
    2250             : 
    2251             :   /**
    2252             :    * Notification that an element is a link and its URI might have been
    2253             :    * changed or the element removed. If the element is still a link relevant
    2254             :    * to style, then someone must ensure that AddStyleRelevantLink is
    2255             :    * (eventually) called on it again.
    2256             :    */
    2257             :   void ForgetLink(mozilla::dom::Link* aLink)
    2258             :   {
    2259             :     NS_ASSERTION(aLink, "Passing in a null link.  Expect crashes RSN!");
    2260             : #ifdef DEBUG
    2261             :     nsPtrHashKey<mozilla::dom::Link>* entry = mStyledLinks.GetEntry(aLink);
    2262             :     NS_ASSERTION(entry || mStyledLinksCleared,
    2263             :                  "Document knows nothing about this Link!");
    2264             : #endif
    2265             :     mStyledLinks.RemoveEntry(aLink);
    2266             :   }
    2267             : 
    2268             :   // Refreshes the hrefs of all the links in the document.
    2269             :   void RefreshLinkHrefs();
    2270             : 
    2271             :   /**
    2272             :    * Resets and removes a box object from the document's box object cache
    2273             :    *
    2274             :    * @param aElement canonical nsIContent pointer of the box object's element
    2275             :    */
    2276             :   void ClearBoxObjectFor(nsIContent* aContent);
    2277             : 
    2278             :   /**
    2279             :    * Get the box object for an element. This is not exposed through a
    2280             :    * scriptable interface except for XUL documents.
    2281             :    */
    2282             :   already_AddRefed<mozilla::dom::BoxObject>
    2283             :     GetBoxObjectFor(mozilla::dom::Element* aElement, mozilla::ErrorResult& aRv);
    2284             : 
    2285             :   /**
    2286             :    * Support for window.matchMedia()
    2287             :    */
    2288             : 
    2289             :   already_AddRefed<mozilla::dom::MediaQueryList>
    2290             :     MatchMedia(const nsAString& aMediaQueryList,
    2291             :                mozilla::dom::CallerType aCallerType);
    2292             : 
    2293             :   mozilla::LinkedList<mozilla::dom::MediaQueryList>& MediaQueryLists() {
    2294             :     return mDOMMediaQueryLists;
    2295             :   }
    2296             : 
    2297             :   /**
    2298             :    * Get the compatibility mode for this document
    2299             :    */
    2300             :   nsCompatibility GetCompatibilityMode() const {
    2301             :     return mCompatMode;
    2302             :   }
    2303             : 
    2304             :   /**
    2305             :    * Check whether we've ever fired a DOMTitleChanged event for this
    2306             :    * document.
    2307             :    */
    2308             :   bool HaveFiredDOMTitleChange() const
    2309             :   {
    2310             :     return mHaveFiredTitleChange;
    2311             :   }
    2312             : 
    2313             :   Element* GetAnonymousElementByAttribute(nsIContent* aElement,
    2314             :                                           nsAtom* aAttrName,
    2315             :                                           const nsAString& aAttrValue) const;
    2316             : 
    2317             :   nsresult NodesFromRectHelper(float aX, float aY,
    2318             :                                float aTopSize, float aRightSize,
    2319             :                                float aBottomSize, float aLeftSize,
    2320             :                                bool aIgnoreRootScrollFrame,
    2321             :                                bool aFlushLayout,
    2322             :                                nsINodeList** aReturn);
    2323             : 
    2324             :   /**
    2325             :    * See FlushSkinBindings on nsBindingManager
    2326             :    */
    2327             :   void FlushSkinBindings();
    2328             : 
    2329             :   /**
    2330             :    * To batch DOMSubtreeModified, document needs to be informed when
    2331             :    * a mutation event might be dispatched, even if the event isn't actually
    2332             :    * created because there are no listeners for it.
    2333             :    *
    2334             :    * @param aTarget is the target for the mutation event.
    2335             :    */
    2336             :   void MayDispatchMutationEvent(nsINode* aTarget)
    2337             :   {
    2338             :     if (mSubtreeModifiedDepth > 0) {
    2339             :       mSubtreeModifiedTargets.AppendObject(aTarget);
    2340             :     }
    2341             :   }
    2342             : 
    2343             :   /**
    2344             :    * Marks as not-going-to-be-collected for the given generation of
    2345             :    * cycle collection.
    2346             :    */
    2347             :   void MarkUncollectableForCCGeneration(uint32_t aGeneration)
    2348             :   {
    2349           0 :     mMarkedCCGeneration = aGeneration;
    2350             :   }
    2351             : 
    2352             :   /**
    2353             :    * Gets the cycle collector generation this document is marked for.
    2354             :    */
    2355             :   uint32_t GetMarkedCCGeneration()
    2356             :   {
    2357             :     return mMarkedCCGeneration;
    2358             :   }
    2359             : 
    2360             :   /**
    2361             :    * Returns whether this document is cookie averse. See
    2362             :    * https://html.spec.whatwg.org/multipage/dom.html#cookie-averse-document-object
    2363             :    */
    2364           0 :   bool IsCookieAverse() const
    2365             :   {
    2366             :     // If we are a document that "has no browsing context."
    2367           0 :     if (!GetInnerWindow()) {
    2368             :       return true;
    2369             :     }
    2370             : 
    2371             :     // If we are a document "whose URL's scheme is not a network scheme."
    2372             :     // NB: Explicitly allow file: URIs to store cookies.
    2373           0 :     nsCOMPtr<nsIURI> codebaseURI;
    2374           0 :     NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
    2375             : 
    2376           0 :     if (!codebaseURI) {
    2377             :       return true;
    2378             :     }
    2379             : 
    2380           0 :     nsAutoCString scheme;
    2381           0 :     codebaseURI->GetScheme(scheme);
    2382           0 :     return !scheme.EqualsLiteral("http") &&
    2383           0 :            !scheme.EqualsLiteral("https") &&
    2384           0 :            !scheme.EqualsLiteral("ftp") &&
    2385           0 :            !scheme.EqualsLiteral("file");
    2386             :   }
    2387             : 
    2388             :   bool IsLoadedAsData()
    2389             :   {
    2390           2 :     return mLoadedAsData;
    2391             :   }
    2392             : 
    2393             :   bool IsLoadedAsInteractiveData()
    2394             :   {
    2395             :     return mLoadedAsInteractiveData;
    2396             :   }
    2397             : 
    2398             :   bool MayStartLayout()
    2399             :   {
    2400             :     return mMayStartLayout;
    2401             :   }
    2402             : 
    2403             :   virtual void SetMayStartLayout(bool aMayStartLayout);
    2404             : 
    2405             :   already_AddRefed<nsIDocumentEncoder> GetCachedEncoder();
    2406             : 
    2407             :   void SetCachedEncoder(already_AddRefed<nsIDocumentEncoder> aEncoder);
    2408             : 
    2409             :   // In case of failure, the document really can't initialize the frame loader.
    2410             :   nsresult InitializeFrameLoader(nsFrameLoader* aLoader);
    2411             :   // In case of failure, the caller must handle the error, for example by
    2412             :   // finalizing frame loader asynchronously.
    2413             :   nsresult FinalizeFrameLoader(nsFrameLoader* aLoader, nsIRunnable* aFinalizer);
    2414             :   // Removes the frame loader of aShell from the initialization list.
    2415             :   void TryCancelFrameLoaderInitialization(nsIDocShell* aShell);
    2416             : 
    2417             :   /**
    2418             :    * Check whether this document is a root document that is not an
    2419             :    * external resource.
    2420             :    */
    2421             :   bool IsRootDisplayDocument() const
    2422             :   {
    2423             :     return !mParentDocument && !mDisplayDocument;
    2424             :   }
    2425             : 
    2426             :   bool IsBeingUsedAsImage() const {
    2427           0 :     return mIsBeingUsedAsImage;
    2428             :   }
    2429             : 
    2430             :   void SetIsBeingUsedAsImage() {
    2431           2 :     mIsBeingUsedAsImage = true;
    2432             :   }
    2433             : 
    2434             :   bool IsSVGGlyphsDocument() const
    2435             :   {
    2436             :     return mIsSVGGlyphsDocument;
    2437             :   }
    2438             : 
    2439             :   void SetIsSVGGlyphsDocument()
    2440             :   {
    2441             :     mIsSVGGlyphsDocument = true;
    2442             :   }
    2443             : 
    2444           0 :   bool IsResourceDoc() const {
    2445           0 :     return IsBeingUsedAsImage() || // Are we a helper-doc for an SVG image?
    2446           0 :       mHasDisplayDocument;         // Are we an external resource doc?
    2447             :   }
    2448             : 
    2449             :   /**
    2450             :    * Get the document for which this document is an external resource.  This
    2451             :    * will be null if this document is not an external resource.  Otherwise,
    2452             :    * GetDisplayDocument() will return a non-null document, and
    2453             :    * GetDisplayDocument()->GetDisplayDocument() is guaranteed to be null.
    2454             :    */
    2455             :   nsIDocument* GetDisplayDocument() const
    2456             :   {
    2457           0 :     return mDisplayDocument;
    2458             :   }
    2459             : 
    2460             :   /**
    2461             :    * Set the display document for this document.  aDisplayDocument must not be
    2462             :    * null.
    2463             :    */
    2464             :   void SetDisplayDocument(nsIDocument* aDisplayDocument)
    2465             :   {
    2466             :     MOZ_ASSERT(!GetShell() &&
    2467             :                !GetContainer() &&
    2468             :                !GetWindow(),
    2469             :                "Shouldn't set mDisplayDocument on documents that already "
    2470             :                "have a presentation or a docshell or a window");
    2471             :     MOZ_ASSERT(aDisplayDocument, "Must not be null");
    2472             :     MOZ_ASSERT(aDisplayDocument != this, "Should be different document");
    2473             :     MOZ_ASSERT(!aDisplayDocument->GetDisplayDocument(),
    2474             :                "Display documents should not nest");
    2475             :     mDisplayDocument = aDisplayDocument;
    2476             :     mHasDisplayDocument = !!aDisplayDocument;
    2477             :   }
    2478             : 
    2479             :   /**
    2480             :    * Request an external resource document for aURI.  This will return the
    2481             :    * resource document if available.  If one is not available yet, it will
    2482             :    * start loading as needed, and the pending load object will be returned in
    2483             :    * aPendingLoad so that the caller can register an observer to wait for the
    2484             :    * load.  If this function returns null and doesn't return a pending load,
    2485             :    * that means that there is no resource document for this URI and won't be
    2486             :    * one in the future.
    2487             :    *
    2488             :    * @param aURI the URI to get
    2489             :    * @param aRequestingNode the node making the request
    2490             :    * @param aPendingLoad the pending load for this request, if any
    2491             :    */
    2492             :   nsIDocument* RequestExternalResource(nsIURI* aURI,
    2493             :                                        nsINode* aRequestingNode,
    2494             :                                        ExternalResourceLoad** aPendingLoad);
    2495             : 
    2496             :   /**
    2497             :    * Enumerate the external resource documents associated with this document.
    2498             :    * The enumerator callback should return true to continue enumerating, or
    2499             :    * false to stop.  This callback will never get passed a null aDocument.
    2500             :    */
    2501             :   void EnumerateExternalResources(nsSubDocEnumFunc aCallback, void* aData);
    2502             : 
    2503             :   nsExternalResourceMap& ExternalResourceMap()
    2504             :   {
    2505             :     return mExternalResourceMap;
    2506             :   }
    2507             : 
    2508             :   /**
    2509             :    * Return whether the document is currently showing (in the sense of
    2510             :    * OnPageShow() having been called already and OnPageHide() not having been
    2511             :    * called yet.
    2512             :    */
    2513           0 :   bool IsShowing() const { return mIsShowing; }
    2514             :   /**
    2515             :    * Return whether the document is currently visible (in the sense of
    2516             :    * OnPageHide having been called and OnPageShow not yet having been called)
    2517             :    */
    2518           0 :   bool IsVisible() const { return mVisible; }
    2519             : 
    2520             :   /**
    2521             :    * Return whether the document and all its ancestors are visible in the sense of
    2522             :    * pageshow / hide.
    2523             :    */
    2524             :   bool IsVisibleConsideringAncestors() const;
    2525             : 
    2526             :   /**
    2527             :    * Return true when this document is active, i.e., an active document
    2528             :    * in a content viewer.  Note that this will return true for bfcached
    2529             :    * documents, so this does NOT match the "active document" concept in
    2530             :    * the WHATWG spec - see IsCurrentActiveDocument.
    2531             :    */
    2532           0 :   bool IsActive() const { return mDocumentContainer && !mRemovedFromDocShell; }
    2533             : 
    2534             :   /**
    2535             :    * Return true if this is the current active document for its
    2536             :    * docshell. Note that a docshell may have multiple active documents
    2537             :    * due to the bfcache -- this should be used when you need to
    2538             :    * differentiate the *current* active document from any active
    2539             :    * documents.
    2540             :    */
    2541           0 :   bool IsCurrentActiveDocument() const
    2542             :   {
    2543           0 :     nsPIDOMWindowInner* inner = GetInnerWindow();
    2544           0 :     return inner && inner->IsCurrentInnerWindow() && inner->GetDoc() == this;
    2545             :   }
    2546             : 
    2547             :   /**
    2548             :    * Returns whether this document should perform image loads.
    2549             :    */
    2550           0 :   bool ShouldLoadImages() const
    2551             :   {
    2552             :     // We check IsBeingUsedAsImage() so that SVG documents loaded as
    2553             :     // images can themselves have data: URL image references.
    2554           0 :     return IsCurrentActiveDocument() || IsBeingUsedAsImage();
    2555             :   }
    2556             : 
    2557             :   /**
    2558             :    * Register/Unregister the ActivityObserver into mActivityObservers to listen
    2559             :    * the document's activity changes such as OnPageHide, visibility, activity.
    2560             :    * The ActivityObserver objects can be nsIObjectLoadingContent or
    2561             :    * nsIDocumentActivity or HTMLMEdiaElement.
    2562             :    */
    2563             :   void RegisterActivityObserver(nsISupports* aSupports);
    2564             :   bool UnregisterActivityObserver(nsISupports* aSupports);
    2565             :   // Enumerate all the observers in mActivityObservers by the aEnumerator.
    2566             :   typedef void (* ActivityObserverEnumerator)(nsISupports*, void*);
    2567             :   void EnumerateActivityObservers(ActivityObserverEnumerator aEnumerator,
    2568             :                                   void* aData);
    2569             : 
    2570             :   // Indicates whether mAnimationController has been (lazily) initialized.
    2571             :   // If this returns true, we're promising that GetAnimationController()
    2572             :   // will have a non-null return value.
    2573           0 :   bool HasAnimationController()  { return !!mAnimationController; }
    2574             : 
    2575             :   // Getter for this document's SMIL Animation Controller. Performs lazy
    2576             :   // initialization, if this document supports animation and if
    2577             :   // mAnimationController isn't yet initialized.
    2578             :   //
    2579             :   // If HasAnimationController is true, this is guaranteed to return non-null.
    2580             :   nsSMILAnimationController* GetAnimationController();
    2581             : 
    2582             :   // Gets the tracker for animations that are waiting to start.
    2583             :   // Returns nullptr if there is no pending animation tracker for this document
    2584             :   // which will be the case if there have never been any CSS animations or
    2585             :   // transitions on elements in the document.
    2586             :   mozilla::PendingAnimationTracker* GetPendingAnimationTracker()
    2587             :   {
    2588           0 :     return mPendingAnimationTracker;
    2589             :   }
    2590             : 
    2591             :   // Gets the tracker for animations that are waiting to start and
    2592             :   // creates it if it doesn't already exist. As a result, the return value
    2593             :   // will never be nullptr.
    2594             :   mozilla::PendingAnimationTracker* GetOrCreatePendingAnimationTracker();
    2595             : 
    2596             :   /**
    2597             :    * Prevents user initiated events from being dispatched to the document and
    2598             :    * subdocuments.
    2599             :    */
    2600             :   void SuppressEventHandling(uint32_t aIncrease = 1);
    2601             : 
    2602             :   /**
    2603             :    * Unsuppress event handling.
    2604             :    * @param aFireEvents If true, delayed events (focus/blur) will be fired
    2605             :    *                    asynchronously.
    2606             :    */
    2607             :   void UnsuppressEventHandlingAndFireEvents(bool aFireEvents);
    2608             : 
    2609             :   uint32_t EventHandlingSuppressed() const { return mEventsSuppressed; }
    2610             : 
    2611             :   bool IsEventHandlingEnabled() {
    2612             :     return !EventHandlingSuppressed() && mScriptGlobalObject;
    2613             :   }
    2614             : 
    2615             :   void DecreaseEventSuppression()
    2616             :   {
    2617             :     MOZ_ASSERT(mEventsSuppressed);
    2618             :     --mEventsSuppressed;
    2619             :     UpdateFrameRequestCallbackSchedulingState();
    2620             :   }
    2621             : 
    2622             :   /**
    2623             :    * Increment https://html.spec.whatwg.org/#ignore-destructive-writes-counter
    2624             :    */
    2625             :   void IncrementIgnoreDestructiveWritesCounter() { ++mIgnoreDestructiveWritesCounter; }
    2626             : 
    2627             :   /**
    2628             :    * Decrement https://html.spec.whatwg.org/#ignore-destructive-writes-counter
    2629             :    */
    2630             :   void DecrementIgnoreDestructiveWritesCounter() { --mIgnoreDestructiveWritesCounter; }
    2631             : 
    2632          16 :   bool IsDNSPrefetchAllowed() const { return mAllowDNSPrefetch; }
    2633             : 
    2634             :   /**
    2635             :    * Returns true if this document is allowed to contain XUL element and
    2636             :    * use non-builtin XBL bindings.
    2637             :    */
    2638           0 :   bool AllowXULXBL() {
    2639           0 :     return mAllowXULXBL == eTriTrue ? true :
    2640           0 :            mAllowXULXBL == eTriFalse ? false :
    2641           0 :            InternalAllowXULXBL();
    2642             :   }
    2643             : 
    2644             :   void ForceEnableXULXBL() {
    2645           0 :     mAllowXULXBL = eTriTrue;
    2646             :   }
    2647             : 
    2648             :   /**
    2649             :    * Returns the template content owner document that owns the content of
    2650             :    * HTMLTemplateElement.
    2651             :    */
    2652             :   nsIDocument* GetTemplateContentsOwner();
    2653             : 
    2654             :   /**
    2655             :    * Returns true if this document is a static clone of a normal document.
    2656             :    *
    2657             :    * We create static clones for print preview and printing (possibly other
    2658             :    * things in future).
    2659             :    *
    2660             :    * Note that static documents are also "loaded as data" (if this method
    2661             :    * returns true, IsLoadedAsData() will also return true).
    2662             :    */
    2663           0 :   bool IsStaticDocument() { return mIsStaticDocument; }
    2664             : 
    2665             :   /**
    2666             :    * Clones the document along with any subdocuments, stylesheet, etc.
    2667             :    *
    2668             :    * The resulting document and everything it contains (including any
    2669             :    * sub-documents) are created purely via cloning.  The returned documents and
    2670             :    * any sub-documents are "loaded as data" documents to preserve the state as
    2671             :    * it was during the clone process (we don't want external resources to load
    2672             :    * and replace the cloned resources).
    2673             :    *
    2674             :    * @param aCloneContainer The container for the clone document.
    2675             :    */
    2676             :   virtual already_AddRefed<nsIDocument>
    2677             :   CreateStaticClone(nsIDocShell* aCloneContainer);
    2678             : 
    2679             :   /**
    2680             :    * If this document is a static clone, this returns the original
    2681             :    * document.
    2682             :    */
    2683             :   nsIDocument* GetOriginalDocument()
    2684             :   {
    2685             :     MOZ_ASSERT(!mOriginalDocument || !mOriginalDocument->GetOriginalDocument());
    2686             :     return mOriginalDocument;
    2687             :   }
    2688             : 
    2689             :   /**
    2690             :    * If this document is a static clone, let the original document know that
    2691             :    * we're going away and then release our reference to it.
    2692             :    */
    2693             :   void UnlinkOriginalDocumentIfStatic();
    2694             : 
    2695             :   /**
    2696             :    * These are called by the parser as it encounters <picture> tags, the end of
    2697             :    * said tags, and possible picture <source srcset> sources respectively. These
    2698             :    * are used to inform ResolvePreLoadImage() calls.  Unset attributes are
    2699             :    * expected to be marked void.
    2700             :    *
    2701             :    * NOTE that the parser does not attempt to track the current picture nesting
    2702             :    * level or whether the given <source> tag is within a picture -- it is only
    2703             :    * guaranteed to order these calls properly with respect to
    2704             :    * ResolvePreLoadImage.
    2705             :    */
    2706             : 
    2707             :   void PreloadPictureOpened()
    2708             :   {
    2709             :     mPreloadPictureDepth++;
    2710             :   }
    2711             : 
    2712             :   void PreloadPictureClosed();
    2713             : 
    2714             :   void PreloadPictureImageSource(const nsAString& aSrcsetAttr,
    2715             :                                  const nsAString& aSizesAttr,
    2716             :                                  const nsAString& aTypeAttr,
    2717             :                                  const nsAString& aMediaAttr);
    2718             : 
    2719             :   /**
    2720             :    * Called by the parser to resolve an image for preloading. The parser will
    2721             :    * call the PreloadPicture* functions to inform us of possible <picture>
    2722             :    * nesting and possible sources, which are used to inform URL selection
    2723             :    * responsive <picture> or <img srcset> images.  Unset attributes are expected
    2724             :    * to be marked void.
    2725             :    * If this image is for <picture> or <img srcset>, aIsImgSet will be set to
    2726             :    * true, false otherwise.
    2727             :    */
    2728             :   already_AddRefed<nsIURI>
    2729             :   ResolvePreloadImage(nsIURI *aBaseURI,
    2730             :                       const nsAString& aSrcAttr,
    2731             :                       const nsAString& aSrcsetAttr,
    2732             :                       const nsAString& aSizesAttr,
    2733             :                       bool *aIsImgSet);
    2734             :   /**
    2735             :    * Called by nsParser to preload images. Can be removed and code moved
    2736             :    * to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
    2737             :    * parser-module is linked with gklayout-module.  aCrossOriginAttr should
    2738             :    * be a void string if the attr is not present.
    2739             :    * aIsImgSet is the value got from calling ResolvePreloadImage, it is true
    2740             :    * when this image is for loading <picture> or <img srcset> images.
    2741             :    */
    2742             :   void MaybePreLoadImage(nsIURI* uri,
    2743             :                          const nsAString& aCrossOriginAttr,
    2744             :                          ReferrerPolicyEnum aReferrerPolicy,
    2745             :                          bool aIsImgSet);
    2746             : 
    2747             :   /**
    2748             :    * Called by images to forget an image preload when they start doing
    2749             :    * the real load.
    2750             :    */
    2751             :   void ForgetImagePreload(nsIURI* aURI);
    2752             : 
    2753             :   /**
    2754             :    * Called by nsParser to preload style sheets.  Can also be merged into the
    2755             :    * parser if and when the parser is merged with libgklayout.  aCrossOriginAttr
    2756             :    * should be a void string if the attr is not present.
    2757             :    */
    2758             :   void PreloadStyle(nsIURI* aURI,
    2759             :                     const mozilla::Encoding* aEncoding,
    2760             :                     const nsAString& aCrossOriginAttr,
    2761             :                     ReferrerPolicyEnum aReferrerPolicy,
    2762             :                     const nsAString& aIntegrity);
    2763             : 
    2764             :   /**
    2765             :    * Called by the chrome registry to load style sheets.  Can be put
    2766             :    * back there if and when when that module is merged with libgklayout.
    2767             :    *
    2768             :    * This always does a synchronous load.  If aIsAgentSheet is true,
    2769             :    * it also uses the system principal and enables unsafe rules.
    2770             :    * DO NOT USE FOR UNTRUSTED CONTENT.
    2771             :    */
    2772             :   nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet,
    2773             :                                RefPtr<mozilla::StyleSheet>* aSheet);
    2774             : 
    2775             :   /**
    2776             :    * Returns true if the locale used for the document specifies a direction of
    2777             :    * right to left. For chrome documents, this comes from the chrome registry.
    2778             :    * This is used to determine the current state for the :-moz-locale-dir pseudoclass
    2779             :    * so once can know whether a document is expected to be rendered left-to-right
    2780             :    * or right-to-left.
    2781             :    */
    2782           0 :   virtual bool IsDocumentRightToLeft() { return false; }
    2783             : 
    2784             :   /**
    2785             :    * Called by Parser for link rel=preconnect
    2786             :    */
    2787             :   void MaybePreconnect(nsIURI* uri, mozilla::CORSMode aCORSMode);
    2788             : 
    2789             :   enum DocumentTheme {
    2790             :     Doc_Theme_Uninitialized, // not determined yet
    2791             :     Doc_Theme_None,
    2792             :     Doc_Theme_Neutral,
    2793             :     Doc_Theme_Dark,
    2794             :     Doc_Theme_Bright
    2795             :   };
    2796             : 
    2797             :   /**
    2798             :    * Set the document's pending state object (as serialized using structured
    2799             :    * clone).
    2800             :    */
    2801             :   void SetStateObject(nsIStructuredCloneContainer *scContainer);
    2802             : 
    2803             :   /**
    2804             :    * Returns Doc_Theme_None if there is no lightweight theme specified,
    2805             :    * Doc_Theme_Dark for a dark theme, Doc_Theme_Bright for a light theme, and
    2806             :    * Doc_Theme_Neutral for any other theme. This is used to determine the state
    2807             :    * of the pseudoclasses :-moz-lwtheme and :-moz-lwtheme-text.
    2808             :    */
    2809           0 :   virtual DocumentTheme GetDocumentLWTheme() { return Doc_Theme_None; }
    2810           0 :   virtual DocumentTheme ThreadSafeGetDocumentLWTheme() const { return Doc_Theme_None; }
    2811             : 
    2812             :   /**
    2813             :    * Returns the document state.
    2814             :    * Document state bits have the form NS_DOCUMENT_STATE_* and are declared in
    2815             :    * nsIDocument.h.
    2816             :    */
    2817             :   mozilla::EventStates GetDocumentState() const
    2818             :   {
    2819             :     return mDocumentState;
    2820             :   }
    2821             : 
    2822             :   nsISupports* GetCurrentContentSink();
    2823             : 
    2824             :   void SetAutoFocusElement(Element* aAutoFocusElement);
    2825             :   void TriggerAutoFocus();
    2826             : 
    2827             :   void SetScrollToRef(nsIURI* aDocumentURI);
    2828             :   void ScrollToRef();
    2829             :   void ResetScrolledToRefAlready()
    2830             :   {
    2831             :     mScrolledToRefAlready = false;
    2832             :   }
    2833             : 
    2834             :   void SetChangeScrollPosWhenScrollingToRef(bool aValue)
    2835             :   {
    2836             :     mChangeScrollPosWhenScrollingToRef = aValue;
    2837             :   }
    2838             : 
    2839             :   using mozilla::dom::DocumentOrShadowRoot::GetElementById;
    2840             :   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName;
    2841             :   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS;
    2842             :   using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName;
    2843             : 
    2844             :   /**
    2845             :    * Lookup an image element using its associated ID, which is usually provided
    2846             :    * by |-moz-element()|. Similar to GetElementById, with the difference that
    2847             :    * elements set using mozSetImageElement have higher priority.
    2848             :    * @param aId the ID associated the element we want to lookup
    2849             :    * @return the element associated with |aId|
    2850             :    */
    2851             :   Element* LookupImageElement(const nsAString& aElementId);
    2852             : 
    2853             :   mozilla::dom::DocumentTimeline* Timeline();
    2854             :   mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines()
    2855             :   {
    2856             :     return mTimelines;
    2857             :   }
    2858             : 
    2859             :   void GetAnimations(nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations);
    2860             : 
    2861             :   mozilla::dom::SVGSVGElement* GetSVGRootElement() const;
    2862             : 
    2863             :   nsresult ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback,
    2864             :                                         int32_t *aHandle);
    2865             :   void CancelFrameRequestCallback(int32_t aHandle);
    2866             : 
    2867             :   typedef nsTArray<RefPtr<mozilla::dom::FrameRequestCallback>> FrameRequestCallbackList;
    2868             :   /**
    2869             :    * Put this document's frame request callbacks into the provided
    2870             :    * list, and forget about them.
    2871             :    */
    2872             :   void TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks);
    2873             : 
    2874             :   /**
    2875             :    * @return true if this document's frame request callbacks should be
    2876             :    * throttled. We throttle requestAnimationFrame for documents which aren't
    2877             :    * visible (e.g. scrolled out of the viewport).
    2878             :    */
    2879             :   bool ShouldThrottleFrameRequests();
    2880             : 
    2881             :   // This returns true when the document tree is being teared down.
    2882             :   bool InUnlinkOrDeletion() { return mInUnlinkOrDeletion; }
    2883             : 
    2884             :   mozilla::dom::ImageTracker* ImageTracker();
    2885             : 
    2886             :   // AddPlugin adds a plugin-related element to mPlugins when the element is
    2887             :   // added to the tree.
    2888             :   void AddPlugin(nsIObjectLoadingContent* aPlugin)
    2889             :   {
    2890             :     MOZ_ASSERT(aPlugin);
    2891             :     mPlugins.PutEntry(aPlugin);
    2892             :   }
    2893             : 
    2894             :   // RemovePlugin removes a plugin-related element to mPlugins when the
    2895             :   // element is removed from the tree.
    2896             :   void RemovePlugin(nsIObjectLoadingContent* aPlugin)
    2897             :   {
    2898             :     MOZ_ASSERT(aPlugin);
    2899             :     mPlugins.RemoveEntry(aPlugin);
    2900             :   }
    2901             : 
    2902             :   // GetPlugins returns the plugin-related elements from
    2903             :   // the frame and any subframes.
    2904             :   void GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins);
    2905             : 
    2906             :   // Adds an element to mResponsiveContent when the element is
    2907             :   // added to the tree.
    2908           0 :   void AddResponsiveContent(mozilla::dom::HTMLImageElement* aContent)
    2909             :   {
    2910           0 :     MOZ_ASSERT(aContent);
    2911           0 :     mResponsiveContent.PutEntry(aContent);
    2912           0 :   }
    2913             : 
    2914             :   // Removes an element from mResponsiveContent when the element is
    2915             :   // removed from the tree.
    2916           0 :   void RemoveResponsiveContent(mozilla::dom::HTMLImageElement* aContent)
    2917             :   {
    2918           0 :     MOZ_ASSERT(aContent);
    2919           0 :     mResponsiveContent.RemoveEntry(aContent);
    2920           0 :   }
    2921             : 
    2922             :   void AddComposedDocShadowRoot(mozilla::dom::ShadowRoot& aShadowRoot)
    2923             :   {
    2924             :     MOZ_ASSERT(IsShadowDOMEnabled());
    2925             :     mComposedShadowRoots.PutEntry(&aShadowRoot);
    2926             :   }
    2927             : 
    2928             :   using ShadowRootSet = nsTHashtable<nsPtrHashKey<mozilla::dom::ShadowRoot>>;
    2929             : 
    2930             :   void RemoveComposedDocShadowRoot(mozilla::dom::ShadowRoot& aShadowRoot)
    2931             :   {
    2932             :     MOZ_ASSERT(IsShadowDOMEnabled());
    2933             :     mComposedShadowRoots.RemoveEntry(&aShadowRoot);
    2934             :   }
    2935             : 
    2936             :   // If you're considering using this, you probably want to use
    2937             :   // ShadowRoot::IsComposedDocParticipant instead. This is just for
    2938             :   // sanity-checking.
    2939             :   bool IsComposedDocShadowRoot(mozilla::dom::ShadowRoot& aShadowRoot)
    2940             :   {
    2941             :     return mComposedShadowRoots.Contains(&aShadowRoot);
    2942             :   }
    2943             : 
    2944             :   const ShadowRootSet& ComposedShadowRoots() const
    2945             :   {
    2946             :     return mComposedShadowRoots;
    2947             :   }
    2948             : 
    2949             :   // Notifies any responsive content added by AddResponsiveContent upon media
    2950             :   // features values changing.
    2951             :   void NotifyMediaFeatureValuesChanged();
    2952             : 
    2953             :   nsresult GetStateObject(nsIVariant** aResult);
    2954             : 
    2955             :   nsDOMNavigationTiming* GetNavigationTiming() const
    2956             :   {
    2957             :     return mTiming;
    2958             :   }
    2959             : 
    2960             :   void SetNavigationTiming(nsDOMNavigationTiming* aTiming);
    2961             : 
    2962             :   Element* FindImageMap(const nsAString& aNormalizedMapName);
    2963             : 
    2964             :   // Add aLink to the set of links that need their status resolved.
    2965             :   void RegisterPendingLinkUpdate(mozilla::dom::Link* aLink);
    2966             : 
    2967             :   // Update state on links in mLinksToUpdate.  This function must be called
    2968             :   // prior to selector matching that needs to differentiate between :link and
    2969             :   // :visited.  In particular, it does _not_ need to be called before doing any
    2970             :   // selector matching that uses TreeMatchContext::eNeverMatchVisited.  The only
    2971             :   // reason we haven't moved all calls to this function entirely inside the
    2972             :   // TreeMatchContext constructor is to not call it all the time during various
    2973             :   // style system and frame construction operations (though it would likely be a
    2974             :   // no-op for all but the first call).
    2975             :   //
    2976             :   // XXXbz Does this really need to be called before selector matching?  All it
    2977             :   // will do is ensure all the links involved are registered to observe history,
    2978             :   // which won't synchronously change their state to :visited anyway!  So
    2979             :   // calling this won't affect selector matching done immediately afterward, as
    2980             :   // far as I can tell.
    2981             :   void FlushPendingLinkUpdates();
    2982             : 
    2983             :   void FlushPendingLinkUpdatesFromRunnable();
    2984             : 
    2985             : #define DEPRECATED_OPERATION(_op) e##_op,
    2986             :   enum DeprecatedOperations {
    2987             : #include "nsDeprecatedOperationList.h"
    2988             :     eDeprecatedOperationCount
    2989             :   };
    2990             : #undef DEPRECATED_OPERATION
    2991             :   bool HasWarnedAbout(DeprecatedOperations aOperation) const;
    2992             :   void WarnOnceAbout(DeprecatedOperations aOperation,
    2993             :                      bool asError = false) const;
    2994             : 
    2995             : #define DOCUMENT_WARNING(_op) e##_op,
    2996             :   enum DocumentWarnings {
    2997             : #include "nsDocumentWarningList.h"
    2998             :     eDocumentWarningCount
    2999             :   };
    3000             : #undef DOCUMENT_WARNING
    3001             :   bool HasWarnedAbout(DocumentWarnings aWarning) const;
    3002             :   void WarnOnceAbout(DocumentWarnings aWarning,
    3003             :                      bool asError = false,
    3004             :                      const char16_t **aParams = nullptr,
    3005             :                      uint32_t aParamsLength = 0) const;
    3006             : 
    3007             :   // Posts an event to call UpdateVisibilityState
    3008             :   void PostVisibilityUpdateEvent();
    3009             : 
    3010           0 :   bool IsSyntheticDocument() const { return mIsSyntheticDocument; }
    3011             : 
    3012             :   // Note: nsIDocument is a sub-class of nsINode, which has a
    3013             :   // SizeOfExcludingThis function.  However, because nsIDocument objects can
    3014             :   // only appear at the top of the DOM tree, we have a specialized measurement
    3015             :   // function which returns multiple sizes.
    3016             :   virtual void DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const;
    3017             :   // DocAddSizeOfIncludingThis doesn't need to be overridden by sub-classes
    3018             :   // because nsIDocument inherits from nsINode;  see the comment above the
    3019             :   // declaration of nsINode::SizeOfIncludingThis.
    3020             :   virtual void DocAddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const;
    3021             : 
    3022             :   bool MayHaveDOMMutationObservers()
    3023             :   {
    3024           0 :     return mMayHaveDOMMutationObservers;
    3025             :   }
    3026             : 
    3027             :   void SetMayHaveDOMMutationObservers()
    3028             :   {
    3029             :     mMayHaveDOMMutationObservers = true;
    3030             :   }
    3031             : 
    3032             :   bool MayHaveAnimationObservers()
    3033             :   {
    3034             :     return mMayHaveAnimationObservers;
    3035             :   }
    3036             : 
    3037             :   void SetMayHaveAnimationObservers()
    3038             :   {
    3039             :     mMayHaveAnimationObservers = true;
    3040             :   }
    3041             : 
    3042             :   bool IsInSyncOperation()
    3043             :   {
    3044             :     return mInSyncOperationCount != 0;
    3045             :   }
    3046             : 
    3047             :   void SetIsInSyncOperation(bool aSync)
    3048             :   {
    3049             :     if (aSync) {
    3050             :       ++mInSyncOperationCount;
    3051             :     } else {
    3052             :       --mInSyncOperationCount;
    3053             :     }
    3054             :   }
    3055             : 
    3056             :   bool CreatingStaticClone() const
    3057             :   {
    3058             :     return mCreatingStaticClone;
    3059             :   }
    3060             : 
    3061             :   /**
    3062             :    * Creates a new element in the HTML namespace with a local name given by
    3063             :    * aTag.
    3064             :    */
    3065             :   already_AddRefed<Element> CreateHTMLElement(nsAtom* aTag);
    3066             : 
    3067             :   // WebIDL API
    3068             :   nsIGlobalObject* GetParentObject() const
    3069             :   {
    3070           0 :     return GetScopeObject();
    3071             :   }
    3072             :   static already_AddRefed<nsIDocument>
    3073             :     Constructor(const GlobalObject& aGlobal,
    3074             :                 mozilla::ErrorResult& rv);
    3075             :   mozilla::dom::DOMImplementation* GetImplementation(mozilla::ErrorResult& rv);
    3076             :   MOZ_MUST_USE nsresult GetURL(nsString& retval) const;
    3077             :   MOZ_MUST_USE nsresult GetDocumentURI(nsString& retval) const;
    3078             :   // Return the URI for the document.
    3079             :   // The returned value may differ if the document is loaded via XHR, and
    3080             :   // when accessed from chrome privileged script and
    3081             :   // from content privileged script for compatibility.
    3082             :   void GetDocumentURIFromJS(nsString& aDocumentURI,
    3083             :                             mozilla::dom::CallerType aCallerType,
    3084             :                             mozilla::ErrorResult& aRv) const;
    3085             :   void GetCompatMode(nsString& retval) const;
    3086             :   void GetCharacterSet(nsAString& retval) const;
    3087             :   // Skip GetContentType, because our NS_IMETHOD version above works fine here.
    3088             :   // GetDoctype defined above
    3089             :   Element* GetDocumentElement() const
    3090             :   {
    3091           0 :     return GetRootElement();
    3092             :   }
    3093             : 
    3094             :   enum ElementCallbackType {
    3095             :     eConnected,
    3096             :     eDisconnected,
    3097             :     eAdopted,
    3098             :     eAttributeChanged
    3099             :   };
    3100             : 
    3101             :   nsIDocument* GetTopLevelContentDocument();
    3102             : 
    3103             :   // Returns the associated XUL window if this is a top-level chrome document,
    3104             :   // null otherwise.
    3105             :   already_AddRefed<nsIXULWindow> GetXULWindowIfToplevelChrome() const;
    3106             : 
    3107             :   already_AddRefed<Element>
    3108             :   CreateElement(const nsAString& aTagName,
    3109             :                 const mozilla::dom::ElementCreationOptionsOrString& aOptions,
    3110             :                 mozilla::ErrorResult& rv);
    3111             :   already_AddRefed<Element>
    3112             :   CreateElementNS(const nsAString& aNamespaceURI,
    3113             :                   const nsAString& aQualifiedName,
    3114             :                   const mozilla::dom::ElementCreationOptionsOrString& aOptions,
    3115             :                   mozilla::ErrorResult& rv);
    3116             :   already_AddRefed<mozilla::dom::DocumentFragment>
    3117             :     CreateDocumentFragment() const;
    3118             :   already_AddRefed<nsTextNode> CreateTextNode(const nsAString& aData) const;
    3119             :   already_AddRefed<nsTextNode> CreateEmptyTextNode() const;
    3120             :   already_AddRefed<mozilla::dom::Comment>
    3121             :     CreateComment(const nsAString& aData) const;
    3122             :   already_AddRefed<mozilla::dom::ProcessingInstruction>
    3123             :     CreateProcessingInstruction(const nsAString& target, const nsAString& data,
    3124             :                                 mozilla::ErrorResult& rv) const;
    3125             :   already_AddRefed<nsINode>
    3126             :     ImportNode(nsINode& aNode, bool aDeep, mozilla::ErrorResult& rv) const;
    3127             :   nsINode* AdoptNode(nsINode& aNode, mozilla::ErrorResult& rv);
    3128             :   already_AddRefed<mozilla::dom::Event>
    3129             :     CreateEvent(const nsAString& aEventType,
    3130             :                 mozilla::dom::CallerType aCallerType,
    3131             :                 mozilla::ErrorResult& rv) const;
    3132             :   already_AddRefed<nsRange> CreateRange(mozilla::ErrorResult& rv);
    3133             :   already_AddRefed<mozilla::dom::NodeIterator>
    3134             :     CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
    3135             :                        mozilla::dom::NodeFilter* aFilter,
    3136             :                        mozilla::ErrorResult& rv) const;
    3137             :   already_AddRefed<mozilla::dom::TreeWalker>
    3138             :     CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
    3139             :                      mozilla::dom::NodeFilter* aFilter, mozilla::ErrorResult& rv) const;
    3140             :   // Deprecated WebIDL bits
    3141             :   already_AddRefed<mozilla::dom::CDATASection>
    3142             :     CreateCDATASection(const nsAString& aData, mozilla::ErrorResult& rv);
    3143             :   already_AddRefed<mozilla::dom::Attr>
    3144             :     CreateAttribute(const nsAString& aName, mozilla::ErrorResult& rv);
    3145             :   already_AddRefed<mozilla::dom::Attr>
    3146             :     CreateAttributeNS(const nsAString& aNamespaceURI,
    3147             :                       const nsAString& aQualifiedName,
    3148             :                       mozilla::ErrorResult& rv);
    3149             :   void GetInputEncoding(nsAString& aInputEncoding) const;
    3150             :   already_AddRefed<mozilla::dom::Location> GetLocation() const;
    3151             :   void GetReferrer(nsAString& aReferrer) const;
    3152             :   void GetLastModified(nsAString& aLastModified) const;
    3153             :   void GetReadyState(nsAString& aReadyState) const;
    3154             : 
    3155             :   void GetTitle(nsAString& aTitle);
    3156             :   void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv);
    3157             :   void GetDir(nsAString& aDirection) const;
    3158             :   void SetDir(const nsAString& aDirection);
    3159             :   nsIHTMLCollection* Images();
    3160             :   nsIHTMLCollection* Embeds();
    3161             :   nsIHTMLCollection* Plugins()
    3162             :   {
    3163             :     return Embeds();
    3164             :   }
    3165             :   nsIHTMLCollection* Links();
    3166             :   nsIHTMLCollection* Forms();
    3167             :   nsIHTMLCollection* Scripts();
    3168             :   already_AddRefed<nsContentList> GetElementsByName(const nsAString& aName)
    3169             :   {
    3170             :     return GetFuncStringContentList<nsCachableElementsByNameNodeList>(this,
    3171             :                                                                       MatchNameAttribute,
    3172             :                                                                       nullptr,
    3173             :                                                                       UseExistingNameString,
    3174             :                                                                       aName);
    3175             :   }
    3176             :   nsPIDOMWindowOuter* GetDefaultView() const
    3177             :   {
    3178           0 :     return GetWindow();
    3179             :   }
    3180             :   Element* GetActiveElement();
    3181             :   bool HasFocus(mozilla::ErrorResult& rv) const;
    3182             :   nsIHTMLCollection* Applets();
    3183             :   nsIHTMLCollection* Anchors();
    3184             :   mozilla::TimeStamp LastFocusTime() const;
    3185             :   void SetLastFocusTime(const mozilla::TimeStamp& aFocusTime);
    3186             :   // Event handlers are all on nsINode already
    3187             :   bool MozSyntheticDocument() const
    3188             :   {
    3189             :     return IsSyntheticDocument();
    3190             :   }
    3191             :   Element* GetCurrentScript();
    3192             :   void ReleaseCapture() const;
    3193             :   void MozSetImageElement(const nsAString& aImageElementId, Element* aElement);
    3194             :   nsIURI* GetDocumentURIObject() const;
    3195             :   // Not const because all the full-screen goop is not const
    3196             :   bool FullscreenEnabled(mozilla::dom::CallerType aCallerType);
    3197             :   Element* FullScreenStackTop();
    3198             :   bool Fullscreen()
    3199             :   {
    3200             :     return !!GetFullscreenElement();
    3201             :   }
    3202             :   void ExitFullscreen();
    3203             :   void ExitPointerLock()
    3204             :   {
    3205             :     UnlockPointer(this);
    3206             :   }
    3207             : 
    3208             :   static bool IsUnprefixedFullscreenEnabled(JSContext* aCx, JSObject* aObject);
    3209             : 
    3210             : #ifdef MOZILLA_INTERNAL_API
    3211             :   bool Hidden() const
    3212             :   {
    3213           0 :     return mVisibilityState != mozilla::dom::VisibilityState::Visible;
    3214             :   }
    3215             :   mozilla::dom::VisibilityState VisibilityState() const
    3216             :   {
    3217             :     return mVisibilityState;
    3218             :   }
    3219             : #endif
    3220             :   void GetSelectedStyleSheetSet(nsAString& aSheetSet);
    3221             :   void SetSelectedStyleSheetSet(const nsAString& aSheetSet);
    3222             :   void GetLastStyleSheetSet(nsAString& aSheetSet)
    3223             :   {
    3224             :     aSheetSet = mLastStyleSheetSet;
    3225             :   }
    3226             :   const nsString& GetCurrentStyleSheetSet() const
    3227             :   {
    3228             :     return mLastStyleSheetSet.IsEmpty()
    3229             :       ? mPreferredStyleSheetSet
    3230             :       : mLastStyleSheetSet;
    3231             :   }
    3232             :   void SetPreferredStyleSheetSet(const nsAString&);
    3233             :   void GetPreferredStyleSheetSet(nsAString& aSheetSet)
    3234             :   {
    3235             :     aSheetSet = mPreferredStyleSheetSet;
    3236             :   }
    3237             :   mozilla::dom::DOMStringList* StyleSheetSets();
    3238             :   void EnableStyleSheetsForSet(const nsAString& aSheetSet);
    3239             : 
    3240             :   /**
    3241             :    * Retrieve the location of the caret position (DOM node and character
    3242             :    * offset within that node), given a point.
    3243             :    *
    3244             :    * @param aX Horizontal point at which to determine the caret position, in
    3245             :    *           page coordinates.
    3246             :    * @param aY Vertical point at which to determine the caret position, in
    3247             :    *           page coordinates.
    3248             :    */
    3249             :   already_AddRefed<nsDOMCaretPosition>
    3250             :     CaretPositionFromPoint(float aX, float aY);
    3251             : 
    3252             :   Element* GetScrollingElement();
    3253             :   // A way to check whether a given element is what would get returned from
    3254             :   // GetScrollingElement.  It can be faster than comparing to the return value
    3255             :   // of GetScrollingElement() due to being able to avoid flushes in various
    3256             :   // cases.  This method assumes that null is NOT passed.
    3257             :   bool IsScrollingElement(Element* aElement);
    3258             : 
    3259             :   // QuerySelector and QuerySelectorAll already defined on nsINode
    3260             :   nsINodeList* GetAnonymousNodes(Element& aElement);
    3261             :   Element* GetAnonymousElementByAttribute(Element& aElement,
    3262             :                                           const nsAString& aAttrName,
    3263             :                                           const nsAString& aAttrValue);
    3264             :   Element* GetBindingParent(nsINode& aNode);
    3265             :   void LoadBindingDocument(const nsAString& aURI,
    3266             :                            nsIPrincipal& aSubjectPrincipal,
    3267             :                            mozilla::ErrorResult& rv);
    3268             :   mozilla::dom::XPathExpression*
    3269             :     CreateExpression(const nsAString& aExpression,
    3270             :                      mozilla::dom::XPathNSResolver* aResolver,
    3271             :                      mozilla::ErrorResult& rv);
    3272             :   nsINode* CreateNSResolver(nsINode& aNodeResolver);
    3273             :   already_AddRefed<mozilla::dom::XPathResult>
    3274             :     Evaluate(JSContext* aCx, const nsAString& aExpression, nsINode& aContextNode,
    3275             :              mozilla::dom::XPathNSResolver* aResolver, uint16_t aType,
    3276             :              JS::Handle<JSObject*> aResult, mozilla::ErrorResult& rv);
    3277             :   // Touch event handlers already on nsINode
    3278             :   already_AddRefed<mozilla::dom::Touch>
    3279             :     CreateTouch(nsGlobalWindowInner* aView, mozilla::dom::EventTarget* aTarget,
    3280             :                 int32_t aIdentifier, int32_t aPageX, int32_t aPageY,
    3281             :                 int32_t aScreenX, int32_t aScreenY, int32_t aClientX,
    3282             :                 int32_t aClientY, int32_t aRadiusX, int32_t aRadiusY,
    3283             :                 float aRotationAngle, float aForce);
    3284             :   already_AddRefed<mozilla::dom::TouchList> CreateTouchList();
    3285             :   already_AddRefed<mozilla::dom::TouchList>
    3286             :     CreateTouchList(mozilla::dom::Touch& aTouch,
    3287             :                     const mozilla::dom::Sequence<mozilla::OwningNonNull<mozilla::dom::Touch> >& aTouches);
    3288             :   already_AddRefed<mozilla::dom::TouchList>
    3289             :     CreateTouchList(const mozilla::dom::Sequence<mozilla::OwningNonNull<mozilla::dom::Touch> >& aTouches);
    3290             : 
    3291             :   void SetStyleSheetChangeEventsEnabled(bool aValue)
    3292             :   {
    3293             :     mStyleSheetChangeEventsEnabled = aValue;
    3294             :   }
    3295             : 
    3296             :   bool StyleSheetChangeEventsEnabled() const
    3297             :   {
    3298             :     return mStyleSheetChangeEventsEnabled;
    3299             :   }
    3300             : 
    3301             :   void ObsoleteSheet(nsIURI *aSheetURI, mozilla::ErrorResult& rv);
    3302             : 
    3303             :   void ObsoleteSheet(const nsAString& aSheetURI, mozilla::ErrorResult& rv);
    3304             : 
    3305             :   already_AddRefed<mozilla::dom::Promise> BlockParsing(mozilla::dom::Promise& aPromise,
    3306             :                                                        const mozilla::dom::BlockParsingOptions& aOptions,
    3307             :                                                        mozilla::ErrorResult& aRv);
    3308             : 
    3309             :   already_AddRefed<nsIURI> GetMozDocumentURIIfNotForErrorPages();
    3310             : 
    3311             :   mozilla::dom::Promise* GetDocumentReadyForIdle(mozilla::ErrorResult& aRv);
    3312             : 
    3313             :   // ParentNode
    3314             :   nsIHTMLCollection* Children();
    3315             :   uint32_t ChildElementCount();
    3316             : 
    3317             :   /**
    3318             :    * Asserts IsHTMLOrXHTML, and can't return null.
    3319             :    * Defined inline in nsHTMLDocument.h
    3320             :    */
    3321             :   inline nsHTMLDocument* AsHTMLDocument();
    3322             : 
    3323             :   /**
    3324             :    * Asserts IsSVGDocument, and can't return null.
    3325             :    * Defined inline in SVGDocument.h
    3326             :    */
    3327             :   inline mozilla::dom::SVGDocument* AsSVGDocument();
    3328             : 
    3329             :   /**
    3330             :    * Asserts IsXULDocument, and can't return null.
    3331             :    * Defined inline in XULDocument.h
    3332             :    */
    3333             :   inline mozilla::dom::XULDocument* AsXULDocument();
    3334             : 
    3335             :   /*
    3336             :    * Given a node, get a weak reference to it and append that reference to
    3337             :    * mBlockedTrackingNodes. Can be used later on to look up a node in it.
    3338             :    * (e.g., by the UI)
    3339             :    */
    3340           0 :   void AddBlockedTrackingNode(nsINode *node)
    3341             :   {
    3342           0 :     if (!node) {
    3343           0 :       return;
    3344             :     }
    3345             : 
    3346           0 :     nsWeakPtr weakNode = do_GetWeakReference(node);
    3347             : 
    3348           0 :     if (weakNode) {
    3349           0 :       mBlockedTrackingNodes.AppendElement(weakNode);
    3350             :     }
    3351             :   }
    3352             : 
    3353             :   gfxUserFontSet* GetUserFontSet(bool aFlushUserFontSet = true);
    3354             :   void FlushUserFontSet();
    3355             :   void MarkUserFontSetDirty();
    3356             :   mozilla::dom::FontFaceSet* GetFonts() { return mFontFaceSet; }
    3357             : 
    3358             :   // FontFaceSource
    3359             :   mozilla::dom::FontFaceSet* Fonts();
    3360             : 
    3361             :   bool DidFireDOMContentLoaded() const { return mDidFireDOMContentLoaded; }
    3362             : 
    3363             :   bool IsSynthesized();
    3364             : 
    3365             :   enum class UseCounterReportKind {
    3366             :     // Flush the document's use counters only; the use counters for any
    3367             :     // external resource documents will be flushed when the external
    3368             :     // resource documents themselves are destroyed.
    3369             :     eDefault,
    3370             : 
    3371             :     // Flush use counters for the document and for its external resource
    3372             :     // documents. (Should only be necessary for tests, where we need
    3373             :     // flushing to happen synchronously and deterministically.)
    3374             :     eIncludeExternalResources,
    3375             :   };
    3376             : 
    3377             :   void ReportUseCounters(UseCounterReportKind aKind = UseCounterReportKind::eDefault);
    3378             : 
    3379             :   void SetDocumentUseCounter(mozilla::UseCounter aUseCounter)
    3380             :   {
    3381             :     if (!mUseCounters[aUseCounter]) {
    3382             :       mUseCounters[aUseCounter] = true;
    3383             :     }
    3384             :   }
    3385             : 
    3386             :   void SetPageUseCounter(mozilla::UseCounter aUseCounter);
    3387             : 
    3388             :   void SetDocumentAndPageUseCounter(mozilla::UseCounter aUseCounter)
    3389             :   {
    3390             :     SetDocumentUseCounter(aUseCounter);
    3391             :     SetPageUseCounter(aUseCounter);
    3392             :   }
    3393             : 
    3394             :   void PropagateUseCounters(nsIDocument* aParentDocument);
    3395             : 
    3396             :   void SetUserHasInteracted(bool aUserHasInteracted);
    3397             :   bool UserHasInteracted()
    3398             :   {
    3399             :     return mUserHasInteracted;
    3400             :   }
    3401             : 
    3402             :   // This would be called when document get activated by specific user gestures
    3403             :   // and propagate the user activation flag to its parent.
    3404             :   void NotifyUserActivation();
    3405             : 
    3406             :   // Return true if document has interacted by specific user gestures.
    3407             :   bool HasBeenUserActivated();
    3408             : 
    3409             :   bool HasScriptsBlockedBySandbox();
    3410             : 
    3411             :   bool InlineScriptAllowedByCSP();
    3412             : 
    3413             :   void ReportHasScrollLinkedEffect();
    3414             :   bool HasScrollLinkedEffect() const
    3415             :   {
    3416             :     return mHasScrollLinkedEffect;
    3417             :   }
    3418             : 
    3419             :   mozilla::dom::DocGroup* GetDocGroup() const;
    3420             : 
    3421             :   void AddIntersectionObserver(mozilla::dom::DOMIntersectionObserver* aObserver)
    3422             :   {
    3423             :     MOZ_ASSERT(!mIntersectionObservers.Contains(aObserver),
    3424             :                "Intersection observer already in the list");
    3425             :     mIntersectionObservers.PutEntry(aObserver);
    3426             :   }
    3427             : 
    3428             :   void RemoveIntersectionObserver(mozilla::dom::DOMIntersectionObserver* aObserver)
    3429             :   {
    3430             :     mIntersectionObservers.RemoveEntry(aObserver);
    3431             :   }
    3432             : 
    3433             :   bool HasIntersectionObservers() const
    3434             :   {
    3435             :     return !mIntersectionObservers.IsEmpty();
    3436             :   }
    3437             : 
    3438             :   void UpdateIntersectionObservations();
    3439             :   void ScheduleIntersectionObserverNotification();
    3440             :   void NotifyIntersectionObservers();
    3441             : 
    3442             :   // Dispatch a runnable related to the document.
    3443             :   nsresult Dispatch(mozilla::TaskCategory aCategory,
    3444             :                     already_AddRefed<nsIRunnable>&& aRunnable) final;
    3445             : 
    3446             :   virtual nsISerialEventTarget*
    3447             :   EventTargetFor(mozilla::TaskCategory aCategory) const override;
    3448             : 
    3449             :   virtual mozilla::AbstractThread*
    3450             :   AbstractMainThreadFor(mozilla::TaskCategory aCategory) override;
    3451             : 
    3452             :   // The URLs passed to these functions should match what
    3453             :   // JS::DescribeScriptedCaller() returns, since these APIs are used to
    3454             :   // determine whether some code is being called from a tracking script.
    3455             :   void NoteScriptTrackingStatus(const nsACString& aURL, bool isTracking);
    3456             :   bool IsScriptTracking(const nsACString& aURL) const;
    3457             : 
    3458             :   // For more information on Flash classification, see
    3459             :   // toolkit/components/url-classifier/flash-block-lists.rst
    3460             :   mozilla::dom::FlashClassification DocumentFlashClassification();
    3461             :   bool IsThirdParty();
    3462             : 
    3463             :   bool IsScopedStyleEnabled();
    3464             : 
    3465             :   nsINode* GetServoRestyleRoot() const
    3466             :   {
    3467             :     return mServoRestyleRoot;
    3468             :   }
    3469             : 
    3470             :   uint32_t GetServoRestyleRootDirtyBits() const
    3471             :   {
    3472             :     MOZ_ASSERT(mServoRestyleRoot);
    3473             :     MOZ_ASSERT(mServoRestyleRootDirtyBits);
    3474             :     return mServoRestyleRootDirtyBits;
    3475             :   }
    3476             : 
    3477             :   void ClearServoRestyleRoot()
    3478             :   {
    3479             :     mServoRestyleRoot = nullptr;
    3480             :     mServoRestyleRootDirtyBits = 0;
    3481             :   }
    3482             : 
    3483             :   inline void SetServoRestyleRoot(nsINode* aRoot, uint32_t aDirtyBits);
    3484             :   inline void SetServoRestyleRootDirtyBits(uint32_t aDirtyBits);
    3485             : 
    3486             :   bool ShouldThrowOnDynamicMarkupInsertion()
    3487             :   {
    3488             :     return mThrowOnDynamicMarkupInsertionCounter;
    3489             :   }
    3490             : 
    3491             :   void IncrementThrowOnDynamicMarkupInsertionCounter()
    3492             :   {
    3493             :     ++mThrowOnDynamicMarkupInsertionCounter;
    3494             :   }
    3495             : 
    3496             :   void DecrementThrowOnDynamicMarkupInsertionCounter()
    3497             :   {
    3498             :     MOZ_ASSERT(mThrowOnDynamicMarkupInsertionCounter);
    3499             :     --mThrowOnDynamicMarkupInsertionCounter;
    3500             :   }
    3501             : 
    3502             :   bool ShouldIgnoreOpens() const
    3503             :   {
    3504             :     return mIgnoreOpensDuringUnloadCounter;
    3505             :   }
    3506             : 
    3507             :   void IncrementIgnoreOpensDuringUnloadCounter()
    3508             :   {
    3509           0 :     ++mIgnoreOpensDuringUnloadCounter;
    3510             :   }
    3511             : 
    3512           2 :   void DecrementIgnoreOpensDuringUnloadCounter()
    3513             :   {
    3514           2 :     MOZ_ASSERT(mIgnoreOpensDuringUnloadCounter);
    3515           2 :     --mIgnoreOpensDuringUnloadCounter;
    3516           2 :   }
    3517             : 
    3518             :   bool AllowPaymentRequest() const
    3519             :   {
    3520           0 :     return mAllowPaymentRequest;
    3521             :   }
    3522             : 
    3523             :   void SetAllowPaymentRequest(bool aAllowPaymentRequest)
    3524             :   {
    3525             :     mAllowPaymentRequest = aAllowPaymentRequest;
    3526             :   }
    3527             : 
    3528             :   bool IsShadowDOMEnabled() const
    3529             :   {
    3530             :     return mIsShadowDOMEnabled;
    3531             :   }
    3532             : 
    3533             :   bool ModuleScriptsEnabled();
    3534             : 
    3535             :   /**
    3536             :    * Find the (non-anonymous) content in this document for aFrame. It will
    3537             :    * be aFrame's content node if that content is in this document and not
    3538             :    * anonymous. Otherwise, when aFrame is in a subdocument, we use the frame
    3539             :    * element containing the subdocument containing aFrame, and/or find the
    3540             :    * nearest non-anonymous ancestor in this document.
    3541             :    * Returns null if there is no such element.
    3542             :    */
    3543             :   nsIContent* GetContentInThisDocument(nsIFrame* aFrame) const;
    3544             : 
    3545             :   void ReportShadowDOMUsage();
    3546             : 
    3547             : protected:
    3548             :   already_AddRefed<nsIPrincipal> MaybeDowngradePrincipal(nsIPrincipal* aPrincipal);
    3549             : 
    3550             :   void EnsureOnloadBlocker();
    3551             : 
    3552             :   void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
    3553             : 
    3554             :   // Returns true if the scheme for the url for this document is "about".
    3555             :   bool IsAboutPage() const;
    3556             : 
    3557             :   bool ContainsEMEContent();
    3558             :   bool ContainsMSEContent();
    3559             : 
    3560             :   void MaybeInitializeFinalizeFrameLoaders();
    3561             : 
    3562             :   /**
    3563             :    * Returns the title element of the document as defined by the HTML
    3564             :    * specification, or null if there isn't one.  For documents whose root
    3565             :    * element is an <svg:svg>, this is the first <svg:title> element that's a
    3566             :    * child of the root.  For other documents, it's the first HTML title element
    3567             :    * in the document.
    3568             :    */
    3569             :   Element* GetTitleElement();
    3570             : 
    3571             :   // Retrieves the classification of the Flash plugins in the document based on
    3572             :   // the classification lists.
    3573             :   mozilla::dom::FlashClassification PrincipalFlashClassification();
    3574             : 
    3575             :   // Attempts to determine the Flash classification of this page based on the
    3576             :   // the classification lists and the classification of parent documents.
    3577             :   mozilla::dom::FlashClassification ComputeFlashClassification();
    3578             : 
    3579             :   void RecordNavigationTiming(ReadyState aReadyState);
    3580             : 
    3581             :   // This method may fire a DOM event; if it does so it will happen
    3582             :   // synchronously.
    3583             :   void UpdateVisibilityState();
    3584             : 
    3585             :   // Recomputes the visibility state but doesn't set the new value.
    3586             :   mozilla::dom::VisibilityState ComputeVisibilityState() const;
    3587             : 
    3588             :   // Since we wouldn't automatically play media from non-visited page, we need
    3589             :   // to notify window when the page was first visited.
    3590             :   void MaybeActiveMediaComponents();
    3591             : 
    3592             :   // Apply the fullscreen state to the document, and trigger related
    3593             :   // events. It returns false if the fullscreen element ready check
    3594             :   // fails and nothing gets changed.
    3595             :   bool ApplyFullscreen(const FullscreenRequest& aRequest);
    3596             : 
    3597             :   bool GetUseCounter(mozilla::UseCounter aUseCounter)
    3598             :   {
    3599             :     return mUseCounters[aUseCounter];
    3600             :   }
    3601             : 
    3602             :   void SetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
    3603             :   {
    3604             :     if (!mChildDocumentUseCounters[aUseCounter]) {
    3605             :       mChildDocumentUseCounters[aUseCounter] = true;
    3606             :     }
    3607             :   }
    3608             : 
    3609             :   bool GetChildDocumentUseCounter(mozilla::UseCounter aUseCounter)
    3610             :   {
    3611             :     return mChildDocumentUseCounters[aUseCounter];
    3612             :   }
    3613             : 
    3614             :   void UpdateDocumentStates(mozilla::EventStates);
    3615             : 
    3616             :   void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
    3617             :   void RemoveDocStyleSheetsFromStyleSets();
    3618             :   void RemoveStyleSheetsFromStyleSets(
    3619             :       const nsTArray<RefPtr<mozilla::StyleSheet>>& aSheets,
    3620             :       mozilla::SheetType aType);
    3621             :   void ResetStylesheetsToURI(nsIURI* aURI);
    3622             :   void FillStyleSet(mozilla::ServoStyleSet* aStyleSet);
    3623             :   void AddStyleSheetToStyleSets(mozilla::StyleSheet* aSheet);
    3624             :   void RemoveStyleSheetFromStyleSets(mozilla::StyleSheet* aSheet);
    3625             :   void NotifyStyleSheetAdded(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
    3626             :   void NotifyStyleSheetRemoved(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
    3627             :   void NotifyStyleSheetApplicableStateChanged();
    3628             :   // Just like EnableStyleSheetsForSet, but doesn't check whether
    3629             :   // aSheetSet is null and allows the caller to control whether to set
    3630             :   // aSheetSet as the preferred set in the CSSLoader.
    3631             :   void EnableStyleSheetsForSetInternal(const nsAString& aSheetSet,
    3632             :                                        bool aUpdateCSSLoader);
    3633             : 
    3634             : private:
    3635             :   mutable std::bitset<eDeprecatedOperationCount> mDeprecationWarnedAbout;
    3636             :   mutable std::bitset<eDocumentWarningCount> mDocWarningWarnedAbout;
    3637             : 
    3638             :   // Lazy-initialization to have mDocGroup initialized in prior to the
    3639             :   // SelectorCaches.
    3640             :   mozilla::UniquePtr<SelectorCache> mSelectorCache;
    3641             : 
    3642             : protected:
    3643             :   friend class nsDocumentOnStack;
    3644             : 
    3645             :   void IncreaseStackRefCnt()
    3646             :   {
    3647             :     ++mStackRefCnt;
    3648             :   }
    3649             : 
    3650             :   void DecreaseStackRefCnt()
    3651             :   {
    3652             :     if (--mStackRefCnt == 0 && mNeedsReleaseAfterStackRefCntRelease) {
    3653             :       mNeedsReleaseAfterStackRefCntRelease = false;
    3654             :       NS_RELEASE_THIS();
    3655             :     }
    3656             :   }
    3657             : 
    3658             :   ~nsIDocument();
    3659             : 
    3660             :   // Never ever call this. Only call GetWindow!
    3661             :   nsPIDOMWindowOuter* GetWindowInternal() const;
    3662             : 
    3663             :   // Never ever call this. Only call GetScriptHandlingObject!
    3664             :   nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const;
    3665             : 
    3666             :   // Never ever call this. Only call AllowXULXBL!
    3667             :   bool InternalAllowXULXBL();
    3668             : 
    3669             :   /**
    3670             :    * These methods should be called before and after dispatching
    3671             :    * a mutation event.
    3672             :    * To make this easy and painless, use the mozAutoSubtreeModified helper class.
    3673             :    */
    3674             :   void WillDispatchMutationEvent(nsINode* aTarget);
    3675             :   void MutationEventDispatched(nsINode* aTarget);
    3676             :   friend class mozAutoSubtreeModified;
    3677             : 
    3678           0 :   virtual Element* GetNameSpaceElement() override
    3679             :   {
    3680           0 :     return GetRootElement();
    3681             :   }
    3682             : 
    3683             :   void SetContentTypeInternal(const nsACString& aType);
    3684             : 
    3685             :   nsCString GetContentTypeInternal() const
    3686             :   {
    3687           0 :     return mContentType;
    3688             :   }
    3689             : 
    3690             :   mozilla::dom::XPathEvaluator* XPathEvaluator();
    3691             : 
    3692             :   // Update our frame request callback scheduling state, if needed.  This will
    3693             :   // schedule or unschedule them, if necessary, and update
    3694             :   // mFrameRequestCallbacksScheduled.  aOldShell should only be passed when
    3695             :   // mPresShell is becoming null; in that case it will be used to get hold of
    3696             :   // the relevant refresh driver.
    3697             :   void UpdateFrameRequestCallbackSchedulingState(nsIPresShell* aOldShell = nullptr);
    3698             : 
    3699             :   // Helper for GetScrollingElement/IsScrollingElement.
    3700             :   bool IsPotentiallyScrollable(mozilla::dom::HTMLBodyElement* aBody);
    3701             : 
    3702             :   // Return the same type parent docuement if exists, or return null.
    3703             :   nsIDocument* GetSameTypeParentDocument();
    3704             : 
    3705             :   // Return the first parent document with same pricipal, return nullptr if we
    3706             :   // can't find it.
    3707             :   nsIDocument* GetFirstParentDocumentWithSamePrincipal(nsIPrincipal* aPrincipal);
    3708             : 
    3709             :   // Activate the flag 'mUserHasActivatedInteraction' by specific user gestures.
    3710             :   void ActivateByUserGesture();
    3711             :   void MaybeActivateByUserGesture(nsIPrincipal* aPrincipal);
    3712             : 
    3713             :   // Helpers for GetElementsByName.
    3714             :   static bool MatchNameAttribute(mozilla::dom::Element* aElement,
    3715             :                                  int32_t aNamespaceID,
    3716             :                                  nsAtom* aAtom, void* aData);
    3717             :   static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
    3718             : 
    3719             :   void MaybeResolveReadyForIdle();
    3720             : 
    3721             :   nsCString mReferrer;
    3722             :   nsString mLastModified;
    3723             : 
    3724             :   nsCOMPtr<nsIURI> mDocumentURI;
    3725             :   nsCOMPtr<nsIURI> mOriginalURI;
    3726             :   nsCOMPtr<nsIURI> mChromeXHRDocURI;
    3727             :   nsCOMPtr<nsIURI> mDocumentBaseURI;
    3728             :   nsCOMPtr<nsIURI> mChromeXHRDocBaseURI;
    3729             : 
    3730             :   // A lazily-constructed URL data for style system to resolve URL value.
    3731             :   RefPtr<mozilla::URLExtraData> mCachedURLData;
    3732             : 
    3733             :   nsWeakPtr mDocumentLoadGroup;
    3734             : 
    3735             :   bool mReferrerPolicySet;
    3736             :   ReferrerPolicyEnum mReferrerPolicy;
    3737             : 
    3738             :   bool mBlockAllMixedContent;
    3739             :   bool mBlockAllMixedContentPreloads;
    3740             :   bool mUpgradeInsecureRequests;
    3741             :   bool mUpgradeInsecurePreloads;
    3742             : 
    3743             :   mozilla::WeakPtr<nsDocShell> mDocumentContainer;
    3744             : 
    3745             :   NotNull<const Encoding*> mCharacterSet;
    3746             :   int32_t mCharacterSetSource;
    3747             : 
    3748             :   // This is just a weak pointer; the parent document owns its children.
    3749             :   nsIDocument* mParentDocument;
    3750             : 
    3751             :   // A reference to the element last returned from GetRootElement().
    3752             :   mozilla::dom::Element* mCachedRootElement;
    3753             : 
    3754             :   // This is a weak reference, but we hold a strong reference to mNodeInfo,
    3755             :   // which in turn holds a strong reference to this mNodeInfoManager.
    3756             :   nsNodeInfoManager* mNodeInfoManager;
    3757             :   RefPtr<mozilla::css::Loader> mCSSLoader;
    3758             :   RefPtr<mozilla::css::ImageLoader> mStyleImageLoader;
    3759             :   RefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
    3760             :   RefPtr<nsHTMLCSSStyleSheet> mStyleAttrStyleSheet;
    3761             : 
    3762             :   // Tracking for images in the document.
    3763             :   RefPtr<mozilla::dom::ImageTracker> mImageTracker;
    3764             : 
    3765             :   // A hashtable of ShadowRoots belonging to the composed doc.
    3766             :   //
    3767             :   // See ShadowRoot::SetIsComposedDocParticipant.
    3768             :   ShadowRootSet mComposedShadowRoots;
    3769             : 
    3770             :   // The set of all object, embed, video/audio elements or
    3771             :   // nsIObjectLoadingContent or nsIDocumentActivity for which this is the owner
    3772             :   // document. (They might not be in the document.)
    3773             :   //
    3774             :   // These are non-owning pointers, the elements are responsible for removing
    3775             :   // themselves when they go away.
    3776             :   nsAutoPtr<nsTHashtable<nsPtrHashKey<nsISupports> > > mActivityObservers;
    3777             : 
    3778             :   // A hashtable of styled links keyed by address pointer.
    3779             :   nsTHashtable<nsPtrHashKey<mozilla::dom::Link>> mStyledLinks;
    3780             : #ifdef DEBUG
    3781             :   // Indicates whether mStyledLinks was cleared or not.  This is used to track
    3782             :   // state so we can provide useful assertions to consumers of ForgetLink and
    3783             :   // AddStyleRelevantLink.
    3784             :   bool mStyledLinksCleared;
    3785             : #endif
    3786             : 
    3787             :   // The array of all links that need their status resolved.  Links must add themselves
    3788             :   // to this set by calling RegisterPendingLinkUpdate when added to a document.
    3789             :   static const size_t kSegmentSize = 128;
    3790             : 
    3791             :   typedef mozilla::SegmentedVector<nsCOMPtr<mozilla::dom::Link>,
    3792             :                                    kSegmentSize,
    3793             :                                    InfallibleAllocPolicy>
    3794             :     LinksToUpdateList;
    3795             : 
    3796             :   LinksToUpdateList mLinksToUpdate;
    3797             : 
    3798             :   // SMIL Animation Controller, lazily-initialized in GetAnimationController
    3799             :   RefPtr<nsSMILAnimationController> mAnimationController;
    3800             : 
    3801             :   // Table of element properties for this document.
    3802             :   nsPropertyTable mPropertyTable;
    3803             : 
    3804             :   // Our cached .children collection
    3805             :   nsCOMPtr<nsIHTMLCollection> mChildrenCollection;
    3806             : 
    3807             :   // Various DOM lists
    3808             :   RefPtr<nsContentList> mImages;
    3809             :   RefPtr<nsContentList> mEmbeds;
    3810             :   RefPtr<nsContentList> mLinks;
    3811             :   RefPtr<nsContentList> mForms;
    3812             :   RefPtr<nsContentList> mScripts;
    3813             :   nsCOMPtr<nsIHTMLCollection> mApplets;
    3814             :   RefPtr<nsContentList> mAnchors;
    3815             : 
    3816             :   // container for per-context fonts (downloadable, SVG, etc.)
    3817             :   RefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
    3818             : 
    3819             :   // Last time this document or a one of its sub-documents was focused.  If
    3820             :   // focus has never occurred then mLastFocusTime.IsNull() will be true.
    3821             :   mozilla::TimeStamp mLastFocusTime;
    3822             : 
    3823             :   mozilla::EventStates mDocumentState;
    3824             : 
    3825             :   RefPtr<mozilla::dom::Promise> mReadyForIdle;
    3826             : 
    3827             :   // True if BIDI is enabled.
    3828             :   bool mBidiEnabled : 1;
    3829             :   // True if a MathML element has ever been owned by this document.
    3830             :   bool mMathMLEnabled : 1;
    3831             : 
    3832             :   // True if this document is the initial document for a window.  This should
    3833             :   // basically be true only for documents that exist in newly-opened windows or
    3834             :   // documents created to satisfy a GetDocument() on a window when there's no
    3835             :   // document in it.
    3836             :   bool mIsInitialDocumentInWindow : 1;
    3837             : 
    3838             :   bool mIgnoreDocGroupMismatches : 1;
    3839             : 
    3840             :   // True if we're loaded as data and therefor has any dangerous stuff, such
    3841             :   // as scripts and plugins, disabled.
    3842             :   bool mLoadedAsData : 1;
    3843             : 
    3844             :   // This flag is only set in XMLDocument, for e.g. documents used in XBL. We
    3845             :   // don't want animations to play in such documents, so we need to store the
    3846             :   // flag here so that we can check it in nsDocument::GetAnimationController.
    3847             :   bool mLoadedAsInteractiveData : 1;
    3848             : 
    3849             :   // If true, whoever is creating the document has gotten it to the
    3850             :   // point where it's safe to start layout on it.
    3851             :   bool mMayStartLayout : 1;
    3852             : 
    3853             :   // True iff we've ever fired a DOMTitleChanged event for this document
    3854             :   bool mHaveFiredTitleChange : 1;
    3855             : 
    3856             :   // State for IsShowing(). mIsShowing starts off false. It becomes true when
    3857             :   // OnPageShow happens and becomes false when OnPageHide happens. So it's false
    3858             :   // before the initial load completes and when we're in bfcache or unloaded,
    3859             :   // true otherwise.
    3860             :   bool mIsShowing : 1;
    3861             : 
    3862             :   // State for IsVisible(). mVisible starts off true. It becomes false when
    3863             :   // OnPageHide happens, and becomes true again when OnPageShow happens.  So
    3864             :   // it's false only when we're in bfcache or unloaded.
    3865             :   bool mVisible : 1;
    3866             : 
    3867             :   // True if our content viewer has been removed from the docshell
    3868             :   // (it may still be displayed, but in zombie state). Form control data
    3869             :   // has been saved.
    3870             :   bool mRemovedFromDocShell : 1;
    3871             : 
    3872             :   // True iff DNS prefetch is allowed for this document.  Note that if the
    3873             :   // document has no window, DNS prefetch won't be performed no matter what.
    3874             :   bool mAllowDNSPrefetch : 1;
    3875             : 
    3876             :   // True when this document is a static clone of a normal document
    3877             :   bool mIsStaticDocument : 1;
    3878             : 
    3879             :   // True while this document is being cloned to a static document.
    3880             :   bool mCreatingStaticClone : 1;
    3881             : 
    3882             :   // True iff the document is being unlinked or deleted.
    3883             :   bool mInUnlinkOrDeletion : 1;
    3884             : 
    3885             :   // True if document has ever had script handling object.
    3886             :   bool mHasHadScriptHandlingObject : 1;
    3887             : 
    3888             :   // True if we're an SVG document being used as an image.
    3889             :   bool mIsBeingUsedAsImage : 1;
    3890             : 
    3891             :   // True is this document is synthetic : stand alone image, video, audio
    3892             :   // file, etc.
    3893             :   bool mIsSyntheticDocument : 1;
    3894             : 
    3895             :   // True is there is a pending runnable which will call FlushPendingLinkUpdates().
    3896             :   bool mHasLinksToUpdateRunnable : 1;
    3897             : 
    3898             :   // True if we're flushing pending link updates.
    3899             :   bool mFlushingPendingLinkUpdates : 1;
    3900             : 
    3901             :   // True if a DOMMutationObserver is perhaps attached to a node in the document.
    3902             :   bool mMayHaveDOMMutationObservers : 1;
    3903             : 
    3904             :   // True if an nsIAnimationObserver is perhaps attached to a node in the document.
    3905             :   bool mMayHaveAnimationObservers : 1;
    3906             : 
    3907             :   // True if a document has loaded Mixed Active Script (see nsMixedContentBlocker.cpp)
    3908             :   bool mHasMixedActiveContentLoaded : 1;
    3909             : 
    3910             :   // True if a document has blocked Mixed Active Script (see nsMixedContentBlocker.cpp)
    3911             :   bool mHasMixedActiveContentBlocked : 1;
    3912             : 
    3913             :   // True if a document has loaded Mixed Display/Passive Content (see nsMixedContentBlocker.cpp)
    3914             :   bool mHasMixedDisplayContentLoaded : 1;
    3915             : 
    3916             :   // True if a document has blocked Mixed Display/Passive Content (see nsMixedContentBlocker.cpp)
    3917             :   bool mHasMixedDisplayContentBlocked : 1;
    3918             : 
    3919             :   // True if a document loads a plugin object that attempts to load mixed content subresources through necko(see nsMixedContentBlocker.cpp)
    3920             :   bool mHasMixedContentObjectSubrequest : 1;
    3921             : 
    3922             :   // True if a document load has a CSP attached.
    3923             :   bool mHasCSP : 1;
    3924             : 
    3925             :   // True if a document load has a CSP with unsafe-eval attached.
    3926             :   bool mHasUnsafeEvalCSP : 1;
    3927             : 
    3928             :   // True if a document load has a CSP with unsafe-inline attached.
    3929             :   bool mHasUnsafeInlineCSP : 1;
    3930             : 
    3931             :   // True if a document has blocked Tracking Content
    3932             :   bool mHasTrackingContentBlocked : 1;
    3933             : 
    3934             :   // True if a document has loaded Tracking Content
    3935             :   bool mHasTrackingContentLoaded : 1;
    3936             : 
    3937             :   // True if DisallowBFCaching has been called on this document.
    3938             :   bool mBFCacheDisallowed : 1;
    3939             : 
    3940             :   bool mHasHadDefaultView : 1;
    3941             : 
    3942             :   // Whether style sheet change events will be dispatched for this document
    3943             :   bool mStyleSheetChangeEventsEnabled : 1;
    3944             : 
    3945             :   // Whether the document was created by a srcdoc iframe.
    3946             :   bool mIsSrcdocDocument : 1;
    3947             : 
    3948             :   // Records whether we've done a document.open. If this is true, it's possible
    3949             :   // for nodes from this document to have outdated wrappers in their wrapper
    3950             :   // caches.
    3951             :   bool mDidDocumentOpen : 1;
    3952             : 
    3953             :   // Whether this document has a display document and thus is considered to
    3954             :   // be a resource document.  Normally this is the same as !!mDisplayDocument,
    3955             :   // but mDisplayDocument is cleared during Unlink.  mHasDisplayDocument is
    3956             :   // valid in the document's destructor.
    3957             :   bool mHasDisplayDocument : 1;
    3958             : 
    3959             :   // Is the current mFontFaceSet valid?
    3960             :   bool mFontFaceSetDirty : 1;
    3961             : 
    3962             :   // Has GetUserFontSet() been called?
    3963             :   bool mGetUserFontSetCalled : 1;
    3964             : 
    3965             :   // True if we have fired the DOMContentLoaded event, or don't plan to fire one
    3966             :   // (e.g. we're not being parsed at all).
    3967             :   bool mDidFireDOMContentLoaded : 1;
    3968             : 
    3969             :   // True if ReportHasScrollLinkedEffect() has been called.
    3970             :   bool mHasScrollLinkedEffect : 1;
    3971             : 
    3972             :   // True if we have frame request callbacks scheduled with the refresh driver.
    3973             :   // This should generally be updated only via
    3974             :   // UpdateFrameRequestCallbackSchedulingState.
    3975             :   bool mFrameRequestCallbacksScheduled : 1;
    3976             : 
    3977             :   bool mIsTopLevelContentDocument : 1;
    3978             : 
    3979             :   bool mIsContentDocument : 1;
    3980             : 
    3981             :   // True if we have called BeginLoad and are expecting a paired EndLoad call.
    3982             :   bool mDidCallBeginLoad : 1;
    3983             : 
    3984             :   // True if the document is allowed to use PaymentRequest.
    3985             :   bool mAllowPaymentRequest : 1;
    3986             : 
    3987             :   // True if the encoding menu should be disabled.
    3988             :   bool mEncodingMenuDisabled : 1;
    3989             : 
    3990             :   // True if dom.webcomponents.shadowdom.enabled pref is set when document is
    3991             :   // created.
    3992             :   bool mIsShadowDOMEnabled : 1;
    3993             : 
    3994             :   // True if this document is for an SVG-in-OpenType font.
    3995             :   bool mIsSVGGlyphsDocument : 1;
    3996             : 
    3997             :   // True if the document is being destroyed.
    3998             :   bool mInDestructor: 1;
    3999             : 
    4000             :   // True if the document has been detached from its content viewer.
    4001             :   bool mIsGoingAway: 1;
    4002             : 
    4003             :   bool mInXBLUpdate: 1;
    4004             : 
    4005             :   bool mNeedsReleaseAfterStackRefCntRelease: 1;
    4006             : 
    4007             :   // Whether we have filled our pres shell's style set with the document's
    4008             :   // additional sheets and sheets from the nsStyleSheetService.
    4009             :   bool mStyleSetFilled: 1;
    4010             : 
    4011             :   // Keeps track of whether we have a pending
    4012             :   // 'style-sheet-applicable-state-changed' notification.
    4013             :   bool mSSApplicableStateNotificationPending: 1;
    4014             : 
    4015             :   // True if this document has ever had an HTML or SVG <title> element
    4016             :   // bound to it
    4017             :   bool mMayHaveTitleElement: 1;
    4018             : 
    4019             :   bool mDOMLoadingSet: 1;
    4020             :   bool mDOMInteractiveSet: 1;
    4021             :   bool mDOMCompleteSet: 1;
    4022             :   bool mAutoFocusFired: 1;
    4023             : 
    4024             :   bool mScrolledToRefAlready : 1;
    4025             :   bool mChangeScrollPosWhenScrollingToRef : 1;
    4026             : 
    4027             :   bool mHasWarnedAboutBoxObjects: 1;
    4028             : 
    4029             :   bool mDelayFrameLoaderInitialization: 1;
    4030             : 
    4031             :   bool mSynchronousDOMContentLoaded: 1;
    4032             : 
    4033             :   // Set to true when the document is possibly controlled by the ServiceWorker.
    4034             :   // Used to prevent multiple requests to ServiceWorkerManager.
    4035             :   bool mMaybeServiceWorkerControlled: 1;
    4036             : 
    4037             :   // These member variables cache information about the viewport so we don't
    4038             :   // have to recalculate it each time.
    4039             :   bool mValidWidth: 1;
    4040             :   bool mValidHeight: 1;
    4041             :   bool mAutoSize: 1;
    4042             :   bool mAllowZoom: 1;
    4043             :   bool mAllowDoubleTapZoom: 1;
    4044             :   bool mValidScaleFloat: 1;
    4045             :   bool mValidMaxScale: 1;
    4046             :   bool mScaleStrEmpty: 1;
    4047             :   bool mWidthStrEmpty: 1;
    4048             : 
    4049             :   // Parser aborted. True if the parser of this document was forcibly
    4050             :   // terminated instead of letting it finish at its own pace.
    4051             :   bool mParserAborted: 1;
    4052             : 
    4053             :   // Whether we have reported use counters for this document with Telemetry yet.
    4054             :   // Normally this is only done at document destruction time, but for image
    4055             :   // documents (SVG documents) that are not guaranteed to be destroyed, we
    4056             :   // report use counters when the image cache no longer has any imgRequestProxys
    4057             :   // pointing to them.  We track whether we ever reported use counters so
    4058             :   // that we only report them once for the document.
    4059             :   bool mReportedUseCounters: 1;
    4060             : 
    4061             :   bool mHasReportedShadowDOMUsage: 1;
    4062             : 
    4063             : #ifdef DEBUG
    4064             : public:
    4065             :   bool mWillReparent: 1;
    4066             : protected:
    4067             : #endif
    4068             : 
    4069             :   uint8_t mPendingFullscreenRequests;
    4070             : 
    4071             :   uint8_t mXMLDeclarationBits;
    4072             : 
    4073             :   // Currently active onload blockers.
    4074             :   uint32_t mOnloadBlockCount;
    4075             : 
    4076             :   // Onload blockers which haven't been activated yet.
    4077             :   uint32_t mAsyncOnloadBlockCount;
    4078             : 
    4079             :   // Compatibility mode
    4080             :   nsCompatibility mCompatMode;
    4081             : 
    4082             :   // Our readyState
    4083             :   ReadyState mReadyState;
    4084             : 
    4085             : #ifdef MOZILLA_INTERNAL_API
    4086             :   // Our visibility state
    4087             :   mozilla::dom::VisibilityState mVisibilityState;
    4088             :   static_assert(sizeof(mozilla::dom::VisibilityState) == sizeof(uint8_t),
    4089             :                 "Error size of mVisibilityState and mDummy");
    4090             : #else
    4091             :   uint8_t mDummy;
    4092             : #endif
    4093             : 
    4094             :   enum Type {
    4095             :     eUnknown, // should never be used
    4096             :     eHTML,
    4097             :     eXHTML,
    4098             :     eGenericXML,
    4099             :     eSVG,
    4100             :     eXUL
    4101             :   };
    4102             : 
    4103             :   Type mType;
    4104             : 
    4105             :   uint8_t mDefaultElementType;
    4106             : 
    4107             :   enum Tri {
    4108             :     eTriUnset = 0,
    4109             :     eTriFalse,
    4110             :     eTriTrue
    4111             :   };
    4112             : 
    4113             :   Tri mAllowXULXBL;
    4114             : 
    4115             :   // The document's script global object, the object from which the
    4116             :   // document can get its script context and scope. This is the
    4117             :   // *inner* window object.
    4118             :   nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
    4119             : 
    4120             :   // If mIsStaticDocument is true, mOriginalDocument points to the original
    4121             :   // document.
    4122             :   nsCOMPtr<nsIDocument> mOriginalDocument;
    4123             : 
    4124             :   // The bidi options for this document.  What this bitfield means is
    4125             :   // defined in nsBidiUtils.h
    4126             :   uint32_t mBidiOptions;
    4127             : 
    4128             :   // The sandbox flags on the document. These reflect the value of the sandbox attribute of the
    4129             :   // associated IFRAME or CSP-protectable content, if existent. These are set at load time and
    4130             :   // are immutable - see nsSandboxFlags.h for the possible flags.
    4131             :   uint32_t mSandboxFlags;
    4132             : 
    4133             :   nsCString mContentLanguage;
    4134             : 
    4135             :   // The channel that got passed to nsDocument::StartDocumentLoad(), if any.
    4136             :   nsCOMPtr<nsIChannel> mChannel;
    4137             : private:
    4138             :   nsCString mContentType;
    4139             : protected:
    4140             :   // For document.write() we may need a different content type than mContentType.
    4141             :   nsCString mContentTypeForWriteCalls;
    4142             : 
    4143             :   // The document's security info
    4144             :   nsCOMPtr<nsISupports> mSecurityInfo;
    4145             : 
    4146             :   // The channel that failed to load and resulted in an error page.
    4147             :   // This only applies to error pages. Might be null.
    4148             :   nsCOMPtr<nsIChannel> mFailedChannel;
    4149             : 
    4150             :   // if this document is part of a multipart document,
    4151             :   // the ID can be used to distinguish it from the other parts.
    4152             :   uint32_t mPartID;
    4153             : 
    4154             :   // Cycle collector generation in which we're certain that this document
    4155             :   // won't be collected
    4156             :   uint32_t mMarkedCCGeneration;
    4157             : 
    4158             :   nsIPresShell* mPresShell;
    4159             : 
    4160             :   nsCOMArray<nsINode> mSubtreeModifiedTargets;
    4161             :   uint32_t mSubtreeModifiedDepth;
    4162             : 
    4163             :   // All images in process of being preloaded.  This is a hashtable so
    4164             :   // we can remove them as the real image loads start; that way we
    4165             :   // make sure to not keep the image load going when no one cares
    4166             :   // about it anymore.
    4167             :   nsRefPtrHashtable<nsURIHashKey, imgIRequest> mPreloadingImages;
    4168             : 
    4169             :   // A list of preconnects initiated by the preloader. This prevents
    4170             :   // the same uri from being used more than once, and allows the dom
    4171             :   // builder to not repeat the work of the preloader.
    4172             :   nsDataHashtable<nsURIHashKey, bool> mPreloadedPreconnects;
    4173             : 
    4174             :   // Current depth of picture elements from parser
    4175             :   uint32_t mPreloadPictureDepth;
    4176             : 
    4177             :   // Set if we've found a URL for the current picture
    4178             :   nsString mPreloadPictureFoundSource;
    4179             : 
    4180             :   // If we're an external resource document, this will be non-null and will
    4181             :   // point to our "display document": the one that all resource lookups should
    4182             :   // go to.
    4183             :   nsCOMPtr<nsIDocument> mDisplayDocument;
    4184             : 
    4185             :   uint32_t mEventsSuppressed;
    4186             : 
    4187             :   /**
    4188             :    * https://html.spec.whatwg.org/#ignore-destructive-writes-counter
    4189             :    */
    4190             :   uint32_t mIgnoreDestructiveWritesCounter;
    4191             : 
    4192             :   /**
    4193             :    * The current frame request callback handle
    4194             :    */
    4195             :   int32_t mFrameRequestCallbackCounter;
    4196             : 
    4197             :   // Count of live static clones of this document.
    4198             :   uint32_t mStaticCloneCount;
    4199             : 
    4200             :   // Array of nodes that have been blocked to prevent user tracking.
    4201             :   // They most likely have had their nsIChannel canceled by the URL
    4202             :   // classifier. (Safebrowsing)
    4203             :   //
    4204             :   // Weak nsINode pointers are used to allow nodes to disappear.
    4205             :   nsTArray<nsWeakPtr> mBlockedTrackingNodes;
    4206             : 
    4207             :   // Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow,
    4208             :   // updated on every set of mScriptGlobalObject.
    4209             :   nsPIDOMWindowInner* mWindow;
    4210             : 
    4211             :   nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
    4212             : 
    4213             :   struct FrameRequest;
    4214             : 
    4215             :   nsTArray<FrameRequest> mFrameRequestCallbacks;
    4216             : 
    4217             :   // This object allows us to evict ourself from the back/forward cache.  The
    4218             :   // pointer is non-null iff we're currently in the bfcache.
    4219             :   nsIBFCacheEntry *mBFCacheEntry;
    4220             : 
    4221             :   // Our base target.
    4222             :   nsString mBaseTarget;
    4223             : 
    4224             :   nsCOMPtr<nsIStructuredCloneContainer> mStateObjectContainer;
    4225             :   nsCOMPtr<nsIVariant> mStateObjectCached;
    4226             : 
    4227             :   uint32_t mInSyncOperationCount;
    4228             : 
    4229             :   mozilla::UniquePtr<mozilla::dom::XPathEvaluator> mXPathEvaluator;
    4230             : 
    4231             :   nsTArray<RefPtr<mozilla::dom::AnonymousContent>> mAnonymousContents;
    4232             : 
    4233             :   uint32_t mBlockDOMContentLoaded;
    4234             : 
    4235             :   // Our live MediaQueryLists
    4236             :   mozilla::LinkedList<mozilla::dom::MediaQueryList> mDOMMediaQueryLists;
    4237             : 
    4238             :   // Array of observers
    4239             :   nsTObserverArray<nsIDocumentObserver*> mObservers;
    4240             : 
    4241             :   // Flags for use counters used directly by this document.
    4242             :   std::bitset<mozilla::eUseCounter_Count> mUseCounters;
    4243             :   // Flags for use counters used by any child documents of this document.
    4244             :   std::bitset<mozilla::eUseCounter_Count> mChildDocumentUseCounters;
    4245             :   // Flags for whether we've notified our top-level "page" of a use counter
    4246             :   // for this child document.
    4247             :   std::bitset<mozilla::eUseCounter_Count> mNotifiedPageForUseCounter;
    4248             : 
    4249             :   // Whether the user has interacted with the document or not:
    4250             :   bool mUserHasInteracted;
    4251             : 
    4252             :   // Whether the user has interacted with the document via some specific user
    4253             :   // gestures.
    4254             :   bool mUserHasActivatedInteraction;
    4255             : 
    4256             :   mozilla::TimeStamp mPageUnloadingEventTimeStamp;
    4257             : 
    4258             :   RefPtr<mozilla::dom::DocGroup> mDocGroup;
    4259             : 
    4260             :   // The set of all the tracking script URLs.  URLs are added to this set by
    4261             :   // calling NoteScriptTrackingStatus().  Currently we assume that a URL not
    4262             :   // existing in the set means the corresponding script isn't a tracking script.
    4263             :   nsTHashtable<nsCStringHashKey> mTrackingScripts;
    4264             : 
    4265             :   // List of ancestor principals.  This is set at the point a document
    4266             :   // is connected to a docshell and not mutated thereafter.
    4267             :   nsTArray<nsCOMPtr<nsIPrincipal>> mAncestorPrincipals;
    4268             :   // List of ancestor outerWindowIDs that correspond to the ancestor principals.
    4269             :   nsTArray<uint64_t> mAncestorOuterWindowIDs;
    4270             : 
    4271             :   // Pointer to our parser if we're currently in the process of being
    4272             :   // parsed into.
    4273             :   nsCOMPtr<nsIParser> mParser;
    4274             : 
    4275             :   nsrefcnt mStackRefCnt;
    4276             : 
    4277             :   // Weak reference to our sink for in case we no longer have a parser.  This
    4278             :   // will allow us to flush out any pending stuff from the sink even if
    4279             :   // EndLoad() has already happened.
    4280             :   nsWeakPtr mWeakSink;
    4281             : 
    4282             :   // Our update nesting level
    4283             :   uint32_t mUpdateNestLevel;
    4284             : 
    4285             :   enum ViewportType : uint8_t {
    4286             :     DisplayWidthHeight,
    4287             :     Specified,
    4288             :     Unknown
    4289             :   };
    4290             : 
    4291             :   ViewportType mViewportType;
    4292             : 
    4293             :   // Enum for how content in this document overflows viewport causing
    4294             :   // out-of-reach issue. Currently it only takes horizontal overflow
    4295             :   // into consideration. This enum and the corresponding field is only
    4296             :   // set and read on a top level content document.
    4297             :   enum class ViewportOverflowType : uint8_t {
    4298             :     // Viewport doesn't have out-of-reach overflow content, either
    4299             :     // because the content doesn't overflow, or the viewport doesn't
    4300             :     // have "overflow: hidden".
    4301             :     NoOverflow,
    4302             : 
    4303             :     // All following items indicates that the content overflows the
    4304             :     // scroll port which causing out-of-reach content.
    4305             : 
    4306             :     // Meta viewport is disabled or the document is in desktop mode.
    4307             :     Desktop,
    4308             :     // The content does not overflow the minimum-scale size. When there
    4309             :     // is no minimum scale specified, the default value used by Blink,
    4310             :     // 0.25, is used for this matter.
    4311             :     ButNotMinScaleSize,
    4312             :     // The content overflows the minimum-scale size.
    4313             :     MinScaleSize,
    4314             :   };
    4315             :   ViewportOverflowType mViewportOverflowType;
    4316             : 
    4317             :   PLDHashTable* mSubDocuments;
    4318             : 
    4319             :   nsDocHeaderData* mHeaderData;
    4320             : 
    4321             :   RefPtr<PrincipalFlashClassifier> mPrincipalFlashClassifier;
    4322             :   mozilla::dom::FlashClassification mFlashClassification;
    4323             :   // Do not use this value directly. Call the |IsThirdParty()| method, which
    4324             :   // caches its result here.
    4325             :   mozilla::Maybe<bool> mIsThirdParty;
    4326             : 
    4327             :   nsRevocableEventPtr<nsRunnableMethod<nsIDocument, void, false>>
    4328             :     mPendingTitleChangeEvent;
    4329             : 
    4330             :   RefPtr<nsDOMNavigationTiming> mTiming;
    4331             : 
    4332             :   // Recorded time of change to 'loading' state.
    4333             :   mozilla::TimeStamp mLoadingTimeStamp;
    4334             : 
    4335             :   nsWeakPtr mAutoFocusElement;
    4336             : 
    4337             :   nsCString mScrollToRef;
    4338             : 
    4339             :   // Weak reference to the scope object (aka the script global object)
    4340             :   // that, unlike mScriptGlobalObject, is never unset once set. This
    4341             :   // is a weak reference to avoid leaks due to circular references.
    4342             :   nsWeakPtr mScopeObject;
    4343             : 
    4344             :   // Array of intersection observers
    4345             :   nsTHashtable<nsPtrHashKey<mozilla::dom::DOMIntersectionObserver>>
    4346             :     mIntersectionObservers;
    4347             : 
    4348             :   // Stack of full-screen elements. When we request full-screen we push the
    4349             :   // full-screen element onto this stack, and when we cancel full-screen we
    4350             :   // pop one off this stack, restoring the previous full-screen state
    4351             :   nsTArray<nsWeakPtr> mFullScreenStack;
    4352             : 
    4353             :   // The root of the doc tree in which this document is in. This is only
    4354             :   // non-null when this document is in fullscreen mode.
    4355             :   nsWeakPtr mFullscreenRoot;
    4356             : 
    4357             :   RefPtr<mozilla::dom::DOMImplementation> mDOMImplementation;
    4358             : 
    4359             :   RefPtr<nsContentList> mImageMaps;
    4360             : 
    4361             :   // A set of responsive images keyed by address pointer.
    4362             :   nsTHashtable<nsPtrHashKey<mozilla::dom::HTMLImageElement>> mResponsiveContent;
    4363             : 
    4364             :   // Tracking for plugins in the document.
    4365             :   nsTHashtable<nsPtrHashKey<nsIObjectLoadingContent>> mPlugins;
    4366             : 
    4367             :   // Array of owning references to all children
    4368             :   nsAttrAndChildArray mChildren;
    4369             : 
    4370             :   RefPtr<mozilla::dom::DocumentTimeline> mDocumentTimeline;
    4371             :   mozilla::LinkedList<mozilla::dom::DocumentTimeline> mTimelines;
    4372             : 
    4373             :   RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
    4374             : 
    4375             :   nsRefPtrHashtable<nsPtrHashKey<nsIContent>, mozilla::dom::BoxObject>*
    4376             :     mBoxObjectTable;
    4377             : 
    4378             :   // Tracker for animations that are waiting to start.
    4379             :   // nullptr until GetOrCreatePendingAnimationTracker is called.
    4380             :   RefPtr<mozilla::PendingAnimationTracker> mPendingAnimationTracker;
    4381             : 
    4382             :   // A document "without a browsing context" that owns the content of
    4383             :   // HTMLTemplateElement.
    4384             :   nsCOMPtr<nsIDocument> mTemplateContentsOwner;
    4385             : 
    4386             :   nsExternalResourceMap mExternalResourceMap;
    4387             : 
    4388             :   // ScreenOrientation "pending promise" as described by
    4389             :   // http://www.w3.org/TR/screen-orientation/
    4390             :   RefPtr<mozilla::dom::Promise> mOrientationPendingPromise;
    4391             : 
    4392             :   uint16_t mCurrentOrientationAngle;
    4393             :   mozilla::dom::OrientationType mCurrentOrientationType;
    4394             : 
    4395             :   nsTArray<RefPtr<nsFrameLoader>> mInitializableFrameLoaders;
    4396             :   nsTArray<nsCOMPtr<nsIRunnable>> mFrameLoaderFinalizers;
    4397             :   RefPtr<nsRunnableMethod<nsIDocument>> mFrameLoaderRunner;
    4398             : 
    4399             :   // The layout history state that should be used by nodes in this
    4400             :   // document.  We only actually store a pointer to it when:
    4401             :   // 1)  We have no script global object.
    4402             :   // 2)  We haven't had Destroy() called on us yet.
    4403             :   nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
    4404             : 
    4405             :   // These member variables cache information about the viewport so we don't
    4406             :   // have to recalculate it each time.
    4407             :   mozilla::LayoutDeviceToScreenScale mScaleMinFloat;
    4408             :   mozilla::LayoutDeviceToScreenScale mScaleMaxFloat;
    4409             :   mozilla::LayoutDeviceToScreenScale mScaleFloat;
    4410             :   mozilla::CSSToLayoutDeviceScale mPixelRatio;
    4411             :   mozilla::CSSSize mViewportSize;
    4412             : 
    4413             :   RefPtr<mozilla::EventListenerManager> mListenerManager;
    4414             : 
    4415             :   nsCOMPtr<nsIRunnable> mMaybeEndOutermostXBLUpdateRunner;
    4416             :   nsCOMPtr<nsIRequest> mOnloadBlocker;
    4417             : 
    4418             :   nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
    4419             :   nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
    4420             : 
    4421             :   // Member to store out last-selected stylesheet set.
    4422             :   nsString mLastStyleSheetSet;
    4423             :   nsString mPreferredStyleSheetSet;
    4424             : 
    4425             :   RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
    4426             : 
    4427             :   // We lazily calculate declaration blocks for SVG elements with mapped
    4428             :   // attributes in Servo mode. This list contains all elements which need lazy
    4429             :   // resolution.
    4430             :   nsTHashtable<nsPtrHashKey<nsSVGElement>> mLazySVGPresElements;
    4431             : 
    4432             :   // Restyle root for servo's style system.
    4433             :   //
    4434             :   // We store this as an nsINode, rather than as an Element, so that we can store
    4435             :   // the Document node as the restyle root if the entire document (along with all
    4436             :   // document-level native-anonymous content) needs to be restyled.
    4437             :   //
    4438             :   // We also track which "descendant" bits (normal/animation-only/lazy-fc) the
    4439             :   // root corresponds to.
    4440             :   nsCOMPtr<nsINode> mServoRestyleRoot;
    4441             :   uint32_t mServoRestyleRootDirtyBits;
    4442             : 
    4443             :   // Used in conjunction with the create-an-element-for-the-token algorithm to
    4444             :   // prevent custom element constructors from being able to use document.open(),
    4445             :   // document.close(), and document.write() when they are invoked by the parser.
    4446             :   uint32_t mThrowOnDynamicMarkupInsertionCounter;
    4447             : 
    4448             :   // Count of unload/beforeunload/pagehide operations in progress.
    4449             :   uint32_t mIgnoreOpensDuringUnloadCounter;
    4450             : };
    4451             : 
    4452             : NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID)
    4453             : 
    4454             : /**
    4455             :  * mozAutoSubtreeModified batches DOM mutations so that a DOMSubtreeModified
    4456             :  * event is dispatched, if necessary, when the outermost mozAutoSubtreeModified
    4457             :  * object is deleted.
    4458             :  */
    4459             : class MOZ_STACK_CLASS mozAutoSubtreeModified
    4460             : {
    4461             : public:
    4462             :   /**
    4463             :    * @param aSubTreeOwner The document in which a subtree will be modified.
    4464             :    * @param aTarget       The target of the possible DOMSubtreeModified event.
    4465             :    *                      Can be nullptr, in which case mozAutoSubtreeModified
    4466             :    *                      is just used to batch DOM mutations.
    4467             :    */
    4468           0 :   mozAutoSubtreeModified(nsIDocument* aSubtreeOwner, nsINode* aTarget)
    4469           0 :   {
    4470           0 :     UpdateTarget(aSubtreeOwner, aTarget);
    4471           0 :   }
    4472             : 
    4473           0 :   ~mozAutoSubtreeModified()
    4474           0 :   {
    4475           0 :     UpdateTarget(nullptr, nullptr);
    4476           0 :   }
    4477             : 
    4478           0 :   void UpdateTarget(nsIDocument* aSubtreeOwner, nsINode* aTarget)
    4479             :   {
    4480           0 :     if (mSubtreeOwner) {
    4481           0 :       mSubtreeOwner->MutationEventDispatched(mTarget);
    4482             :     }
    4483             : 
    4484           0 :     mTarget = aTarget;
    4485           0 :     mSubtreeOwner = aSubtreeOwner;
    4486           0 :     if (mSubtreeOwner) {
    4487           0 :       mSubtreeOwner->WillDispatchMutationEvent(mTarget);
    4488             :     }
    4489           0 :   }
    4490             : 
    4491             : private:
    4492             :   nsCOMPtr<nsINode>     mTarget;
    4493             :   nsCOMPtr<nsIDocument> mSubtreeOwner;
    4494             : };
    4495             : 
    4496             : class MOZ_STACK_CLASS nsAutoSyncOperation
    4497             : {
    4498             : public:
    4499             :   explicit nsAutoSyncOperation(nsIDocument* aDocument);
    4500             :   ~nsAutoSyncOperation();
    4501             : private:
    4502             :   nsCOMArray<nsIDocument> mDocuments;
    4503             :   uint32_t                mMicroTaskLevel;
    4504             : };
    4505             : 
    4506             : class MOZ_RAII AutoSetThrowOnDynamicMarkupInsertionCounter final {
    4507             :   public:
    4508             :     explicit AutoSetThrowOnDynamicMarkupInsertionCounter(
    4509             :       nsIDocument* aDocument)
    4510             :       : mDocument(aDocument)
    4511             :     {
    4512             :       mDocument->IncrementThrowOnDynamicMarkupInsertionCounter();
    4513             :     }
    4514             : 
    4515             :     ~AutoSetThrowOnDynamicMarkupInsertionCounter() {
    4516             :       mDocument->DecrementThrowOnDynamicMarkupInsertionCounter();
    4517             :     }
    4518             : 
    4519             :   private:
    4520             :     nsIDocument* mDocument;
    4521             : };
    4522             : 
    4523             : class MOZ_RAII IgnoreOpensDuringUnload final
    4524             : {
    4525             : public:
    4526             :   explicit IgnoreOpensDuringUnload(nsIDocument* aDoc)
    4527           0 :     : mDoc(aDoc)
    4528             :   {
    4529           0 :     mDoc->IncrementIgnoreOpensDuringUnloadCounter();
    4530             :   }
    4531             : 
    4532           2 :   ~IgnoreOpensDuringUnload()
    4533           2 :   {
    4534           2 :     mDoc->DecrementIgnoreOpensDuringUnloadCounter();
    4535           2 :   }
    4536             : private:
    4537             :   nsIDocument* mDoc;
    4538             : };
    4539             : 
    4540             : // XXX These belong somewhere else
    4541             : nsresult
    4542             : NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
    4543             : 
    4544             : nsresult
    4545             : NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false,
    4546             :                   bool aIsPlainDocument = false);
    4547             : 
    4548             : nsresult
    4549             : NS_NewSVGDocument(nsIDocument** aInstancePtrResult);
    4550             : 
    4551             : nsresult
    4552             : NS_NewImageDocument(nsIDocument** aInstancePtrResult);
    4553             : 
    4554             : nsresult
    4555             : NS_NewVideoDocument(nsIDocument** aInstancePtrResult);
    4556             : 
    4557             : // Note: it's the caller's responsibility to create or get aPrincipal as needed
    4558             : // -- this method will not attempt to get a principal based on aDocumentURI.
    4559             : // Also, both aDocumentURI and aBaseURI must not be null.
    4560             : nsresult
    4561             : NS_NewDOMDocument(nsIDocument** aInstancePtrResult,
    4562             :                   const nsAString& aNamespaceURI,
    4563             :                   const nsAString& aQualifiedName,
    4564             :                   mozilla::dom::DocumentType* aDoctype,
    4565             :                   nsIURI* aDocumentURI,
    4566             :                   nsIURI* aBaseURI,
    4567             :                   nsIPrincipal* aPrincipal,
    4568             :                   bool aLoadedAsData,
    4569             :                   nsIGlobalObject* aEventObject,
    4570             :                   DocumentFlavor aFlavor);
    4571             : 
    4572             : // This is used only for xbl documents created from the startup cache.
    4573             : // Non-cached documents are created in the same manner as xml documents.
    4574             : nsresult
    4575             : NS_NewXBLDocument(nsIDocument** aInstancePtrResult,
    4576             :                   nsIURI* aDocumentURI,
    4577             :                   nsIURI* aBaseURI,
    4578             :                   nsIPrincipal* aPrincipal);
    4579             : 
    4580             : nsresult
    4581             : NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
    4582             : 
    4583             : inline nsIDocument*
    4584             : nsINode::GetOwnerDocument() const
    4585             : {
    4586             :   nsIDocument* ownerDoc = OwnerDoc();
    4587             : 
    4588             :   return ownerDoc != this ? ownerDoc : nullptr;
    4589             : }
    4590             : 
    4591             : inline nsINode*
    4592             : nsINode::OwnerDocAsNode() const
    4593             : {
    4594             :   return OwnerDoc();
    4595             : }
    4596             : 
    4597             : // ShouldUseXBLScope is defined here as a template so that we can get the faster
    4598             : // version of IsInAnonymousSubtree if we're statically known to be an
    4599             : // nsIContent.  we could try defining ShouldUseXBLScope separately on nsINode
    4600             : // and nsIContent, but then we couldn't put its nsINode implementation here
    4601             : // (because this header does not include nsIContent) and we can't put it in
    4602             : // nsIContent.h, because the definition of nsIContent::IsInAnonymousSubtree is
    4603             : // in nsIContentInlines.h.  And then we get include hell from people trying to
    4604             : // call nsINode::GetParentObject but not including nsIContentInlines.h and with
    4605             : // no really good way to include it.
    4606             : template<typename T>
    4607             : inline bool ShouldUseXBLScope(const T* aNode)
    4608             : {
    4609             :   return aNode->IsInAnonymousSubtree() &&
    4610             :          !aNode->IsAnonymousContentInSVGUseSubtree();
    4611             : }
    4612             : 
    4613             : inline mozilla::dom::ParentObject
    4614             : nsINode::GetParentObject() const
    4615             : {
    4616             :   mozilla::dom::ParentObject p(OwnerDoc());
    4617             :     // Note that mUseXBLScope is a no-op for chrome, and other places where we
    4618             :     // don't use XBL scopes.
    4619             :   p.mUseXBLScope = ShouldUseXBLScope(this);
    4620             :   return p;
    4621             : }
    4622             : 
    4623             : inline nsIDocument*
    4624             : nsINode::AsDocument()
    4625             : {
    4626             :   MOZ_ASSERT(IsDocument());
    4627             :   return static_cast<nsIDocument*>(this);
    4628             : }
    4629             : 
    4630             : inline const nsIDocument*
    4631             : nsINode::AsDocument() const
    4632             : {
    4633             :   MOZ_ASSERT(IsDocument());
    4634             :   return static_cast<const nsIDocument*>(this);
    4635             : }
    4636             : 
    4637             : #endif /* nsIDocument_h___ */

Generated by: LCOV version 1.13-14-ga5dd952