| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/dom/ContextLifecycleNotifier.h" | 29 #include "core/dom/ContextLifecycleNotifier.h" |
| 30 | 30 |
| 31 #include "core/dom/ScriptExecutionContext.h" |
| 31 #include "core/dom/WebCoreMemoryInstrumentation.h" | 32 #include "core/dom/WebCoreMemoryInstrumentation.h" |
| 32 #include "wtf/TemporaryChange.h" | 33 #include "wtf/TemporaryChange.h" |
| 33 | 34 |
| 34 namespace WebCore { | 35 namespace WebCore { |
| 35 | 36 |
| 36 ContextLifecycleNotifier::ContextLifecycleNotifier(ScriptExecutionContext* conte
xt) | 37 ContextLifecycleNotifier::ContextLifecycleNotifier(ScriptExecutionContext* conte
xt) |
| 37 : m_context(context) | 38 : SimpleLifecycleNotifier(context) |
| 38 , m_iterating(IteratingNone) | |
| 39 , m_inDestructor(false) | |
| 40 { | 39 { |
| 41 } | 40 } |
| 42 | 41 |
| 43 ContextLifecycleNotifier::~ContextLifecycleNotifier() | 42 ContextLifecycleNotifier::~ContextLifecycleNotifier() |
| 44 { | 43 { |
| 45 m_inDestructor = true; | |
| 46 for (ContextObserverSet::iterator iter = m_contextObservers.begin(); iter !=
m_contextObservers.end(); iter = m_contextObservers.begin()) { | |
| 47 ContextLifecycleObserver* observer = *iter; | |
| 48 m_contextObservers.remove(observer); | |
| 49 ASSERT(observer->scriptExecutionContext() == m_context); | |
| 50 observer->contextDestroyed(); | |
| 51 } | |
| 52 } | 44 } |
| 53 | 45 |
| 54 void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer, C
ontextLifecycleObserver::Type as) | 46 void ContextLifecycleNotifier::addObserver(SimpleLifecycleObserver* observer, Si
mpleLifecycleObserver::Type type) |
| 55 { | 47 { |
| 56 RELEASE_ASSERT(!m_inDestructor); | 48 SimpleLifecycleNotifier::addObserver(observer, type); |
| 49 |
| 57 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); | 50 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); |
| 58 m_contextObservers.add(observer); | 51 if (type == SimpleLifecycleObserver::ActiveDOMObjectType) { |
| 59 if (as == ContextLifecycleObserver::ActiveDOMObjectType) { | |
| 60 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); | 52 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); |
| 61 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); | 53 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); |
| 62 } | 54 } |
| 63 } | 55 } |
| 64 | 56 |
| 65 void ContextLifecycleNotifier::removeObserver(ContextLifecycleObserver* observer
, ContextLifecycleObserver::Type as) | 57 void ContextLifecycleNotifier::removeObserver(SimpleLifecycleObserver* observer,
SimpleLifecycleObserver::Type type) |
| 66 { | 58 { |
| 67 RELEASE_ASSERT(!m_inDestructor); | 59 SimpleLifecycleNotifier::removeObserver(observer, type); |
| 60 |
| 68 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); | 61 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); |
| 69 m_contextObservers.remove(observer); | 62 if (type == SimpleLifecycleObserver::ActiveDOMObjectType) { |
| 70 if (as == ContextLifecycleObserver::ActiveDOMObjectType) { | |
| 71 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); | 63 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); |
| 72 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); | 64 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); |
| 73 } | 65 } |
| 74 } | 66 } |
| 75 | 67 |
| 76 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() | 68 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() |
| 77 { | 69 { |
| 78 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 70 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
| 79 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 71 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
| 80 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { | 72 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { |
| 81 ASSERT((*iter)->scriptExecutionContext() == m_context); | 73 ASSERT((*iter)->scriptExecutionContext() == context()); |
| 82 ASSERT((*iter)->suspendIfNeededCalled()); | 74 ASSERT((*iter)->suspendIfNeededCalled()); |
| 83 (*iter)->resume(); | 75 (*iter)->resume(); |
| 84 } | 76 } |
| 85 } | 77 } |
| 86 | 78 |
| 87 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects(ActiveDOMObject:
:ReasonForSuspension why) | 79 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects(ActiveDOMObject:
:ReasonForSuspension why) |
| 88 { | 80 { |
| 89 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 81 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
| 90 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 82 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
| 91 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { | 83 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { |
| 92 ASSERT((*iter)->scriptExecutionContext() == m_context); | 84 ASSERT((*iter)->scriptExecutionContext() == context()); |
| 93 ASSERT((*iter)->suspendIfNeededCalled()); | 85 ASSERT((*iter)->suspendIfNeededCalled()); |
| 94 (*iter)->suspend(why); | 86 (*iter)->suspend(why); |
| 95 } | 87 } |
| 96 } | 88 } |
| 97 | 89 |
| 98 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 90 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
| 99 { | 91 { |
| 100 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 92 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
| 101 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 93 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
| 102 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { | 94 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { |
| 103 ASSERT((*iter)->scriptExecutionContext() == m_context); | 95 ASSERT((*iter)->scriptExecutionContext() == context()); |
| 104 ASSERT((*iter)->suspendIfNeededCalled()); | 96 ASSERT((*iter)->suspendIfNeededCalled()); |
| 105 (*iter)->stop(); | 97 (*iter)->stop(); |
| 106 } | 98 } |
| 107 } | 99 } |
| 108 | 100 |
| 109 bool ContextLifecycleNotifier::canSuspendActiveDOMObjects() | 101 bool ContextLifecycleNotifier::canSuspendActiveDOMObjects() |
| 110 { | 102 { |
| 111 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 103 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
| 112 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 104 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
| 113 for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); i
ter != activeObjectsEnd; ++iter) { | 105 for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); i
ter != activeObjectsEnd; ++iter) { |
| 114 ASSERT((*iter)->scriptExecutionContext() == m_context); | 106 ASSERT((*iter)->scriptExecutionContext() == context()); |
| 115 ASSERT((*iter)->suspendIfNeededCalled()); | 107 ASSERT((*iter)->suspendIfNeededCalled()); |
| 116 if (!(*iter)->canSuspend()) | 108 if (!(*iter)->canSuspend()) |
| 117 return false; | 109 return false; |
| 118 } | 110 } |
| 119 | 111 |
| 120 return true; | 112 return true; |
| 121 } | 113 } |
| 122 | 114 |
| 123 bool ContextLifecycleNotifier::hasPendingActivity() const | 115 bool ContextLifecycleNotifier::hasPendingActivity() const |
| 124 { | 116 { |
| 125 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end
(); | 117 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end
(); |
| 126 for (ActiveDOMObjectSet::const_iterator iter = activeDOMObjects().begin(); i
ter != activeObjectsEnd; ++iter) { | 118 for (ActiveDOMObjectSet::const_iterator iter = activeDOMObjects().begin(); i
ter != activeObjectsEnd; ++iter) { |
| 127 if ((*iter)->hasPendingActivity()) | 119 if ((*iter)->hasPendingActivity()) |
| 128 return true; | 120 return true; |
| 129 } | 121 } |
| 130 | 122 |
| 131 return false; | 123 return false; |
| 132 } | 124 } |
| 133 | 125 |
| 134 void ContextLifecycleNotifier::reportMemoryUsage(WTF::MemoryObjectInfo* memoryOb
jectInfo) const | 126 void ContextLifecycleNotifier::reportMemoryUsage(WTF::MemoryObjectInfo* memoryOb
jectInfo) const |
| 135 { | 127 { |
| 136 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); | 128 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); |
| 137 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 129 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
| 138 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) | 130 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) |
| 139 info.addMember(*iter, "activeDOMObject", WTF::RetainingPointer); | 131 info.addMember(*iter, "activeDOMObject", WTF::RetainingPointer); |
| 140 } | 132 } |
| 141 | 133 |
| 142 } // namespace WebCore | 134 } // namespace WebCore |
| 143 | 135 |
| OLD | NEW |