1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 5 * (C) 2006 Alexey Proskuryakov (ap (at) 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. 10 * 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Library General Public 13 * License as published by the Free Software Foundation; either 14 * version 2 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Library General Public License for more details. 20 * 21 * You should have received a copy of the GNU Library General Public License 22 * along with this library; see the file COPYING.LIB. If not, write to 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 * Boston, MA 02110-1301, USA. 25 * 26 */ 27 28 #ifndef Document_h 29 #define Document_h 30 31 #include "bindings/v8/ScriptValue.h" 32 #include "core/dom/ContainerNode.h" 33 #include "core/dom/CustomElement.h" 34 #include "core/dom/DOMTimeStamp.h" 35 #include "core/dom/DocumentEventQueue.h" 36 #include "core/dom/DocumentInit.h" 37 #include "core/dom/DocumentTiming.h" 38 #include "core/dom/IconURL.h" 39 #include "core/dom/MutationObserver.h" 40 #include "core/dom/QualifiedName.h" 41 #include "core/dom/ScriptExecutionContext.h" 42 #include "core/dom/TextLinkColors.h" 43 #include "core/dom/TreeScope.h" 44 #include "core/dom/UserActionElementSet.h" 45 #include "core/dom/ViewportArguments.h" 46 #include "core/html/CollectionType.h" 47 #include "core/page/FocusDirection.h" 48 #include "core/page/PageVisibilityState.h" 49 #include "weborigin/ReferrerPolicy.h" 50 #include "core/platform/Timer.h" 51 #include "core/platform/text/StringWithDirection.h" 52 #include "core/rendering/HitTestRequest.h" 53 #include "wtf/Deque.h" 54 #include "wtf/HashSet.h" 55 #include "wtf/OwnPtr.h" 56 #include "wtf/PassOwnPtr.h" 57 #include "wtf/PassRefPtr.h" 58 #include "wtf/WeakPtr.h" 59 60 namespace WebCore { 61 62 class AXObjectCache; 63 class Attr; 64 class CDATASection; 65 class CSSStyleDeclaration; 66 class CSSStyleSheet; 67 class CSSStyleSheetResource; 68 class ScriptResource; 69 class CanvasRenderingContext; 70 class CharacterData; 71 class Comment; 72 class ContentSecurityPolicyResponseHeaders; 73 class ContextFeatures; 74 class CustomElementRegistrationContext; 75 class DOMImplementation; 76 class DOMNamedFlowCollection; 77 class DOMSecurityPolicy; 78 class DOMSelection; 79 class DOMWindow; 80 class DOMWrapperWorld; 81 class Database; 82 class DatabaseThread; 83 class DocumentFragment; 84 class DocumentLifecycleNotifier; 85 class DocumentLifecycleObserver; 86 class DocumentLoader; 87 class DocumentMarkerController; 88 class DocumentParser; 89 class DocumentSharedObjectPool; 90 class DocumentStyleSheetCollection; 91 class DocumentTimeline; 92 class DocumentType; 93 class Element; 94 class Event; 95 class EventListener; 96 class ExceptionState; 97 class FloatQuad; 98 class FloatRect; 99 class FormController; 100 class Frame; 101 class FrameView; 102 class HTMLAllCollection; 103 class HTMLCanvasElement; 104 class HTMLCollection; 105 class HTMLDocument; 106 class HTMLElement; 107 class HTMLFrameOwnerElement; 108 class HTMLHeadElement; 109 class HTMLIFrameElement; 110 class HTMLImport; 111 class HTMLMapElement; 112 class HTMLNameCollection; 113 class HTMLScriptElement; 114 class HitTestRequest; 115 class HitTestResult; 116 class IntPoint; 117 class JSNode; 118 class LayoutPoint; 119 class LayoutRect; 120 class LiveNodeListBase; 121 class Locale; 122 class MediaQueryList; 123 class MediaQueryMatcher; 124 class MouseEventWithHitTestResults; 125 class NamedFlowCollection; 126 class NodeFilter; 127 class NodeIterator; 128 class Page; 129 class PlatformMouseEvent; 130 class Prerenderer; 131 class ProcessingInstruction; 132 class Range; 133 class RegisteredEventListener; 134 class RenderView; 135 class RequestAnimationFrameCallback; 136 class ResourceFetcher; 137 class SVGDocumentExtensions; 138 class ScriptElementData; 139 class ScriptRunner; 140 class ScriptableDocumentParser; 141 class ScriptedAnimationController; 142 class SecurityOrigin; 143 class SegmentedString; 144 class SelectorQueryCache; 145 class SerializedScriptValue; 146 class Settings; 147 class StyleResolver; 148 class StyleSheet; 149 class StyleSheetContents; 150 class StyleSheetList; 151 class Text; 152 class TextAutosizer; 153 class TextResourceDecoder; 154 class Touch; 155 class TouchList; 156 class TransformSource; 157 class TreeWalker; 158 class VisitedLinkState; 159 class XMLHttpRequest; 160 161 struct AnnotatedRegionValue; 162 163 class FontLoader; 164 165 typedef int ExceptionCode; 166 167 enum PageshowEventPersistence { 168 PageshowEventNotPersisted = 0, 169 PageshowEventPersisted = 1 170 }; 171 172 // FIXME: We should rename DeferRecalcStyle to RecalcStyleDeferred to be consitent. 173 174 enum StyleResolverUpdateType { RecalcStyleImmediately, DeferRecalcStyle }; 175 176 enum StyleResolverUpdateMode { 177 // Discards the StyleResolver and rebuilds it. 178 FullStyleUpdate, 179 // Attempts to use StyleInvalidationAnalysis to avoid discarding the entire StyleResolver. 180 AnalyzedStyleUpdate 181 }; 182 183 enum NodeListInvalidationType { 184 DoNotInvalidateOnAttributeChanges = 0, 185 InvalidateOnClassAttrChange, 186 InvalidateOnIdNameAttrChange, 187 InvalidateOnNameAttrChange, 188 InvalidateOnForAttrChange, 189 InvalidateForFormControls, 190 InvalidateOnHRefAttrChange, 191 InvalidateOnItemAttrChange, 192 InvalidateOnAnyAttrChange, 193 }; 194 const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1; 195 196 typedef HashCountedSet<Node*> TouchEventTargetSet; 197 198 enum DocumentClass { 199 DefaultDocumentClass = 0, 200 HTMLDocumentClass = 1, 201 XHTMLDocumentClass = 1 << 1, 202 ImageDocumentClass = 1 << 2, 203 PluginDocumentClass = 1 << 3, 204 MediaDocumentClass = 1 << 4, 205 SVGDocumentClass = 1 << 5, 206 }; 207 208 typedef unsigned char DocumentClassFlags; 209 210 class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext { 211 public: 212 static PassRefPtr<Document> create(const DocumentInit& initializer = DocumentInit()) 213 { 214 return adoptRef(new Document(initializer)); 215 } 216 static PassRefPtr<Document> createXHTML(const DocumentInit& initializer = DocumentInit()) 217 { 218 return adoptRef(new Document(initializer, XHTMLDocumentClass)); 219 } 220 virtual ~Document(); 221 222 MediaQueryMatcher* mediaQueryMatcher(); 223 224 using ContainerNode::ref; 225 using ContainerNode::deref; 226 227 Element* getElementById(const AtomicString& id) const; 228 229 virtual bool canContainRangeEndPoint() const { return true; } 230 231 SelectorQueryCache* selectorQueryCache(); 232 233 // DOM methods & attributes for Document 234 235 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); 236 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); 237 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); 238 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu); 239 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick); 240 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter); 241 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover); 242 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave); 243 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop); 244 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart); 245 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag); 246 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend); 247 DEFINE_ATTRIBUTE_EVENT_LISTENER(input); 248 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid); 249 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown); 250 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress); 251 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup); 252 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown); 253 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseenter); 254 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseleave); 255 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove); 256 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout); 257 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover); 258 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup); 259 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel); 260 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll); 261 DEFINE_ATTRIBUTE_EVENT_LISTENER(select); 262 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit); 263 264 DEFINE_ATTRIBUTE_EVENT_LISTENER(blur); 265 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 266 DEFINE_ATTRIBUTE_EVENT_LISTENER(focus); 267 DEFINE_ATTRIBUTE_EVENT_LISTENER(load); 268 DEFINE_ATTRIBUTE_EVENT_LISTENER(readystatechange); 269 270 // WebKit extensions 271 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut); 272 DEFINE_ATTRIBUTE_EVENT_LISTENER(cut); 273 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy); 274 DEFINE_ATTRIBUTE_EVENT_LISTENER(copy); 275 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste); 276 DEFINE_ATTRIBUTE_EVENT_LISTENER(paste); 277 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset); 278 DEFINE_ATTRIBUTE_EVENT_LISTENER(search); 279 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart); 280 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectionchange); 281 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart); 282 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove); 283 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend); 284 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel); 285 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange); 286 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror); 287 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockchange); 288 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitpointerlockerror); 289 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitvisibilitychange); 290 DEFINE_ATTRIBUTE_EVENT_LISTENER(securitypolicyviolation); 291 292 void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; } 293 ViewportArguments viewportArguments() const { return m_viewportArguments; } 294 #ifndef NDEBUG 295 bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; } 296 #endif 297 298 void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; } 299 ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } 300 301 DocumentType* doctype() const { return m_docType.get(); } 302 303 DOMImplementation* implementation(); 304 305 Element* documentElement() const 306 { 307 return m_documentElement.get(); 308 } 309 310 bool hasManifest() const; 311 312 PassRefPtr<Element> createElement(const AtomicString& name, ExceptionState&); 313 PassRefPtr<DocumentFragment> createDocumentFragment(); 314 PassRefPtr<Text> createTextNode(const String& data); 315 PassRefPtr<Comment> createComment(const String& data); 316 PassRefPtr<CDATASection> createCDATASection(const String& data, ExceptionState&); 317 PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionState&); 318 PassRefPtr<Attr> createAttribute(const String& name, ExceptionState&); 319 PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionState&, bool shouldIgnoreNamespaceChecks = false); 320 PassRefPtr<Node> importNode(Node* importedNode, ExceptionState& ec) { return importNode(importedNode, true, ec); } 321 PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionState&); 322 PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionState&); 323 PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser); 324 325 bool cssStickyPositionEnabled() const; 326 bool cssCompositingEnabled() const; 327 PassRefPtr<DOMNamedFlowCollection> webkitGetNamedFlows(); 328 329 NamedFlowCollection* namedFlows(); 330 331 bool regionBasedColumnsEnabled() const; 332 333 /** 334 * Retrieve all nodes that intersect a rect in the window's document, until it is fully enclosed by 335 * the boundaries of a node. 336 * 337 * @param centerX x reference for the rectangle in CSS pixels 338 * @param centerY y reference for the rectangle in CSS pixels 339 * @param topPadding How much to expand the top of the rectangle 340 * @param rightPadding How much to expand the right of the rectangle 341 * @param bottomPadding How much to expand the bottom of the rectangle 342 * @param leftPadding How much to expand the left of the rectangle 343 */ 344 PassRefPtr<NodeList> nodesFromRect(int centerX, int centerY, 345 unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, 346 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent) const; 347 Element* elementFromPoint(int x, int y) const; 348 PassRefPtr<Range> caretRangeFromPoint(int x, int y); 349 350 String readyState() const; 351 352 String defaultCharset() const; 353 354 String inputEncoding() const { return Document::encoding(); } 355 String charset() const { return Document::encoding(); } 356 String characterSet() const { return Document::encoding(); } 357 358 String encoding() const; 359 360 void setCharset(const String&); 361 362 void setContent(const String&); 363 364 String suggestedMIMEType() const; 365 366 String contentLanguage() const { return m_contentLanguage; } 367 void setContentLanguage(const String&); 368 369 String xmlEncoding() const { return m_xmlEncoding; } 370 String xmlVersion() const { return m_xmlVersion; } 371 enum StandaloneStatus { StandaloneUnspecified, Standalone, NotStandalone }; 372 bool xmlStandalone() const { return m_xmlStandalone == Standalone; } 373 StandaloneStatus xmlStandaloneStatus() const { return static_cast<StandaloneStatus>(m_xmlStandalone); } 374 bool hasXMLDeclaration() const { return m_hasXMLDeclaration; } 375 376 void setXMLEncoding(const String& encoding) { m_xmlEncoding = encoding; } // read-only property, only to be set from XMLDocumentParser 377 void setXMLVersion(const String&, ExceptionState&); 378 void setXMLStandalone(bool, ExceptionState&); 379 void setHasXMLDeclaration(bool hasXMLDeclaration) { m_hasXMLDeclaration = hasXMLDeclaration ? 1 : 0; } 380 381 String documentURI() const { return m_documentURI; } 382 383 virtual KURL baseURI() const; 384 385 String webkitVisibilityState() const; 386 bool webkitHidden() const; 387 void dispatchVisibilityStateChangeEvent(); 388 389 DOMSecurityPolicy* securityPolicy(); 390 391 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionState&); 392 393 PassRefPtr<HTMLCollection> images(); 394 PassRefPtr<HTMLCollection> embeds(); 395 PassRefPtr<HTMLCollection> plugins(); // an alias for embeds() required for the JS DOM bindings. 396 PassRefPtr<HTMLCollection> applets(); 397 PassRefPtr<HTMLCollection> links(); 398 PassRefPtr<HTMLCollection> forms(); 399 PassRefPtr<HTMLCollection> anchors(); 400 PassRefPtr<HTMLCollection> scripts(); 401 PassRefPtr<HTMLCollection> allForBinding(); 402 PassRefPtr<HTMLCollection> all(); 403 404 PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name); 405 PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name); 406 407 bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; } 408 bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; } 409 bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; } 410 bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; } 411 bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; } 412 bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; } 413 414 bool hasSVGRootNode() const; 415 416 bool isFrameSet() const; 417 418 bool isSrcdocDocument() const { return m_isSrcdocDocument; } 419 420 StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); } 421 422 bool isViewSource() const { return m_isViewSource; } 423 void setIsViewSource(bool); 424 425 bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; } 426 427 StyleResolver* styleResolver() 428 { 429 if (!m_styleResolver) 430 createStyleResolver(); 431 return m_styleResolver.get(); 432 } 433 434 void notifyRemovePendingSheetIfNeeded(); 435 436 bool haveStylesheetsLoaded() const; 437 bool haveStylesheetsAndImportsLoaded() const { return haveImportsLoaded() && haveStylesheetsLoaded(); } 438 439 // This is a DOM function. 440 StyleSheetList* styleSheets(); 441 442 DocumentStyleSheetCollection* styleSheetCollection() { return m_styleSheetCollection.get(); } 443 444 bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; } 445 void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; } 446 447 // Called when one or more stylesheets in the document may have been added, removed, or changed. 448 void styleResolverChanged(StyleResolverUpdateType, StyleResolverUpdateMode = FullStyleUpdate); 449 450 // FIXME: Switch all callers of styleResolverChanged to these or better ones and then make them 451 // do something smarter. 452 void removedStyleSheet(StyleSheet*, StyleResolverUpdateType type = DeferRecalcStyle) { styleResolverChanged(type); } 453 void addedStyleSheet(StyleSheet*, StyleResolverUpdateType type = DeferRecalcStyle) { styleResolverChanged(type); } 454 void modifiedStyleSheet(StyleSheet*, StyleResolverUpdateType type = DeferRecalcStyle) { styleResolverChanged(type); } 455 456 void didAccessStyleResolver(); 457 458 void evaluateMediaQueryList(); 459 460 // Never returns 0. 461 FormController* formController(); 462 Vector<String> formElementsState() const; 463 void setStateForNewFormElements(const Vector<String>&); 464 465 FrameView* view() const; // can be NULL 466 Frame* frame() const { return m_frame; } // can be NULL 467 Page* page() const; // can be NULL 468 Settings* settings() const; // can be NULL 469 470 PassRefPtr<Range> createRange(); 471 472 PassRefPtr<NodeIterator> createNodeIterator(Node* root, ExceptionState&); 473 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, ExceptionState&); 474 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, ExceptionState&); 475 PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionState&); 476 477 PassRefPtr<TreeWalker> createTreeWalker(Node* root, ExceptionState&); 478 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, ExceptionState&); 479 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, ExceptionState&); 480 PassRefPtr<TreeWalker> createTreeWalker(Node* root, unsigned whatToShow, PassRefPtr<NodeFilter>, bool expandEntityReferences, ExceptionState&); 481 482 // Special support for editing 483 PassRefPtr<CSSStyleDeclaration> createCSSStyleDeclaration(); 484 PassRefPtr<Text> createEditingTextNode(const String&); 485 486 void recalcStyle(StyleChange = NoChange); 487 void updateStyleIfNeeded(); 488 void updateStyleForNodeIfNeeded(Node*); 489 void updateLayout(); 490 void updateLayoutIgnorePendingStylesheets(); 491 PassRefPtr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*); 492 PassRefPtr<RenderStyle> styleForPage(int pageIndex); 493 494 void updateDistributionForNodeIfNeeded(Node*); 495 496 // Returns true if page box (margin boxes and page borders) is visible. 497 bool isPageBoxVisible(int pageIndex); 498 499 // Returns the preferred page size and margins in pixels, assuming 96 500 // pixels per inch. pageSize, marginTop, marginRight, marginBottom, 501 // marginLeft must be initialized to the default values that are used if 502 // auto is specified. 503 void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft); 504 505 ResourceFetcher* fetcher() { return m_fetcher.get(); } 506 507 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE; 508 virtual void detach(const AttachContext& = AttachContext()) OVERRIDE; 509 void prepareForDestruction(); 510 511 // Override ScriptExecutionContext methods to do additional work 512 virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) OVERRIDE; 513 virtual void resumeActiveDOMObjects() OVERRIDE; 514 515 // Implemented in RenderView.h to avoid a cyclic header dependency this just 516 // returns renderer so callers can avoid verbose casts. 517 RenderView* renderView() const; 518 519 // Shadow the implementations on Node to provide faster access for documents. 520 RenderObject* renderer() const { return m_renderer; } 521 void setRenderer(RenderObject* renderer) 522 { 523 m_renderer = renderer; 524 Node::setRenderer(renderer); 525 } 526 527 AXObjectCache* existingAXObjectCache() const; 528 AXObjectCache* axObjectCache() const; 529 void clearAXObjectCache(); 530 531 // to get visually ordered hebrew and arabic pages right 532 void setVisuallyOrdered(); 533 bool visuallyOrdered() const { return m_visuallyOrdered; } 534 535 DocumentLoader* loader() const; 536 537 void open(Document* ownerDocument = 0); 538 PassRefPtr<DocumentParser> implicitOpen(); 539 540 // close() is the DOM API document.close() 541 void close(); 542 // In some situations (see the code), we ignore document.close(). 543 // explicitClose() bypass these checks and actually tries to close the 544 // input stream. 545 void explicitClose(); 546 // implicitClose() actually does the work of closing the input stream. 547 void implicitClose(); 548 549 void cancelParsing(); 550 551 void write(const SegmentedString& text, Document* ownerDocument = 0); 552 void write(const String& text, Document* ownerDocument = 0); 553 void writeln(const String& text, Document* ownerDocument = 0); 554 555 bool wellFormed() const { return m_wellFormed; } 556 557 const KURL& url() const { return m_url; } 558 void setURL(const KURL&); 559 560 // To understand how these concepts relate to one another, please see the 561 // comments surrounding their declaration. 562 const KURL& baseURL() const { return m_baseURL; } 563 void setBaseURLOverride(const KURL&); 564 const KURL& baseURLOverride() const { return m_baseURLOverride; } 565 const KURL& baseElementURL() const { return m_baseElementURL; } 566 const String& baseTarget() const { return m_baseTarget; } 567 void processBaseElement(); 568 569 KURL completeURL(const String&) const; 570 KURL completeURL(const String&, const KURL& baseURLOverride) const; 571 572 virtual String userAgent(const KURL&) const; 573 574 virtual void disableEval(const String& errorMessage); 575 576 bool canNavigate(Frame* targetFrame); 577 Frame* findUnsafeParentScrollPropagationBoundary(); 578 579 CSSStyleSheet* elementSheet(); 580 581 virtual PassRefPtr<DocumentParser> createParser(); 582 DocumentParser* parser() const { return m_parser.get(); } 583 ScriptableDocumentParser* scriptableDocumentParser() const; 584 585 bool printing() const { return m_printing; } 586 void setPrinting(bool p) { m_printing = p; } 587 588 bool paginatedForScreen() const { return m_paginatedForScreen; } 589 void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; } 590 591 bool paginated() const { return printing() || paginatedForScreen(); } 592 593 enum CompatibilityMode { QuirksMode, LimitedQuirksMode, NoQuirksMode }; 594 595 void setCompatibilityMode(CompatibilityMode m); 596 void lockCompatibilityMode() { m_compatibilityModeLocked = true; } 597 CompatibilityMode compatibilityMode() const { return m_compatibilityMode; } 598 599 String compatMode() const; 600 601 bool inQuirksMode() const { return m_compatibilityMode == QuirksMode; } 602 bool inLimitedQuirksMode() const { return m_compatibilityMode == LimitedQuirksMode; } 603 bool inNoQuirksMode() const { return m_compatibilityMode == NoQuirksMode; } 604 605 enum ReadyState { 606 Loading, 607 Interactive, 608 Complete 609 }; 610 void setReadyState(ReadyState); 611 void setParsing(bool); 612 bool parsing() const { return m_bParsing; } 613 int minimumLayoutDelay(); 614 615 bool shouldScheduleLayout(); 616 bool shouldParserYieldAgressivelyBeforeScriptExecution(); 617 int elapsedTime() const; 618 619 TextLinkColors& textLinkColors() { return m_textLinkColors; } 620 VisitedLinkState* visitedLinkState() const { return m_visitedLinkState.get(); } 621 622 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&); 623 624 /* Newly proposed CSS3 mechanism for selecting alternate 625 stylesheets using the DOM. May be subject to change as 626 spec matures. - dwh 627 */ 628 String preferredStylesheetSet() const; 629 String selectedStylesheetSet() const; 630 void setSelectedStylesheetSet(const String&); 631 632 bool setFocusedElement(PassRefPtr<Element>, FocusDirection = FocusDirectionNone); 633 Element* focusedElement() const { return m_focusedElement.get(); } 634 UserActionElementSet& userActionElements() { return m_userActionElements; } 635 const UserActionElementSet& userActionElements() const { return m_userActionElements; } 636 void setNeedsFocusedElementCheck(); 637 void didRunCheckFocusedElementTask() { m_didPostCheckFocusedElementTask = false; } 638 639 // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough 640 // for WebCore to ignore the autofocus attribute on any form controls 641 bool ignoreAutofocus() const { return m_ignoreAutofocus; }; 642 void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; }; 643 644 void setHoverNode(PassRefPtr<Node>); 645 Node* hoverNode() const { return m_hoverNode.get(); } 646 647 void setActiveElement(PassRefPtr<Element>); 648 Element* activeElement() const { return m_activeElement.get(); } 649 650 void removeFocusedElementOfSubtree(Node*, bool amongChildrenOnly = false); 651 void hoveredNodeDetached(Node*); 652 void activeChainNodeDetached(Node*); 653 654 void updateHoverActiveState(const HitTestRequest&, Element*, const PlatformMouseEvent* = 0); 655 656 // Updates for :target (CSS3 selector). 657 void setCSSTarget(Element*); 658 Element* cssTarget() const { return m_cssTarget; } 659 660 void scheduleStyleRecalc(); 661 void unscheduleStyleRecalc(); 662 bool hasPendingStyleRecalc() const; 663 bool hasPendingForcedStyleRecalc() const; 664 void styleRecalcTimerFired(Timer<Document>*); 665 666 void registerNodeList(LiveNodeListBase*); 667 void unregisterNodeList(LiveNodeListBase*); 668 bool shouldInvalidateNodeListCaches(const QualifiedName* attrName = 0) const; 669 void invalidateNodeListCaches(const QualifiedName* attrName); 670 671 void attachNodeIterator(NodeIterator*); 672 void detachNodeIterator(NodeIterator*); 673 void moveNodeIteratorsToNewDocument(Node*, Document*); 674 675 void attachRange(Range*); 676 void detachRange(Range*); 677 678 void updateRangesAfterChildrenChanged(ContainerNode*); 679 // nodeChildrenWillBeRemoved is used when removing all node children at once. 680 void nodeChildrenWillBeRemoved(ContainerNode*); 681 // nodeWillBeRemoved is only safe when removing one node at a time. 682 void nodeWillBeRemoved(Node*); 683 bool canReplaceChild(Node* newChild, Node* oldChild); 684 685 void textInserted(Node*, unsigned offset, unsigned length); 686 void textRemoved(Node*, unsigned offset, unsigned length); 687 void textNodesMerged(Text* oldNode, unsigned offset); 688 void textNodeSplit(Text* oldNode); 689 690 void setDOMWindow(DOMWindow* domWindow) { m_domWindow = domWindow; } 691 DOMWindow* domWindow() const { return m_domWindow; } 692 // In DOM Level 2, the Document's DOMWindow is called the defaultView. 693 DOMWindow* defaultView() const { return domWindow(); } 694 695 // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists. 696 void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, DOMWrapperWorld* isolatedWorld = 0); 697 EventListener* getWindowAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld); 698 void dispatchWindowEvent(PassRefPtr<Event>, PassRefPtr<EventTarget> = 0); 699 700 PassRefPtr<Event> createEvent(const String& eventType, ExceptionState&); 701 702 // keep track of what types of event listeners are registered, so we don't 703 // dispatch events unnecessarily 704 enum ListenerType { 705 DOMSUBTREEMODIFIED_LISTENER = 1, 706 DOMNODEINSERTED_LISTENER = 1 << 1, 707 DOMNODEREMOVED_LISTENER = 1 << 2, 708 DOMNODEREMOVEDFROMDOCUMENT_LISTENER = 1 << 3, 709 DOMNODEINSERTEDINTODOCUMENT_LISTENER = 1 << 4, 710 DOMCHARACTERDATAMODIFIED_LISTENER = 1 << 5, 711 OVERFLOWCHANGED_LISTENER = 1 << 6, 712 ANIMATIONEND_LISTENER = 1 << 7, 713 ANIMATIONSTART_LISTENER = 1 << 8, 714 ANIMATIONITERATION_LISTENER = 1 << 9, 715 TRANSITIONEND_LISTENER = 1 << 10, 716 BEFORELOAD_LISTENER = 1 << 11, 717 SCROLL_LISTENER = 1 << 12 718 // 3 bits remaining 719 }; 720 721 bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); } 722 void addListenerTypeIfNeeded(const AtomicString& eventType); 723 724 bool hasMutationObserversOfType(MutationObserver::MutationType type) const 725 { 726 return m_mutationObserverTypes & type; 727 } 728 bool hasMutationObservers() const { return m_mutationObserverTypes; } 729 void addMutationObserverTypes(MutationObserverOptions types) { m_mutationObserverTypes |= types; } 730 731 CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt); 732 733 /** 734 * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called 735 * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta 736 * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being 737 * specified in a HTML file. 738 * 739 * @param equiv The http header name (value of the meta tag's "equiv" attribute) 740 * @param content The header value (value of the meta tag's "content" attribute) 741 */ 742 void processHttpEquiv(const String& equiv, const String& content); 743 void processViewport(const String& features, ViewportArguments::Type origin); 744 void updateViewportArguments(); 745 void processReferrerPolicy(const String& policy); 746 747 // Returns the owning element in the parent document. 748 // Returns 0 if this is the top level document. 749 HTMLFrameOwnerElement* ownerElement() const; 750 751 HTMLIFrameElement* seamlessParentIFrame() const; 752 bool shouldDisplaySeamlesslyWithParent() const; 753 754 // Used by DOM bindings; no direction known. 755 String title() const { return m_title.string(); } 756 void setTitle(const String&); 757 758 Element* titleElement() const { return m_titleElement.get(); } 759 void setTitleElement(const StringWithDirection&, Element* titleElement); 760 void removeTitle(Element* titleElement); 761 762 String cookie(ExceptionState&) const; 763 void setCookie(const String&, ExceptionState&); 764 765 String referrer() const; 766 767 String domain() const; 768 void setDomain(const String& newDomain, ExceptionState&); 769 770 String lastModified() const; 771 772 // The cookieURL is used to query the cookie database for this document's 773 // cookies. For example, if the cookie URL is http://example.com, we'll 774 // use the non-Secure cookies for example.com when computing 775 // document.cookie. 776 // 777 // Q: How is the cookieURL different from the document's URL? 778 // A: The two URLs are the same almost all the time. However, if one 779 // document inherits the security context of another document, it 780 // inherits its cookieURL but not its URL. 781 // 782 const KURL& cookieURL() const { return m_cookieURL; } 783 void setCookieURL(const KURL& url) { m_cookieURL = url; } 784 785 const KURL& firstPartyForCookies() const; 786 787 // The following implements the rule from HTML 4 for what valid names are. 788 // To get this right for all the XML cases, we probably have to improve this or move it 789 // and make it sensitive to the type of document. 790 static bool isValidName(const String&); 791 792 // The following breaks a qualified name into a prefix and a local name. 793 // It also does a validity check, and returns false if the qualified name 794 // is invalid. It also sets ExceptionCode when name is invalid. 795 static bool parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionState&); 796 797 // Checks to make sure prefix and namespace do not conflict (per DOM Core 3) 798 static bool hasValidNamespaceForElements(const QualifiedName&); 799 static bool hasValidNamespaceForAttributes(const QualifiedName&); 800 801 HTMLElement* body() const; 802 void setBody(PassRefPtr<HTMLElement>, ExceptionState&); 803 804 HTMLHeadElement* head(); 805 806 DocumentMarkerController* markers() const { return m_markers.get(); } 807 808 bool directionSetOnDocumentElement() const { return m_directionSetOnDocumentElement; } 809 bool writingModeSetOnDocumentElement() const { return m_writingModeSetOnDocumentElement; } 810 void setDirectionSetOnDocumentElement(bool b) { m_directionSetOnDocumentElement = b; } 811 void setWritingModeSetOnDocumentElement(bool b) { m_writingModeSetOnDocumentElement = b; } 812 813 bool execCommand(const String& command, bool userInterface = false, const String& value = String()); 814 bool queryCommandEnabled(const String& command); 815 bool queryCommandIndeterm(const String& command); 816 bool queryCommandState(const String& command); 817 bool queryCommandSupported(const String& command); 818 String queryCommandValue(const String& command); 819 820 KURL openSearchDescriptionURL(); 821 822 // designMode support 823 enum InheritedBool { off = false, on = true, inherit }; 824 void setDesignMode(InheritedBool value); 825 InheritedBool getDesignMode() const; 826 bool inDesignMode() const; 827 828 Document* parentDocument() const; 829 Document* topDocument() const; 830 831 ScriptRunner* scriptRunner() { return m_scriptRunner.get(); } 832 833 HTMLScriptElement* currentScript() const { return !m_currentScriptStack.isEmpty() ? m_currentScriptStack.last().get() : 0; } 834 void pushCurrentScript(PassRefPtr<HTMLScriptElement>); 835 void popCurrentScript(); 836 837 void applyXSLTransform(ProcessingInstruction* pi); 838 PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; } 839 void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; } 840 841 void setTransformSource(PassOwnPtr<TransformSource>); 842 TransformSource* transformSource() const { return m_transformSource.get(); } 843 844 void incDOMTreeVersion() { m_domTreeVersion = ++s_globalTreeVersion; } 845 uint64_t domTreeVersion() const { return m_domTreeVersion; } 846 847 void setDocType(PassRefPtr<DocumentType>); 848 849 enum PendingSheetLayout { NoLayoutWithPendingSheets, DidLayoutWithPendingSheets, IgnoreLayoutWithPendingSheets }; 850 851 bool didLayoutWithPendingStylesheets() const { return m_pendingSheetLayout == DidLayoutWithPendingSheets; } 852 853 bool hasNodesWithPlaceholderStyle() const { return m_hasNodesWithPlaceholderStyle; } 854 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; } 855 856 const Vector<IconURL>& shortcutIconURLs(); 857 const Vector<IconURL>& iconURLs(int iconTypesMask); 858 859 void setUseSecureKeyboardEntryWhenActive(bool); 860 bool useSecureKeyboardEntryWhenActive() const; 861 862 void updateFocusAppearanceSoon(bool restorePreviousSelection); 863 void cancelFocusAppearanceUpdate(); 864 865 // Extension for manipulating canvas drawing contexts for use in CSS 866 CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height); 867 HTMLCanvasElement* getCSSCanvasElement(const String& name); 868 869 bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; } 870 void parseDNSPrefetchControlHeader(const String&); 871 872 virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously. 873 874 void suspendScriptedAnimationControllerCallbacks(); 875 void resumeScriptedAnimationControllerCallbacks(); 876 877 void finishedParsing(); 878 879 void documentWillBecomeInactive(); 880 881 void setDecoder(PassRefPtr<TextResourceDecoder>); 882 TextResourceDecoder* decoder() const { return m_decoder.get(); } 883 884 String displayStringModifiedByEncoding(const String&) const; 885 PassRefPtr<StringImpl> displayStringModifiedByEncoding(PassRefPtr<StringImpl>) const; 886 void displayBufferModifiedByEncoding(LChar* buffer, unsigned len) const 887 { 888 displayBufferModifiedByEncodingInternal(buffer, len); 889 } 890 void displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const 891 { 892 displayBufferModifiedByEncodingInternal(buffer, len); 893 } 894 895 void setAnnotatedRegionsDirty(bool f) { m_annotatedRegionsDirty = f; } 896 bool annotatedRegionsDirty() const { return m_annotatedRegionsDirty; } 897 bool hasAnnotatedRegions () const { return m_hasAnnotatedRegions; } 898 void setHasAnnotatedRegions(bool f) { m_hasAnnotatedRegions = f; } 899 const Vector<AnnotatedRegionValue>& annotatedRegions() const; 900 void setAnnotatedRegions(const Vector<AnnotatedRegionValue>&); 901 902 virtual void removeAllEventListeners(); 903 904 const SVGDocumentExtensions* svgExtensions(); 905 SVGDocumentExtensions* accessSVGExtensions(); 906 907 void initSecurityContext(); 908 void initSecurityContext(const DocumentInit&); 909 void initContentSecurityPolicy(const ContentSecurityPolicyResponseHeaders&); 910 911 void statePopped(PassRefPtr<SerializedScriptValue>); 912 913 enum LoadEventProgress { 914 LoadEventNotRun, 915 LoadEventTried, 916 LoadEventInProgress, 917 LoadEventCompleted, 918 UnloadEventInProgress, 919 UnloadEventHandled 920 }; 921 bool loadEventStillNeeded() const { return m_loadEventProgress == LoadEventNotRun; } 922 bool processingLoadEvent() const { return m_loadEventProgress == LoadEventInProgress; } 923 bool loadEventFinished() const { return m_loadEventProgress >= LoadEventCompleted; } 924 bool unloadEventStillNeeded() const { return m_loadEventProgress >= LoadEventTried && m_loadEventProgress <= UnloadEventInProgress; } 925 void unloadEventStarted() { m_loadEventProgress = UnloadEventInProgress; } 926 void unloadEventWasHandled() { m_loadEventProgress = UnloadEventHandled; } 927 928 virtual bool isContextThread() const; 929 virtual bool isJSExecutionForbidden() const { return false; } 930 931 bool containsValidityStyleRules() const { return m_containsValidityStyleRules; } 932 void setContainsValidityStyleRules() { m_containsValidityStyleRules = true; } 933 934 void enqueueWindowEvent(PassRefPtr<Event>); 935 void enqueueDocumentEvent(PassRefPtr<Event>); 936 void enqueuePageshowEvent(PageshowEventPersistence); 937 void enqueueHashchangeEvent(const String& oldURL, const String& newURL); 938 void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject); 939 virtual DocumentEventQueue* eventQueue() const { return m_eventQueue.get(); } 940 941 const QualifiedName& idAttributeName() const { return m_idAttributeName; } 942 943 bool hasFullscreenElementStack() const { return m_hasFullscreenElementStack; } 944 void setHasFullscreenElementStack() { m_hasFullscreenElementStack = true; } 945 946 void webkitExitPointerLock(); 947 Element* webkitPointerLockElement() const; 948 949 // Used to allow element that loads data without going through a FrameLoader to delay the 'load' event. 950 void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; } 951 void decrementLoadEventDelayCount(); 952 bool isDelayingLoadEvent() const { return m_loadEventDelayCount; } 953 954 PassRefPtr<Touch> createTouch(DOMWindow*, EventTarget*, int identifier, int pageX, int pageY, int screenX, int screenY, int radiusX, int radiusY, float rotationAngle, float force) const; 955 956 const DocumentTiming* timing() const { return &m_documentTiming; } 957 958 int requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>); 959 void cancelAnimationFrame(int id); 960 void serviceScriptedAnimations(double monotonicAnimationStartTime); 961 962 virtual EventTarget* errorEventTarget(); 963 virtual void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtr<ScriptCallStack>); 964 965 void initDNSPrefetch(); 966 967 unsigned wheelEventHandlerCount() const { return m_wheelEventHandlerCount; } 968 void didAddWheelEventHandler(); 969 void didRemoveWheelEventHandler(); 970 971 double lastHandledUserGestureTimestamp() const { return m_lastHandledUserGestureTimestamp; } 972 void resetLastHandledUserGestureTimestamp(); 973 974 bool hasTouchEventHandlers() const { return (m_touchEventTargets.get()) ? m_touchEventTargets->size() : false; } 975 976 void didAddTouchEventHandler(Node*); 977 void didRemoveTouchEventHandler(Node*); 978 979 void didRemoveEventTargetNode(Node*); 980 981 const TouchEventTargetSet* touchEventTargets() const { return m_touchEventTargets.get(); } 982 983 bool isInDocumentWrite() { return m_writeRecursionDepth > 0; } 984 985 void suspendScheduledTasks(ActiveDOMObject::ReasonForSuspension); 986 void resumeScheduledTasks(); 987 988 IntSize viewportSize() const; 989 IntSize initialViewportSize() const; 990 991 Prerenderer* prerenderer() { return m_prerenderer.get(); } 992 993 TextAutosizer* textAutosizer() { return m_textAutosizer.get(); } 994 995 PassRefPtr<Element> createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionState&); 996 PassRefPtr<Element> createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionState&); 997 ScriptValue registerElement(WebCore::ScriptState*, const AtomicString& name, ExceptionState&); 998 // FIXME: When embedders switch to using WebDocument::registerEmbedderCustomElement, make the default name set StandardNames. 999 ScriptValue registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionState&, CustomElement::NameSet validNames = CustomElement::AllNames); 1000 CustomElementRegistrationContext* registrationContext() { return m_registrationContext.get(); } 1001 1002 void setImport(HTMLImport*); 1003 HTMLImport* import() const { return m_import; } 1004 bool haveImportsLoaded() const; 1005 void didLoadAllImports(); 1006 1007 void adjustFloatQuadsForScrollAndAbsoluteZoom(Vector<FloatQuad>&, RenderObject*); 1008 void adjustFloatRectForScrollAndAbsoluteZoom(FloatRect&, RenderObject*); 1009 1010 bool hasActiveParser(); 1011 unsigned activeParserCount() { return m_activeParserCount; } 1012 void incrementActiveParserCount() { ++m_activeParserCount; } 1013 void decrementActiveParserCount(); 1014 1015 void setContextFeatures(PassRefPtr<ContextFeatures>); 1016 ContextFeatures* contextFeatures() { return m_contextFeatures.get(); } 1017 1018 DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); } 1019 1020 void didRemoveAllPendingStylesheet(); 1021 void setNeedsNotifyRemoveAllPendingStylesheet() { m_needsNotifyRemoveAllPendingStylesheet = true; } 1022 void clearStyleResolver(); 1023 void notifySeamlessChildDocumentsOfStylesheetUpdate() const; 1024 1025 bool inStyleRecalc() { return m_inStyleRecalc; } 1026 1027 // Return a Locale for the default locale if the argument is null or empty. 1028 Locale& getCachedLocale(const AtomicString& locale = nullAtom); 1029 1030 DocumentTimeline* timeline() const { return m_timeline.get(); } 1031 1032 void addToTopLayer(Element*, const Element* before = 0); 1033 void removeFromTopLayer(Element*); 1034 const Vector<RefPtr<Element> >& topLayerElements() const { return m_topLayerElements; } 1035 Element* activeModalDialog() const { return !m_topLayerElements.isEmpty() ? m_topLayerElements.last().get() : 0; } 1036 1037 const Document* templateDocument() const; 1038 Document* ensureTemplateDocument(); 1039 void setTemplateDocumentHost(Document* templateDocumentHost) { m_templateDocumentHost = templateDocumentHost; } 1040 Document* templateDocumentHost() { return m_templateDocumentHost; } 1041 1042 void didAssociateFormControl(Element*); 1043 1044 virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0); 1045 1046 virtual DOMWindow* executingWindow() OVERRIDE { return domWindow(); } 1047 virtual void userEventWasHandled() OVERRIDE { resetLastHandledUserGestureTimestamp(); } 1048 1049 PassRefPtr<FontLoader> fontloader(); 1050 DocumentLifecycleNotifier* lifecycleNotifier(); 1051 1052 enum HttpRefreshType { 1053 HttpRefreshFromHeader, 1054 HttpRefreshFromMetaTag 1055 }; 1056 void maybeHandleHttpRefresh(const String&, HttpRefreshType); 1057 1058 protected: 1059 Document(const DocumentInit&, DocumentClassFlags = DefaultDocumentClass); 1060 1061 virtual void didUpdateSecurityOrigin() OVERRIDE; 1062 1063 void clearXMLVersion() { m_xmlVersion = String(); } 1064 1065 virtual void dispose() OVERRIDE; 1066 1067 private: 1068 friend class Node; 1069 friend class IgnoreDestructiveWriteCountIncrementer; 1070 1071 void updateDistributionIfNeeded(); 1072 1073 void detachParser(); 1074 1075 typedef void (*ArgumentsCallback)(const String& keyString, const String& valueString, Document*, void* data); 1076 void processArguments(const String& features, void* data, ArgumentsCallback); 1077 1078 virtual bool isDocument() const OVERRIDE { return true; } 1079 1080 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 1081 1082 virtual String nodeName() const; 1083 virtual NodeType nodeType() const; 1084 virtual bool childTypeAllowed(NodeType) const; 1085 virtual PassRefPtr<Node> cloneNode(bool deep = true); 1086 1087 virtual void refScriptExecutionContext() { ref(); } 1088 virtual void derefScriptExecutionContext() { deref(); } 1089 virtual PassOwnPtr<LifecycleNotifier> createLifecycleNotifier() OVERRIDE; 1090 1091 virtual const KURL& virtualURL() const; // Same as url(), but needed for ScriptExecutionContext to implement it without a performance loss for direct calls. 1092 virtual KURL virtualCompleteURL(const String&) const; // Same as completeURL() for the same reason as above. 1093 1094 virtual void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptCallStack>, ScriptState* = 0, unsigned long requestIdentifier = 0); 1095 1096 virtual double timerAlignmentInterval() const; 1097 1098 void updateTitle(const StringWithDirection&); 1099 void updateFocusAppearanceTimerFired(Timer<Document>*); 1100 void updateBaseURL(); 1101 1102 void createStyleResolver(); 1103 1104 void executeScriptsWaitingForResourcesIfNeeded(); 1105 1106 void seamlessParentUpdatedStylesheets(); 1107 1108 PassRefPtr<NodeList> handleZeroPadding(const HitTestRequest&, HitTestResult&) const; 1109 1110 void loadEventDelayTimerFired(Timer<Document>*); 1111 1112 void pendingTasksTimerFired(Timer<Document>*); 1113 1114 static void didReceiveTask(void*); 1115 1116 template <typename CharacterType> 1117 void displayBufferModifiedByEncodingInternal(CharacterType*, unsigned) const; 1118 1119 PageVisibilityState visibilityState() const; 1120 1121 PassRefPtr<HTMLCollection> ensureCachedCollection(CollectionType); 1122 1123 // Note that dispatching a window load event may cause the DOMWindow to be detached from 1124 // the Frame, so callers should take a reference to the DOMWindow (which owns us) to 1125 // prevent the Document from getting blown away from underneath them. 1126 void dispatchWindowLoadEvent(); 1127 1128 void addListenerType(ListenerType listenerType) { m_listenerTypes |= listenerType; } 1129 void addMutationEventListenerTypeIfEnabled(ListenerType); 1130 1131 void didAssociateFormControlsTimerFired(Timer<Document>*); 1132 void styleResolverThrowawayTimerFired(Timer<Document>*); 1133 1134 void processHttpEquivDefaultStyle(const String& content); 1135 void processHttpEquivRefresh(const String& content); 1136 void processHttpEquivSetCookie(const String& content); 1137 void processHttpEquivXFrameOptions(const String& content); 1138 void processHttpEquivContentSecurityPolicy(const String& equiv, const String& content); 1139 1140 Timer<Document> m_styleResolverThrowawayTimer; 1141 double m_lastStyleResolverAccessTime; 1142 1143 OwnPtr<StyleResolver> m_styleResolver; 1144 bool m_didCalculateStyleResolver; 1145 bool m_hasNodesWithPlaceholderStyle; 1146 bool m_needsNotifyRemoveAllPendingStylesheet; 1147 // But sometimes you need to ignore pending stylesheet count to 1148 // force an immediate layout when requested by JS. 1149 bool m_ignorePendingStylesheets; 1150 1151 // If we do ignore the pending stylesheet count, then we need to add a boolean 1152 // to track that this happened so that we can do a full repaint when the stylesheets 1153 // do eventually load. 1154 PendingSheetLayout m_pendingSheetLayout; 1155 1156 Frame* m_frame; 1157 DOMWindow* m_domWindow; 1158 HTMLImport* m_import; 1159 1160 RefPtr<ResourceFetcher> m_fetcher; 1161 RefPtr<DocumentParser> m_parser; 1162 unsigned m_activeParserCount; 1163 RefPtr<ContextFeatures> m_contextFeatures; 1164 1165 bool m_wellFormed; 1166 1167 // Document URLs. 1168 KURL m_url; // Document.URL: The URL from which this document was retrieved. 1169 KURL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs. 1170 KURL m_baseURLOverride; // An alternative base URL that takes precedence over m_baseURL (but not m_baseElementURL). 1171 KURL m_baseElementURL; // The URL set by the <base> element. 1172 KURL m_cookieURL; // The URL to use for cookie access. 1173 1174 // Document.documentURI: 1175 // Although URL-like, Document.documentURI can actually be set to any 1176 // string by content. Document.documentURI affects m_baseURL unless the 1177 // document contains a <base> element, in which case the <base> element 1178 // takes precedence. 1179 String m_documentURI; 1180 1181 String m_baseTarget; 1182 1183 RefPtr<DocumentType> m_docType; 1184 OwnPtr<DOMImplementation> m_implementation; 1185 1186 RefPtr<CSSStyleSheet> m_elemSheet; 1187 1188 bool m_printing; 1189 bool m_paginatedForScreen; 1190 1191 bool m_ignoreAutofocus; 1192 1193 CompatibilityMode m_compatibilityMode; 1194 bool m_compatibilityModeLocked; // This is cheaper than making setCompatibilityMode virtual. 1195 1196 bool m_didPostCheckFocusedElementTask; 1197 RefPtr<Element> m_focusedElement; 1198 RefPtr<Node> m_hoverNode; 1199 RefPtr<Element> m_activeElement; 1200 RefPtr<Element> m_documentElement; 1201 UserActionElementSet m_userActionElements; 1202 1203 uint64_t m_domTreeVersion; 1204 static uint64_t s_globalTreeVersion; 1205 1206 HashSet<NodeIterator*> m_nodeIterators; 1207 HashSet<Range*> m_ranges; 1208 1209 unsigned short m_listenerTypes; 1210 1211 MutationObserverOptions m_mutationObserverTypes; 1212 1213 OwnPtr<DocumentStyleSheetCollection> m_styleSheetCollection; 1214 RefPtr<StyleSheetList> m_styleSheetList; 1215 1216 OwnPtr<FormController> m_formController; 1217 1218 TextLinkColors m_textLinkColors; 1219 OwnPtr<VisitedLinkState> m_visitedLinkState; 1220 1221 bool m_loadingSheet; 1222 bool m_visuallyOrdered; 1223 ReadyState m_readyState; 1224 bool m_bParsing; 1225 1226 Timer<Document> m_styleRecalcTimer; 1227 bool m_inStyleRecalc; 1228 bool m_closeAfterStyleRecalc; 1229 1230 bool m_gotoAnchorNeededAfterStylesheetsLoad; 1231 bool m_isDNSPrefetchEnabled; 1232 bool m_haveExplicitlyDisabledDNSPrefetch; 1233 bool m_containsValidityStyleRules; 1234 bool m_updateFocusAppearanceRestoresSelection; 1235 1236 // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter 1237 unsigned m_ignoreDestructiveWriteCount; 1238 1239 StringWithDirection m_title; 1240 StringWithDirection m_rawTitle; 1241 bool m_titleSetExplicitly; 1242 RefPtr<Element> m_titleElement; 1243 1244 OwnPtr<AXObjectCache> m_axObjectCache; 1245 OwnPtr<DocumentMarkerController> m_markers; 1246 1247 Timer<Document> m_updateFocusAppearanceTimer; 1248 1249 Element* m_cssTarget; 1250 1251 LoadEventProgress m_loadEventProgress; 1252 1253 RefPtr<SerializedScriptValue> m_pendingStateObject; 1254 double m_startTime; 1255 bool m_overMinimumLayoutThreshold; 1256 1257 OwnPtr<ScriptRunner> m_scriptRunner; 1258 1259 Vector<RefPtr<HTMLScriptElement> > m_currentScriptStack; 1260 1261 OwnPtr<TransformSource> m_transformSource; 1262 RefPtr<Document> m_transformSourceDocument; 1263 1264 String m_xmlEncoding; 1265 String m_xmlVersion; 1266 unsigned m_xmlStandalone : 2; 1267 unsigned m_hasXMLDeclaration : 1; 1268 1269 String m_contentLanguage; 1270 1271 RefPtr<TextResourceDecoder> m_decoder; 1272 1273 InheritedBool m_designMode; 1274 1275 HashSet<LiveNodeListBase*> m_listsInvalidatedAtDocument; 1276 unsigned m_nodeListCounts[numNodeListInvalidationTypes]; 1277 1278 OwnPtr<SVGDocumentExtensions> m_svgExtensions; 1279 1280 Vector<AnnotatedRegionValue> m_annotatedRegions; 1281 bool m_hasAnnotatedRegions; 1282 bool m_annotatedRegionsDirty; 1283 1284 HashMap<String, RefPtr<HTMLCanvasElement> > m_cssCanvasElements; 1285 1286 Vector<IconURL> m_iconURLs; 1287 1288 OwnPtr<SelectorQueryCache> m_selectorQueryCache; 1289 1290 bool m_useSecureKeyboardEntryWhenActive; 1291 1292 DocumentClassFlags m_documentClasses; 1293 1294 bool m_isViewSource; 1295 bool m_sawElementsInKnownNamespaces; 1296 bool m_isSrcdocDocument; 1297 1298 RenderObject* m_renderer; 1299 RefPtr<DocumentEventQueue> m_eventQueue; 1300 1301 WeakPtrFactory<Document> m_weakFactory; 1302 1303 QualifiedName m_idAttributeName; 1304 1305 bool m_hasFullscreenElementStack; // For early return in FullscreenElementStack::fromIfExists() 1306 1307 Vector<RefPtr<Element> > m_topLayerElements; 1308 1309 int m_loadEventDelayCount; 1310 Timer<Document> m_loadEventDelayTimer; 1311 1312 ViewportArguments m_viewportArguments; 1313 1314 ReferrerPolicy m_referrerPolicy; 1315 1316 bool m_directionSetOnDocumentElement; 1317 bool m_writingModeSetOnDocumentElement; 1318 1319 DocumentTiming m_documentTiming; 1320 RefPtr<MediaQueryMatcher> m_mediaQueryMatcher; 1321 bool m_writeRecursionIsTooDeep; 1322 unsigned m_writeRecursionDepth; 1323 1324 unsigned m_wheelEventHandlerCount; 1325 OwnPtr<TouchEventTargetSet> m_touchEventTargets; 1326 1327 double m_lastHandledUserGestureTimestamp; 1328 1329 RefPtr<ScriptedAnimationController> m_scriptedAnimationController; 1330 1331 Timer<Document> m_pendingTasksTimer; 1332 Vector<OwnPtr<Task> > m_pendingTasks; 1333 1334 OwnPtr<Prerenderer> m_prerenderer; 1335 1336 OwnPtr<TextAutosizer> m_textAutosizer; 1337 1338 RefPtr<CustomElementRegistrationContext> m_registrationContext; 1339 1340 bool m_scheduledTasksAreSuspended; 1341 1342 RefPtr<NamedFlowCollection> m_namedFlows; 1343 1344 RefPtr<DOMSecurityPolicy> m_domSecurityPolicy; 1345 1346 void sharedObjectPoolClearTimerFired(Timer<Document>*); 1347 Timer<Document> m_sharedObjectPoolClearTimer; 1348 1349 OwnPtr<DocumentSharedObjectPool> m_sharedObjectPool; 1350 1351 #ifndef NDEBUG 1352 bool m_didDispatchViewportPropertiesChanged; 1353 #endif 1354 1355 typedef HashMap<AtomicString, OwnPtr<Locale> > LocaleIdentifierToLocaleMap; 1356 LocaleIdentifierToLocaleMap m_localeCache; 1357 1358 RefPtr<DocumentTimeline> m_timeline; 1359 1360 RefPtr<Document> m_templateDocument; 1361 Document* m_templateDocumentHost; // Manually managed weakref (backpointer from m_templateDocument). 1362 1363 RefPtr<FontLoader> m_fontloader; 1364 1365 Timer<Document> m_didAssociateFormControlsTimer; 1366 HashSet<RefPtr<Element> > m_associatedFormControls; 1367 }; 1368 1369 inline void Document::notifyRemovePendingSheetIfNeeded() 1370 { 1371 if (m_needsNotifyRemoveAllPendingStylesheet) 1372 didRemoveAllPendingStylesheet(); 1373 } 1374 1375 inline const Document* Document::templateDocument() const 1376 { 1377 // If DOCUMENT does not have a browsing context, Let TEMPLATE CONTENTS OWNER be DOCUMENT and abort these steps. 1378 if (!m_frame) 1379 return this; 1380 1381 return m_templateDocument.get(); 1382 } 1383 1384 inline Document* toDocument(ScriptExecutionContext* scriptExecutionContext) 1385 { 1386 ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext || scriptExecutionContext->isDocument()); 1387 return static_cast<Document*>(scriptExecutionContext); 1388 } 1389 1390 inline const Document* toDocument(const ScriptExecutionContext* scriptExecutionContext) 1391 { 1392 ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext || scriptExecutionContext->isDocument()); 1393 return static_cast<const Document*>(scriptExecutionContext); 1394 } 1395 1396 inline Document* toDocument(Node* node) 1397 { 1398 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isDocumentNode()); 1399 return static_cast<Document*>(node); 1400 } 1401 1402 inline const Document* toDocument(const Node* node) 1403 { 1404 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isDocumentNode()); 1405 return static_cast<const Document*>(node); 1406 } 1407 1408 // This will catch anyone doing an unnecessary cast. 1409 void toDocument(const Document*); 1410 1411 // Put these methods here, because they require the Document definition, but we really want to inline them. 1412 1413 inline bool Node::isDocumentNode() const 1414 { 1415 return this == documentInternal(); 1416 } 1417 1418 Node* eventTargetNodeForDocument(Document*); 1419 1420 } // namespace WebCore 1421 1422 #endif // Document_h 1423