content/base/public/nsIDocument.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsIDocument_h___
     6 #define nsIDocument_h___
     8 #include "mozFlushType.h"                // for enum
     9 #include "nsAutoPtr.h"                   // for member
    10 #include "nsCOMArray.h"                  // for member
    11 #include "nsCRT.h"                       // for NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
    12 #include "nsCompatibility.h"             // for member
    13 #include "nsCOMPtr.h"                    // for member
    14 #include "nsGkAtoms.h"                   // for static class members
    15 #include "nsIDocumentObserver.h"         // for typedef (nsUpdateType)
    16 #include "nsILoadGroup.h"                // for member (in nsCOMPtr)
    17 #include "nsINode.h"                     // for base class
    18 #include "nsIScriptGlobalObject.h"       // for member (in nsCOMPtr)
    19 #include "nsPIDOMWindow.h"               // for use in inline functions
    20 #include "nsPropertyTable.h"             // for member
    21 #include "nsTHashtable.h"                // for member
    22 #include "nsWeakReference.h"
    23 #include "mozilla/dom/DocumentBinding.h"
    24 #include "mozilla/WeakPtr.h"
    25 #include "Units.h"
    26 #include "nsExpirationTracker.h"
    27 #include "nsClassHashtable.h"
    29 class imgIRequest;
    30 class nsAString;
    31 class nsBindingManager;
    32 class nsCSSStyleSheet;
    33 class nsIDocShell;
    34 class nsDocShell;
    35 class nsDOMNavigationTiming;
    36 class nsFrameLoader;
    37 class nsHTMLCSSStyleSheet;
    38 class nsHTMLDocument;
    39 class nsHTMLStyleSheet;
    40 class nsIAtom;
    41 class nsIBFCacheEntry;
    42 class nsIBoxObject;
    43 class nsIChannel;
    44 class nsIContent;
    45 class nsIContentSink;
    46 class nsIDocShell;
    47 class nsIDocumentEncoder;
    48 class nsIDocumentObserver;
    49 class nsIDOMDocument;
    50 class nsIDOMDocumentFragment;
    51 class nsIDOMDocumentType;
    52 class nsIDOMElement;
    53 class nsIDOMNodeFilter;
    54 class nsIDOMNodeList;
    55 class nsIDOMXPathExpression;
    56 class nsIDOMXPathNSResolver;
    57 class nsIHTMLCollection;
    58 class nsILayoutHistoryState;
    59 class nsILoadContext;
    60 class nsIObjectLoadingContent;
    61 class nsIObserver;
    62 class nsIPresShell;
    63 class nsIPrincipal;
    64 class nsIRequest;
    65 class nsIStreamListener;
    66 class nsIStructuredCloneContainer;
    67 class nsIStyleRule;
    68 class nsIStyleSheet;
    69 class nsIURI;
    70 class nsIVariant;
    71 class nsViewManager;
    72 class nsPresContext;
    73 class nsRange;
    74 class nsScriptLoader;
    75 class nsSMILAnimationController;
    76 class nsStyleSet;
    77 class nsTextNode;
    78 class nsWindowSizes;
    79 class nsSmallVoidArray;
    80 class nsDOMCaretPosition;
    81 class nsViewportInfo;
    82 class nsIGlobalObject;
    83 class nsCSSSelectorList;
    85 namespace mozilla {
    86 class ErrorResult;
    87 class EventStates;
    89 namespace css {
    90 class Loader;
    91 class ImageLoader;
    92 } // namespace css
    94 namespace dom {
    95 class Attr;
    96 class CDATASection;
    97 class Comment;
    98 struct CustomElementDefinition;
    99 class DocumentFragment;
   100 class DocumentType;
   101 class DOMImplementation;
   102 class DOMStringList;
   103 class Element;
   104 struct ElementRegistrationOptions;
   105 class Event;
   106 class EventTarget;
   107 class FrameRequestCallback;
   108 class HTMLBodyElement;
   109 struct LifecycleCallbackArgs;
   110 class Link;
   111 class GlobalObject;
   112 class NodeFilter;
   113 class NodeIterator;
   114 class ProcessingInstruction;
   115 class StyleSheetList;
   116 class Touch;
   117 class TouchList;
   118 class TreeWalker;
   119 class UndoManager;
   120 class XPathEvaluator;
   121 template<typename> class OwningNonNull;
   122 template<typename> class Sequence;
   124 template<typename, typename> class CallbackObjectHolder;
   125 typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
   126 } // namespace dom
   127 } // namespace mozilla
   129 #define NS_IDOCUMENT_IID \
   130 { 0x906d05e7, 0x39af, 0x4ff0, \
   131   { 0xbc, 0xcd, 0x30, 0x0c, 0x7f, 0xeb, 0x86, 0x21 } }
   133 // Flag for AddStyleSheet().
   134 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
   136 // Enum for requesting a particular type of document when creating a doc
   137 enum DocumentFlavor {
   138   DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
   139   DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
   140   DocumentFlavorSVG // SVGDocument
   141 };
   143 // Document states
   145 // RTL locale: specific to the XUL localedir attribute
   146 #define NS_DOCUMENT_STATE_RTL_LOCALE              NS_DEFINE_EVENT_STATE_MACRO(0)
   147 // Window activation status
   148 #define NS_DOCUMENT_STATE_WINDOW_INACTIVE         NS_DEFINE_EVENT_STATE_MACRO(1)
   150 // Some function forward-declarations
   151 class nsContentList;
   153 already_AddRefed<nsContentList>
   154 NS_GetContentList(nsINode* aRootNode,
   155                   int32_t aMatchNameSpaceId,
   156                   const nsAString& aTagname);
   157 //----------------------------------------------------------------------
   159 // Document interface.  This is implemented by all document objects in
   160 // Gecko.
   161 class nsIDocument : public nsINode
   162 {
   163   typedef mozilla::dom::GlobalObject GlobalObject;
   164 public:
   165   typedef mozilla::dom::Element Element;
   167   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
   168   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
   170 #ifdef MOZILLA_INTERNAL_API
   171   nsIDocument();
   172 #endif
   174   /**
   175    * Let the document know that we're starting to load data into it.
   176    * @param aCommand The parser command. Must not be null.
   177    *                 XXXbz It's odd to have that here.
   178    * @param aChannel The channel the data will come from. The channel must be
   179    *                 able to report its Content-Type.
   180    * @param aLoadGroup The loadgroup this document should use from now on.
   181    *                   Note that the document might not be the only thing using
   182    *                   this loadgroup.
   183    * @param aContainer The container this document is in.  This may be null.
   184    *                   XXXbz maybe we should make it more explicit (eg make the
   185    *                   container an nsIWebNavigation or nsIDocShell or
   186    *                   something)?
   187    * @param [out] aDocListener the listener to pump data from the channel into.
   188    *                           Generally this will be the parser this document
   189    *                           sets up, or some sort of data-handler for media
   190    *                           documents.
   191    * @param aReset whether the document should call Reset() on itself.  If this
   192    *               is false, the document will NOT set its principal to the
   193    *               channel's owner, will not clear any event listeners that are
   194    *               already set on it, etc.
   195    * @param aSink The content sink to use for the data.  If this is null and
   196    *              the document needs a content sink, it will create one based
   197    *              on whatever it knows about the data it's going to load.
   198    *              This MUST be null if the underlying document is an HTML
   199    *              document. Even in the XML case, please don't add new calls
   200    *              with non-null sink.
   201    *
   202    * Once this has been called, the document will return false for
   203    * MayStartLayout() until SetMayStartLayout(true) is called on it.  Making
   204    * sure this happens is the responsibility of the caller of
   205    * StartDocumentLoad().
   206    */  
   207   virtual nsresult StartDocumentLoad(const char* aCommand,
   208                                      nsIChannel* aChannel,
   209                                      nsILoadGroup* aLoadGroup,
   210                                      nsISupports* aContainer,
   211                                      nsIStreamListener **aDocListener,
   212                                      bool aReset,
   213                                      nsIContentSink* aSink = nullptr) = 0;
   214   virtual void StopDocumentLoad() = 0;
   216   /**
   217    * Signal that the document title may have changed
   218    * (see nsDocument::GetTitle).
   219    * @param aBoundTitleElement true if an HTML or SVG <title> element
   220    * has just been bound to the document.
   221    */
   222   virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) = 0;
   224   /**
   225    * Return the URI for the document. May return null.
   226    *
   227    * The value returned corresponds to the "document's current address" in
   228    * HTML5.  As such, it may change over the lifetime of the document, for
   229    * instance as a result of a call to pushState() or replaceState().
   230    */
   231   nsIURI* GetDocumentURI() const
   232   {
   233     return mDocumentURI;
   234   }
   236   /**
   237    * Return the original URI of the document.  This is the same as the
   238    * document's URI unless history.pushState() or replaceState() is invoked on
   239    * the document.
   240    *
   241    * This method corresponds to the "document's address" in HTML5 and, once
   242    * set, doesn't change over the lifetime of the document.
   243    */
   244   nsIURI* GetOriginalURI() const
   245   {
   246     return mOriginalURI;
   247   }
   249   /**
   250    * Set the URI for the document.  This also sets the document's original URI,
   251    * if it's null.
   252    */
   253   virtual void SetDocumentURI(nsIURI* aURI) = 0;
   255   /**
   256    * Set the URI for the document loaded via XHR, when accessed from
   257    * chrome privileged script.
   258    */
   259   virtual void SetChromeXHRDocURI(nsIURI* aURI) = 0;
   261   /**
   262    * Set the base URI for the document loaded via XHR, when accessed from
   263    * chrome privileged script.
   264    */
   265   virtual void SetChromeXHRDocBaseURI(nsIURI* aURI) = 0;
   267   /**
   268    * Set the principal responsible for this document.
   269    */
   270   virtual void SetPrincipal(nsIPrincipal *aPrincipal) = 0;
   272   /**
   273    * Return the LoadGroup for the document. May return null.
   274    */
   275   already_AddRefed<nsILoadGroup> GetDocumentLoadGroup() const
   276   {
   277     nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
   278     return group.forget();
   279   }
   281   /**
   282    * Return the base URI for relative URIs in the document (the document uri
   283    * unless it's overridden by SetBaseURI, HTML <base> tags, etc.).  The
   284    * returned URI could be null if there is no document URI.  If the document
   285    * is a srcdoc document, return the parent document's base URL.
   286    */
   287   nsIURI* GetDocBaseURI() const
   288   {
   289     if (mIsSrcdocDocument && mParentDocument) {
   290       return mParentDocument->GetDocBaseURI();
   291     }
   292     return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
   293   }
   294   virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const MOZ_OVERRIDE;
   296   virtual nsresult SetBaseURI(nsIURI* aURI) = 0;
   298   /**
   299    * Get/Set the base target of a link in a document.
   300    */
   301   virtual void GetBaseTarget(nsAString &aBaseTarget) = 0;
   302   void SetBaseTarget(const nsString& aBaseTarget) {
   303     mBaseTarget = aBaseTarget;
   304   }
   306   /**
   307    * Return a standard name for the document's character set.
   308    */
   309   const nsCString& GetDocumentCharacterSet() const
   310   {
   311     return mCharacterSet;
   312   }
   314   /**
   315    * Set the document's character encoding. |aCharSetID| should be canonical. 
   316    * That is, callers are responsible for the charset alias resolution. 
   317    */
   318   virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) = 0;
   320   int32_t GetDocumentCharacterSetSource() const
   321   {
   322     return mCharacterSetSource;
   323   }
   325   // This method MUST be called before SetDocumentCharacterSet if
   326   // you're planning to call both.
   327   void SetDocumentCharacterSetSource(int32_t aCharsetSource)
   328   {
   329     mCharacterSetSource = aCharsetSource;
   330   }
   332   /**
   333    * Add an observer that gets notified whenever the charset changes.
   334    */
   335   virtual nsresult AddCharSetObserver(nsIObserver* aObserver) = 0;
   337   /**
   338    * Remove a charset observer.
   339    */
   340   virtual void RemoveCharSetObserver(nsIObserver* aObserver) = 0;
   342   /**
   343    * This gets fired when the element that an id refers to changes.
   344    * This fires at difficult times. It is generally not safe to do anything
   345    * which could modify the DOM in any way. Use
   346    * nsContentUtils::AddScriptRunner.
   347    * @return true to keep the callback in the callback set, false
   348    * to remove it.
   349    */
   350   typedef bool (* IDTargetObserver)(Element* aOldElement,
   351                                       Element* aNewelement, void* aData);
   353   /**
   354    * Add an IDTargetObserver for a specific ID. The IDTargetObserver
   355    * will be fired whenever the content associated with the ID changes
   356    * in the future. If aForImage is true, mozSetImageElement can override
   357    * what content is associated with the ID. In that case the IDTargetObserver
   358    * will be notified at those times when the result of LookupImageElement
   359    * changes.
   360    * At most one (aObserver, aData, aForImage) triple can be
   361    * registered for each ID.
   362    * @return the content currently associated with the ID.
   363    */
   364   virtual Element* AddIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
   365                                        void* aData, bool aForImage) = 0;
   366   /**
   367    * Remove the (aObserver, aData, aForImage) triple for a specific ID, if
   368    * registered.
   369    */
   370   virtual void RemoveIDTargetObserver(nsIAtom* aID, IDTargetObserver aObserver,
   371                                       void* aData, bool aForImage) = 0;
   373   /**
   374    * Get the Content-Type of this document.
   375    * (This will always return NS_OK, but has this signature to be compatible
   376    *  with nsIDOMDocument::GetContentType())
   377    */
   378   NS_IMETHOD GetContentType(nsAString& aContentType) = 0;
   380   /**
   381    * Set the Content-Type of this document.
   382    */
   383   virtual void SetContentType(const nsAString& aContentType) = 0;
   385   /**
   386    * Return the language of this document.
   387    */
   388   void GetContentLanguage(nsAString& aContentLanguage) const
   389   {
   390     CopyASCIItoUTF16(mContentLanguage, aContentLanguage);
   391   }
   393   // The states BidiEnabled and MathMLEnabled should persist across multiple views
   394   // (screen, print) of the same document.
   396   /**
   397    * Check if the document contains bidi data.
   398    * If so, we have to apply the Unicode Bidi Algorithm.
   399    */
   400   bool GetBidiEnabled() const
   401   {
   402     return mBidiEnabled;
   403   }
   405   /**
   406    * Indicate the document contains bidi data.
   407    * Currently, we cannot disable bidi, because once bidi is enabled,
   408    * it affects a frame model irreversibly, and plays even though
   409    * the document no longer contains bidi data.
   410    */
   411   void SetBidiEnabled()
   412   {
   413     mBidiEnabled = true;
   414   }
   416   /**
   417    * Check if the document contains (or has contained) any MathML elements.
   418    */
   419   bool GetMathMLEnabled() const
   420   {
   421     return mMathMLEnabled;
   422   }
   424   void SetMathMLEnabled()
   425   {
   426     mMathMLEnabled = true;
   427   }
   429   /**
   430    * Ask this document whether it's the initial document in its window.
   431    */
   432   bool IsInitialDocument() const
   433   {
   434     return mIsInitialDocumentInWindow;
   435   }
   437   /**
   438    * Tell this document that it's the initial document in its window.  See
   439    * comments on mIsInitialDocumentInWindow for when this should be called.
   440    */
   441   void SetIsInitialDocument(bool aIsInitialDocument)
   442   {
   443     mIsInitialDocumentInWindow = aIsInitialDocument;
   444   }
   447   /**
   448    * Get the bidi options for this document.
   449    * @see nsBidiUtils.h
   450    */
   451   uint32_t GetBidiOptions() const
   452   {
   453     return mBidiOptions;
   454   }
   456   /**
   457    * Set the bidi options for this document.  This just sets the bits;
   458    * callers are expected to take action as needed if they want this
   459    * change to actually change anything immediately.
   460    * @see nsBidiUtils.h
   461    */
   462   void SetBidiOptions(uint32_t aBidiOptions)
   463   {
   464     mBidiOptions = aBidiOptions;
   465   }
   467   /**
   468    * Get the has mixed active content loaded flag for this document.
   469    */
   470   bool GetHasMixedActiveContentLoaded()
   471   {
   472     return mHasMixedActiveContentLoaded;
   473   }
   475   /**
   476    * Set the has mixed active content loaded flag for this document.
   477    */
   478   void SetHasMixedActiveContentLoaded(bool aHasMixedActiveContentLoaded)
   479   {
   480     mHasMixedActiveContentLoaded = aHasMixedActiveContentLoaded;
   481   }
   483   /**
   484    * Get mixed active content blocked flag for this document.
   485    */
   486   bool GetHasMixedActiveContentBlocked()
   487   {
   488     return mHasMixedActiveContentBlocked;
   489   }
   491   /**
   492    * Set the mixed active content blocked flag for this document.
   493    */
   494   void SetHasMixedActiveContentBlocked(bool aHasMixedActiveContentBlocked)
   495   {
   496     mHasMixedActiveContentBlocked = aHasMixedActiveContentBlocked;
   497   }
   499   /**
   500    * Get the has mixed display content loaded flag for this document.
   501    */
   502   bool GetHasMixedDisplayContentLoaded()
   503   {
   504     return mHasMixedDisplayContentLoaded;
   505   }
   507   /**
   508    * Set the has mixed display content loaded flag for this document.
   509    */
   510   void SetHasMixedDisplayContentLoaded(bool aHasMixedDisplayContentLoaded)
   511   {
   512     mHasMixedDisplayContentLoaded = aHasMixedDisplayContentLoaded;
   513   }
   515   /**
   516    * Get mixed display content blocked flag for this document.
   517    */
   518   bool GetHasMixedDisplayContentBlocked()
   519   {
   520     return mHasMixedDisplayContentBlocked;
   521   }
   523   /**
   524    * Set the mixed display content blocked flag for this document.
   525    */
   526   void SetHasMixedDisplayContentBlocked(bool aHasMixedDisplayContentBlocked)
   527   {
   528     mHasMixedDisplayContentBlocked = aHasMixedDisplayContentBlocked;
   529   }
   531   /**
   532    * Get the sandbox flags for this document.
   533    * @see nsSandboxFlags.h for the possible flags
   534    */
   535   uint32_t GetSandboxFlags() const
   536   {
   537     return mSandboxFlags;
   538   }
   540   /**
   541    * Set the sandbox flags for this document.
   542    * @see nsSandboxFlags.h for the possible flags
   543    */
   544   void SetSandboxFlags(uint32_t sandboxFlags)
   545   {
   546     mSandboxFlags = sandboxFlags;
   547   }
   549   /**
   550    * Access HTTP header data (this may also get set from other
   551    * sources, like HTML META tags).
   552    */
   553   virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
   554   virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
   556   /**
   557    * Create a new presentation shell that will use aContext for its
   558    * presentation context (presentation contexts <b>must not</b> be
   559    * shared among multiple presentation shells). The caller of this
   560    * method is responsible for calling BeginObservingDocument() on the
   561    * presshell if the presshell should observe document mutations.
   562    */
   563   virtual already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
   564                                                      nsViewManager* aViewManager,
   565                                                      nsStyleSet* aStyleSet) = 0;
   566   virtual void DeleteShell() = 0;
   568   nsIPresShell* GetShell() const
   569   {
   570     return GetBFCacheEntry() ? nullptr : mPresShell;
   571   }
   573   void DisallowBFCaching()
   574   {
   575     NS_ASSERTION(!mBFCacheEntry, "We're already in the bfcache!");
   576     mBFCacheDisallowed = true;
   577   }
   579   bool IsBFCachingAllowed() const
   580   {
   581     return !mBFCacheDisallowed;
   582   }
   584   void SetBFCacheEntry(nsIBFCacheEntry* aEntry)
   585   {
   586     NS_ASSERTION(IsBFCachingAllowed() || !aEntry,
   587                  "You should have checked!");
   589     mBFCacheEntry = aEntry;
   590   }
   592   nsIBFCacheEntry* GetBFCacheEntry() const
   593   {
   594     return mBFCacheEntry;
   595   }
   597   /**
   598    * Return the parent document of this document. Will return null
   599    * unless this document is within a compound document and has a
   600    * parent. Note that this parent chain may cross chrome boundaries.
   601    */
   602   nsIDocument *GetParentDocument() const
   603   {
   604     return mParentDocument;
   605   }
   607   /**
   608    * Set the parent document of this document.
   609    */
   610   void SetParentDocument(nsIDocument* aParent)
   611   {
   612     mParentDocument = aParent;
   613   }
   615   /**
   616    * Are plugins allowed in this document ?
   617    */
   618   virtual nsresult GetAllowPlugins (bool* aAllowPlugins) = 0;
   620   /**
   621    * Set the sub document for aContent to aSubDoc.
   622    */
   623   virtual nsresult SetSubDocumentFor(Element* aContent,
   624                                      nsIDocument* aSubDoc) = 0;
   626   /**
   627    * Get the sub document for aContent
   628    */
   629   virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
   631   /**
   632    * Find the content node for which aDocument is a sub document.
   633    */
   634   virtual Element* FindContentForSubDocument(nsIDocument* aDocument) const = 0;
   636   /**
   637    * Return the doctype for this document.
   638    */
   639   mozilla::dom::DocumentType* GetDoctype() const;
   641   /**
   642    * Return the root element for this document.
   643    */
   644   Element* GetRootElement() const;
   646   virtual nsViewportInfo GetViewportInfo(const mozilla::ScreenIntSize& aDisplaySize) = 0;
   648   /**
   649    * True iff this doc will ignore manual character encoding overrides.
   650    */
   651   virtual bool WillIgnoreCharsetOverride() {
   652     return true;
   653   }
   655   /**
   656    * Return whether the document was created by a srcdoc iframe.
   657    */
   658   bool IsSrcdocDocument() const {
   659     return mIsSrcdocDocument;
   660   }
   662   /**
   663    * Sets whether the document was created by a srcdoc iframe.
   664    */
   665   void SetIsSrcdocDocument(bool aIsSrcdocDocument) {
   666     mIsSrcdocDocument = aIsSrcdocDocument;
   667   }
   669   /*
   670    * Gets the srcdoc string from within the channel (assuming both exist).
   671    * Returns a void string if this isn't a srcdoc document or if
   672    * the channel has not been set.
   673    */
   674   nsresult GetSrcdocData(nsAString& aSrcdocData);
   676   bool DidDocumentOpen() {
   677     return mDidDocumentOpen;
   678   }
   680 protected:
   681   virtual Element *GetRootElementInternal() const = 0;
   683 private:
   684   class SelectorCacheKey
   685   {
   686     public:
   687       SelectorCacheKey(const nsAString& aString) : mKey(aString)
   688       {
   689         MOZ_COUNT_CTOR(SelectorCacheKey);
   690       }
   692       nsString mKey;
   693       nsExpirationState mState;
   695       nsExpirationState* GetExpirationState() { return &mState; }
   697       ~SelectorCacheKey()
   698       {
   699         MOZ_COUNT_DTOR(SelectorCacheKey);
   700       }
   701   };
   703   class SelectorCacheKeyDeleter;
   705 public:
   706   class SelectorCache MOZ_FINAL
   707     : public nsExpirationTracker<SelectorCacheKey, 4>
   708   {
   709     public:
   710       SelectorCache();
   712       // CacheList takes ownership of aSelectorList.
   713       void CacheList(const nsAString& aSelector, nsCSSSelectorList* aSelectorList);
   715       virtual void NotifyExpired(SelectorCacheKey* aSelector) MOZ_OVERRIDE;
   717       // We do not call MarkUsed because it would just slow down lookups and
   718       // because we're OK expiring things after a few seconds even if they're
   719       // being used.  Returns whether we actually had an entry for aSelector.
   720       // If we have an entry and *aList is null, that indicates that aSelector
   721       // has already been parsed and is not a syntactically valid selector.
   722       bool GetList(const nsAString& aSelector, nsCSSSelectorList** aList)
   723       {
   724         return mTable.Get(aSelector, aList);
   725       }
   727       ~SelectorCache()
   728       {
   729         AgeAllGenerations();
   730       }
   732     private:
   733       nsClassHashtable<nsStringHashKey, nsCSSSelectorList> mTable;
   734   };
   736   SelectorCache& GetSelectorCache()
   737   {
   738     return mSelectorCache;
   739   }
   740   // Get the root <html> element, or return null if there isn't one (e.g.
   741   // if the root isn't <html>)
   742   Element* GetHtmlElement() const;
   743   // Returns the first child of GetHtmlContent which has the given tag,
   744   // or nullptr if that doesn't exist.
   745   Element* GetHtmlChildElement(nsIAtom* aTag);
   746   // Get the canonical <body> element, or return null if there isn't one (e.g.
   747   // if the root isn't <html> or if the <body> isn't there)
   748   mozilla::dom::HTMLBodyElement* GetBodyElement();
   749   // Get the canonical <head> element, or return null if there isn't one (e.g.
   750   // if the root isn't <html> or if the <head> isn't there)
   751   Element* GetHeadElement() {
   752     return GetHtmlChildElement(nsGkAtoms::head);
   753   }
   755   /**
   756    * Accessors to the collection of stylesheets owned by this document.
   757    * Style sheets are ordered, most significant last.
   758    */
   760   /**
   761    * Get the number of stylesheets
   762    *
   763    * @return the number of stylesheets
   764    * @throws no exceptions
   765    */
   766   virtual int32_t GetNumberOfStyleSheets() const = 0;
   768   /**
   769    * Get a particular stylesheet
   770    * @param aIndex the index the stylesheet lives at.  This is zero-based
   771    * @return the stylesheet at aIndex.  Null if aIndex is out of range.
   772    * @throws no exceptions
   773    */
   774   virtual nsIStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0;
   776   /**
   777    * Insert a sheet at a particular spot in the stylesheet list (zero-based)
   778    * @param aSheet the sheet to insert
   779    * @param aIndex the index to insert at.  This index will be
   780    *   adjusted for the "special" sheets.
   781    * @throws no exceptions
   782    */
   783   virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) = 0;
   785   /**
   786    * Get the index of a particular stylesheet.  This will _always_
   787    * consider the "special" sheets as part of the sheet list.
   788    * @param aSheet the sheet to get the index of
   789    * @return aIndex the index of the sheet in the full list
   790    */
   791   virtual int32_t GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const = 0;
   793   /**
   794    * Replace the stylesheets in aOldSheets with the stylesheets in
   795    * aNewSheets. The two lists must have equal length, and the sheet
   796    * at positon J in the first list will be replaced by the sheet at
   797    * position J in the second list.  Some sheets in the second list
   798    * may be null; if so the corresponding sheets in the first list
   799    * will simply be removed.
   800    */
   801   virtual void UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
   802                                  nsCOMArray<nsIStyleSheet>& aNewSheets) = 0;
   804   /**
   805    * Add a stylesheet to the document
   806    */
   807   virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
   809   /**
   810    * Remove a stylesheet from the document
   811    */
   812   virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
   814   /**
   815    * Notify the document that the applicable state of the sheet changed
   816    * and that observers should be notified and style sets updated
   817    */
   818   virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
   819                                             bool aApplicable) = 0;  
   821   /**
   822    * Just like the style sheet API, but for "catalog" sheets,
   823    * extra sheets inserted at the UA level.
   824    */
   825   virtual int32_t GetNumberOfCatalogStyleSheets() const = 0;
   826   virtual nsIStyleSheet* GetCatalogStyleSheetAt(int32_t aIndex) const = 0;
   827   virtual void AddCatalogStyleSheet(nsCSSStyleSheet* aSheet) = 0;
   828   virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI) = 0;
   830   enum additionalSheetType {
   831     eAgentSheet,
   832     eUserSheet,
   833     eAuthorSheet,
   834     SheetTypeCount
   835   };
   837   virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) = 0;
   838   virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) = 0;
   839   virtual nsIStyleSheet* FirstAdditionalAuthorSheet() = 0;
   841   /**
   842    * Get this document's CSSLoader.  This is guaranteed to not return null.
   843    */
   844   mozilla::css::Loader* CSSLoader() const {
   845     return mCSSLoader;
   846   }
   848   /**
   849    * Get this document's StyleImageLoader.  This is guaranteed to not return null.
   850    */
   851   mozilla::css::ImageLoader* StyleImageLoader() const {
   852     return mStyleImageLoader;
   853   }
   855   /**
   856    * Get the channel that was passed to StartDocumentLoad or Reset for this
   857    * document.  Note that this may be null in some cases (eg if
   858    * StartDocumentLoad or Reset were never called)
   859    */
   860   virtual nsIChannel* GetChannel() const = 0;
   862   /**
   863    * Get this document's attribute stylesheet.  May return null if
   864    * there isn't one.
   865    */
   866   nsHTMLStyleSheet* GetAttributeStyleSheet() const {
   867     return mAttrStyleSheet;
   868   }
   870   /**
   871    * Get this document's inline style sheet.  May return null if there
   872    * isn't one
   873    */
   874   nsHTMLCSSStyleSheet* GetInlineStyleSheet() const {
   875     return mStyleAttrStyleSheet;
   876   }
   878   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
   880   /**
   881    * Get/set the object from which the context for the event/script handling can
   882    * be got. Normally GetScriptHandlingObject() returns the same object as
   883    * GetScriptGlobalObject(), but if the document is loaded as data,
   884    * non-null may be returned, even if GetScriptGlobalObject() returns null.
   885    * aHasHadScriptHandlingObject is set true if document has had the object
   886    * for event/script handling. Do not process any events/script if the method
   887    * returns null, but aHasHadScriptHandlingObject is true.
   888    */
   889   nsIScriptGlobalObject*
   890     GetScriptHandlingObject(bool& aHasHadScriptHandlingObject) const
   891   {
   892     aHasHadScriptHandlingObject = mHasHadScriptHandlingObject;
   893     return mScriptGlobalObject ? mScriptGlobalObject.get() :
   894                                  GetScriptHandlingObjectInternal();
   895   }
   896   virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) = 0;
   898   /**
   899    * Get the object that is used as the scope for all of the content
   900    * wrappers whose owner document is this document. Unlike the script global
   901    * object, this will only return null when the global object for this
   902    * document is truly gone. Use this object when you're trying to find a
   903    * content wrapper in XPConnect.
   904    */
   905   virtual nsIGlobalObject* GetScopeObject() const = 0;
   906   virtual void SetScopeObject(nsIGlobalObject* aGlobal) = 0;
   908   /**
   909    * Return the window containing the document (the outer window).
   910    */
   911   nsPIDOMWindow *GetWindow() const
   912   {
   913     return mWindow ? mWindow->GetOuterWindow() : GetWindowInternal();
   914   }
   916   bool IsInBackgroundWindow() const
   917   {
   918     nsPIDOMWindow* outer = mWindow ? mWindow->GetOuterWindow() : nullptr;
   919     return outer && outer->IsBackground();
   920   }
   922   /**
   923    * Return the inner window used as the script compilation scope for
   924    * this document. If you're not absolutely sure you need this, use
   925    * GetWindow().
   926    */
   927   nsPIDOMWindow* GetInnerWindow() const
   928   {
   929     return mRemovedFromDocShell ? nullptr : mWindow;
   930   }
   932   /**
   933    * Return the outer window ID.
   934    */
   935   uint64_t OuterWindowID() const
   936   {
   937     nsPIDOMWindow *window = GetWindow();
   938     return window ? window->WindowID() : 0;
   939   }
   941   /**
   942    * Return the inner window ID.
   943    */
   944   uint64_t InnerWindowID()
   945   {
   946     nsPIDOMWindow *window = GetInnerWindow();
   947     return window ? window->WindowID() : 0;
   948   }
   950   /**
   951    * Get the script loader for this document
   952    */ 
   953   virtual nsScriptLoader* ScriptLoader() = 0;
   955   /**
   956    * Add/Remove an element to the document's id and name hashes
   957    */
   958   virtual void AddToIdTable(Element* aElement, nsIAtom* aId) = 0;
   959   virtual void RemoveFromIdTable(Element* aElement, nsIAtom* aId) = 0;
   960   virtual void AddToNameTable(Element* aElement, nsIAtom* aName) = 0;
   961   virtual void RemoveFromNameTable(Element* aElement, nsIAtom* aName) = 0;
   963   /**
   964    * Returns the element which either requested DOM full-screen mode, or
   965    * contains the element which requested DOM full-screen mode if the
   966    * requestee is in a subdocument. Note this element must be *in*
   967    * this document.
   968    */
   969   virtual Element* GetFullScreenElement() = 0;
   971   /**
   972    * Asynchronously requests that the document make aElement the fullscreen
   973    * element, and move into fullscreen mode. The current fullscreen element
   974    * (if any) is pushed onto the fullscreen element stack, and it can be
   975    * returned to fullscreen status by calling RestorePreviousFullScreenState().
   976    *
   977    * Note that requesting fullscreen in a document also makes the element which
   978    * contains this document in this document's parent document fullscreen. i.e.
   979    * the <iframe> or <browser> that contains this document is also mode
   980    * fullscreen. This happens recursively in all ancestor documents.
   981    */
   982   virtual void AsyncRequestFullScreen(Element* aElement) = 0;
   984   /**
   985    * Called when a frame in a child process has entered fullscreen or when a
   986    * fullscreen frame in a child process changes to another origin.
   987    * aFrameElement is the frame element which contains the child-process
   988    * fullscreen document, and aNewOrigin is the origin of the new fullscreen
   989    * document.
   990    */
   991   virtual nsresult RemoteFrameFullscreenChanged(nsIDOMElement* aFrameElement,
   992                                                 const nsAString& aNewOrigin) = 0;
   994   /**
   995    * Called when a frame in a remote child document has rolled back fullscreen
   996    * so that all its fullscreen element stacks are empty; we must continue the
   997    * rollback in this parent process' doc tree branch which is fullscreen.
   998    * Note that only one branch of the document tree can have its documents in
   999    * fullscreen state at one time. We're in inconsistent state if a
  1000    * fullscreen document has a parent and that parent isn't fullscreen. We
  1001    * preserve this property across process boundaries.
  1002    */
  1003    virtual nsresult RemoteFrameFullscreenReverted() = 0;
  1005   /**
  1006    * Restores the previous full-screen element to full-screen status. If there
  1007    * is no former full-screen element, this exits full-screen, moving the
  1008    * top-level browser window out of full-screen mode.
  1009    */
  1010   virtual void RestorePreviousFullScreenState() = 0;
  1012   /**
  1013    * Returns true if this document is in full-screen mode.
  1014    */
  1015   virtual bool IsFullScreenDoc() = 0;
  1017   /**
  1018    * Returns true if this document is a fullscreen leaf document, i.e. it
  1019    * is in fullscreen mode and has no fullscreen children.
  1020    */
  1021   virtual bool IsFullscreenLeaf() = 0;
  1023   /**
  1024    * Returns the document which is at the root of this document's branch
  1025    * in the in-process document tree. Returns nullptr if the document isn't
  1026    * fullscreen.
  1027    */
  1028   virtual nsIDocument* GetFullscreenRoot() = 0;
  1030   /**
  1031    * Sets the fullscreen root to aRoot. This stores a weak reference to aRoot
  1032    * in this document.
  1033    */
  1034   virtual void SetFullscreenRoot(nsIDocument* aRoot) = 0;
  1036   /**
  1037    * Sets whether this document is approved for fullscreen mode.
  1038    * Documents aren't approved for fullscreen until chrome has sent a
  1039    * "fullscreen-approved" notification with a subject which is a pointer
  1040    * to the approved document.
  1041    */
  1042   virtual void SetApprovedForFullscreen(bool aIsApproved) = 0;
  1044   /**
  1045    * Exits documents out of DOM fullscreen mode.
  1047    * If aDocument is null, all fullscreen documents in all browser windows
  1048    * exit fullscreen.
  1050    * If aDocument is non null, all documents from aDocument's fullscreen root
  1051    * to the fullscreen leaf exit fullscreen. 
  1053    * Note that the fullscreen leaf is the bottom-most document which is
  1054    * fullscreen, it may have non-fullscreen child documents. The fullscreen
  1055    * root is usually the chrome document, but if fullscreen is content-only,
  1056    * (see the comment in nsContentUtils.h on IsFullscreenApiContentOnly())
  1057    * the fullscreen root will be a direct child of the chrome document, and
  1058    * there may be other branches of the same doctree that are fullscreen.
  1060    * If aRunAsync is true, fullscreen is executed asynchronously.
  1062    * Note if aDocument is not fullscreen this function has no effect, even if
  1063    * aDocument has fullscreen ancestors.
  1064    */
  1065   static void ExitFullscreen(nsIDocument* aDocument, bool aRunAsync);
  1067   virtual void RequestPointerLock(Element* aElement) = 0;
  1069   static void UnlockPointer(nsIDocument* aDoc = nullptr);
  1072   //----------------------------------------------------------------------
  1074   // Document notification API's
  1076   /**
  1077    * Add a new observer of document change notifications. Whenever
  1078    * content is changed, appended, inserted or removed the observers are
  1079    * informed.  An observer that is already observing the document must
  1080    * not be added without being removed first.
  1081    */
  1082   virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
  1084   /**
  1085    * Remove an observer of document change notifications. This will
  1086    * return false if the observer cannot be found.
  1087    */
  1088   virtual bool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
  1090   // Observation hooks used to propagate notifications to document observers.
  1091   // BeginUpdate must be called before any batch of modifications of the
  1092   // content model or of style data, EndUpdate must be called afterward.
  1093   // To make this easy and painless, use the mozAutoDocUpdate helper class.
  1094   virtual void BeginUpdate(nsUpdateType aUpdateType) = 0;
  1095   virtual void EndUpdate(nsUpdateType aUpdateType) = 0;
  1096   virtual void BeginLoad() = 0;
  1097   virtual void EndLoad() = 0;
  1099   enum ReadyState { READYSTATE_UNINITIALIZED = 0, READYSTATE_LOADING = 1, READYSTATE_INTERACTIVE = 3, READYSTATE_COMPLETE = 4};
  1100   virtual void SetReadyStateInternal(ReadyState rs) = 0;
  1101   ReadyState GetReadyStateEnum()
  1103     return mReadyState;
  1106   // notify that a content node changed state.  This must happen under
  1107   // a scriptblocker but NOT within a begin/end update.
  1108   virtual void ContentStateChanged(nsIContent* aContent,
  1109                                    mozilla::EventStates aStateMask) = 0;
  1111   // Notify that a document state has changed.
  1112   // This should only be called by callers whose state is also reflected in the
  1113   // implementation of nsDocument::GetDocumentState.
  1114   virtual void DocumentStatesChanged(mozilla::EventStates aStateMask) = 0;
  1116   // Observation hooks for style data to propagate notifications
  1117   // to document observers
  1118   virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
  1119                                 nsIStyleRule* aOldStyleRule,
  1120                                 nsIStyleRule* aNewStyleRule) = 0;
  1121   virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
  1122                               nsIStyleRule* aStyleRule) = 0;
  1123   virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
  1124                                 nsIStyleRule* aStyleRule) = 0;
  1126   /**
  1127    * Flush notifications for this document and its parent documents
  1128    * (since those may affect the layout of this one).
  1129    */
  1130   virtual void FlushPendingNotifications(mozFlushType aType) = 0;
  1132   /**
  1133    * Calls FlushPendingNotifications on any external resources this document
  1134    * has. If this document has no external resources or is an external resource
  1135    * itself this does nothing. This should only be called with
  1136    * aType >= Flush_Style.
  1137    */
  1138   virtual void FlushExternalResources(mozFlushType aType) = 0;
  1140   nsBindingManager* BindingManager() const
  1142     return mNodeInfoManager->GetBindingManager();
  1145   /**
  1146    * Only to be used inside Gecko, you can't really do anything with the
  1147    * pointer outside Gecko anyway.
  1148    */
  1149   nsNodeInfoManager* NodeInfoManager() const
  1151     return mNodeInfoManager;
  1154   /**
  1155    * Reset the document using the given channel and loadgroup.  This works
  1156    * like ResetToURI, but also sets the document's channel to aChannel.
  1157    * The principal of the document will be set from the channel.
  1158    */
  1159   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0;
  1161   /**
  1162    * Reset this document to aURI, aLoadGroup, and aPrincipal.  aURI must not be
  1163    * null.  If aPrincipal is null, a codebase principal based on aURI will be
  1164    * used.
  1165    */
  1166   virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup,
  1167                           nsIPrincipal* aPrincipal) = 0;
  1169   /**
  1170    * Set the container (docshell) for this document. Virtual so that
  1171    * docshell can call it.
  1172    */
  1173   virtual void SetContainer(nsDocShell* aContainer);
  1175   /**
  1176    * Get the container (docshell) for this document.
  1177    */
  1178   virtual nsISupports* GetContainer() const;
  1180   /**
  1181    * Get the container's load context for this document.
  1182    */
  1183   nsILoadContext* GetLoadContext() const;
  1185   /**
  1186    * Get docshell the for this document.
  1187    */
  1188   nsIDocShell* GetDocShell() const;
  1190   /**
  1191    * Set and get XML declaration. If aVersion is null there is no declaration.
  1192    * aStandalone takes values -1, 0 and 1 indicating respectively that there
  1193    * was no standalone parameter in the declaration, that it was given as no,
  1194    * or that it was given as yes.
  1195    */
  1196   virtual void SetXMLDeclaration(const char16_t *aVersion,
  1197                                  const char16_t *aEncoding,
  1198                                  const int32_t aStandalone) = 0;
  1199   virtual void GetXMLDeclaration(nsAString& aVersion,
  1200                                  nsAString& aEncoding,
  1201                                  nsAString& Standalone) = 0;
  1203   bool IsHTML() const
  1205     return mIsRegularHTML;
  1207   bool IsXUL() const
  1209     return mIsXUL;
  1212   virtual bool IsScriptEnabled() = 0;
  1214   /**
  1215    * Create an element with the specified name, prefix and namespace ID.
  1216    */
  1217   virtual nsresult CreateElem(const nsAString& aName, nsIAtom *aPrefix,
  1218                               int32_t aNamespaceID,
  1219                               nsIContent** aResult) = 0;
  1221   /**
  1222    * Get the security info (i.e. SSL state etc) that the document got
  1223    * from the channel/document that created the content of the
  1224    * document.
  1226    * @see nsIChannel
  1227    */
  1228   nsISupports *GetSecurityInfo()
  1230     return mSecurityInfo;
  1233   /**
  1234    * Returns the default namespace ID used for elements created in this
  1235    * document.
  1236    */
  1237   int32_t GetDefaultNamespaceID() const
  1239     return mDefaultElementType;
  1242   void DeleteAllProperties();
  1243   void DeleteAllPropertiesFor(nsINode* aNode);
  1245   nsPropertyTable* PropertyTable(uint16_t aCategory) {
  1246     if (aCategory == 0)
  1247       return &mPropertyTable;
  1248     return GetExtraPropertyTable(aCategory);
  1250   uint32_t GetPropertyTableCount()
  1251   { return mExtraPropertyTables.Length() + 1; }
  1253   /**
  1254    * Sets the ID used to identify this part of the multipart document
  1255    */
  1256   void SetPartID(uint32_t aID) {
  1257     mPartID = aID;
  1260   /**
  1261    * Return the ID used to identify this part of the multipart document
  1262    */
  1263   uint32_t GetPartID() const {
  1264     return mPartID;
  1267   /**
  1268    * Sanitize the document by resetting all input elements and forms that have
  1269    * autocomplete=off to their default values.
  1270    */
  1271   virtual void Sanitize() = 0;
  1273   /**
  1274    * Enumerate all subdocuments.
  1275    * The enumerator callback should return true to continue enumerating, or
  1276    * false to stop.  This will never get passed a null aDocument.
  1277    */
  1278   typedef bool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
  1279   virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
  1280                                      void *aData) = 0;
  1282   /**
  1283    * Check whether it is safe to cache the presentation of this document
  1284    * and all of its subdocuments. This method checks the following conditions
  1285    * recursively:
  1286    *  - Some document types, such as plugin documents, cannot be safely cached.
  1287    *  - If there are any pending requests, we don't allow the presentation
  1288    *    to be cached.  Ideally these requests would be suspended and resumed,
  1289    *    but that is difficult in some cases, such as XMLHttpRequest.
  1290    *  - If there are any beforeunload or unload listeners, we must fire them
  1291    *    for correctness, but this likely puts the document into a state where
  1292    *    it would not function correctly if restored.
  1294    * |aNewRequest| should be the request for a new document which will
  1295    * replace this document in the docshell.  The new document's request
  1296    * will be ignored when checking for active requests.  If there is no
  1297    * request associated with the new document, this parameter may be null.
  1298    */
  1299   virtual bool CanSavePresentation(nsIRequest *aNewRequest) = 0;
  1301   /**
  1302    * Notify the document that its associated ContentViewer is being destroyed.
  1303    * This releases circular references so that the document can go away.
  1304    * Destroy() is only called on documents that have a content viewer.
  1305    */
  1306   virtual void Destroy() = 0;
  1308   /**
  1309    * Notify the document that its associated ContentViewer is no longer
  1310    * the current viewer for the docshell. The document might still
  1311    * be rendered in "zombie state" until the next document is ready.
  1312    * The document should save form control state.
  1313    */
  1314   virtual void RemovedFromDocShell() = 0;
  1316   /**
  1317    * Get the layout history state that should be used to save and restore state
  1318    * for nodes in this document.  This may return null; if that happens state
  1319    * saving and restoration is not possible.
  1320    */
  1321   virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const = 0;
  1323   /**
  1324    * Methods that can be used to prevent onload firing while an event that
  1325    * should block onload is posted.  onload is guaranteed to not fire until
  1326    * either all calls to BlockOnload() have been matched by calls to
  1327    * UnblockOnload() or the load has been stopped altogether (by the user
  1328    * pressing the Stop button, say).
  1329    */
  1330   virtual void BlockOnload() = 0;
  1331   /**
  1332    * @param aFireSync whether to fire onload synchronously.  If false,
  1333    * onload will fire asynchronously after all onload blocks have been
  1334    * removed.  It will NOT fire from inside UnblockOnload.  If true,
  1335    * onload may fire from inside UnblockOnload.
  1336    */
  1337   virtual void UnblockOnload(bool aFireSync) = 0;
  1339   void BlockDOMContentLoaded()
  1341     ++mBlockDOMContentLoaded;
  1344   virtual void UnblockDOMContentLoaded() = 0;
  1346   /**
  1347    * Notification that the page has been shown, for documents which are loaded
  1348    * into a DOM window.  This corresponds to the completion of document load,
  1349    * or to the page's presentation being restored into an existing DOM window.
  1350    * This notification fires applicable DOM events to the content window.  See
  1351    * nsIDOMPageTransitionEvent.idl for a description of the |aPersisted|
  1352    * parameter. If aDispatchStartTarget is null, the pageshow event is
  1353    * dispatched on the ScriptGlobalObject for this document, otherwise it's
  1354    * dispatched on aDispatchStartTarget.
  1355    * Note: if aDispatchStartTarget isn't null, the showing state of the
  1356    * document won't be altered.
  1357    */
  1358   virtual void OnPageShow(bool aPersisted,
  1359                           mozilla::dom::EventTarget* aDispatchStartTarget) = 0;
  1361   /**
  1362    * Notification that the page has been hidden, for documents which are loaded
  1363    * into a DOM window.  This corresponds to the unloading of the document, or
  1364    * to the document's presentation being saved but removed from an existing
  1365    * DOM window.  This notification fires applicable DOM events to the content
  1366    * window.  See nsIDOMPageTransitionEvent.idl for a description of the
  1367    * |aPersisted| parameter. If aDispatchStartTarget is null, the pagehide
  1368    * event is dispatched on the ScriptGlobalObject for this document,
  1369    * otherwise it's dispatched on aDispatchStartTarget.
  1370    * Note: if aDispatchStartTarget isn't null, the showing state of the
  1371    * document won't be altered.
  1372    */
  1373   virtual void OnPageHide(bool aPersisted,
  1374                           mozilla::dom::EventTarget* aDispatchStartTarget) = 0;
  1376   /*
  1377    * We record the set of links in the document that are relevant to
  1378    * style.
  1379    */
  1380   /**
  1381    * Notification that an element is a link that is relevant to style.
  1382    */
  1383   virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) = 0;
  1384   /**
  1385    * Notification that an element is a link and its URI might have been
  1386    * changed or the element removed. If the element is still a link relevant
  1387    * to style, then someone must ensure that AddStyleRelevantLink is
  1388    * (eventually) called on it again.
  1389    */
  1390   virtual void ForgetLink(mozilla::dom::Link* aLink) = 0;
  1392   /**
  1393    * Resets and removes a box object from the document's box object cache
  1395    * @param aElement canonical nsIContent pointer of the box object's element
  1396    */
  1397   virtual void ClearBoxObjectFor(nsIContent *aContent) = 0;
  1399   /**
  1400    * Get the box object for an element. This is not exposed through a
  1401    * scriptable interface except for XUL documents.
  1402    */
  1403   virtual already_AddRefed<nsIBoxObject>
  1404     GetBoxObjectFor(mozilla::dom::Element* aElement,
  1405                     mozilla::ErrorResult& aRv) = 0;
  1407   /**
  1408    * Get the compatibility mode for this document
  1409    */
  1410   nsCompatibility GetCompatibilityMode() const {
  1411     return mCompatMode;
  1414   /**
  1415    * Check whether we've ever fired a DOMTitleChanged event for this
  1416    * document.
  1417    */
  1418   bool HaveFiredDOMTitleChange() const {
  1419     return mHaveFiredTitleChange;
  1422   /**
  1423    * See GetAnonymousElementByAttribute on nsIDOMDocumentXBL.
  1424    */
  1425   virtual Element*
  1426     GetAnonymousElementByAttribute(nsIContent* aElement,
  1427                                    nsIAtom* aAttrName,
  1428                                    const nsAString& aAttrValue) const = 0;
  1430   /**
  1431    * Helper for nsIDOMDocument::elementFromPoint implementation that allows
  1432    * ignoring the scroll frame and/or avoiding layout flushes.
  1434    * @see nsIDOMWindowUtils::elementFromPoint
  1435    */
  1436   virtual Element* ElementFromPointHelper(float aX, float aY,
  1437                                           bool aIgnoreRootScrollFrame,
  1438                                           bool aFlushLayout) = 0;
  1440   virtual nsresult NodesFromRectHelper(float aX, float aY,
  1441                                        float aTopSize, float aRightSize,
  1442                                        float aBottomSize, float aLeftSize,
  1443                                        bool aIgnoreRootScrollFrame,
  1444                                        bool aFlushLayout,
  1445                                        nsIDOMNodeList** aReturn) = 0;
  1447   /**
  1448    * See FlushSkinBindings on nsBindingManager
  1449    */
  1450   virtual void FlushSkinBindings() = 0;
  1452   /**
  1453    * To batch DOMSubtreeModified, document needs to be informed when
  1454    * a mutation event might be dispatched, even if the event isn't actually
  1455    * created because there are no listeners for it.
  1457    * @param aTarget is the target for the mutation event.
  1458    */
  1459   void MayDispatchMutationEvent(nsINode* aTarget)
  1461     if (mSubtreeModifiedDepth > 0) {
  1462       mSubtreeModifiedTargets.AppendObject(aTarget);
  1466   /**
  1467    * Marks as not-going-to-be-collected for the given generation of
  1468    * cycle collection.
  1469    */
  1470   void MarkUncollectableForCCGeneration(uint32_t aGeneration)
  1472     mMarkedCCGeneration = aGeneration;
  1475   /**
  1476    * Gets the cycle collector generation this document is marked for.
  1477    */
  1478   uint32_t GetMarkedCCGeneration()
  1480     return mMarkedCCGeneration;
  1483   bool IsLoadedAsData()
  1485     return mLoadedAsData;
  1488   bool IsLoadedAsInteractiveData()
  1490     return mLoadedAsInteractiveData;
  1493   bool MayStartLayout()
  1495     return mMayStartLayout;
  1498   void SetMayStartLayout(bool aMayStartLayout)
  1500     mMayStartLayout = aMayStartLayout;
  1503   already_AddRefed<nsIDocumentEncoder> GetCachedEncoder();
  1505   void SetCachedEncoder(already_AddRefed<nsIDocumentEncoder> aEncoder);
  1507   // In case of failure, the document really can't initialize the frame loader.
  1508   virtual nsresult InitializeFrameLoader(nsFrameLoader* aLoader) = 0;
  1509   // In case of failure, the caller must handle the error, for example by
  1510   // finalizing frame loader asynchronously.
  1511   virtual nsresult FinalizeFrameLoader(nsFrameLoader* aLoader) = 0;
  1512   // Removes the frame loader of aShell from the initialization list.
  1513   virtual void TryCancelFrameLoaderInitialization(nsIDocShell* aShell) = 0;
  1514   //  Returns true if the frame loader of aShell is in the finalization list.
  1515   virtual bool FrameLoaderScheduledToBeFinalized(nsIDocShell* aShell) = 0;
  1517   /**
  1518    * Check whether this document is a root document that is not an
  1519    * external resource.
  1520    */
  1521   bool IsRootDisplayDocument() const
  1523     return !mParentDocument && !mDisplayDocument;
  1526   bool IsBeingUsedAsImage() const {
  1527     return mIsBeingUsedAsImage;
  1530   void SetIsBeingUsedAsImage() {
  1531     mIsBeingUsedAsImage = true;
  1534   bool IsResourceDoc() const {
  1535     return IsBeingUsedAsImage() || // Are we a helper-doc for an SVG image?
  1536       !!mDisplayDocument;          // Are we an external resource doc?
  1539   /**
  1540    * Get the document for which this document is an external resource.  This
  1541    * will be null if this document is not an external resource.  Otherwise,
  1542    * GetDisplayDocument() will return a non-null document, and
  1543    * GetDisplayDocument()->GetDisplayDocument() is guaranteed to be null.
  1544    */
  1545   nsIDocument* GetDisplayDocument() const
  1547     return mDisplayDocument;
  1550   /**
  1551    * Set the display document for this document.  aDisplayDocument must not be
  1552    * null.
  1553    */
  1554   void SetDisplayDocument(nsIDocument* aDisplayDocument)
  1556     NS_PRECONDITION(!GetShell() &&
  1557                     !GetContainer() &&
  1558                     !GetWindow(),
  1559                     "Shouldn't set mDisplayDocument on documents that already "
  1560                     "have a presentation or a docshell or a window");
  1561     NS_PRECONDITION(aDisplayDocument != this, "Should be different document");
  1562     NS_PRECONDITION(!aDisplayDocument->GetDisplayDocument(),
  1563                     "Display documents should not nest");
  1564     mDisplayDocument = aDisplayDocument;
  1567   /**
  1568    * A class that represents an external resource load that has begun but
  1569    * doesn't have a document yet.  Observers can be registered on this object,
  1570    * and will be notified after the document is created.  Observers registered
  1571    * after the document has been created will NOT be notified.  When observers
  1572    * are notified, the subject will be the newly-created document, the topic
  1573    * will be "external-resource-document-created", and the data will be null.
  1574    * If document creation fails for some reason, observers will still be
  1575    * notified, with a null document pointer.
  1576    */
  1577   class ExternalResourceLoad : public nsISupports
  1579   public:
  1580     virtual ~ExternalResourceLoad() {}
  1582     void AddObserver(nsIObserver* aObserver) {
  1583       NS_PRECONDITION(aObserver, "Must have observer");
  1584       mObservers.AppendElement(aObserver);
  1587     const nsTArray< nsCOMPtr<nsIObserver> > & Observers() {
  1588       return mObservers;
  1590   protected:
  1591     nsAutoTArray< nsCOMPtr<nsIObserver>, 8 > mObservers;    
  1592   };
  1594   /**
  1595    * Request an external resource document for aURI.  This will return the
  1596    * resource document if available.  If one is not available yet, it will
  1597    * start loading as needed, and the pending load object will be returned in
  1598    * aPendingLoad so that the caller can register an observer to wait for the
  1599    * load.  If this function returns null and doesn't return a pending load,
  1600    * that means that there is no resource document for this URI and won't be
  1601    * one in the future.
  1603    * @param aURI the URI to get
  1604    * @param aRequestingNode the node making the request
  1605    * @param aPendingLoad the pending load for this request, if any
  1606    */
  1607   virtual nsIDocument*
  1608     RequestExternalResource(nsIURI* aURI,
  1609                             nsINode* aRequestingNode,
  1610                             ExternalResourceLoad** aPendingLoad) = 0;
  1612   /**
  1613    * Enumerate the external resource documents associated with this document.
  1614    * The enumerator callback should return true to continue enumerating, or
  1615    * false to stop.  This callback will never get passed a null aDocument.
  1616    */
  1617   virtual void EnumerateExternalResources(nsSubDocEnumFunc aCallback,
  1618                                           void* aData) = 0;
  1620   /**
  1621    * Return whether the document is currently showing (in the sense of
  1622    * OnPageShow() having been called already and OnPageHide() not having been
  1623    * called yet.
  1624    */
  1625   bool IsShowing() const { return mIsShowing; }
  1626   /**
  1627    * Return whether the document is currently visible (in the sense of
  1628    * OnPageHide having been called and OnPageShow not yet having been called)
  1629    */
  1630   bool IsVisible() const { return mVisible; }
  1632   /**
  1633    * Return whether the document and all its ancestors are visible in the sense of
  1634    * pageshow / hide.
  1635    */
  1636   bool IsVisibleConsideringAncestors() const;
  1638   /**
  1639    * Return true when this document is active, i.e., the active document
  1640    * in a content viewer.  Note that this will return true for bfcached
  1641    * documents, so this does NOT match the "active document" concept in
  1642    * the WHATWG spec.  That would correspond to GetInnerWindow() &&
  1643    * GetInnerWindow()->IsCurrentInnerWindow().
  1644    */
  1645   bool IsActive() const { return mDocumentContainer && !mRemovedFromDocShell; }
  1647   void RegisterFreezableElement(nsIContent* aContent);
  1648   bool UnregisterFreezableElement(nsIContent* aContent);
  1649   typedef void (* FreezableElementEnumerator)(nsIContent*, void*);
  1650   void EnumerateFreezableElements(FreezableElementEnumerator aEnumerator,
  1651                                   void* aData);
  1653   // Indicates whether mAnimationController has been (lazily) initialized.
  1654   // If this returns true, we're promising that GetAnimationController()
  1655   // will have a non-null return value.
  1656   bool HasAnimationController()  { return !!mAnimationController; }
  1658   // Getter for this document's SMIL Animation Controller. Performs lazy
  1659   // initialization, if this document supports animation and if
  1660   // mAnimationController isn't yet initialized.
  1661   virtual nsSMILAnimationController* GetAnimationController() = 0;
  1663   // Makes the images on this document capable of having their animation
  1664   // active or suspended. An Image will animate as long as at least one of its
  1665   // owning Documents needs it to animate; otherwise it can suspend.
  1666   virtual void SetImagesNeedAnimating(bool aAnimating) = 0;
  1668   enum SuppressionType {
  1669     eAnimationsOnly = 0x1,
  1671     // Note that suppressing events also suppresses animation frames, so
  1672     // there's no need to split out events in its own bitmask.
  1673     eEvents = 0x3,
  1674   };
  1676   /**
  1677    * Prevents user initiated events from being dispatched to the document and
  1678    * subdocuments.
  1679    */
  1680   virtual void SuppressEventHandling(SuppressionType aWhat,
  1681                                      uint32_t aIncrease = 1) = 0;
  1683   /**
  1684    * Unsuppress event handling.
  1685    * @param aFireEvents If true, delayed events (focus/blur) will be fired
  1686    *                    asynchronously.
  1687    */
  1688   virtual void UnsuppressEventHandlingAndFireEvents(SuppressionType aWhat,
  1689                                                     bool aFireEvents) = 0;
  1691   uint32_t EventHandlingSuppressed() const { return mEventsSuppressed; }
  1692   uint32_t AnimationsPaused() const { return mAnimationsPaused; }
  1694   bool IsEventHandlingEnabled() {
  1695     return !EventHandlingSuppressed() && mScriptGlobalObject;
  1698   /**
  1699    * Increment the number of external scripts being evaluated.
  1700    */
  1701   void BeginEvaluatingExternalScript() { ++mExternalScriptsBeingEvaluated; }
  1703   /**
  1704    * Decrement the number of external scripts being evaluated.
  1705    */
  1706   void EndEvaluatingExternalScript() { --mExternalScriptsBeingEvaluated; }
  1708   bool IsDNSPrefetchAllowed() const { return mAllowDNSPrefetch; }
  1710   /**
  1711    * Returns true if this document is allowed to contain XUL element and
  1712    * use non-builtin XBL bindings.
  1713    */
  1714   bool AllowXULXBL() {
  1715     return mAllowXULXBL == eTriTrue ? true :
  1716            mAllowXULXBL == eTriFalse ? false :
  1717            InternalAllowXULXBL();
  1720   void ForceEnableXULXBL() {
  1721     mAllowXULXBL = eTriTrue;
  1724   /**
  1725    * Returns the template content owner document that owns the content of
  1726    * HTMLTemplateElement.
  1727    */
  1728   virtual nsIDocument* GetTemplateContentsOwner() = 0;
  1730   /**
  1731    * true when this document is a static clone of a normal document.
  1732    * For example print preview and printing use static documents.
  1733    */
  1734   bool IsStaticDocument() { return mIsStaticDocument; }
  1736   /**
  1737    * Clones the document and subdocuments and stylesheet etc.
  1738    * @param aCloneContainer The container for the clone document.
  1739    */
  1740   virtual already_AddRefed<nsIDocument>
  1741   CreateStaticClone(nsIDocShell* aCloneContainer);
  1743   /**
  1744    * If this document is a static clone, this returns the original
  1745    * document.
  1746    */
  1747   nsIDocument* GetOriginalDocument()
  1749     MOZ_ASSERT(!mOriginalDocument || !mOriginalDocument->GetOriginalDocument());
  1750     return mOriginalDocument;
  1753   /**
  1754    * Called by nsParser to preload images. Can be removed and code moved
  1755    * to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
  1756    * parser-module is linked with gklayout-module.  aCrossOriginAttr should
  1757    * be a void string if the attr is not present.
  1758    */
  1759   virtual void MaybePreLoadImage(nsIURI* uri,
  1760                                  const nsAString& aCrossOriginAttr) = 0;
  1762   /**
  1763    * Called by nsParser to preload style sheets.  Can also be merged into the
  1764    * parser if and when the parser is merged with libgklayout.  aCrossOriginAttr
  1765    * should be a void string if the attr is not present.
  1766    */
  1767   virtual void PreloadStyle(nsIURI* aURI, const nsAString& aCharset,
  1768                             const nsAString& aCrossOriginAttr) = 0;
  1770   /**
  1771    * Called by the chrome registry to load style sheets.  Can be put
  1772    * back there if and when when that module is merged with libgklayout.
  1774    * This always does a synchronous load.  If aIsAgentSheet is true,
  1775    * it also uses the system principal and enables unsafe rules.
  1776    * DO NOT USE FOR UNTRUSTED CONTENT.
  1777    */
  1778   virtual nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet,
  1779                                        nsCSSStyleSheet** aSheet) = 0;
  1781   /**
  1782    * Returns true if the locale used for the document specifies a direction of
  1783    * right to left. For chrome documents, this comes from the chrome registry.
  1784    * This is used to determine the current state for the :-moz-locale-dir pseudoclass
  1785    * so once can know whether a document is expected to be rendered left-to-right
  1786    * or right-to-left.
  1787    */
  1788   virtual bool IsDocumentRightToLeft() { return false; }
  1790   enum DocumentTheme {
  1791     Doc_Theme_Uninitialized, // not determined yet
  1792     Doc_Theme_None,
  1793     Doc_Theme_Neutral,
  1794     Doc_Theme_Dark,
  1795     Doc_Theme_Bright
  1796   };
  1798   /**
  1799    * Set the document's pending state object (as serialized using structured
  1800    * clone).
  1801    */
  1802   void SetStateObject(nsIStructuredCloneContainer *scContainer);
  1804   /**
  1805    * Returns Doc_Theme_None if there is no lightweight theme specified,
  1806    * Doc_Theme_Dark for a dark theme, Doc_Theme_Bright for a light theme, and
  1807    * Doc_Theme_Neutral for any other theme. This is used to determine the state
  1808    * of the pseudoclasses :-moz-lwtheme and :-moz-lwtheme-text.
  1809    */
  1810   virtual int GetDocumentLWTheme() { return Doc_Theme_None; }
  1812   /**
  1813    * Returns the document state.
  1814    * Document state bits have the form NS_DOCUMENT_STATE_* and are declared in
  1815    * nsIDocument.h.
  1816    */
  1817   virtual mozilla::EventStates GetDocumentState() = 0;
  1819   virtual nsISupports* GetCurrentContentSink() = 0;
  1821   /**
  1822    * Register/Unregister a hostobject uri as being "owned" by this document.
  1823    * I.e. that its lifetime is connected with this document. When the document
  1824    * goes away it should "kill" the uri by calling
  1825    * nsHostObjectProtocolHandler::RemoveDataEntry
  1826    */
  1827   virtual void RegisterHostObjectUri(const nsACString& aUri) = 0;
  1828   virtual void UnregisterHostObjectUri(const nsACString& aUri) = 0;
  1830   virtual void SetScrollToRef(nsIURI *aDocumentURI) = 0;
  1831   virtual void ScrollToRef() = 0;
  1832   virtual void ResetScrolledToRefAlready() = 0;
  1833   virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) = 0;
  1835   /**
  1836    * This method is similar to GetElementById() from nsIDOMDocument but it
  1837    * returns a mozilla::dom::Element instead of a nsIDOMElement.
  1838    * It prevents converting nsIDOMElement to mozilla::dom::Element which is
  1839    * already converted from mozilla::dom::Element.
  1840    */
  1841   virtual Element* GetElementById(const nsAString& aElementId) = 0;
  1843   /**
  1844    * This method returns _all_ the elements in this document which
  1845    * have id aElementId, if there are any.  Otherwise it returns null.
  1846    * The entries of the nsSmallVoidArray are Element*
  1847    */
  1848   virtual const nsSmallVoidArray* GetAllElementsForId(const nsAString& aElementId) const = 0;
  1850   /**
  1851    * Lookup an image element using its associated ID, which is usually provided
  1852    * by |-moz-element()|. Similar to GetElementById, with the difference that
  1853    * elements set using mozSetImageElement have higher priority.
  1854    * @param aId the ID associated the element we want to lookup
  1855    * @return the element associated with |aId|
  1856    */
  1857   virtual Element* LookupImageElement(const nsAString& aElementId) = 0;
  1859   virtual already_AddRefed<mozilla::dom::UndoManager> GetUndoManager() = 0;
  1861   typedef mozilla::dom::CallbackObjectHolder<
  1862     mozilla::dom::FrameRequestCallback,
  1863     nsIFrameRequestCallback> FrameRequestCallbackHolder;
  1864   nsresult ScheduleFrameRequestCallback(const FrameRequestCallbackHolder& aCallback,
  1865                                         int32_t *aHandle);
  1866   void CancelFrameRequestCallback(int32_t aHandle);
  1868   typedef nsTArray<FrameRequestCallbackHolder> FrameRequestCallbackList;
  1869   /**
  1870    * Put this document's frame request callbacks into the provided
  1871    * list, and forget about them.
  1872    */
  1873   void TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks);
  1875   // This returns true when the document tree is being teared down.
  1876   bool InUnlinkOrDeletion() { return mInUnlinkOrDeletion; }
  1878   /*
  1879    * Image Tracking
  1881    * Style and content images register their imgIRequests with their document
  1882    * so that the document can efficiently tell all descendant images when they
  1883    * are and are not visible. When an image is on-screen, we want to call
  1884    * LockImage() on it so that it doesn't do things like discarding frame data
  1885    * to save memory. The PresShell informs the document whether its images
  1886    * should be locked or not via SetImageLockingState().
  1888    * See bug 512260.
  1889    */
  1891   // Add/Remove images from the document image tracker
  1892   virtual nsresult AddImage(imgIRequest* aImage) = 0;
  1893   // If the REQUEST_DISCARD flag is passed then if the lock count is zero we
  1894   // will request the image be discarded now (instead of waiting).
  1895   enum { REQUEST_DISCARD = 0x1 };
  1896   virtual nsresult RemoveImage(imgIRequest* aImage, uint32_t aFlags = 0) = 0;
  1898   // Makes the images on this document locked/unlocked. By default, the locking
  1899   // state is unlocked/false.
  1900   virtual nsresult SetImageLockingState(bool aLocked) = 0;
  1902   virtual nsresult AddPlugin(nsIObjectLoadingContent* aPlugin) = 0;
  1903   virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) = 0;
  1904   virtual void GetPlugins(nsTArray<nsIObjectLoadingContent*>& aPlugins) = 0;
  1906   virtual nsresult GetStateObject(nsIVariant** aResult) = 0;
  1908   virtual nsDOMNavigationTiming* GetNavigationTiming() const = 0;
  1910   virtual nsresult SetNavigationTiming(nsDOMNavigationTiming* aTiming) = 0;
  1912   virtual Element* FindImageMap(const nsAString& aNormalizedMapName) = 0;
  1914   // Add aLink to the set of links that need their status resolved. 
  1915   void RegisterPendingLinkUpdate(mozilla::dom::Link* aLink);
  1917   // Remove aLink from the set of links that need their status resolved.
  1918   // This function must be called when links are removed from the document.
  1919   void UnregisterPendingLinkUpdate(mozilla::dom::Link* aElement);
  1921   // Update state on links in mLinksToUpdate.  This function must
  1922   // be called prior to selector matching.
  1923   void FlushPendingLinkUpdates();
  1925 #define DEPRECATED_OPERATION(_op) e##_op,
  1926   enum DeprecatedOperations {
  1927 #include "nsDeprecatedOperationList.h"
  1928     eDeprecatedOperationCount
  1929   };
  1930 #undef DEPRECATED_OPERATION
  1931   void WarnOnceAbout(DeprecatedOperations aOperation, bool asError = false);
  1933   virtual void PostVisibilityUpdateEvent() = 0;
  1935   bool IsSyntheticDocument() const { return mIsSyntheticDocument; }
  1937   void SetNeedLayoutFlush() {
  1938     mNeedLayoutFlush = true;
  1939     if (mDisplayDocument) {
  1940       mDisplayDocument->SetNeedLayoutFlush();
  1944   void SetNeedStyleFlush() {
  1945     mNeedStyleFlush = true;
  1946     if (mDisplayDocument) {
  1947       mDisplayDocument->SetNeedStyleFlush();
  1951   // Note: nsIDocument is a sub-class of nsINode, which has a
  1952   // SizeOfExcludingThis function.  However, because nsIDocument objects can
  1953   // only appear at the top of the DOM tree, we have a specialized measurement
  1954   // function which returns multiple sizes.
  1955   virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
  1956   // DocAddSizeOfIncludingThis doesn't need to be overridden by sub-classes
  1957   // because nsIDocument inherits from nsINode;  see the comment above the
  1958   // declaration of nsINode::SizeOfIncludingThis.
  1959   virtual void DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const;
  1961   bool MayHaveDOMMutationObservers()
  1963     return mMayHaveDOMMutationObservers;
  1966   void SetMayHaveDOMMutationObservers()
  1968     mMayHaveDOMMutationObservers = true;
  1971   bool IsInSyncOperation()
  1973     return mInSyncOperationCount != 0;
  1976   void SetIsInSyncOperation(bool aSync)
  1978     if (aSync) {
  1979       ++mInSyncOperationCount;
  1980     } else {
  1981       --mInSyncOperationCount;
  1985   bool CreatingStaticClone() const
  1987     return mCreatingStaticClone;
  1990   /**
  1991    * Creates a new element in the HTML namespace with a local name given by
  1992    * aTag.
  1993    */
  1994   already_AddRefed<Element> CreateHTMLElement(nsIAtom* aTag);
  1996   // WebIDL API
  1997   nsIGlobalObject* GetParentObject() const
  1999     return GetScopeObject();
  2001   static already_AddRefed<nsIDocument>
  2002     Constructor(const GlobalObject& aGlobal,
  2003                 mozilla::ErrorResult& rv);
  2004   virtual mozilla::dom::DOMImplementation*
  2005     GetImplementation(mozilla::ErrorResult& rv) = 0;
  2006   void GetURL(nsString& retval) const;
  2007   void GetDocumentURI(nsString& retval) const;
  2008   // Return the URI for the document.
  2009   // The returned value may differ if the document is loaded via XHR, and
  2010   // when accessed from chrome privileged script and
  2011   // from content privileged script for compatibility.
  2012   void GetDocumentURIFromJS(nsString& aDocumentURI) const;
  2013   void GetCompatMode(nsString& retval) const;
  2014   void GetCharacterSet(nsAString& retval) const;
  2015   // Skip GetContentType, because our NS_IMETHOD version above works fine here.
  2016   // GetDoctype defined above
  2017   Element* GetDocumentElement() const
  2019     return GetRootElement();
  2022   enum ElementCallbackType {
  2023     eCreated,
  2024     eAttached,
  2025     eDetached,
  2026     eAttributeChanged
  2027   };
  2029   /**
  2030    * Registers an unresolved custom element that is a candidate for
  2031    * upgrade when the definition is registered via registerElement.
  2032    * |aTypeName| is the name of the custom element type, if it is not
  2033    * provided, then element name is used. |aTypeName| should be provided
  2034    * when registering a custom element that extends an existing
  2035    * element. e.g. <button is="x-button">.
  2036    */
  2037   virtual nsresult RegisterUnresolvedElement(Element* aElement,
  2038                                              nsIAtom* aTypeName = nullptr) = 0;
  2039   virtual void EnqueueLifecycleCallback(ElementCallbackType aType,
  2040                                         Element* aCustomElement,
  2041                                         mozilla::dom::LifecycleCallbackArgs* aArgs = nullptr,
  2042                                         mozilla::dom::CustomElementDefinition* aDefinition = nullptr) = 0;
  2043   virtual void SwizzleCustomElement(Element* aElement,
  2044                                     const nsAString& aTypeExtension,
  2045                                     uint32_t aNamespaceID,
  2046                                     mozilla::ErrorResult& rv) = 0;
  2047   virtual void
  2048     RegisterElement(JSContext* aCx, const nsAString& aName,
  2049                     const mozilla::dom::ElementRegistrationOptions& aOptions,
  2050                     JS::MutableHandle<JSObject*> aRetval,
  2051                     mozilla::ErrorResult& rv) = 0;
  2053   /**
  2054    * In some cases, new document instances must be associated with
  2055    * an existing web components custom element registry as specified.
  2056    */
  2057   virtual void UseRegistryFromDocument(nsIDocument* aDocument) = 0;
  2059   already_AddRefed<nsContentList>
  2060   GetElementsByTagName(const nsAString& aTagName)
  2062     return NS_GetContentList(this, kNameSpaceID_Unknown, aTagName);
  2064   already_AddRefed<nsContentList>
  2065     GetElementsByTagNameNS(const nsAString& aNamespaceURI,
  2066                            const nsAString& aLocalName,
  2067                            mozilla::ErrorResult& aResult);
  2068   already_AddRefed<nsContentList>
  2069     GetElementsByClassName(const nsAString& aClasses);
  2070   // GetElementById defined above
  2071   already_AddRefed<Element> CreateElement(const nsAString& aTagName,
  2072                                           mozilla::ErrorResult& rv);
  2073   already_AddRefed<Element> CreateElementNS(const nsAString& aNamespaceURI,
  2074                                             const nsAString& aQualifiedName,
  2075                                             mozilla::ErrorResult& rv);
  2076   virtual already_AddRefed<Element> CreateElement(const nsAString& aTagName,
  2077                                                   const nsAString& aTypeExtension,
  2078                                                   mozilla::ErrorResult& rv) = 0;
  2079   virtual already_AddRefed<Element> CreateElementNS(const nsAString& aNamespaceURI,
  2080                                                     const nsAString& aQualifiedName,
  2081                                                     const nsAString& aTypeExtension,
  2082                                                     mozilla::ErrorResult& rv) = 0;
  2083   already_AddRefed<mozilla::dom::DocumentFragment>
  2084     CreateDocumentFragment() const;
  2085   already_AddRefed<nsTextNode> CreateTextNode(const nsAString& aData) const;
  2086   already_AddRefed<mozilla::dom::Comment>
  2087     CreateComment(const nsAString& aData) const;
  2088   already_AddRefed<mozilla::dom::ProcessingInstruction>
  2089     CreateProcessingInstruction(const nsAString& target, const nsAString& data,
  2090                                 mozilla::ErrorResult& rv) const;
  2091   already_AddRefed<nsINode>
  2092     ImportNode(nsINode& aNode, bool aDeep, mozilla::ErrorResult& rv) const;
  2093   nsINode* AdoptNode(nsINode& aNode, mozilla::ErrorResult& rv);
  2094   already_AddRefed<mozilla::dom::Event>
  2095     CreateEvent(const nsAString& aEventType, mozilla::ErrorResult& rv) const;
  2096   already_AddRefed<nsRange> CreateRange(mozilla::ErrorResult& rv);
  2097   already_AddRefed<mozilla::dom::NodeIterator>
  2098     CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
  2099                        mozilla::dom::NodeFilter* aFilter,
  2100                        mozilla::ErrorResult& rv) const;
  2101   already_AddRefed<mozilla::dom::NodeIterator>
  2102     CreateNodeIterator(nsINode& aRoot, uint32_t aWhatToShow,
  2103                        const mozilla::dom::NodeFilterHolder& aFilter,
  2104                        mozilla::ErrorResult& rv) const;
  2105   already_AddRefed<mozilla::dom::TreeWalker>
  2106     CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
  2107                      mozilla::dom::NodeFilter* aFilter, mozilla::ErrorResult& rv) const;
  2108   already_AddRefed<mozilla::dom::TreeWalker>
  2109     CreateTreeWalker(nsINode& aRoot, uint32_t aWhatToShow,
  2110                      const mozilla::dom::NodeFilterHolder& aFilter,
  2111                      mozilla::ErrorResult& rv) const;
  2113   // Deprecated WebIDL bits
  2114   already_AddRefed<mozilla::dom::CDATASection>
  2115     CreateCDATASection(const nsAString& aData, mozilla::ErrorResult& rv);
  2116   already_AddRefed<mozilla::dom::Attr>
  2117     CreateAttribute(const nsAString& aName, mozilla::ErrorResult& rv);
  2118   already_AddRefed<mozilla::dom::Attr>
  2119     CreateAttributeNS(const nsAString& aNamespaceURI,
  2120                       const nsAString& aQualifiedName,
  2121                       mozilla::ErrorResult& rv);
  2122   void GetInputEncoding(nsAString& aInputEncoding);
  2123   already_AddRefed<nsIDOMLocation> GetLocation() const;
  2124   void GetReferrer(nsAString& aReferrer) const;
  2125   void GetLastModified(nsAString& aLastModified) const;
  2126   void GetReadyState(nsAString& aReadyState) const;
  2127   // Not const because otherwise the compiler can't figure out whether to call
  2128   // this GetTitle or the nsAString version from non-const methods, since
  2129   // neither is an exact match.
  2130   virtual void GetTitle(nsString& aTitle) = 0;
  2131   virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) = 0;
  2132   void GetDir(nsAString& aDirection) const;
  2133   void SetDir(const nsAString& aDirection);
  2134   nsIDOMWindow* GetDefaultView() const
  2136     return GetWindow();
  2138   Element* GetActiveElement();
  2139   bool HasFocus(mozilla::ErrorResult& rv) const;
  2140   // Event handlers are all on nsINode already
  2141   bool MozSyntheticDocument() const
  2143     return IsSyntheticDocument();
  2145   Element* GetCurrentScript();
  2146   void ReleaseCapture() const;
  2147   virtual void MozSetImageElement(const nsAString& aImageElementId,
  2148                                   Element* aElement) = 0;
  2149   nsIURI* GetDocumentURIObject() const;
  2150   // Not const because all the full-screen goop is not const
  2151   virtual bool MozFullScreenEnabled() = 0;
  2152   virtual Element* GetMozFullScreenElement(mozilla::ErrorResult& rv) = 0;
  2153   bool MozFullScreen()
  2155     return IsFullScreenDoc();
  2157   void MozCancelFullScreen();
  2158   Element* GetMozPointerLockElement();
  2159   void MozExitPointerLock()
  2161     UnlockPointer(this);
  2163   bool Hidden() const
  2165     return mVisibilityState != mozilla::dom::VisibilityState::Visible;
  2167   bool MozHidden() // Not const because of WarnOnceAbout
  2169     WarnOnceAbout(ePrefixedVisibilityAPI);
  2170     return Hidden();
  2172   mozilla::dom::VisibilityState VisibilityState()
  2174     return mVisibilityState;
  2176   mozilla::dom::VisibilityState MozVisibilityState()
  2178     WarnOnceAbout(ePrefixedVisibilityAPI);
  2179     return VisibilityState();
  2181   virtual mozilla::dom::StyleSheetList* StyleSheets() = 0;
  2182   void GetSelectedStyleSheetSet(nsAString& aSheetSet);
  2183   virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) = 0;
  2184   virtual void GetLastStyleSheetSet(nsString& aSheetSet) = 0;
  2185   void GetPreferredStyleSheetSet(nsAString& aSheetSet);
  2186   virtual mozilla::dom::DOMStringList* StyleSheetSets() = 0;
  2187   virtual void EnableStyleSheetsForSet(const nsAString& aSheetSet) = 0;
  2188   Element* ElementFromPoint(float aX, float aY);
  2190   /**
  2191    * Retrieve the location of the caret position (DOM node and character
  2192    * offset within that node), given a point.
  2194    * @param aX Horizontal point at which to determine the caret position, in
  2195    *           page coordinates.
  2196    * @param aY Vertical point at which to determine the caret position, in
  2197    *           page coordinates.
  2198    */
  2199   already_AddRefed<nsDOMCaretPosition>
  2200     CaretPositionFromPoint(float aX, float aY);
  2202   // QuerySelector and QuerySelectorAll already defined on nsINode
  2203   nsINodeList* GetAnonymousNodes(Element& aElement);
  2204   Element* GetAnonymousElementByAttribute(Element& aElement,
  2205                                           const nsAString& aAttrName,
  2206                                           const nsAString& aAttrValue);
  2207   Element* GetBindingParent(nsINode& aNode);
  2208   void LoadBindingDocument(const nsAString& aURI, mozilla::ErrorResult& rv);
  2209   already_AddRefed<nsIDOMXPathExpression>
  2210     CreateExpression(const nsAString& aExpression,
  2211                      nsIDOMXPathNSResolver* aResolver,
  2212                      mozilla::ErrorResult& rv);
  2213   already_AddRefed<nsIDOMXPathNSResolver>
  2214     CreateNSResolver(nsINode* aNodeResolver, mozilla::ErrorResult& rv);
  2215   already_AddRefed<nsISupports>
  2216     Evaluate(const nsAString& aExpression, nsINode* aContextNode,
  2217              nsIDOMXPathNSResolver* aResolver, uint16_t aType,
  2218              nsISupports* aResult, mozilla::ErrorResult& rv);
  2219   // Touch event handlers already on nsINode
  2220   already_AddRefed<mozilla::dom::Touch>
  2221     CreateTouch(nsIDOMWindow* aView, mozilla::dom::EventTarget* aTarget,
  2222                 int32_t aIdentifier, int32_t aPageX, int32_t aPageY,
  2223                 int32_t aScreenX, int32_t aScreenY, int32_t aClientX,
  2224                 int32_t aClientY, int32_t aRadiusX, int32_t aRadiusY,
  2225                 float aRotationAngle, float aForce);
  2226   already_AddRefed<mozilla::dom::TouchList> CreateTouchList();
  2227   already_AddRefed<mozilla::dom::TouchList>
  2228     CreateTouchList(mozilla::dom::Touch& aTouch,
  2229                     const mozilla::dom::Sequence<mozilla::dom::OwningNonNull<mozilla::dom::Touch> >& aTouches);
  2230   already_AddRefed<mozilla::dom::TouchList>
  2231     CreateTouchList(const mozilla::dom::Sequence<mozilla::dom::OwningNonNull<mozilla::dom::Touch> >& aTouches);
  2233   void SetStyleSheetChangeEventsEnabled(bool aValue)
  2235     mStyleSheetChangeEventsEnabled = aValue;
  2238   bool StyleSheetChangeEventsEnabled() const
  2240     return mStyleSheetChangeEventsEnabled;
  2243   void ObsoleteSheet(nsIURI *aSheetURI, mozilla::ErrorResult& rv);
  2245   void ObsoleteSheet(const nsAString& aSheetURI, mozilla::ErrorResult& rv);
  2247   // ParentNode
  2248   nsIHTMLCollection* Children();
  2249   uint32_t ChildElementCount();
  2251   virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; }
  2253   virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
  2255 private:
  2256   uint64_t mWarnedAbout;
  2257   SelectorCache mSelectorCache;
  2259 protected:
  2260   ~nsIDocument();
  2261   nsPropertyTable* GetExtraPropertyTable(uint16_t aCategory);
  2263   // Never ever call this. Only call GetWindow!
  2264   virtual nsPIDOMWindow *GetWindowInternal() const = 0;
  2266   // Never ever call this. Only call GetScriptHandlingObject!
  2267   virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() const = 0;
  2269   // Never ever call this. Only call AllowXULXBL!
  2270   virtual bool InternalAllowXULXBL() = 0;
  2272   /**
  2273    * These methods should be called before and after dispatching
  2274    * a mutation event.
  2275    * To make this easy and painless, use the mozAutoSubtreeModified helper class.
  2276    */
  2277   virtual void WillDispatchMutationEvent(nsINode* aTarget) = 0;
  2278   virtual void MutationEventDispatched(nsINode* aTarget) = 0;
  2279   friend class mozAutoSubtreeModified;
  2281   virtual Element* GetNameSpaceElement()
  2283     return GetRootElement();
  2286   void SetContentTypeInternal(const nsACString& aType);
  2288   nsCString GetContentTypeInternal() const
  2290     return mContentType;
  2293   mozilla::dom::XPathEvaluator* XPathEvaluator();
  2295   nsCString mReferrer;
  2296   nsString mLastModified;
  2298   nsCOMPtr<nsIURI> mDocumentURI;
  2299   nsCOMPtr<nsIURI> mOriginalURI;
  2300   nsCOMPtr<nsIURI> mChromeXHRDocURI;
  2301   nsCOMPtr<nsIURI> mDocumentBaseURI;
  2302   nsCOMPtr<nsIURI> mChromeXHRDocBaseURI;
  2304   nsWeakPtr mDocumentLoadGroup;
  2306   mozilla::WeakPtr<nsDocShell> mDocumentContainer;
  2308   nsCString mCharacterSet;
  2309   int32_t mCharacterSetSource;
  2311   // This is just a weak pointer; the parent document owns its children.
  2312   nsIDocument* mParentDocument;
  2314   // A reference to the element last returned from GetRootElement().
  2315   mozilla::dom::Element* mCachedRootElement;
  2317   // This is a weak reference, but we hold a strong reference to mNodeInfo,
  2318   // which in turn holds a strong reference to this mNodeInfoManager.
  2319   nsNodeInfoManager* mNodeInfoManager;
  2320   nsRefPtr<mozilla::css::Loader> mCSSLoader;
  2321   nsRefPtr<mozilla::css::ImageLoader> mStyleImageLoader;
  2322   nsRefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
  2323   nsRefPtr<nsHTMLCSSStyleSheet> mStyleAttrStyleSheet;
  2325   // The set of all object, embed, applet, video and audio elements for
  2326   // which this is the owner document. (They might not be in the document.)
  2327   // These are non-owning pointers, the elements are responsible for removing
  2328   // themselves when they go away.
  2329   nsAutoPtr<nsTHashtable<nsPtrHashKey<nsIContent> > > mFreezableElements;
  2331   // The set of all links that need their status resolved.  Links must add themselves
  2332   // to this set by calling RegisterPendingLinkUpdate when added to a document and must
  2333   // remove themselves by calling UnregisterPendingLinkUpdate when removed from a document.
  2334   nsTHashtable<nsPtrHashKey<mozilla::dom::Link> > mLinksToUpdate;
  2336   // SMIL Animation Controller, lazily-initialized in GetAnimationController
  2337   nsRefPtr<nsSMILAnimationController> mAnimationController;
  2339   // Table of element properties for this document.
  2340   nsPropertyTable mPropertyTable;
  2341   nsTArray<nsAutoPtr<nsPropertyTable> > mExtraPropertyTables;
  2343   // Our cached .children collection
  2344   nsCOMPtr<nsIHTMLCollection> mChildrenCollection;
  2346   // Compatibility mode
  2347   nsCompatibility mCompatMode;
  2349   // Our readyState
  2350   ReadyState mReadyState;
  2352   // Our visibility state
  2353   mozilla::dom::VisibilityState mVisibilityState;
  2355   // True if BIDI is enabled.
  2356   bool mBidiEnabled;
  2357   // True if a MathML element has ever been owned by this document.
  2358   bool mMathMLEnabled;
  2360   // True if this document is the initial document for a window.  This should
  2361   // basically be true only for documents that exist in newly-opened windows or
  2362   // documents created to satisfy a GetDocument() on a window when there's no
  2363   // document in it.
  2364   bool mIsInitialDocumentInWindow;
  2366   bool mIsRegularHTML;
  2367   bool mIsXUL;
  2369   enum {
  2370     eTriUnset = 0,
  2371     eTriFalse,
  2372     eTriTrue
  2373   } mAllowXULXBL;
  2375   // True if we're loaded as data and therefor has any dangerous stuff, such
  2376   // as scripts and plugins, disabled.
  2377   bool mLoadedAsData;
  2379   // This flag is only set in XMLDocument, for e.g. documents used in XBL. We
  2380   // don't want animations to play in such documents, so we need to store the
  2381   // flag here so that we can check it in nsDocument::GetAnimationController.
  2382   bool mLoadedAsInteractiveData;
  2384   // If true, whoever is creating the document has gotten it to the
  2385   // point where it's safe to start layout on it.
  2386   bool mMayStartLayout;
  2388   // True iff we've ever fired a DOMTitleChanged event for this document
  2389   bool mHaveFiredTitleChange;
  2391   // True iff IsShowing() should be returning true
  2392   bool mIsShowing;
  2394   // True iff the document "page" is not hidden (i.e. currently in the
  2395   // bfcache)
  2396   bool mVisible;
  2398   // True if our content viewer has been removed from the docshell
  2399   // (it may still be displayed, but in zombie state). Form control data
  2400   // has been saved.
  2401   bool mRemovedFromDocShell;
  2403   // True iff DNS prefetch is allowed for this document.  Note that if the
  2404   // document has no window, DNS prefetch won't be performed no matter what.
  2405   bool mAllowDNSPrefetch;
  2407   // True when this document is a static clone of a normal document
  2408   bool mIsStaticDocument;
  2410   // True while this document is being cloned to a static document.
  2411   bool mCreatingStaticClone;
  2413   // True iff the document is being unlinked or deleted.
  2414   bool mInUnlinkOrDeletion;
  2416   // True if document has ever had script handling object.
  2417   bool mHasHadScriptHandlingObject;
  2419   // True if we're an SVG document being used as an image.
  2420   bool mIsBeingUsedAsImage;
  2422   // True is this document is synthetic : stand alone image, video, audio
  2423   // file, etc.
  2424   bool mIsSyntheticDocument;
  2426   // True if this document has links whose state needs updating
  2427   bool mHasLinksToUpdate;
  2429   // True if a layout flush might not be a no-op
  2430   bool mNeedLayoutFlush;
  2432   // True if a style flush might not be a no-op
  2433   bool mNeedStyleFlush;
  2435   // True if a DOMMutationObserver is perhaps attached to a node in the document.
  2436   bool mMayHaveDOMMutationObservers;
  2438   // True if a document has loaded Mixed Active Script (see nsMixedContentBlocker.cpp)
  2439   bool mHasMixedActiveContentLoaded;
  2441   // True if a document has blocked Mixed Active Script (see nsMixedContentBlocker.cpp)
  2442   bool mHasMixedActiveContentBlocked;
  2444   // True if a document has loaded Mixed Display/Passive Content (see nsMixedContentBlocker.cpp)
  2445   bool mHasMixedDisplayContentLoaded;
  2447   // True if a document has blocked Mixed Display/Passive Content (see nsMixedContentBlocker.cpp)
  2448   bool mHasMixedDisplayContentBlocked;
  2450   // True if DisallowBFCaching has been called on this document.
  2451   bool mBFCacheDisallowed;
  2453   // If true, we have an input encoding.  If this is false, then the
  2454   // document was created entirely in memory
  2455   bool mHaveInputEncoding;
  2457   bool mHasHadDefaultView;
  2459   // Whether style sheet change events will be dispatched for this document
  2460   bool mStyleSheetChangeEventsEnabled;
  2462   // Whether the document was created by a srcdoc iframe.
  2463   bool mIsSrcdocDocument;
  2465   // Records whether we've done a document.open. If this is true, it's possible
  2466   // for nodes from this document to have outdated wrappers in their wrapper
  2467   // caches.
  2468   bool mDidDocumentOpen;
  2470 #ifdef DEBUG
  2471   /**
  2472    * This is true while FlushPendingLinkUpdates executes.  Calls to
  2473    * [Un]RegisterPendingLinkUpdate will assert when this is true.
  2474    */
  2475   bool mIsLinkUpdateRegistrationsForbidden;
  2476 #endif
  2478   // The document's script global object, the object from which the
  2479   // document can get its script context and scope. This is the
  2480   // *inner* window object.
  2481   nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
  2483   // If mIsStaticDocument is true, mOriginalDocument points to the original
  2484   // document.
  2485   nsCOMPtr<nsIDocument> mOriginalDocument;
  2487   // The bidi options for this document.  What this bitfield means is
  2488   // defined in nsBidiUtils.h
  2489   uint32_t mBidiOptions;
  2491   // The sandbox flags on the document. These reflect the value of the sandbox attribute of the
  2492   // associated IFRAME or CSP-protectable content, if existent. These are set at load time and
  2493   // are immutable - see nsSandboxFlags.h for the possible flags.
  2494   uint32_t mSandboxFlags;
  2496   nsCString mContentLanguage;
  2498   // The channel that got passed to nsDocument::StartDocumentLoad(), if any.
  2499   nsCOMPtr<nsIChannel> mChannel;
  2500 private:
  2501   nsCString mContentType;
  2502 protected:
  2504   // The document's security info
  2505   nsCOMPtr<nsISupports> mSecurityInfo;
  2507   // if this document is part of a multipart document,
  2508   // the ID can be used to distinguish it from the other parts.
  2509   uint32_t mPartID;
  2511   // Cycle collector generation in which we're certain that this document
  2512   // won't be collected
  2513   uint32_t mMarkedCCGeneration;
  2515   nsIPresShell* mPresShell;
  2517   nsCOMArray<nsINode> mSubtreeModifiedTargets;
  2518   uint32_t            mSubtreeModifiedDepth;
  2520   // If we're an external resource document, this will be non-null and will
  2521   // point to our "display document": the one that all resource lookups should
  2522   // go to.
  2523   nsCOMPtr<nsIDocument> mDisplayDocument;
  2525   uint32_t mEventsSuppressed;
  2527   uint32_t mAnimationsPaused;
  2529   /**
  2530    * The number number of external scripts (ones with the src attribute) that
  2531    * have this document as their owner and that are being evaluated right now.
  2532    */
  2533   uint32_t mExternalScriptsBeingEvaluated;
  2535   /**
  2536    * The current frame request callback handle
  2537    */
  2538   int32_t mFrameRequestCallbackCounter;
  2540   // Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow,
  2541   // updated on every set of mSecriptGlobalObject.
  2542   nsPIDOMWindow *mWindow;
  2544   nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
  2546   struct FrameRequest;
  2548   nsTArray<FrameRequest> mFrameRequestCallbacks;
  2550   // This object allows us to evict ourself from the back/forward cache.  The
  2551   // pointer is non-null iff we're currently in the bfcache.
  2552   nsIBFCacheEntry *mBFCacheEntry;
  2554   // Our base target.
  2555   nsString mBaseTarget;
  2557   nsCOMPtr<nsIStructuredCloneContainer> mStateObjectContainer;
  2558   nsCOMPtr<nsIVariant> mStateObjectCached;
  2560   uint8_t mDefaultElementType;
  2562   uint32_t mInSyncOperationCount;
  2564   nsRefPtr<mozilla::dom::XPathEvaluator> mXPathEvaluator;
  2566   uint32_t mBlockDOMContentLoaded;
  2567   bool mDidFireDOMContentLoaded:1;
  2568 };
  2570 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID)
  2572 /**
  2573  * mozAutoSubtreeModified batches DOM mutations so that a DOMSubtreeModified
  2574  * event is dispatched, if necessary, when the outermost mozAutoSubtreeModified
  2575  * object is deleted.
  2576  */
  2577 class MOZ_STACK_CLASS mozAutoSubtreeModified
  2579 public:
  2580   /**
  2581    * @param aSubTreeOwner The document in which a subtree will be modified.
  2582    * @param aTarget       The target of the possible DOMSubtreeModified event.
  2583    *                      Can be nullptr, in which case mozAutoSubtreeModified
  2584    *                      is just used to batch DOM mutations.
  2585    */
  2586   mozAutoSubtreeModified(nsIDocument* aSubtreeOwner, nsINode* aTarget)
  2588     UpdateTarget(aSubtreeOwner, aTarget);
  2591   ~mozAutoSubtreeModified()
  2593     UpdateTarget(nullptr, nullptr);
  2596   void UpdateTarget(nsIDocument* aSubtreeOwner, nsINode* aTarget)
  2598     if (mSubtreeOwner) {
  2599       mSubtreeOwner->MutationEventDispatched(mTarget);
  2602     mTarget = aTarget;
  2603     mSubtreeOwner = aSubtreeOwner;
  2604     if (mSubtreeOwner) {
  2605       mSubtreeOwner->WillDispatchMutationEvent(mTarget);
  2609 private:
  2610   nsCOMPtr<nsINode>     mTarget;
  2611   nsCOMPtr<nsIDocument> mSubtreeOwner;
  2612 };
  2614 class MOZ_STACK_CLASS nsAutoSyncOperation
  2616 public:
  2617   nsAutoSyncOperation(nsIDocument* aDocument);
  2618   ~nsAutoSyncOperation();
  2619 private:
  2620   nsCOMArray<nsIDocument> mDocuments;
  2621   uint32_t                mMicroTaskLevel;
  2622 };
  2624 // XXX These belong somewhere else
  2625 nsresult
  2626 NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
  2628 nsresult
  2629 NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
  2631 nsresult
  2632 NS_NewSVGDocument(nsIDocument** aInstancePtrResult);
  2634 nsresult
  2635 NS_NewImageDocument(nsIDocument** aInstancePtrResult);
  2637 nsresult
  2638 NS_NewVideoDocument(nsIDocument** aInstancePtrResult);
  2640 // Note: it's the caller's responsibility to create or get aPrincipal as needed
  2641 // -- this method will not attempt to get a principal based on aDocumentURI.
  2642 // Also, both aDocumentURI and aBaseURI must not be null.
  2643 nsresult
  2644 NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
  2645                   const nsAString& aNamespaceURI, 
  2646                   const nsAString& aQualifiedName, 
  2647                   nsIDOMDocumentType* aDoctype,
  2648                   nsIURI* aDocumentURI,
  2649                   nsIURI* aBaseURI,
  2650                   nsIPrincipal* aPrincipal,
  2651                   bool aLoadedAsData,
  2652                   nsIGlobalObject* aEventObject,
  2653                   DocumentFlavor aFlavor);
  2655 // This is used only for xbl documents created from the startup cache.
  2656 // Non-cached documents are created in the same manner as xml documents.
  2657 nsresult
  2658 NS_NewXBLDocument(nsIDOMDocument** aInstancePtrResult,
  2659                   nsIURI* aDocumentURI,
  2660                   nsIURI* aBaseURI,
  2661                   nsIPrincipal* aPrincipal);
  2663 nsresult
  2664 NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
  2666 inline nsIDocument*
  2667 nsINode::GetOwnerDocument() const
  2669   nsIDocument* ownerDoc = OwnerDoc();
  2671   return ownerDoc != this ? ownerDoc : nullptr;
  2674 inline nsINode*
  2675 nsINode::OwnerDocAsNode() const
  2677   return OwnerDoc();
  2680 inline mozilla::dom::ParentObject
  2681 nsINode::GetParentObject() const
  2683   return GetParentObjectInternal(OwnerDoc());
  2686 #endif /* nsIDocument_h___ */

mercurial