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-2017 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.
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.
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.
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.
31 #include "ContainerNode.h"
32 #include "DocumentEventQueue.h"
33 #include "DocumentTimeline.h"
34 #include "DocumentTiming.h"
35 #include "FocusDirection.h"
36 #include "FontSelectorClient.h"
37 #include "FrameDestructionObserver.h"
38 #include "MediaProducer.h"
39 #include "MutationObserver.h"
40 #include "OrientationNotifier.h"
41 #include "PlatformEvent.h"
42 #include "ReferrerPolicy.h"
44 #include "RenderPtr.h"
45 #include "ScriptExecutionContext.h"
46 #include "StringWithDirection.h"
47 #include "Supplementable.h"
48 #include "TextResourceDecoder.h"
50 #include "TreeScope.h"
51 #include "UserActionElementSet.h"
52 #include "ViewportArguments.h"
53 #include "VisibilityState.h"
54 #include <pal/Logger.h>
55 #include <pal/SessionID.h>
56 #include <wtf/Deque.h>
57 #include <wtf/Forward.h>
58 #include <wtf/HashCountedSet.h>
59 #include <wtf/HashSet.h>
60 #include <wtf/WeakPtr.h>
61 #include <wtf/text/AtomicStringHash.h>
64 #include "EventTrackingRegions.h"
67 #if ENABLE(IOS_TOUCH_EVENTS)
68 #include <wtf/ThreadingPrimitives.h>
81 class CSSCustomPropertyValue;
82 class CSSFontSelector;
83 class CSSStyleDeclaration;
85 class CachedCSSStyleSheet;
86 class CachedFrameBase;
87 class CachedResourceLoader;
89 class CanvasRenderingContext2D;
92 class ConstantPropertyMap;
93 class DOMImplementation;
96 class DOMWrapperWorld;
99 class DeferredPromise;
100 class DocumentFragment;
101 class DocumentLoader;
102 class DocumentMarkerController;
103 class DocumentParser;
104 class DocumentSharedObjectPool;
106 class ExtensionStyleSheets;
110 class FormController;
113 class HTMLAllCollection;
114 class HTMLBodyElement;
115 class HTMLCanvasElement;
116 class HTMLCollection;
119 class HTMLFrameOwnerElement;
120 class HTMLHeadElement;
121 class HTMLIFrameElement;
122 class HTMLImageElement;
123 class HTMLMapElement;
124 class HTMLMediaElement;
125 class HTMLPictureElement;
126 class HTMLScriptElement;
127 class HitTestRequest;
129 class ImageBitmapRenderingContext;
137 class MediaCanStartListener;
138 class MediaPlaybackTarget;
139 class MediaPlaybackTargetClient;
140 class MediaQueryList;
141 class MediaQueryMatcher;
142 class MouseEventWithHitTestResults;
146 class PlatformMouseEvent;
147 class ProcessingInstruction;
150 class RenderFullScreen;
152 class RequestAnimationFrameCallback;
153 class SVGDocumentExtensions;
155 class ScriptElementData;
156 class ScriptModuleLoader;
158 class ScriptableDocumentParser;
159 class ScriptedAnimationController;
160 class SecurityOrigin;
161 class SegmentedString;
163 class SelectorQueryCache;
164 class SerializedScriptValue;
166 class StringCallback;
169 class StyleSheetContents;
170 class StyleSheetList;
172 class TextResourceDecoder;
174 class VisibilityChangeClient;
175 class VisitedLinkState;
176 class WebGL2RenderingContext;
177 class WebGLRenderingContext;
178 class WebGPURenderingContext;
179 class XPathEvaluator;
180 class XPathExpression;
181 class XPathNSResolver;
184 template<typename> class ExceptionOr;
187 enum class ShouldOpenExternalURLsPolicy;
189 using PlatformDisplayID = uint32_t;
192 class TransformSource;
195 #if ENABLE(DASHBOARD_SUPPORT)
196 struct AnnotatedRegionValue;
199 #if ENABLE(TOUCH_EVENTS) || ENABLE(IOS_TOUCH_EVENTS)
205 class DeviceMotionClient;
206 class DeviceMotionController;
207 class DeviceOrientationClient;
208 class DeviceOrientationController;
211 #if ENABLE(TEXT_AUTOSIZING)
212 class TextAutoSizing;
215 #if ENABLE(MEDIA_SESSION)
223 const uint64_t HTMLMediaElementInvalidID = 0;
225 enum PageshowEventPersistence {
226 PageshowEventNotPersisted = 0,
227 PageshowEventPersisted = 1
230 enum NodeListInvalidationType {
231 DoNotInvalidateOnAttributeChanges = 0,
232 InvalidateOnClassAttrChange,
233 InvalidateOnIdNameAttrChange,
234 InvalidateOnNameAttrChange,
235 InvalidateOnForTypeAttrChange,
236 InvalidateForFormControls,
237 InvalidateOnHRefAttrChange,
238 InvalidateOnAnyAttrChange,
240 const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
242 enum class EventHandlerRemoval { One, All };
243 typedef HashCountedSet<Node*> EventTargetSet;
246 DefaultDocumentClass = 0,
247 HTMLDocumentClass = 1,
248 XHTMLDocumentClass = 1 << 1,
249 ImageDocumentClass = 1 << 2,
250 PluginDocumentClass = 1 << 3,
251 MediaDocumentClass = 1 << 4,
252 SVGDocumentClass = 1 << 5,
253 TextDocumentClass = 1 << 6,
254 XMLDocumentClass = 1 << 7,
257 typedef unsigned char DocumentClassFlags;
259 enum class DocumentCompatibilityMode : unsigned char {
262 LimitedQuirksMode = 1 << 2
265 enum DimensionsCheck { WidthDimensionsCheck = 1 << 0, HeightDimensionsCheck = 1 << 1, AllDimensionsCheck = 1 << 2 };
267 enum class SelectionRestorationMode {
272 enum class HttpEquivPolicy {
275 DisabledByContentDispositionAttachmentSandbox
278 enum class CustomElementNameValidationStatus {
280 FirstCharacterIsNotLowercaseASCIILetter,
282 ContainsUppercaseASCIILetter,
283 ContainsDisallowedCharacter,
284 ConflictsWithStandardElementName
287 using RenderingContext = Variant<
289 RefPtr<WebGLRenderingContext>,
292 RefPtr<WebGL2RenderingContext>,
295 RefPtr<WebGPURenderingContext>,
297 RefPtr<ImageBitmapRenderingContext>,
298 RefPtr<CanvasRenderingContext2D>
302 : public ContainerNode
304 , public ScriptExecutionContext
305 , public FontSelectorClient
306 , public FrameDestructionObserver
307 , public Supplementable<Document>
308 , public PAL::Logger::Observer {
310 static Ref<Document> create(Frame* frame, const URL& url)
312 return adoptRef(*new Document(frame, url));
315 static Ref<Document> createNonRenderedPlaceholder(Frame* frame, const URL& url)
317 return adoptRef(*new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder));
319 static Ref<Document> create(Document&);
323 // Nodes belonging to this document increase referencingNodeCount -
324 // these are enough to keep the document from being destroyed, but
325 // not enough to keep it from removing its children. This allows a
326 // node that outlives its document to still have a valid document
327 // pointer without introducing reference cycles.
328 void incrementReferencingNodeCount()
330 ASSERT(!m_deletionHasBegun);
331 ++m_referencingNodeCount;
334 void decrementReferencingNodeCount()
336 ASSERT(!m_deletionHasBegun || !m_referencingNodeCount);
337 --m_referencingNodeCount;
338 if (!m_referencingNodeCount && !refCount()) {
340 m_deletionHasBegun = true;
346 unsigned referencingNodeCount() const { return m_referencingNodeCount; }
348 void removedLastRef();
350 WEBCORE_EXPORT static HashSet<Document*>& allDocuments();
352 MediaQueryMatcher& mediaQueryMatcher();
354 using ContainerNode::ref;
355 using ContainerNode::deref;
356 using TreeScope::rootNode;
358 bool canContainRangeEndPoint() const final { return true; }
360 Element* getElementByAccessKey(const String& key);
361 void invalidateAccessKeyMap();
363 void addImageElementByUsemap(const AtomicStringImpl&, HTMLImageElement&);
364 void removeImageElementByUsemap(const AtomicStringImpl&, HTMLImageElement&);
365 HTMLImageElement* imageElementByUsemap(const AtomicStringImpl&) const;
367 ExceptionOr<SelectorQuery&> selectorQueryForString(const String&);
368 void clearSelectorQueryCache();
370 // DOM methods & attributes for Document
372 void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; }
373 ViewportArguments viewportArguments() const { return m_viewportArguments; }
375 bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; }
378 void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; }
379 ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
381 WEBCORE_EXPORT DocumentType* doctype() const;
383 WEBCORE_EXPORT DOMImplementation& implementation();
385 Element* documentElement() const
387 return m_documentElement.get();
389 static ptrdiff_t documentElementMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentElement); }
391 WEBCORE_EXPORT Element* activeElement();
392 WEBCORE_EXPORT bool hasFocus() const;
394 bool hasManifest() const;
396 WEBCORE_EXPORT ExceptionOr<Ref<Element>> createElementForBindings(const AtomicString& tagName);
397 WEBCORE_EXPORT Ref<DocumentFragment> createDocumentFragment();
398 WEBCORE_EXPORT Ref<Text> createTextNode(const String& data);
399 WEBCORE_EXPORT Ref<Comment> createComment(const String& data);
400 WEBCORE_EXPORT ExceptionOr<Ref<CDATASection>> createCDATASection(const String& data);
401 WEBCORE_EXPORT ExceptionOr<Ref<ProcessingInstruction>> createProcessingInstruction(const String& target, const String& data);
402 WEBCORE_EXPORT ExceptionOr<Ref<Attr>> createAttribute(const String& name);
403 WEBCORE_EXPORT ExceptionOr<Ref<Attr>> createAttributeNS(const AtomicString& namespaceURI, const String& qualifiedName, bool shouldIgnoreNamespaceChecks = false);
404 WEBCORE_EXPORT ExceptionOr<Ref<Node>> importNode(Node& nodeToImport, bool deep);
405 WEBCORE_EXPORT ExceptionOr<Ref<Element>> createElementNS(const AtomicString& namespaceURI, const String& qualifiedName);
406 WEBCORE_EXPORT Ref<Element> createElement(const QualifiedName&, bool createdByParser);
408 static CustomElementNameValidationStatus validateCustomElementName(const AtomicString&);
410 bool isCSSGridLayoutEnabled() const;
412 WEBCORE_EXPORT RefPtr<Range> caretRangeFromPoint(int x, int y);
413 RefPtr<Range> caretRangeFromPoint(const LayoutPoint& clientPoint);
415 WEBCORE_EXPORT Element* scrollingElement();
422 ReadyState readyState() const { return m_readyState; }
424 WEBCORE_EXPORT String defaultCharsetForLegacyBindings() const;
426 String charset() const { return Document::encoding(); }
427 WEBCORE_EXPORT String characterSetWithUTF8Fallback() const;
428 TextEncoding textEncoding() const;
430 AtomicString encoding() const { return textEncoding().domName(); }
432 WEBCORE_EXPORT void setCharset(const String&); // Used by ObjC / GOBject bindings only.
434 void setContent(const String&);
436 String suggestedMIMEType() const;
438 void overrideMIMEType(const String&);
439 WEBCORE_EXPORT String contentType() const;
441 String contentLanguage() const { return m_contentLanguage; }
442 void setContentLanguage(const String&);
444 String xmlEncoding() const { return m_xmlEncoding; }
445 String xmlVersion() const { return m_xmlVersion; }
446 enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone };
447 bool xmlStandalone() const { return m_xmlStandalone == Standalone; }
448 StandaloneStatus xmlStandaloneStatus() const { return m_xmlStandalone; }
449 bool hasXMLDeclaration() const { return m_hasXMLDeclaration; }
451 void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser
452 WEBCORE_EXPORT ExceptionOr<void> setXMLVersion(const String&);
453 WEBCORE_EXPORT void setXMLStandalone(bool);
454 void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration; }
456 String documentURI() const { return m_documentURI; }
457 WEBCORE_EXPORT void setDocumentURI(const String&);
459 WEBCORE_EXPORT VisibilityState visibilityState() const;
460 void visibilityStateChanged();
461 WEBCORE_EXPORT bool hidden() const;
463 void setTimerThrottlingEnabled(bool);
464 bool isTimerThrottlingEnabled() const { return m_isTimerThrottlingEnabled; }
466 WEBCORE_EXPORT ExceptionOr<Ref<Node>> adoptNode(Node& source);
468 WEBCORE_EXPORT Ref<HTMLCollection> images();
469 WEBCORE_EXPORT Ref<HTMLCollection> embeds();
470 WEBCORE_EXPORT Ref<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings.
471 WEBCORE_EXPORT Ref<HTMLCollection> applets();
472 WEBCORE_EXPORT Ref<HTMLCollection> links();
473 WEBCORE_EXPORT Ref<HTMLCollection> forms();
474 WEBCORE_EXPORT Ref<HTMLCollection> anchors();
475 WEBCORE_EXPORT Ref<HTMLCollection> scripts();
476 Ref<HTMLCollection> all();
477 Ref<HTMLCollection> allFilteredByName(const AtomicString&);
479 Ref<HTMLCollection> windowNamedItems(const AtomicString&);
480 Ref<HTMLCollection> documentNamedItems(const AtomicString&);
482 // Other methods (not part of DOM)
483 bool isSynthesized() const { return m_isSynthesized; }
484 bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; }
485 bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; }
486 bool isXMLDocument() const { return m_documentClasses & XMLDocumentClass; }
487 bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; }
488 bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; }
489 bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; }
490 bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; }
491 bool isTextDocument() const { return m_documentClasses & TextDocumentClass; }
492 bool hasSVGRootNode() const;
493 virtual bool isFrameSet() const { return false; }
495 static ptrdiff_t documentClassesMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentClasses); }
496 static uint32_t isHTMLDocumentClassFlag() { return HTMLDocumentClass; }
498 bool isSrcdocDocument() const { return m_isSrcdocDocument; }
500 bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
502 StyleResolver& userAgentShadowTreeStyleResolver();
504 CSSFontSelector& fontSelector() { return m_fontSelector; }
506 WEBCORE_EXPORT bool haveStylesheetsLoaded() const;
507 bool isIgnoringPendingStylesheets() const { return m_ignorePendingStylesheets; }
509 WEBCORE_EXPORT StyleSheetList& styleSheets();
511 Style::Scope& styleScope() { return *m_styleScope; }
512 const Style::Scope& styleScope() const { return *m_styleScope; }
513 ExtensionStyleSheets& extensionStyleSheets() { return *m_extensionStyleSheets; }
514 const ExtensionStyleSheets& extensionStyleSheets() const { return *m_extensionStyleSheets; }
516 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
517 void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
519 void evaluateMediaQueryList();
521 FormController& formController();
522 Vector<String> formElementsState() const;
523 void setStateForNewFormElements(const Vector<String>&);
525 WEBCORE_EXPORT FrameView* view() const; // can be NULL
526 WEBCORE_EXPORT Page* page() const; // can be NULL
527 const Settings& settings() const { return m_settings.get(); }
528 Settings& mutableSettings() { return m_settings.get(); }
530 float deviceScaleFactor() const;
532 WEBCORE_EXPORT Ref<Range> createRange();
534 // The last bool parameter is for ObjC bindings.
535 WEBCORE_EXPORT Ref<NodeIterator> createNodeIterator(Node& root, unsigned long whatToShow = 0xFFFFFFFF, RefPtr<NodeFilter>&& = nullptr, bool = false);
537 // The last bool parameter is for ObjC bindings.
538 WEBCORE_EXPORT Ref<TreeWalker> createTreeWalker(Node& root, unsigned long whatToShow = 0xFFFFFFFF, RefPtr<NodeFilter>&& = nullptr, bool = false);
540 // Special support for editing
541 WEBCORE_EXPORT Ref<CSSStyleDeclaration> createCSSStyleDeclaration();
542 Ref<Text> createEditingTextNode(const String&);
544 enum class ResolveStyleType { Normal, Rebuild };
545 void resolveStyle(ResolveStyleType = ResolveStyleType::Normal);
546 WEBCORE_EXPORT bool updateStyleIfNeeded();
547 bool needsStyleRecalc() const;
548 unsigned lastStyleUpdateSizeForTesting() const { return m_lastStyleUpdateSizeForTesting; }
550 WEBCORE_EXPORT void updateLayout();
552 // updateLayoutIgnorePendingStylesheets() forces layout even if we are waiting for pending stylesheet loads,
553 // so calling this may cause a flash of unstyled content (FOUC).
554 enum class RunPostLayoutTasks {
558 WEBCORE_EXPORT void updateLayoutIgnorePendingStylesheets(RunPostLayoutTasks = RunPostLayoutTasks::Asynchronously);
560 std::unique_ptr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element&, const RenderStyle* parentStyle, PseudoId = NOPSEUDO);
562 // Returns true if page box (margin boxes and page borders) is visible.
563 WEBCORE_EXPORT bool isPageBoxVisible(int pageIndex);
565 // Returns the preferred page size and margins in pixels, assuming 96
566 // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
567 // marginLeft must be initialized to the default values that are used if
568 // auto is specified.
569 WEBCORE_EXPORT void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);
571 CachedResourceLoader& cachedResourceLoader() { return m_cachedResourceLoader; }
573 void didBecomeCurrentDocumentInFrame();
574 void destroyRenderTree();
575 void prepareForDestruction();
577 // Override ScriptExecutionContext methods to do additional work
578 WEBCORE_EXPORT bool shouldBypassMainWorldContentSecurityPolicy() const final;
579 void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) final;
580 void resumeActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) final;
581 void stopActiveDOMObjects() final;
583 void suspendDeviceMotionAndOrientationUpdates();
584 void resumeDeviceMotionAndOrientationUpdates();
586 RenderView* renderView() const { return m_renderView.get(); }
588 bool renderTreeBeingDestroyed() const { return m_renderTreeBeingDestroyed; }
589 bool hasLivingRenderTree() const { return renderView() && !renderTreeBeingDestroyed(); }
591 bool updateLayoutIfDimensionsOutOfDate(Element&, DimensionsCheck = AllDimensionsCheck);
593 AXObjectCache* existingAXObjectCache() const;
594 WEBCORE_EXPORT AXObjectCache* axObjectCache() const;
595 void clearAXObjectCache();
597 // to get visually ordered hebrew and arabic pages right
598 void setVisuallyOrdered();
599 bool visuallyOrdered() const { return m_visuallyOrdered; }
601 WEBCORE_EXPORT DocumentLoader* loader() const;
603 WEBCORE_EXPORT ExceptionOr<RefPtr<DOMWindow>> openForBindings(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& url, const AtomicString& name, const String& features);
604 WEBCORE_EXPORT ExceptionOr<Document&> openForBindings(Document* responsibleDocument, const String& type, const String& replace);
606 // FIXME: We should rename this at some point and give back the name 'open' to the HTML specified ones.
607 WEBCORE_EXPORT void open(Document* responsibleDocument = nullptr);
610 WEBCORE_EXPORT ExceptionOr<void> closeForBindings();
612 // FIXME: We should rename this at some point and give back the name 'close' to the HTML specified one.
613 WEBCORE_EXPORT void close();
614 // In some situations (see the code), we ignore document.close().
615 // explicitClose() bypass these checks and actually tries to close the
617 void explicitClose();
618 // implicitClose() actually does the work of closing the input stream.
619 void implicitClose();
621 void cancelParsing();
623 void write(Document* responsibleDocument, SegmentedString&&);
624 WEBCORE_EXPORT ExceptionOr<void> write(Document* responsibleDocument, Vector<String>&&);
625 WEBCORE_EXPORT ExceptionOr<void> writeln(Document* responsibleDocument, Vector<String>&&);
627 bool wellFormed() const { return m_wellFormed; }
629 const URL& url() const final { return m_url; }
630 void setURL(const URL&);
631 const URL& urlForBindings() const { return m_url.isEmpty() ? blankURL() : m_url; }
633 // To understand how these concepts relate to one another, please see the
634 // comments surrounding their declaration.
635 const URL& baseURL() const { return m_baseURL; }
636 void setBaseURLOverride(const URL&);
637 const URL& baseURLOverride() const { return m_baseURLOverride; }
638 const URL& baseElementURL() const { return m_baseElementURL; }
639 const String& baseTarget() const { return m_baseTarget; }
640 void processBaseElement();
642 WEBCORE_EXPORT URL completeURL(const String&) const final;
643 URL completeURL(const String&, const URL& baseURLOverride) const;
644 WEBCORE_EXPORT PAL::SessionID sessionID() const final;
646 String userAgent(const URL&) const final;
648 void disableEval(const String& errorMessage) final;
649 void disableWebAssembly(const String& errorMessage) final;
651 #if ENABLE(INDEXED_DATABASE)
652 IDBClient::IDBConnectionProxy* idbConnectionProxy() final;
654 SocketProvider* socketProvider() final;
656 bool canNavigate(Frame* targetFrame);
657 Frame* findUnsafeParentScrollPropagationBoundary();
659 bool usesStyleBasedEditability() const;
660 void setHasElementUsingStyleBasedEditability();
662 virtual Ref<DocumentParser> createParser();
663 DocumentParser* parser() const { return m_parser.get(); }
664 ScriptableDocumentParser* scriptableDocumentParser() const;
666 bool printing() const { return m_printing; }
667 void setPrinting(bool p) { m_printing = p; }
669 bool paginatedForScreen() const { return m_paginatedForScreen; }
670 void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; }
672 bool paginated() const { return printing() || paginatedForScreen(); }
674 void setCompatibilityMode(DocumentCompatibilityMode);
675 void lockCompatibilityMode() { m_compatibilityModeLocked = true; }
676 static ptrdiff_t compatibilityModeMemoryOffset() { return OBJECT_OFFSETOF(Document, m_compatibilityMode); }
678 WEBCORE_EXPORT String compatMode() const;
680 bool inQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::QuirksMode; }
681 bool inLimitedQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::LimitedQuirksMode; }
682 bool inNoQuirksMode() const { return m_compatibilityMode == DocumentCompatibilityMode::NoQuirksMode; }
684 void setReadyState(ReadyState);
685 void setParsing(bool);
686 bool parsing() const { return m_bParsing; }
687 Seconds minimumLayoutDelay();
689 bool shouldScheduleLayout();
690 bool isLayoutTimerActive();
691 Seconds timeSinceDocumentCreation() const;
693 void setTextColor(const Color& color) { m_textColor = color; }
694 const Color& textColor() const { return m_textColor; }
696 const Color& linkColor() const { return m_linkColor; }
697 const Color& visitedLinkColor() const { return m_visitedLinkColor; }
698 const Color& activeLinkColor() const { return m_activeLinkColor; }
699 void setLinkColor(const Color& c) { m_linkColor = c; }
700 void setVisitedLinkColor(const Color& c) { m_visitedLinkColor = c; }
701 void setActiveLinkColor(const Color& c) { m_activeLinkColor = c; }
702 void resetLinkColor();
703 void resetVisitedLinkColor();
704 void resetActiveLinkColor();
705 VisitedLinkState& visitedLinkState() const { return *m_visitedLinkState; }
707 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&);
709 WEBCORE_EXPORT String preferredStylesheetSet() const;
710 WEBCORE_EXPORT String selectedStylesheetSet() const;
711 WEBCORE_EXPORT void setSelectedStylesheetSet(const String&);
713 enum class FocusRemovalEventsMode { Dispatch, DoNotDispatch };
714 WEBCORE_EXPORT bool setFocusedElement(Element*, FocusDirection = FocusDirectionNone,
715 FocusRemovalEventsMode = FocusRemovalEventsMode::Dispatch);
716 Element* focusedElement() const { return m_focusedElement.get(); }
717 UserActionElementSet& userActionElements() { return m_userActionElements; }
718 const UserActionElementSet& userActionElements() const { return m_userActionElements; }
720 void setFocusNavigationStartingNode(Node*);
721 Element* focusNavigationStartingNode(FocusDirection) const;
723 void removeFocusedNodeOfSubtree(Node&, bool amongChildrenOnly = false);
724 void hoveredElementDidDetach(Element*);
725 void elementInActiveChainDidDetach(Element*);
727 void updateHoverActiveState(const HitTestRequest&, Element*);
729 // Updates for :target (CSS3 selector).
730 void setCSSTarget(Element*);
731 Element* cssTarget() const { return m_cssTarget; }
732 static ptrdiff_t cssTargetMemoryOffset() { return OBJECT_OFFSETOF(Document, m_cssTarget); }
734 WEBCORE_EXPORT void scheduleForcedStyleRecalc();
735 void scheduleStyleRecalc();
736 void unscheduleStyleRecalc();
737 bool hasPendingStyleRecalc() const;
738 bool hasPendingForcedStyleRecalc() const;
740 void registerNodeListForInvalidation(LiveNodeList&);
741 void unregisterNodeListForInvalidation(LiveNodeList&);
742 WEBCORE_EXPORT void registerCollection(HTMLCollection&);
743 void unregisterCollection(HTMLCollection&);
744 void collectionCachedIdNameMap(const HTMLCollection&);
745 void collectionWillClearIdNameMap(const HTMLCollection&);
746 bool shouldInvalidateNodeListAndCollectionCaches() const;
747 bool shouldInvalidateNodeListAndCollectionCachesForAttribute(const QualifiedName& attrName) const;
749 template <typename InvalidationFunction>
750 void invalidateNodeListAndCollectionCaches(InvalidationFunction);
752 void attachNodeIterator(NodeIterator*);
753 void detachNodeIterator(NodeIterator*);
754 void moveNodeIteratorsToNewDocument(Node&, Document&);
756 void attachRange(Range*);
757 void detachRange(Range*);
759 void updateRangesAfterChildrenChanged(ContainerNode&);
760 // nodeChildrenWillBeRemoved is used when removing all node children at once.
761 void nodeChildrenWillBeRemoved(ContainerNode&);
762 // nodeWillBeRemoved is only safe when removing one node at a time.
763 void nodeWillBeRemoved(Node&);
764 void removeFocusNavigationNodeOfSubtree(Node&, bool amongChildrenOnly = false);
765 enum class AcceptChildOperation { Replace, InsertOrAdd };
766 bool canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation) const;
768 void textInserted(Node*, unsigned offset, unsigned length);
769 void textRemoved(Node*, unsigned offset, unsigned length);
770 void textNodesMerged(Text* oldNode, unsigned offset);
771 void textNodeSplit(Text* oldNode);
773 void createDOMWindow();
774 void takeDOMWindowFrom(Document*);
776 DOMWindow* domWindow() const { return m_domWindow.get(); }
777 // In DOM Level 2, the Document's DOMWindow is called the defaultView.
778 DOMWindow* defaultView() const { return domWindow(); }
780 Document& contextDocument() const;
781 void setContextDocument(Document& document) { m_contextDocument = document.createWeakPtr(); }
783 // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
784 void setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value, DOMWrapperWorld&);
785 void setWindowAttributeEventListener(const AtomicString& eventType, RefPtr<EventListener>&&, DOMWrapperWorld&);
786 EventListener* getWindowAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld&);
787 WEBCORE_EXPORT void dispatchWindowEvent(Event&, EventTarget* = nullptr);
788 void dispatchWindowLoadEvent();
790 WEBCORE_EXPORT ExceptionOr<Ref<Event>> createEvent(const String& eventType);
792 // keep track of what types of event listeners are registered, so we don't
793 // dispatch events unnecessarily
795 DOMSUBTREEMODIFIED_LISTENER = 1,
796 DOMNODEINSERTED_LISTENER = 1 << 1,
797 DOMNODEREMOVED_LISTENER = 1 << 2,
798 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 1 << 3,
799 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 1 << 4,
800 DOMCHARACTERDATAMODIFIED_LISTENER = 1 << 5,
801 OVERFLOWCHANGED_LISTENER = 1 << 6,
802 ANIMATIONEND_LISTENER = 1 << 7,
803 ANIMATIONSTART_LISTENER = 1 << 8,
804 ANIMATIONITERATION_LISTENER = 1 << 9,
805 TRANSITIONEND_LISTENER = 1 << 10,
806 BEFORELOAD_LISTENER = 1 << 11,
807 SCROLL_LISTENER = 1 << 12,
808 FORCEWILLBEGIN_LISTENER = 1 << 13,
809 FORCECHANGED_LISTENER = 1 << 14,
810 FORCEDOWN_LISTENER = 1 << 15,
811 FORCEUP_LISTENER = 1 << 16
814 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
815 bool hasListenerTypeForEventType(PlatformEvent::Type) const;
816 void addListenerTypeIfNeeded(const AtomicString& eventType);
818 bool hasMutationObserversOfType(MutationObserver::MutationType type) const
820 return m_mutationObserverTypes & type;
822 bool hasMutationObservers() const { return m_mutationObserverTypes; }
823 void addMutationObserverTypes(MutationObserverOptions types) { m_mutationObserverTypes |= types; }
825 WEBCORE_EXPORT CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
827 // Handles an HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
828 // when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
829 // tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
830 // specified in an HTML file.
831 void processHttpEquiv(const String& equiv, const String& content, bool isInDocumentHead);
834 void processFormatDetection(const String&);
836 // Called when <meta name="apple-mobile-web-app-orientations"> changes.
837 void processWebAppOrientations();
840 void processViewport(const String& features, ViewportArguments::Type origin);
841 void updateViewportArguments();
842 void processReferrerPolicy(const String& policy);
844 // Returns the owning element in the parent document.
845 // Returns 0 if this is the top level document.
846 HTMLFrameOwnerElement* ownerElement() const;
848 // Used by DOM bindings; no direction known.
849 const String& title() const { return m_title.string; }
850 WEBCORE_EXPORT void setTitle(const String&);
852 WEBCORE_EXPORT const AtomicString& dir() const;
853 WEBCORE_EXPORT void setDir(const AtomicString&);
855 void titleElementAdded(Element& titleElement);
856 void titleElementRemoved(Element& titleElement);
857 void titleElementTextChanged(Element& titleElement);
859 WEBCORE_EXPORT ExceptionOr<String> cookie();
860 WEBCORE_EXPORT ExceptionOr<void> setCookie(const String&);
862 WEBCORE_EXPORT String referrer() const;
864 WEBCORE_EXPORT String origin() const final;
866 WEBCORE_EXPORT String domain() const;
867 ExceptionOr<void> setDomain(const String& newDomain);
869 WEBCORE_EXPORT String lastModified();
871 // The cookieURL is used to query the cookie database for this document's
872 // cookies. For example, if the cookie URL is http://example.com, we'll
873 // use the non-Secure cookies for example.com when computing
876 // Q: How is the cookieURL different from the document's URL?
877 // A: The two URLs are the same almost all the time. However, if one
878 // document inherits the security context of another document, it
879 // inherits its cookieURL but not its URL.
881 const URL& cookieURL() const { return m_cookieURL; }
882 void setCookieURL(const URL&);
884 // The firstPartyForCookies is used to compute whether this document
885 // appears in a "third-party" context for the purpose of third-party
886 // cookie blocking. The document is in a third-party context if the
887 // cookieURL and the firstPartyForCookies are from different hosts.
889 // Note: Some ports (including possibly Apple's) only consider the
890 // document in a third-party context if the cookieURL and the
891 // firstPartyForCookies have a different registry-controlled
894 const URL& firstPartyForCookies() const { return m_firstPartyForCookies; }
895 void setFirstPartyForCookies(const URL& url) { m_firstPartyForCookies = url; }
897 // The following implements the rule from HTML 4 for what valid names are.
898 // To get this right for all the XML cases, we probably have to improve this or move it
899 // and make it sensitive to the type of document.
900 static bool isValidName(const String&);
902 // The following breaks a qualified name into a prefix and a local name.
903 // It also does a validity check, and returns an error if the qualified name is invalid.
904 static ExceptionOr<std::pair<AtomicString, AtomicString>> parseQualifiedName(const String& qualifiedName);
905 static ExceptionOr<QualifiedName> parseQualifiedName(const AtomicString& namespaceURI, const String& qualifiedName);
907 // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
908 static bool hasValidNamespaceForElements(const QualifiedName&);
909 static bool hasValidNamespaceForAttributes(const QualifiedName&);
911 WEBCORE_EXPORT HTMLBodyElement* body() const;
912 WEBCORE_EXPORT HTMLElement* bodyOrFrameset() const;
913 WEBCORE_EXPORT ExceptionOr<void> setBodyOrFrameset(RefPtr<HTMLElement>&&);
915 Location* location() const;
917 WEBCORE_EXPORT HTMLHeadElement* head();
919 DocumentMarkerController& markers() const { return *m_markers; }
921 WEBCORE_EXPORT bool execCommand(const String& command, bool userInterface = false, const String& value = String());
922 WEBCORE_EXPORT bool queryCommandEnabled(const String& command);
923 WEBCORE_EXPORT bool queryCommandIndeterm(const String& command);
924 WEBCORE_EXPORT bool queryCommandState(const String& command);
925 WEBCORE_EXPORT bool queryCommandSupported(const String& command);
926 WEBCORE_EXPORT String queryCommandValue(const String& command);
928 // designMode support
929 enum InheritedBool { off = false, on = true, inherit };
930 void setDesignMode(InheritedBool value);
931 InheritedBool getDesignMode() const;
932 bool inDesignMode() const;
933 WEBCORE_EXPORT String designMode() const;
934 WEBCORE_EXPORT void setDesignMode(const String&);
936 Document* parentDocument() const;
937 WEBCORE_EXPORT Document& topDocument() const;
939 ScriptRunner* scriptRunner() { return m_scriptRunner.get(); }
940 ScriptModuleLoader* moduleLoader() { return m_moduleLoader.get(); }
942 HTMLScriptElement* currentScript() const { return !m_currentScriptStack.isEmpty() ? m_currentScriptStack.last().get() : nullptr; }
943 void pushCurrentScript(HTMLScriptElement*);
944 void popCurrentScript();
947 void scheduleToApplyXSLTransforms();
948 void applyPendingXSLTransformsNowIfScheduled();
949 RefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
950 void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
952 void setTransformSource(std::unique_ptr<TransformSource>);
953 TransformSource* transformSource() const { return m_transformSource.get(); }
956 void incDOMTreeVersion() { m_domTreeVersion = ++s_globalTreeVersion; }
957 uint64_t domTreeVersion() const { return m_domTreeVersion; }
959 String originIdentifierForPasteboard();
961 // XPathEvaluator methods
962 WEBCORE_EXPORT ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&);
963 WEBCORE_EXPORT Ref<XPathNSResolver> createNSResolver(Node* nodeResolver);
964 WEBCORE_EXPORT ExceptionOr<Ref<XPathResult>> evaluate(const String& expression, Node* contextNode, RefPtr<XPathNSResolver>&&, unsigned short type, XPathResult*);
966 bool hasNodesWithNonFinalStyle() const { return m_hasNodesWithNonFinalStyle; }
967 void setHasNodesWithNonFinalStyle() { m_hasNodesWithNonFinalStyle = true; }
968 bool hasNodesWithMissingStyle() const { return m_hasNodesWithMissingStyle; }
969 void setHasNodesWithMissingStyle() { m_hasNodesWithMissingStyle = true; }
971 // Extension for manipulating canvas drawing contexts for use in CSS
972 std::optional<RenderingContext> getCSSCanvasContext(const String& type, const String& name, int width, int height);
973 HTMLCanvasElement* getCSSCanvasElement(const String& name);
975 bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
976 void parseDNSPrefetchControlHeader(const String&);
978 void postTask(Task&&) final; // Executes the task on context's thread asynchronously.
980 ScriptedAnimationController* scriptedAnimationController() { return m_scriptedAnimationController.get(); }
981 void suspendScriptedAnimationControllerCallbacks();
982 void resumeScriptedAnimationControllerCallbacks();
984 void windowScreenDidChange(PlatformDisplayID);
986 void finishedParsing();
988 enum PageCacheState { NotInPageCache, AboutToEnterPageCache, InPageCache };
990 PageCacheState pageCacheState() const { return m_pageCacheState; }
991 void setPageCacheState(PageCacheState);
993 // Elements can register themselves for the "suspend()" and
994 // "resume()" callbacks
995 void registerForDocumentSuspensionCallbacks(Element*);
996 void unregisterForDocumentSuspensionCallbacks(Element*);
998 void documentWillBecomeInactive();
999 void suspend(ActiveDOMObject::ReasonForSuspension);
1000 void resume(ActiveDOMObject::ReasonForSuspension);
1002 void registerForMediaVolumeCallbacks(Element*);
1003 void unregisterForMediaVolumeCallbacks(Element*);
1004 void mediaVolumeDidChange();
1006 bool audioPlaybackRequiresUserGesture() const;
1007 bool videoPlaybackRequiresUserGesture() const;
1009 #if ENABLE(MEDIA_SESSION)
1010 MediaSession& defaultMediaSession();
1013 void registerForPrivateBrowsingStateChangedCallbacks(Element*);
1014 void unregisterForPrivateBrowsingStateChangedCallbacks(Element*);
1015 void storageBlockingStateDidChange();
1016 void privateBrowsingStateDidChange();
1018 #if ENABLE(VIDEO_TRACK)
1019 void registerForCaptionPreferencesChangedCallbacks(Element*);
1020 void unregisterForCaptionPreferencesChangedCallbacks(Element*);
1021 void captionPreferencesChanged();
1024 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
1025 void registerForPageScaleFactorChangedCallbacks(HTMLMediaElement*);
1026 void unregisterForPageScaleFactorChangedCallbacks(HTMLMediaElement*);
1027 void pageScaleFactorChangedAndStable();
1028 void registerForUserInterfaceLayoutDirectionChangedCallbacks(HTMLMediaElement&);
1029 void unregisterForUserInterfaceLayoutDirectionChangedCallbacks(HTMLMediaElement&);
1030 void userInterfaceLayoutDirectionChanged();
1033 void registerForVisibilityStateChangedCallbacks(VisibilityChangeClient*);
1034 void unregisterForVisibilityStateChangedCallbacks(VisibilityChangeClient*);
1037 void registerForAllowsMediaDocumentInlinePlaybackChangedCallbacks(HTMLMediaElement&);
1038 void unregisterForAllowsMediaDocumentInlinePlaybackChangedCallbacks(HTMLMediaElement&);
1039 void allowsMediaDocumentInlinePlaybackChanged();
1042 WEBCORE_EXPORT void setShouldCreateRenderers(bool);
1043 bool shouldCreateRenderers();
1045 void setDecoder(RefPtr<TextResourceDecoder>&&);
1046 TextResourceDecoder* decoder() const { return m_decoder.get(); }
1048 WEBCORE_EXPORT String displayStringModifiedByEncoding(const String&) const;
1050 #if ENABLE(DASHBOARD_SUPPORT)
1051 void setAnnotatedRegionsDirty(bool f) { m_annotatedRegionsDirty = f; }
1052 bool annotatedRegionsDirty() const { return m_annotatedRegionsDirty; }
1053 bool hasAnnotatedRegions () const { return m_hasAnnotatedRegions; }
1054 void setHasAnnotatedRegions(bool f) { m_hasAnnotatedRegions = f; }
1055 WEBCORE_EXPORT const Vector<AnnotatedRegionValue>& annotatedRegions() const;
1056 void setAnnotatedRegions(const Vector<AnnotatedRegionValue>&);
1059 void removeAllEventListeners() final;
1061 WEBCORE_EXPORT const SVGDocumentExtensions* svgExtensions();
1062 WEBCORE_EXPORT SVGDocumentExtensions& accessSVGExtensions();
1064 void initSecurityContext();
1065 void initContentSecurityPolicy();
1067 void updateURLForPushOrReplaceState(const URL&);
1068 void statePopped(Ref<SerializedScriptValue>&&);
1070 bool processingLoadEvent() const { return m_processingLoadEvent; }
1071 bool loadEventFinished() const { return m_loadEventFinished; }
1073 bool isContextThread() const final;
1074 bool isSecureContext() const final;
1075 bool isJSExecutionForbidden() const final { return false; }
1077 void enqueueWindowEvent(Ref<Event>&&);
1078 void enqueueDocumentEvent(Ref<Event>&&);
1079 void enqueueOverflowEvent(Ref<Event>&&);
1080 void dispatchPageshowEvent(PageshowEventPersistence);
1081 void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
1082 void dispatchPopstateEvent(RefPtr<SerializedScriptValue>&& stateObject);
1083 DocumentEventQueue& eventQueue() const final { return m_eventQueue; }
1085 WEBCORE_EXPORT void addMediaCanStartListener(MediaCanStartListener*);
1086 WEBCORE_EXPORT void removeMediaCanStartListener(MediaCanStartListener*);
1087 MediaCanStartListener* takeAnyMediaCanStartListener();
1089 #if ENABLE(FULLSCREEN_API)
1090 bool webkitIsFullScreen() const { return m_fullScreenElement.get(); }
1091 bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
1092 Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); }
1093 Element* webkitCurrentFullScreenElementForBindings() const { return ancestorElementInThisScope(webkitCurrentFullScreenElement()); }
1095 enum FullScreenCheckType {
1096 EnforceIFrameAllowFullScreenRequirement,
1097 ExemptIFrameAllowFullScreenRequirement,
1100 void requestFullScreenForElement(Element*, FullScreenCheckType);
1101 WEBCORE_EXPORT void webkitCancelFullScreen();
1103 WEBCORE_EXPORT void webkitWillEnterFullScreenForElement(Element*);
1104 WEBCORE_EXPORT void webkitDidEnterFullScreenForElement(Element*);
1105 WEBCORE_EXPORT void webkitWillExitFullScreenForElement(Element*);
1106 WEBCORE_EXPORT void webkitDidExitFullScreenForElement(Element*);
1108 void setFullScreenRenderer(RenderFullScreen*);
1109 RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer.get(); }
1111 void fullScreenChangeDelayTimerFired();
1112 bool fullScreenIsAllowedForElement(Element*) const;
1113 void fullScreenElementRemoved();
1114 void removeFullScreenElementOfSubtree(Node&, bool amongChildrenOnly = false);
1115 bool isAnimatingFullScreen() const;
1116 WEBCORE_EXPORT void setAnimatingFullScreen(bool);
1118 WEBCORE_EXPORT bool webkitFullscreenEnabled() const;
1119 Element* webkitFullscreenElement() const { return !m_fullScreenElementStack.isEmpty() ? m_fullScreenElementStack.last().get() : nullptr; }
1120 Element* webkitFullscreenElementForBindings() const { return ancestorElementInThisScope(webkitFullscreenElement()); }
1121 WEBCORE_EXPORT void webkitExitFullscreen();
1124 #if ENABLE(POINTER_LOCK)
1125 WEBCORE_EXPORT void exitPointerLock();
1128 // Used to allow element that loads data without going through a FrameLoader to delay the 'load' event.
1129 void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; }
1130 void decrementLoadEventDelayCount();
1131 bool isDelayingLoadEvent() const { return m_loadEventDelayCount; }
1132 void checkCompleted();
1134 #if ENABLE(IOS_TOUCH_EVENTS)
1135 #include <WebKitAdditions/DocumentIOS.h>
1138 #if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS)
1139 DeviceMotionController* deviceMotionController() const;
1140 DeviceOrientationController* deviceOrientationController() const;
1143 const DocumentTiming& timing() const { return m_documentTiming; }
1145 double monotonicTimestamp() const;
1147 int requestAnimationFrame(Ref<RequestAnimationFrameCallback>&&);
1148 void cancelAnimationFrame(int id);
1150 EventTarget* errorEventTarget() final;
1151 void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, RefPtr<Inspector::ScriptCallStack>&&) final;
1153 void initDNSPrefetch();
1155 void didAddWheelEventHandler(Node&);
1156 void didRemoveWheelEventHandler(Node&, EventHandlerRemoval = EventHandlerRemoval::One);
1158 MonotonicTime lastHandledUserGestureTimestamp() const { return m_lastHandledUserGestureTimestamp; }
1159 bool hasHadUserInteraction() const { return static_cast<bool>(m_lastHandledUserGestureTimestamp); }
1160 void updateLastHandledUserGestureTimestamp(MonotonicTime);
1161 bool processingUserGestureForMedia() const;
1163 void setUserDidInteractWithPage(bool userDidInteractWithPage) { ASSERT(&topDocument() == this); m_userDidInteractWithPage = userDidInteractWithPage; }
1164 bool userDidInteractWithPage() const { ASSERT(&topDocument() == this); return m_userDidInteractWithPage; }
1166 // Used for testing. Count handlers in the main document, and one per frame which contains handlers.
1167 WEBCORE_EXPORT unsigned wheelEventHandlerCount() const;
1168 WEBCORE_EXPORT unsigned touchEventHandlerCount() const;
1170 WEBCORE_EXPORT void startTrackingStyleRecalcs();
1171 WEBCORE_EXPORT unsigned styleRecalcCount() const;
1173 #if ENABLE(TOUCH_EVENTS)
1174 bool hasTouchEventHandlers() const { return (m_touchEventTargets.get()) ? m_touchEventTargets->size() : false; }
1175 bool touchEventTargetsContain(Node& node) const { return m_touchEventTargets ? m_touchEventTargets->contains(&node) : false; }
1177 bool hasTouchEventHandlers() const { return false; }
1178 bool touchEventTargetsContain(Node&) const { return false; }
1181 void didAddTouchEventHandler(Node&);
1182 void didRemoveTouchEventHandler(Node&, EventHandlerRemoval = EventHandlerRemoval::One);
1184 void didRemoveEventTargetNode(Node&);
1186 const EventTargetSet* touchEventTargets() const
1188 #if ENABLE(TOUCH_EVENTS)
1189 return m_touchEventTargets.get();
1195 const EventTargetSet* wheelEventTargets() const { return m_wheelEventTargets.get(); }
1197 typedef std::pair<Region, bool> RegionFixedPair;
1198 RegionFixedPair absoluteRegionForEventTargets(const EventTargetSet*);
1200 LayoutRect absoluteEventHandlerBounds(bool&) final;
1202 bool visualUpdatesAllowed() const { return m_visualUpdatesAllowed; }
1204 bool isInDocumentWrite() { return m_writeRecursionDepth > 0; }
1206 void suspendScheduledTasks(ActiveDOMObject::ReasonForSuspension);
1207 void resumeScheduledTasks(ActiveDOMObject::ReasonForSuspension);
1209 #if ENABLE(CSS_DEVICE_ADAPTATION)
1210 IntSize initialViewportSize() const;
1213 void convertAbsoluteToClientQuads(Vector<FloatQuad>&, const RenderStyle&);
1214 void convertAbsoluteToClientRects(Vector<FloatRect>&, const RenderStyle&);
1215 void convertAbsoluteToClientRect(FloatRect&, const RenderStyle&);
1217 bool hasActiveParser();
1218 void incrementActiveParserCount() { ++m_activeParserCount; }
1219 void decrementActiveParserCount();
1221 DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); }
1223 void invalidateMatchedPropertiesCacheAndForceStyleRecalc();
1225 void didRemoveAllPendingStylesheet();
1226 void didClearStyleResolver();
1228 bool inStyleRecalc() const { return m_inStyleRecalc; }
1229 bool inRenderTreeUpdate() const { return m_inRenderTreeUpdate; }
1231 void updateTextRenderer(Text&, unsigned offsetOfReplacedText, unsigned lengthOfReplacedText);
1233 // Return a Locale for the default locale if the argument is null or empty.
1234 Locale& getCachedLocale(const AtomicString& locale = nullAtom());
1236 const Document* templateDocument() const;
1237 Document& ensureTemplateDocument();
1238 void setTemplateDocumentHost(Document* templateDocumentHost) { m_templateDocumentHost = templateDocumentHost; }
1239 Document* templateDocumentHost() { return m_templateDocumentHost; }
1241 void didAssociateFormControl(Element*);
1242 bool hasDisabledFieldsetElement() const { return m_disabledFieldsetElementsCount; }
1243 void addDisabledFieldsetElement() { m_disabledFieldsetElementsCount++; }
1244 void removeDisabledFieldsetElement() { ASSERT(m_disabledFieldsetElementsCount); m_disabledFieldsetElementsCount--; }
1246 WEBCORE_EXPORT void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&) final;
1248 // The following addConsoleMessage function is deprecated.
1249 // Callers should try to create the ConsoleMessage themselves.
1250 WEBCORE_EXPORT void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) final;
1252 SecurityOrigin& securityOrigin() const { return *SecurityContext::securityOrigin(); }
1253 SecurityOrigin& topOrigin() const final { return topDocument().securityOrigin(); }
1255 Ref<FontFaceSet> fonts();
1257 void ensurePlugInsInjectedScript(DOMWrapperWorld&);
1259 void setVisualUpdatesAllowedByClient(bool);
1261 #if ENABLE(SUBTLE_CRYPTO)
1262 bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) final;
1263 bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) final;
1266 void setHasStyleWithViewportUnits() { m_hasStyleWithViewportUnits = true; }
1267 bool hasStyleWithViewportUnits() const { return m_hasStyleWithViewportUnits; }
1268 void updateViewportUnitsOnResize();
1270 WEBCORE_EXPORT void addAudioProducer(MediaProducer*);
1271 WEBCORE_EXPORT void removeAudioProducer(MediaProducer*);
1272 MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
1273 void noteUserInteractionWithMediaElement();
1274 bool isCapturing() const { return MediaProducer::isCapturing(m_mediaState); }
1275 WEBCORE_EXPORT void updateIsPlayingMedia(uint64_t = HTMLMediaElementInvalidID);
1276 void pageMutedStateDidChange();
1277 WeakPtr<Document> createWeakPtr() { return m_weakFactory.createWeakPtr(*this); }
1279 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
1280 void addPlaybackTargetPickerClient(MediaPlaybackTargetClient&);
1281 void removePlaybackTargetPickerClient(MediaPlaybackTargetClient&);
1282 void showPlaybackTargetPicker(MediaPlaybackTargetClient&, bool);
1283 void playbackTargetPickerClientStateDidChange(MediaPlaybackTargetClient&, MediaProducer::MediaStateFlags);
1285 void setPlaybackTarget(uint64_t, Ref<MediaPlaybackTarget>&&);
1286 void playbackTargetAvailabilityDidChange(uint64_t, bool);
1287 void setShouldPlayToPlaybackTarget(uint64_t, bool);
1290 ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToPropagate() const;
1291 bool shouldEnforceContentDispositionAttachmentSandbox() const;
1292 void applyContentDispositionAttachmentSandbox();
1294 void addViewportDependentPicture(HTMLPictureElement&);
1295 void removeViewportDependentPicture(HTMLPictureElement&);
1297 #if ENABLE(MEDIA_STREAM)
1298 void setHasActiveMediaStreamTrack() { m_hasHadActiveMediaStreamTrack = true; }
1299 bool hasHadActiveMediaStreamTrack() const { return m_hasHadActiveMediaStreamTrack; }
1300 void setDeviceIDHashSalt(const String& salt) { m_idHashSalt = salt; }
1301 String deviceIDHashSalt() const { return m_idHashSalt; }
1302 void stopMediaCapture();
1303 void registerForMediaStreamStateChangeCallbacks(HTMLMediaElement&);
1304 void unregisterForMediaStreamStateChangeCallbacks(HTMLMediaElement&);
1305 void mediaStreamCaptureStateChanged();
1308 // FIXME: Find a better place for this functionality.
1309 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
1310 // These functions provide a two-level setting:
1311 // - A user-settable wantsTelephoneNumberParsing (at the Page / WebView level)
1312 // - A read-only telephoneNumberParsingAllowed which is set by the
1313 // document if it has the appropriate meta tag.
1314 // - isTelephoneNumberParsingEnabled() == isTelephoneNumberParsingAllowed() && page()->settings()->isTelephoneNumberParsingEnabled()
1315 WEBCORE_EXPORT bool isTelephoneNumberParsingAllowed() const;
1316 WEBCORE_EXPORT bool isTelephoneNumberParsingEnabled() const;
1319 using ContainerNode::setAttributeEventListener;
1320 void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value, DOMWrapperWorld& isolatedWorld);
1322 DOMSelection* getSelection();
1324 void didInsertInDocumentShadowRoot(ShadowRoot&);
1325 void didRemoveInDocumentShadowRoot(ShadowRoot&);
1326 const HashSet<ShadowRoot*>& inDocumentShadowRoots() const { return m_inDocumentShadowRoots; }
1328 void attachToCachedFrame(CachedFrameBase&);
1329 void detachFromCachedFrame(CachedFrameBase&);
1331 ConstantPropertyMap& constantProperties() const { return *m_constantPropertyMap; }
1333 void orientationChanged(int orientation);
1334 OrientationNotifier& orientationNotifier() { return m_orientationNotifier; }
1336 WEBCORE_EXPORT const AtomicString& bgColor() const;
1337 WEBCORE_EXPORT void setBgColor(const String&);
1338 WEBCORE_EXPORT const AtomicString& fgColor() const;
1339 WEBCORE_EXPORT void setFgColor(const String&);
1340 WEBCORE_EXPORT const AtomicString& alinkColor() const;
1341 WEBCORE_EXPORT void setAlinkColor(const String&);
1342 WEBCORE_EXPORT const AtomicString& linkColorForBindings() const;
1343 WEBCORE_EXPORT void setLinkColorForBindings(const String&);
1344 WEBCORE_EXPORT const AtomicString& vlinkColor() const;
1345 WEBCORE_EXPORT void setVlinkColor(const String&);
1347 // Per https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-clear, this method does nothing.
1349 // Per https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-captureevents, this method does nothing.
1350 void captureEvents() { }
1351 // Per https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-releaseevents, this method does nothing.
1352 void releaseEvents() { }
1354 #if ENABLE(TEXT_AUTOSIZING)
1355 TextAutoSizing& textAutoSizing();
1358 PAL::Logger& logger();
1360 bool hasStorageAccess() const { return m_hasStorageAccess; };
1361 void requestStorageAccess(Ref<DeferredPromise>&& passedPromise);
1362 void setUserGrantsStorageAccessOverride(bool value) { m_grantStorageAccessOverride = value; }
1364 WEBCORE_EXPORT void setConsoleMessageListener(RefPtr<StringCallback>&&); // For testing.
1366 DocumentTimeline& timeline();
1369 enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
1370 Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
1372 void clearXMLVersion() { m_xmlVersion = String(); }
1374 virtual Ref<Document> cloneDocumentWithoutChildren() const;
1378 friend class IgnoreDestructiveWriteCountIncrementer;
1379 friend class IgnoreOpensDuringUnloadCountIncrementer;
1381 bool shouldInheritContentSecurityPolicyFromOwner() const;
1383 void detachFromFrame() { observeFrame(nullptr); }
1385 void updateTitleElement(Element& changingTitleElement);
1386 void frameDestroyed() final;
1388 void commonTeardown();
1390 RenderObject* renderer() const = delete;
1391 void setRenderer(RenderObject*) = delete;
1393 void createRenderTree();
1394 void detachParser();
1396 // FontSelectorClient
1397 void fontsNeedUpdate(FontSelector&) final;
1399 bool isDocument() const final { return true; }
1401 void childrenChanged(const ChildChange&) final;
1403 String nodeName() const final;
1404 NodeType nodeType() const final;
1405 bool childTypeAllowed(NodeType) const final;
1406 Ref<Node> cloneNodeInternal(Document&, CloningOperation) final;
1407 void cloneDataFromDocument(const Document&);
1409 void refScriptExecutionContext() final { ref(); }
1410 void derefScriptExecutionContext() final { deref(); }
1412 // The following addMessage function is deprecated.
1413 // Callers should try to create the ConsoleMessage themselves.
1414 void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0) final;
1416 Seconds minimumDOMTimerInterval() const final;
1418 Seconds domTimerAlignmentInterval(bool hasReachedMaxNestingLevel) const final;
1420 void updateTitleFromTitleElement();
1421 void updateTitle(const StringWithDirection&);
1422 void updateBaseURL();
1424 void buildAccessKeyMap(TreeScope* root);
1426 void loadEventDelayTimerFired();
1428 void pendingTasksTimerFired();
1429 bool isCookieAverse() const;
1431 template<CollectionType> Ref<HTMLCollection> ensureCachedCollection();
1433 #if ENABLE(FULLSCREEN_API)
1434 void dispatchFullScreenChangeOrErrorEvent(Deque<RefPtr<Node>>&, const AtomicString& eventName, bool shouldNotifyMediaElement);
1435 void clearFullscreenElementStack();
1436 void popFullscreenElementStack();
1437 void pushFullscreenElementStack(Element*);
1438 void addDocumentToFullScreenChangeEventQueue(Document*);
1441 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
1442 friend void setParserFeature(const String& key, const String& value, Document*, void* userData);
1443 void setIsTelephoneNumberParsingAllowed(bool);
1446 void setVisualUpdatesAllowed(ReadyState);
1447 void setVisualUpdatesAllowed(bool);
1448 void visualUpdatesSuppressionTimerFired();
1450 void addListenerType(ListenerType listenerType) { m_listenerTypes |= listenerType; }
1452 void didAssociateFormControlsTimerFired();
1454 void wheelEventHandlersChanged();
1456 HttpEquivPolicy httpEquivPolicy() const;
1457 AXObjectCache* existingAXObjectCacheSlow() const;
1459 // DOM Cookies caching.
1460 const String& cachedDOMCookies() const { return m_cachedDOMCookies; }
1461 void setCachedDOMCookies(const String&);
1462 bool isDOMCookieCacheValid() const { return m_cookieCacheExpiryTimer.isActive(); }
1463 void invalidateDOMCookieCache();
1464 void didLoadResourceSynchronously() final;
1466 void checkViewportDependentPictures();
1469 bool shouldEnforceQuickLookSandbox() const;
1470 void applyQuickLookSandbox();
1473 bool shouldEnforceHTTP09Sandbox() const;
1475 void platformSuspendOrStopActiveDOMObjects();
1477 bool domainIsRegisterable(const String&) const;
1479 const Ref<Settings> m_settings;
1481 std::unique_ptr<StyleResolver> m_userAgentShadowTreeStyleResolver;
1483 RefPtr<DOMWindow> m_domWindow;
1484 WeakPtr<Document> m_contextDocument;
1486 Ref<CachedResourceLoader> m_cachedResourceLoader;
1487 RefPtr<DocumentParser> m_parser;
1490 URL m_url; // Document.URL: The URL from which this document was retrieved.
1491 URL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs.
1492 URL m_baseURLOverride; // An alternative base URL that takes precedence over m_baseURL (but not m_baseElementURL).
1493 URL m_baseElementURL; // The URL set by the <base> element.
1494 URL m_cookieURL; // The URL to use for cookie access.
1495 URL m_firstPartyForCookies; // The policy URL for third-party cookie blocking.
1497 // Document.documentURI:
1498 // Although URL-like, Document.documentURI can actually be set to any
1499 // string by content. Document.documentURI affects m_baseURL unless the
1500 // document contains a <base> element, in which case the <base> element
1501 // takes precedence.
1503 // This property is read-only from JavaScript, but writable from Objective C.
1504 String m_documentURI;
1506 String m_baseTarget;
1508 // MIME type of the document in case it was cloned or created by XHR.
1509 String m_overriddenMIMEType;
1511 std::unique_ptr<DOMImplementation> m_implementation;
1513 RefPtr<Node> m_focusNavigationStartingNode;
1514 RefPtr<Element> m_focusedElement;
1515 RefPtr<Element> m_hoveredElement;
1516 RefPtr<Element> m_activeElement;
1517 RefPtr<Element> m_documentElement;
1518 UserActionElementSet m_userActionElements;
1520 uint64_t m_domTreeVersion;
1521 static uint64_t s_globalTreeVersion;
1523 String m_uniqueIdentifier;
1525 HashSet<NodeIterator*> m_nodeIterators;
1526 HashSet<Range*> m_ranges;
1528 std::unique_ptr<Style::Scope> m_styleScope;
1529 std::unique_ptr<ExtensionStyleSheets> m_extensionStyleSheets;
1530 RefPtr<StyleSheetList> m_styleSheetList;
1532 std::unique_ptr<FormController> m_formController;
1534 Color m_textColor { Color::black };
1536 Color m_visitedLinkColor;
1537 Color m_activeLinkColor;
1538 const std::unique_ptr<VisitedLinkState> m_visitedLinkState;
1540 StringWithDirection m_title;
1541 StringWithDirection m_rawTitle;
1542 RefPtr<Element> m_titleElement;
1544 std::unique_ptr<AXObjectCache> m_axObjectCache;
1545 const std::unique_ptr<DocumentMarkerController> m_markers;
1547 Timer m_styleRecalcTimer;
1549 Element* m_cssTarget { nullptr };
1551 RefPtr<SerializedScriptValue> m_pendingStateObject;
1552 MonotonicTime m_documentCreationTime;
1553 bool m_overMinimumLayoutThreshold { false };
1555 std::unique_ptr<ScriptRunner> m_scriptRunner;
1556 std::unique_ptr<ScriptModuleLoader> m_moduleLoader;
1558 Vector<RefPtr<HTMLScriptElement>> m_currentScriptStack;
1561 void applyPendingXSLTransformsTimerFired();
1563 std::unique_ptr<TransformSource> m_transformSource;
1564 RefPtr<Document> m_transformSourceDocument;
1565 Timer m_applyPendingXSLTransformsTimer;
1568 String m_xmlEncoding;
1569 String m_xmlVersion;
1570 StandaloneStatus m_xmlStandalone { StandaloneUnspecified };
1571 bool m_hasXMLDeclaration { false };
1573 String m_contentLanguage;
1575 RefPtr<TextResourceDecoder> m_decoder;
1577 HashSet<LiveNodeList*> m_listsInvalidatedAtDocument;
1578 HashSet<HTMLCollection*> m_collectionsInvalidatedAtDocument;
1579 unsigned m_nodeListAndCollectionCounts[numNodeListInvalidationTypes];
1581 RefPtr<XPathEvaluator> m_xpathEvaluator;
1583 std::unique_ptr<SVGDocumentExtensions> m_svgExtensions;
1585 #if ENABLE(DASHBOARD_SUPPORT)
1586 Vector<AnnotatedRegionValue> m_annotatedRegions;
1587 bool m_hasAnnotatedRegions { false };
1588 bool m_annotatedRegionsDirty { false };
1591 HashMap<String, RefPtr<HTMLCanvasElement>> m_cssCanvasElements;
1593 HashSet<Element*> m_documentSuspensionCallbackElements;
1594 HashSet<Element*> m_mediaVolumeCallbackElements;
1595 HashSet<Element*> m_privateBrowsingStateChangedElements;
1596 #if ENABLE(VIDEO_TRACK)
1597 HashSet<Element*> m_captionPreferencesChangedElements;
1600 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
1601 HashSet<HTMLMediaElement*> m_pageScaleFactorChangedElements;
1602 HashSet<HTMLMediaElement*> m_userInterfaceLayoutDirectionChangedElements;
1605 HashSet<VisibilityChangeClient*> m_visibilityStateCallbackClients;
1607 HashSet<HTMLMediaElement*> m_allowsMediaDocumentInlinePlaybackElements;
1610 HashMap<StringImpl*, Element*, ASCIICaseInsensitiveHash> m_elementsByAccessKey;
1612 DocumentOrderedMap m_imagesByUsemap;
1614 std::unique_ptr<ConstantPropertyMap> m_constantPropertyMap;
1616 std::unique_ptr<SelectorQueryCache> m_selectorQueryCache;
1618 DocumentClassFlags m_documentClasses;
1620 RenderPtr<RenderView> m_renderView;
1621 mutable DocumentEventQueue m_eventQueue;
1623 WeakPtrFactory<Document> m_weakFactory;
1625 HashSet<MediaCanStartListener*> m_mediaCanStartListeners;
1627 #if ENABLE(FULLSCREEN_API)
1628 RefPtr<Element> m_fullScreenElement;
1629 Vector<RefPtr<Element>> m_fullScreenElementStack;
1630 WeakPtr<RenderFullScreen> m_fullScreenRenderer { nullptr };
1631 Timer m_fullScreenChangeDelayTimer;
1632 Deque<RefPtr<Node>> m_fullScreenChangeEventTargetQueue;
1633 Deque<RefPtr<Node>> m_fullScreenErrorEventTargetQueue;
1634 LayoutRect m_savedPlaceholderFrameRect;
1635 std::unique_ptr<RenderStyle> m_savedPlaceholderRenderStyle;
1637 bool m_areKeysEnabledInFullScreen { false };
1638 bool m_isAnimatingFullScreen { false };
1641 HashSet<HTMLPictureElement*> m_viewportDependentPictures;
1643 Timer m_loadEventDelayTimer;
1645 ViewportArguments m_viewportArguments;
1647 DocumentTiming m_documentTiming;
1649 RefPtr<MediaQueryMatcher> m_mediaQueryMatcher;
1651 #if ENABLE(TOUCH_EVENTS)
1652 std::unique_ptr<EventTargetSet> m_touchEventTargets;
1654 std::unique_ptr<EventTargetSet> m_wheelEventTargets;
1656 MonotonicTime m_lastHandledUserGestureTimestamp;
1658 void clearScriptedAnimationController();
1659 RefPtr<ScriptedAnimationController> m_scriptedAnimationController;
1661 void notifyMediaCaptureOfVisibilityChanged();
1663 void didLogMessage(const WTFLogChannel&, WTFLogLevel, const String&) final;
1665 #if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS)
1666 std::unique_ptr<DeviceMotionClient> m_deviceMotionClient;
1667 std::unique_ptr<DeviceMotionController> m_deviceMotionController;
1668 std::unique_ptr<DeviceOrientationClient> m_deviceOrientationClient;
1669 std::unique_ptr<DeviceOrientationController> m_deviceOrientationController;
1672 Timer m_pendingTasksTimer;
1673 Vector<Task> m_pendingTasks;
1675 #if ENABLE(TEXT_AUTOSIZING)
1676 std::unique_ptr<TextAutoSizing> m_textAutoSizing;
1679 Timer m_visualUpdatesSuppressionTimer;
1681 void clearSharedObjectPool();
1682 Timer m_sharedObjectPoolClearTimer;
1684 std::unique_ptr<DocumentSharedObjectPool> m_sharedObjectPool;
1686 typedef HashMap<AtomicString, std::unique_ptr<Locale>> LocaleIdentifierToLocaleMap;
1687 LocaleIdentifierToLocaleMap m_localeCache;
1689 RefPtr<Document> m_templateDocument;
1690 Document* m_templateDocumentHost { nullptr }; // Manually managed weakref (backpointer from m_templateDocument).
1692 Ref<CSSFontSelector> m_fontSelector;
1694 HashSet<MediaProducer*> m_audioProducers;
1696 HashSet<ShadowRoot*> m_inDocumentShadowRoots;
1698 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
1699 typedef HashMap<uint64_t, WebCore::MediaPlaybackTargetClient*> TargetIdToClientMap;
1700 TargetIdToClientMap m_idToClientMap;
1701 typedef HashMap<WebCore::MediaPlaybackTargetClient*, uint64_t> TargetClientToIdMap;
1702 TargetClientToIdMap m_clientToIDMap;
1705 #if ENABLE(MEDIA_SESSION)
1706 RefPtr<MediaSession> m_defaultMediaSession;
1709 #if ENABLE(INDEXED_DATABASE)
1710 RefPtr<IDBClient::IDBConnectionProxy> m_idbConnectionProxy;
1713 Timer m_didAssociateFormControlsTimer;
1714 Timer m_cookieCacheExpiryTimer;
1716 RefPtr<SocketProvider> m_socketProvider;
1718 String m_cachedDOMCookies;
1720 HashSet<RefPtr<Element>> m_associatedFormControls;
1721 unsigned m_disabledFieldsetElementsCount { 0 };
1723 unsigned m_listenerTypes { 0 };
1724 unsigned m_referencingNodeCount { 0 };
1725 int m_loadEventDelayCount { 0 };
1726 unsigned m_lastStyleUpdateSizeForTesting { 0 };
1728 // https://html.spec.whatwg.org/multipage/webappapis.html#ignore-destructive-writes-counter
1729 unsigned m_ignoreDestructiveWriteCount { 0 };
1731 // https://html.spec.whatwg.org/multipage/webappapis.html#ignore-opens-during-unload-counter
1732 unsigned m_ignoreOpensDuringUnloadCount { 0 };
1734 unsigned m_activeParserCount { 0 };
1735 unsigned m_styleRecalcCount { 0 };
1737 unsigned m_writeRecursionDepth { 0 };
1739 InheritedBool m_designMode { inherit };
1740 MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
1741 bool m_userHasInteractedWithMediaElement { false };
1742 PageCacheState m_pageCacheState { NotInPageCache };
1743 ReferrerPolicy m_referrerPolicy { ReferrerPolicy::NoReferrerWhenDowngrade };
1744 ReadyState m_readyState { Complete };
1746 MutationObserverOptions m_mutationObserverTypes { 0 };
1748 bool m_writeRecursionIsTooDeep { false };
1749 bool m_wellFormed { false };
1750 bool m_createRenderers { true };
1752 bool m_hasNodesWithNonFinalStyle { false };
1753 bool m_hasNodesWithMissingStyle { false };
1754 // But sometimes you need to ignore pending stylesheet count to
1755 // force an immediate layout when requested by JS.
1756 bool m_ignorePendingStylesheets { false };
1758 bool m_hasElementUsingStyleBasedEditability { false };
1759 bool m_focusNavigationStartingNodeIsRemoved { false };
1761 bool m_printing { false };
1762 bool m_paginatedForScreen { false };
1764 DocumentCompatibilityMode m_compatibilityMode { DocumentCompatibilityMode::NoQuirksMode };
1765 bool m_compatibilityModeLocked { false }; // This is cheaper than making setCompatibilityMode virtual.
1767 // FIXME: Merge these 2 variables into an enum. Also, FrameLoader::m_didCallImplicitClose
1768 // is almost a duplication of this data, so that should probably get merged in too.
1769 // FIXME: Document::m_processingLoadEvent and DocumentLoader::m_wasOnloadDispatched are roughly the same
1770 // and should be merged.
1771 bool m_processingLoadEvent { false };
1772 bool m_loadEventFinished { false };
1774 bool m_visuallyOrdered { false };
1775 bool m_bParsing { false }; // FIXME: rename
1777 bool m_pendingStyleRecalcShouldForce { false };
1778 bool m_inStyleRecalc { false };
1779 bool m_closeAfterStyleRecalc { false };
1780 bool m_inRenderTreeUpdate { false };
1782 bool m_gotoAnchorNeededAfterStylesheetsLoad { false };
1783 bool m_isDNSPrefetchEnabled { false };
1784 bool m_haveExplicitlyDisabledDNSPrefetch { false };
1786 bool m_accessKeyMapValid { false };
1787 bool m_isSynthesized { false };
1788 bool m_isNonRenderedPlaceholder { false };
1790 bool m_sawElementsInKnownNamespaces { false };
1791 bool m_isSrcdocDocument { false };
1793 bool m_hasInjectedPlugInsScript { false };
1794 bool m_renderTreeBeingDestroyed { false };
1795 bool m_hasPreparedForDestruction { false };
1797 bool m_hasStyleWithViewportUnits { false };
1798 bool m_isTimerThrottlingEnabled { false };
1799 bool m_isSuspended { false };
1801 bool m_scheduledTasksAreSuspended { false };
1802 bool m_visualUpdatesAllowed { true };
1804 bool m_areDeviceMotionAndOrientationUpdatesSuspended { false };
1805 bool m_userDidInteractWithPage { false };
1807 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
1808 bool m_isTelephoneNumberParsingAllowed { true };
1811 #if ENABLE(MEDIA_STREAM)
1812 HashSet<HTMLMediaElement*> m_mediaStreamStateChangeElements;
1813 String m_idHashSalt;
1814 bool m_hasHadActiveMediaStreamTrack { false };
1818 bool m_didDispatchViewportPropertiesChanged { false };
1821 OrientationNotifier m_orientationNotifier;
1822 mutable PAL::SessionID m_sessionID;
1823 mutable RefPtr<PAL::Logger> m_logger;
1824 RefPtr<StringCallback> m_consoleMessageListener;
1826 static bool hasEverCreatedAnAXObjectCache;
1828 bool m_hasStorageAccess { false };
1829 bool m_grantStorageAccessOverride { false };
1831 RefPtr<DocumentTimeline> m_timeline;
1834 Element* eventTargetElementForDocument(Document*);
1836 inline TextEncoding Document::textEncoding() const
1838 if (auto* decoder = this->decoder())
1839 return decoder->encoding();
1840 return TextEncoding();
1843 inline const Document* Document::templateDocument() const
1845 return m_templateDocumentHost ? this : m_templateDocument.get();
1848 inline AXObjectCache* Document::existingAXObjectCache() const
1850 if (!hasEverCreatedAnAXObjectCache)
1852 return existingAXObjectCacheSlow();
1855 // These functions are here because they require the Document class definition and we want to inline them.
1857 inline ScriptExecutionContext* Node::scriptExecutionContext() const
1859 return &document().contextDocument();
1862 } // namespace WebCore
1864 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Document)
1865 static bool isType(const WebCore::ScriptExecutionContext& context) { return context.isDocument(); }
1866 static bool isType(const WebCore::Node& node) { return node.isDocumentNode(); }
1867 SPECIALIZE_TYPE_TRAITS_END()