/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) * (C) 2006 Alexey Proskuryakov (ap@webkit.org) * Copyright (C) 2004-2010, 2012-2013, 2015 Apple Inc. All rights reserved. * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2011 Google Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef Document_h #define Document_h #include "CollectionType.h" #include "Color.h" #include "ContainerNode.h" #include "DocumentEventQueue.h" #include "DocumentTiming.h" #include "FocusDirection.h" #include "FontSelector.h" #include "MediaProducer.h" #include "MutationObserver.h" #include "PageVisibilityState.h" #include "PlatformEvent.h" #include "PlatformScreen.h" #include "ReferrerPolicy.h" #include "Region.h" #include "RenderPtr.h" #include "ScriptExecutionContext.h" #include "StringWithDirection.h" #include "StyleChange.h" #include "TextResourceDecoder.h" #include "Timer.h" #include "TreeScope.h" #include "UserActionElementSet.h" #include "ViewportArguments.h" #include #include #include #include #include #include namespace JSC { class ExecState; #if ENABLE(WEB_REPLAY) class InputCursor; #endif } namespace WebCore { class AXObjectCache; class Attr; class AuthorStyleSheets; class CDATASection; class CSSFontSelector; class CSSStyleDeclaration; class CSSStyleSheet; class CachedCSSStyleSheet; class CachedResourceLoader; class CachedScript; class CanvasRenderingContext; class CharacterData; class Comment; class DOMImplementation; class DOMNamedFlowCollection; class DOMSelection; class DOMWindow; class DOMWrapperWorld; class Database; class DatabaseThread; class DocumentFragment; class DocumentLoader; class DocumentMarkerController; class DocumentParser; class DocumentSharedObjectPool; class DocumentType; class Element; class EntityReference; class Event; class EventListener; class ExtensionStyleSheets; class FloatRect; class FloatQuad; class FormController; class Frame; class FrameView; class HTMLAllCollection; class HTMLBodyElement; class HTMLCanvasElement; class HTMLCollection; class HTMLDocument; class HTMLElement; class HTMLFrameOwnerElement; class HTMLHeadElement; class HTMLIFrameElement; class HTMLImageElement; class HTMLMapElement; class HTMLMediaElement; class HTMLPictureElement; class HTMLScriptElement; class HitTestRequest; class HitTestResult; class IntPoint; class LayoutPoint; class LayoutRect; class LiveNodeList; class JSModuleLoader; class JSNode; class Locale; class Location; class MediaCanStartListener; class MediaPlaybackTarget; class MediaPlaybackTargetClient; class MediaQueryList; class MediaQueryMatcher; class MouseEventWithHitTestResults; class NamedFlowCollection; class NodeFilter; class NodeIterator; class Page; class PlatformMouseEvent; class ProcessingInstruction; class QualifiedName; class Range; class RegisteredEventListener; class RenderView; class RenderFullScreen; class ScriptableDocumentParser; class ScriptElementData; class ScriptRunner; class SecurityOrigin; class SelectorQuery; class SelectorQueryCache; class SerializedScriptValue; class SegmentedString; class Settings; class StyleResolver; class StyleSheet; class StyleSheetContents; class StyleSheetList; class SVGDocumentExtensions; class Text; class TextResourceDecoder; class TreeWalker; class VisitedLinkState; class WebKitNamedFlow; class XMLHttpRequest; class XPathEvaluator; class XPathExpression; class XPathNSResolver; class XPathResult; enum class ShouldOpenExternalURLsPolicy; #if ENABLE(XSLT) class TransformSource; #endif #if ENABLE(CUSTOM_ELEMENTS) class CustomElementDefinitions; #endif #if ENABLE(DASHBOARD_SUPPORT) struct AnnotatedRegionValue; #endif #if ENABLE(IOS_TOUCH_EVENTS) #include #endif #if ENABLE(TOUCH_EVENTS) || ENABLE(IOS_TOUCH_EVENTS) class Touch; class TouchList; #endif #if ENABLE(REQUEST_ANIMATION_FRAME) class RequestAnimationFrameCallback; class ScriptedAnimationController; #endif #if ENABLE(TEXT_AUTOSIZING) class TextAutosizer; #endif #if ENABLE(FONT_LOAD_EVENTS) class FontLoader; #endif typedef int ExceptionCode; #if PLATFORM(IOS) class DeviceMotionClient; class DeviceMotionController; class DeviceOrientationClient; class DeviceOrientationController; #endif #if ENABLE(IOS_TEXT_AUTOSIZING) struct TextAutoSizingHash; class TextAutoSizingKey; class TextAutoSizingValue; struct TextAutoSizingTraits : WTF::GenericHashTraits { static const bool emptyValueIsZero = true; static void constructDeletedValue(TextAutoSizingKey& slot); static bool isDeletedValue(const TextAutoSizingKey& value); }; #endif #if ENABLE(MEDIA_SESSION) class MediaSession; #endif const uint64_t HTMLMediaElementInvalidID = 0; enum PageshowEventPersistence { PageshowEventNotPersisted = 0, PageshowEventPersisted = 1 }; enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded, DeferRecalcStyleIfNeeded }; enum NodeListInvalidationType { DoNotInvalidateOnAttributeChanges = 0, InvalidateOnClassAttrChange, InvalidateOnIdNameAttrChange, InvalidateOnNameAttrChange, InvalidateOnForAttrChange, InvalidateForFormControls, InvalidateOnHRefAttrChange, InvalidateOnAnyAttrChange, }; const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1; enum class EventHandlerRemoval { One, All }; typedef HashCountedSet EventTargetSet; enum DocumentClass { DefaultDocumentClass = 0, HTMLDocumentClass = 1, XHTMLDocumentClass = 1 << 1, ImageDocumentClass = 1 << 2, PluginDocumentClass = 1 << 3, MediaDocumentClass = 1 << 4, SVGDocumentClass = 1 << 5, TextDocumentClass = 1 << 6, XMLDocumentClass = 1 << 7, }; typedef unsigned char DocumentClassFlags; enum class DocumentCompatibilityMode : unsigned char { NoQuirksMode = 1, QuirksMode = 1 << 1, LimitedQuirksMode = 1 << 2 }; enum DimensionsCheck { WidthDimensionsCheck = 1 << 0, HeightDimensionsCheck = 1 << 1, AllDimensionsCheck = 1 << 2 }; enum class SelectionRestorationMode { Restore, SetDefault, }; enum class SelectionRevealMode { Reveal, DoNotReveal }; enum class HttpEquivPolicy { Enabled, DisabledBySettings, DisabledByContentDispositionAttachmentSandbox }; class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext, public FontSelectorClient { public: static Ref create(Frame* frame, const URL& url) { return adoptRef(*new Document(frame, url)); } static Ref createNonRenderedPlaceholder(Frame* frame, const URL& url) { return adoptRef(*new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder)); } static Ref create(ScriptExecutionContext&); virtual ~Document(); // Nodes belonging to this document increase referencingNodeCount - // these are enough to keep the document from being destroyed, but // not enough to keep it from removing its children. This allows a // node that outlives its document to still have a valid document // pointer without introducing reference cycles. void incrementReferencingNodeCount() { ASSERT(!m_deletionHasBegun); ++m_referencingNodeCount; } void decrementReferencingNodeCount() { ASSERT(!m_deletionHasBegun || !m_referencingNodeCount); --m_referencingNodeCount; if (!m_referencingNodeCount && !refCount()) { #if !ASSERT_DISABLED m_deletionHasBegun = true; #endif delete this; } } unsigned referencingNodeCount() const { return m_referencingNodeCount; } void removedLastRef(); WEBCORE_EXPORT static HashSet& allDocuments(); MediaQueryMatcher& mediaQueryMatcher(); using ContainerNode::ref; using ContainerNode::deref; virtual bool canContainRangeEndPoint() const override final { return true; } Element* getElementByAccessKey(const String& key); void invalidateAccessKeyMap(); void addImageElementByCaseFoldedUsemap(const AtomicStringImpl&, HTMLImageElement&); void removeImageElementByCaseFoldedUsemap(const AtomicStringImpl&, HTMLImageElement&); HTMLImageElement* imageElementByCaseFoldedUsemap(const AtomicStringImpl&) const; SelectorQuery* selectorQueryForString(const String&, ExceptionCode&); void clearSelectorQueryCache(); // DOM methods & attributes for Document void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; } ViewportArguments viewportArguments() const { return m_viewportArguments; } #ifndef NDEBUG bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; } #endif void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; } ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } DocumentType* doctype() const; DOMImplementation& implementation(); Element* documentElement() const { return m_documentElement.get(); } static ptrdiff_t documentElementMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentElement); } Element* activeElement(); bool hasFocus() const; bool hasManifest() const; WEBCORE_EXPORT RefPtr createElementForBindings(const AtomicString& tagName, ExceptionCode&); WEBCORE_EXPORT Ref createDocumentFragment(); WEBCORE_EXPORT Ref createTextNode(const String& data); Ref createComment(const String& data); RefPtr createCDATASection(const String& data, ExceptionCode&); RefPtr createProcessingInstruction(const String& target, const String& data, ExceptionCode&); RefPtr createAttribute(const String& name, ExceptionCode&); RefPtr createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false); RefPtr createEntityReference(const String& name, ExceptionCode&); RefPtr importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, false, ec); } RefPtr importNode(Node* importedNode, bool deep, ExceptionCode&); WEBCORE_EXPORT RefPtr createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&); WEBCORE_EXPORT Ref createElement(const QualifiedName&, bool createdByParser); bool cssRegionsEnabled() const; bool cssCompositingEnabled() const; #if ENABLE(CSS_REGIONS) RefPtr webkitGetNamedFlows(); #endif NamedFlowCollection& namedFlows(); Element* elementFromPoint(int x, int y) { return elementFromPoint(LayoutPoint(x, y)); } Element* elementFromPoint(const LayoutPoint& clientPoint); RefPtr caretRangeFromPoint(int x, int y); RefPtr caretRangeFromPoint(const LayoutPoint& clientPoint); Element* scrollingElement(); String readyState() const; String defaultCharset() const; String charset() const { return Document::encoding(); } String characterSetWithUTF8Fallback() const; TextEncoding textEncoding() const; AtomicString encoding() const { return textEncoding().domName(); } void setCharset(const String&); // Used by ObjC / GOBject bindings only. void setContent(const String&); String suggestedMIMEType() const; void overrideMIMEType(const String&); String contentType() const; String contentLanguage() const { return m_contentLanguage; } void setContentLanguage(const String&); String xmlEncoding() const { return m_xmlEncoding; } String xmlVersion() const { return m_xmlVersion; } enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone }; bool xmlStandalone() const { return m_xmlStandalone == Standalone; } StandaloneStatus xmlStandaloneStatus() const { return static_cast(m_xmlStandalone); } bool hasXMLDeclaration() const { return m_hasXMLDeclaration; } void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser void setXMLVersion(const String&, ExceptionCode&); void setXMLStandalone(bool, ExceptionCode&); void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; } String documentURI() const { return m_documentURI; } void setDocumentURI(const String&); #if ENABLE(WEB_REPLAY) JSC::InputCursor& inputCursor() const { return *m_inputCursor; } void setInputCursor(PassRefPtr); #endif void visibilityStateChanged(); String visibilityState() const; bool hidden() const; void setTimerThrottlingEnabled(bool); bool isTimerThrottlingEnabled() const { return m_isTimerThrottlingEnabled; } RefPtr adoptNode(Node* source, ExceptionCode&); Ref images(); Ref embeds(); Ref plugins(); // an alias for embeds() required for the JS DOM bindings. Ref applets(); Ref links(); Ref forms(); Ref anchors(); Ref scripts(); Ref all(); Ref windowNamedItems(const AtomicString& name); Ref documentNamedItems(const AtomicString& name); // Other methods (not part of DOM) bool isSynthesized() const { return m_isSynthesized; } bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; } bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; } bool isXMLDocument() const { return m_documentClasses & XMLDocumentClass; } bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; } bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; } bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; } bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; } bool isTextDocument() const { return m_documentClasses & TextDocumentClass; } bool hasSVGRootNode() const; virtual bool isFrameSet() const { return false; } static ptrdiff_t documentClassesMemoryOffset() { return OBJECT_OFFSETOF(Document, m_documentClasses); } static uint32_t isHTMLDocumentClassFlag() { return HTMLDocumentClass; } bool isSrcdocDocument() const { return m_isSrcdocDocument; } StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); } bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; } StyleResolver& ensureStyleResolver() { if (!m_styleResolver) createStyleResolver(); return *m_styleResolver; } StyleResolver& userAgentShadowTreeStyleResolver(); CSSFontSelector& fontSelector(); void notifyRemovePendingSheetIfNeeded(); WEBCORE_EXPORT bool haveStylesheetsLoaded() const; // This is a DOM function. StyleSheetList& styleSheets(); AuthorStyleSheets& authorStyleSheets() { return *m_authorStyleSheets; } const AuthorStyleSheets& authorStyleSheets() const { return *m_authorStyleSheets; } ExtensionStyleSheets& extensionStyleSheets() { return *m_extensionStyleSheets; } const ExtensionStyleSheets& extensionStyleSheets() const { return *m_extensionStyleSheets; } bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; } void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; } /** * Called when one or more stylesheets in the document may have been added, removed or changed. * * Creates a new style resolver and assign it to this document. This is done by iterating through all nodes in * document (or those before in a HTML document), searching for stylesheets. Stylesheets can be contained in * ,