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 #ifndef ContextLifecycleNotifier_h | 27 #ifndef ContextLifecycleNotifier_h |
28 #define ContextLifecycleNotifier_h | 28 #define ContextLifecycleNotifier_h |
29 | 29 |
30 #include "core/dom/ActiveDOMObject.h" | 30 #include "core/dom/ActiveDOMObject.h" |
| 31 #include "core/platform/LifecycleNotifier.h" |
31 #include "wtf/HashSet.h" | 32 #include "wtf/HashSet.h" |
32 #include "wtf/PassOwnPtr.h" | 33 #include "wtf/PassOwnPtr.h" |
33 | 34 |
34 namespace WebCore { | 35 namespace WebCore { |
35 | 36 |
36 class ActiveDOMObject; | 37 class ActiveDOMObject; |
37 class ContextLifecycleObserver; | 38 class ContextLifecycleObserver; |
38 class ScriptExecutionContext; | 39 class ScriptExecutionContext; |
39 | 40 |
40 class ContextLifecycleNotifier { | 41 class ContextLifecycleNotifier : public LifecycleNotifier { |
41 public: | 42 public: |
42 static PassOwnPtr<ContextLifecycleNotifier> create(ScriptExecutionContext*); | 43 static PassOwnPtr<ContextLifecycleNotifier> create(ScriptExecutionContext*); |
43 | 44 |
44 virtual ~ContextLifecycleNotifier(); | 45 virtual ~ContextLifecycleNotifier(); |
45 | 46 |
46 typedef HashSet<ContextLifecycleObserver*> ContextObserverSet; | |
47 typedef HashSet<ActiveDOMObject*> ActiveDOMObjectSet; | 47 typedef HashSet<ActiveDOMObject*> ActiveDOMObjectSet; |
48 | 48 |
49 const ActiveDOMObjectSet& activeDOMObjects() const { return m_activeDOMObjec
ts; } | 49 const ActiveDOMObjectSet& activeDOMObjects() const { return m_activeDOMObjec
ts; } |
50 | 50 |
51 virtual void addObserver(ContextLifecycleObserver*, ContextLifecycleObserver
::Type as); | 51 virtual void addObserver(LifecycleObserver*, LifecycleObserver::Type) OVERRI
DE; |
52 virtual void removeObserver(ContextLifecycleObserver*, ContextLifecycleObser
ver::Type as); | 52 virtual void removeObserver(LifecycleObserver*, LifecycleObserver::Type) OVE
RRIDE; |
53 | 53 |
54 void notifyResumingActiveDOMObjects(); | 54 void notifyResumingActiveDOMObjects(); |
55 void notifySuspendingActiveDOMObjects(ActiveDOMObject::ReasonForSuspension); | 55 void notifySuspendingActiveDOMObjects(ActiveDOMObject::ReasonForSuspension); |
56 void notifyStoppingActiveDOMObjects(); | 56 void notifyStoppingActiveDOMObjects(); |
57 | 57 |
58 bool contains(ActiveDOMObject* object) const { return m_activeDOMObjects.con
tains(object); } | 58 bool contains(ActiveDOMObject* object) const { return m_activeDOMObjects.con
tains(object); } |
59 bool canSuspendActiveDOMObjects(); | 59 bool canSuspendActiveDOMObjects(); |
60 bool hasPendingActivity() const; | 60 bool hasPendingActivity() const; |
61 | 61 |
62 protected: | 62 protected: |
63 explicit ContextLifecycleNotifier(ScriptExecutionContext*); | 63 explicit ContextLifecycleNotifier(ScriptExecutionContext*); |
64 | 64 |
65 enum IterationType { | |
66 IteratingNone, | |
67 IteratingOverActiveDOMObjects, | |
68 IteratingOverContextObservers, | |
69 IteratingOverDocumentObservers | |
70 }; | |
71 | |
72 IterationType m_iterating; | |
73 | |
74 private: | 65 private: |
75 ScriptExecutionContext* m_context; | |
76 ContextObserverSet m_contextObservers; | |
77 ActiveDOMObjectSet m_activeDOMObjects; | 66 ActiveDOMObjectSet m_activeDOMObjects; |
78 bool m_inDestructor; | |
79 }; | 67 }; |
80 | 68 |
81 inline PassOwnPtr<ContextLifecycleNotifier> ContextLifecycleNotifier::create(Scr
iptExecutionContext* context) | 69 inline PassOwnPtr<ContextLifecycleNotifier> ContextLifecycleNotifier::create(Scr
iptExecutionContext* context) |
82 { | 70 { |
83 return adoptPtr(new ContextLifecycleNotifier(context)); | 71 return adoptPtr(new ContextLifecycleNotifier(context)); |
84 } | 72 } |
85 | 73 |
86 } // namespace WebCore | 74 } // namespace WebCore |
87 | 75 |
88 #endif // ContextLifecycleNotifier_h | 76 #endif // ContextLifecycleNotifier_h |
89 | |
OLD | NEW |