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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #include "core/dom/ContextFeatures.h" | 64 #include "core/dom/ContextFeatures.h" |
65 #include "core/dom/DOMImplementation.h" | 65 #include "core/dom/DOMImplementation.h" |
66 #include "core/dom/DocumentFragment.h" | 66 #include "core/dom/DocumentFragment.h" |
67 #include "core/dom/DocumentLifecycleNotifier.h" | 67 #include "core/dom/DocumentLifecycleNotifier.h" |
68 #include "core/dom/DocumentLifecycleObserver.h" | 68 #include "core/dom/DocumentLifecycleObserver.h" |
69 #include "core/dom/DocumentMarkerController.h" | 69 #include "core/dom/DocumentMarkerController.h" |
70 #include "core/dom/DocumentType.h" | 70 #include "core/dom/DocumentType.h" |
71 #include "core/dom/Element.h" | 71 #include "core/dom/Element.h" |
72 #include "core/dom/ElementDataCache.h" | 72 #include "core/dom/ElementDataCache.h" |
73 #include "core/dom/ElementTraversal.h" | 73 #include "core/dom/ElementTraversal.h" |
| 74 #include "core/dom/EventHandlerRegistry.h" |
74 #include "core/dom/ExceptionCode.h" | 75 #include "core/dom/ExceptionCode.h" |
75 #include "core/dom/ExecutionContextTask.h" | 76 #include "core/dom/ExecutionContextTask.h" |
76 #include "core/dom/MainThreadTaskRunner.h" | 77 #include "core/dom/MainThreadTaskRunner.h" |
77 #include "core/dom/MutationObserver.h" | 78 #include "core/dom/MutationObserver.h" |
78 #include "core/dom/NodeChildRemovalTracker.h" | 79 #include "core/dom/NodeChildRemovalTracker.h" |
79 #include "core/dom/NodeFilter.h" | 80 #include "core/dom/NodeFilter.h" |
80 #include "core/dom/NodeIterator.h" | 81 #include "core/dom/NodeIterator.h" |
81 #include "core/dom/NodeRareData.h" | 82 #include "core/dom/NodeRareData.h" |
82 #include "core/dom/NodeRenderStyle.h" | 83 #include "core/dom/NodeRenderStyle.h" |
83 #include "core/dom/NodeRenderingTraversal.h" | 84 #include "core/dom/NodeRenderingTraversal.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 }; | 373 }; |
373 | 374 |
374 DocumentVisibilityObserver::DocumentVisibilityObserver(Document& document) | 375 DocumentVisibilityObserver::DocumentVisibilityObserver(Document& document) |
375 : m_document(0) | 376 : m_document(0) |
376 { | 377 { |
377 registerObserver(document); | 378 registerObserver(document); |
378 } | 379 } |
379 | 380 |
380 DocumentVisibilityObserver::~DocumentVisibilityObserver() | 381 DocumentVisibilityObserver::~DocumentVisibilityObserver() |
381 { | 382 { |
| 383 #if !ENABLE(OILPAN) |
382 unregisterObserver(); | 384 unregisterObserver(); |
| 385 #endif |
383 } | 386 } |
384 | 387 |
385 void DocumentVisibilityObserver::unregisterObserver() | 388 void DocumentVisibilityObserver::unregisterObserver() |
386 { | 389 { |
387 if (m_document) { | 390 if (m_document) { |
388 m_document->unregisterVisibilityObserver(this); | 391 m_document->unregisterVisibilityObserver(this); |
389 m_document = 0; | 392 m_document = 0; |
390 } | 393 } |
391 } | 394 } |
392 | 395 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 // CSSFontSelector, need to initialize m_styleEngine after initializing | 520 // CSSFontSelector, need to initialize m_styleEngine after initializing |
518 // m_fetcher. | 521 // m_fetcher. |
519 m_styleEngine = StyleEngine::create(*this); | 522 m_styleEngine = StyleEngine::create(*this); |
520 } | 523 } |
521 | 524 |
522 Document::~Document() | 525 Document::~Document() |
523 { | 526 { |
524 ASSERT(!renderView()); | 527 ASSERT(!renderView()); |
525 ASSERT(m_ranges.isEmpty()); | 528 ASSERT(m_ranges.isEmpty()); |
526 ASSERT(!parentTreeScope()); | 529 ASSERT(!parentTreeScope()); |
| 530 #if !ENABLE(OILPAN) |
527 ASSERT(!hasGuardRefCount()); | 531 ASSERT(!hasGuardRefCount()); |
| 532 // With Oilpan, either the document outlives the visibility observers |
| 533 // or the visibility observers and the document die in the same GC round. |
| 534 // When they die in the same GC round, the list of visibility observers |
| 535 // will not be empty on Document destruction. |
528 ASSERT(m_visibilityObservers.isEmpty()); | 536 ASSERT(m_visibilityObservers.isEmpty()); |
| 537 #endif |
529 | 538 |
530 if (m_templateDocument) | 539 if (m_templateDocument) |
531 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem
plateDocument(). | 540 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem
plateDocument(). |
532 | 541 |
533 m_scriptRunner.clear(); | 542 m_scriptRunner.clear(); |
534 | 543 |
535 removeAllEventListenersRecursively(); | 544 removeAllEventListenersRecursively(); |
536 | 545 |
537 // Currently we believe that Document can never outlive the parser. | 546 // Currently we believe that Document can never outlive the parser. |
538 // Although the Document may be replaced synchronously, DocumentParsers | 547 // Although the Document may be replaced synchronously, DocumentParsers |
539 // generally keep at least one reference to an Element which would in turn | 548 // generally keep at least one reference to an Element which would in turn |
540 // has a reference to the Document. If you hit this ASSERT, then that | 549 // has a reference to the Document. If you hit this ASSERT, then that |
541 // assumption is wrong. DocumentParser::detach() should ensure that even | 550 // assumption is wrong. DocumentParser::detach() should ensure that even |
542 // if the DocumentParser outlives the Document it won't cause badness. | 551 // if the DocumentParser outlives the Document it won't cause badness. |
543 ASSERT(!m_parser || m_parser->refCount() == 1); | 552 ASSERT(!m_parser || m_parser->refCount() == 1); |
544 detachParser(); | 553 detachParser(); |
545 | 554 |
546 if (this == topDocument()) | 555 if (this == topDocument()) |
547 clearAXObjectCache(); | 556 clearAXObjectCache(); |
548 | 557 |
| 558 #if !ENABLE(OILPAN) |
549 if (m_styleSheetList) | 559 if (m_styleSheetList) |
550 m_styleSheetList->detachFromDocument(); | 560 m_styleSheetList->detachFromDocument(); |
| 561 #endif |
551 | 562 |
552 if (m_importsController) { | 563 if (m_importsController) { |
553 m_importsController->wasDetachedFrom(*this); | 564 m_importsController->wasDetachedFrom(*this); |
554 m_importsController = 0; | 565 m_importsController = 0; |
555 } | 566 } |
556 | 567 |
557 m_timeline->detachFromDocument(); | 568 m_timeline->detachFromDocument(); |
558 m_transitionTimeline->detachFromDocument(); | 569 m_transitionTimeline->detachFromDocument(); |
559 | 570 |
560 // We need to destroy CSSFontSelector before destroying m_fetcher. | 571 // We need to destroy CSSFontSelector before destroying m_fetcher. |
561 if (m_styleEngine) | 572 if (m_styleEngine) |
562 m_styleEngine->detachFromDocument(); | 573 m_styleEngine->detachFromDocument(); |
563 | 574 |
| 575 #if !ENABLE(OILPAN) |
564 if (m_elemSheet) | 576 if (m_elemSheet) |
565 m_elemSheet->clearOwnerNode(); | 577 m_elemSheet->clearOwnerNode(); |
| 578 #endif |
566 | 579 |
567 // It's possible for multiple Documents to end up referencing the same Resou
rceFetcher (e.g., SVGImages | 580 // It's possible for multiple Documents to end up referencing the same Resou
rceFetcher (e.g., SVGImages |
568 // load the initial empty document and the SVGDocument with the same Documen
tLoader). | 581 // load the initial empty document and the SVGDocument with the same Documen
tLoader). |
569 if (m_fetcher->document() == this) | 582 if (m_fetcher->document() == this) |
570 m_fetcher->setDocument(0); | 583 m_fetcher->setDocument(0); |
571 m_fetcher.clear(); | 584 m_fetcher.clear(); |
572 | 585 |
573 // We must call clearRareData() here since a Document class inherits TreeSco
pe | 586 // We must call clearRareData() here since a Document class inherits TreeSco
pe |
574 // as well as Node. See a comment on TreeScope.h for the reason. | 587 // as well as Node. See a comment on TreeScope.h for the reason. |
575 if (hasRareData()) | 588 if (hasRareData()) |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 return pageVisibilityState() != PageVisibilityStateVisible; | 1433 return pageVisibilityState() != PageVisibilityStateVisible; |
1421 } | 1434 } |
1422 | 1435 |
1423 void Document::didChangeVisibilityState() | 1436 void Document::didChangeVisibilityState() |
1424 { | 1437 { |
1425 dispatchEvent(Event::create(EventTypeNames::visibilitychange)); | 1438 dispatchEvent(Event::create(EventTypeNames::visibilitychange)); |
1426 // Also send out the deprecated version until it can be removed. | 1439 // Also send out the deprecated version until it can be removed. |
1427 dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange)); | 1440 dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange)); |
1428 | 1441 |
1429 PageVisibilityState state = pageVisibilityState(); | 1442 PageVisibilityState state = pageVisibilityState(); |
1430 HashSet<DocumentVisibilityObserver*>::const_iterator observerEnd = m_visibil
ityObservers.end(); | 1443 DocumentVisibilityObserverSet::const_iterator observerEnd = m_visibilityObse
rvers.end(); |
1431 for (HashSet<DocumentVisibilityObserver*>::const_iterator it = m_visibilityO
bservers.begin(); it != observerEnd; ++it) | 1444 for (DocumentVisibilityObserverSet::const_iterator it = m_visibilityObserver
s.begin(); it != observerEnd; ++it) |
1432 (*it)->didChangeVisibilityState(state); | 1445 (*it)->didChangeVisibilityState(state); |
1433 } | 1446 } |
1434 | 1447 |
1435 void Document::registerVisibilityObserver(DocumentVisibilityObserver* observer) | 1448 void Document::registerVisibilityObserver(DocumentVisibilityObserver* observer) |
1436 { | 1449 { |
1437 ASSERT(!m_visibilityObservers.contains(observer)); | 1450 ASSERT(!m_visibilityObservers.contains(observer)); |
1438 m_visibilityObservers.add(observer); | 1451 m_visibilityObservers.add(observer); |
1439 } | 1452 } |
1440 | 1453 |
1441 void Document::unregisterVisibilityObserver(DocumentVisibilityObserver* observer
) | 1454 void Document::unregisterVisibilityObserver(DocumentVisibilityObserver* observer
) |
(...skipping 3381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4823 m_ranges.add(range); | 4836 m_ranges.add(range); |
4824 } | 4837 } |
4825 | 4838 |
4826 void Document::detachRange(Range* range) | 4839 void Document::detachRange(Range* range) |
4827 { | 4840 { |
4828 // We don't ASSERT m_ranges.contains(range) to allow us to call this | 4841 // We don't ASSERT m_ranges.contains(range) to allow us to call this |
4829 // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044 | 4842 // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044 |
4830 m_ranges.remove(range); | 4843 m_ranges.remove(range); |
4831 } | 4844 } |
4832 | 4845 |
4833 void Document::getCSSCanvasContext(const String& type, const String& name, int w
idth, int height, bool& is2d, RefPtr<CanvasRenderingContext2D>& context2d, bool&
is3d, RefPtr<WebGLRenderingContext>& context3d) | 4846 void Document::getCSSCanvasContext(const String& type, const String& name, int w
idth, int height, bool& is2d, RefPtrWillBeRawPtr<CanvasRenderingContext2D>& cont
ext2d, bool& is3d, RefPtrWillBeRawPtr<WebGLRenderingContext>& context3d) |
4834 { | 4847 { |
4835 HTMLCanvasElement& element = getCSSCanvasElement(name); | 4848 HTMLCanvasElement& element = getCSSCanvasElement(name); |
4836 element.setSize(IntSize(width, height)); | 4849 element.setSize(IntSize(width, height)); |
4837 CanvasRenderingContext* context = element.getContext(type); | 4850 CanvasRenderingContext* context = element.getContext(type); |
4838 if (!context) | 4851 if (!context) |
4839 return; | 4852 return; |
4840 | 4853 |
4841 if (context->is2d()) { | 4854 if (context->is2d()) { |
4842 is2d = true; | 4855 is2d = true; |
4843 context2d = toCanvasRenderingContext2D(context); | 4856 context2d = toCanvasRenderingContext2D(context); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5026 return element; | 5039 return element; |
5027 } | 5040 } |
5028 return 0; | 5041 return 0; |
5029 } | 5042 } |
5030 | 5043 |
5031 void Document::decrementLoadEventDelayCount() | 5044 void Document::decrementLoadEventDelayCount() |
5032 { | 5045 { |
5033 ASSERT(m_loadEventDelayCount); | 5046 ASSERT(m_loadEventDelayCount); |
5034 --m_loadEventDelayCount; | 5047 --m_loadEventDelayCount; |
5035 | 5048 |
5036 if (frame() && !m_loadEventDelayCount && !m_loadEventDelayTimer.isActive()) | 5049 if (!m_loadEventDelayCount) |
| 5050 checkLoadEventSoon(); |
| 5051 } |
| 5052 |
| 5053 void Document::checkLoadEventSoon() |
| 5054 { |
| 5055 if (frame() && !m_loadEventDelayTimer.isActive()) |
5037 m_loadEventDelayTimer.startOneShot(0, FROM_HERE); | 5056 m_loadEventDelayTimer.startOneShot(0, FROM_HERE); |
5038 } | 5057 } |
5039 | 5058 |
| 5059 bool Document::isDelayingLoadEvent() |
| 5060 { |
| 5061 #if ENABLE(OILPAN) |
| 5062 // Always delay load events until after garbage collection. |
| 5063 // This way we don't have to explicitly delay load events via |
| 5064 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in |
| 5065 // Node destructors. |
| 5066 if (ThreadState::current()->isSweepInProgress()) { |
| 5067 if (!m_loadEventDelayCount) |
| 5068 checkLoadEventSoon(); |
| 5069 return true; |
| 5070 } |
| 5071 #endif |
| 5072 return m_loadEventDelayCount; |
| 5073 } |
| 5074 |
| 5075 |
5040 void Document::loadEventDelayTimerFired(Timer<Document>*) | 5076 void Document::loadEventDelayTimerFired(Timer<Document>*) |
5041 { | 5077 { |
5042 if (frame()) | 5078 if (frame()) |
5043 frame()->loader().checkCompleted(); | 5079 frame()->loader().checkCompleted(); |
5044 } | 5080 } |
5045 | 5081 |
5046 void Document::loadPluginsSoon() | 5082 void Document::loadPluginsSoon() |
5047 { | 5083 { |
5048 // FIXME: Remove this timer once we don't need to compute layout to load plu
gins. | 5084 // FIXME: Remove this timer once we don't need to compute layout to load plu
gins. |
5049 if (!m_pluginLoadingTimer.isActive()) | 5085 if (!m_pluginLoadingTimer.isActive()) |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5583 return false; | 5619 return false; |
5584 } | 5620 } |
5585 | 5621 |
5586 void Document::invalidateNodeListCaches(const QualifiedName* attrName) | 5622 void Document::invalidateNodeListCaches(const QualifiedName* attrName) |
5587 { | 5623 { |
5588 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end(
); | 5624 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end(
); |
5589 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument.
begin(); it != end; ++it) | 5625 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument.
begin(); it != end; ++it) |
5590 (*it)->invalidateCacheForAttribute(attrName); | 5626 (*it)->invalidateCacheForAttribute(attrName); |
5591 } | 5627 } |
5592 | 5628 |
| 5629 void Document::clearWeakMembers(Visitor* visitor) |
| 5630 { |
| 5631 if (m_axObjectCache) |
| 5632 m_axObjectCache->clearWeakMembers(visitor); |
| 5633 |
| 5634 if (m_markers) |
| 5635 m_markers->clearWeakMembers(visitor); |
| 5636 |
| 5637 // FIXME: Oilpan: Use a weak counted set instead. |
| 5638 if (m_touchEventTargets) { |
| 5639 Vector<Node*> deadNodes; |
| 5640 for (TouchEventTargetSet::iterator it = m_touchEventTargets->begin(); it
!= m_touchEventTargets->end(); ++it) { |
| 5641 if (!visitor->isAlive(it->key)) |
| 5642 deadNodes.append(it->key); |
| 5643 } |
| 5644 for (unsigned i = 0; i < deadNodes.size(); ++i) |
| 5645 didClearTouchEventHandlers(deadNodes[i]); |
| 5646 } |
| 5647 |
| 5648 EventHandlerRegistry* registry = static_cast<EventHandlerRegistry*>(Document
Supplement::from(this, EventHandlerRegistry::supplementName())); |
| 5649 // FIXME: Oilpan: This is pretty funky. The current code disables all modifi
cations of the |
| 5650 // EventHandlerRegistry when the document becomes inactive. To keep that beh
avior we only |
| 5651 // perform weak processing of the registry when the document is active. |
| 5652 if (registry && isActive()) |
| 5653 registry->clearWeakMembers(visitor); |
| 5654 } |
| 5655 |
5593 void Document::trace(Visitor* visitor) | 5656 void Document::trace(Visitor* visitor) |
5594 { | 5657 { |
| 5658 visitor->trace(m_styleSheetList); |
| 5659 visitor->trace(m_visibilityObservers); |
| 5660 visitor->registerWeakMembers<Document, &Document::clearWeakMembers>(this); |
5595 Supplementable<Document>::trace(visitor); | 5661 Supplementable<Document>::trace(visitor); |
| 5662 TreeScope::trace(visitor); |
5596 ContainerNode::trace(visitor); | 5663 ContainerNode::trace(visitor); |
5597 } | 5664 } |
5598 | 5665 |
5599 } // namespace WebCore | 5666 } // namespace WebCore |
OLD | NEW |