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 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 "bindings/core/v8/ExceptionStatePlaceholder.h"
32 #include "bindings/core/v8/ScriptValue.h"
33 #include "core/CoreExport.h"
34 #include "core/animation/AnimationClock.h"
35 #include "core/animation/CompositorPendingAnimations.h"
36 #include "core/dom/ContainerNode.h"
37 #include "core/dom/DocumentEncodingData.h"
38 #include "core/dom/DocumentInit.h"
39 #include "core/dom/DocumentLifecycle.h"
40 #include "core/dom/DocumentLifecycleNotifier.h"
41 #include "core/dom/DocumentLifecycleObserver.h"
42 #include "core/dom/DocumentTiming.h"
43 #include "core/dom/ExecutionContext.h"
44 #include "core/dom/MutationObserver.h"
45 #include "core/dom/TextLinkColors.h"
46 #include "core/dom/TreeScope.h"
47 #include "core/dom/UserActionElementSet.h"
48 #include "core/dom/ViewportDescription.h"
49 #include "core/dom/custom/CustomElement.h"
50 #include "core/fetch/ClientHintsPreferences.h"
51 #include "core/frame/DOMTimerCoordinator.h"
52 #include "core/frame/LocalDOMWindow.h"
53 #include "core/frame/OriginsUsingFeatures.h"
54 #include "core/html/CollectionType.h"
55 #include "core/html/parser/ParserSynchronizationPolicy.h"
56 #include "core/page/PageVisibilityState.h"
57 #include "platform/Length.h"
58 #include "platform/Timer.h"
59 #include "platform/heap/Handle.h"
60 #include "platform/weborigin/KURL.h"
61 #include "platform/weborigin/ReferrerPolicy.h"
62 #include "public/platform/WebFocusType.h"
63 #include "wtf/HashSet.h"
64 #include "wtf/OwnPtr.h"
65 #include "wtf/PassOwnPtr.h"
66 #include "wtf/PassRefPtr.h"
67 #include "wtf/WeakPtr.h"
71 class AnimationTimeline
;
75 class CSSStyleDeclaration
;
77 class CancellableTaskFactory
;
78 class CanvasFontCache
;
79 class CanvasRenderingContext2D
;
80 class CanvasRenderingContext2DOrWebGLRenderingContext
;
84 class ContextFeatures
;
85 class CustomElementMicrotaskRunQueue
;
86 class CustomElementRegistrationContext
;
87 class DOMImplementation
;
89 class DocumentFragment
;
91 class DocumentMarkerController
;
92 class DocumentNameCollection
;
96 class DocumentVisibilityObserver
;
98 class ElementDataCache
;
99 class ElementRegistrationOptions
;
101 class EventFactoryBase
;
103 template <typename EventType
>
104 class EventWithHitTestResults
;
105 class ExceptionState
;
108 class FormController
;
111 class FrameRequestCallback
;
113 class HTMLAllCollection
;
114 class HTMLBodyElement
;
115 class HTMLCanvasElement
;
116 class HTMLCollection
;
117 class HTMLDialogElement
;
119 class HTMLFrameOwnerElement
;
120 class HTMLHeadElement
;
121 class HTMLImportLoader
;
122 class HTMLImportsController
;
123 class HTMLLinkElement
;
124 class HTMLScriptElement
;
125 class HitTestRequest
;
126 class IdleRequestCallback
;
127 class InputDeviceCapabilities
;
129 class LiveNodeListBase
;
133 class MainThreadTaskRunner
;
134 class MediaQueryListListener
;
135 class MediaQueryMatcher
;
140 class PlatformMouseEvent
;
141 class ProcessingInstruction
;
145 class ResourceFetcher
;
146 class SVGDocumentExtensions
;
149 class ScriptableDocumentParser
;
150 class ScriptedAnimationController
;
151 class ScriptedIdleTaskController
;
152 class SecurityOrigin
;
153 class SegmentedString
;
154 class SelectorQueryCache
;
155 class SerializedScriptValue
;
160 class StyleSheetList
;
165 class TransformSource
;
167 class VisitedLinkState
;
168 class WebGLRenderingContext
;
170 struct AnnotatedRegionValue
;
173 using MouseEventWithHitTestResults
= EventWithHitTestResults
<PlatformMouseEvent
>;
174 using ExceptionCode
= int;
176 enum StyleResolverUpdateMode
{
177 // Discards the StyleResolver and rebuilds it.
179 // Attempts to use StyleInvalidationAnalysis to avoid discarding the entire StyleResolver.
183 enum NodeListInvalidationType
{
184 DoNotInvalidateOnAttributeChanges
= 0,
185 InvalidateOnClassAttrChange
,
186 InvalidateOnIdNameAttrChange
,
187 InvalidateOnNameAttrChange
,
188 InvalidateOnForAttrChange
,
189 InvalidateForFormControls
,
190 InvalidateOnHRefAttrChange
,
191 InvalidateOnAnyAttrChange
,
193 const int numNodeListInvalidationTypes
= InvalidateOnAnyAttrChange
+ 1;
196 DefaultDocumentClass
= 0,
197 HTMLDocumentClass
= 1,
198 XHTMLDocumentClass
= 1 << 1,
199 ImageDocumentClass
= 1 << 2,
200 PluginDocumentClass
= 1 << 3,
201 MediaDocumentClass
= 1 << 4,
202 SVGDocumentClass
= 1 << 5,
203 XMLDocumentClass
= 1 << 6,
206 using DocumentClassFlags
= unsigned char;
208 class CORE_EXPORT Document
: public ContainerNode
, public TreeScope
, public SecurityContext
, public ExecutionContext
209 , public WillBeHeapSupplementable
<Document
>, public DocumentLifecycleNotifier
{
210 DEFINE_WRAPPERTYPEINFO();
211 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Document
);
213 static PassRefPtrWillBeRawPtr
<Document
> create(const DocumentInit
& initializer
= DocumentInit())
215 return adoptRefWillBeNoop(new Document(initializer
));
217 ~Document() override
;
219 MediaQueryMatcher
& mediaQueryMatcher();
221 void mediaQueryAffectingValueChanged();
224 using ContainerNode::ref
;
225 using ContainerNode::deref
;
227 using SecurityContext::securityOrigin
;
228 using SecurityContext::contentSecurityPolicy
;
229 using TreeScope::getElementById
;
231 bool canContainRangeEndPoint() const override
{ return true; }
233 SelectorQueryCache
& selectorQueryCache();
236 Element
* activeElement() const;
237 bool hasFocus() const;
239 // DOM methods & attributes for Document
241 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy
);
242 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut
);
243 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste
);
244 DEFINE_ATTRIBUTE_EVENT_LISTENER(copy
);
245 DEFINE_ATTRIBUTE_EVENT_LISTENER(cut
);
246 DEFINE_ATTRIBUTE_EVENT_LISTENER(paste
);
247 DEFINE_ATTRIBUTE_EVENT_LISTENER(pointerlockchange
);
248 DEFINE_ATTRIBUTE_EVENT_LISTENER(pointerlockerror
);
249 DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange
);
250 DEFINE_ATTRIBUTE_EVENT_LISTENER(search
);
251 DEFINE_ATTRIBUTE_EVENT_LISTENER(securitypolicyviolation
);
252 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange
);
253 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart
);
254 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel
);
255 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend
);
256 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove
);
257 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart
);
258 DEFINE_ATTRIBUTE_EVENT_LISTENER(wheel
);
260 bool shouldMergeWithLegacyDescription(ViewportDescription::Type
);
261 bool shouldOverrideLegacyDescription(ViewportDescription::Type
);
262 void setViewportDescription(const ViewportDescription
&);
263 const ViewportDescription
& viewportDescription() const { return m_viewportDescription
; }
264 Length
viewportDefaultMinWidth() const { return m_viewportDefaultMinWidth
; }
266 bool hasLegacyViewportTag() const { return m_legacyViewportDescription
.isLegacyViewportType(); }
268 String
outgoingReferrer();
269 String
outgoingOrigin() const;
271 void setDoctype(PassRefPtrWillBeRawPtr
<DocumentType
>);
272 DocumentType
* doctype() const { return m_docType
.get(); }
274 DOMImplementation
& implementation();
276 Element
* documentElement() const
278 return m_documentElement
.get();
281 // Returns whether the Document has an AppCache manifest.
282 bool hasAppCacheManifest() const;
284 Location
* location() const;
286 PassRefPtrWillBeRawPtr
<Element
> createElement(const AtomicString
& name
, ExceptionState
&);
287 PassRefPtrWillBeRawPtr
<DocumentFragment
> createDocumentFragment();
288 PassRefPtrWillBeRawPtr
<Text
> createTextNode(const String
& data
);
289 PassRefPtrWillBeRawPtr
<Comment
> createComment(const String
& data
);
290 PassRefPtrWillBeRawPtr
<CDATASection
> createCDATASection(const String
& data
, ExceptionState
&);
291 PassRefPtrWillBeRawPtr
<ProcessingInstruction
> createProcessingInstruction(const String
& target
, const String
& data
, ExceptionState
&);
292 PassRefPtrWillBeRawPtr
<Attr
> createAttribute(const AtomicString
& name
, ExceptionState
&);
293 PassRefPtrWillBeRawPtr
<Attr
> createAttributeNS(const AtomicString
& namespaceURI
, const AtomicString
& qualifiedName
, ExceptionState
&, bool shouldIgnoreNamespaceChecks
= false);
294 PassRefPtrWillBeRawPtr
<Node
> importNode(Node
* importedNode
, bool deep
, ExceptionState
&);
295 PassRefPtrWillBeRawPtr
<Element
> createElementNS(const AtomicString
& namespaceURI
, const AtomicString
& qualifiedName
, ExceptionState
&);
296 PassRefPtrWillBeRawPtr
<Element
> createElement(const QualifiedName
&, bool createdByParser
);
298 Element
* elementFromPoint(int x
, int y
) const;
299 Vector
<Element
*> elementsFromPoint(int x
, int y
) const;
300 PassRefPtrWillBeRawPtr
<Range
> caretRangeFromPoint(int x
, int y
);
301 Element
* scrollingElement();
303 String
readyState() const;
305 String
defaultCharset() const;
307 AtomicString
charset() const { return Document::encodingName(); }
308 AtomicString
characterSet() const { return Document::encodingName(); }
310 AtomicString
encodingName() const;
312 void setContent(const String
&);
314 String
suggestedMIMEType() const;
315 void setMimeType(const AtomicString
&);
316 AtomicString
contentType() const; // DOM 4 document.contentType
318 const AtomicString
& contentLanguage() const { return m_contentLanguage
; }
319 void setContentLanguage(const AtomicString
&);
321 String
xmlEncoding() const { return m_xmlEncoding
; }
322 String
xmlVersion() const { return m_xmlVersion
; }
323 enum StandaloneStatus
{ StandaloneUnspecified
, Standalone
, NotStandalone
};
324 bool xmlStandalone() const { return m_xmlStandalone
== Standalone
; }
325 StandaloneStatus
xmlStandaloneStatus() const { return static_cast<StandaloneStatus
>(m_xmlStandalone
); }
326 bool hasXMLDeclaration() const { return m_hasXMLDeclaration
; }
328 void setXMLEncoding(const String
& encoding
) { m_xmlEncoding
= encoding
; } // read-only property, only to be set from XMLDocumentParser
329 void setXMLVersion(const String
&, ExceptionState
&);
330 void setXMLStandalone(bool, ExceptionState
&);
331 void setHasXMLDeclaration(bool hasXMLDeclaration
) { m_hasXMLDeclaration
= hasXMLDeclaration
? 1 : 0; }
333 KURL
baseURI() const final
;
335 String
origin() const { return securityOrigin()->toString(); }
337 String
visibilityState() const;
338 PageVisibilityState
pageVisibilityState() const;
340 void didChangeVisibilityState();
342 PassRefPtrWillBeRawPtr
<Node
> adoptNode(PassRefPtrWillBeRawPtr
<Node
> source
, ExceptionState
&);
344 PassRefPtrWillBeRawPtr
<HTMLCollection
> images();
345 PassRefPtrWillBeRawPtr
<HTMLCollection
> embeds();
346 PassRefPtrWillBeRawPtr
<HTMLCollection
> applets();
347 PassRefPtrWillBeRawPtr
<HTMLCollection
> links();
348 PassRefPtrWillBeRawPtr
<HTMLCollection
> forms();
349 PassRefPtrWillBeRawPtr
<HTMLCollection
> anchors();
350 PassRefPtrWillBeRawPtr
<HTMLCollection
> scripts();
351 PassRefPtrWillBeRawPtr
<HTMLAllCollection
> allForBinding();
352 PassRefPtrWillBeRawPtr
<HTMLAllCollection
> all();
354 PassRefPtrWillBeRawPtr
<HTMLCollection
> windowNamedItems(const AtomicString
& name
);
355 PassRefPtrWillBeRawPtr
<DocumentNameCollection
> documentNamedItems(const AtomicString
& name
);
357 bool isHTMLDocument() const { return m_documentClasses
& HTMLDocumentClass
; }
358 bool isXHTMLDocument() const { return m_documentClasses
& XHTMLDocumentClass
; }
359 bool isXMLDocument() const { return m_documentClasses
& XMLDocumentClass
; }
360 bool isImageDocument() const { return m_documentClasses
& ImageDocumentClass
; }
361 bool isSVGDocument() const { return m_documentClasses
& SVGDocumentClass
; }
362 bool isPluginDocument() const { return m_documentClasses
& PluginDocumentClass
; }
363 bool isMediaDocument() const { return m_documentClasses
& MediaDocumentClass
; }
365 bool hasSVGRootNode() const;
367 bool isFrameSet() const;
369 bool isSrcdocDocument() const { return m_isSrcdocDocument
; }
370 bool isMobileDocument() const { return m_isMobileDocument
; }
372 StyleResolver
* styleResolver() const;
373 StyleResolver
& ensureStyleResolver() const;
375 bool isViewSource() const { return m_isViewSource
; }
376 void setIsViewSource(bool);
378 bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces
; }
380 bool isRenderingReady() const { return haveImportsLoaded() && haveStylesheetsLoaded(); }
381 bool isScriptExecutionReady() const { return isRenderingReady(); }
383 // This is a DOM function.
384 StyleSheetList
* styleSheets();
386 StyleEngine
& styleEngine() { ASSERT(m_styleEngine
.get()); return *m_styleEngine
.get(); }
388 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad
; }
389 void setGotoAnchorNeededAfterStylesheetsLoad(bool b
) { m_gotoAnchorNeededAfterStylesheetsLoad
= b
; }
391 // Called when one or more stylesheets in the document may have been added, removed, or changed.
392 void styleResolverChanged(StyleResolverUpdateMode
= FullStyleUpdate
);
393 void styleResolverMayHaveChanged();
395 // FIXME: Switch all callers of styleResolverChanged to these or better ones and then make them
396 // do something smarter.
397 void removedStyleSheet(StyleSheet
*, StyleResolverUpdateMode
= FullStyleUpdate
);
398 void addedStyleSheet(StyleSheet
*) { styleResolverChanged(); }
399 void modifiedStyleSheet(StyleSheet
*, StyleResolverUpdateMode
= FullStyleUpdate
);
400 void changedSelectorWatch() { styleResolverChanged(); }
402 void scheduleUseShadowTreeUpdate(SVGUseElement
&);
403 void unscheduleUseShadowTreeUpdate(SVGUseElement
&);
405 // FIXME: SVG filters should change to store the filter on the ComputedStyle
406 // instead of the LayoutObject so we can get rid of this hack.
407 void scheduleSVGFilterLayerUpdateHack(Element
&);
408 void unscheduleSVGFilterLayerUpdateHack(Element
&);
410 void evaluateMediaQueryList();
412 FormController
& formController();
413 DocumentState
* formElementsState() const;
414 void setStateForNewFormElements(const Vector
<String
>&);
416 FrameView
* view() const; // can be null
417 LocalFrame
* frame() const { return m_frame
; } // can be null
418 FrameHost
* frameHost() const; // can be null
419 Page
* page() const; // can be null
420 Settings
* settings() const; // can be null
422 float devicePixelRatio() const;
424 PassRefPtrWillBeRawPtr
<Range
> createRange();
426 PassRefPtrWillBeRawPtr
<NodeIterator
> createNodeIterator(Node
* root
, unsigned whatToShow
, PassRefPtrWillBeRawPtr
<NodeFilter
>, ExceptionState
&);
427 PassRefPtrWillBeRawPtr
<TreeWalker
> createTreeWalker(Node
* root
, unsigned whatToShow
, PassRefPtrWillBeRawPtr
<NodeFilter
>, ExceptionState
&);
429 // Special support for editing
430 PassRefPtrWillBeRawPtr
<Text
> createEditingTextNode(const String
&);
432 void setupFontBuilder(ComputedStyle
& documentStyle
);
434 bool needsLayoutTreeUpdate() const;
435 void updateLayoutTreeIfNeeded() { updateLayoutTree(NoChange
); }
436 void updateLayoutTreeForNodeIfNeeded(Node
*);
438 void layoutUpdated();
439 enum RunPostLayoutTasks
{
440 RunPostLayoutTasksAsyhnchronously
,
441 RunPostLayoutTasksSynchronously
,
443 void updateLayoutIgnorePendingStylesheets(RunPostLayoutTasks
= RunPostLayoutTasksAsyhnchronously
);
444 PassRefPtr
<ComputedStyle
> styleForElementIgnoringPendingStylesheets(Element
*);
445 PassRefPtr
<ComputedStyle
> styleForPage(int pageIndex
);
447 // Returns true if page box (margin boxes and page borders) is visible.
448 bool isPageBoxVisible(int pageIndex
);
450 // Returns the preferred page size and margins in pixels, assuming 96
451 // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
452 // marginLeft must be initialized to the default values that are used if
453 // auto is specified.
454 void pageSizeAndMarginsInPixels(int pageIndex
, IntSize
& pageSize
, int& marginTop
, int& marginRight
, int& marginBottom
, int& marginLeft
);
456 ResourceFetcher
* fetcher() { return m_fetcher
.get(); }
458 void attach(const AttachContext
& = AttachContext()) override
;
459 void detach(const AttachContext
& = AttachContext()) override
;
461 // If you have a Document, use layoutView() instead which is faster.
462 void layoutObject() const = delete;
464 LayoutView
* layoutView() const { return m_layoutView
; }
466 Document
& axObjectCacheOwner() const;
467 AXObjectCache
* existingAXObjectCache() const;
468 AXObjectCache
* axObjectCache() const;
469 void clearAXObjectCache();
471 // to get visually ordered hebrew and arabic pages right
472 bool visuallyOrdered() const { return m_visuallyOrdered
; }
474 DocumentLoader
* loader() const;
476 // This is the DOM API document.open()
477 void open(Document
* ownerDocument
, ExceptionState
&);
478 // This is used internally and does not handle exceptions.
480 PassRefPtrWillBeRawPtr
<DocumentParser
> implicitOpen(ParserSynchronizationPolicy
);
482 // This is the DOM API document.close()
483 void close(ExceptionState
&);
484 // This is used internally and does not handle exceptions.
486 // In some situations (see the code), we ignore document.close().
487 // explicitClose() bypass these checks and actually tries to close the
489 void explicitClose();
490 // implicitClose() actually does the work of closing the input stream.
491 void implicitClose();
493 bool dispatchBeforeUnloadEvent(ChromeClient
&, bool&);
494 void dispatchUnloadEvents();
496 enum PageDismissalType
{
498 BeforeUnloadDismissal
= 1,
499 PageHideDismissal
= 2,
502 PageDismissalType
pageDismissalEventBeingDispatched() const;
504 void cancelParsing();
506 void write(const SegmentedString
& text
, Document
* ownerDocument
= nullptr, ExceptionState
& = ASSERT_NO_EXCEPTION
);
507 void write(const String
& text
, Document
* ownerDocument
= nullptr, ExceptionState
& = ASSERT_NO_EXCEPTION
);
508 void writeln(const String
& text
, Document
* ownerDocument
= nullptr, ExceptionState
& = ASSERT_NO_EXCEPTION
);
509 void write(LocalDOMWindow
*, const Vector
<String
>& text
, ExceptionState
&);
510 void writeln(LocalDOMWindow
*, const Vector
<String
>& text
, ExceptionState
&);
512 bool wellFormed() const { return m_wellFormed
; }
514 const KURL
& url() const { return m_url
; }
515 void setURL(const KURL
&);
517 // To understand how these concepts relate to one another, please see the
518 // comments surrounding their declaration.
519 const KURL
& baseURL() const { return m_baseURL
; }
520 void setBaseURLOverride(const KURL
&);
521 const KURL
& baseURLOverride() const { return m_baseURLOverride
; }
522 const KURL
& baseElementURL() const { return m_baseElementURL
; }
523 const AtomicString
& baseTarget() const { return m_baseTarget
; }
524 void processBaseElement();
526 KURL
completeURL(const String
&) const;
527 KURL
completeURLWithOverride(const String
&, const KURL
& baseURLOverride
) const;
529 String
userAgent(const KURL
&) const final
;
530 void disableEval(const String
& errorMessage
) final
;
532 CSSStyleSheet
& elementSheet();
534 virtual PassRefPtrWillBeRawPtr
<DocumentParser
> createParser();
535 DocumentParser
* parser() const { return m_parser
.get(); }
536 ScriptableDocumentParser
* scriptableDocumentParser() const;
538 bool printing() const { return m_printing
; }
539 void setPrinting(bool p
) { m_printing
= p
; }
541 bool paginatedForScreen() const { return m_paginatedForScreen
; }
542 void setPaginatedForScreen(bool p
) { m_paginatedForScreen
= p
; }
544 bool paginated() const { return printing() || paginatedForScreen(); }
546 enum CompatibilityMode
{ QuirksMode
, LimitedQuirksMode
, NoQuirksMode
};
548 void setCompatibilityMode(CompatibilityMode
);
549 CompatibilityMode
compatibilityMode() const { return m_compatibilityMode
; }
551 String
compatMode() const;
553 bool inQuirksMode() const { return m_compatibilityMode
== QuirksMode
; }
554 bool inLimitedQuirksMode() const { return m_compatibilityMode
== LimitedQuirksMode
; }
555 bool inNoQuirksMode() const { return m_compatibilityMode
== NoQuirksMode
; }
562 void setReadyState(ReadyState
);
563 bool isLoadCompleted();
570 void setParsingState(ParsingState
);
571 bool parsing() const { return m_parsingState
== Parsing
; }
572 bool isInDOMContentLoaded() const { return m_parsingState
== InDOMContentLoaded
; }
573 bool hasFinishedParsing() const { return m_parsingState
== FinishedParsing
; }
575 bool shouldScheduleLayout() const;
576 int elapsedTime() const;
578 TextLinkColors
& textLinkColors() { return m_textLinkColors
; }
579 VisitedLinkState
& visitedLinkState() const { return *m_visitedLinkState
; }
581 MouseEventWithHitTestResults
prepareMouseEvent(const HitTestRequest
&, const LayoutPoint
&, const PlatformMouseEvent
&);
583 /* Newly proposed CSS3 mechanism for selecting alternate
584 stylesheets using the DOM. May be subject to change as
587 String
preferredStylesheetSet() const;
588 String
selectedStylesheetSet() const;
589 void setSelectedStylesheetSet(const String
&);
591 bool setFocusedElement(PassRefPtrWillBeRawPtr
<Element
>, WebFocusType
= WebFocusTypeNone
, InputDeviceCapabilities
* sourceCapabilities
= nullptr);
592 Element
* focusedElement() const { return m_focusedElement
.get(); }
593 UserActionElementSet
& userActionElements() { return m_userActionElements
; }
594 const UserActionElementSet
& userActionElements() const { return m_userActionElements
; }
595 void setNeedsFocusedElementCheck();
596 void setAutofocusElement(Element
*);
597 Element
* autofocusElement() const { return m_autofocusElement
.get(); }
599 void setActiveHoverElement(PassRefPtrWillBeRawPtr
<Element
>);
600 Element
* activeHoverElement() const { return m_activeHoverElement
.get(); }
602 Node
* hoverNode() const { return m_hoverNode
.get(); }
604 void removeFocusedElementOfSubtree(Node
*, bool amongChildrenOnly
= false);
605 void hoveredNodeDetached(Element
&);
606 void activeChainNodeDetached(Element
&);
608 void updateHoverActiveState(const HitTestRequest
&, Element
*);
610 // Updates for :target (CSS3 selector).
611 void setCSSTarget(Element
*);
612 Element
* cssTarget() const { return m_cssTarget
; }
614 void scheduleLayoutTreeUpdateIfNeeded();
615 bool hasPendingForcedStyleRecalc() const;
617 void registerNodeList(const LiveNodeListBase
*);
618 void unregisterNodeList(const LiveNodeListBase
*);
619 void registerNodeListWithIdNameCache(const LiveNodeListBase
*);
620 void unregisterNodeListWithIdNameCache(const LiveNodeListBase
*);
621 bool shouldInvalidateNodeListCaches(const QualifiedName
* attrName
= nullptr) const;
622 void invalidateNodeListCaches(const QualifiedName
* attrName
);
624 void attachNodeIterator(NodeIterator
*);
625 void detachNodeIterator(NodeIterator
*);
626 void moveNodeIteratorsToNewDocument(Node
&, Document
&);
628 void attachRange(Range
*);
629 void detachRange(Range
*);
631 void updateRangesAfterChildrenChanged(ContainerNode
*);
632 void updateRangesAfterNodeMovedToAnotherDocument(const Node
&);
633 // nodeChildrenWillBeRemoved is used when removing all node children at once.
634 void nodeChildrenWillBeRemoved(ContainerNode
&);
635 // nodeWillBeRemoved is only safe when removing one node at a time.
636 void nodeWillBeRemoved(Node
&);
637 bool canAcceptChild(const Node
& newChild
, const Node
* oldChild
, ExceptionState
&) const;
639 void didInsertText(Node
*, unsigned offset
, unsigned length
);
640 void didRemoveText(Node
*, unsigned offset
, unsigned length
);
641 void didMergeTextNodes(Text
& oldNode
, unsigned offset
);
642 void didSplitTextNode(Text
& oldNode
);
644 void clearDOMWindow() { m_domWindow
= nullptr; }
645 LocalDOMWindow
* domWindow() const { return m_domWindow
; }
647 // Helper functions for forwarding LocalDOMWindow event related tasks to the LocalDOMWindow if it exists.
648 void setWindowAttributeEventListener(const AtomicString
& eventType
, PassRefPtrWillBeRawPtr
<EventListener
>);
649 EventListener
* getWindowAttributeEventListener(const AtomicString
& eventType
);
651 static void registerEventFactory(PassOwnPtr
<EventFactoryBase
>);
652 static PassRefPtrWillBeRawPtr
<Event
> createEvent(const String
& eventType
, ExceptionState
&);
654 // keep track of what types of event listeners are registered, so we don't
655 // dispatch events unnecessarily
657 DOMSUBTREEMODIFIED_LISTENER
= 1,
658 DOMNODEINSERTED_LISTENER
= 1 << 1,
659 DOMNODEREMOVED_LISTENER
= 1 << 2,
660 DOMNODEREMOVEDFROMDOCUMENT_LISTENER
= 1 << 3,
661 DOMNODEINSERTEDINTODOCUMENT_LISTENER
= 1 << 4,
662 DOMCHARACTERDATAMODIFIED_LISTENER
= 1 << 5,
663 ANIMATIONEND_LISTENER
= 1 << 6,
664 ANIMATIONSTART_LISTENER
= 1 << 7,
665 ANIMATIONITERATION_LISTENER
= 1 << 8,
666 TRANSITIONEND_LISTENER
= 1 << 9,
667 SCROLL_LISTENER
= 1 << 10
671 bool hasListenerType(ListenerType listenerType
) const { return (m_listenerTypes
& listenerType
); }
672 void addListenerTypeIfNeeded(const AtomicString
& eventType
);
674 bool hasMutationObserversOfType(MutationObserver::MutationType type
) const
676 return m_mutationObserverTypes
& type
;
678 bool hasMutationObservers() const { return m_mutationObserverTypes
; }
679 void addMutationObserverTypes(MutationObserverOptions types
) { m_mutationObserverTypes
|= types
; }
681 void updateViewportDescription();
682 void processReferrerPolicy(const String
& policy
);
684 // Returns the owning element in the parent document.
685 // Returns nullptr if this is the top level document.
686 HTMLFrameOwnerElement
* ownerElement() const;
688 // Returns true if this document belongs to a frame that the parent document
689 // made invisible (for instance by setting as style display:none).
690 bool isInInvisibleSubframe() const;
692 String
title() const { return m_title
; }
693 void setTitle(const String
&);
695 Element
* titleElement() const { return m_titleElement
.get(); }
696 void setTitleElement(Element
*);
697 void removeTitle(Element
* titleElement
);
699 const AtomicString
& dir();
700 void setDir(const AtomicString
&);
702 String
cookie(ExceptionState
&) const;
703 void setCookie(const String
&, ExceptionState
&);
705 const AtomicString
& referrer() const;
707 String
domain() const;
708 void setDomain(const String
& newDomain
, ExceptionState
&);
710 String
lastModified() const;
712 // The cookieURL is used to query the cookie database for this document's
713 // cookies. For example, if the cookie URL is http://example.com, we'll
714 // use the non-Secure cookies for example.com when computing
717 // Q: How is the cookieURL different from the document's URL?
718 // A: The two URLs are the same almost all the time. However, if one
719 // document inherits the security context of another document, it
720 // inherits its cookieURL but not its URL.
722 const KURL
& cookieURL() const { return m_cookieURL
; }
723 void setCookieURL(const KURL
& url
) { m_cookieURL
= url
; }
725 const KURL
& firstPartyForCookies() const;
727 // The following implements the rule from HTML 4 for what valid names are.
728 // To get this right for all the XML cases, we probably have to improve this or move it
729 // and make it sensitive to the type of document.
730 static bool isValidName(const String
&);
732 // The following breaks a qualified name into a prefix and a local name.
733 // It also does a validity check, and returns false if the qualified name
734 // is invalid. It also sets ExceptionCode when name is invalid.
735 static bool parseQualifiedName(const AtomicString
& qualifiedName
, AtomicString
& prefix
, AtomicString
& localName
, ExceptionState
&);
737 // Checks to make sure prefix and namespace do not conflict (per DOM Core 3)
738 static bool hasValidNamespaceForElements(const QualifiedName
&);
739 static bool hasValidNamespaceForAttributes(const QualifiedName
&);
741 // "body element" as defined by HTML5 (https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2).
742 // That is, the first body or frameset child of the document element.
743 HTMLElement
* body() const;
745 // "HTML body element" as defined by CSSOM View spec (http://dev.w3.org/csswg/cssom-view/#the-html-body-element).
746 // That is, the first body child of the document element.
747 HTMLBodyElement
* firstBodyElement() const;
749 void setBody(PassRefPtrWillBeRawPtr
<HTMLElement
>, ExceptionState
&);
751 HTMLHeadElement
* head() const;
753 // Decide which element is to define the viewport's overflow policy. If |rootStyle| is set, use
754 // that as the style for the root element, rather than obtaining it on our own. The reason for
755 // this is that style may not have been associated with the elements yet - in which case it may
756 // have been calculated on the fly (without associating it with the actual element) somewhere.
757 Element
* viewportDefiningElement(const ComputedStyle
* rootStyle
= nullptr) const;
759 DocumentMarkerController
& markers() const { return *m_markers
; }
761 bool execCommand(const String
& command
, bool showUI
, const String
& value
, ExceptionState
&);
762 bool queryCommandEnabled(const String
& command
, ExceptionState
&);
763 bool queryCommandIndeterm(const String
& command
, ExceptionState
&);
764 bool queryCommandState(const String
& command
, ExceptionState
&);
765 bool queryCommandSupported(const String
& command
, ExceptionState
&);
766 String
queryCommandValue(const String
& command
, ExceptionState
&);
768 KURL
openSearchDescriptionURL();
770 // designMode support
771 bool inDesignMode() const { return m_designMode
; }
772 String
designMode() const;
773 void setDesignMode(const String
&);
775 Document
* parentDocument() const;
776 Document
& topDocument() const;
777 WeakPtrWillBeRawPtr
<Document
> contextDocument();
779 ScriptRunner
* scriptRunner() { return m_scriptRunner
.get(); }
781 HTMLScriptElement
* currentScript() const { return !m_currentScriptStack
.isEmpty() ? m_currentScriptStack
.last().get() : nullptr; }
782 void pushCurrentScript(PassRefPtrWillBeRawPtr
<HTMLScriptElement
>);
783 void popCurrentScript();
785 void setTransformSource(PassOwnPtr
<TransformSource
>);
786 TransformSource
* transformSource() const { return m_transformSource
.get(); }
788 void incDOMTreeVersion() { ASSERT(m_lifecycle
.stateAllowsTreeMutations()); m_domTreeVersion
= ++s_globalTreeVersion
; }
789 uint64_t domTreeVersion() const { return m_domTreeVersion
; }
791 uint64_t styleVersion() const { return m_styleVersion
; }
793 enum PendingSheetLayout
{ NoLayoutWithPendingSheets
, DidLayoutWithPendingSheets
, IgnoreLayoutWithPendingSheets
};
795 bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout
== DidLayoutWithPendingSheets
; }
796 bool ignoreLayoutWithPendingStylesheets() const { return m_pendingSheetLayout
== IgnoreLayoutWithPendingSheets
; }
798 bool hasNodesWithPlaceholderStyle() const { return m_hasNodesWithPlaceholderStyle
; }
799 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle
= true; }
801 Vector
<IconURL
> iconURLs(int iconTypesMask
);
803 Color
themeColor() const;
805 // Returns the HTMLLinkElement currently in use for the Web Manifest.
806 // Returns null if there is no such element.
807 HTMLLinkElement
* linkManifest() const;
809 void setUseSecureKeyboardEntryWhenActive(bool);
810 bool useSecureKeyboardEntryWhenActive() const;
812 void updateFocusAppearanceSoon(bool restorePreviousSelection
);
813 void cancelFocusAppearanceUpdate();
815 // Extension for manipulating canvas drawing contexts for use in CSS
816 ScriptValue
getCSSCanvasContext(ScriptState
*, const String
& type
, const String
& name
, int width
, int height
);
817 HTMLCanvasElement
& getCSSCanvasElement(const String
& name
);
819 bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled
; }
820 void parseDNSPrefetchControlHeader(const String
&);
822 // FIXME(crbug.com/305497): This should be removed once LocalDOMWindow is an ExecutionContext.
823 void postTask(const WebTraceLocation
&, PassOwnPtr
<ExecutionContextTask
>) override
; // Executes the task on context's thread asynchronously.
824 void postInspectorTask(const WebTraceLocation
&, PassOwnPtr
<ExecutionContextTask
>);
826 void tasksWereSuspended() final
;
827 void tasksWereResumed() final
;
828 void suspendScheduledTasks() final
;
829 void resumeScheduledTasks() final
;
830 bool tasksNeedSuspension() final
;
832 void finishedParsing();
834 void setEncodingData(const DocumentEncodingData
& newData
);
835 const WTF::TextEncoding
& encoding() const { return m_encodingData
.encoding(); }
837 bool encodingWasDetectedHeuristically() const { return m_encodingData
.wasDetectedHeuristically(); }
838 bool sawDecodingError() const { return m_encodingData
.sawDecodingError(); }
840 void setAnnotatedRegionsDirty(bool f
) { m_annotatedRegionsDirty
= f
; }
841 bool annotatedRegionsDirty() const { return m_annotatedRegionsDirty
; }
842 bool hasAnnotatedRegions () const { return m_hasAnnotatedRegions
; }
843 void setHasAnnotatedRegions(bool f
) { m_hasAnnotatedRegions
= f
; }
844 const Vector
<AnnotatedRegionValue
>& annotatedRegions() const;
845 void setAnnotatedRegions(const Vector
<AnnotatedRegionValue
>&);
847 void removeAllEventListeners() final
;
849 const SVGDocumentExtensions
* svgExtensions();
850 SVGDocumentExtensions
& accessSVGExtensions();
852 void initSecurityContext();
853 void initSecurityContext(const DocumentInit
&);
854 void initContentSecurityPolicy(PassRefPtrWillBeRawPtr
<ContentSecurityPolicy
> = nullptr);
856 bool allowInlineEventHandlers(Node
*, EventListener
*, const String
& contextURL
, const WTF::OrdinalNumber
& contextLine
);
857 bool allowExecutingScripts(Node
*);
859 void statePopped(PassRefPtr
<SerializedScriptValue
>);
861 enum LoadEventProgress
{
865 BeforeUnloadEventInProgress
,
866 BeforeUnloadEventCompleted
,
868 UnloadEventInProgress
,
871 bool loadEventStillNeeded() const { return m_loadEventProgress
== LoadEventNotRun
; }
872 bool processingLoadEvent() const { return m_loadEventProgress
== LoadEventInProgress
; }
873 bool loadEventFinished() const { return m_loadEventProgress
>= LoadEventCompleted
; }
874 bool unloadStarted() const { return m_loadEventProgress
>= PageHideInProgress
; }
875 bool processingBeforeUnload() const { return m_loadEventProgress
== BeforeUnloadEventInProgress
; }
876 void suppressLoadEvent();
878 void setContainsPlugins() { m_containsPlugins
= true; }
879 bool containsPlugins() const { return m_containsPlugins
; }
881 bool isContextThread() const final
;
882 bool isJSExecutionForbidden() const final
{ return false; }
884 bool containsValidityStyleRules() const { return m_containsValidityStyleRules
; }
885 void setContainsValidityStyleRules() { m_containsValidityStyleRules
= true; }
887 void enqueueResizeEvent();
888 void enqueueScrollEventForNode(Node
*);
889 void enqueueAnimationFrameEvent(PassRefPtrWillBeRawPtr
<Event
>);
890 // Only one event for a target/event type combination will be dispatched per frame.
891 void enqueueUniqueAnimationFrameEvent(PassRefPtrWillBeRawPtr
<Event
>);
892 void enqueueMediaQueryChangeListeners(WillBeHeapVector
<RefPtrWillBeMember
<MediaQueryListListener
>>&);
894 void dispatchEventsForPrinting();
896 bool hasFullscreenSupplement() const { return m_hasFullscreenSupplement
; }
897 void setHasFullscreenSupplement() { m_hasFullscreenSupplement
= true; }
899 void exitPointerLock();
900 Element
* pointerLockElement() const;
902 // Used to allow element that loads data without going through a FrameLoader to delay the 'load' event.
903 void incrementLoadEventDelayCount() { ++m_loadEventDelayCount
; }
904 void decrementLoadEventDelayCount();
905 void checkLoadEventSoon();
906 bool isDelayingLoadEvent();
907 void loadPluginsSoon();
909 PassRefPtrWillBeRawPtr
<Touch
> createTouch(DOMWindow
*, EventTarget
*, int identifier
, double pageX
, double pageY
, double screenX
, double screenY
, double radiusX
, double radiusY
, float rotationAngle
, float force
) const;
910 PassRefPtrWillBeRawPtr
<TouchList
> createTouchList(WillBeHeapVector
<RefPtrWillBeMember
<Touch
>>&) const;
912 const DocumentTiming
& timing() const { return m_documentTiming
; }
914 int requestAnimationFrame(FrameRequestCallback
*);
915 void cancelAnimationFrame(int id
);
916 void serviceScriptedAnimations(double monotonicAnimationStartTime
);
918 int requestIdleCallback(IdleRequestCallback
*, double timeoutMillis
);
919 void cancelIdleCallback(int id
);
921 EventTarget
* errorEventTarget() final
;
922 void logExceptionToConsole(const String
& errorMessage
, int scriptId
, const String
& sourceURL
, int lineNumber
, int columnNumber
, PassRefPtrWillBeRawPtr
<ScriptCallStack
>) final
;
924 void initDNSPrefetch();
926 bool isInDocumentWrite() { return m_writeRecursionDepth
> 0; }
928 TextAutosizer
* textAutosizer();
930 PassRefPtrWillBeRawPtr
<Element
> createElement(const AtomicString
& localName
, const AtomicString
& typeExtension
, ExceptionState
&);
931 PassRefPtrWillBeRawPtr
<Element
> createElementNS(const AtomicString
& namespaceURI
, const AtomicString
& qualifiedName
, const AtomicString
& typeExtension
, ExceptionState
&);
932 ScriptValue
registerElement(ScriptState
*, const AtomicString
& name
, const ElementRegistrationOptions
&, ExceptionState
&, CustomElement::NameSet validNames
= CustomElement::StandardNames
);
933 CustomElementRegistrationContext
* registrationContext() { return m_registrationContext
.get(); }
934 CustomElementMicrotaskRunQueue
* customElementMicrotaskRunQueue();
936 void setImportsController(HTMLImportsController
*);
937 HTMLImportsController
* importsController() const { return m_importsController
; }
938 HTMLImportLoader
* importLoader() const;
940 bool haveImportsLoaded() const;
941 void didLoadAllImports();
943 void adjustFloatQuadsForScrollAndAbsoluteZoom(Vector
<FloatQuad
>&, LayoutObject
&);
944 void adjustFloatRectForScrollAndAbsoluteZoom(FloatRect
&, LayoutObject
&);
946 bool hasActiveParser();
947 unsigned activeParserCount() { return m_activeParserCount
; }
948 void incrementActiveParserCount() { ++m_activeParserCount
; }
949 void decrementActiveParserCount() { --m_activeParserCount
; }
951 void setContextFeatures(ContextFeatures
&);
952 ContextFeatures
& contextFeatures() const { return *m_contextFeatures
; }
954 ElementDataCache
* elementDataCache() { return m_elementDataCache
.get(); }
956 void didLoadAllScriptBlockingResources();
957 void didRemoveAllPendingStylesheet();
959 bool inStyleRecalc() const { return m_lifecycle
.state() == DocumentLifecycle::InStyleRecalc
; }
961 // Return a Locale for the default locale if the argument is null or empty.
962 Locale
& getCachedLocale(const AtomicString
& locale
= nullAtom
);
964 AnimationClock
& animationClock() { return m_animationClock
; }
965 AnimationTimeline
& timeline() const { return *m_timeline
; }
966 CompositorPendingAnimations
& compositorPendingAnimations() { return m_compositorPendingAnimations
; }
968 void addToTopLayer(Element
*, const Element
* before
= nullptr);
969 void removeFromTopLayer(Element
*);
970 const WillBeHeapVector
<RefPtrWillBeMember
<Element
>>& topLayerElements() const { return m_topLayerElements
; }
971 HTMLDialogElement
* activeModalDialog() const;
973 // A non-null m_templateDocumentHost implies that |this| was created by ensureTemplateDocument().
974 bool isTemplateDocument() const { return !!m_templateDocumentHost
; }
975 Document
& ensureTemplateDocument();
976 Document
* templateDocumentHost() { return m_templateDocumentHost
; }
978 // TODO(thestig): Rename these and related functions, since we can call them
979 // for labels and input fields outside of forms as well.
980 void didAssociateFormControl(Element
*);
981 void removeFormAssociation(Element
*);
983 void addConsoleMessage(PassRefPtrWillBeRawPtr
<ConsoleMessage
>) final
;
985 LocalDOMWindow
* executingWindow() final
;
986 LocalFrame
* executingFrame();
988 DocumentLifecycle
& lifecycle() { return m_lifecycle
; }
989 bool isActive() const { return m_lifecycle
.isActive(); }
990 bool isDetached() const { return m_lifecycle
.state() >= DocumentLifecycle::Stopping
; }
991 bool isStopped() const { return m_lifecycle
.state() == DocumentLifecycle::Stopped
; }
992 bool isDisposed() const { return m_lifecycle
.state() == DocumentLifecycle::Disposed
; }
994 enum HttpRefreshType
{
995 HttpRefreshFromHeader
,
996 HttpRefreshFromMetaTag
998 void maybeHandleHttpRefresh(const String
&, HttpRefreshType
);
1000 void updateSecurityOrigin(PassRefPtr
<SecurityOrigin
>);
1002 void setHasViewportUnits() { m_hasViewportUnits
= true; }
1003 bool hasViewportUnits() const { return m_hasViewportUnits
; }
1004 void notifyResizeForViewportUnits();
1006 void registerVisibilityObserver(DocumentVisibilityObserver
*);
1007 void unregisterVisibilityObserver(DocumentVisibilityObserver
*);
1009 void updateStyleInvalidationIfNeeded();
1011 DECLARE_VIRTUAL_TRACE();
1013 bool hasSVGFilterElementsRequiringLayerUpdate() const { return m_layerUpdateSVGFilterElements
.size(); }
1014 void didRecalculateStyleForElement() { ++m_styleRecalcElementCounter
; }
1016 AtomicString
convertLocalName(const AtomicString
&);
1018 void platformColorsChanged();
1020 DOMTimerCoordinator
* timers() final
;
1022 v8::Local
<v8::Object
> wrap(v8::Isolate
*, v8::Local
<v8::Object
> creationContext
) override
;
1023 v8::Local
<v8::Object
> associateWithWrapper(v8::Isolate
*, const WrapperTypeInfo
*, v8::Local
<v8::Object
> wrapper
) override WARN_UNUSED_RETURN
;
1025 OriginsUsingFeatures::Value
& originsUsingFeaturesValue() { return m_originsUsingFeaturesValue
; }
1027 NthIndexCache
* nthIndexCache() const { return m_nthIndexCache
; }
1029 bool isPrivilegedContext(String
& errorMessage
, const PrivilegeContextCheck
= StandardPrivilegeCheck
) const override
;
1031 ClientHintsPreferences
& clientHintsPreferences() { return m_clientHintsPreferences
; }
1033 CanvasFontCache
* canvasFontCache();
1035 // Used by unit tests so that all parsing will be main thread for
1036 // controlling parsing and chunking precisely.
1037 static void setThreadedParsingEnabledForTesting(bool);
1038 static bool threadedParsingEnabledForTesting();
1040 void incrementNodeCount() { m_nodeCount
++; }
1041 void decrementNodeCount()
1043 ASSERT(m_nodeCount
> 0);
1046 int nodeCount() const { return m_nodeCount
; }
1048 using WeakDocumentSet
= WillBeHeapHashSet
<RawPtrWillBeWeakMember
<Document
>>;
1049 static WeakDocumentSet
& liveDocumentSet();
1052 Document(const DocumentInit
&, DocumentClassFlags
= DefaultDocumentClass
);
1054 void didUpdateSecurityOrigin() final
;
1056 void clearXMLVersion() { m_xmlVersion
= String(); }
1059 void dispose() override
;
1062 virtual PassRefPtrWillBeRawPtr
<Document
> cloneDocumentWithoutChildren();
1064 bool importContainerNodeChildren(ContainerNode
* oldContainerNode
, PassRefPtrWillBeRawPtr
<ContainerNode
> newContainerNode
, ExceptionState
&);
1065 void lockCompatibilityMode() { m_compatibilityModeLocked
= true; }
1066 ParserSynchronizationPolicy
parserSynchronizationPolicy() const { return m_parserSyncPolicy
; }
1069 friend class IgnoreDestructiveWriteCountIncrementer
;
1070 friend class NthIndexCache
;
1072 bool isDocumentFragment() const = delete; // This will catch anyone doing an unnecessary check.
1073 bool isDocumentNode() const = delete; // This will catch anyone doing an unnecessary check.
1074 bool isElementNode() const = delete; // This will catch anyone doing an unnecessary check.
1076 ScriptedAnimationController
& ensureScriptedAnimationController();
1077 ScriptedIdleTaskController
& ensureScriptedIdleTaskController();
1078 SecurityContext
& securityContext() final
{ return *this; }
1079 EventQueue
* eventQueue() const final
;
1081 // FIXME: Rename the StyleRecalc state to LayoutTreeUpdate.
1082 bool hasPendingStyleRecalc() const { return m_lifecycle
.state() == DocumentLifecycle::VisualUpdatePending
; }
1084 bool shouldScheduleLayoutTreeUpdate() const;
1085 void scheduleLayoutTreeUpdate();
1087 bool needsFullLayoutTreeUpdate() const;
1089 void inheritHtmlAndBodyElementStyles(StyleRecalcChange
);
1091 bool dirtyElementsForLayerUpdate();
1093 void updateUseShadowTreesIfNeeded();
1094 void evaluateMediaQueryListIfNeeded();
1096 void updateLayoutTree(StyleRecalcChange
);
1097 void updateStyle(StyleRecalcChange
);
1098 void notifyLayoutTreeOfSubtreeChanges();
1100 void detachParser();
1102 bool isDocument() const final
{ return true; }
1104 void childrenChanged(const ChildrenChange
&) override
;
1106 String
nodeName() const final
;
1107 NodeType
nodeType() const final
;
1108 bool childTypeAllowed(NodeType
) const final
;
1109 PassRefPtrWillBeRawPtr
<Node
> cloneNode(bool deep
= true) final
;
1110 void cloneDataFromDocument(const Document
&);
1113 void refExecutionContext() final
{ ref(); }
1114 void derefExecutionContext() final
{ deref(); }
1117 const KURL
& virtualURL() const final
; // Same as url(), but needed for ExecutionContext to implement it without a performance loss for direct calls.
1118 KURL
virtualCompleteURL(const String
&) const final
; // Same as completeURL() for the same reason as above.
1120 void reportBlockedScriptExecutionToInspector(const String
& directiveText
) final
;
1122 double timerAlignmentInterval() const final
;
1124 void updateTitle(const String
&);
1125 void updateFocusAppearanceTimerFired(Timer
<Document
>*);
1126 void updateBaseURL();
1128 void executeScriptsWaitingForResources();
1130 void loadEventDelayTimerFired(Timer
<Document
>*);
1131 void pluginLoadingTimerFired(Timer
<Document
>*);
1133 // Note that dispatching a window load event may cause the LocalDOMWindow to be detached from
1134 // the LocalFrame, so callers should take a reference to the LocalDOMWindow (which owns us) to
1135 // prevent the Document from getting blown away from underneath them.
1136 void dispatchWindowLoadEvent();
1138 void addListenerType(ListenerType listenerType
) { m_listenerTypes
|= listenerType
; }
1139 void addMutationEventListenerTypeIfEnabled(ListenerType
);
1141 void didAssociateFormControlsTimerFired(Timer
<Document
>*);
1143 void clearFocusedElementSoon();
1144 void clearFocusedElementTimerFired(Timer
<Document
>*);
1146 bool haveStylesheetsLoaded() const;
1148 void setHoverNode(PassRefPtrWillBeRawPtr
<Node
>);
1150 using EventFactorySet
= HashSet
<OwnPtr
<EventFactoryBase
>>;
1151 static EventFactorySet
& eventFactories();
1153 void setNthIndexCache(NthIndexCache
* nthIndexCache
) { ASSERT(!m_nthIndexCache
|| !nthIndexCache
); m_nthIndexCache
= nthIndexCache
; }
1155 DocumentLifecycle m_lifecycle
;
1157 bool m_hasNodesWithPlaceholderStyle
;
1158 bool m_evaluateMediaQueriesOnStyleRecalc
;
1160 // If we do ignore the pending stylesheet count, then we need to add a boolean
1161 // to track that this happened so that we can do a full repaint when the stylesheets
1162 // do eventually load.
1163 PendingSheetLayout m_pendingSheetLayout
;
1165 RawPtrWillBeMember
<LocalFrame
> m_frame
;
1166 RawPtrWillBeMember
<LocalDOMWindow
> m_domWindow
;
1167 // FIXME: oilpan: when we get rid of the transition types change the
1168 // HTMLImportsController to not be a DocumentSupplement since it is
1169 // redundant with oilpan.
1170 RawPtrWillBeMember
<HTMLImportsController
> m_importsController
;
1172 PersistentWillBeMember
<ResourceFetcher
> m_fetcher
;
1173 RefPtrWillBeMember
<DocumentParser
> m_parser
;
1174 unsigned m_activeParserCount
;
1175 RefPtrWillBeMember
<ContextFeatures
> m_contextFeatures
;
1180 KURL m_url
; // Document.URL: The URL from which this document was retrieved.
1181 KURL m_baseURL
; // Node.baseURI: The URL to use when resolving relative URLs.
1182 KURL m_baseURLOverride
; // An alternative base URL that takes precedence over m_baseURL (but not m_baseElementURL).
1183 KURL m_baseElementURL
; // The URL set by the <base> element.
1184 KURL m_cookieURL
; // The URL to use for cookie access.
1186 AtomicString m_baseTarget
;
1188 // Mime-type of the document in case it was cloned or created by XHR.
1189 AtomicString m_mimeType
;
1191 RefPtrWillBeMember
<DocumentType
> m_docType
;
1192 OwnPtrWillBeMember
<DOMImplementation
> m_implementation
;
1194 RefPtrWillBeMember
<CSSStyleSheet
> m_elemSheet
;
1197 bool m_paginatedForScreen
;
1199 CompatibilityMode m_compatibilityMode
;
1200 bool m_compatibilityModeLocked
; // This is cheaper than making setCompatibilityMode virtual.
1202 OwnPtr
<CancellableTaskFactory
> m_executeScriptsWaitingForResourcesTask
;
1204 bool m_hasAutofocused
;
1205 Timer
<Document
> m_clearFocusedElementTimer
;
1206 RefPtrWillBeMember
<Element
> m_autofocusElement
;
1207 RefPtrWillBeMember
<Element
> m_focusedElement
;
1208 RefPtrWillBeMember
<Node
> m_hoverNode
;
1209 RefPtrWillBeMember
<Element
> m_activeHoverElement
;
1210 RefPtrWillBeMember
<Element
> m_documentElement
;
1211 UserActionElementSet m_userActionElements
;
1213 uint64_t m_domTreeVersion
;
1214 static uint64_t s_globalTreeVersion
;
1216 uint64_t m_styleVersion
;
1218 WillBeHeapHashSet
<RawPtrWillBeWeakMember
<NodeIterator
>> m_nodeIterators
;
1219 using AttachedRangeSet
= WillBeHeapHashSet
<RawPtrWillBeWeakMember
<Range
>>;
1220 AttachedRangeSet m_ranges
;
1222 unsigned short m_listenerTypes
;
1224 MutationObserverOptions m_mutationObserverTypes
;
1226 OwnPtrWillBeMember
<StyleEngine
> m_styleEngine
;
1227 RefPtrWillBeMember
<StyleSheetList
> m_styleSheetList
;
1229 OwnPtrWillBeMember
<FormController
> m_formController
;
1231 TextLinkColors m_textLinkColors
;
1232 const OwnPtrWillBeMember
<VisitedLinkState
> m_visitedLinkState
;
1234 bool m_visuallyOrdered
;
1235 ReadyState m_readyState
;
1236 ParsingState m_parsingState
;
1238 bool m_gotoAnchorNeededAfterStylesheetsLoad
;
1239 bool m_isDNSPrefetchEnabled
;
1240 bool m_haveExplicitlyDisabledDNSPrefetch
;
1241 bool m_containsValidityStyleRules
;
1242 bool m_updateFocusAppearanceRestoresSelection
;
1243 bool m_containsPlugins
;
1245 // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter
1246 unsigned m_ignoreDestructiveWriteCount
;
1250 RefPtrWillBeMember
<Element
> m_titleElement
;
1252 PersistentWillBeMember
<AXObjectCache
> m_axObjectCache
;
1253 OwnPtrWillBeMember
<DocumentMarkerController
> m_markers
;
1255 Timer
<Document
> m_updateFocusAppearanceTimer
;
1257 RawPtrWillBeMember
<Element
> m_cssTarget
;
1259 LoadEventProgress m_loadEventProgress
;
1263 OwnPtrWillBeMember
<ScriptRunner
> m_scriptRunner
;
1265 WillBeHeapVector
<RefPtrWillBeMember
<HTMLScriptElement
>> m_currentScriptStack
;
1267 OwnPtr
<TransformSource
> m_transformSource
;
1269 String m_xmlEncoding
;
1270 String m_xmlVersion
;
1271 unsigned m_xmlStandalone
: 2;
1272 unsigned m_hasXMLDeclaration
: 1;
1274 AtomicString m_contentLanguage
;
1276 DocumentEncodingData m_encodingData
;
1280 WillBeHeapHashSet
<RawPtrWillBeWeakMember
<const LiveNodeListBase
>> m_listsInvalidatedAtDocument
;
1282 // Oilpan keeps track of all registered NodeLists.
1284 // FIXME: Oilpan: improve - only need to know if a NodeList
1285 // is currently alive or not for the different types.
1286 HeapHashSet
<WeakMember
<const LiveNodeListBase
>> m_nodeLists
[numNodeListInvalidationTypes
];
1288 unsigned m_nodeListCounts
[numNodeListInvalidationTypes
];
1291 OwnPtrWillBeMember
<SVGDocumentExtensions
> m_svgExtensions
;
1293 Vector
<AnnotatedRegionValue
> m_annotatedRegions
;
1294 bool m_hasAnnotatedRegions
;
1295 bool m_annotatedRegionsDirty
;
1297 WillBeHeapHashMap
<String
, RefPtrWillBeMember
<HTMLCanvasElement
>> m_cssCanvasElements
;
1299 OwnPtr
<SelectorQueryCache
> m_selectorQueryCache
;
1301 // It is safe to keep a raw, untraced pointer to this stack-allocated
1302 // cache object: it is set upon the cache object being allocated on
1303 // the stack and cleared upon leaving its allocated scope. Hence it
1304 // is acceptable not to trace it -- should a conservative GC occur,
1305 // the cache object's references will be traced by a stack walk.
1306 GC_PLUGIN_IGNORE("461878")
1307 NthIndexCache
* m_nthIndexCache
= nullptr;
1309 bool m_useSecureKeyboardEntryWhenActive
;
1311 DocumentClassFlags m_documentClasses
;
1313 bool m_isViewSource
;
1314 bool m_sawElementsInKnownNamespaces
;
1315 bool m_isSrcdocDocument
;
1316 bool m_isMobileDocument
;
1318 LayoutView
* m_layoutView
;
1321 WeakPtrFactory
<Document
> m_weakFactory
;
1323 WeakPtrWillBeWeakMember
<Document
> m_contextDocument
;
1325 bool m_hasFullscreenSupplement
; // For early return in Fullscreen::fromIfExists()
1327 WillBeHeapVector
<RefPtrWillBeMember
<Element
>> m_topLayerElements
;
1329 int m_loadEventDelayCount
;
1330 Timer
<Document
> m_loadEventDelayTimer
;
1331 Timer
<Document
> m_pluginLoadingTimer
;
1333 ViewportDescription m_viewportDescription
;
1334 ViewportDescription m_legacyViewportDescription
;
1335 Length m_viewportDefaultMinWidth
;
1337 ReferrerPolicy m_referrerPolicy
;
1339 DocumentTiming m_documentTiming
;
1340 RefPtrWillBeMember
<MediaQueryMatcher
> m_mediaQueryMatcher
;
1341 bool m_writeRecursionIsTooDeep
;
1342 unsigned m_writeRecursionDepth
;
1344 RefPtrWillBeMember
<ScriptedAnimationController
> m_scriptedAnimationController
;
1345 RefPtrWillBeMember
<ScriptedIdleTaskController
> m_scriptedIdleTaskController
;
1346 OwnPtrWillBeMember
<MainThreadTaskRunner
> m_taskRunner
;
1347 OwnPtrWillBeMember
<TextAutosizer
> m_textAutosizer
;
1349 RefPtrWillBeMember
<CustomElementRegistrationContext
> m_registrationContext
;
1350 RefPtrWillBeMember
<CustomElementMicrotaskRunQueue
> m_customElementMicrotaskRunQueue
;
1352 void elementDataCacheClearTimerFired(Timer
<Document
>*);
1353 Timer
<Document
> m_elementDataCacheClearTimer
;
1355 OwnPtrWillBeMember
<ElementDataCache
> m_elementDataCache
;
1357 using LocaleIdentifierToLocaleMap
= HashMap
<AtomicString
, OwnPtr
<Locale
>>;
1358 LocaleIdentifierToLocaleMap m_localeCache
;
1360 AnimationClock m_animationClock
;
1361 PersistentWillBeMember
<AnimationTimeline
> m_timeline
;
1362 CompositorPendingAnimations m_compositorPendingAnimations
;
1364 RefPtrWillBeMember
<Document
> m_templateDocument
;
1365 // With Oilpan the templateDocument and the templateDocumentHost
1366 // live and die together. Without Oilpan, the templateDocumentHost
1367 // is a manually managed backpointer from m_templateDocument.
1368 RawPtrWillBeMember
<Document
> m_templateDocumentHost
;
1370 Timer
<Document
> m_didAssociateFormControlsTimer
;
1371 WillBeHeapHashSet
<RefPtrWillBeMember
<Element
>> m_associatedFormControls
;
1373 WillBeHeapHashSet
<RawPtrWillBeMember
<SVGUseElement
>> m_useElementsNeedingUpdate
;
1374 WillBeHeapHashSet
<RawPtrWillBeMember
<Element
>> m_layerUpdateSVGFilterElements
;
1376 DOMTimerCoordinator m_timers
;
1378 bool m_hasViewportUnits
;
1380 using DocumentVisibilityObserverSet
= WillBeHeapHashSet
<RawPtrWillBeWeakMember
<DocumentVisibilityObserver
>>;
1381 DocumentVisibilityObserverSet m_visibilityObservers
;
1383 int m_styleRecalcElementCounter
;
1385 ParserSynchronizationPolicy m_parserSyncPolicy
;
1387 OriginsUsingFeatures::Value m_originsUsingFeaturesValue
;
1389 ClientHintsPreferences m_clientHintsPreferences
;
1391 PersistentWillBeMember
<CanvasFontCache
> m_canvasFontCache
;
1396 extern template class CORE_EXTERN_TEMPLATE_EXPORT WillBeHeapSupplement
<Document
>;
1398 inline bool Document::shouldOverrideLegacyDescription(ViewportDescription::Type origin
)
1400 // The different (legacy) meta tags have different priorities based on the type
1401 // regardless of which order they appear in the DOM. The priority is given by the
1402 // ViewportDescription::Type enum.
1403 return origin
>= m_legacyViewportDescription
.type
;
1406 inline void Document::scheduleLayoutTreeUpdateIfNeeded()
1408 // Inline early out to avoid the function calls below.
1409 if (hasPendingStyleRecalc())
1411 if (shouldScheduleLayoutTreeUpdate() && needsLayoutTreeUpdate())
1412 scheduleLayoutTreeUpdate();
1415 DEFINE_TYPE_CASTS(Document
, ExecutionContext
, context
, context
->isDocument(), context
.isDocument());
1416 DEFINE_NODE_TYPE_CASTS(Document
, isDocumentNode());
1418 #define DEFINE_DOCUMENT_TYPE_CASTS(thisType) \
1419 DEFINE_TYPE_CASTS(thisType, Document, document, document->is##thisType(), document.is##thisType())
1421 // This is needed to avoid ambiguous overloads with the Node and TreeScope versions.
1422 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(Document
)
1424 // Put these methods here, because they require the Document definition, but we really want to inline them.
1426 inline bool Node::isDocumentNode() const
1428 return this == document();
1431 Node
* eventTargetNodeForDocument(Document
*);
1433 DEFINE_TYPE_CASTS(TreeScope
, Document
, document
, true, true);
1435 } // namespace blink
1438 // Outside the WebCore namespace for ease of invocation from gdb.
1439 CORE_EXPORT
void showLiveDocumentInstances();
1442 #endif // Document_h