1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* 8 * Base class for all our document implementations. 9 */ 10 11 #ifndef nsDocument_h___ 12 #define nsDocument_h___ 13 14 #include "nsIDocument.h" 15 16 #include "nsCOMPtr.h" 17 #include "nsAutoPtr.h" 18 #include "nsCRT.h" 19 #include "nsWeakReference.h" 20 #include "nsWeakPtr.h" 21 #include "nsTArray.h" 22 #include "nsIdentifierMapEntry.h" 23 #include "nsIDOMDocument.h" 24 #include "nsStubDocumentObserver.h" 25 #include "nsIScriptGlobalObject.h" 26 #include "nsIContent.h" 27 #include "nsIPrincipal.h" 28 #include "nsIParser.h" 29 #include "nsBindingManager.h" 30 #include "nsRefPtrHashtable.h" 31 #include "nsJSThingHashtable.h" 32 #include "nsIScriptObjectPrincipal.h" 33 #include "nsIURI.h" 34 #include "nsIRadioGroupContainer.h" 35 #include "nsILayoutHistoryState.h" 36 #include "nsIRequest.h" 37 #include "nsILoadGroup.h" 38 #include "nsTObserverArray.h" 39 #include "nsStubMutationObserver.h" 40 #include "nsIChannel.h" 41 #include "nsCycleCollectionParticipant.h" 42 #include "nsContentList.h" 43 #include "nsGkAtoms.h" 44 #include "nsIApplicationCache.h" 45 #include "nsIApplicationCacheContainer.h" 46 #include "mozilla/StyleSetHandle.h" 47 #include "PLDHashTable.h" 48 #include "nsAttrAndChildArray.h" 49 #include "nsDOMAttributeMap.h" 50 #include "nsIContentViewer.h" 51 #include "nsIInterfaceRequestor.h" 52 #include "nsILoadContext.h" 53 #include "nsIProgressEventSink.h" 54 #include "nsISecurityEventSink.h" 55 #include "nsIChannelEventSink.h" 56 #include "imgIRequest.h" 57 #include "mozilla/EventListenerManager.h" 58 #include "mozilla/EventStates.h" 59 #include "mozilla/MemoryReporting.h" 60 #include "mozilla/PendingAnimationTracker.h" 61 #include "mozilla/dom/BoxObject.h" 62 #include "mozilla/dom/DOMImplementation.h" 63 #include "mozilla/dom/ScriptLoader.h" 64 #include "mozilla/dom/StyleSheetList.h" 65 #include "nsDataHashtable.h" 66 #include "mozilla/TimeStamp.h" 67 #include "mozilla/Attributes.h" 68 #include "jsfriendapi.h" 69 #include "mozilla/LinkedList.h" 70 #include "CustomElementRegistry.h" 71 #include "mozilla/dom/Performance.h" 72 #include "mozilla/Maybe.h" 73 #include "nsIURIClassifier.h" 74 75 #define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0) 76 #define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1) 77 #define XML_DECLARATION_BITS_STANDALONE_EXISTS (1 << 2) 78 #define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3) 79 80 class nsDOMStyleSheetSetList; 81 class nsDocument; 82 class nsIRadioVisitor; 83 class nsIFormControl; 84 struct nsRadioGroupStruct; 85 class nsOnloadBlocker; 86 class nsUnblockOnloadEvent; 87 class nsDOMNavigationTiming; 88 class nsWindowSizes; 89 class nsHtml5TreeOpExecutor; 90 class nsDocumentOnStack; 91 class nsISecurityConsoleMessage; 92 93 namespace mozilla { 94 class EventChainPreVisitor; 95 namespace dom { 96 class ImageTracker; 97 struct LifecycleCallbacks; 98 class CallbackFunction; 99 class DOMIntersectionObserver; 100 class Performance; 101 102 struct FullscreenRequest : public LinkedListElement<FullscreenRequest> { 103 explicit FullscreenRequest(Element* aElement); 104 FullscreenRequest(const FullscreenRequest&) = delete; 105 ~FullscreenRequest(); 106 GetElementFullscreenRequest107 Element* GetElement() const { return mElement; } GetDocumentFullscreenRequest108 nsDocument* GetDocument() const { return mDocument; } 109 110 private: 111 RefPtr<Element> mElement; 112 RefPtr<nsDocument> mDocument; 113 114 public: 115 // This value should be true if the fullscreen request is 116 // originated from chrome code. 117 bool mIsCallerChrome = false; 118 // This value denotes whether we should trigger a NewOrigin event if 119 // requesting fullscreen in its document causes the origin which is 120 // fullscreen to change. We may want *not* to trigger that event if 121 // we're calling RequestFullScreen() as part of a continuation of a 122 // request in a subdocument in different process, whereupon the caller 123 // need to send some notification itself with the real origin. 124 bool mShouldNotifyNewOrigin = true; 125 }; 126 127 } // namespace dom 128 } // namespace mozilla 129 130 class nsDocHeaderData { 131 public: nsDocHeaderData(nsAtom * aField,const nsAString & aData)132 nsDocHeaderData(nsAtom* aField, const nsAString& aData) 133 : mField(aField), mData(aData), mNext(nullptr) {} 134 ~nsDocHeaderData(void)135 ~nsDocHeaderData(void) { delete mNext; } 136 137 RefPtr<nsAtom> mField; 138 nsString mData; 139 nsDocHeaderData* mNext; 140 }; 141 142 class nsOnloadBlocker final : public nsIRequest { 143 public: nsOnloadBlocker()144 nsOnloadBlocker() {} 145 146 NS_DECL_ISUPPORTS 147 NS_DECL_NSIREQUEST 148 149 private: ~nsOnloadBlocker()150 ~nsOnloadBlocker() {} 151 }; 152 153 class nsExternalResourceMap { 154 public: 155 typedef nsIDocument::ExternalResourceLoad ExternalResourceLoad; 156 nsExternalResourceMap(); 157 158 /** 159 * Request an external resource document. This does exactly what 160 * nsIDocument::RequestExternalResource is documented to do. 161 */ 162 nsIDocument* RequestResource(nsIURI* aURI, nsINode* aRequestingNode, 163 nsDocument* aDisplayDocument, 164 ExternalResourceLoad** aPendingLoad); 165 166 /** 167 * Enumerate the resource documents. See 168 * nsIDocument::EnumerateExternalResources. 169 */ 170 void EnumerateResources(nsIDocument::nsSubDocEnumFunc aCallback, void* aData); 171 172 /** 173 * Traverse ourselves for cycle-collection 174 */ 175 void Traverse(nsCycleCollectionTraversalCallback* aCallback) const; 176 177 /** 178 * Shut ourselves down (used for cycle-collection unlink), as well 179 * as for document destruction. 180 */ Shutdown()181 void Shutdown() { 182 mPendingLoads.Clear(); 183 mMap.Clear(); 184 mHaveShutDown = true; 185 } 186 HaveShutDown()187 bool HaveShutDown() const { return mHaveShutDown; } 188 189 // Needs to be public so we can traverse them sanely 190 struct ExternalResource { 191 ~ExternalResource(); 192 nsCOMPtr<nsIDocument> mDocument; 193 nsCOMPtr<nsIContentViewer> mViewer; 194 nsCOMPtr<nsILoadGroup> mLoadGroup; 195 }; 196 197 // Hide all our viewers 198 void HideViewers(); 199 200 // Show all our viewers 201 void ShowViewers(); 202 203 protected: 204 class PendingLoad : public ExternalResourceLoad, public nsIStreamListener { ~PendingLoad()205 ~PendingLoad() {} 206 207 public: PendingLoad(nsDocument * aDisplayDocument)208 explicit PendingLoad(nsDocument* aDisplayDocument) 209 : mDisplayDocument(aDisplayDocument) {} 210 211 NS_DECL_ISUPPORTS 212 NS_DECL_NSISTREAMLISTENER 213 NS_DECL_NSIREQUESTOBSERVER 214 215 /** 216 * Start aURI loading. This will perform the necessary security checks and 217 * so forth. 218 */ 219 nsresult StartLoad(nsIURI* aURI, nsINode* aRequestingNode); 220 221 /** 222 * Set up an nsIContentViewer based on aRequest. This is guaranteed to 223 * put null in *aViewer and *aLoadGroup on all failures. 224 */ 225 nsresult SetupViewer(nsIRequest* aRequest, nsIContentViewer** aViewer, 226 nsILoadGroup** aLoadGroup); 227 228 private: 229 RefPtr<nsDocument> mDisplayDocument; 230 nsCOMPtr<nsIStreamListener> mTargetListener; 231 nsCOMPtr<nsIURI> mURI; 232 }; 233 friend class PendingLoad; 234 235 class LoadgroupCallbacks final : public nsIInterfaceRequestor { ~LoadgroupCallbacks()236 ~LoadgroupCallbacks() {} 237 238 public: LoadgroupCallbacks(nsIInterfaceRequestor * aOtherCallbacks)239 explicit LoadgroupCallbacks(nsIInterfaceRequestor* aOtherCallbacks) 240 : mCallbacks(aOtherCallbacks) {} 241 NS_DECL_ISUPPORTS 242 NS_DECL_NSIINTERFACEREQUESTOR 243 private: 244 // The only reason it's safe to hold a strong ref here without leaking is 245 // that the notificationCallbacks on a loadgroup aren't the docshell itself 246 // but a shim that holds a weak reference to the docshell. 247 nsCOMPtr<nsIInterfaceRequestor> mCallbacks; 248 249 // Use shims for interfaces that docshell implements directly so that we 250 // don't hand out references to the docshell. The shims should all allow 251 // getInterface back on us, but other than that each one should only 252 // implement one interface. 253 254 // XXXbz I wish we could just derive the _allcaps thing from _i 255 #define DECL_SHIM(_i, _allcaps) \ 256 class _i##Shim final : public nsIInterfaceRequestor, public _i { \ 257 ~_i##Shim() {} \ 258 \ 259 public: \ 260 _i##Shim(nsIInterfaceRequestor* aIfreq, _i* aRealPtr) \ 261 : mIfReq(aIfreq), mRealPtr(aRealPtr) { \ 262 NS_ASSERTION(mIfReq, "Expected non-null here"); \ 263 NS_ASSERTION(mRealPtr, "Expected non-null here"); \ 264 } \ 265 NS_DECL_ISUPPORTS \ 266 NS_FORWARD_NSIINTERFACEREQUESTOR(mIfReq->) \ 267 NS_FORWARD_##_allcaps(mRealPtr->) private \ 268 : nsCOMPtr<nsIInterfaceRequestor> mIfReq; \ 269 nsCOMPtr<_i> mRealPtr; \ 270 }; 271 272 DECL_SHIM(nsILoadContext, NSILOADCONTEXT) 273 DECL_SHIM(nsIProgressEventSink, NSIPROGRESSEVENTSINK) 274 DECL_SHIM(nsIChannelEventSink, NSICHANNELEVENTSINK) 275 DECL_SHIM(nsISecurityEventSink, NSISECURITYEVENTSINK) 276 DECL_SHIM(nsIApplicationCacheContainer, NSIAPPLICATIONCACHECONTAINER) 277 #undef DECL_SHIM 278 }; 279 280 /** 281 * Add an ExternalResource for aURI. aViewer and aLoadGroup might be null 282 * when this is called if the URI didn't result in an XML document. This 283 * function makes sure to remove the pending load for aURI, if any, from our 284 * hashtable, and to notify its observers, if any. 285 */ 286 nsresult AddExternalResource(nsIURI* aURI, nsIContentViewer* aViewer, 287 nsILoadGroup* aLoadGroup, 288 nsIDocument* aDisplayDocument); 289 290 nsClassHashtable<nsURIHashKey, ExternalResource> mMap; 291 nsRefPtrHashtable<nsURIHashKey, PendingLoad> mPendingLoads; 292 bool mHaveShutDown; 293 }; 294 295 // For classifying a flash document based on its principal. 296 class PrincipalFlashClassifier; 297 298 // Base class for our document implementations. 299 class nsDocument : public nsIDocument, 300 public nsIDOMDocument, 301 public nsSupportsWeakReference, 302 public nsIScriptObjectPrincipal, 303 public nsIRadioGroupContainer, 304 public nsIApplicationCacheContainer, 305 public nsStubMutationObserver { 306 friend class nsIDocument; 307 308 public: 309 typedef mozilla::dom::Element Element; 310 typedef mozilla::net::ReferrerPolicy ReferrerPolicy; 311 312 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 313 314 NS_DECL_ADDSIZEOFEXCLUDINGTHIS 315 316 virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override; 317 virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, 318 nsIPrincipal* aPrincipal) override; 319 320 already_AddRefed<nsIPrincipal> MaybeDowngradePrincipal( 321 nsIPrincipal* aPrincipal); 322 323 // StartDocumentLoad is pure virtual so that subclasses must override it. 324 // The nsDocument StartDocumentLoad does some setup, but does NOT set 325 // *aDocListener; this is the job of subclasses. 326 virtual nsresult StartDocumentLoad( 327 const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, 328 nsISupports* aContainer, nsIStreamListener** aDocListener, 329 bool aReset = true, nsIContentSink* aContentSink = nullptr) override = 0; 330 331 virtual void StopDocumentLoad() override; 332 333 virtual void NotifyPossibleTitleChange(bool aBoundTitleElement) override; 334 335 virtual void SetDocumentURI(nsIURI* aURI) override; 336 337 virtual void SetChromeXHRDocURI(nsIURI* aURI) override; 338 339 virtual void SetChromeXHRDocBaseURI(nsIURI* aURI) override; 340 341 virtual void ApplySettingsFromCSP(bool aSpeculative) override; 342 343 /** 344 * Set the principal responsible for this document. 345 */ 346 virtual void SetPrincipal(nsIPrincipal* aPrincipal) override; 347 348 /** 349 * Set the Content-Type of this document. 350 */ 351 virtual void SetContentType(const nsAString& aContentType) override; 352 353 virtual void SetBaseURI(nsIURI* aURI) override; 354 355 /** 356 * Get/Set the base target of a link in a document. 357 */ 358 virtual void GetBaseTarget(nsAString& aBaseTarget) override; 359 360 /** 361 * Set the document's character encoding. This will 362 * trigger a startDocumentLoad if necessary to answer the question. 363 */ 364 virtual void SetDocumentCharacterSet( 365 NotNull<const Encoding*> aEncoding) override; 366 367 virtual Element* AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver, 368 void* aData, bool aForImage) override; 369 virtual void RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver, 370 void* aData, bool aForImage) override; 371 372 /** 373 * Access HTTP header data (this may also get set from other sources, like 374 * HTML META tags). 375 */ 376 virtual void GetHeaderData(nsAtom* aHeaderField, 377 nsAString& aData) const override; 378 virtual void SetHeaderData(nsAtom* aheaderField, 379 const nsAString& aData) override; 380 381 /** 382 * Create a new presentation shell that will use aContext for 383 * its presentation context (presentation contexts <b>must not</b> be 384 * shared among multiple presentation shells). 385 */ 386 already_AddRefed<nsIPresShell> CreateShell( 387 nsPresContext* aContext, nsViewManager* aViewManager, 388 mozilla::StyleSetHandle aStyleSet) final; 389 virtual void DeleteShell() override; 390 391 virtual bool GetAllowPlugins() override; 392 393 static bool CallerIsTrustedAboutPage(JSContext* aCx, JSObject* aObject); 394 static bool IsElementAnimateEnabled(JSContext* aCx, JSObject* aObject); 395 static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject); 396 static bool IsWebAnimationsEnabled(mozilla::dom::CallerType aCallerType); 397 virtual mozilla::dom::DocumentTimeline* Timeline() override; 398 virtual void GetAnimations( 399 nsTArray<RefPtr<mozilla::dom::Animation>>& aAnimations) override; Timelines()400 mozilla::LinkedList<mozilla::dom::DocumentTimeline>& Timelines() override { 401 return mTimelines; 402 } 403 404 virtual nsresult SetSubDocumentFor(Element* aContent, 405 nsIDocument* aSubDoc) override; 406 virtual nsIDocument* GetSubDocumentFor(nsIContent* aContent) const override; 407 virtual Element* FindContentForSubDocument( 408 nsIDocument* aDocument) const override; 409 virtual Element* GetRootElementInternal() const override; 410 GetChannel()411 virtual nsIChannel* GetChannel() const override { return mChannel; } 412 GetFailedChannel()413 virtual nsIChannel* GetFailedChannel() const override { 414 return mFailedChannel; 415 } SetFailedChannel(nsIChannel * aChannel)416 virtual void SetFailedChannel(nsIChannel* aChannel) override { 417 mFailedChannel = aChannel; 418 } 419 420 virtual void SetScriptGlobalObject( 421 nsIScriptGlobalObject* aGlobalObject) override; 422 423 virtual void SetScriptHandlingObject( 424 nsIScriptGlobalObject* aScriptObject) override; 425 426 virtual nsIGlobalObject* GetScopeObject() const override; 427 void SetScopeObject(nsIGlobalObject* aGlobal) override; 428 /** 429 * Get the script loader for this document 430 */ 431 virtual mozilla::dom::ScriptLoader* ScriptLoader() override; 432 433 /** 434 * Add/Remove an element to the document's id and name hashes 435 */ 436 virtual void AddToIdTable(Element* aElement, nsAtom* aId) override; 437 virtual void RemoveFromIdTable(Element* aElement, nsAtom* aId) override; 438 virtual void AddToNameTable(Element* aElement, nsAtom* aName) override; 439 virtual void RemoveFromNameTable(Element* aElement, nsAtom* aName) override; 440 441 virtual void EndUpdate(nsUpdateType aUpdateType) override; 442 virtual void BeginLoad() override; 443 virtual void EndLoad() override; 444 445 virtual void SetReadyStateInternal(ReadyState rs) override; 446 447 virtual void FlushExternalResources(mozilla::FlushType aType) override; 448 virtual void SetXMLDeclaration(const char16_t* aVersion, 449 const char16_t* aEncoding, 450 const int32_t aStandalone) override; 451 virtual void GetXMLDeclaration(nsAString& aVersion, nsAString& aEncoding, 452 nsAString& Standalone) override; 453 virtual bool IsScriptEnabled() override; 454 455 virtual void OnPageShow( 456 bool aPersisted, 457 mozilla::dom::EventTarget* aDispatchStartTarget) override; 458 virtual void OnPageHide( 459 bool aPersisted, 460 mozilla::dom::EventTarget* aDispatchStartTarget) override; 461 462 virtual void WillDispatchMutationEvent(nsINode* aTarget) override; 463 virtual void MutationEventDispatched(nsINode* aTarget) override; 464 465 // nsINode 466 virtual bool IsNodeOfType(uint32_t aFlags) const override; 467 virtual nsIContent* GetChildAt_Deprecated(uint32_t aIndex) const override; 468 virtual int32_t ComputeIndexOf(const nsINode* aPossibleChild) const override; 469 virtual uint32_t GetChildCount() const override; 470 virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis, 471 bool aNotify) override; 472 virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex, 473 bool aNotify) override; 474 virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override; 475 virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override; Clone(mozilla::dom::NodeInfo * aNodeInfo,nsINode ** aResult,bool aPreallocateChildren)476 virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult, 477 bool aPreallocateChildren) const override { 478 return NS_ERROR_NOT_IMPLEMENTED; 479 } 480 481 // nsIRadioGroupContainer 482 NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor, 483 bool aFlushContent) override; 484 virtual void SetCurrentRadioButton( 485 const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override; 486 virtual mozilla::dom::HTMLInputElement* GetCurrentRadioButton( 487 const nsAString& aName) override; 488 NS_IMETHOD 489 GetNextRadioButton(const nsAString& aName, const bool aPrevious, 490 mozilla::dom::HTMLInputElement* aFocusedRadio, 491 mozilla::dom::HTMLInputElement** aRadioOut) override; 492 virtual void AddToRadioGroup(const nsAString& aName, 493 mozilla::dom::HTMLInputElement* aRadio) override; 494 virtual void RemoveFromRadioGroup( 495 const nsAString& aName, mozilla::dom::HTMLInputElement* aRadio) override; 496 virtual uint32_t GetRequiredRadioCount(const nsAString& aName) const override; 497 virtual void RadioRequiredWillChange(const nsAString& aName, 498 bool aRequiredAdded) override; 499 virtual bool GetValueMissingState(const nsAString& aName) const override; 500 virtual void SetValueMissingState(const nsAString& aName, 501 bool aValue) override; 502 503 // for radio group 504 nsRadioGroupStruct* GetRadioGroup(const nsAString& aName) const; 505 nsRadioGroupStruct* GetOrCreateRadioGroup(const nsAString& aName); 506 507 virtual nsViewportInfo GetViewportInfo( 508 const mozilla::ScreenIntSize& aDisplaySize) override; 509 510 enum class UseCounterReportKind { 511 // Flush the document's use counters only; the use counters for any 512 // external resource documents will be flushed when the external 513 // resource documents themselves are destroyed. 514 eDefault, 515 516 // Flush use counters for the document and for its external resource 517 // documents. (Should only be necessary for tests, where we need 518 // flushing to happen synchronously and deterministically.) 519 eIncludeExternalResources, 520 }; 521 522 void ReportUseCounters( 523 UseCounterReportKind aKind = UseCounterReportKind::eDefault); 524 525 virtual void AddIntersectionObserver( 526 mozilla::dom::DOMIntersectionObserver* aObserver) override; 527 virtual void RemoveIntersectionObserver( 528 mozilla::dom::DOMIntersectionObserver* aObserver) override; 529 virtual void UpdateIntersectionObservations() override; 530 virtual void ScheduleIntersectionObserverNotification() override; 531 virtual void NotifyIntersectionObservers() override; HasIntersectionObservers()532 virtual bool HasIntersectionObservers() const override { 533 return !mIntersectionObservers.IsEmpty(); 534 } 535 536 virtual void NotifyLayerManagerRecreated() override; 537 538 bool IsSynthesized(); 539 540 // Check whether shadow DOM is enabled for the global of aObject. 541 static bool IsShadowDOMEnabled(JSContext* aCx, JSObject* aObject); 542 // Check whether shadow DOM is enabled for the document this node belongs to. 543 static bool IsShadowDOMEnabled(const nsINode* aNode); 544 545 private: 546 void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages); 547 548 public: 549 // nsIDOMDocument 550 NS_DECL_NSIDOMDOCUMENT 551 552 using mozilla::dom::DocumentOrShadowRoot::GetElementById; 553 using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName; 554 using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName; 555 using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS; 556 557 // nsIDOMEventTarget 558 virtual nsresult GetEventTargetParent( 559 mozilla::EventChainPreVisitor& aVisitor) override; 560 virtual mozilla::EventListenerManager* GetOrCreateListenerManager() override; 561 virtual mozilla::EventListenerManager* GetExistingListenerManager() 562 const override; 563 564 // nsIScriptObjectPrincipal 565 virtual nsIPrincipal* GetPrincipal() override; 566 567 // nsIApplicationCacheContainer 568 NS_DECL_NSIAPPLICATIONCACHECONTAINER 569 570 virtual nsresult Init(); 571 572 virtual already_AddRefed<Element> CreateElem( 573 const nsAString& aName, nsAtom* aPrefix, int32_t aNamespaceID, 574 const nsAString* aIs = nullptr) override; 575 576 virtual void Sanitize() override; 577 578 virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback, 579 void* aData) override; 580 virtual void CollectDescendantDocuments( 581 nsTArray<nsCOMPtr<nsIDocument>>& aDescendants, 582 nsDocTestFunc aCallback) const override; 583 584 virtual bool CanSavePresentation(nsIRequest* aNewRequest) override; 585 virtual void Destroy() override; 586 virtual void RemovedFromDocShell() override; 587 virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() 588 const override; 589 590 virtual void BlockOnload() override; 591 virtual void UnblockOnload(bool aFireSync) override; 592 593 virtual void AddStyleRelevantLink(mozilla::dom::Link* aLink) override; 594 virtual void ForgetLink(mozilla::dom::Link* aLink) override; 595 596 virtual void ClearBoxObjectFor(nsIContent* aContent) override; 597 598 virtual already_AddRefed<mozilla::dom::BoxObject> GetBoxObjectFor( 599 mozilla::dom::Element* aElement, mozilla::ErrorResult& aRv) override; 600 601 virtual Element* GetAnonymousElementByAttribute( 602 nsIContent* aElement, nsAtom* aAttrName, 603 const nsAString& aAttrValue) const override; 604 605 virtual nsresult NodesFromRectHelper(float aX, float aY, float aTopSize, 606 float aRightSize, float aBottomSize, 607 float aLeftSize, 608 bool aIgnoreRootScrollFrame, 609 bool aFlushLayout, 610 nsIDOMNodeList** aReturn) override; 611 612 virtual void FlushSkinBindings() override; 613 614 virtual nsresult InitializeFrameLoader(nsFrameLoader* aLoader) override; 615 virtual nsresult FinalizeFrameLoader(nsFrameLoader* aLoader, 616 nsIRunnable* aFinalizer) override; 617 virtual void TryCancelFrameLoaderInitialization(nsIDocShell* aShell) override; 618 virtual nsIDocument* RequestExternalResource( 619 nsIURI* aURI, nsINode* aRequestingNode, 620 ExternalResourceLoad** aPendingLoad) override; 621 virtual void EnumerateExternalResources(nsSubDocEnumFunc aCallback, 622 void* aData) override; 623 624 // Returns our (lazily-initialized) animation controller. 625 // If HasAnimationController is true, this is guaranteed to return non-null. 626 nsSMILAnimationController* GetAnimationController() override; 627 GetPendingAnimationTracker()628 mozilla::PendingAnimationTracker* GetPendingAnimationTracker() final { 629 return mPendingAnimationTracker; 630 } 631 632 virtual mozilla::PendingAnimationTracker* GetOrCreatePendingAnimationTracker() 633 override; 634 635 virtual void SuppressEventHandling(uint32_t aIncrease) override; 636 637 virtual void UnsuppressEventHandlingAndFireEvents(bool aFireEvents) override; 638 DecreaseEventSuppression()639 void DecreaseEventSuppression() { 640 MOZ_ASSERT(mEventsSuppressed); 641 --mEventsSuppressed; 642 UpdateFrameRequestCallbackSchedulingState(); 643 } 644 645 virtual nsIDocument* GetTemplateContentsOwner() override; 646 647 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument, 648 nsIDocument) 649 650 void DoNotifyPossibleTitleChange(); 651 ExternalResourceMap()652 nsExternalResourceMap& ExternalResourceMap() { return mExternalResourceMap; } 653 SetLoadedAsData(bool aLoadedAsData)654 void SetLoadedAsData(bool aLoadedAsData) { mLoadedAsData = aLoadedAsData; } SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData)655 void SetLoadedAsInteractiveData(bool aLoadedAsInteractiveData) { 656 mLoadedAsInteractiveData = aLoadedAsInteractiveData; 657 } 658 659 nsresult CloneDocHelper(nsDocument* clone, bool aPreallocateChildren) const; 660 661 void MaybeInitializeFinalizeFrameLoaders(); 662 663 void MaybeEndOutermostXBLUpdate(); 664 665 virtual void PreloadPictureOpened() override; 666 virtual void PreloadPictureClosed() override; 667 668 virtual void PreloadPictureImageSource(const nsAString& aSrcsetAttr, 669 const nsAString& aSizesAttr, 670 const nsAString& aTypeAttr, 671 const nsAString& aMediaAttr) override; 672 673 virtual already_AddRefed<nsIURI> ResolvePreloadImage( 674 nsIURI* aBaseURI, const nsAString& aSrcAttr, const nsAString& aSrcsetAttr, 675 const nsAString& aSizesAttr, bool* aIsImgSet) override; 676 677 virtual void MaybePreLoadImage(nsIURI* uri, const nsAString& aCrossOriginAttr, 678 ReferrerPolicy aReferrerPolicy, 679 bool aIsImgSet) override; 680 681 virtual void ForgetImagePreload(nsIURI* aURI) override; 682 683 virtual void MaybePreconnect(nsIURI* uri, 684 mozilla::CORSMode aCORSMode) override; 685 686 virtual nsISupports* GetCurrentContentSink() override; 687 688 // Only BlockOnload should call this! 689 void AsyncBlockOnload(); 690 691 virtual void SetAutoFocusElement(Element* aAutoFocusElement) override; 692 virtual void TriggerAutoFocus() override; 693 694 virtual void SetScrollToRef(nsIURI* aDocumentURI) override; 695 virtual void ScrollToRef() override; 696 virtual void ResetScrolledToRefAlready() override; 697 virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) override; 698 699 virtual Element* LookupImageElement(const nsAString& aElementId) override; 700 virtual void MozSetImageElement(const nsAString& aImageElementId, 701 Element* aElement) override; 702 703 // AddPlugin adds a plugin-related element to mPlugins when the element is 704 // added to the tree. 705 virtual nsresult AddPlugin(nsIObjectLoadingContent* aPlugin) override; 706 // RemovePlugin removes a plugin-related element to mPlugins when the 707 // element is removed from the tree. 708 virtual void RemovePlugin(nsIObjectLoadingContent* aPlugin) override; 709 // GetPlugins returns the plugin-related elements from 710 // the frame and any subframes. 711 virtual void GetPlugins( 712 nsTArray<nsIObjectLoadingContent*>& aPlugins) override; 713 714 // Adds an element to mResponsiveContent when the element is 715 // added to the tree. 716 virtual nsresult AddResponsiveContent(nsIContent* aContent) override; 717 // Removes an element from mResponsiveContent when the element is 718 // removed from the tree. 719 virtual void RemoveResponsiveContent(nsIContent* aContent) override; 720 // Notifies any responsive content added by AddResponsiveContent upon media 721 // features values changing. 722 virtual void NotifyMediaFeatureValuesChanged() override; 723 724 virtual nsresult GetStateObject(nsIVariant** aResult) override; 725 726 virtual nsDOMNavigationTiming* GetNavigationTiming() const override; 727 virtual nsresult SetNavigationTiming(nsDOMNavigationTiming* aTiming) override; 728 729 virtual Element* FindImageMap(const nsAString& aNormalizedMapName) override; 730 731 virtual nsTArray<Element*> GetFullscreenStack() const override; 732 virtual void AsyncRequestFullScreen( 733 mozilla::UniquePtr<FullscreenRequest>&& aRequest) override; 734 virtual void RestorePreviousFullScreenState() override; 735 virtual bool IsFullscreenLeaf() override; 736 virtual nsresult RemoteFrameFullscreenChanged( 737 nsIDOMElement* aFrameElement) override; 738 739 virtual nsresult RemoteFrameFullscreenReverted() override; 740 virtual nsIDocument* GetFullscreenRoot() override; 741 virtual void SetFullscreenRoot(nsIDocument* aRoot) override; 742 743 // Returns the size of the mBlockedTrackingNodes array. (nsIDocument.h) 744 // 745 // This array contains nodes that have been blocked to prevent 746 // user tracking. They most likely have had their nsIChannel 747 // canceled by the URL classifier (Safebrowsing). 748 // 749 // A script can subsequently use GetBlockedTrackingNodes() 750 // to get a list of references to these nodes. 751 // 752 // Note: 753 // This expresses how many tracking nodes have been blocked for this 754 // document since its beginning, not how many of them are still around 755 // in the DOM tree. Weak references to blocked nodes are added in the 756 // mBlockedTrackingNodesArray but they are not removed when those nodes 757 // are removed from the tree or even garbage collected. 758 long BlockedTrackingNodeCount() const; 759 760 // 761 // Returns strong references to mBlockedTrackingNodes. (nsIDocument.h) 762 // 763 // This array contains nodes that have been blocked to prevent 764 // user tracking. They most likely have had their nsIChannel 765 // canceled by the URL classifier (Safebrowsing). 766 // 767 already_AddRefed<nsSimpleContentList> BlockedTrackingNodes() const; 768 769 // Do the "fullscreen element ready check" from the fullscreen spec. 770 // It returns true if the given element is allowed to go into fullscreen. 771 bool FullscreenElementReadyCheck(Element* aElement, bool aWasCallerChrome); 772 773 // This is called asynchronously by nsIDocument::AsyncRequestFullScreen() 774 // to move this document into full-screen mode if allowed. 775 void RequestFullScreen(mozilla::UniquePtr<FullscreenRequest>&& aRequest); 776 777 // Removes all elements from the full-screen stack, removing full-scren 778 // styles from the top element in the stack. 779 void CleanupFullscreenState(); 780 781 // Pushes aElement onto the full-screen stack, and removes full-screen styles 782 // from the former full-screen stack top, and its ancestors, and applies the 783 // styles to aElement. aElement becomes the new "full-screen element". 784 bool FullScreenStackPush(Element* aElement); 785 786 // Remove the top element from the full-screen stack. Removes the full-screen 787 // styles from the former top element, and applies them to the new top 788 // element, if there is one. 789 void FullScreenStackPop(); 790 791 // Returns the top element from the full-screen stack. 792 Element* FullScreenStackTop() override; 793 794 // DOM-exposed fullscreen API 795 bool FullscreenEnabled(mozilla::dom::CallerType aCallerType) override; 796 797 virtual bool AllowPaymentRequest() const override; 798 virtual void SetAllowPaymentRequest(bool aIsAllowPaymentRequest) override; 799 800 void RequestPointerLock(Element* aElement, 801 mozilla::dom::CallerType aCallerType) override; 802 bool SetPointerLock(Element* aElement, int aCursorStyle); 803 static void UnlockPointer(nsIDocument* aDoc = nullptr); 804 805 void SetCurrentOrientation(mozilla::dom::OrientationType aType, 806 uint16_t aAngle) override; 807 uint16_t CurrentOrientationAngle() const override; 808 mozilla::dom::OrientationType CurrentOrientationType() const override; 809 void SetOrientationPendingPromise(mozilla::dom::Promise* aPromise) override; 810 mozilla::dom::Promise* GetOrientationPendingPromise() const override; 811 812 // This method may fire a DOM event; if it does so it will happen 813 // synchronously. 814 void UpdateVisibilityState(); 815 // Posts an event to call UpdateVisibilityState 816 virtual void PostVisibilityUpdateEvent() override; 817 818 // Since we wouldn't automatically play media from non-visited page, we need 819 // to notify window when the page was first visited. 820 void MaybeActiveMediaComponents(); 821 822 virtual void DocAddSizeOfExcludingThis( 823 nsWindowSizes& aWindowSizes) const override; 824 // DocAddSizeOfIncludingThis is inherited from nsIDocument. 825 AsDOMNode()826 virtual nsIDOMNode* AsDOMNode() override { return this; } 827 828 // WebIDL bits 829 virtual mozilla::dom::DOMImplementation* GetImplementation( 830 mozilla::ErrorResult& rv) override; 831 832 virtual already_AddRefed<Element> CreateElement( 833 const nsAString& aTagName, 834 const mozilla::dom::ElementCreationOptionsOrString& aOptions, 835 ErrorResult& rv) override; 836 virtual already_AddRefed<Element> CreateElementNS( 837 const nsAString& aNamespaceURI, const nsAString& aQualifiedName, 838 const mozilla::dom::ElementCreationOptionsOrString& aOptions, 839 mozilla::ErrorResult& rv) override; 840 841 virtual void UnblockDOMContentLoaded() override; 842 843 protected: 844 friend class nsNodeUtils; 845 846 /** 847 * Check that aId is not empty and log a message to the console 848 * service if it is. 849 * @returns true if aId looks correct, false otherwise. 850 */ CheckGetElementByIdArg(const nsAString & aId)851 inline bool CheckGetElementByIdArg(const nsAString& aId) { 852 if (aId.IsEmpty()) { 853 ReportEmptyGetElementByIdArg(); 854 return false; 855 } 856 return true; 857 } 858 859 void ReportEmptyGetElementByIdArg(); 860 861 void DispatchContentLoadedEvents(); 862 863 void RetrieveRelevantHeaders(nsIChannel* aChannel); 864 865 void TryChannelCharset(nsIChannel* aChannel, int32_t& aCharsetSource, 866 NotNull<const Encoding*>& aEncoding, 867 nsHtml5TreeOpExecutor* aExecutor); 868 869 // Call this before the document does something that will unbind all content. 870 // That will stop us from doing a lot of work as each element is removed. 871 void DestroyElementMaps(); 872 873 // Refreshes the hrefs of all the links in the document. 874 void RefreshLinkHrefs(); 875 876 nsIContent* GetFirstBaseNodeWithHref(); 877 nsresult SetFirstBaseNodeWithHref(nsIContent* node); 878 879 /** 880 * Returns the title element of the document as defined by the HTML 881 * specification, or null if there isn't one. For documents whose root 882 * element is an <svg:svg>, this is the first <svg:title> element that's a 883 * child of the root. For other documents, it's the first HTML title element 884 * in the document. 885 */ 886 Element* GetTitleElement(); 887 888 public: 889 // Get our title 890 virtual void GetTitle(nsAString& aTitle) override; 891 // Set our title 892 virtual void SetTitle(const nsAString& aTitle, 893 mozilla::ErrorResult& rv) override; 894 895 js::ExpandoAndGeneration mExpandoAndGeneration; 896 897 bool ContainsEMEContent(); 898 899 bool ContainsMSEContent(); 900 901 protected: 902 void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget, 903 const nsAString& aType, bool aPersisted); 904 905 virtual nsPIDOMWindowOuter* GetWindowInternal() const override; 906 virtual nsIScriptGlobalObject* GetScriptHandlingObjectInternal() 907 const override; 908 virtual bool InternalAllowXULXBL() override; 909 910 void UpdateScreenOrientation(); 911 912 virtual mozilla::dom::FlashClassification DocumentFlashClassification() 913 override; 914 virtual bool IsThirdParty() override; 915 916 #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) \ 917 do { \ 918 NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mObservers, nsIDocumentObserver, \ 919 func_, params_); \ 920 /* FIXME(emilio): Apparently we can keep observing from the BFCache? That \ 921 looks bogus. */ \ 922 if (nsIPresShell* shell = GetObservingShell()) { \ 923 shell->func_ params_; \ 924 } \ 925 } while (0) 926 927 #ifdef DEBUG 928 void VerifyRootContentState(); 929 #endif 930 931 explicit nsDocument(const char* aContentType); 932 virtual ~nsDocument(); 933 934 void EnsureOnloadBlocker(); 935 936 // Apply the fullscreen state to the document, and trigger related 937 // events. It returns false if the fullscreen element ready check 938 // fails and nothing gets changed. 939 bool ApplyFullscreen(const FullscreenRequest& aRequest); 940 941 // Retrieves the classification of the Flash plugins in the document based on 942 // the classification lists. 943 mozilla::dom::FlashClassification PrincipalFlashClassification(); 944 945 // Attempts to determine the Flash classification of this page based on the 946 // the classification lists and the classification of parent documents. 947 mozilla::dom::FlashClassification ComputeFlashClassification(); 948 949 PLDHashTable* mSubDocuments; 950 951 // Array of owning references to all children 952 nsAttrAndChildArray mChildren; 953 954 // Array of intersection observers 955 nsTHashtable<nsPtrHashKey<mozilla::dom::DOMIntersectionObserver>> 956 mIntersectionObservers; 957 958 // Tracker for animations that are waiting to start. 959 // nullptr until GetOrCreatePendingAnimationTracker is called. 960 RefPtr<mozilla::PendingAnimationTracker> mPendingAnimationTracker; 961 962 // Weak reference to the scope object (aka the script global object) 963 // that, unlike mScriptGlobalObject, is never unset once set. This 964 // is a weak reference to avoid leaks due to circular references. 965 nsWeakPtr mScopeObject; 966 967 // Stack of full-screen elements. When we request full-screen we push the 968 // full-screen element onto this stack, and when we cancel full-screen we 969 // pop one off this stack, restoring the previous full-screen state 970 nsTArray<nsWeakPtr> mFullScreenStack; 971 972 // The root of the doc tree in which this document is in. This is only 973 // non-null when this document is in fullscreen mode. 974 nsWeakPtr mFullscreenRoot; 975 976 RefPtr<PrincipalFlashClassifier> mPrincipalFlashClassifier; 977 mozilla::dom::FlashClassification mFlashClassification; 978 // Do not use this value directly. Call the |IsThirdParty()| method, which 979 // caches its result here. 980 mozilla::Maybe<bool> mIsThirdParty; 981 982 public: 983 RefPtr<mozilla::EventListenerManager> mListenerManager; 984 RefPtr<mozilla::dom::ScriptLoader> mScriptLoader; 985 nsDocHeaderData* mHeaderData; 986 987 nsClassHashtable<nsStringHashKey, nsRadioGroupStruct> mRadioGroups; 988 989 // Recorded time of change to 'loading' state. 990 mozilla::TimeStamp mLoadingTimeStamp; 991 992 // True if this document has ever had an HTML or SVG <title> element 993 // bound to it 994 bool mMayHaveTitleElement : 1; 995 996 bool mHasWarnedAboutBoxObjects : 1; 997 998 bool mDelayFrameLoaderInitialization : 1; 999 1000 bool mSynchronousDOMContentLoaded : 1; 1001 1002 // Parser aborted. True if the parser of this document was forcibly 1003 // terminated instead of letting it finish at its own pace. 1004 bool mParserAborted : 1; 1005 1006 friend class nsCallRequestFullScreen; 1007 1008 // ScreenOrientation "pending promise" as described by 1009 // http://www.w3.org/TR/screen-orientation/ 1010 RefPtr<mozilla::dom::Promise> mOrientationPendingPromise; 1011 1012 uint16_t mCurrentOrientationAngle; 1013 mozilla::dom::OrientationType mCurrentOrientationType; 1014 1015 // Whether we have reported use counters for this document with Telemetry yet. 1016 // Normally this is only done at document destruction time, but for image 1017 // documents (SVG documents) that are not guaranteed to be destroyed, we 1018 // report use counters when the image cache no longer has any imgRequestProxys 1019 // pointing to them. We track whether we ever reported use counters so 1020 // that we only report them once for the document. 1021 bool mReportedUseCounters : 1; 1022 1023 uint8_t mPendingFullscreenRequests; 1024 1025 uint8_t mXMLDeclarationBits; 1026 1027 nsRefPtrHashtable<nsPtrHashKey<nsIContent>, mozilla::dom::BoxObject>* 1028 mBoxObjectTable; 1029 1030 // A document "without a browsing context" that owns the content of 1031 // HTMLTemplateElement. 1032 nsCOMPtr<nsIDocument> mTemplateContentsOwner; 1033 1034 // The application cache that this document is associated with, if 1035 // any. This can change during the lifetime of the document. 1036 nsCOMPtr<nsIApplicationCache> mApplicationCache; 1037 1038 nsCOMPtr<nsIContent> mFirstBaseNodeWithHref; 1039 1040 RefPtr<nsDOMNavigationTiming> mTiming; 1041 1042 private: 1043 friend class nsUnblockOnloadEvent; 1044 // Recomputes the visibility state but doesn't set the new value. 1045 mozilla::dom::VisibilityState GetVisibilityState() const; 1046 1047 void PostUnblockOnloadEvent(); 1048 void DoUnblockOnload(); 1049 1050 nsresult InitCSP(nsIChannel* aChannel); 1051 1052 void ClearAllBoxObjects(); 1053 1054 // Returns true if the scheme for the url for this document is "about" 1055 bool IsAboutPage() const; 1056 1057 // These are not implemented and not supported. 1058 nsDocument(const nsDocument& aOther); 1059 nsDocument& operator=(const nsDocument& aOther); 1060 1061 // The layout history state that should be used by nodes in this 1062 // document. We only actually store a pointer to it when: 1063 // 1) We have no script global object. 1064 // 2) We haven't had Destroy() called on us yet. 1065 nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState; 1066 1067 // Currently active onload blockers 1068 uint32_t mOnloadBlockCount; 1069 // Onload blockers which haven't been activated yet 1070 uint32_t mAsyncOnloadBlockCount; 1071 nsCOMPtr<nsIRequest> mOnloadBlocker; 1072 1073 // A hashtable of styled links keyed by address pointer. 1074 nsTHashtable<nsPtrHashKey<mozilla::dom::Link>> mStyledLinks; 1075 #ifdef DEBUG 1076 // Indicates whether mStyledLinks was cleared or not. This is used to track 1077 // state so we can provide useful assertions to consumers of ForgetLink and 1078 // AddStyleRelevantLink. 1079 bool mStyledLinksCleared; 1080 #endif 1081 1082 // A set of responsive images keyed by address pointer. 1083 nsTHashtable<nsPtrHashKey<nsIContent>> mResponsiveContent; 1084 1085 nsTArray<RefPtr<nsFrameLoader>> mInitializableFrameLoaders; 1086 nsTArray<nsCOMPtr<nsIRunnable>> mFrameLoaderFinalizers; 1087 RefPtr<nsRunnableMethod<nsDocument>> mFrameLoaderRunner; 1088 1089 nsCOMPtr<nsIRunnable> mMaybeEndOutermostXBLUpdateRunner; 1090 1091 nsRevocableEventPtr<nsRunnableMethod<nsDocument, void, false>> 1092 mPendingTitleChangeEvent; 1093 1094 nsExternalResourceMap mExternalResourceMap; 1095 1096 // All images in process of being preloaded. This is a hashtable so 1097 // we can remove them as the real image loads start; that way we 1098 // make sure to not keep the image load going when no one cares 1099 // about it anymore. 1100 nsRefPtrHashtable<nsURIHashKey, imgIRequest> mPreloadingImages; 1101 1102 // A list of preconnects initiated by the preloader. This prevents 1103 // the same uri from being used more than once, and allows the dom 1104 // builder to not repeat the work of the preloader. 1105 nsDataHashtable<nsURIHashKey, bool> mPreloadedPreconnects; 1106 1107 // Current depth of picture elements from parser 1108 int32_t mPreloadPictureDepth; 1109 1110 // Set if we've found a URL for the current picture 1111 nsString mPreloadPictureFoundSource; 1112 1113 RefPtr<mozilla::dom::DOMImplementation> mDOMImplementation; 1114 1115 RefPtr<nsContentList> mImageMaps; 1116 1117 nsWeakPtr mAutoFocusElement; 1118 1119 nsCString mScrollToRef; 1120 uint8_t mScrolledToRefAlready : 1; 1121 uint8_t mChangeScrollPosWhenScrollingToRef : 1; 1122 1123 // Tracking for plugins in the document. 1124 nsTHashtable<nsPtrHashKey<nsIObjectLoadingContent>> mPlugins; 1125 1126 RefPtr<mozilla::dom::DocumentTimeline> mDocumentTimeline; 1127 mozilla::LinkedList<mozilla::dom::DocumentTimeline> mTimelines; 1128 1129 enum ViewportType { DisplayWidthHeight, Specified, Unknown }; 1130 1131 ViewportType mViewportType; 1132 1133 // These member variables cache information about the viewport so we don't 1134 // have to recalculate it each time. 1135 bool mValidWidth, mValidHeight; 1136 mozilla::LayoutDeviceToScreenScale mScaleMinFloat; 1137 mozilla::LayoutDeviceToScreenScale mScaleMaxFloat; 1138 mozilla::LayoutDeviceToScreenScale mScaleFloat; 1139 mozilla::CSSToLayoutDeviceScale mPixelRatio; 1140 bool mAutoSize, mAllowZoom, mAllowDoubleTapZoom, mValidScaleFloat, 1141 mValidMaxScale, mScaleStrEmpty, mWidthStrEmpty; 1142 mozilla::CSSSize mViewportSize; 1143 1144 // Set to true when the document is possibly controlled by the ServiceWorker. 1145 // Used to prevent multiple requests to ServiceWorkerManager. 1146 bool mMaybeServiceWorkerControlled; 1147 1148 #ifdef DEBUG 1149 public: 1150 bool mWillReparent; 1151 #endif 1152 1153 private: 1154 void RecordNavigationTiming(ReadyState aReadyState); 1155 bool mDOMLoadingSet : 1; 1156 bool mDOMInteractiveSet : 1; 1157 bool mDOMCompleteSet : 1; 1158 bool mAutoFocusFired : 1; 1159 }; 1160 1161 class nsDocumentOnStack { 1162 public: nsDocumentOnStack(nsIDocument * aDoc)1163 explicit nsDocumentOnStack(nsIDocument* aDoc) : mDoc(aDoc) { 1164 mDoc->IncreaseStackRefCnt(); 1165 } ~nsDocumentOnStack()1166 ~nsDocumentOnStack() { mDoc->DecreaseStackRefCnt(); } 1167 1168 private: 1169 nsIDocument* mDoc; 1170 }; 1171 1172 #endif /* nsDocument_h___ */ 1173