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 "wtf/TemporaryChange.h" | 32 #include "wtf/TemporaryChange.h" |
32 | 33 |
33 namespace WebCore { | 34 namespace WebCore { |
34 | 35 |
35 ContextLifecycleNotifier::ContextLifecycleNotifier(ScriptExecutionContext* conte
xt) | 36 ContextLifecycleNotifier::ContextLifecycleNotifier(ScriptExecutionContext* conte
xt) |
36 : m_context(context) | 37 : LifecycleNotifier(context) |
37 , m_iterating(IteratingNone) | |
38 , m_inDestructor(false) | |
39 { | 38 { |
40 } | 39 } |
41 | 40 |
42 ContextLifecycleNotifier::~ContextLifecycleNotifier() | 41 ContextLifecycleNotifier::~ContextLifecycleNotifier() |
43 { | 42 { |
44 m_inDestructor = true; | |
45 for (ContextObserverSet::iterator iter = m_contextObservers.begin(); iter !=
m_contextObservers.end(); iter = m_contextObservers.begin()) { | |
46 ContextLifecycleObserver* observer = *iter; | |
47 m_contextObservers.remove(observer); | |
48 ASSERT(observer->scriptExecutionContext() == m_context); | |
49 observer->contextDestroyed(); | |
50 } | |
51 } | 43 } |
52 | 44 |
53 void ContextLifecycleNotifier::addObserver(ContextLifecycleObserver* observer, C
ontextLifecycleObserver::Type as) | 45 void ContextLifecycleNotifier::addObserver(LifecycleObserver* observer, Lifecycl
eObserver::Type type) |
54 { | 46 { |
55 RELEASE_ASSERT(!m_inDestructor); | 47 LifecycleNotifier::addObserver(observer, type); |
| 48 |
56 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); | 49 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); |
57 m_contextObservers.add(observer); | 50 if (type == LifecycleObserver::ActiveDOMObjectType) { |
58 if (as == ContextLifecycleObserver::ActiveDOMObjectType) { | |
59 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); | 51 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); |
60 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); | 52 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); |
61 } | 53 } |
62 } | 54 } |
63 | 55 |
64 void ContextLifecycleNotifier::removeObserver(ContextLifecycleObserver* observer
, ContextLifecycleObserver::Type as) | 56 void ContextLifecycleNotifier::removeObserver(LifecycleObserver* observer, Lifec
ycleObserver::Type type) |
65 { | 57 { |
66 RELEASE_ASSERT(!m_inDestructor); | 58 LifecycleNotifier::removeObserver(observer, type); |
| 59 |
67 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); | 60 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); |
68 m_contextObservers.remove(observer); | 61 if (type == LifecycleObserver::ActiveDOMObjectType) { |
69 if (as == ContextLifecycleObserver::ActiveDOMObjectType) { | |
70 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); | 62 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects); |
71 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); | 63 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); |
72 } | 64 } |
73 } | 65 } |
74 | 66 |
75 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() | 67 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() |
76 { | 68 { |
77 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 69 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
78 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 70 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
79 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { | 71 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { |
80 ASSERT((*iter)->scriptExecutionContext() == m_context); | 72 ASSERT((*iter)->scriptExecutionContext() == context()); |
81 ASSERT((*iter)->suspendIfNeededCalled()); | 73 ASSERT((*iter)->suspendIfNeededCalled()); |
82 (*iter)->resume(); | 74 (*iter)->resume(); |
83 } | 75 } |
84 } | 76 } |
85 | 77 |
86 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects(ActiveDOMObject:
:ReasonForSuspension why) | 78 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects(ActiveDOMObject:
:ReasonForSuspension why) |
87 { | 79 { |
88 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 80 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
89 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 81 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
90 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { | 82 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { |
91 ASSERT((*iter)->scriptExecutionContext() == m_context); | 83 ASSERT((*iter)->scriptExecutionContext() == context()); |
92 ASSERT((*iter)->suspendIfNeededCalled()); | 84 ASSERT((*iter)->suspendIfNeededCalled()); |
93 (*iter)->suspend(why); | 85 (*iter)->suspend(why); |
94 } | 86 } |
95 } | 87 } |
96 | 88 |
97 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 89 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
98 { | 90 { |
99 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 91 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
100 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 92 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
101 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { | 93 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter !=
activeObjectsEnd; ++iter) { |
102 ASSERT((*iter)->scriptExecutionContext() == m_context); | 94 ASSERT((*iter)->scriptExecutionContext() == context()); |
103 ASSERT((*iter)->suspendIfNeededCalled()); | 95 ASSERT((*iter)->suspendIfNeededCalled()); |
104 (*iter)->stop(); | 96 (*iter)->stop(); |
105 } | 97 } |
106 } | 98 } |
107 | 99 |
108 bool ContextLifecycleNotifier::canSuspendActiveDOMObjects() | 100 bool ContextLifecycleNotifier::canSuspendActiveDOMObjects() |
109 { | 101 { |
110 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); | 102 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD
OMObjects); |
111 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); | 103 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); |
112 for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); i
ter != activeObjectsEnd; ++iter) { | 104 for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); i
ter != activeObjectsEnd; ++iter) { |
113 ASSERT((*iter)->scriptExecutionContext() == m_context); | 105 ASSERT((*iter)->scriptExecutionContext() == context()); |
114 ASSERT((*iter)->suspendIfNeededCalled()); | 106 ASSERT((*iter)->suspendIfNeededCalled()); |
115 if (!(*iter)->canSuspend()) | 107 if (!(*iter)->canSuspend()) |
116 return false; | 108 return false; |
117 } | 109 } |
118 | 110 |
119 return true; | 111 return true; |
120 } | 112 } |
121 | 113 |
122 bool ContextLifecycleNotifier::hasPendingActivity() const | 114 bool ContextLifecycleNotifier::hasPendingActivity() const |
123 { | 115 { |
124 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end
(); | 116 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end
(); |
125 for (ActiveDOMObjectSet::const_iterator iter = activeDOMObjects().begin(); i
ter != activeObjectsEnd; ++iter) { | 117 for (ActiveDOMObjectSet::const_iterator iter = activeDOMObjects().begin(); i
ter != activeObjectsEnd; ++iter) { |
126 if ((*iter)->hasPendingActivity()) | 118 if ((*iter)->hasPendingActivity()) |
127 return true; | 119 return true; |
128 } | 120 } |
129 | 121 |
130 return false; | 122 return false; |
131 } | 123 } |
132 | 124 |
133 } // namespace WebCore | 125 } // namespace WebCore |
134 | 126 |
OLD | NEW |