Chromium Code Reviews| 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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 }; | 371 }; |
| 372 | 372 |
| 373 DocumentVisibilityObserver::DocumentVisibilityObserver(Document& document) | 373 DocumentVisibilityObserver::DocumentVisibilityObserver(Document& document) |
| 374 : m_document(0) | 374 : m_document(0) |
| 375 { | 375 { |
| 376 registerObserver(document); | 376 registerObserver(document); |
| 377 } | 377 } |
| 378 | 378 |
| 379 DocumentVisibilityObserver::~DocumentVisibilityObserver() | 379 DocumentVisibilityObserver::~DocumentVisibilityObserver() |
| 380 { | 380 { |
| 381 #if !ENABLE(OILPAN) | |
| 381 unregisterObserver(); | 382 unregisterObserver(); |
| 383 #endif | |
| 382 } | 384 } |
| 383 | 385 |
| 384 void DocumentVisibilityObserver::unregisterObserver() | 386 void DocumentVisibilityObserver::unregisterObserver() |
| 385 { | 387 { |
| 386 if (m_document) { | 388 if (m_document) { |
| 387 m_document->unregisterVisibilityObserver(this); | 389 m_document->unregisterVisibilityObserver(this); |
| 388 m_document = 0; | 390 m_document = 0; |
| 389 } | 391 } |
| 390 } | 392 } |
| 391 | 393 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 // m_fetcher. | 518 // m_fetcher. |
| 517 m_styleEngine = StyleEngine::create(*this); | 519 m_styleEngine = StyleEngine::create(*this); |
| 518 } | 520 } |
| 519 | 521 |
| 520 Document::~Document() | 522 Document::~Document() |
| 521 { | 523 { |
| 522 ASSERT(!renderView()); | 524 ASSERT(!renderView()); |
| 523 ASSERT(m_ranges.isEmpty()); | 525 ASSERT(m_ranges.isEmpty()); |
| 524 ASSERT(!parentTreeScope()); | 526 ASSERT(!parentTreeScope()); |
| 525 ASSERT(!hasGuardRefCount()); | 527 ASSERT(!hasGuardRefCount()); |
| 528 #if !ENABLE(OILPAN) | |
| 529 // With oilpan the visibility obeservers and the document can die together | |
|
haraken
2014/04/24 04:18:43
This comment is a bit misreading. Document can out
Mads Ager (chromium)
2014/04/24 10:57:36
Yes, either the document outlives the visibility o
| |
| 530 // at which point the weak collection of observers will not be empty. | |
| 526 ASSERT(m_visibilityObservers.isEmpty()); | 531 ASSERT(m_visibilityObservers.isEmpty()); |
| 532 #endif | |
| 527 | 533 |
| 528 if (m_templateDocument) | 534 if (m_templateDocument) |
| 529 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem plateDocument(). | 535 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem plateDocument(). |
| 530 | 536 |
| 531 m_scriptRunner.clear(); | 537 m_scriptRunner.clear(); |
| 532 | 538 |
| 533 removeAllEventListenersRecursively(); | 539 removeAllEventListenersRecursively(); |
| 534 | 540 |
| 535 // Currently we believe that Document can never outlive the parser. | 541 // Currently we believe that Document can never outlive the parser. |
| 536 // Although the Document may be replaced synchronously, DocumentParsers | 542 // Although the Document may be replaced synchronously, DocumentParsers |
| 537 // generally keep at least one reference to an Element which would in turn | 543 // generally keep at least one reference to an Element which would in turn |
| 538 // has a reference to the Document. If you hit this ASSERT, then that | 544 // has a reference to the Document. If you hit this ASSERT, then that |
| 539 // assumption is wrong. DocumentParser::detach() should ensure that even | 545 // assumption is wrong. DocumentParser::detach() should ensure that even |
| 540 // if the DocumentParser outlives the Document it won't cause badness. | 546 // if the DocumentParser outlives the Document it won't cause badness. |
| 541 ASSERT(!m_parser || m_parser->refCount() == 1); | 547 ASSERT(!m_parser || m_parser->refCount() == 1); |
| 542 detachParser(); | 548 detachParser(); |
| 543 | 549 |
| 544 if (this == topDocument()) | 550 if (this == topDocument()) |
| 545 clearAXObjectCache(); | 551 clearAXObjectCache(); |
| 546 | 552 |
| 553 #if !ENABLE(OILPAN) | |
| 547 if (m_styleSheetList) | 554 if (m_styleSheetList) |
| 548 m_styleSheetList->detachFromDocument(); | 555 m_styleSheetList->detachFromDocument(); |
| 556 #endif | |
| 549 | 557 |
| 550 if (m_importsController) { | 558 if (m_importsController) { |
| 551 m_importsController->wasDetachedFrom(*this); | 559 m_importsController->wasDetachedFrom(*this); |
| 552 m_importsController = 0; | 560 m_importsController = 0; |
| 553 } | 561 } |
| 554 | 562 |
| 555 m_timeline->detachFromDocument(); | 563 m_timeline->detachFromDocument(); |
| 556 m_transitionTimeline->detachFromDocument(); | 564 m_transitionTimeline->detachFromDocument(); |
| 557 | 565 |
| 558 // We need to destroy CSSFontSelector before destroying m_fetcher. | 566 // We need to destroy CSSFontSelector before destroying m_fetcher. |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1428 return pageVisibilityState() != PageVisibilityStateVisible; | 1436 return pageVisibilityState() != PageVisibilityStateVisible; |
| 1429 } | 1437 } |
| 1430 | 1438 |
| 1431 void Document::didChangeVisibilityState() | 1439 void Document::didChangeVisibilityState() |
| 1432 { | 1440 { |
| 1433 dispatchEvent(Event::create(EventTypeNames::visibilitychange)); | 1441 dispatchEvent(Event::create(EventTypeNames::visibilitychange)); |
| 1434 // Also send out the deprecated version until it can be removed. | 1442 // Also send out the deprecated version until it can be removed. |
| 1435 dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange)); | 1443 dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange)); |
| 1436 | 1444 |
| 1437 PageVisibilityState state = pageVisibilityState(); | 1445 PageVisibilityState state = pageVisibilityState(); |
| 1438 HashSet<DocumentVisibilityObserver*>::const_iterator observerEnd = m_visibil ityObservers.end(); | 1446 WillBeHeapHashSet<RawPtrWillBeWeakMember<DocumentVisibilityObserver> >::cons t_iterator observerEnd = m_visibilityObservers.end(); |
| 1439 for (HashSet<DocumentVisibilityObserver*>::const_iterator it = m_visibilityO bservers.begin(); it != observerEnd; ++it) | 1447 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<DocumentVisibilityObserver> >: :const_iterator it = m_visibilityObservers.begin(); it != observerEnd; ++it) |
| 1440 (*it)->didChangeVisibilityState(state); | 1448 (*it)->didChangeVisibilityState(state); |
| 1441 } | 1449 } |
| 1442 | 1450 |
| 1443 void Document::registerVisibilityObserver(DocumentVisibilityObserver* observer) | 1451 void Document::registerVisibilityObserver(DocumentVisibilityObserver* observer) |
| 1444 { | 1452 { |
| 1445 ASSERT(!m_visibilityObservers.contains(observer)); | 1453 ASSERT(!m_visibilityObservers.contains(observer)); |
| 1446 m_visibilityObservers.add(observer); | 1454 m_visibilityObservers.add(observer); |
| 1447 } | 1455 } |
| 1448 | 1456 |
| 1449 void Document::unregisterVisibilityObserver(DocumentVisibilityObserver* observer ) | 1457 void Document::unregisterVisibilityObserver(DocumentVisibilityObserver* observer ) |
| (...skipping 3382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4832 m_ranges.add(range); | 4840 m_ranges.add(range); |
| 4833 } | 4841 } |
| 4834 | 4842 |
| 4835 void Document::detachRange(Range* range) | 4843 void Document::detachRange(Range* range) |
| 4836 { | 4844 { |
| 4837 // We don't ASSERT m_ranges.contains(range) to allow us to call this | 4845 // We don't ASSERT m_ranges.contains(range) to allow us to call this |
| 4838 // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044 | 4846 // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044 |
| 4839 m_ranges.remove(range); | 4847 m_ranges.remove(range); |
| 4840 } | 4848 } |
| 4841 | 4849 |
| 4842 void Document::getCSSCanvasContext(const String& type, const String& name, int w idth, int height, bool& is2d, RefPtr<CanvasRenderingContext2D>& context2d, bool& is3d, RefPtr<WebGLRenderingContext>& context3d) | 4850 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) |
| 4843 { | 4851 { |
| 4844 HTMLCanvasElement& element = getCSSCanvasElement(name); | 4852 HTMLCanvasElement& element = getCSSCanvasElement(name); |
| 4845 element.setSize(IntSize(width, height)); | 4853 element.setSize(IntSize(width, height)); |
| 4846 CanvasRenderingContext* context = element.getContext(type); | 4854 CanvasRenderingContext* context = element.getContext(type); |
| 4847 if (!context) | 4855 if (!context) |
| 4848 return; | 4856 return; |
| 4849 | 4857 |
| 4850 if (context->is2d()) { | 4858 if (context->is2d()) { |
| 4851 is2d = true; | 4859 is2d = true; |
| 4852 context2d = toCanvasRenderingContext2D(context); | 4860 context2d = toCanvasRenderingContext2D(context); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5035 return element; | 5043 return element; |
| 5036 } | 5044 } |
| 5037 return 0; | 5045 return 0; |
| 5038 } | 5046 } |
| 5039 | 5047 |
| 5040 void Document::decrementLoadEventDelayCount() | 5048 void Document::decrementLoadEventDelayCount() |
| 5041 { | 5049 { |
| 5042 ASSERT(m_loadEventDelayCount); | 5050 ASSERT(m_loadEventDelayCount); |
| 5043 --m_loadEventDelayCount; | 5051 --m_loadEventDelayCount; |
| 5044 | 5052 |
| 5045 if (frame() && !m_loadEventDelayCount && !m_loadEventDelayTimer.isActive()) | 5053 if (!m_loadEventDelayCount) |
| 5054 checkLoadEventSoon(); | |
| 5055 } | |
| 5056 | |
| 5057 void Document::checkLoadEventSoon() | |
| 5058 { | |
| 5059 if (frame() && !m_loadEventDelayTimer.isActive()) | |
| 5046 m_loadEventDelayTimer.startOneShot(0, FROM_HERE); | 5060 m_loadEventDelayTimer.startOneShot(0, FROM_HERE); |
| 5047 } | 5061 } |
| 5048 | 5062 |
| 5063 bool Document::isDelayingLoadEvent() | |
| 5064 { | |
| 5065 #if ENABLE(OILPAN) | |
| 5066 // With Oilpan, always delay load events until after garbage collection. | |
| 5067 // This way we don't have to explicitly delay load events via | |
| 5068 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in | |
| 5069 // Node destructors. | |
| 5070 if (!m_loadEventDelayCount && ThreadState::current()->isSweepInProgress()) { | |
|
haraken
2014/04/24 04:18:43
I understand this code is needed in order not to l
Mads Ager (chromium)
2014/04/24 10:57:36
This is a little complicated, but it is a minor co
| |
| 5071 checkLoadEventSoon(); | |
| 5072 return true; | |
| 5073 } | |
| 5074 #endif | |
| 5075 return m_loadEventDelayCount; | |
| 5076 } | |
| 5077 | |
| 5078 | |
| 5049 void Document::loadEventDelayTimerFired(Timer<Document>*) | 5079 void Document::loadEventDelayTimerFired(Timer<Document>*) |
| 5050 { | 5080 { |
| 5051 if (frame()) | 5081 if (frame()) |
| 5052 frame()->loader().checkCompleted(); | 5082 frame()->loader().checkCompleted(); |
| 5053 } | 5083 } |
| 5054 | 5084 |
| 5055 void Document::loadPluginsSoon() | 5085 void Document::loadPluginsSoon() |
| 5056 { | 5086 { |
| 5057 // FIXME: Remove this timer once we don't need to compute layout to load plu gins. | 5087 // FIXME: Remove this timer once we don't need to compute layout to load plu gins. |
| 5058 if (!m_pluginLoadingTimer.isActive()) | 5088 if (!m_pluginLoadingTimer.isActive()) |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5592 return false; | 5622 return false; |
| 5593 } | 5623 } |
| 5594 | 5624 |
| 5595 void Document::invalidateNodeListCaches(const QualifiedName* attrName) | 5625 void Document::invalidateNodeListCaches(const QualifiedName* attrName) |
| 5596 { | 5626 { |
| 5597 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end( ); | 5627 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end( ); |
| 5598 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument. begin(); it != end; ++it) | 5628 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument. begin(); it != end; ++it) |
| 5599 (*it)->invalidateCache(attrName); | 5629 (*it)->invalidateCache(attrName); |
| 5600 } | 5630 } |
| 5601 | 5631 |
| 5632 void Document::clearWeakMembers(Visitor* visitor) | |
| 5633 { | |
| 5634 if (m_axObjectCache) | |
| 5635 m_axObjectCache->clearWeakMembers(visitor); | |
| 5636 | |
| 5637 if (m_markers) | |
| 5638 m_markers->clearWeakMembers(visitor); | |
|
haraken
2014/04/24 04:18:43
This is a clarifying question about a programming
Mads Ager (chromium)
2014/04/24 10:57:36
Right, so here is the thing: This is all weak proc
| |
| 5639 | |
| 5640 // FIXME: Oilpan: Use a weak counted set instead. | |
| 5641 if (m_touchEventTargets) { | |
| 5642 Vector<Node*> deadNodes; | |
| 5643 for (TouchEventTargetSet::iterator it = m_touchEventTargets->begin(); it != m_touchEventTargets->end(); ++it) { | |
| 5644 if (!visitor->isAlive(it->key)) | |
| 5645 deadNodes.append(it->key); | |
| 5646 } | |
| 5647 for (unsigned i = 0; i < deadNodes.size(); ++i) | |
| 5648 didClearTouchEventHandlers(deadNodes[i]); | |
| 5649 } | |
| 5650 } | |
| 5651 | |
| 5602 void Document::trace(Visitor* visitor) | 5652 void Document::trace(Visitor* visitor) |
| 5603 { | 5653 { |
| 5654 visitor->trace(m_styleSheetList); | |
| 5655 visitor->trace(m_visibilityObservers); | |
| 5656 visitor->registerWeakMembers<Document, &Document::clearWeakMembers>(this); | |
| 5604 Supplementable<Document>::trace(visitor); | 5657 Supplementable<Document>::trace(visitor); |
| 5658 TreeScope::trace(visitor); | |
| 5605 ContainerNode::trace(visitor); | 5659 ContainerNode::trace(visitor); |
| 5606 } | 5660 } |
| 5607 | 5661 |
| 5608 } // namespace WebCore | 5662 } // namespace WebCore |
| OLD | NEW |