Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 235113002: Oilpan: Remove guardRef and guardDeref from TreeScope. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Only perform weak processing of the event handler registry if the document is active. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 }; 372 };
372 373
373 DocumentVisibilityObserver::DocumentVisibilityObserver(Document& document) 374 DocumentVisibilityObserver::DocumentVisibilityObserver(Document& document)
374 : m_document(0) 375 : m_document(0)
375 { 376 {
376 registerObserver(document); 377 registerObserver(document);
377 } 378 }
378 379
379 DocumentVisibilityObserver::~DocumentVisibilityObserver() 380 DocumentVisibilityObserver::~DocumentVisibilityObserver()
380 { 381 {
382 #if !ENABLE(OILPAN)
381 unregisterObserver(); 383 unregisterObserver();
384 #endif
382 } 385 }
383 386
384 void DocumentVisibilityObserver::unregisterObserver() 387 void DocumentVisibilityObserver::unregisterObserver()
385 { 388 {
386 if (m_document) { 389 if (m_document) {
387 m_document->unregisterVisibilityObserver(this); 390 m_document->unregisterVisibilityObserver(this);
388 m_document = 0; 391 m_document = 0;
389 } 392 }
390 } 393 }
391 394
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 // CSSFontSelector, need to initialize m_styleEngine after initializing 518 // CSSFontSelector, need to initialize m_styleEngine after initializing
516 // m_fetcher. 519 // m_fetcher.
517 m_styleEngine = StyleEngine::create(*this); 520 m_styleEngine = StyleEngine::create(*this);
518 } 521 }
519 522
520 Document::~Document() 523 Document::~Document()
521 { 524 {
522 ASSERT(!renderView()); 525 ASSERT(!renderView());
523 ASSERT(m_ranges.isEmpty()); 526 ASSERT(m_ranges.isEmpty());
524 ASSERT(!parentTreeScope()); 527 ASSERT(!parentTreeScope());
528 #if !ENABLE(OILPAN)
525 ASSERT(!hasGuardRefCount()); 529 ASSERT(!hasGuardRefCount());
530 // With Oilpan, either the document outlives the visibility observers
531 // or the visibility observers and the document die in the same GC round.
532 // When they die in the same GC round, the list of visibility observers
533 // will not be empty on Document destruction.
526 ASSERT(m_visibilityObservers.isEmpty()); 534 ASSERT(m_visibilityObservers.isEmpty());
535 #endif
527 536
528 if (m_templateDocument) 537 if (m_templateDocument)
529 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem plateDocument(). 538 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem plateDocument().
530 539
531 m_scriptRunner.clear(); 540 m_scriptRunner.clear();
532 541
533 removeAllEventListenersRecursively(); 542 removeAllEventListenersRecursively();
534 543
535 // Currently we believe that Document can never outlive the parser. 544 // Currently we believe that Document can never outlive the parser.
536 // Although the Document may be replaced synchronously, DocumentParsers 545 // Although the Document may be replaced synchronously, DocumentParsers
537 // generally keep at least one reference to an Element which would in turn 546 // 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 547 // has a reference to the Document. If you hit this ASSERT, then that
539 // assumption is wrong. DocumentParser::detach() should ensure that even 548 // assumption is wrong. DocumentParser::detach() should ensure that even
540 // if the DocumentParser outlives the Document it won't cause badness. 549 // if the DocumentParser outlives the Document it won't cause badness.
541 ASSERT(!m_parser || m_parser->refCount() == 1); 550 ASSERT(!m_parser || m_parser->refCount() == 1);
542 detachParser(); 551 detachParser();
543 552
544 if (this == topDocument()) 553 if (this == topDocument())
545 clearAXObjectCache(); 554 clearAXObjectCache();
546 555
556 #if !ENABLE(OILPAN)
547 if (m_styleSheetList) 557 if (m_styleSheetList)
548 m_styleSheetList->detachFromDocument(); 558 m_styleSheetList->detachFromDocument();
559 #endif
549 560
550 if (m_importsController) { 561 if (m_importsController) {
551 m_importsController->wasDetachedFrom(*this); 562 m_importsController->wasDetachedFrom(*this);
552 m_importsController = 0; 563 m_importsController = 0;
553 } 564 }
554 565
555 m_timeline->detachFromDocument(); 566 m_timeline->detachFromDocument();
556 m_transitionTimeline->detachFromDocument(); 567 m_transitionTimeline->detachFromDocument();
557 568
558 // We need to destroy CSSFontSelector before destroying m_fetcher. 569 // We need to destroy CSSFontSelector before destroying m_fetcher.
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 return pageVisibilityState() != PageVisibilityStateVisible; 1429 return pageVisibilityState() != PageVisibilityStateVisible;
1419 } 1430 }
1420 1431
1421 void Document::didChangeVisibilityState() 1432 void Document::didChangeVisibilityState()
1422 { 1433 {
1423 dispatchEvent(Event::create(EventTypeNames::visibilitychange)); 1434 dispatchEvent(Event::create(EventTypeNames::visibilitychange));
1424 // Also send out the deprecated version until it can be removed. 1435 // Also send out the deprecated version until it can be removed.
1425 dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange)); 1436 dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange));
1426 1437
1427 PageVisibilityState state = pageVisibilityState(); 1438 PageVisibilityState state = pageVisibilityState();
1428 HashSet<DocumentVisibilityObserver*>::const_iterator observerEnd = m_visibil ityObservers.end(); 1439 DocumentVisibilityObserverSet::const_iterator observerEnd = m_visibilityObse rvers.end();
1429 for (HashSet<DocumentVisibilityObserver*>::const_iterator it = m_visibilityO bservers.begin(); it != observerEnd; ++it) 1440 for (DocumentVisibilityObserverSet::const_iterator it = m_visibilityObserver s.begin(); it != observerEnd; ++it)
1430 (*it)->didChangeVisibilityState(state); 1441 (*it)->didChangeVisibilityState(state);
1431 } 1442 }
1432 1443
1433 void Document::registerVisibilityObserver(DocumentVisibilityObserver* observer) 1444 void Document::registerVisibilityObserver(DocumentVisibilityObserver* observer)
1434 { 1445 {
1435 ASSERT(!m_visibilityObservers.contains(observer)); 1446 ASSERT(!m_visibilityObservers.contains(observer));
1436 m_visibilityObservers.add(observer); 1447 m_visibilityObservers.add(observer);
1437 } 1448 }
1438 1449
1439 void Document::unregisterVisibilityObserver(DocumentVisibilityObserver* observer ) 1450 void Document::unregisterVisibilityObserver(DocumentVisibilityObserver* observer )
(...skipping 3373 matching lines...) Expand 10 before | Expand all | Expand 10 after
4813 m_ranges.add(range); 4824 m_ranges.add(range);
4814 } 4825 }
4815 4826
4816 void Document::detachRange(Range* range) 4827 void Document::detachRange(Range* range)
4817 { 4828 {
4818 // We don't ASSERT m_ranges.contains(range) to allow us to call this 4829 // We don't ASSERT m_ranges.contains(range) to allow us to call this
4819 // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044 4830 // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044
4820 m_ranges.remove(range); 4831 m_ranges.remove(range);
4821 } 4832 }
4822 4833
4823 void Document::getCSSCanvasContext(const String& type, const String& name, int w idth, int height, bool& is2d, RefPtr<CanvasRenderingContext2D>& context2d, bool& is3d, RefPtr<WebGLRenderingContext>& context3d) 4834 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)
4824 { 4835 {
4825 HTMLCanvasElement& element = getCSSCanvasElement(name); 4836 HTMLCanvasElement& element = getCSSCanvasElement(name);
4826 element.setSize(IntSize(width, height)); 4837 element.setSize(IntSize(width, height));
4827 CanvasRenderingContext* context = element.getContext(type); 4838 CanvasRenderingContext* context = element.getContext(type);
4828 if (!context) 4839 if (!context)
4829 return; 4840 return;
4830 4841
4831 if (context->is2d()) { 4842 if (context->is2d()) {
4832 is2d = true; 4843 is2d = true;
4833 context2d = toCanvasRenderingContext2D(context); 4844 context2d = toCanvasRenderingContext2D(context);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
5016 return element; 5027 return element;
5017 } 5028 }
5018 return 0; 5029 return 0;
5019 } 5030 }
5020 5031
5021 void Document::decrementLoadEventDelayCount() 5032 void Document::decrementLoadEventDelayCount()
5022 { 5033 {
5023 ASSERT(m_loadEventDelayCount); 5034 ASSERT(m_loadEventDelayCount);
5024 --m_loadEventDelayCount; 5035 --m_loadEventDelayCount;
5025 5036
5026 if (frame() && !m_loadEventDelayCount && !m_loadEventDelayTimer.isActive()) 5037 if (!m_loadEventDelayCount)
5038 checkLoadEventSoon();
5039 }
5040
5041 void Document::checkLoadEventSoon()
5042 {
5043 if (frame() && !m_loadEventDelayTimer.isActive())
5027 m_loadEventDelayTimer.startOneShot(0, FROM_HERE); 5044 m_loadEventDelayTimer.startOneShot(0, FROM_HERE);
5028 } 5045 }
5029 5046
5047 bool Document::isDelayingLoadEvent()
5048 {
5049 #if ENABLE(OILPAN)
5050 // Always delay load events until after garbage collection.
5051 // This way we don't have to explicitly delay load events via
5052 // incrementLoadEventDelayCount and decrementLoadEventDelayCount in
5053 // Node destructors.
5054 if (ThreadState::current()->isSweepInProgress()) {
5055 if (!m_loadEventDelayCount)
5056 checkLoadEventSoon();
5057 return true;
5058 }
5059 #endif
5060 return m_loadEventDelayCount;
5061 }
5062
5063
5030 void Document::loadEventDelayTimerFired(Timer<Document>*) 5064 void Document::loadEventDelayTimerFired(Timer<Document>*)
5031 { 5065 {
5032 if (frame()) 5066 if (frame())
5033 frame()->loader().checkCompleted(); 5067 frame()->loader().checkCompleted();
5034 } 5068 }
5035 5069
5036 void Document::loadPluginsSoon() 5070 void Document::loadPluginsSoon()
5037 { 5071 {
5038 // FIXME: Remove this timer once we don't need to compute layout to load plu gins. 5072 // FIXME: Remove this timer once we don't need to compute layout to load plu gins.
5039 if (!m_pluginLoadingTimer.isActive()) 5073 if (!m_pluginLoadingTimer.isActive())
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
5573 return false; 5607 return false;
5574 } 5608 }
5575 5609
5576 void Document::invalidateNodeListCaches(const QualifiedName* attrName) 5610 void Document::invalidateNodeListCaches(const QualifiedName* attrName)
5577 { 5611 {
5578 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end( ); 5612 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end( );
5579 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument. begin(); it != end; ++it) 5613 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument. begin(); it != end; ++it)
5580 (*it)->invalidateCacheForAttribute(attrName); 5614 (*it)->invalidateCacheForAttribute(attrName);
5581 } 5615 }
5582 5616
5617 void Document::clearWeakMembers(Visitor* visitor)
5618 {
5619 if (m_axObjectCache)
5620 m_axObjectCache->clearWeakMembers(visitor);
5621
5622 if (m_markers)
5623 m_markers->clearWeakMembers(visitor);
5624
5625 // FIXME: Oilpan: Use a weak counted set instead.
5626 if (m_touchEventTargets) {
5627 Vector<Node*> deadNodes;
5628 for (TouchEventTargetSet::iterator it = m_touchEventTargets->begin(); it != m_touchEventTargets->end(); ++it) {
5629 if (!visitor->isAlive(it->key))
5630 deadNodes.append(it->key);
5631 }
5632 for (unsigned i = 0; i < deadNodes.size(); ++i)
5633 didClearTouchEventHandlers(deadNodes[i]);
5634 }
5635
5636 EventHandlerRegistry* registry = static_cast<EventHandlerRegistry*>(Document Supplement::from(this, EventHandlerRegistry::supplementName()));
5637 // FIXME: Oilpan: This is pretty funky. The current code disables all modifi cations of the
5638 // EventHandlerRegistry when the document becomes inactive. To keep that beh avior we only
5639 // perform weak processing of the registry when the document is active.
haraken 2014/04/25 14:30:32 Just to confirm: Even if we don't have the isActiv
Mads Ager (chromium) 2014/04/28 09:45:21 Without the isActive check this will crash for the
5640 if (registry && isActive())
5641 registry->clearWeakMembers(visitor);
haraken 2014/04/25 14:30:32 EventHandlerRegistry is a supplement object of Doc
Mads Ager (chromium) 2014/04/28 09:45:21 I can't at this point because the EventHandlerRegi
5642 }
5643
5583 void Document::trace(Visitor* visitor) 5644 void Document::trace(Visitor* visitor)
5584 { 5645 {
5646 visitor->trace(m_styleSheetList);
5647 visitor->trace(m_visibilityObservers);
5648 visitor->registerWeakMembers<Document, &Document::clearWeakMembers>(this);
5585 Supplementable<Document>::trace(visitor); 5649 Supplementable<Document>::trace(visitor);
5650 TreeScope::trace(visitor);
5586 ContainerNode::trace(visitor); 5651 ContainerNode::trace(visitor);
5587 } 5652 }
5588 5653
5589 } // namespace WebCore 5654 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698