1/* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2011 Google Inc. All rights reserved. 10 * 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Library General Public 13 * License as published by the Free Software Foundation; either 14 * version 2 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Library General Public License for more details. 20 * 21 * You should have received a copy of the GNU Library General Public License 22 * along with this library; see the file COPYING.LIB. If not, write to 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 * Boston, MA 02110-1301, USA. 25 * 26 */ 27 28#ifndef Document_h 29#define Document_h 30 31#include "CollectionType.h" 32#include "Color.h" 33#include "ContainerNode.h" 34#include "DocumentEventQueue.h" 35#include "DocumentStyleSheetCollection.h" 36#include "DocumentTiming.h" 37#include "FocusDirection.h" 38#include "IconURL.h" 39#include "MutationObserver.h" 40#include "PageVisibilityState.h" 41#include "PlatformScreen.h" 42#include "ReferrerPolicy.h" 43#include "RenderPtr.h" 44#include "ScriptExecutionContext.h" 45#include "StringWithDirection.h" 46#include "StyleResolveTree.h" 47#include "Timer.h" 48#include "TreeScope.h" 49#include "UserActionElementSet.h" 50#include "ViewportArguments.h" 51#include <chrono> 52#include <memory> 53#include <wtf/Deque.h> 54#include <wtf/HashSet.h> 55#include <wtf/OwnPtr.h> 56#include <wtf/PassOwnPtr.h> 57#include <wtf/PassRefPtr.h> 58#include <wtf/WeakPtr.h> 59 60namespace JSC { 61class ExecState; 62#if ENABLE(WEB_REPLAY) 63class InputCursor; 64#endif 65} 66 67namespace WebCore { 68 69class AXObjectCache; 70class Attr; 71class CDATASection; 72class CSSStyleDeclaration; 73class CSSStyleSheet; 74class CachedCSSStyleSheet; 75class CachedResourceLoader; 76class CachedScript; 77class CanvasRenderingContext; 78class CharacterData; 79class Comment; 80class DOMImplementation; 81class DOMNamedFlowCollection; 82class DOMSelection; 83class DOMWindow; 84class DOMWrapperWorld; 85class Database; 86class DatabaseThread; 87class DocumentFragment; 88class DocumentLoader; 89class DocumentMarkerController; 90class DocumentParser; 91class DocumentSharedObjectPool; 92class DocumentType; 93class Element; 94class EntityReference; 95class Event; 96class EventListener; 97class FloatRect; 98class FloatQuad; 99class FormController; 100class Frame; 101class FrameView; 102class HTMLCanvasElement; 103class HTMLCollection; 104class HTMLAllCollection; 105class HTMLDocument; 106class HTMLElement; 107class HTMLFrameOwnerElement; 108class HTMLHeadElement; 109class HTMLIFrameElement; 110class HTMLImageElement; 111class HTMLMapElement; 112class HTMLMediaElement; 113class HTMLNameCollection; 114class HTMLScriptElement; 115class HitTestRequest; 116class HitTestResult; 117class IntPoint; 118class LayoutPoint; 119class LayoutRect; 120class LiveNodeList; 121class JSNode; 122class Locale; 123class MediaCanStartListener; 124class MediaQueryList; 125class MediaQueryMatcher; 126class MouseEventWithHitTestResults; 127class NamedFlowCollection; 128class NodeFilter; 129class NodeIterator; 130class Page; 131class PlatformMouseEvent; 132class ProcessingInstruction; 133class QualifiedName; 134class Range; 135class RegisteredEventListener; 136class RenderView; 137class RenderFullScreen; 138class ScriptableDocumentParser; 139class ScriptElementData; 140class ScriptRunner; 141class SecurityOrigin; 142class SelectorQuery; 143class SelectorQueryCache; 144class SerializedScriptValue; 145class SegmentedString; 146class Settings; 147class StyleResolver; 148class StyleSheet; 149class StyleSheetContents; 150class StyleSheetList; 151class SVGDocumentExtensions; 152class Text; 153class TextResourceDecoder; 154class TreeWalker; 155class VisitedLinkState; 156class WebKitNamedFlow; 157class XMLHttpRequest; 158class XPathEvaluator; 159class XPathExpression; 160class XPathNSResolver; 161class XPathResult; 162 163#if ENABLE(XSLT) 164class TransformSource; 165#endif 166 167#if ENABLE(DASHBOARD_SUPPORT) 168struct AnnotatedRegionValue; 169#endif 170 171#if ENABLE(TOUCH_EVENTS) 172#if PLATFORM(IOS) 173#include <WebKitAdditions/DocumentIOSForward.h> 174#endif // PLATFORM(IOS) 175class Touch; 176class TouchList; 177#endif 178 179#if ENABLE(REQUEST_ANIMATION_FRAME) 180class RequestAnimationFrameCallback; 181class ScriptedAnimationController; 182#endif 183 184#if ENABLE(TEXT_AUTOSIZING) 185class TextAutosizer; 186#endif 187 188#if ENABLE(CSP_NEXT) 189class DOMSecurityPolicy; 190#endif 191 192#if ENABLE(FONT_LOAD_EVENTS) 193class FontLoader; 194#endif 195 196typedef int ExceptionCode; 197 198#if PLATFORM(IOS) 199class DeviceMotionClient; 200class DeviceMotionController; 201class DeviceOrientationClient; 202class DeviceOrientationController; 203#endif 204 205#if ENABLE(IOS_TEXT_AUTOSIZING) 206struct TextAutoSizingHash; 207class TextAutoSizingKey; 208class TextAutoSizingValue; 209 210struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> { 211 static const bool emptyValueIsZero = true; 212 static void constructDeletedValue(TextAutoSizingKey& slot); 213 static bool isDeletedValue(const TextAutoSizingKey& value); 214}; 215#endif 216 217enum PageshowEventPersistence { 218 PageshowEventNotPersisted = 0, 219 PageshowEventPersisted = 1 220}; 221 222enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded, DeferRecalcStyleIfNeeded }; 223 224enum NodeListInvalidationType { 225 DoNotInvalidateOnAttributeChanges = 0, 226 InvalidateOnClassAttrChange, 227 InvalidateOnIdNameAttrChange, 228 InvalidateOnNameAttrChange, 229 InvalidateOnForAttrChange, 230 InvalidateForFormControls, 231 InvalidateOnHRefAttrChange, 232 InvalidateOnAnyAttrChange, 233}; 234const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1; 235 236typedef HashCountedSet<Node*> TouchEventTargetSet; 237 238enum DocumentClass { 239 DefaultDocumentClass = 0, 240 HTMLDocumentClass = 1, 241 XHTMLDocumentClass = 1 << 1, 242 ImageDocumentClass = 1 << 2, 243 PluginDocumentClass = 1 << 3, 244 MediaDocumentClass = 1 << 4, 245 SVGDocumentClass = 1 << 5, 246 TextDocumentClass = 1 << 6 247}; 248 249typedef unsigned char DocumentClassFlags; 250 251enum class DocumentCompatibilityMode : unsigned char { 252 NoQuirksMode = 1, 253 QuirksMode = 1 << 1, 254 LimitedQuirksMode = 1 << 2 255}; 256 257class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext { 258public: 259 static PassRefPtr<Document> create(Frame* frame, const URL& url) 260 { 261 return adoptRef(new Document(frame, url)); 262 } 263 static PassRefPtr<Document> createXHTML(Frame* frame, const URL& url) 264 { 265 return adoptRef(new Document(frame, url, XHTMLDocumentClass)); 266 } 267 static PassRefPtr<Document> createNonRenderedPlaceholder(Frame* frame, const URL& url) 268 { 269 return adoptRef(new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder)); 270 } 271 static PassRefPtr<Document> create(ScriptExecutionContext&); 272 273 virtual ~Document(); 274 275 // Nodes belonging to this document increase referencingNodeCount - 276 // these are enough to keep the document from being destroyed, but 277 // not enough to keep it from removing its children. This allows a 278 // node that outlives its document to still have a valid document 279 // pointer without introducing reference cycles. 280 void incrementReferencingNodeCount() 281 { 282 ASSERT(!m_deletionHasBegun); 283 ++m_referencingNodeCount; 284 } 285 286 void decrementReferencingNodeCount() 287 { 288 ASSERT(!m_deletionHasBegun || !m_referencingNodeCount); 289 --m_referencingNodeCount; 290 if (!m_referencingNodeCount && !refCount()) { 291#if !ASSERT_DISABLED 292 m_deletionHasBegun = true; 293#endif 294 delete this; 295 } 296 } 297 298 unsigned referencingNodeCount() const { return m_referencingNodeCount; } 299 300 void removedLastRef(); 301 302 static HashSet<Document*>& allDocuments(); 303 304 MediaQueryMatcher& mediaQueryMatcher(); 305 306 using ContainerNode::ref; 307 using ContainerNode::deref; 308 309 virtual bool canContainRangeEndPoint() const override { return true; } 310 311 Element* getElementByAccessKey(const String& key); 312 void invalidateAccessKeyMap(); 313 314 void addImageElementByLowercasedUsemap(const AtomicStringImpl&, HTMLImageElement&); 315 void removeImageElementByLowercasedUsemap(const AtomicStringImpl&, HTMLImageElement&); 316 HTMLImageElement* imageElementByLowercasedUsemap(const AtomicStringImpl&) const; 317 318 SelectorQuery* selectorQueryForString(const String&, ExceptionCode&); 319 void clearSelectorQueryCache(); 320 321 // DOM methods & attributes for Document 322 323 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); 324 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); 325 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); 326 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu); 327 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick); 328 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter); 329 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover); 330 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave); 331 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop); 332 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart); 333 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag); 334 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend); 335 DEFINE_ATTRIBUTE_EVENT_LISTENER(input); 336 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid); 337 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown); 338 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress); 339 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup); 340 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown); 341 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseenter); 342 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseleave); 343 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove); 344 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout); 345 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover); 346 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup); 347 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel); 348 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll); 349 DEFINE_ATTRIBUTE_EVENT_LISTENER(select); 350 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit); 351#if ENABLE(WILL_REVEAL_EDGE_EVENTS) 352 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitwillrevealbottom); 353 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitwillrevealleft); 354 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitwillrevealright); 355 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitwillrevealtop); 356#endif 357 DEFINE_ATTRIBUTE_EVENT_LISTENER(wheel); 358 359 DEFINE_ATTRIBUTE_EVENT_LISTENER(blur); 360 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 361 DEFINE_ATTRIBUTE_EVENT_LISTENER(focus); 362 DEFINE_ATTRIBUTE_EVENT_LISTENER(load); 363 DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange); 364 365 // WebKit extensions 366 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut); 367 DEFINE_ATTRIBUTE_EVENT_LISTENER(cut); 368 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy); 369 DEFINE_ATTRIBUTE_EVENT_LISTENER(copy); 370 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste); 371 DEFINE_ATTRIBUTE_EVENT_LISTENER(paste); 372 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset); 373 DEFINE_ATTRIBUTE_EVENT_LISTENER(search); 374 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart); 375 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange); 376#if ENABLE(TOUCH_EVENTS) 377 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart); 378 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove); 379 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend); 380 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel); 381#endif 382#if ENABLE(IOS_GESTURE_EVENTS) 383 DEFINE_ATTRIBUTE_EVENT_LISTENER(gesturestart); 384 DEFINE_ATTRIBUTE_EVENT_LISTENER(gesturechange); 385 DEFINE_ATTRIBUTE_EVENT_LISTENER(gestureend); 386#endif 387#if ENABLE(FULLSCREEN_API) 388 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange); 389 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror); 390#endif 391#if ENABLE(POINTER_LOCK) 392 DEFINE_ATTRIBUTE_EVENT_LISTENER(pointerlockchange); 393 DEFINE_ATTRIBUTE_EVENT_LISTENER(pointerlockerror); 394#endif 395#if ENABLE(CSP_NEXT) 396 DEFINE_ATTRIBUTE_EVENT_LISTENER(securitypolicyviolation); 397#endif 398 399 void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; } 400 ViewportArguments viewportArguments() const { return m_viewportArguments; } 401#ifndef NDEBUG 402 bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; } 403#endif 404 405 void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; } 406 ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } 407 408 DocumentType* doctype() const; 409 410 DOMImplementation* implementation(); 411 412 Element* documentElement() const 413 { 414 return m_documentElement.get(); 415 } 416 static ptrdiff_t documentElementMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentElement); } 417 418 Element* activeElement(); 419 bool hasFocus() const; 420 421 bool hasManifest() const; 422 423 virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&); 424 PassRefPtr<DocumentFragment> createDocumentFragment(); 425 PassRefPtr<Text> createTextNode(const String& data); 426 PassRefPtr<Comment> createComment(const String& data); 427 PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionCode&); 428 PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&); 429 PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&); 430 PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false); 431 PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&); 432 PassRefPtr<Node> importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); } 433 PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&); 434 PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&); 435 PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser); 436 437 bool cssRegionsEnabled() const; 438 bool cssCompositingEnabled() const; 439#if ENABLE(CSS_REGIONS) 440 PassRefPtr<DOMNamedFlowCollection> webkitGetNamedFlows(); 441#endif 442 443 NamedFlowCollection* namedFlows(); 444 445 Element* elementFromPoint(int x, int y) const; 446 PassRefPtr<Range> caretRangeFromPoint(int x, int y); 447 448 String readyState() const; 449 450 String defaultCharset() const; 451 452 String inputEncoding() const { return Document::encoding(); } 453 String charset() const { return Document::encoding(); } 454 String characterSet() const { return Document::encoding(); } 455 456 AtomicString encoding() const; 457 458 void setCharset(const String&); 459 460 void setContent(const String&); 461 462 String suggestedMIMEType() const; 463 464 String contentLanguage() const { return m_contentLanguage; } 465 void setContentLanguage(const String&); 466 467 String xmlEncoding() const { return m_xmlEncoding; } 468 String xmlVersion() const { return m_xmlVersion; } 469 enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone }; 470 bool xmlStandalone() const { return m_xmlStandalone == Standalone; } 471 StandaloneStatus xmlStandaloneStatus() const { return static_cast<StandaloneStatus>(m_xmlStandalone); } 472 bool hasXMLDeclaration() const { return m_hasXMLDeclaration; } 473 474 void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser 475 void setXMLVersion(const String&, ExceptionCode&); 476 void setXMLStandalone(bool, ExceptionCode&); 477 void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; } 478 479 String documentURI() const { return m_documentURI; } 480 void setDocumentURI(const String&); 481 482 virtual URL baseURI() const override; 483 484#if ENABLE(WEB_REPLAY) 485 JSC::InputCursor& inputCursor() const { return *m_inputCursor; } 486 void setInputCursor(PassRefPtr<JSC::InputCursor>); 487#endif 488 489 void visibilityStateChanged(); 490 String visibilityState() const; 491 bool hidden() const; 492 493#if ENABLE(CSP_NEXT) 494 DOMSecurityPolicy* securityPolicy(); 495#endif 496 497 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&); 498 499 PassRefPtr<HTMLCollection> images(); 500 PassRefPtr<HTMLCollection> embeds(); 501 PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings. 502 PassRefPtr<HTMLCollection> applets(); 503 PassRefPtr<HTMLCollection> links(); 504 PassRefPtr<HTMLCollection> forms(); 505 PassRefPtr<HTMLCollection> anchors(); 506 PassRefPtr<HTMLCollection> scripts(); 507 PassRefPtr<HTMLCollection> all(); 508 509 PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name); 510 PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name); 511 512 // Other methods (not part of DOM) 513 bool isSynthesized() const { return m_isSynthesized; } 514 bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; } 515 bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; } 516 bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; } 517 bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; } 518 bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; } 519 bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; } 520 bool isTextDocument() const { return m_documentClasses & TextDocumentClass; } 521 bool hasSVGRootNode() const; 522 virtual bool isFrameSet() const { return false; } 523 524 static ptrdiff_t documentClassesMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentClasses); } 525 static uint32_t isHTMLDocumentClassFlag() { return HTMLDocumentClass; } 526 527 bool isSrcdocDocument() const { return m_isSrcdocDocument; } 528 529 StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); } 530 531 bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; } 532 533 StyleResolver& ensureStyleResolver() 534 { 535 if (!m_styleResolver) 536 createStyleResolver(); 537 return *m_styleResolver; 538 } 539 540 void notifyRemovePendingSheetIfNeeded(); 541 542 bool haveStylesheetsLoaded() const; 543 544 // This is a DOM function. 545 StyleSheetList* styleSheets(); 546 547 DocumentStyleSheetCollection& styleSheetCollection() { return m_styleSheetCollection; } 548 549 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; } 550 void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; } 551 552 /** 553 * Called when one or more stylesheets in the document may have been added, removed or changed. 554 * 555 * Creates a new style resolver and assign it to this document. This is done by iterating through all nodes in 556 * document (or those before <BODY> in a HTML document), searching for stylesheets. Stylesheets can be contained in 557 * <LINK>, <STYLE> or <BODY> elements, as well as processing instructions (XML documents only). A list is 558 * constructed from these which is used to create the a new style selector which collates all of the stylesheets 559 * found and is used to calculate the derived styles for all rendering objects. 560 */ 561 void styleResolverChanged(StyleResolverUpdateFlag); 562 563 void scheduleOptimizedStyleSheetUpdate(); 564 565 void evaluateMediaQueryList(); 566 567 FormController& formController(); 568 Vector<String> formElementsState() const; 569 void setStateForNewFormElements(const Vector<String>&); 570 571 FrameView* view() const; // can be NULL 572 Frame* frame() const { return m_frame; } // can be NULL 573 Page* page() const; // can be NULL 574 Settings* settings() const; // can be NULL 575 576 float deviceScaleFactor() const; 577 578 PassRefPtr<Range> createRange(); 579 580 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, 581 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&); 582 583 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, 584 PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionCode&); 585 586 // Special support for editing 587 PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration(); 588 PassRefPtr<Text> createEditingTextNode(const String&); 589 590 void recalcStyle(Style::Change = Style::NoChange); 591 void updateStyleIfNeeded(); 592 bool updateStyleIfNeededForNode(const Node&); 593 void updateLayout(); 594 enum RunPostLayoutTasks { 595 RunPostLayoutTasksAsynchronously, 596 RunPostLayoutTasksSynchronously, 597 }; 598 void updateLayoutIgnorePendingStylesheets(RunPostLayoutTasks = RunPostLayoutTasksAsynchronously); 599 PassRef<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*); 600 601 // Returns true if page box (margin boxes and page borders) is visible. 602 bool isPageBoxVisible(int pageIndex); 603 604 // Returns the preferred page size and margins in pixels, assuming 96 605 // pixels per inch. pageSize, marginTop, marginRight, marginBottom, 606 // marginLeft must be initialized to the default values that are used if 607 // auto is specified. 608 void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft); 609 610 CachedResourceLoader* cachedResourceLoader() { return m_cachedResourceLoader.get(); } 611 612 void didBecomeCurrentDocumentInFrame(); 613 void destroyRenderTree(); 614 void disconnectFromFrame(); 615 void prepareForDestruction(); 616 617 // Override ScriptExecutionContext methods to do additional work 618 virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) override; 619 virtual void resumeActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) override; 620 virtual void stopActiveDOMObjects() override; 621 622 RenderView* renderView() const { return m_renderView.get(); } 623 624 bool renderTreeBeingDestroyed() const { return m_renderTreeBeingDestroyed; } 625 bool hasLivingRenderTree() const { return renderView() && !renderTreeBeingDestroyed(); } 626 627 AXObjectCache* existingAXObjectCache() const; 628 AXObjectCache* axObjectCache() const; 629 void clearAXObjectCache(); 630 631 // to get visually ordered hebrew and arabic pages right 632 void setVisuallyOrdered(); 633 bool visuallyOrdered() const { return m_visuallyOrdered; } 634 635 DocumentLoader* loader() const; 636 637 void open(Document* ownerDocument = 0); 638 void implicitOpen(); 639 640 // close() is the DOM API document.close() 641 void close(); 642 // In some situations (see the code), we ignore document.close(). 643 // explicitClose() bypass these checks and actually tries to close the 644 // input stream. 645 void explicitClose(); 646 // implicitClose() actually does the work of closing the input stream. 647 void implicitClose(); 648 649 void cancelParsing(); 650 651 void write(const SegmentedString& text, Document* ownerDocument = 0); 652 void write(const String& text, Document* ownerDocument = 0); 653 void writeln(const String& text, Document* ownerDocument = 0); 654 655 bool wellFormed() const { return m_wellFormed; } 656 657 virtual const URL& url() const override final { return m_url; } 658 void setURL(const URL&); 659 660 // To understand how these concepts relate to one another, please see the 661 // comments surrounding their declaration. 662 const URL& baseURL() const { return m_baseURL; } 663 void setBaseURLOverride(const URL&); 664 const URL& baseURLOverride() const { return m_baseURLOverride; } 665 const URL& baseElementURL() const { return m_baseElementURL; } 666 const String& baseTarget() const { return m_baseTarget; } 667 void processBaseElement(); 668 669 virtual URL completeURL(const String&) const override final; 670 URL completeURL(const String&, const URL& baseURLOverride) const; 671 672 virtual String userAgent(const URL&) const override; 673 674 virtual void disableEval(const String& errorMessage) override; 675 676 bool canNavigate(Frame* targetFrame); 677 Frame* findUnsafeParentScrollPropagationBoundary(); 678 679 CSSStyleSheet& elementSheet(); 680 681 virtual PassRefPtr<DocumentParser> createParser(); 682 DocumentParser* parser() const { return m_parser.get(); } 683 ScriptableDocumentParser* scriptableDocumentParser() const; 684 685 bool printing() const { return m_printing; } 686 void setPrinting(bool p) { m_printing = p; } 687 688 bool paginatedForScreen() const { return m_paginatedForScreen; } 689 void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; } 690 691 bool paginated() const { return printing() || paginatedForScreen(); } 692 693 void setCompatibilityMode(DocumentCompatibilityMode); 694 void lockCompatibilityMode() { m_compatibilityModeLocked = true; } 695 static ptrdiff_t compatibilityModeMemoryOffset() { return OBJECT_OFFSETOF(Document, m_compatibilityMode); } 696 697 String compatMode() const; 698 699 bool inQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::QuirksMode; } 700 bool inLimitedQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::LimitedQuirksMode; } 701 bool inNoQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::NoQuirksMode; } 702 703 enum ReadyState { 704 Loading, 705 Interactive, 706 Complete 707 }; 708 void setReadyState(ReadyState); 709 void setParsing(bool); 710 bool parsing() const { return m_bParsing; } 711 std::chrono::milliseconds minimumLayoutDelay(); 712 713 bool shouldScheduleLayout(); 714 bool isLayoutTimerActive(); 715 std::chrono::milliseconds elapsedTime() const; 716 717 void setTextColor(const Color& color) { m_textColor = color; } 718 Color textColor() const { return m_textColor; } 719 720 const Color& linkColor() const { return m_linkColor; } 721 const Color& visitedLinkColor() const { return m_visitedLinkColor; } 722 const Color& activeLinkColor() const { return m_activeLinkColor; } 723 void setLinkColor(const Color& c) { m_linkColor = c; } 724 void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; } 725 void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; } 726 void resetLinkColor(); 727 void resetVisitedLinkColor(); 728 void resetActiveLinkColor(); 729 VisitedLinkState& visitedLinkState() const { return *m_visitedLinkState; } 730 731 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&); 732 733 /* Newly proposed CSS3 mechanism for selecting alternate 734 stylesheets using the DOM. May be subject to change as 735 spec matures. - dwh 736 */ 737 String preferredStylesheetSet() const; 738 String selectedStylesheetSet() const; 739 void setSelectedStylesheetSet(const String&); 740 741 bool setFocusedElement(PassRefPtr<Element>, FocusDirection = FocusDirectionNone); 742 Element* focusedElement() const { return m_focusedElement.get(); } 743 UserActionElementSet& userActionElements() { return m_userActionElements; } 744 const UserActionElementSet& userActionElements() const { return m_userActionElements; } 745 746 // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough 747 // for WebCore to ignore the autofocus attribute on any form controls 748 bool ignoreAutofocus() const { return m_ignoreAutofocus; }; 749 void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; }; 750 751 void removeFocusedNodeOfSubtree(Node*, bool amongChildrenOnly = false); 752 void hoveredElementDidDetach(Element*); 753 void elementInActiveChainDidDetach(Element*); 754 755 void updateHoverActiveState(const HitTestRequest&, Element*, StyleResolverUpdateFlag = RecalcStyleIfNeeded); 756 757 // Updates for :target (CSS3 selector). 758 void setCSSTarget(Element*); 759 Element* cssTarget() const { return m_cssTarget; } 760 static ptrdiff_t cssTargetMemoryOffset() { return OBJECT_OFFSETOF(Document, m_cssTarget); } 761 762 void scheduleForcedStyleRecalc(); 763 void scheduleStyleRecalc(); 764 void unscheduleStyleRecalc(); 765 bool hasPendingStyleRecalc() const; 766 bool hasPendingForcedStyleRecalc() const; 767 void styleRecalcTimerFired(Timer<Document>&); 768 void optimizedStyleSheetUpdateTimerFired(Timer<Document>&); 769 770 void registerNodeListForInvalidation(LiveNodeList&); 771 void unregisterNodeListForInvalidation(LiveNodeList&); 772 void registerCollection(HTMLCollection&); 773 void unregisterCollection(HTMLCollection&); 774 void collectionCachedIdNameMap(const HTMLCollection&); 775 void collectionWillClearIdNameMap(const HTMLCollection&); 776 bool shouldInvalidateNodeListAndCollectionCaches(const QualifiedName* attrName = nullptr) const; 777 void invalidateNodeListAndCollectionCaches(const QualifiedName* attrName); 778 779 void attachNodeIterator(NodeIterator*); 780 void detachNodeIterator(NodeIterator*); 781 void moveNodeIteratorsToNewDocument(Node*, Document*); 782 783 void attachRange(Range*); 784 void detachRange(Range*); 785 786 void updateRangesAfterChildrenChanged(ContainerNode&); 787 // nodeChildrenWillBeRemoved is used when removing all node children at once. 788 void nodeChildrenWillBeRemoved(ContainerNode&); 789 // nodeWillBeRemoved is only safe when removing one node at a time. 790 void nodeWillBeRemoved(Node*); 791 bool canReplaceChild(Node* newChild, Node* oldChild); 792 793 void textInserted(Node*, unsigned offset, unsigned length); 794 void textRemoved(Node*, unsigned offset, unsigned length); 795 void textNodesMerged(Text* oldNode, unsigned offset); 796 void textNodeSplit(Text* oldNode); 797 798 void createDOMWindow(); 799 void takeDOMWindowFrom(Document*); 800 801 DOMWindow* domWindow() const { return m_domWindow.get(); } 802 // In DOM Level 2, the Document's DOMWindow is called the defaultView. 803 DOMWindow* defaultView() const { return domWindow(); } 804 805 // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists. 806 void setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value); 807 void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>); 808 EventListener* getWindowAttributeEventListener(const AtomicString& eventType); 809 void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0); 810 void dispatchWindowLoadEvent(); 811 812 PassRefPtr<Event> createEvent(const String& eventType, ExceptionCode&); 813 814 // keep track of what types of event listeners are registered, so we don't 815 // dispatch events unnecessarily 816 enum ListenerType { 817 DOMSUBTREEMODIFIED_LISTENER = 1, 818 DOMNODEINSERTED_LISTENER = 1 << 1, 819 DOMNODEREMOVED_LISTENER = 1 << 2, 820 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 1 << 3, 821 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 1 << 4, 822 DOMCHARACTERDATAMODIFIED_LISTENER = 1 << 5, 823 OVERFLOWCHANGED_LISTENER = 1 << 6, 824 ANIMATIONEND_LISTENER = 1 << 7, 825 ANIMATIONSTART_LISTENER = 1 << 8, 826 ANIMATIONITERATION_LISTENER = 1 << 9, 827 TRANSITIONEND_LISTENER = 1 << 10, 828 BEFORELOAD_LISTENER = 1 << 11, 829 SCROLL_LISTENER = 1 << 12 830 // 3 bits remaining 831 }; 832 833 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); } 834 void addListenerTypeIfNeeded(const AtomicString& eventType); 835 836 bool hasMutationObserversOfType(MutationObserver::MutationType type) const 837 { 838 return m_mutationObserverTypes & type; 839 } 840 bool hasMutationObservers() const { return m_mutationObserverTypes; } 841 void addMutationObserverTypes(MutationObserverOptions types) { m_mutationObserverTypes |= types; } 842 843 CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt); 844 845 /** 846 * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called 847 * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta 848 * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being 849 * specified in a HTML file. 850 * 851 * @param equiv The http header name (value of the meta tag's "equiv" attribute) 852 * @param content The header value (value of the meta tag's "content" attribute) 853 */ 854 void processHttpEquiv(const String& equiv, const String& content); 855 856#if PLATFORM(IOS) 857 void processFormatDetection(const String&); 858 859 // Called when <meta name="apple-mobile-web-app-orientations"> changes. 860 void processWebAppOrientations(); 861#endif 862 863 void processViewport(const String& features, ViewportArguments::Type origin); 864 void updateViewportArguments(); 865 void processReferrerPolicy(const String& policy); 866 867 // Returns the owning element in the parent document. 868 // Returns 0 if this is the top level document. 869 HTMLFrameOwnerElement* ownerElement() const; 870 871 // Used by DOM bindings; no direction known. 872 String title() const { return m_title.string(); } 873 void setTitle(const String&); 874 875 void setTitleElement(const StringWithDirection&, Element* titleElement); 876 void removeTitle(Element* titleElement); 877 878 String cookie(ExceptionCode&) const; 879 void setCookie(const String&, ExceptionCode&); 880 881 String referrer() const; 882 883 String origin() const; 884 885 String domain() const; 886 void setDomain(const String& newDomain, ExceptionCode&); 887 888 String lastModified() const; 889 890 // The cookieURL is used to query the cookie database for this document's 891 // cookies. For example, if the cookie URL is http://example.com, we'll 892 // use the non-Secure cookies for example.com when computing 893 // document.cookie. 894 // 895 // Q: How is the cookieURL different from the document's URL? 896 // A: The two URLs are the same almost all the time. However, if one 897 // document inherits the security context of another document, it 898 // inherits its cookieURL but not its URL. 899 // 900 const URL& cookieURL() const { return m_cookieURL; } 901 void setCookieURL(const URL& url) { m_cookieURL = url; } 902 903 // The firstPartyForCookies is used to compute whether this document 904 // appears in a "third-party" context for the purpose of third-party 905 // cookie blocking. The document is in a third-party context if the 906 // cookieURL and the firstPartyForCookies are from different hosts. 907 // 908 // Note: Some ports (including possibly Apple's) only consider the 909 // document in a third-party context if the cookieURL and the 910 // firstPartyForCookies have a different registry-controlled 911 // domain. 912 // 913 const URL& firstPartyForCookies() const { return m_firstPartyForCookies; } 914 void setFirstPartyForCookies(const URL& url) { m_firstPartyForCookies = url; } 915 916 // The following implements the rule from HTML 4 for what valid names are. 917 // To get this right for all the XML cases, we probably have to improve this or move it 918 // and make it sensitive to the type of document. 919 static bool isValidName(const String&); 920 921 // The following breaks a qualified name into a prefix and a local name. 922 // It also does a validity check, and returns false if the qualified name 923 // is invalid. It also sets ExceptionCode when name is invalid. 924 static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode&); 925 926 // Checks to make sure prefix and namespace do not conflict (per DOM Core 3) 927 static bool hasValidNamespaceForElements(const QualifiedName&); 928 static bool hasValidNamespaceForAttributes(const QualifiedName&); 929 930 HTMLElement* body() const; 931 void setBody(PassRefPtr<HTMLElement>, ExceptionCode&); 932 933 HTMLHeadElement* head(); 934 935 DocumentMarkerController& markers() const { return *m_markers; } 936 937 bool directionSetOnDocumentElement() const { return m_directionSetOnDocumentElement; } 938 bool writingModeSetOnDocumentElement() const { return m_writingModeSetOnDocumentElement; } 939 void setDirectionSetOnDocumentElement(bool b) { m_directionSetOnDocumentElement = b; } 940 void setWritingModeSetOnDocumentElement(bool b) { m_writingModeSetOnDocumentElement = b; } 941 942 bool execCommand(const String& command, bool userInterface = false, const String& value = String()); 943 bool queryCommandEnabled(const String& command); 944 bool queryCommandIndeterm(const String& command); 945 bool queryCommandState(const String& command); 946 bool queryCommandSupported(const String& command); 947 String queryCommandValue(const String& command); 948 949 // designMode support 950 enum InheritedBool { off = false, on = true, inherit }; 951 void setDesignMode(InheritedBool value); 952 InheritedBool getDesignMode() const; 953 bool inDesignMode() const; 954 955 Document* parentDocument() const; 956 Document& topDocument() const; 957 958 ScriptRunner* scriptRunner() { return m_scriptRunner.get(); } 959 960 HTMLScriptElement* currentScript() const { return !m_currentScriptStack.isEmpty() ? m_currentScriptStack.last().get() : 0; } 961 void pushCurrentScript(PassRefPtr<HTMLScriptElement>); 962 void popCurrentScript(); 963 964#if ENABLE(XSLT) 965 void applyXSLTransform(ProcessingInstruction* pi); 966 PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; } 967 void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; } 968 969 void setTransformSource(std::unique_ptr<TransformSource>); 970 TransformSource* transformSource() const { return m_transformSource.get(); } 971#endif 972 973 void incDOMTreeVersion() { m_domTreeVersion = ++s_globalTreeVersion; } 974 uint64_t domTreeVersion() const { return m_domTreeVersion; } 975 976 // XPathEvaluator methods 977 PassRefPtr<XPathExpression> createExpression(const String& expression, 978 XPathNSResolver* resolver, 979 ExceptionCode& ec); 980 PassRefPtr<XPathNSResolver> createNSResolver(Node *nodeResolver); 981 PassRefPtr<XPathResult> evaluate(const String& expression, 982 Node* contextNode, 983 XPathNSResolver* resolver, 984 unsigned short type, 985 XPathResult* result, 986 ExceptionCode& ec); 987 988 enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets }; 989 990 bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; } 991 992 bool hasNodesWithPlaceholderStyle() const { return m_hasNodesWithPlaceholderStyle; } 993 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; } 994 995 const Vector<IconURL>& shortcutIconURLs(); 996 const Vector<IconURL>& iconURLs(int iconTypesMask); 997 void addIconURL(const String& url, const String& mimeType, const String& size, IconType); 998 999 void updateFocusAppearanceSoon(bool restorePreviousSelection); 1000 void cancelFocusAppearanceUpdate(); 1001 1002 // Extension for manipulating canvas drawing contexts for use in CSS 1003 CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height); 1004 HTMLCanvasElement* getCSSCanvasElement(const String& name); 1005 1006 bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; } 1007 void parseDNSPrefetchControlHeader(const String&); 1008 1009 virtual void postTask(Task) override; // Executes the task on context's thread asynchronously. 1010 1011 void suspendScriptedAnimationControllerCallbacks(); 1012 void resumeScriptedAnimationControllerCallbacks(); 1013 virtual void scriptedAnimationControllerSetThrottled(bool); 1014 1015 void windowScreenDidChange(PlatformDisplayID); 1016 1017 void finishedParsing(); 1018 1019 bool inPageCache() const { return m_inPageCache; } 1020 void setInPageCache(bool flag); 1021 1022 // Elements can register themselves for the "documentWillSuspendForPageCache()" and 1023 // "documentDidResumeFromPageCache()" callbacks 1024 void registerForPageCacheSuspensionCallbacks(Element*); 1025 void unregisterForPageCacheSuspensionCallbacks(Element*); 1026 1027 void documentWillBecomeInactive(); 1028 void documentWillSuspendForPageCache(); 1029 void documentDidResumeFromPageCache(); 1030 1031 void registerForMediaVolumeCallbacks(Element*); 1032 void unregisterForMediaVolumeCallbacks(Element*); 1033 void mediaVolumeDidChange(); 1034 1035 void registerForPrivateBrowsingStateChangedCallbacks(Element*); 1036 void unregisterForPrivateBrowsingStateChangedCallbacks(Element*); 1037 void storageBlockingStateDidChange(); 1038 void privateBrowsingStateDidChange(); 1039 1040#if ENABLE(VIDEO_TRACK) 1041 void registerForCaptionPreferencesChangedCallbacks(Element*); 1042 void unregisterForCaptionPreferencesChangedCallbacks(Element*); 1043 void captionPreferencesChanged(); 1044#endif 1045 1046#if ENABLE(MEDIA_CONTROLS_SCRIPT) 1047 void registerForPageScaleFactorChangedCallbacks(HTMLMediaElement*); 1048 void unregisterForPageScaleFactorChangedCallbacks(HTMLMediaElement*); 1049 void pageScaleFactorChangedAndStable(); 1050#endif 1051 1052 void registerForVisibilityStateChangedCallbacks(Element*); 1053 void unregisterForVisibilityStateChangedCallbacks(Element*); 1054 1055 void setShouldCreateRenderers(bool); 1056 bool shouldCreateRenderers(); 1057 1058 void setDecoder(PassRefPtr<TextResourceDecoder>); 1059 TextResourceDecoder* decoder() const { return m_decoder.get(); } 1060 1061 String displayStringModifiedByEncoding(const String&) const; 1062 PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const; 1063 void displayBufferModifiedByEncoding(LChar* buffer, unsigned len) const 1064 { 1065 displayBufferModifiedByEncodingInternal(buffer, len); 1066 } 1067 void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const 1068 { 1069 displayBufferModifiedByEncodingInternal(buffer, len); 1070 } 1071 1072 // Quirk for the benefit of Apple's Dictionary application. 1073 void setFrameElementsShouldIgnoreScrolling(bool ignore) { m_frameElementsShouldIgnoreScrolling = ignore; } 1074 bool frameElementsShouldIgnoreScrolling() const { return m_frameElementsShouldIgnoreScrolling; } 1075 1076#if ENABLE(DASHBOARD_SUPPORT) 1077 void setAnnotatedRegionsDirty(bool f) { m_annotatedRegionsDirty = f; } 1078 bool annotatedRegionsDirty() const { return m_annotatedRegionsDirty; } 1079 bool hasAnnotatedRegions () const { return m_hasAnnotatedRegions; } 1080 void setHasAnnotatedRegions(bool f) { m_hasAnnotatedRegions = f; } 1081 const Vector<AnnotatedRegionValue>& annotatedRegions() const; 1082 void setAnnotatedRegions(const Vector<AnnotatedRegionValue>&); 1083#endif 1084 1085 virtual void removeAllEventListeners() override; 1086 1087 const SVGDocumentExtensions* svgExtensions(); 1088 SVGDocumentExtensions* accessSVGExtensions(); 1089 1090 void initSecurityContext(); 1091 void initContentSecurityPolicy(); 1092 1093 void updateURLForPushOrReplaceState(const URL&); 1094 void statePopped(PassRefPtr<SerializedScriptValue>); 1095 1096 bool processingLoadEvent() const { return m_processingLoadEvent; } 1097 bool loadEventFinished() const { return m_loadEventFinished; } 1098 1099 virtual bool isContextThread() const override; 1100 virtual bool isJSExecutionForbidden() const override { return false; } 1101 1102 bool containsValidityStyleRules() const { return m_containsValidityStyleRules; } 1103 void setContainsValidityStyleRules() { m_containsValidityStyleRules = true; } 1104 1105 void enqueueWindowEvent(PassRefPtr<Event>); 1106 void enqueueDocumentEvent(PassRefPtr<Event>); 1107 void enqueueOverflowEvent(PassRefPtr<Event>); 1108 void enqueuePageshowEvent(PageshowEventPersistence); 1109 void enqueueHashchangeEvent(const String& oldURL, const String& newURL); 1110 void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject); 1111 virtual DocumentEventQueue& eventQueue() const override { return m_eventQueue; } 1112 1113 void addMediaCanStartListener(MediaCanStartListener*); 1114 void removeMediaCanStartListener(MediaCanStartListener*); 1115 MediaCanStartListener* takeAnyMediaCanStartListener(); 1116 1117#if ENABLE(FULLSCREEN_API) 1118 bool webkitIsFullScreen() const { return m_fullScreenElement.get(); } 1119 bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; } 1120 Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); } 1121 1122 enum FullScreenCheckType { 1123 EnforceIFrameAllowFullScreenRequirement, 1124 ExemptIFrameAllowFullScreenRequirement, 1125 }; 1126 1127 void requestFullScreenForElement(Element*, unsigned short flags, FullScreenCheckType); 1128 void webkitCancelFullScreen(); 1129 1130 void webkitWillEnterFullScreenForElement(Element*); 1131 void webkitDidEnterFullScreenForElement(Element*); 1132 void webkitWillExitFullScreenForElement(Element*); 1133 void webkitDidExitFullScreenForElement(Element*); 1134 1135 void setFullScreenRenderer(RenderFullScreen*); 1136 RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer; } 1137 void fullScreenRendererDestroyed(); 1138 1139 void fullScreenChangeDelayTimerFired(Timer<Document>&); 1140 bool fullScreenIsAllowedForElement(Element*) const; 1141 void fullScreenElementRemoved(); 1142 void removeFullScreenElementOfSubtree(Node*, bool amongChildrenOnly = false); 1143 bool isAnimatingFullScreen() const; 1144 void setAnimatingFullScreen(bool); 1145 1146 // W3C API 1147 bool webkitFullscreenEnabled() const; 1148 Element* webkitFullscreenElement() const { return !m_fullScreenElementStack.isEmpty() ? m_fullScreenElementStack.last().get() : 0; } 1149 void webkitExitFullscreen(); 1150#endif 1151 1152#if ENABLE(POINTER_LOCK) 1153 void exitPointerLock(); 1154 Element* pointerLockElement() const; 1155#endif 1156 1157 // Used to allow element that loads data without going through a FrameLoader to delay the 'load' event. 1158 void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; } 1159 void decrementLoadEventDelayCount(); 1160 bool isDelayingLoadEvent() const { return m_loadEventDelayCount; } 1161 1162#if ENABLE(TOUCH_EVENTS) 1163#if PLATFORM(IOS) 1164#include <WebKitAdditions/DocumentIOS.h> 1165#else 1166 PassRefPtr<Touch> createTouch(DOMWindow*, EventTarget*, int identifier, int pageX, int pageY, int screenX, int screenY, int radiusX, int radiusY, float rotationAngle, float force, ExceptionCode&) const; 1167#endif // PLATFORM(IOS) 1168#endif 1169 1170#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS) 1171 DeviceMotionController* deviceMotionController() const; 1172 DeviceOrientationController* deviceOrientationController() const; 1173#endif 1174 1175#if ENABLE(WEB_TIMING) 1176 const DocumentTiming* timing() const { return &m_documentTiming; } 1177#endif 1178 1179#if ENABLE(REQUEST_ANIMATION_FRAME) 1180 int requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>); 1181 void cancelAnimationFrame(int id); 1182 void serviceScriptedAnimations(double monotonicAnimationStartTime); 1183#endif 1184 1185 void sendWillRevealEdgeEventsIfNeeded(const IntPoint& oldPosition, const IntPoint& newPosition, const IntRect& visibleRect, const IntSize& contentsSize, Element* target = nullptr); 1186 1187 virtual EventTarget* errorEventTarget() override; 1188 virtual void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtr<Inspector::ScriptCallStack>) override; 1189 1190 void initDNSPrefetch(); 1191 1192 unsigned wheelEventHandlerCount() const { return m_wheelEventHandlerCount; } 1193 void didAddWheelEventHandler(); 1194 void didRemoveWheelEventHandler(); 1195 1196 double lastHandledUserGestureTimestamp() const { return m_lastHandledUserGestureTimestamp; } 1197 void resetLastHandledUserGestureTimestamp(); 1198 1199#if ENABLE(TOUCH_EVENTS) 1200 bool hasTouchEventHandlers() const { return (m_touchEventTargets.get()) ? m_touchEventTargets->size() : false; } 1201#else 1202 bool hasTouchEventHandlers() const { return false; } 1203#endif 1204 1205 void didAddTouchEventHandler(Node*); 1206 void didRemoveTouchEventHandler(Node*); 1207 1208#if ENABLE(TOUCH_EVENTS) 1209 void didRemoveEventTargetNode(Node*); 1210#endif 1211 1212#if ENABLE(TOUCH_EVENTS) 1213 const TouchEventTargetSet* touchEventTargets() const { return m_touchEventTargets.get(); } 1214#else 1215 const TouchEventTargetSet* touchEventTargets() const { return 0; } 1216#endif 1217 1218 bool visualUpdatesAllowed() const { return m_visualUpdatesAllowed; } 1219 1220 bool isInDocumentWrite() { return m_writeRecursionDepth > 0; } 1221 1222 void suspendScheduledTasks(ActiveDOMObject::ReasonForSuspension); 1223 void resumeScheduledTasks(ActiveDOMObject::ReasonForSuspension); 1224 1225#if ENABLE(CSS_DEVICE_ADAPTATION) 1226 IntSize initialViewportSize() const; 1227#endif 1228 1229#if ENABLE(TEXT_AUTOSIZING) 1230 TextAutosizer* textAutosizer() { return m_textAutosizer.get(); } 1231#endif 1232 1233 void adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>&, const RenderStyle&); 1234 void adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect&, const RenderStyle&); 1235 1236 bool hasActiveParser(); 1237 void incrementActiveParserCount() { ++m_activeParserCount; } 1238 void decrementActiveParserCount(); 1239 1240 DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); } 1241 1242 void didRemoveAllPendingStylesheet(); 1243 void setNeedsNotifyRemoveAllPendingStylesheet() { m_needsNotifyRemoveAllPendingStylesheet = true; } 1244 void clearStyleResolver(); 1245 1246 bool inStyleRecalc() { return m_inStyleRecalc; } 1247 1248 // Return a Locale for the default locale if the argument is null or empty. 1249 Locale& getCachedLocale(const AtomicString& locale = nullAtom); 1250 1251#if ENABLE(TEMPLATE_ELEMENT) 1252 const Document* templateDocument() const; 1253 Document* ensureTemplateDocument(); 1254 void setTemplateDocumentHost(Document* templateDocumentHost) { m_templateDocumentHost = templateDocumentHost; } 1255 Document* templateDocumentHost() { return m_templateDocumentHost; } 1256#endif 1257 1258 void didAssociateFormControl(Element*); 1259 bool hasDisabledFieldsetElement() const { return m_disabledFieldsetElementsCount; } 1260 void addDisabledFieldsetElement() { m_disabledFieldsetElementsCount++; } 1261 void removeDisabledFieldsetElement() { ASSERT(m_disabledFieldsetElementsCount); m_disabledFieldsetElementsCount--; } 1262 1263 virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) override; 1264 1265 virtual SecurityOrigin* topOrigin() const override; 1266 1267#if ENABLE(FONT_LOAD_EVENTS) 1268 PassRefPtr<FontLoader> fontloader(); 1269#endif 1270 1271 void ensurePlugInsInjectedScript(DOMWrapperWorld&); 1272 1273 void setVisualUpdatesAllowedByClient(bool); 1274 1275#if ENABLE(SUBTLE_CRYPTO) 1276 virtual bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) override; 1277 virtual bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) override; 1278#endif 1279 1280 void setHasStyleWithViewportUnits() { m_hasStyleWithViewportUnits = true; } 1281 bool hasStyleWithViewportUnits() const { return m_hasStyleWithViewportUnits; } 1282 void updateViewportUnitsOnResize(); 1283 1284protected: 1285 enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 }; 1286 Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0); 1287 1288 void clearXMLVersion() { m_xmlVersion = String(); } 1289 1290 virtual PassRefPtr<Document> cloneDocumentWithoutChildren() const; 1291 1292private: 1293 friend class Node; 1294 friend class IgnoreDestructiveWriteCountIncrementer; 1295 1296 void commonTeardown(); 1297 1298 RenderObject* renderer() const = delete; 1299 void setRenderer(RenderObject*) = delete; 1300 1301 void createRenderTree(); 1302 void detachParser(); 1303 1304 typedef void (*ArgumentsCallback)(const String& keyString, const String& valueString, Document*, void* data); 1305 void processArguments(const String& features, void* data, ArgumentsCallback); 1306 1307 virtual bool isDocument() const override { return true; } 1308 1309 virtual void childrenChanged(const ChildChange&) override; 1310 1311 virtual String nodeName() const override; 1312 virtual NodeType nodeType() const override; 1313 virtual bool childTypeAllowed(NodeType) const override; 1314 virtual PassRefPtr<Node> cloneNode(bool deep) override; 1315 void cloneDataFromDocument(const Document&); 1316 1317 virtual void refScriptExecutionContext() override { ref(); } 1318 virtual void derefScriptExecutionContext() override { deref(); } 1319 1320 virtual void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<Inspector::ScriptCallStack>, JSC::ExecState* = 0, unsigned long requestIdentifier = 0) override; 1321 1322 virtual double minimumTimerInterval() const override; 1323 1324 virtual double timerAlignmentInterval() const override; 1325 1326 void updateTitle(const StringWithDirection&); 1327 void updateFocusAppearanceTimerFired(Timer<Document>&); 1328 void updateBaseURL(); 1329 1330 void buildAccessKeyMap(TreeScope* root); 1331 1332 void createStyleResolver(); 1333 1334 void loadEventDelayTimerFired(Timer<Document>&); 1335 1336 void pendingTasksTimerFired(Timer<Document>&); 1337 1338 template <typename CharacterType> 1339 void displayBufferModifiedByEncodingInternal(CharacterType*, unsigned) const; 1340 1341 PageVisibilityState pageVisibilityState() const; 1342 1343 PassRefPtr<HTMLCollection> ensureCachedCollection(CollectionType); 1344 1345#if ENABLE(FULLSCREEN_API) 1346 void dispatchFullScreenChangeOrErrorEvent(Deque<RefPtr<Node>>&, const AtomicString& eventName, bool shouldNotifyMediaElement); 1347 void clearFullscreenElementStack(); 1348 void popFullscreenElementStack(); 1349 void pushFullscreenElementStack(Element*); 1350 void addDocumentToFullScreenChangeEventQueue(Document*); 1351#endif 1352 1353 void setVisualUpdatesAllowed(ReadyState); 1354 void setVisualUpdatesAllowed(bool); 1355 void visualUpdatesSuppressionTimerFired(Timer<Document>&); 1356 1357 void addListenerType(ListenerType listenerType) { m_listenerTypes |= listenerType; } 1358 1359 void didAssociateFormControlsTimerFired(Timer<Document>&); 1360 1361 unsigned m_referencingNodeCount; 1362 1363 std::unique_ptr<StyleResolver> m_styleResolver; 1364 bool m_didCalculateStyleResolver; 1365 bool m_hasNodesWithPlaceholderStyle; 1366 bool m_needsNotifyRemoveAllPendingStylesheet; 1367 // But sometimes you need to ignore pending stylesheet count to 1368 // force an immediate layout when requested by JS. 1369 bool m_ignorePendingStylesheets; 1370 1371 // If we do ignore the pending stylesheet count, then we need to add a boolean 1372 // to track that this happened so that we can do a full repaint when the stylesheets 1373 // do eventually load. 1374 PendingSheetLayout m_pendingSheetLayout; 1375 1376 Frame* m_frame; 1377 RefPtr<DOMWindow> m_domWindow; 1378 1379 RefPtr<CachedResourceLoader> m_cachedResourceLoader; 1380 RefPtr<DocumentParser> m_parser; 1381 unsigned m_activeParserCount; 1382 1383 bool m_wellFormed; 1384 1385 // Document URLs. 1386 URL m_url; // Document.URL: The URL from which this document was retrieved. 1387 URL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs. 1388 URL m_baseURLOverride; // An alternative base URL that takes precedence over m_baseURL (but not m_baseElementURL). 1389 URL m_baseElementURL; // The URL set by the <base> element. 1390 URL m_cookieURL; // The URL to use for cookie access. 1391 URL m_firstPartyForCookies; // The policy URL for third-party cookie blocking. 1392 1393 // Document.documentURI: 1394 // Although URL-like, Document.documentURI can actually be set to any 1395 // string by content. Document.documentURI affects m_baseURL unless the 1396 // document contains a <base> element, in which case the <base> element 1397 // takes precedence. 1398 // 1399 // This property is read-only from JavaScript, but writable from Objective C. 1400 String m_documentURI; 1401 1402 String m_baseTarget; 1403 1404 std::unique_ptr<DOMImplementation> m_implementation; 1405 1406 RefPtr<CSSStyleSheet> m_elementSheet; 1407 1408 bool m_printing; 1409 bool m_paginatedForScreen; 1410 1411 bool m_ignoreAutofocus; 1412 1413 DocumentCompatibilityMode m_compatibilityMode; 1414 bool m_compatibilityModeLocked; // This is cheaper than making setCompatibilityMode virtual. 1415 1416 Color m_textColor; 1417 1418 RefPtr<Element> m_focusedElement; 1419 RefPtr<Element> m_hoveredElement; 1420 RefPtr<Element> m_activeElement; 1421 RefPtr<Element> m_documentElement; 1422 UserActionElementSet m_userActionElements; 1423 1424 uint64_t m_domTreeVersion; 1425 static uint64_t s_globalTreeVersion; 1426 1427 HashSet<NodeIterator*> m_nodeIterators; 1428 HashSet<Range*> m_ranges; 1429 1430 unsigned short m_listenerTypes; 1431 1432 MutationObserverOptions m_mutationObserverTypes; 1433 1434 DocumentStyleSheetCollection m_styleSheetCollection; 1435 RefPtr<StyleSheetList> m_styleSheetList; 1436 1437 std::unique_ptr<FormController> m_formController; 1438 1439 Color m_linkColor; 1440 Color m_visitedLinkColor; 1441 Color m_activeLinkColor; 1442 const std::unique_ptr<VisitedLinkState> m_visitedLinkState; 1443 1444 bool m_visuallyOrdered; 1445 ReadyState m_readyState; 1446 bool m_bParsing; 1447 1448 Timer<Document> m_optimizedStyleSheetUpdateTimer; 1449 Timer<Document> m_styleRecalcTimer; 1450 bool m_pendingStyleRecalcShouldForce; 1451 bool m_inStyleRecalc; 1452 bool m_closeAfterStyleRecalc; 1453 1454 bool m_gotoAnchorNeededAfterStylesheetsLoad; 1455 bool m_isDNSPrefetchEnabled; 1456 bool m_haveExplicitlyDisabledDNSPrefetch; 1457 bool m_frameElementsShouldIgnoreScrolling; 1458 bool m_containsValidityStyleRules; 1459 bool m_updateFocusAppearanceRestoresSelection; 1460 1461 // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter 1462 unsigned m_ignoreDestructiveWriteCount; 1463 1464 StringWithDirection m_title; 1465 StringWithDirection m_rawTitle; 1466 bool m_titleSetExplicitly; 1467 RefPtr<Element> m_titleElement; 1468 1469 std::unique_ptr<AXObjectCache> m_axObjectCache; 1470 const std::unique_ptr<DocumentMarkerController> m_markers; 1471 1472 Timer<Document> m_updateFocusAppearanceTimer; 1473 1474 Element* m_cssTarget; 1475 1476 // FIXME: Merge these 2 variables into an enum. Also, FrameLoader::m_didCallImplicitClose 1477 // is almost a duplication of this data, so that should probably get merged in too. 1478 // FIXME: Document::m_processingLoadEvent and DocumentLoader::m_wasOnloadHandled are roughly the same 1479 // and should be merged. 1480 bool m_processingLoadEvent; 1481 bool m_loadEventFinished; 1482 1483 RefPtr<SerializedScriptValue> m_pendingStateObject; 1484 std::chrono::steady_clock::time_point m_startTime; 1485 bool m_overMinimumLayoutThreshold; 1486 1487 std::unique_ptr<ScriptRunner> m_scriptRunner; 1488 1489 Vector<RefPtr<HTMLScriptElement>> m_currentScriptStack; 1490 1491#if ENABLE(XSLT) 1492 std::unique_ptr<TransformSource> m_transformSource; 1493 RefPtr<Document> m_transformSourceDocument; 1494#endif 1495 1496 String m_xmlEncoding; 1497 String m_xmlVersion; 1498 unsigned m_xmlStandalone : 2; 1499 unsigned m_hasXMLDeclaration : 1; 1500 1501 String m_contentLanguage; 1502 1503 RefPtr<TextResourceDecoder> m_decoder; 1504 1505 InheritedBool m_designMode; 1506 1507 HashSet<LiveNodeList*> m_listsInvalidatedAtDocument; 1508 HashSet<HTMLCollection*> m_collectionsInvalidatedAtDocument; 1509#if !ASSERT_DISABLED 1510 bool m_inInvalidateNodeListAndCollectionCaches; 1511#endif 1512 1513 unsigned m_nodeListAndCollectionCounts[numNodeListInvalidationTypes]; 1514 1515 RefPtr<XPathEvaluator> m_xpathEvaluator; 1516 1517 std::unique_ptr<SVGDocumentExtensions> m_svgExtensions; 1518 1519#if ENABLE(DASHBOARD_SUPPORT) 1520 Vector<AnnotatedRegionValue> m_annotatedRegions; 1521 bool m_hasAnnotatedRegions; 1522 bool m_annotatedRegionsDirty; 1523#endif 1524 1525 HashMap<String, RefPtr<HTMLCanvasElement>> m_cssCanvasElements; 1526 1527 bool m_createRenderers; 1528 bool m_inPageCache; 1529 Vector<IconURL> m_iconURLs; 1530 1531 HashSet<Element*> m_documentSuspensionCallbackElements; 1532 HashSet<Element*> m_mediaVolumeCallbackElements; 1533 HashSet<Element*> m_privateBrowsingStateChangedElements; 1534#if ENABLE(VIDEO_TRACK) 1535 HashSet<Element*> m_captionPreferencesChangedElements; 1536#endif 1537 1538#if ENABLE(MEDIA_CONTROLS_SCRIPT) 1539 HashSet<HTMLMediaElement*> m_pageScaleFactorChangedElements; 1540#endif 1541 1542 HashSet<Element*> m_visibilityStateCallbackElements; 1543 1544 HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKey; 1545 bool m_accessKeyMapValid; 1546 1547 DocumentOrderedMap m_imagesByUsemap; 1548 1549 std::unique_ptr<SelectorQueryCache> m_selectorQueryCache; 1550 1551 DocumentClassFlags m_documentClasses; 1552 1553 bool m_isSynthesized; 1554 bool m_isNonRenderedPlaceholder; 1555 1556 bool m_sawElementsInKnownNamespaces; 1557 bool m_isSrcdocDocument; 1558 1559 RenderPtr<RenderView> m_renderView; 1560 mutable DocumentEventQueue m_eventQueue; 1561 1562 WeakPtrFactory<Document> m_weakFactory; 1563 1564 HashSet<MediaCanStartListener*> m_mediaCanStartListeners; 1565 1566#if ENABLE(FULLSCREEN_API) 1567 bool m_areKeysEnabledInFullScreen; 1568 RefPtr<Element> m_fullScreenElement; 1569 Vector<RefPtr<Element>> m_fullScreenElementStack; 1570 RenderFullScreen* m_fullScreenRenderer; 1571 Timer<Document> m_fullScreenChangeDelayTimer; 1572 Deque<RefPtr<Node>> m_fullScreenChangeEventTargetQueue; 1573 Deque<RefPtr<Node>> m_fullScreenErrorEventTargetQueue; 1574 bool m_isAnimatingFullScreen; 1575 LayoutRect m_savedPlaceholderFrameRect; 1576 RefPtr<RenderStyle> m_savedPlaceholderRenderStyle; 1577#endif 1578 1579 int m_loadEventDelayCount; 1580 Timer<Document> m_loadEventDelayTimer; 1581 1582 ViewportArguments m_viewportArguments; 1583 1584 ReferrerPolicy m_referrerPolicy; 1585 1586 bool m_directionSetOnDocumentElement; 1587 bool m_writingModeSetOnDocumentElement; 1588 1589#if ENABLE(WEB_TIMING) 1590 DocumentTiming m_documentTiming; 1591#endif 1592 1593 RefPtr<MediaQueryMatcher> m_mediaQueryMatcher; 1594 bool m_writeRecursionIsTooDeep; 1595 unsigned m_writeRecursionDepth; 1596 1597 unsigned m_wheelEventHandlerCount; 1598#if ENABLE(TOUCH_EVENTS) 1599 std::unique_ptr<TouchEventTargetSet> m_touchEventTargets; 1600#endif 1601 1602 double m_lastHandledUserGestureTimestamp; 1603 1604#if ENABLE(REQUEST_ANIMATION_FRAME) 1605 void clearScriptedAnimationController(); 1606 RefPtr<ScriptedAnimationController> m_scriptedAnimationController; 1607#endif 1608 1609#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS) 1610 std::unique_ptr<DeviceMotionClient> m_deviceMotionClient; 1611 std::unique_ptr<DeviceMotionController> m_deviceMotionController; 1612 std::unique_ptr<DeviceOrientationClient> m_deviceOrientationClient; 1613 std::unique_ptr<DeviceOrientationController> m_deviceOrientationController; 1614#endif 1615 1616// FIXME: Find a better place for this functionality. 1617#if ENABLE(TELEPHONE_NUMBER_DETECTION) 1618public: 1619 1620 // These functions provide a two-level setting: 1621 // - A user-settable wantsTelephoneNumberParsing (at the Page / WebView level) 1622 // - A read-only telephoneNumberParsingAllowed which is set by the 1623 // document if it has the appropriate meta tag. 1624 // - isTelephoneNumberParsingEnabled() == isTelephoneNumberParsingAllowed() && page()->settings()->isTelephoneNumberParsingEnabled() 1625 1626 bool isTelephoneNumberParsingAllowed() const; 1627 bool isTelephoneNumberParsingEnabled() const; 1628 1629private: 1630 friend void setParserFeature(const String& key, const String& value, Document*, void* userData); 1631 void setIsTelephoneNumberParsingAllowed(bool); 1632 1633 bool m_isTelephoneNumberParsingAllowed; 1634#endif 1635 1636 Timer<Document> m_pendingTasksTimer; 1637 Vector<Task> m_pendingTasks; 1638 1639#if ENABLE(IOS_TEXT_AUTOSIZING) 1640public: 1641 void addAutoSizingNode(Node*, float size); 1642 void validateAutoSizingNodes(); 1643 void resetAutoSizingNodes(); 1644 1645private: 1646 typedef HashMap<TextAutoSizingKey, RefPtr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits> TextAutoSizingMap; 1647 TextAutoSizingMap m_textAutoSizedNodes; 1648#endif 1649 1650#if ENABLE(TEXT_AUTOSIZING) 1651 std::unique_ptr<TextAutosizer> m_textAutosizer; 1652#endif 1653 1654 void platformSuspendOrStopActiveDOMObjects(); 1655 1656 bool m_scheduledTasksAreSuspended; 1657 1658 bool m_visualUpdatesAllowed; 1659 Timer<Document> m_visualUpdatesSuppressionTimer; 1660 1661 RefPtr<NamedFlowCollection> m_namedFlows; 1662 1663#if ENABLE(CSP_NEXT) 1664 RefPtr<DOMSecurityPolicy> m_domSecurityPolicy; 1665#endif 1666 1667 void sharedObjectPoolClearTimerFired(Timer<Document>&); 1668 Timer<Document> m_sharedObjectPoolClearTimer; 1669 1670 std::unique_ptr<DocumentSharedObjectPool> m_sharedObjectPool; 1671 1672#ifndef NDEBUG 1673 bool m_didDispatchViewportPropertiesChanged; 1674#endif 1675 1676 typedef HashMap<AtomicString, OwnPtr<Locale>> LocaleIdentifierToLocaleMap; 1677 LocaleIdentifierToLocaleMap m_localeCache; 1678 1679#if ENABLE(TEMPLATE_ELEMENT) 1680 RefPtr<Document> m_templateDocument; 1681 Document* m_templateDocumentHost; // Manually managed weakref (backpointer from m_templateDocument). 1682#endif 1683 1684#if ENABLE(FONT_LOAD_EVENTS) 1685 RefPtr<FontLoader> m_fontloader; 1686#endif 1687 1688#if ENABLE(WEB_REPLAY) 1689 RefPtr<JSC::InputCursor> m_inputCursor; 1690#endif 1691 1692 Timer<Document> m_didAssociateFormControlsTimer; 1693 HashSet<RefPtr<Element>> m_associatedFormControls; 1694 unsigned m_disabledFieldsetElementsCount; 1695 1696 bool m_hasInjectedPlugInsScript; 1697 bool m_renderTreeBeingDestroyed; 1698 bool m_hasPreparedForDestruction; 1699 1700 bool m_hasStyleWithViewportUnits; 1701}; 1702 1703inline void Document::notifyRemovePendingSheetIfNeeded() 1704{ 1705 if (m_needsNotifyRemoveAllPendingStylesheet) 1706 didRemoveAllPendingStylesheet(); 1707} 1708 1709#if ENABLE(TEMPLATE_ELEMENT) 1710inline const Document* Document::templateDocument() const 1711{ 1712 // If DOCUMENT does not have a browsing context, Let TEMPLATE CONTENTS OWNER be DOCUMENT and abort these steps. 1713 if (!m_frame) 1714 return this; 1715 1716 return m_templateDocument.get(); 1717} 1718#endif 1719 1720// Put these methods here, because they require the Document definition, but we really want to inline them. 1721 1722inline bool Node::isDocumentNode() const 1723{ 1724 return this == &document(); 1725} 1726 1727inline Node::Node(Document& document, ConstructionType type) 1728 : m_nodeFlags(type) 1729 , m_parentNode(0) 1730 , m_treeScope(&document) 1731 , m_previous(0) 1732 , m_next(0) 1733{ 1734 document.incrementReferencingNodeCount(); 1735 1736#if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS) 1737 trackForDebugging(); 1738#endif 1739} 1740 1741inline ScriptExecutionContext* Node::scriptExecutionContext() const 1742{ 1743 return &document(); 1744} 1745 1746Element* eventTargetElementForDocument(Document*); 1747 1748SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(Document) 1749 1750inline bool isDocument(const Node& node) { return node.isDocumentNode(); } 1751void isDocument(const Document&); // Catch unnecessary runtime check of type known at compile time. 1752 1753NODE_TYPE_CASTS(Document) 1754 1755#define DOCUMENT_TYPE_CASTS(ToClassName) \ 1756 TYPE_CASTS_BASE(ToClassName, Document, document, WebCore::is##ToClassName(*document), WebCore::is##ToClassName(document)) 1757 1758} // namespace WebCore 1759 1760namespace WTF { 1761inline WebCore::Document* getPtr(WebCore::Document& p) { return &p; } 1762} 1763 1764#endif // Document_h 1765