content/base/public/nsIDocument.h

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial