LCOV - code coverage report
Current view: top level - dom/base - nsDocument.h (source / functions) Hit Total Coverage
Test: output.info Lines: 36 82 43.9 %
Date: 2017-07-14 16:53:18 Functions: 18 94 19.1 %
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             : 
       7             : /*
       8             :  * Base class for all our document implementations.
       9             :  */
      10             : 
      11             : #ifndef nsDocument_h___
      12             : #define nsDocument_h___
      13             : 
      14             : #include "nsIDocument.h"
      15             : 
      16             : #include "nsCOMPtr.h"
      17             : #include "nsAutoPtr.h"
      18             : #include "nsCRT.h"
      19             : #include "nsWeakReference.h"
      20             : #include "nsWeakPtr.h"
      21             : #include "nsTArray.h"
      22             : #include "nsIdentifierMapEntry.h"
      23             : #include "nsIDOMDocument.h"
      24             : #include "nsIDOMDocumentXBL.h"
      25             : #include "nsStubDocumentObserver.h"
      26             : #include "nsIScriptGlobalObject.h"
      27             : #include "nsIContent.h"
      28             : #include "nsIPrincipal.h"
      29             : #include "nsIParser.h"
      30             : #include "nsBindingManager.h"
      31             : #include "nsRefPtrHashtable.h"
      32             : #include "nsJSThingHashtable.h"
      33             : #include "nsIScriptObjectPrincipal.h"
      34             : #include "nsIURI.h"
      35             : #include "nsIRadioGroupContainer.h"
      36             : #include "nsILayoutHistoryState.h"
      37             : #include "nsIRequest.h"
      38             : #include "nsILoadGroup.h"
      39             : #include "nsTObserverArray.h"
      40             : #include "nsStubMutationObserver.h"
      41             : #include "nsIChannel.h"
      42             : #include "nsCycleCollectionParticipant.h"
      43             : #include "nsContentList.h"
      44             : #include "nsGkAtoms.h"
      45             : #include "nsIApplicationCache.h"
      46             : #include "nsIApplicationCacheContainer.h"
      47             : #include "mozilla/StyleSetHandle.h"
      48             : #include "PLDHashTable.h"
      49             : #include "nsAttrAndChildArray.h"
      50             : #include "nsDOMAttributeMap.h"
      51             : #include "nsIContentViewer.h"
      52             : #include "nsIInterfaceRequestor.h"
      53             : #include "nsILoadContext.h"
      54             : #include "nsIProgressEventSink.h"
      55             : #include "nsISecurityEventSink.h"
      56             : #include "nsIChannelEventSink.h"
      57             : #include "imgIRequest.h"
      58             : #include "mozilla/EventListenerManager.h"
      59             : #include "mozilla/EventStates.h"
      60             : #include "mozilla/MemoryReporting.h"
      61             : #include "mozilla/PendingAnimationTracker.h"
      62             : #include "mozilla/dom/BoxObject.h"
      63             : #include "mozilla/dom/DOMImplementation.h"
      64             : #include "mozilla/dom/ScriptLoader.h"
      65             : #include "mozilla/dom/StyleSheetList.h"
      66             : #include "nsDataHashtable.h"
      67             : #include "mozilla/TimeStamp.h"
      68             : #include "mozilla/Attributes.h"
      69             : #include "nsIDOMXPathEvaluator.h"
      70             : #include "jsfriendapi.h"
      71             : #include "mozilla/LinkedList.h"
      72             : #include "CustomElementRegistry.h"
      73             : #include "mozilla/dom/Performance.h"
      74             : #include "mozilla/Maybe.h"
      75             : 
      76             : #define XML_DECLARATION_BITS_DECLARATION_EXISTS   (1 << 0)
      77             : #define XML_DECLARATION_BITS_ENCODING_EXISTS      (1 << 1)
      78             : #define XML_DECLARATION_BITS_STANDALONE_EXISTS    (1 << 2)
      79             : #define XML_DECLARATION_BITS_STANDALONE_YES       (1 << 3)
      80             : 
      81             : 
      82             : class nsDOMStyleSheetSetList;
      83             : class nsDocument;
      84             : class nsIRadioVisitor;
      85             : class nsIFormControl;
      86             : struct nsRadioGroupStruct;
      87             : class nsOnloadBlocker;
      88             : class nsUnblockOnloadEvent;
      89             : class nsDOMNavigationTiming;
      90             : class nsWindowSizes;
      91             : class nsHtml5TreeOpExecutor;
      92             : class nsDocumentOnStack;
      93             : class nsISecurityConsoleMessage;
      94             : 
      95             : namespace mozilla {
      96             : class EventChainPreVisitor;
      97             : namespace dom {
      98             : class ImageTracker;
      99             : struct LifecycleCallbacks;
     100             : class CallbackFunction;
     101             : class DOMIntersectionObserver;
     102             : class Performance;
     103             : 
     104             : struct FullscreenRequest : public LinkedListElement<FullscreenRequest>
     105             : {
     106             :   explicit FullscreenRequest(Element* aElement);
     107             :   FullscreenRequest(const FullscreenRequest&) = delete;
     108             :   ~FullscreenRequest();
     109             : 
     110           0 :   Element* GetElement() const { return mElement; }
     111           0 :   nsDocument* GetDocument() const { return mDocument; }
     112             : 
     113             : private:
     114             :   RefPtr<Element> mElement;
     115             :   RefPtr<nsDocument> mDocument;
     116             : 
     117             : public:
     118             :   // This value should be true if the fullscreen request is
     119             :   // originated from chrome code.
     120             :   bool mIsCallerChrome = false;
     121             :   // This value denotes whether we should trigger a NewOrigin event if
     122             :   // requesting fullscreen in its document causes the origin which is
     123             :   // fullscreen to change. We may want *not* to trigger that event if
     124             :   // we're calling RequestFullScreen() as part of a continuation of a
     125             :   // request in a subdocument in different process, whereupon the caller
     126             :   // need to send some notification itself with the real origin.
     127             :   bool mShouldNotifyNewOrigin = true;
     128             : };
     129             : 
     130             : } // namespace dom
     131             : } // namespace mozilla
     132             : 
     133             : class nsDocHeaderData
     134             : {
     135             : public:
     136           0 :   nsDocHeaderData(nsIAtom* aField, const nsAString& aData)
     137           0 :     : mField(aField), mData(aData), mNext(nullptr)
     138             :   {
     139           0 :   }
     140             : 
     141           0 :   ~nsDocHeaderData(void)
     142           0 :   {
     143           0 :     delete mNext;
     144           0 :   }
     145             : 
     146             :   nsCOMPtr<nsIAtom> mField;
     147             :   nsString          mData;
     148             :   nsDocHeaderData*  mNext;
     149             : };
     150             : 
     151             : class nsDOMStyleSheetList : public mozilla::dom::StyleSheetList,
     152             :                             public nsStubDocumentObserver
     153             : {
     154             : public:
     155             :   explicit nsDOMStyleSheetList(nsIDocument* aDocument);
     156             : 
     157             :   NS_DECL_ISUPPORTS_INHERITED
     158             : 
     159             :   // nsIDocumentObserver
     160             :   NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED
     161             :   NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED
     162             : 
     163             :   // nsIMutationObserver
     164             :   NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
     165             : 
     166           2 :   virtual nsINode* GetParentObject() const override
     167             :   {
     168           2 :     return mDocument;
     169             :   }
     170             : 
     171             :   uint32_t Length() override;
     172             :   mozilla::StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) override;
     173             : 
     174             : protected:
     175             :   virtual ~nsDOMStyleSheetList();
     176             : 
     177             :   int32_t       mLength;
     178             :   nsIDocument*  mDocument;
     179             : };
     180             : 
     181             : class nsOnloadBlocker final : public nsIRequest
     182             : {
     183             : public:
     184          55 :   nsOnloadBlocker() {}
     185             : 
     186             :   NS_DECL_ISUPPORTS
     187             :   NS_DECL_NSIREQUEST
     188             : 
     189             : private:
     190           0 :   ~nsOnloadBlocker() {}
     191             : };
     192             : 
     193           0 : class nsExternalResourceMap
     194             : {
     195             : public:
     196             :   typedef nsIDocument::ExternalResourceLoad ExternalResourceLoad;
     197             :   nsExternalResourceMap();
     198             : 
     199             :   /**
     200             :    * Request an external resource document.  This does exactly what
     201             :    * nsIDocument::RequestExternalResource is documented to do.
     202             :    */
     203             :   nsIDocument* RequestResource(nsIURI* aURI,
     204             :                                nsINode* aRequestingNode,
     205             :                                nsDocument* aDisplayDocument,
     206             :                                ExternalResourceLoad** aPendingLoad);
     207             : 
     208             :   /**
     209             :    * Enumerate the resource documents.  See
     210             :    * nsIDocument::EnumerateExternalResources.
     211             :    */
     212             :   void EnumerateResources(nsIDocument::nsSubDocEnumFunc aCallback, void* aData);
     213             : 
     214             :   /**
     215             :    * Traverse ourselves for cycle-collection
     216             :    */
     217             :   void Traverse(nsCycleCollectionTraversalCallback* aCallback) const;
     218             : 
     219             :   /**
     220             :    * Shut ourselves down (used for cycle-collection unlink), as well
     221             :    * as for document destruction.
     222             :    */
     223           4 :   void Shutdown()
     224             :   {
     225           4 :     mPendingLoads.Clear();
     226           4 :     mMap.Clear();
     227           4 :     mHaveShutDown = true;
     228           4 :   }
     229             : 
     230           0 :   bool HaveShutDown() const
     231             :   {
     232           0 :     return mHaveShutDown;
     233             :   }
     234             : 
     235             :   // Needs to be public so we can traverse them sanely
     236           0 :   struct ExternalResource
     237             :   {
     238             :     ~ExternalResource();
     239             :     nsCOMPtr<nsIDocument> mDocument;
     240             :     nsCOMPtr<nsIContentViewer> mViewer;
     241             :     nsCOMPtr<nsILoadGroup> mLoadGroup;
     242             :   };
     243             : 
     244             :   // Hide all our viewers
     245             :   void HideViewers();
     246             : 
     247             :   // Show all our viewers
     248             :   void ShowViewers();
     249             : 
     250             : protected:
     251             :   class PendingLoad : public ExternalResourceLoad,
     252             :                       public nsIStreamListener
     253             :   {
     254           0 :     ~PendingLoad() {}
     255             : 
     256             :   public:
     257           0 :     explicit PendingLoad(nsDocument* aDisplayDocument) :
     258           0 :       mDisplayDocument(aDisplayDocument)
     259           0 :     {}
     260             : 
     261             :     NS_DECL_ISUPPORTS
     262             :     NS_DECL_NSISTREAMLISTENER
     263             :     NS_DECL_NSIREQUESTOBSERVER
     264             : 
     265             :     /**
     266             :      * Start aURI loading.  This will perform the necessary security checks and
     267             :      * so forth.
     268             :      */
     269             :     nsresult StartLoad(nsIURI* aURI, nsINode* aRequestingNode);
     270             : 
     271             :     /**
     272             :      * Set up an nsIContentViewer based on aRequest.  This is guaranteed to
     273             :      * put null in *aViewer and *aLoadGroup on all failures.
     274             :      */
     275             :     nsresult SetupViewer(nsIRequest* aRequest, nsIContentViewer** aViewer,
     276             :                          nsILoadGroup** aLoadGroup);
     277             : 
     278             :   private:
     279             :     RefPtr<nsDocument> mDisplayDocument;
     280             :     nsCOMPtr<nsIStreamListener> mTargetListener;
     281             :     nsCOMPtr<nsIURI> mURI;
     282             :   };
     283             :   friend class PendingLoad;
     284             : 
     285             :   class LoadgroupCallbacks final : public nsIInterfaceRequestor
     286             :   {
     287           0 :     ~LoadgroupCallbacks() {}
     288             :   public:
     289           0 :     explicit LoadgroupCallbacks(nsIInterfaceRequestor* aOtherCallbacks)
     290           0 :       : mCallbacks(aOtherCallbacks)
     291           0 :     {}
     292             :     NS_DECL_ISUPPORTS
     293             :     NS_DECL_NSIINTERFACEREQUESTOR
     294             :   private:
     295             :     // The only reason it's safe to hold a strong ref here without leaking is
     296             :     // that the notificationCallbacks on a loadgroup aren't the docshell itself
     297             :     // but a shim that holds a weak reference to the docshell.
     298             :     nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
     299             : 
     300             :     // Use shims for interfaces that docshell implements directly so that we
     301             :     // don't hand out references to the docshell.  The shims should all allow
     302             :     // getInterface back on us, but other than that each one should only
     303             :     // implement one interface.
     304             : 
     305             :     // XXXbz I wish we could just derive the _allcaps thing from _i
     306             : #define DECL_SHIM(_i, _allcaps)                                              \
     307             :     class _i##Shim final : public nsIInterfaceRequestor,                     \
     308             :                            public _i                                         \
     309             :     {                                                                        \
     310             :       ~_i##Shim() {}                                                         \
     311             :     public:                                                                  \
     312             :       _i##Shim(nsIInterfaceRequestor* aIfreq, _i* aRealPtr)                  \
     313             :         : mIfReq(aIfreq), mRealPtr(aRealPtr)                                 \
     314             :       {                                                                      \
     315             :         NS_ASSERTION(mIfReq, "Expected non-null here");                      \
     316             :         NS_ASSERTION(mRealPtr, "Expected non-null here");                    \
     317             :       }                                                                      \
     318             :       NS_DECL_ISUPPORTS                                                      \
     319             :       NS_FORWARD_NSIINTERFACEREQUESTOR(mIfReq->)                             \
     320             :       NS_FORWARD_##_allcaps(mRealPtr->)                                      \
     321             :     private:                                                                 \
     322             :       nsCOMPtr<nsIInterfaceRequestor> mIfReq;                                \
     323             :       nsCOMPtr<_i> mRealPtr;                                                 \
     324             :     };
     325             : 
     326           0 :     DECL_SHIM(nsILoadContext, NSILOADCONTEXT)
     327           0 :     DECL_SHIM(nsIProgressEventSink, NSIPROGRESSEVENTSINK)
     328           0 :     DECL_SHIM(nsIChannelEventSink, NSICHANNELEVENTSINK)
     329           0 :     DECL_SHIM(nsISecurityEventSink, NSISECURITYEVENTSINK)
     330           0 :     DECL_SHIM(nsIApplicationCacheContainer, NSIAPPLICATIONCACHECONTAINER)
     331             : #undef DECL_SHIM
     332             :   };
     333             : 
     334             :   /**
     335             :    * Add an ExternalResource for aURI.  aViewer and aLoadGroup might be null
     336             :    * when this is called if the URI didn't result in an XML document.  This
     337             :    * function makes sure to remove the pending load for aURI, if any, from our
     338             :    * hashtable, and to notify its observers, if any.
     339             :    */
     340             :   nsresult AddExternalResource(nsIURI* aURI, nsIContentViewer* aViewer,
     341             :                                nsILoadGroup* aLoadGroup,
     342             :                                nsIDocument* aDisplayDocument);
     343             : 
     344             :   nsClassHashtable<nsURIHashKey, ExternalResource> mMap;
     345             :   nsRefPtrHashtable<nsURIHashKey, PendingLoad> mPendingLoads;
     346             :   bool mHaveShutDown;
     347             : };
     348             : 
     349             : // Base class for our document implementations.
     350             : class nsDocument : public nsIDocument,
     351             :                    public nsIDOMDocument,
     352             :                    public nsIDOMDocumentXBL,
     353             :                    public nsSupportsWeakReference,
     354             :                    public nsIScriptObjectPrincipal,
     355             :                    public nsIRadioGroupContainer,
     356             :                    public nsIApplicationCacheContainer,
     357             :                    public nsStubMutationObserver,
     358             :                    public nsIObserver,
     359             :                    public nsIDOMXPathEvaluator
     360             : {
     361             :   friend class nsIDocument;
     362             : 
     363             : public:
     364             :   typedef mozilla::dom::Element Element;
     365             :   using nsIDocument::GetElementsByTagName;
     366             :   typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
     367             : 
     368             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     369             : 
     370             :   NS_DECL_SIZEOF_EXCLUDING_THIS
     371             : 
     372             :   virtual void Reset(nsIChannel *aChannel, nsILoadGroup *aLoadGroup) override;
     373             :   virtual void ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
     374             :                           nsIPrincipal* aPrincipal) override;
     375             : 
     376             :   already_AddRefed<nsIPrincipal> MaybeDowngradePrincipal(nsIPrincipal* aPrincipal);
     377             : 
     378             :   // StartDocumentLoad is pure virtual so that subclasses must override it.
     379             :   // The nsDocument StartDocumentLoad does some setup, but does NOT set
     380             :   // *aDocListener; this is the job of subclasses.
     381             :   virtual nsresult StartDocumentLoad(const char* aCommand,
     382             :                                      nsIChannel* aChannel,
     383             :                                      nsILoadGroup* aLoadGroup,
     384             :                                      nsISupports* aContainer,
     385             :                                      nsIStreamListener **aDocListener,
     386             :                                      bool aReset = true,
     387             :                                      nsIContentSink* aContentSink = nullptr) override = 0;
     388             : 
     389             :   virtual void StopDocumentLoad() override;
     390             : 
     391             :   virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) override;
     392             : 
     393             :   virtual void SetDocumentURI(nsIURI* aURI) override;
     394             : 
     395             :   virtual void SetChromeXHRDocURI(nsIURI* aURI) override;
     396             : 
     397             :   virtual void SetChromeXHRDocBaseURI(nsIURI* aURI) override;
     398             : 
     399             :   virtual void ApplySettingsFromCSP(bool aSpeculative) override;
     400             : 
     401             :   virtual already_AddRefed<nsIParser> CreatorParserOrNull() override;
     402             : 
     403             :   /**
     404             :    * Set the principal responsible for this document.
     405             :    */
     406             :   virtual void SetPrincipal(nsIPrincipal *aPrincipal) override;
     407             : 
     408             :   /**
     409             :    * Get the Content-Type of this document.
     410             :    */
     411             :   // NS_IMETHOD GetContentType(nsAString& aContentType);
     412             :   // Already declared in nsIDOMDocument
     413             : 
     414             :   /**
     415             :    * Set the Content-Type of this document.
     416             :    */
     417             :   virtual void SetContentType(const nsAString& aContentType) override;
     418             : 
     419             :   virtual void SetBaseURI(nsIURI* aURI) override;
     420             : 
     421             :   /**
     422             :    * Get/Set the base target of a link in a document.
     423             :    */
     424             :   virtual void GetBaseTarget(nsAString &aBaseTarget) override;
     425             : 
     426             :   /**
     427             :    * Set the document's character encoding. This will
     428             :    * trigger a startDocumentLoad if necessary to answer the question.
     429             :    */
     430             :   virtual void
     431             :     SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) override;
     432             : 
     433             :   /**
     434             :    * Add an observer that gets notified whenever the charset changes.
     435             :    */
     436             :   virtual nsresult AddCharSetObserver(nsIObserver* aObserver) override;
     437             : 
     438             :   /**
     439             :    * Remove a charset observer.
     440             :    */
     441             :   virtual void RemoveCharSetObserver(nsIObserver* aObserver) override;
     442             : 
     443             :   virtual Element* AddIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
     444             :                                        void* aData, bool aForImage) override;
     445             :   virtual void RemoveIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
     446             :                                       void* aData, bool aForImage) override;
     447             : 
     448             :   /**
     449             :    * Access HTTP header data (this may also get set from other sources, like
     450             :    * HTML META tags).
     451             :    */
     452             :   virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const override;
     453             :   virtual void SetHeaderData(nsIAtom* aheaderField,
     454             :                              const nsAString& aData) override;
     455             : 
     456             :   /**
     457             :    * Create a new presentation shell that will use aContext for
     458             :    * its presentation context (presentation contexts <b>must not</b> be
     459             :    * shared among multiple presentation shells).
     460             :    */
     461             :   already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
     462             :                                              nsViewManager* aViewManager,
     463             :                                              mozilla::StyleSetHandle aStyleSet)
     464             :     final;
     465             :   virtual void DeleteShell() override;
     466             : 
     467             :   virtual bool GetAllowPlugins() override;
     468             : 
     469             :   static bool IsElementAnimateEnabled(JSContext* aCx, JSObject* aObject);
     470             :   static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject);
     471             :   virtual mozilla::dom::DocumentTimeline* Timeline() override;
     472             :   virtual void GetAnimations(
     473             :       nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations) override;
     474          54 :   mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines() override
     475             :   {
     476          54 :     return mTimelines;
     477             :   }
     478             : 
     479             :   virtual nsresult SetSubDocumentFor(Element* aContent,
     480             :                                      nsIDocument* aSubDoc) override;
     481             :   virtual nsIDocument* GetSubDocumentFor(nsIContent* aContent) const override;
     482             :   virtual Element* FindContentForSubDocument(nsIDocument *aDocument) const override;
     483             :   virtual Element* GetRootElementInternal() const override;
     484             : 
     485             :   virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) override;
     486             : 
     487             :   /**
     488             :    * Get the (document) style sheets owned by this document.
     489             :    * These are ordered, highest priority last
     490             :    */
     491             :   virtual int32_t GetNumberOfStyleSheets() const override;
     492             :   virtual mozilla::StyleSheet* GetStyleSheetAt(int32_t aIndex) const override;
     493             :   virtual int32_t GetIndexOfStyleSheet(
     494             :       const mozilla::StyleSheet* aSheet) const override;
     495             :   virtual void AddStyleSheet(mozilla::StyleSheet* aSheet) override;
     496             :   virtual void RemoveStyleSheet(mozilla::StyleSheet* aSheet) override;
     497             : 
     498             :   virtual void UpdateStyleSheets(
     499             :       nsTArray<RefPtr<mozilla::StyleSheet>>& aOldSheets,
     500             :       nsTArray<RefPtr<mozilla::StyleSheet>>& aNewSheets) override;
     501             :   virtual void AddStyleSheetToStyleSets(mozilla::StyleSheet* aSheet);
     502             :   virtual void RemoveStyleSheetFromStyleSets(mozilla::StyleSheet* aSheet);
     503             : 
     504             :   virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
     505             :                                   int32_t aIndex) override;
     506             :   virtual void SetStyleSheetApplicableState(mozilla::StyleSheet* aSheet,
     507             :                                             bool aApplicable) override;
     508             : 
     509             :   virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType,
     510             :                                             nsIURI* aSheetURI) override;
     511             :   virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType,
     512             :                                            mozilla::StyleSheet* aSheet) override;
     513             :   virtual void RemoveAdditionalStyleSheet(additionalSheetType aType,
     514             :                                           nsIURI* sheetURI) override;
     515             :   virtual mozilla::StyleSheet* GetFirstAdditionalAuthorSheet() override;
     516             : 
     517         115 :   virtual nsIChannel* GetChannel() const override {
     518         115 :     return mChannel;
     519             :   }
     520             : 
     521           0 :   virtual nsIChannel* GetFailedChannel() const override {
     522           0 :     return mFailedChannel;
     523             :   }
     524           0 :   virtual void SetFailedChannel(nsIChannel* aChannel) override {
     525           0 :     mFailedChannel = aChannel;
     526           0 :   }
     527             : 
     528             :   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) override;
     529             : 
     530             :   virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) override;
     531             : 
     532             :   virtual nsIGlobalObject* GetScopeObject() const override;
     533             :   void SetScopeObject(nsIGlobalObject* aGlobal) override;
     534             :   /**
     535             :    * Get the script loader for this document
     536             :    */
     537             :   virtual mozilla::dom::ScriptLoader* ScriptLoader() override;
     538             : 
     539             :   /**
     540             :    * Add/Remove an element to the document's id and name hashes
     541             :    */
     542             :   virtual void AddToIdTable(Element* aElement, nsIAtom* aId) override;
     543             :   virtual void RemoveFromIdTable(Element* aElement, nsIAtom* aId) override;
     544             :   virtual void AddToNameTable(Element* aElement, nsIAtom* aName) override;
     545             :   virtual void RemoveFromNameTable(Element* aElement, nsIAtom* aName) override;
     546             : 
     547             :   /**
     548             :    * Add a new observer of document change notifications. Whenever
     549             :    * content is changed, appended, inserted or removed the observers are
     550             :    * informed.
     551             :    */
     552             :   virtual void AddObserver(nsIDocumentObserver* aObserver) override;
     553             : 
     554             :   /**
     555             :    * Remove an observer of document change notifications. This will
     556             :    * return false if the observer cannot be found.
     557             :    */
     558             :   virtual bool RemoveObserver(nsIDocumentObserver* aObserver) override;
     559             : 
     560             :   // Observation hooks used to propagate notifications to document
     561             :   // observers.
     562             :   virtual void BeginUpdate(nsUpdateType aUpdateType) override;
     563             :   virtual void EndUpdate(nsUpdateType aUpdateType) override;
     564             :   virtual void BeginLoad() override;
     565             :   virtual void EndLoad() override;
     566             : 
     567             :   virtual void SetReadyStateInternal(ReadyState rs) override;
     568             : 
     569             :   virtual void ContentStateChanged(nsIContent* aContent,
     570             :                                    mozilla::EventStates aStateMask)
     571             :                                      override;
     572             :   virtual void DocumentStatesChanged(
     573             :                  mozilla::EventStates aStateMask) override;
     574             : 
     575             :   virtual void StyleRuleChanged(mozilla::StyleSheet* aStyleSheet,
     576             :                                 mozilla::css::Rule* aStyleRule) override;
     577             :   virtual void StyleRuleAdded(mozilla::StyleSheet* aStyleSheet,
     578             :                               mozilla::css::Rule* aStyleRule) override;
     579             :   virtual void StyleRuleRemoved(mozilla::StyleSheet* aStyleSheet,
     580             :                                 mozilla::css::Rule* aStyleRule) override;
     581             : 
     582             :   virtual void FlushPendingNotifications(mozilla::FlushType aType) override;
     583             :   virtual void FlushExternalResources(mozilla::FlushType aType) override;
     584             :   virtual void SetXMLDeclaration(const char16_t *aVersion,
     585             :                                  const char16_t *aEncoding,
     586             :                                  const int32_t aStandalone) override;
     587             :   virtual void GetXMLDeclaration(nsAString& aVersion,
     588             :                                  nsAString& aEncoding,
     589             :                                  nsAString& Standalone) override;
     590             :   virtual bool IsScriptEnabled() override;
     591             : 
     592             :   virtual void OnPageShow(bool aPersisted, mozilla::dom::EventTarget* aDispatchStartTarget) override;
     593             :   virtual void OnPageHide(bool aPersisted, mozilla::dom::EventTarget* aDispatchStartTarget) override;
     594             : 
     595             :   virtual void WillDispatchMutationEvent(nsINode* aTarget) override;
     596             :   virtual void MutationEventDispatched(nsINode* aTarget) override;
     597             : 
     598             :   // nsINode
     599             :   virtual bool IsNodeOfType(uint32_t aFlags) const override;
     600             :   virtual nsIContent *GetChildAt(uint32_t aIndex) const override;
     601             :   virtual nsIContent * const * GetChildArray(uint32_t* aChildCount) const override;
     602             :   virtual int32_t IndexOf(const nsINode* aPossibleChild) const override;
     603             :   virtual uint32_t GetChildCount() const override;
     604             :   virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
     605             :                                  bool aNotify) override;
     606             :   virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
     607           0 :   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
     608             :                          bool aPreallocateChildren) const override
     609             :   {
     610           0 :     return NS_ERROR_NOT_IMPLEMENTED;
     611             :   }
     612             : 
     613             :   // nsIRadioGroupContainer
     614             :   NS_IMETHOD WalkRadioGroup(const nsAString& aName,
     615             :                             nsIRadioVisitor* aVisitor,
     616             :                             bool aFlushContent) override;
     617             :   virtual void
     618             :     SetCurrentRadioButton(const nsAString& aName,
     619             :                           mozilla::dom::HTMLInputElement* aRadio) override;
     620             :   virtual mozilla::dom::HTMLInputElement*
     621             :     GetCurrentRadioButton(const nsAString& aName) override;
     622             :   NS_IMETHOD
     623             :     GetNextRadioButton(const nsAString& aName,
     624             :                        const bool aPrevious,
     625             :                        mozilla::dom::HTMLInputElement*  aFocusedRadio,
     626             :                        mozilla::dom::HTMLInputElement** aRadioOut) override;
     627             :   virtual void AddToRadioGroup(const nsAString& aName,
     628             :                                nsIFormControl* aRadio) override;
     629             :   virtual void RemoveFromRadioGroup(const nsAString& aName,
     630             :                                     nsIFormControl* aRadio) override;
     631             :   virtual uint32_t GetRequiredRadioCount(const nsAString& aName) const override;
     632             :   virtual void RadioRequiredWillChange(const nsAString& aName,
     633             :                                        bool aRequiredAdded) override;
     634             :   virtual bool GetValueMissingState(const nsAString& aName) const override;
     635             :   virtual void SetValueMissingState(const nsAString& aName, bool aValue) override;
     636             : 
     637             :   // for radio group
     638             :   nsRadioGroupStruct* GetRadioGroup(const nsAString& aName) const;
     639             :   nsRadioGroupStruct* GetOrCreateRadioGroup(const nsAString& aName);
     640             : 
     641             :   virtual nsViewportInfo GetViewportInfo(const mozilla::ScreenIntSize& aDisplaySize) override;
     642             : 
     643             :   enum class UseCounterReportKind {
     644             :     // Flush the document's use counters only; the use counters for any
     645             :     // external resource documents will be flushed when the external
     646             :     // resource documents themselves are destroyed.
     647             :     eDefault,
     648             : 
     649             :     // Flush use counters for the document and for its external resource
     650             :     // documents. (Should only be necessary for tests, where we need
     651             :     // flushing to happen synchronously and deterministically.)
     652             :     eIncludeExternalResources,
     653             :   };
     654             : 
     655             :   void ReportUseCounters(UseCounterReportKind aKind = UseCounterReportKind::eDefault);
     656             : 
     657             :   virtual void AddIntersectionObserver(
     658             :     mozilla::dom::DOMIntersectionObserver* aObserver) override;
     659             :   virtual void RemoveIntersectionObserver(
     660             :     mozilla::dom::DOMIntersectionObserver* aObserver) override;
     661             :   virtual void UpdateIntersectionObservations() override;
     662             :   virtual void ScheduleIntersectionObserverNotification() override;
     663             :   virtual void NotifyIntersectionObservers() override;
     664             : 
     665             :   virtual void NotifyLayerManagerRecreated() override;
     666             : 
     667             :   virtual void ScheduleSVGForPresAttrEvaluation(nsSVGElement* aSVG) override;
     668             :   virtual void UnscheduleSVGForPresAttrEvaluation(nsSVGElement* aSVG) override;
     669             :   virtual void ResolveScheduledSVGPresAttrs() override;
     670             : 
     671             : private:
     672             :   void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
     673             :   void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
     674             : 
     675             : public:
     676             :   // nsIDOMNode
     677           0 :   NS_FORWARD_NSIDOMNODE_TO_NSINODE_OVERRIDABLE
     678             : 
     679             :   // nsIDOMDocument
     680             :   NS_DECL_NSIDOMDOCUMENT
     681             : 
     682             :   // nsIDOMDocumentXBL
     683             :   NS_DECL_NSIDOMDOCUMENTXBL
     684             : 
     685             :   // nsIDOMEventTarget
     686             :   virtual nsresult GetEventTargetParent(
     687             :                      mozilla::EventChainPreVisitor& aVisitor) override;
     688             :   virtual mozilla::EventListenerManager*
     689             :     GetOrCreateListenerManager() override;
     690             :   virtual mozilla::EventListenerManager*
     691             :     GetExistingListenerManager() const override;
     692             : 
     693             :   // nsIScriptObjectPrincipal
     694             :   virtual nsIPrincipal* GetPrincipal() override;
     695             : 
     696             :   // nsIApplicationCacheContainer
     697             :   NS_DECL_NSIAPPLICATIONCACHECONTAINER
     698             : 
     699             :   // nsIObserver
     700             :   NS_DECL_NSIOBSERVER
     701             : 
     702             :   NS_DECL_NSIDOMXPATHEVALUATOR
     703             : 
     704             :   virtual nsresult Init();
     705             : 
     706             :   virtual already_AddRefed<Element> CreateElem(const nsAString& aName,
     707             :                                                nsIAtom* aPrefix,
     708             :                                                int32_t aNamespaceID,
     709             :                                                const nsAString* aIs = nullptr) override;
     710             : 
     711             :   virtual void Sanitize() override;
     712             : 
     713             :   virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
     714             :                                                  void *aData) override;
     715             : 
     716             :   virtual bool CanSavePresentation(nsIRequest *aNewRequest) override;
     717             :   virtual void Destroy() override;
     718             :   virtual void RemovedFromDocShell() override;
     719             :   virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const override;
     720             : 
     721             :   virtual void BlockOnload() override;
     722             :   virtual void UnblockOnload(bool aFireSync) override;
     723             : 
     724             :   virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) override;
     725             :   virtual void ForgetLink(mozilla::dom::Link* aLink) override;
     726             : 
     727             :   virtual void ClearBoxObjectFor(nsIContent* aContent) override;
     728             : 
     729             :   virtual already_AddRefed<mozilla::dom::BoxObject>
     730             :   GetBoxObjectFor(mozilla::dom::Element* aElement,
     731             :                   mozilla::ErrorResult& aRv) override;
     732             : 
     733             :   virtual Element*
     734             :     GetAnonymousElementByAttribute(nsIContent* aElement,
     735             :                                    nsIAtom* aAttrName,
     736             :                                    const nsAString& aAttrValue) const override;
     737             : 
     738             :   virtual Element* ElementFromPointHelper(float aX, float aY,
     739             :                                           bool aIgnoreRootScrollFrame,
     740             :                                           bool aFlushLayout) override;
     741             : 
     742             :   virtual void ElementsFromPointHelper(float aX, float aY,
     743             :                                        uint32_t aFlags,
     744             :                                        nsTArray<RefPtr<mozilla::dom::Element>>& aElements) override;
     745             : 
     746             :   virtual nsresult NodesFromRectHelper(float aX, float aY,
     747             :                                                    float aTopSize, float aRightSize,
     748             :                                                    float aBottomSize, float aLeftSize,
     749             :                                                    bool aIgnoreRootScrollFrame,
     750             :                                                    bool aFlushLayout,
     751             :                                                    nsIDOMNodeList** aReturn) override;
     752             : 
     753             :   virtual void FlushSkinBindings() override;
     754             : 
     755             :   virtual nsresult InitializeFrameLoader(nsFrameLoader* aLoader) override;
     756             :   virtual nsresult FinalizeFrameLoader(nsFrameLoader* aLoader, nsIRunnable* aFinalizer) override;
     757             :   virtual void TryCancelFrameLoaderInitialization(nsIDocShell* aShell) override;
     758             :   virtual nsIDocument*
     759             :     RequestExternalResource(nsIURI* aURI,
     760             :                             nsINode* aRequestingNode,
     761             :                             ExternalResourceLoad** aPendingLoad) override;
     762             :   virtual void
     763             :     EnumerateExternalResources(nsSubDocEnumFunc aCallback, void* aData) override;
     764             : 
     765             :   // Returns our (lazily-initialized) animation controller.
     766             :   // If HasAnimationController is true, this is guaranteed to return non-null.
     767             :   nsSMILAnimationController* GetAnimationController() override;
     768             : 
     769             :   virtual mozilla::PendingAnimationTracker*
     770          92 :   GetPendingAnimationTracker() final override
     771             :   {
     772          92 :     return mPendingAnimationTracker;
     773             :   }
     774             : 
     775             :   virtual mozilla::PendingAnimationTracker*
     776             :   GetOrCreatePendingAnimationTracker() override;
     777             : 
     778             :   virtual void SuppressEventHandling(uint32_t aIncrease) override;
     779             : 
     780             :   virtual void UnsuppressEventHandlingAndFireEvents(bool aFireEvents) override;
     781             : 
     782           0 :   void DecreaseEventSuppression() {
     783           0 :     MOZ_ASSERT(mEventsSuppressed);
     784           0 :     --mEventsSuppressed;
     785           0 :     UpdateFrameRequestCallbackSchedulingState();
     786           0 :   }
     787             : 
     788             :   virtual nsIDocument* GetTemplateContentsOwner() override;
     789             : 
     790       35753 :   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument,
     791             :                                                                    nsIDocument)
     792             : 
     793             :   void DoNotifyPossibleTitleChange();
     794             : 
     795           0 :   nsExternalResourceMap& ExternalResourceMap()
     796             :   {
     797           0 :     return mExternalResourceMap;
     798             :   }
     799             : 
     800          58 :   void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; }
     801          25 :   void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData)
     802             :   {
     803          25 :     mLoadedAsInteractiveData = aLoadedAsInteractiveData;
     804          25 :   }
     805             : 
     806             :   nsresult CloneDocHelper(nsDocument* clone, bool aPreallocateChildren) const;
     807             : 
     808             :   void MaybeInitializeFinalizeFrameLoaders();
     809             : 
     810             :   void MaybeEndOutermostXBLUpdate();
     811             : 
     812             :   virtual void PreloadPictureOpened() override;
     813             :   virtual void PreloadPictureClosed() override;
     814             : 
     815             :   virtual void
     816             :     PreloadPictureImageSource(const nsAString& aSrcsetAttr,
     817             :                               const nsAString& aSizesAttr,
     818             :                               const nsAString& aTypeAttr,
     819             :                               const nsAString& aMediaAttr) override;
     820             : 
     821             :   virtual already_AddRefed<nsIURI>
     822             :     ResolvePreloadImage(nsIURI *aBaseURI,
     823             :                         const nsAString& aSrcAttr,
     824             :                         const nsAString& aSrcsetAttr,
     825             :                         const nsAString& aSizesAttr) override;
     826             : 
     827             :   virtual void MaybePreLoadImage(nsIURI* uri,
     828             :                                  const nsAString &aCrossOriginAttr,
     829             :                                  ReferrerPolicy aReferrerPolicy) override;
     830             :   virtual void ForgetImagePreload(nsIURI* aURI) override;
     831             : 
     832             :   virtual void MaybePreconnect(nsIURI* uri,
     833             :                                mozilla::CORSMode aCORSMode) override;
     834             : 
     835             :   virtual void PreloadStyle(nsIURI* uri, const nsAString& charset,
     836             :                             const nsAString& aCrossOriginAttr,
     837             :                             ReferrerPolicy aReferrerPolicy,
     838             :                             const nsAString& aIntegrity) override;
     839             : 
     840             :   virtual nsresult LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet,
     841             :                                        RefPtr<mozilla::StyleSheet>* aSheet) override;
     842             : 
     843             :   virtual nsISupports* GetCurrentContentSink() override;
     844             : 
     845             :   virtual mozilla::EventStates GetDocumentState() final;
     846             :   // GetDocumentState() mutates the state due to lazy resolution;
     847             :   // and can't be used during parallel traversal. Use this instead,
     848             :   // and ensure GetDocumentState() has been called first.
     849             :   // This will assert if the state is stale.
     850             :   virtual mozilla::EventStates ThreadSafeGetDocumentState() const final;
     851             : 
     852             :   // Only BlockOnload should call this!
     853             :   void AsyncBlockOnload();
     854             : 
     855             :   virtual void SetScrollToRef(nsIURI *aDocumentURI) override;
     856             :   virtual void ScrollToRef() override;
     857             :   virtual void ResetScrolledToRefAlready() override;
     858             :   virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) override;
     859             : 
     860             :   virtual Element *GetElementById(const nsAString& aElementId) override;
     861             :   virtual const nsTArray<Element*>* GetAllElementsForId(const nsAString& aElementId) const override;
     862             : 
     863             :   virtual Element *LookupImageElement(const nsAString& aElementId) override;
     864             :   virtual void MozSetImageElement(const nsAString& aImageElementId,
     865             :                                   Element* aElement) override;
     866             : 
     867             :   // AddPlugin adds a plugin-related element to mPlugins when the element is
     868             :   // added to the tree.
     869             :   virtual nsresult AddPlugin(nsIObjectLoadingContent* aPlugin) override;
     870             :   // RemovePlugin removes a plugin-related element to mPlugins when the
     871             :   // element is removed from the tree.
     872             :   virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) override;
     873             :   // GetPlugins returns the plugin-related elements from
     874             :   // the frame and any subframes.
     875             :   virtual void GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins) override;
     876             : 
     877             :   // Adds an element to mResponsiveContent when the element is
     878             :   // added to the tree.
     879             :   virtual nsresult AddResponsiveContent(nsIContent* aContent) override;
     880             :   // Removes an element from mResponsiveContent when the element is
     881             :   // removed from the tree.
     882             :   virtual void RemoveResponsiveContent(nsIContent* aContent) override;
     883             :   // Notifies any responsive content added by AddResponsiveContent upon media
     884             :   // features values changing.
     885             :   virtual void NotifyMediaFeatureValuesChanged() override;
     886             : 
     887             :   virtual nsresult GetStateObject(nsIVariant** aResult) override;
     888             : 
     889             :   virtual nsDOMNavigationTiming* GetNavigationTiming() const override;
     890             :   virtual nsresult SetNavigationTiming(nsDOMNavigationTiming* aTiming) override;
     891             : 
     892             :   virtual Element* FindImageMap(const nsAString& aNormalizedMapName) override;
     893             : 
     894             :   virtual nsTArray<Element*> GetFullscreenStack() const override;
     895             :   virtual void AsyncRequestFullScreen(
     896             :     mozilla::UniquePtr<FullscreenRequest>&& aRequest) override;
     897             :   virtual void RestorePreviousFullScreenState() override;
     898             :   virtual bool IsFullscreenLeaf() override;
     899             :   virtual nsresult
     900             :     RemoteFrameFullscreenChanged(nsIDOMElement* aFrameElement) override;
     901             : 
     902             :   virtual nsresult RemoteFrameFullscreenReverted() override;
     903             :   virtual nsIDocument* GetFullscreenRoot() override;
     904             :   virtual void SetFullscreenRoot(nsIDocument* aRoot) override;
     905             : 
     906             :   // Returns the size of the mBlockedTrackingNodes array. (nsIDocument.h)
     907             :   //
     908             :   // This array contains nodes that have been blocked to prevent
     909             :   // user tracking. They most likely have had their nsIChannel
     910             :   // canceled by the URL classifier (Safebrowsing).
     911             :   //
     912             :   // A script can subsequently use GetBlockedTrackingNodes()
     913             :   // to get a list of references to these nodes.
     914             :   //
     915             :   // Note:
     916             :   // This expresses how many tracking nodes have been blocked for this
     917             :   // document since its beginning, not how many of them are still around
     918             :   // in the DOM tree. Weak references to blocked nodes are added in the
     919             :   // mBlockedTrackingNodesArray but they are not removed when those nodes
     920             :   // are removed from the tree or even garbage collected.
     921             :   long BlockedTrackingNodeCount() const;
     922             : 
     923             :   //
     924             :   // Returns strong references to mBlockedTrackingNodes. (nsIDocument.h)
     925             :   //
     926             :   // This array contains nodes that have been blocked to prevent
     927             :   // user tracking. They most likely have had their nsIChannel
     928             :   // canceled by the URL classifier (Safebrowsing).
     929             :   //
     930             :   already_AddRefed<nsSimpleContentList> BlockedTrackingNodes() const;
     931             : 
     932             :   static bool IsUnprefixedFullscreenEnabled(JSContext* aCx, JSObject* aObject);
     933             : 
     934             :   // Do the "fullscreen element ready check" from the fullscreen spec.
     935             :   // It returns true if the given element is allowed to go into fullscreen.
     936             :   bool FullscreenElementReadyCheck(Element* aElement, bool aWasCallerChrome);
     937             : 
     938             :   // This is called asynchronously by nsIDocument::AsyncRequestFullScreen()
     939             :   // to move this document into full-screen mode if allowed.
     940             :   void RequestFullScreen(mozilla::UniquePtr<FullscreenRequest>&& aRequest);
     941             : 
     942             :   // Removes all elements from the full-screen stack, removing full-scren
     943             :   // styles from the top element in the stack.
     944             :   void CleanupFullscreenState();
     945             : 
     946             :   // Pushes aElement onto the full-screen stack, and removes full-screen styles
     947             :   // from the former full-screen stack top, and its ancestors, and applies the
     948             :   // styles to aElement. aElement becomes the new "full-screen element".
     949             :   bool FullScreenStackPush(Element* aElement);
     950             : 
     951             :   // Remove the top element from the full-screen stack. Removes the full-screen
     952             :   // styles from the former top element, and applies them to the new top
     953             :   // element, if there is one.
     954             :   void FullScreenStackPop();
     955             : 
     956             :   // Returns the top element from the full-screen stack.
     957             :   Element* FullScreenStackTop();
     958             : 
     959             :   // DOM-exposed fullscreen API
     960             :   bool FullscreenEnabled(mozilla::dom::CallerType aCallerType) override;
     961             :   Element* GetFullscreenElement() override;
     962             : 
     963             :   void RequestPointerLock(Element* aElement,
     964             :                           mozilla::dom::CallerType aCallerType) override;
     965             :   bool SetPointerLock(Element* aElement, int aCursorStyle);
     966             :   static void UnlockPointer(nsIDocument* aDoc = nullptr);
     967             : 
     968             :   void SetCurrentOrientation(mozilla::dom::OrientationType aType,
     969             :                              uint16_t aAngle) override;
     970             :   uint16_t CurrentOrientationAngle() const override;
     971             :   mozilla::dom::OrientationType CurrentOrientationType() const override;
     972             :   void SetOrientationPendingPromise(mozilla::dom::Promise* aPromise) override;
     973             :   mozilla::dom::Promise* GetOrientationPendingPromise() const override;
     974             : 
     975             :   // This method may fire a DOM event; if it does so it will happen
     976             :   // synchronously.
     977             :   void UpdateVisibilityState();
     978             :   // Posts an event to call UpdateVisibilityState
     979             :   virtual void PostVisibilityUpdateEvent() override;
     980             : 
     981             :   // Since we wouldn't automatically play media from non-visited page, we need
     982             :   // to notify window when the page was first visited.
     983             :   void MaybeActiveMediaComponents();
     984             : 
     985             :   virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const override;
     986             :   // DocAddSizeOfIncludingThis is inherited from nsIDocument.
     987             : 
     988          44 :   virtual nsIDOMNode* AsDOMNode() override { return this; }
     989             : 
     990             :   // WebIDL bits
     991             :   virtual mozilla::dom::DOMImplementation*
     992             :     GetImplementation(mozilla::ErrorResult& rv) override;
     993             :   virtual void
     994             :     RegisterElement(JSContext* aCx, const nsAString& aName,
     995             :                     const mozilla::dom::ElementRegistrationOptions& aOptions,
     996             :                     JS::MutableHandle<JSObject*> aRetval,
     997             :                     mozilla::ErrorResult& rv) override;
     998             :   virtual mozilla::dom::StyleSheetList* StyleSheets() override;
     999             :   virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) override;
    1000             :   virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
    1001             :   virtual mozilla::dom::DOMStringList* StyleSheetSets() override;
    1002             :   virtual void EnableStyleSheetsForSet(const nsAString& aSheetSet) override;
    1003             :   virtual already_AddRefed<Element> CreateElement(const nsAString& aTagName,
    1004             :                                                   const mozilla::dom::ElementCreationOptionsOrString& aOptions,
    1005             :                                                   ErrorResult& rv) override;
    1006             :   virtual already_AddRefed<Element> CreateElementNS(const nsAString& aNamespaceURI,
    1007             :                                                     const nsAString& aQualifiedName,
    1008             :                                                     const mozilla::dom::ElementCreationOptionsOrString& aOptions,
    1009             :                                                     mozilla::ErrorResult& rv) override;
    1010             : 
    1011             :   virtual void UnblockDOMContentLoaded() override;
    1012             : 
    1013             : protected:
    1014             :   friend class nsNodeUtils;
    1015             :   friend class nsDocumentOnStack;
    1016             : 
    1017         594 :   void IncreaseStackRefCnt()
    1018             :   {
    1019         594 :     ++mStackRefCnt;
    1020         594 :   }
    1021             : 
    1022         594 :   void DecreaseStackRefCnt()
    1023             :   {
    1024         594 :     if (--mStackRefCnt == 0 && mNeedsReleaseAfterStackRefCntRelease) {
    1025           0 :       mNeedsReleaseAfterStackRefCntRelease = false;
    1026           0 :       NS_RELEASE_THIS();
    1027             :     }
    1028         594 :   }
    1029             : 
    1030             :   /**
    1031             :    * Check that aId is not empty and log a message to the console
    1032             :    * service if it is.
    1033             :    * @returns true if aId looks correct, false otherwise.
    1034             :    */
    1035         544 :   inline bool CheckGetElementByIdArg(const nsAString& aId)
    1036             :   {
    1037         544 :     if (aId.IsEmpty()) {
    1038           0 :       ReportEmptyGetElementByIdArg();
    1039           0 :       return false;
    1040             :     }
    1041         544 :     return true;
    1042             :   }
    1043             : 
    1044             :   void ReportEmptyGetElementByIdArg();
    1045             : 
    1046             :   void DispatchContentLoadedEvents();
    1047             : 
    1048             :   void RetrieveRelevantHeaders(nsIChannel *aChannel);
    1049             : 
    1050             :   void TryChannelCharset(nsIChannel *aChannel,
    1051             :                          int32_t& aCharsetSource,
    1052             :                          NotNull<const Encoding*>& aEncoding,
    1053             :                          nsHtml5TreeOpExecutor* aExecutor);
    1054             : 
    1055             :   // Call this before the document does something that will unbind all content.
    1056             :   // That will stop us from doing a lot of work as each element is removed.
    1057             :   void DestroyElementMaps();
    1058             : 
    1059             :   // Refreshes the hrefs of all the links in the document.
    1060             :   void RefreshLinkHrefs();
    1061             : 
    1062             :   nsIContent* GetFirstBaseNodeWithHref();
    1063             :   nsresult SetFirstBaseNodeWithHref(nsIContent *node);
    1064             : 
    1065             :   /**
    1066             :    * Returns the title element of the document as defined by the HTML
    1067             :    * specification, or null if there isn't one.  For documents whose root
    1068             :    * element is an <svg:svg>, this is the first <svg:title> element that's a
    1069             :    * child of the root.  For other documents, it's the first HTML title element
    1070             :    * in the document.
    1071             :    */
    1072             :   Element* GetTitleElement();
    1073             : 
    1074             : public:
    1075             :   // Get our title
    1076             :   virtual void GetTitle(nsString& aTitle) override;
    1077             :   // Set our title
    1078             :   virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) override;
    1079             : 
    1080             :   js::ExpandoAndGeneration mExpandoAndGeneration;
    1081             : 
    1082             :   bool ContainsEMEContent();
    1083             : 
    1084             :   bool ContainsMSEContent();
    1085             : 
    1086             : protected:
    1087             :   void RemoveDocStyleSheetsFromStyleSets();
    1088             :   void RemoveStyleSheetsFromStyleSets(
    1089             :       const nsTArray<RefPtr<mozilla::StyleSheet>>& aSheets,
    1090             :       mozilla::SheetType aType);
    1091             :   void ResetStylesheetsToURI(nsIURI* aURI);
    1092             :   void FillStyleSet(mozilla::StyleSetHandle aStyleSet);
    1093             : 
    1094             :   // Return whether all the presshells for this document are safe to flush
    1095             :   bool IsSafeToFlush() const;
    1096             : 
    1097             :   void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget,
    1098             :                               const nsAString& aType,
    1099             :                               bool aPersisted);
    1100             : 
    1101             :   virtual nsPIDOMWindowOuter* GetWindowInternal() const override;
    1102             :   virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const override;
    1103             :   virtual bool InternalAllowXULXBL() override;
    1104             : 
    1105             :   void UpdateScreenOrientation();
    1106             : 
    1107             :   virtual mozilla::dom::FlashClassification DocumentFlashClassification() override;
    1108             :   virtual bool IsThirdParty() override;
    1109             : 
    1110             : #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_)                        \
    1111             :   NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \
    1112             :                                            func_, params_);
    1113             : 
    1114             : #ifdef DEBUG
    1115             :   void VerifyRootContentState();
    1116             : #endif
    1117             : 
    1118             :   explicit nsDocument(const char* aContentType);
    1119             :   virtual ~nsDocument();
    1120             : 
    1121             :   void EnsureOnloadBlocker();
    1122             : 
    1123             :   void NotifyStyleSheetApplicableStateChanged();
    1124             : 
    1125             :   // Apply the fullscreen state to the document, and trigger related
    1126             :   // events. It returns false if the fullscreen element ready check
    1127             :   // fails and nothing gets changed.
    1128             :   bool ApplyFullscreen(const FullscreenRequest& aRequest);
    1129             : 
    1130             :   // Retrieves the classification of the Flash plugins in the document based on
    1131             :   // the classification lists.
    1132             :   mozilla::dom::FlashClassification PrincipalFlashClassification();
    1133             : 
    1134             :   // Attempts to determine the Flash classification of this page based on the
    1135             :   // the classification lists and the classification of parent documents.
    1136             :   mozilla::dom::FlashClassification ComputeFlashClassification();
    1137             : 
    1138             :   nsTArray<nsIObserver*> mCharSetObservers;
    1139             : 
    1140             :   PLDHashTable *mSubDocuments;
    1141             : 
    1142             :   // Array of owning references to all children
    1143             :   nsAttrAndChildArray mChildren;
    1144             : 
    1145             :   // Pointer to our parser if we're currently in the process of being
    1146             :   // parsed into.
    1147             :   nsCOMPtr<nsIParser> mParser;
    1148             : 
    1149             :   // Weak reference to our sink for in case we no longer have a parser.  This
    1150             :   // will allow us to flush out any pending stuff from the sink even if
    1151             :   // EndLoad() has already happened.
    1152             :   nsWeakPtr mWeakSink;
    1153             : 
    1154             :   nsTArray<RefPtr<mozilla::StyleSheet>> mStyleSheets;
    1155             :   nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
    1156             :   nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
    1157             : 
    1158             :   // Array of observers
    1159             :   nsTObserverArray<nsIDocumentObserver*> mObservers;
    1160             : 
    1161             :   // Array of intersection observers
    1162             :   nsTHashtable<nsPtrHashKey<mozilla::dom::DOMIntersectionObserver>>
    1163             :     mIntersectionObservers;
    1164             : 
    1165             :   // Tracker for animations that are waiting to start.
    1166             :   // nullptr until GetOrCreatePendingAnimationTracker is called.
    1167             :   RefPtr<mozilla::PendingAnimationTracker> mPendingAnimationTracker;
    1168             : 
    1169             :   // Weak reference to the scope object (aka the script global object)
    1170             :   // that, unlike mScriptGlobalObject, is never unset once set. This
    1171             :   // is a weak reference to avoid leaks due to circular references.
    1172             :   nsWeakPtr mScopeObject;
    1173             : 
    1174             :   // Stack of full-screen elements. When we request full-screen we push the
    1175             :   // full-screen element onto this stack, and when we cancel full-screen we
    1176             :   // pop one off this stack, restoring the previous full-screen state
    1177             :   nsTArray<nsWeakPtr> mFullScreenStack;
    1178             : 
    1179             :   // The root of the doc tree in which this document is in. This is only
    1180             :   // non-null when this document is in fullscreen mode.
    1181             :   nsWeakPtr mFullscreenRoot;
    1182             : 
    1183             :   mozilla::dom::FlashClassification mFlashClassification;
    1184             :   // Do not use this value directly. Call the |IsThirdParty()| method, which
    1185             :   // caches its result here.
    1186             :   mozilla::Maybe<bool> mIsThirdParty;
    1187             : private:
    1188             :   void UpdatePossiblyStaleDocumentState();
    1189             :   static bool CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp);
    1190             : 
    1191             : public:
    1192             :   virtual already_AddRefed<mozilla::dom::CustomElementRegistry>
    1193             :     GetCustomElementRegistry() override;
    1194             : 
    1195             :   // Check whether web components are enabled for the global of aObject.
    1196             :   static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
    1197             :   // Check whether web components are enabled for the global of the document
    1198             :   // this nodeinfo comes from.
    1199             :   static bool IsWebComponentsEnabled(mozilla::dom::NodeInfo* aNodeInfo);
    1200             : 
    1201             :   RefPtr<mozilla::EventListenerManager> mListenerManager;
    1202             :   RefPtr<mozilla::dom::StyleSheetList> mDOMStyleSheets;
    1203             :   RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
    1204             :   RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
    1205             :   nsDocHeaderData* mHeaderData;
    1206             :   /* mIdentifierMap works as follows for IDs:
    1207             :    * 1) Attribute changes affect the table immediately (removing and adding
    1208             :    *    entries as needed).
    1209             :    * 2) Removals from the DOM affect the table immediately
    1210             :    * 3) Additions to the DOM always update existing entries for names, and add
    1211             :    *    new ones for IDs.
    1212             :    */
    1213             :   nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;
    1214             : 
    1215             :   nsClassHashtable<nsStringHashKey, nsRadioGroupStruct> mRadioGroups;
    1216             : 
    1217             :   // Recorded time of change to 'loading' state.
    1218             :   mozilla::TimeStamp mLoadingTimeStamp;
    1219             : 
    1220             :   // True if the document has been detached from its content viewer.
    1221             :   bool mIsGoingAway:1;
    1222             :   // True if the document is being destroyed.
    1223             :   bool mInDestructor:1;
    1224             : 
    1225             :   // True if this document has ever had an HTML or SVG <title> element
    1226             :   // bound to it
    1227             :   bool mMayHaveTitleElement:1;
    1228             : 
    1229             :   bool mHasWarnedAboutBoxObjects:1;
    1230             : 
    1231             :   bool mDelayFrameLoaderInitialization:1;
    1232             : 
    1233             :   bool mSynchronousDOMContentLoaded:1;
    1234             : 
    1235             :   bool mInXBLUpdate:1;
    1236             : 
    1237             :   // Parser aborted. True if the parser of this document was forcibly
    1238             :   // terminated instead of letting it finish at its own pace.
    1239             :   bool mParserAborted:1;
    1240             : 
    1241             :   friend class nsCallRequestFullScreen;
    1242             : 
    1243             :   // ScreenOrientation "pending promise" as described by
    1244             :   // http://www.w3.org/TR/screen-orientation/
    1245             :   RefPtr<mozilla::dom::Promise> mOrientationPendingPromise;
    1246             : 
    1247             :   uint16_t mCurrentOrientationAngle;
    1248             :   mozilla::dom::OrientationType mCurrentOrientationType;
    1249             : 
    1250             :   // Keeps track of whether we have a pending
    1251             :   // 'style-sheet-applicable-state-changed' notification.
    1252             :   bool mSSApplicableStateNotificationPending:1;
    1253             : 
    1254             :   // Whether we have reported use counters for this document with Telemetry yet.
    1255             :   // Normally this is only done at document destruction time, but for image
    1256             :   // documents (SVG documents) that are not guaranteed to be destroyed, we
    1257             :   // report use counters when the image cache no longer has any imgRequestProxys
    1258             :   // pointing to them.  We track whether we ever reported use counters so
    1259             :   // that we only report them once for the document.
    1260             :   bool mReportedUseCounters:1;
    1261             : 
    1262             :   // Whether we have filled our pres shell's style set with the document's
    1263             :   // additional sheets and sheets from the nsStyleSheetService.
    1264             :   bool mStyleSetFilled:1;
    1265             : 
    1266             :   uint8_t mPendingFullscreenRequests;
    1267             : 
    1268             :   uint8_t mXMLDeclarationBits;
    1269             : 
    1270             :   nsRefPtrHashtable<nsPtrHashKey<nsIContent>, mozilla::dom::BoxObject>* mBoxObjectTable;
    1271             : 
    1272             :   // A document "without a browsing context" that owns the content of
    1273             :   // HTMLTemplateElement.
    1274             :   nsCOMPtr<nsIDocument> mTemplateContentsOwner;
    1275             : 
    1276             :   // Our update nesting level
    1277             :   uint32_t mUpdateNestLevel;
    1278             : 
    1279             :   // The application cache that this document is associated with, if
    1280             :   // any.  This can change during the lifetime of the document.
    1281             :   nsCOMPtr<nsIApplicationCache> mApplicationCache;
    1282             : 
    1283             :   nsCOMPtr<nsIContent> mFirstBaseNodeWithHref;
    1284             : 
    1285             :   mozilla::EventStates mDocumentState;
    1286             :   mozilla::EventStates mGotDocumentState;
    1287             : 
    1288             :   RefPtr<nsDOMNavigationTiming> mTiming;
    1289             : private:
    1290             :   friend class nsUnblockOnloadEvent;
    1291             :   // Recomputes the visibility state but doesn't set the new value.
    1292             :   mozilla::dom::VisibilityState GetVisibilityState() const;
    1293             :   void NotifyStyleSheetAdded(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
    1294             :   void NotifyStyleSheetRemoved(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
    1295             : 
    1296             :   void PostUnblockOnloadEvent();
    1297             :   void DoUnblockOnload();
    1298             : 
    1299             :   nsresult InitCSP(nsIChannel* aChannel);
    1300             : 
    1301             :   /**
    1302             :    * Find the (non-anonymous) content in this document for aFrame. It will
    1303             :    * be aFrame's content node if that content is in this document and not
    1304             :    * anonymous. Otherwise, when aFrame is in a subdocument, we use the frame
    1305             :    * element containing the subdocument containing aFrame, and/or find the
    1306             :    * nearest non-anonymous ancestor in this document.
    1307             :    * Returns null if there is no such element.
    1308             :    */
    1309             :   nsIContent* GetContentInThisDocument(nsIFrame* aFrame) const;
    1310             : 
    1311             :   // Just like EnableStyleSheetsForSet, but doesn't check whether
    1312             :   // aSheetSet is null and allows the caller to control whether to set
    1313             :   // aSheetSet as the preferred set in the CSSLoader.
    1314             :   void EnableStyleSheetsForSetInternal(const nsAString& aSheetSet,
    1315             :                                        bool aUpdateCSSLoader);
    1316             : 
    1317             :   void ClearAllBoxObjects();
    1318             : 
    1319             :   // Returns true if the scheme for the url for this document is "about"
    1320             :   bool IsAboutPage() const;
    1321             : 
    1322             :   // These are not implemented and not supported.
    1323             :   nsDocument(const nsDocument& aOther);
    1324             :   nsDocument& operator=(const nsDocument& aOther);
    1325             : 
    1326             :   // The layout history state that should be used by nodes in this
    1327             :   // document.  We only actually store a pointer to it when:
    1328             :   // 1)  We have no script global object.
    1329             :   // 2)  We haven't had Destroy() called on us yet.
    1330             :   nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
    1331             : 
    1332             :   // Currently active onload blockers
    1333             :   uint32_t mOnloadBlockCount;
    1334             :   // Onload blockers which haven't been activated yet
    1335             :   uint32_t mAsyncOnloadBlockCount;
    1336             :   nsCOMPtr<nsIRequest> mOnloadBlocker;
    1337             : 
    1338             :   // A hashtable of styled links keyed by address pointer.
    1339             :   nsTHashtable<nsPtrHashKey<mozilla::dom::Link> > mStyledLinks;
    1340             : #ifdef DEBUG
    1341             :   // Indicates whether mStyledLinks was cleared or not.  This is used to track
    1342             :   // state so we can provide useful assertions to consumers of ForgetLink and
    1343             :   // AddStyleRelevantLink.
    1344             :   bool mStyledLinksCleared;
    1345             : #endif
    1346             : 
    1347             :   // A set of responsive images keyed by address pointer.
    1348             :   nsTHashtable< nsPtrHashKey<nsIContent> > mResponsiveContent;
    1349             : 
    1350             :   // Member to store out last-selected stylesheet set.
    1351             :   nsString mLastStyleSheetSet;
    1352             : 
    1353             :   nsTArray<RefPtr<nsFrameLoader> > mInitializableFrameLoaders;
    1354             :   nsTArray<nsCOMPtr<nsIRunnable> > mFrameLoaderFinalizers;
    1355             :   RefPtr<nsRunnableMethod<nsDocument> > mFrameLoaderRunner;
    1356             : 
    1357             :   nsCOMPtr<nsIRunnable> mMaybeEndOutermostXBLUpdateRunner;
    1358             : 
    1359             :   nsRevocableEventPtr<nsRunnableMethod<nsDocument, void, false> >
    1360             :     mPendingTitleChangeEvent;
    1361             : 
    1362             :   nsExternalResourceMap mExternalResourceMap;
    1363             : 
    1364             :   // All images in process of being preloaded.  This is a hashtable so
    1365             :   // we can remove them as the real image loads start; that way we
    1366             :   // make sure to not keep the image load going when no one cares
    1367             :   // about it anymore.
    1368             :   nsRefPtrHashtable<nsURIHashKey, imgIRequest> mPreloadingImages;
    1369             : 
    1370             :   // A list of preconnects initiated by the preloader. This prevents
    1371             :   // the same uri from being used more than once, and allows the dom
    1372             :   // builder to not repeat the work of the preloader.
    1373             :   nsDataHashtable< nsURIHashKey, bool> mPreloadedPreconnects;
    1374             : 
    1375             :   // Current depth of picture elements from parser
    1376             :   int32_t mPreloadPictureDepth;
    1377             : 
    1378             :   // Set if we've found a URL for the current picture
    1379             :   nsString mPreloadPictureFoundSource;
    1380             : 
    1381             :   RefPtr<mozilla::dom::DOMImplementation> mDOMImplementation;
    1382             : 
    1383             :   RefPtr<nsContentList> mImageMaps;
    1384             : 
    1385             :   nsCString mScrollToRef;
    1386             :   uint8_t mScrolledToRefAlready : 1;
    1387             :   uint8_t mChangeScrollPosWhenScrollingToRef : 1;
    1388             : 
    1389             :   // Tracking for plugins in the document.
    1390             :   nsTHashtable< nsPtrHashKey<nsIObjectLoadingContent> > mPlugins;
    1391             : 
    1392             :   RefPtr<mozilla::dom::DocumentTimeline> mDocumentTimeline;
    1393             :   mozilla::LinkedList<mozilla::dom::DocumentTimeline> mTimelines;
    1394             : 
    1395             :   enum ViewportType {
    1396             :     DisplayWidthHeight,
    1397             :     Specified,
    1398             :     Unknown
    1399             :   };
    1400             : 
    1401             :   ViewportType mViewportType;
    1402             : 
    1403             :   // These member variables cache information about the viewport so we don't have to
    1404             :   // recalculate it each time.
    1405             :   bool mValidWidth, mValidHeight;
    1406             :   mozilla::LayoutDeviceToScreenScale mScaleMinFloat;
    1407             :   mozilla::LayoutDeviceToScreenScale mScaleMaxFloat;
    1408             :   mozilla::LayoutDeviceToScreenScale mScaleFloat;
    1409             :   mozilla::CSSToLayoutDeviceScale mPixelRatio;
    1410             :   bool mAutoSize, mAllowZoom, mAllowDoubleTapZoom, mValidScaleFloat, mValidMaxScale, mScaleStrEmpty, mWidthStrEmpty;
    1411             :   mozilla::CSSSize mViewportSize;
    1412             : 
    1413             :   nsrefcnt mStackRefCnt;
    1414             :   bool mNeedsReleaseAfterStackRefCntRelease;
    1415             : 
    1416             :   // Set to true when the document is possibly controlled by the ServiceWorker.
    1417             :   // Used to prevent multiple requests to ServiceWorkerManager.
    1418             :   bool mMaybeServiceWorkerControlled;
    1419             : 
    1420             :   // We lazily calculate declaration blocks for SVG elements
    1421             :   // with mapped attributes in Servo mode. This list contains all elements which
    1422             :   // need lazy resolution
    1423             :   nsTHashtable<nsPtrHashKey<nsSVGElement>> mLazySVGPresElements;
    1424             : 
    1425             : #ifdef DEBUG
    1426             : public:
    1427             :   bool mWillReparent;
    1428             : #endif
    1429             : };
    1430             : 
    1431             : class nsDocumentOnStack
    1432             : {
    1433             : public:
    1434         594 :   explicit nsDocumentOnStack(nsDocument* aDoc) : mDoc(aDoc)
    1435             :   {
    1436         594 :     mDoc->IncreaseStackRefCnt();
    1437         594 :   }
    1438         594 :   ~nsDocumentOnStack()
    1439         594 :   {
    1440         594 :     mDoc->DecreaseStackRefCnt();
    1441         594 :   }
    1442             : private:
    1443             :   nsDocument* mDoc;
    1444             : };
    1445             : 
    1446             : #endif /* nsDocument_h___ */

Generated by: LCOV version 1.13