| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. |
| 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #include "sky/engine/core/events/HashChangeEvent.h" | 75 #include "sky/engine/core/events/HashChangeEvent.h" |
| 76 #include "sky/engine/core/events/PageTransitionEvent.h" | 76 #include "sky/engine/core/events/PageTransitionEvent.h" |
| 77 #include "sky/engine/core/events/ScopedEventQueue.h" | 77 #include "sky/engine/core/events/ScopedEventQueue.h" |
| 78 #include "sky/engine/core/fetch/ResourceFetcher.h" | 78 #include "sky/engine/core/fetch/ResourceFetcher.h" |
| 79 #include "sky/engine/core/frame/FrameConsole.h" | 79 #include "sky/engine/core/frame/FrameConsole.h" |
| 80 #include "sky/engine/core/frame/FrameHost.h" | 80 #include "sky/engine/core/frame/FrameHost.h" |
| 81 #include "sky/engine/core/frame/FrameView.h" | 81 #include "sky/engine/core/frame/FrameView.h" |
| 82 #include "sky/engine/core/frame/LocalDOMWindow.h" | 82 #include "sky/engine/core/frame/LocalDOMWindow.h" |
| 83 #include "sky/engine/core/frame/LocalFrame.h" | 83 #include "sky/engine/core/frame/LocalFrame.h" |
| 84 #include "sky/engine/core/frame/Settings.h" | 84 #include "sky/engine/core/frame/Settings.h" |
| 85 #include "sky/engine/core/html/HTMLAnchorElement.h" | |
| 86 #include "sky/engine/core/html/HTMLScriptElement.h" | |
| 87 #include "sky/engine/core/html/HTMLStyleElement.h" | |
| 88 #include "sky/engine/core/html/HTMLTemplateElement.h" | |
| 89 #include "sky/engine/core/html/HTMLTitleElement.h" | |
| 90 #include "sky/engine/core/html/imports/HTMLImportChild.h" | |
| 91 #include "sky/engine/core/html/imports/HTMLImportLoader.h" | |
| 92 #include "sky/engine/core/html/imports/HTMLImportTreeRoot.h" | |
| 93 #include "sky/engine/core/html/imports/HTMLImportsController.h" | |
| 94 #include "sky/engine/core/html/parser/HTMLDocumentParser.h" | |
| 95 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" | |
| 96 #include "sky/engine/core/html/parser/NestingLevelIncrementer.h" | |
| 97 #include "sky/engine/core/html/parser/TextResourceDecoder.h" | |
| 98 #include "sky/engine/core/inspector/ConsoleMessage.h" | 85 #include "sky/engine/core/inspector/ConsoleMessage.h" |
| 99 #include "sky/engine/core/inspector/InspectorCounters.h" | 86 #include "sky/engine/core/inspector/InspectorCounters.h" |
| 100 #include "sky/engine/core/loader/FrameLoaderClient.h" | 87 #include "sky/engine/core/loader/FrameLoaderClient.h" |
| 101 #include "sky/engine/core/loader/ImageLoader.h" | 88 #include "sky/engine/core/loader/ImageLoader.h" |
| 102 #include "sky/engine/core/page/ChromeClient.h" | 89 #include "sky/engine/core/page/ChromeClient.h" |
| 103 #include "sky/engine/core/page/EventHandler.h" | 90 #include "sky/engine/core/page/EventHandler.h" |
| 104 #include "sky/engine/core/page/FocusController.h" | 91 #include "sky/engine/core/page/FocusController.h" |
| 105 #include "sky/engine/core/page/Page.h" | 92 #include "sky/engine/core/page/Page.h" |
| 106 #include "sky/engine/core/painting/PaintingTasks.h" | 93 #include "sky/engine/core/painting/PaintingTasks.h" |
| 107 #include "sky/engine/core/painting/Picture.h" | 94 #include "sky/engine/core/painting/Picture.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 205 } |
| 219 #endif | 206 #endif |
| 220 | 207 |
| 221 Document::Document(const DocumentInit& initializer) | 208 Document::Document(const DocumentInit& initializer) |
| 222 : ContainerNode(0, CreateDocument) | 209 : ContainerNode(0, CreateDocument) |
| 223 , TreeScope(*this) | 210 , TreeScope(*this) |
| 224 , m_module(nullptr) | 211 , m_module(nullptr) |
| 225 , m_evaluateMediaQueriesOnStyleRecalc(false) | 212 , m_evaluateMediaQueriesOnStyleRecalc(false) |
| 226 , m_frame(initializer.frame()) | 213 , m_frame(initializer.frame()) |
| 227 , m_domWindow(m_frame ? m_frame->domWindow() : 0) | 214 , m_domWindow(m_frame ? m_frame->domWindow() : 0) |
| 228 , m_importsController(initializer.importsController()) | |
| 229 , m_activeParserCount(0) | 215 , m_activeParserCount(0) |
| 230 , m_resumeParserWaitingForResourcesTimer(this, &Document::resumeParserWaitin
gForResourcesTimerFired) | 216 , m_resumeParserWaitingForResourcesTimer(this, &Document::resumeParserWaitin
gForResourcesTimerFired) |
| 231 , m_clearFocusedElementTimer(this, &Document::clearFocusedElementTimerFired) | 217 , m_clearFocusedElementTimer(this, &Document::clearFocusedElementTimerFired) |
| 232 , m_listenerTypes(0) | 218 , m_listenerTypes(0) |
| 233 , m_mutationObserverTypes(0) | 219 , m_mutationObserverTypes(0) |
| 234 , m_readyState(Complete) | 220 , m_readyState(Complete) |
| 235 , m_isParsing(false) | 221 , m_isParsing(false) |
| 236 , m_containsValidityStyleRules(false) | 222 , m_containsValidityStyleRules(false) |
| 237 , m_markers(adoptPtr(new DocumentMarkerController)) | 223 , m_markers(adoptPtr(new DocumentMarkerController)) |
| 238 , m_loadEventProgress(LoadEventNotRun) | 224 , m_loadEventProgress(LoadEventNotRun) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 ASSERT(!hasGuardRefCount()); | 273 ASSERT(!hasGuardRefCount()); |
| 288 | 274 |
| 289 if (m_templateDocument) | 275 if (m_templateDocument) |
| 290 m_templateDocument->m_templateDocumentHost = nullptr; // balanced in ens
ureTemplateDocument(). | 276 m_templateDocument->m_templateDocumentHost = nullptr; // balanced in ens
ureTemplateDocument(). |
| 291 | 277 |
| 292 // FIXME: Oilpan: Not removing event listeners here also means that we do | 278 // FIXME: Oilpan: Not removing event listeners here also means that we do |
| 293 // not notify the inspector instrumentation that the event listeners are | 279 // not notify the inspector instrumentation that the event listeners are |
| 294 // gone. The Document and all the nodes in the document are gone, so maybe | 280 // gone. The Document and all the nodes in the document are gone, so maybe |
| 295 // that is OK? | 281 // that is OK? |
| 296 removeAllEventListenersRecursively(); | 282 removeAllEventListenersRecursively(); |
| 297 | |
| 298 // Currently we believe that Document can never outlive the parser. | |
| 299 // Although the Document may be replaced synchronously, DocumentParsers | |
| 300 // generally keep at least one reference to an Element which would in turn | |
| 301 // has a reference to the Document. If you hit this ASSERT, then that | |
| 302 // assumption is wrong. DocumentParser::detach() should ensure that even | |
| 303 // if the DocumentParser outlives the Document it won't cause badness. | |
| 304 ASSERT(!m_parser || m_parser->refCount() == 1); | |
| 305 detachParser(); | |
| 306 #endif | 283 #endif |
| 307 | 284 |
| 308 #if !ENABLE(OILPAN) | 285 #if !ENABLE(OILPAN) |
| 309 | 286 |
| 310 if (m_importsController) | |
| 311 HTMLImportsController::removeFrom(*this); | |
| 312 | |
| 313 m_timeline->detachFromDocument(); | 287 m_timeline->detachFromDocument(); |
| 314 | 288 |
| 315 if (m_elemSheet) | 289 if (m_elemSheet) |
| 316 m_elemSheet->clearOwnerNode(); | 290 m_elemSheet->clearOwnerNode(); |
| 317 | 291 |
| 318 m_fetcher.clear(); | 292 m_fetcher.clear(); |
| 319 | 293 |
| 320 // We must call clearRareData() here since a Document class inherits TreeSco
pe | 294 // We must call clearRareData() here since a Document class inherits TreeSco
pe |
| 321 // as well as Node. See a comment on TreeScope.h for the reason. | 295 // as well as Node. See a comment on TreeScope.h for the reason. |
| 322 if (hasRareData()) | 296 if (hasRareData()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 335 #if !ENABLE(OILPAN) | 309 #if !ENABLE(OILPAN) |
| 336 void Document::dispose() | 310 void Document::dispose() |
| 337 { | 311 { |
| 338 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); | 312 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); |
| 339 | 313 |
| 340 // We must make sure not to be retaining any of our children through | 314 // We must make sure not to be retaining any of our children through |
| 341 // these extra pointers or we will create a reference cycle. | 315 // these extra pointers or we will create a reference cycle. |
| 342 m_focusedElement = nullptr; | 316 m_focusedElement = nullptr; |
| 343 m_hoverNode = nullptr; | 317 m_hoverNode = nullptr; |
| 344 m_activeHoverElement = nullptr; | 318 m_activeHoverElement = nullptr; |
| 345 m_titleElement = nullptr; | |
| 346 m_userActionElements.documentDidRemoveLastRef(); | 319 m_userActionElements.documentDidRemoveLastRef(); |
| 347 | 320 |
| 348 detachParser(); | 321 detachParser(); |
| 349 | 322 |
| 350 m_elementRegistry.clear(); | 323 m_elementRegistry.clear(); |
| 351 | 324 |
| 352 if (m_importsController) | |
| 353 HTMLImportsController::removeFrom(*this); | |
| 354 | |
| 355 // removeDetachedChildren() doesn't always unregister IDs, | 325 // removeDetachedChildren() doesn't always unregister IDs, |
| 356 // so tear down scope information upfront to avoid having stale references i
n the map. | 326 // so tear down scope information upfront to avoid having stale references i
n the map. |
| 357 destroyTreeScopeData(); | 327 destroyTreeScopeData(); |
| 358 | 328 |
| 359 removeDetachedChildren(); | 329 removeDetachedChildren(); |
| 360 | 330 |
| 361 m_markers->clear(); | 331 m_markers->clear(); |
| 362 | 332 |
| 363 // FIXME: consider using ActiveDOMObject. | 333 // FIXME: consider using ActiveDOMObject. |
| 364 if (m_scriptedAnimationController) | 334 if (m_scriptedAnimationController) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 PassRefPtr<Text> Document::createText(const String& text) | 381 PassRefPtr<Text> Document::createText(const String& text) |
| 412 { | 382 { |
| 413 return Text::create(*this, text); | 383 return Text::create(*this, text); |
| 414 } | 384 } |
| 415 | 385 |
| 416 void Document::registerElement(const AtomicString& name, PassRefPtr<DartValue> t
ype, ExceptionState& es) | 386 void Document::registerElement(const AtomicString& name, PassRefPtr<DartValue> t
ype, ExceptionState& es) |
| 417 { | 387 { |
| 418 m_elementRegistry->RegisterElement(name, type); | 388 m_elementRegistry->RegisterElement(name, type); |
| 419 } | 389 } |
| 420 | 390 |
| 421 void Document::setImportsController(HTMLImportsController* controller) | |
| 422 { | |
| 423 ASSERT(!m_importsController || !controller); | |
| 424 m_importsController = controller; | |
| 425 } | |
| 426 | |
| 427 HTMLImportsController& Document::ensureImportsController() | |
| 428 { | |
| 429 if (!m_importsController) { | |
| 430 ASSERT(frame()); // The document should be the master. | |
| 431 HTMLImportsController::provideTo(*this); | |
| 432 } | |
| 433 return *m_importsController; | |
| 434 } | |
| 435 | |
| 436 HTMLImportLoader* Document::importLoader() const | |
| 437 { | |
| 438 if (!m_importsController) | |
| 439 return 0; | |
| 440 return m_importsController->loaderFor(*this); | |
| 441 } | |
| 442 | |
| 443 HTMLImport* Document::import() const | |
| 444 { | |
| 445 if (!m_importsController) | |
| 446 return 0; | |
| 447 if (HTMLImportLoader* loader = importLoader()) | |
| 448 return loader->firstImport(); | |
| 449 return m_importsController->root(); | |
| 450 } | |
| 451 | |
| 452 bool Document::haveImportsLoaded() const | |
| 453 { | |
| 454 if (!m_importsController) | |
| 455 return true; | |
| 456 return !m_importsController->shouldBlockScriptExecution(*this); | |
| 457 } | |
| 458 | |
| 459 LocalDOMWindow* Document::executingWindow() | 391 LocalDOMWindow* Document::executingWindow() |
| 460 { | 392 { |
| 461 if (LocalDOMWindow* owningWindow = domWindow()) | 393 if (LocalDOMWindow* owningWindow = domWindow()) |
| 462 return owningWindow; | 394 return owningWindow; |
| 463 if (HTMLImportsController* import = this->importsController()) | |
| 464 return import->master()->domWindow(); | |
| 465 return 0; | 395 return 0; |
| 466 } | 396 } |
| 467 | 397 |
| 468 LocalFrame* Document::executingFrame() | 398 LocalFrame* Document::executingFrame() |
| 469 { | 399 { |
| 470 LocalDOMWindow* window = executingWindow(); | 400 LocalDOMWindow* window = executingWindow(); |
| 471 if (!window) | 401 if (!window) |
| 472 return 0; | 402 return 0; |
| 473 return window->frame(); | 403 return window->frame(); |
| 474 } | 404 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 504 return Text::create(*this, toText(importedNode)->data()); | 434 return Text::create(*this, toText(importedNode)->data()); |
| 505 case ELEMENT_NODE: { | 435 case ELEMENT_NODE: { |
| 506 Element* oldElement = toElement(importedNode); | 436 Element* oldElement = toElement(importedNode); |
| 507 RefPtr<Element> newElement = createElement(oldElement->tagQName(), false
); | 437 RefPtr<Element> newElement = createElement(oldElement->tagQName(), false
); |
| 508 | 438 |
| 509 newElement->cloneDataFromElement(*oldElement); | 439 newElement->cloneDataFromElement(*oldElement); |
| 510 | 440 |
| 511 if (deep) { | 441 if (deep) { |
| 512 if (!importContainerNodeChildren(oldElement, newElement, exceptionSt
ate)) | 442 if (!importContainerNodeChildren(oldElement, newElement, exceptionSt
ate)) |
| 513 return nullptr; | 443 return nullptr; |
| 514 if (isHTMLTemplateElement(*oldElement) | |
| 515 && !importContainerNodeChildren(toHTMLTemplateElement(oldElement
)->content(), toHTMLTemplateElement(newElement)->content(), exceptionState)) | |
| 516 return nullptr; | |
| 517 } | 444 } |
| 518 | 445 |
| 519 return newElement.release(); | 446 return newElement.release(); |
| 520 } | 447 } |
| 521 case DOCUMENT_FRAGMENT_NODE: { | 448 case DOCUMENT_FRAGMENT_NODE: { |
| 522 if (importedNode->isShadowRoot()) { | 449 if (importedNode->isShadowRoot()) { |
| 523 // ShadowRoot nodes should not be explicitly importable. | 450 // ShadowRoot nodes should not be explicitly importable. |
| 524 // Either they are imported along with their host node, or created i
mplicitly. | 451 // Either they are imported along with their host node, or created i
mplicitly. |
| 525 exceptionState.ThrowDOMException(NotSupportedError, "The node provid
ed is a shadow root, which may not be imported."); | 452 exceptionState.ThrowDOMException(NotSupportedError, "The node provid
ed is a shadow root, which may not be imported."); |
| 526 return nullptr; | 453 return nullptr; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 644 } |
| 718 | 645 |
| 719 if (!builderIndex && buffer[builderIndex] == ' ') | 646 if (!builderIndex && buffer[builderIndex] == ' ') |
| 720 return String(); | 647 return String(); |
| 721 | 648 |
| 722 buffer.shrink(builderIndex + 1); | 649 buffer.shrink(builderIndex + 1); |
| 723 | 650 |
| 724 return String::adopt(buffer); | 651 return String::adopt(buffer); |
| 725 } | 652 } |
| 726 | 653 |
| 727 void Document::updateTitle(const String& title) | |
| 728 { | |
| 729 if (m_rawTitle == title) | |
| 730 return; | |
| 731 | |
| 732 m_rawTitle = title; | |
| 733 | |
| 734 String oldTitle = m_title; | |
| 735 if (m_rawTitle.isEmpty()) | |
| 736 m_title = String(); | |
| 737 else if (m_rawTitle.is8Bit()) | |
| 738 m_title = canonicalizedTitle<LChar>(this, m_rawTitle); | |
| 739 else | |
| 740 m_title = canonicalizedTitle<UChar>(this, m_rawTitle); | |
| 741 | |
| 742 if (!m_frame || oldTitle == m_title) | |
| 743 return; | |
| 744 m_frame->loaderClient()->dispatchDidReceiveTitle(m_title); | |
| 745 } | |
| 746 | |
| 747 void Document::setTitle(const String& title) | |
| 748 { | |
| 749 } | |
| 750 | |
| 751 void Document::setTitleElement(Element* titleElement) | |
| 752 { | |
| 753 // Only allow the first title element to change the title -- others have no
effect. | |
| 754 if (m_titleElement && m_titleElement != titleElement) { | |
| 755 m_titleElement = Traversal<HTMLTitleElement>::firstWithin(*this); | |
| 756 } else { | |
| 757 m_titleElement = titleElement; | |
| 758 } | |
| 759 | |
| 760 if (isHTMLTitleElement(m_titleElement)) | |
| 761 updateTitle(toHTMLTitleElement(m_titleElement)->text()); | |
| 762 } | |
| 763 | |
| 764 void Document::removeTitle(Element* titleElement) | |
| 765 { | |
| 766 if (m_titleElement != titleElement) | |
| 767 return; | |
| 768 | |
| 769 m_titleElement = nullptr; | |
| 770 | |
| 771 // Update title based on first title element in the document, if one exists. | |
| 772 if (HTMLTitleElement* title = Traversal<HTMLTitleElement>::firstWithin(*this
)) | |
| 773 setTitleElement(title); | |
| 774 | |
| 775 if (!m_titleElement) | |
| 776 updateTitle(String()); | |
| 777 } | |
| 778 | |
| 779 const AtomicString& Document::dir() | 654 const AtomicString& Document::dir() |
| 780 { | 655 { |
| 781 return nullAtom; | 656 return nullAtom; |
| 782 } | 657 } |
| 783 | 658 |
| 784 void Document::setDir(const AtomicString& value) | 659 void Document::setDir(const AtomicString& value) |
| 785 { | 660 { |
| 786 } | 661 } |
| 787 | 662 |
| 788 PageVisibilityState Document::pageVisibilityState() const | 663 PageVisibilityState Document::pageVisibilityState() const |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 void Document::removeAllEventListeners() | 1059 void Document::removeAllEventListeners() |
| 1185 { | 1060 { |
| 1186 ContainerNode::removeAllEventListeners(); | 1061 ContainerNode::removeAllEventListeners(); |
| 1187 | 1062 |
| 1188 if (LocalDOMWindow* domWindow = this->domWindow()) | 1063 if (LocalDOMWindow* domWindow = this->domWindow()) |
| 1189 domWindow->removeAllEventListeners(); | 1064 domWindow->removeAllEventListeners(); |
| 1190 } | 1065 } |
| 1191 | 1066 |
| 1192 void Document::detachParser() | 1067 void Document::detachParser() |
| 1193 { | 1068 { |
| 1194 if (!m_parser) | |
| 1195 return; | |
| 1196 m_parser->detach(); | |
| 1197 m_parser.clear(); | |
| 1198 } | 1069 } |
| 1199 | 1070 |
| 1200 void Document::cancelParsing() | 1071 void Document::cancelParsing() |
| 1201 { | 1072 { |
| 1202 if (!m_parser) | |
| 1203 return; | |
| 1204 | |
| 1205 // We have to clear the parser to avoid possibly triggering | |
| 1206 // the onload handler when closing as a side effect of a cancel-style | |
| 1207 // change, such as opening a new document or closing the window while | |
| 1208 // still parsing. | |
| 1209 detachParser(); | |
| 1210 | |
| 1211 // FIXME(sky): Unclear if anything below this makes any sense. | |
| 1212 if (!m_frame) { | |
| 1213 m_loadEventProgress = LoadEventTried; | |
| 1214 return; | |
| 1215 } | |
| 1216 checkCompleted(); | |
| 1217 } | 1073 } |
| 1218 | 1074 |
| 1219 DocumentParser* Document::startParsing() | 1075 DocumentParser* Document::startParsing() |
| 1220 { | 1076 { |
| 1221 ASSERT(!m_parser); | 1077 return nullptr; |
| 1222 ASSERT(!m_isParsing); | |
| 1223 ASSERT(!firstChild()); | |
| 1224 ASSERT(!m_focusedElement); | |
| 1225 | |
| 1226 m_parser = HTMLDocumentParser::create(*this, false); | |
| 1227 setParsing(true); | |
| 1228 setReadyState(Loading); | |
| 1229 return m_parser.get(); | |
| 1230 } | 1078 } |
| 1231 | 1079 |
| 1232 void Document::implicitClose() | 1080 void Document::implicitClose() |
| 1233 { | 1081 { |
| 1234 ASSERT(!inStyleRecalc()); | 1082 ASSERT(!inStyleRecalc()); |
| 1235 | 1083 |
| 1236 bool doload = !parsing() && m_parser && !processingLoadEvent(); | 1084 bool doload = false; |
| 1237 | 1085 |
| 1238 // If the load was blocked because of a pending location change and the loca
tion change triggers a same document | 1086 // If the load was blocked because of a pending location change and the loca
tion change triggers a same document |
| 1239 // navigation, don't fire load events after the same document navigation com
pletes (unless there's an explicit open). | 1087 // navigation, don't fire load events after the same document navigation com
pletes (unless there's an explicit open). |
| 1240 m_loadEventProgress = LoadEventTried; | 1088 m_loadEventProgress = LoadEventTried; |
| 1241 | 1089 |
| 1242 if (!doload) | 1090 if (!doload) |
| 1243 return; | 1091 return; |
| 1244 | 1092 |
| 1245 // The call to dispatchWindowLoadEvent can detach the LocalDOMWindow and cau
se it (and its | 1093 // The call to dispatchWindowLoadEvent can detach the LocalDOMWindow and cau
se it (and its |
| 1246 // attached Document) to be destroyed. | 1094 // attached Document) to be destroyed. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1277 | 1125 |
| 1278 void Document::checkCompleted() | 1126 void Document::checkCompleted() |
| 1279 { | 1127 { |
| 1280 if (isLoadCompleted()) | 1128 if (isLoadCompleted()) |
| 1281 return; | 1129 return; |
| 1282 | 1130 |
| 1283 // Are we still parsing? | 1131 // Are we still parsing? |
| 1284 if (parsing()) | 1132 if (parsing()) |
| 1285 return; | 1133 return; |
| 1286 | 1134 |
| 1287 // Still waiting imports? | |
| 1288 if (!haveImportsLoaded()) | |
| 1289 return; | |
| 1290 | |
| 1291 // Still waiting for images/scripts? | 1135 // Still waiting for images/scripts? |
| 1292 if (fetcher()->requestCount()) | 1136 if (fetcher()->requestCount()) |
| 1293 return; | 1137 return; |
| 1294 | 1138 |
| 1295 // Still waiting for elements that don't go through a FrameLoader? | 1139 // Still waiting for elements that don't go through a FrameLoader? |
| 1296 if (isDelayingLoadEvent()) | 1140 if (isDelayingLoadEvent()) |
| 1297 return; | 1141 return; |
| 1298 | 1142 |
| 1299 // OK, completed. | 1143 // OK, completed. |
| 1300 setReadyState(Complete); | 1144 setReadyState(Complete); |
| 1301 if (loadEventStillNeeded()) | 1145 if (loadEventStillNeeded()) |
| 1302 implicitClose(); | 1146 implicitClose(); |
| 1303 } | 1147 } |
| 1304 | 1148 |
| 1305 void Document::dispatchUnloadEvents() | 1149 void Document::dispatchUnloadEvents() |
| 1306 { | 1150 { |
| 1307 RefPtr<Document> protect(this); | |
| 1308 if (m_parser) | |
| 1309 m_parser->stopParsing(); | |
| 1310 | |
| 1311 if (m_loadEventProgress >= LoadEventTried && m_loadEventProgress <= UnloadEv
entInProgress) { | |
| 1312 if (m_loadEventProgress < PageHideInProgress) { | |
| 1313 m_loadEventProgress = PageHideInProgress; | |
| 1314 if (LocalDOMWindow* window = domWindow()) | |
| 1315 window->dispatchEvent(PageTransitionEvent::create(EventTypeNames
::pagehide, false), this); | |
| 1316 if (!m_frame) | |
| 1317 return; | |
| 1318 | |
| 1319 m_loadEventProgress = UnloadEventInProgress; | |
| 1320 RefPtr<Event> unloadEvent(Event::create(EventTypeNames::unload)); | |
| 1321 m_frame->domWindow()->dispatchEvent(unloadEvent, this); | |
| 1322 } | |
| 1323 m_loadEventProgress = UnloadEventHandled; | |
| 1324 } | |
| 1325 | |
| 1326 if (!m_frame) | |
| 1327 return; | |
| 1328 | |
| 1329 removeAllEventListenersRecursively(); | |
| 1330 } | 1151 } |
| 1331 | 1152 |
| 1332 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const | 1153 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const |
| 1333 { | 1154 { |
| 1334 if (m_loadEventProgress == PageHideInProgress) | 1155 if (m_loadEventProgress == PageHideInProgress) |
| 1335 return PageHideDismissal; | 1156 return PageHideDismissal; |
| 1336 if (m_loadEventProgress == UnloadEventInProgress) | 1157 if (m_loadEventProgress == UnloadEventInProgress) |
| 1337 return UnloadDismissal; | 1158 return UnloadDismissal; |
| 1338 return NoDismissal; | 1159 return NoDismissal; |
| 1339 } | 1160 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 | 1214 |
| 1394 void Document::updateBaseURL() | 1215 void Document::updateBaseURL() |
| 1395 { | 1216 { |
| 1396 KURL oldBaseURL = m_baseURL; | 1217 KURL oldBaseURL = m_baseURL; |
| 1397 m_baseURL = m_url; | 1218 m_baseURL = m_url; |
| 1398 | 1219 |
| 1399 if (!m_baseURL.isValid()) | 1220 if (!m_baseURL.isValid()) |
| 1400 m_baseURL = KURL(); | 1221 m_baseURL = KURL(); |
| 1401 } | 1222 } |
| 1402 | 1223 |
| 1403 void Document::didLoadAllImports() | |
| 1404 { | |
| 1405 if (!importLoader()) | |
| 1406 styleResolverChanged(); | |
| 1407 didLoadAllParserBlockingResources(); | |
| 1408 } | |
| 1409 | |
| 1410 void Document::didLoadAllParserBlockingResources() | 1224 void Document::didLoadAllParserBlockingResources() |
| 1411 { | 1225 { |
| 1412 m_resumeParserWaitingForResourcesTimer.startOneShot(0, FROM_HERE); | 1226 m_resumeParserWaitingForResourcesTimer.startOneShot(0, FROM_HERE); |
| 1413 } | 1227 } |
| 1414 | 1228 |
| 1415 void Document::resumeParserWaitingForResourcesTimerFired(Timer<Document>*) | 1229 void Document::resumeParserWaitingForResourcesTimerFired(Timer<Document>*) |
| 1416 { | 1230 { |
| 1417 if (!haveImportsLoaded()) | |
| 1418 return; | |
| 1419 if (m_parser) | |
| 1420 m_parser->resumeAfterWaitingForImports(); | |
| 1421 } | 1231 } |
| 1422 | 1232 |
| 1423 TextPosition Document::parserPosition() const | 1233 TextPosition Document::parserPosition() const |
| 1424 { | 1234 { |
| 1425 if (m_parser) | |
| 1426 m_parser->textPosition(); | |
| 1427 return TextPosition::belowRangePosition(); | 1235 return TextPosition::belowRangePosition(); |
| 1428 } | 1236 } |
| 1429 | 1237 |
| 1430 CSSStyleSheet& Document::elementSheet() | 1238 CSSStyleSheet& Document::elementSheet() |
| 1431 { | 1239 { |
| 1432 if (!m_elemSheet) | 1240 if (!m_elemSheet) |
| 1433 m_elemSheet = CSSStyleSheet::create(this, m_baseURL); | 1241 m_elemSheet = CSSStyleSheet::create(this, m_baseURL); |
| 1434 return *m_elemSheet; | 1242 return *m_elemSheet; |
| 1435 } | 1243 } |
| 1436 | 1244 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 if (url.isNull()) | 1767 if (url.isNull()) |
| 1960 return KURL(); | 1768 return KURL(); |
| 1961 return KURL(m_baseURL, url); | 1769 return KURL(m_baseURL, url); |
| 1962 } | 1770 } |
| 1963 | 1771 |
| 1964 KURL Document::openSearchDescriptionURL() | 1772 KURL Document::openSearchDescriptionURL() |
| 1965 { | 1773 { |
| 1966 return KURL(); | 1774 return KURL(); |
| 1967 } | 1775 } |
| 1968 | 1776 |
| 1969 void Document::pushCurrentScript(PassRefPtr<HTMLScriptElement> newCurrentScript) | |
| 1970 { | |
| 1971 ASSERT(newCurrentScript); | |
| 1972 m_currentScriptStack.append(newCurrentScript); | |
| 1973 } | |
| 1974 | |
| 1975 void Document::popCurrentScript() | |
| 1976 { | |
| 1977 ASSERT(!m_currentScriptStack.isEmpty()); | |
| 1978 m_currentScriptStack.removeLast(); | |
| 1979 } | |
| 1980 | |
| 1981 Document& Document::topDocument() const | 1777 Document& Document::topDocument() const |
| 1982 { | 1778 { |
| 1983 Document* doc = const_cast<Document*>(this); | 1779 Document* doc = const_cast<Document*>(this); |
| 1984 ASSERT(doc); | 1780 ASSERT(doc); |
| 1985 return *doc; | 1781 return *doc; |
| 1986 } | 1782 } |
| 1987 | 1783 |
| 1988 WeakPtr<Document> Document::contextDocument() | 1784 WeakPtr<Document> Document::contextDocument() |
| 1989 { | 1785 { |
| 1990 if (m_contextDocument) | 1786 if (m_contextDocument) |
| 1991 return m_contextDocument; | 1787 return m_contextDocument; |
| 1992 if (m_frame) { | 1788 if (m_frame) { |
| 1993 #if ENABLE(OILPAN) | 1789 #if ENABLE(OILPAN) |
| 1994 return this; | 1790 return this; |
| 1995 #else | 1791 #else |
| 1996 return m_weakFactory.createWeakPtr(); | 1792 return m_weakFactory.createWeakPtr(); |
| 1997 #endif | 1793 #endif |
| 1998 } | 1794 } |
| 1999 return WeakPtr<Document>(nullptr); | 1795 return WeakPtr<Document>(nullptr); |
| 2000 } | 1796 } |
| 2001 | 1797 |
| 2002 void Document::finishedParsing() | 1798 void Document::finishedParsing() |
| 2003 { | 1799 { |
| 2004 ASSERT(!m_parser || !m_parser->isParsing()); | |
| 2005 ASSERT(!m_parser || m_readyState != Loading); | |
| 2006 setParsing(false); | |
| 2007 dispatchEvent(Event::createBubble(EventTypeNames::DOMContentLoaded)); | |
| 2008 | |
| 2009 // The loader's finishedParsing() method may invoke script that causes this
object to | |
| 2010 // be dereferenced (when this document is in an iframe and the onload causes
the iframe's src to change). | |
| 2011 // Keep it alive until we are done. | |
| 2012 RefPtr<Document> protect(this); | |
| 2013 | |
| 2014 if (RefPtr<LocalFrame> f = frame()) | |
| 2015 checkCompleted(); | |
| 2016 | |
| 2017 // Schedule dropping of the ElementDataCache. We keep it alive for a while a
fter parsing finishes | |
| 2018 // so that dynamically inserted content can also benefit from sharing optimi
zations. | |
| 2019 // Note that we don't refresh the timer on cache access since that could lea
d to huge caches being kept | |
| 2020 // alive indefinitely by something innocuous like JS setting .innerHTML repe
atedly on a timer. | |
| 2021 m_elementDataCacheClearTimer.startOneShot(10, FROM_HERE); | |
| 2022 | |
| 2023 if (HTMLImportLoader* import = importLoader()) | |
| 2024 import->didFinishParsing(); | |
| 2025 } | 1800 } |
| 2026 | 1801 |
| 2027 void Document::elementDataCacheClearTimerFired(Timer<Document>*) | 1802 void Document::elementDataCacheClearTimerFired(Timer<Document>*) |
| 2028 { | 1803 { |
| 2029 m_elementDataCache.clear(); | 1804 m_elementDataCache.clear(); |
| 2030 } | 1805 } |
| 2031 | 1806 |
| 2032 bool Document::allowExecutingScripts(Node* node) | 1807 bool Document::allowExecutingScripts(Node* node) |
| 2033 { | 1808 { |
| 2034 // FIXME: Eventually we'd like to evaluate scripts which are inserted into a | 1809 // FIXME: Eventually we'd like to evaluate scripts which are inserted into a |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2061 } | 1836 } |
| 2062 | 1837 |
| 2063 void Document::reportBlockedScriptExecutionToInspector(const String& directiveTe
xt) | 1838 void Document::reportBlockedScriptExecutionToInspector(const String& directiveTe
xt) |
| 2064 { | 1839 { |
| 2065 } | 1840 } |
| 2066 | 1841 |
| 2067 void Document::addMessage(PassRefPtr<ConsoleMessage> consoleMessage) | 1842 void Document::addMessage(PassRefPtr<ConsoleMessage> consoleMessage) |
| 2068 { | 1843 { |
| 2069 if (!m_frame) | 1844 if (!m_frame) |
| 2070 return; | 1845 return; |
| 2071 | |
| 2072 if (consoleMessage->url().isNull() && !consoleMessage->lineNumber()) { | |
| 2073 consoleMessage->setURL(url().string()); | |
| 2074 if (parsing() && m_parser) { | |
| 2075 if (!m_parser->isWaitingForScripts() && !m_parser->isExecutingScript
()) | |
| 2076 consoleMessage->setLineNumber(m_parser->textPosition().m_line.on
eBasedInt()); | |
| 2077 } | |
| 2078 } | |
| 2079 m_frame->console().addMessage(consoleMessage); | 1846 m_frame->console().addMessage(consoleMessage); |
| 2080 } | 1847 } |
| 2081 | 1848 |
| 2082 void Document::decrementLoadEventDelayCount() | 1849 void Document::decrementLoadEventDelayCount() |
| 2083 { | 1850 { |
| 2084 ASSERT(m_loadEventDelayCount); | 1851 ASSERT(m_loadEventDelayCount); |
| 2085 --m_loadEventDelayCount; | 1852 --m_loadEventDelayCount; |
| 2086 | 1853 |
| 2087 if (!m_loadEventDelayCount) | 1854 if (!m_loadEventDelayCount) |
| 2088 checkLoadEventSoon(); | 1855 checkLoadEventSoon(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2224 using namespace blink; | 1991 using namespace blink; |
| 2225 void showLiveDocumentInstances() | 1992 void showLiveDocumentInstances() |
| 2226 { | 1993 { |
| 2227 WeakDocumentSet& set = liveDocumentSet(); | 1994 WeakDocumentSet& set = liveDocumentSet(); |
| 2228 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 1995 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 2229 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it
) { | 1996 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it
) { |
| 2230 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut
f8().data()); | 1997 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut
f8().data()); |
| 2231 } | 1998 } |
| 2232 } | 1999 } |
| 2233 #endif | 2000 #endif |
| OLD | NEW |