OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ScopedWindowFocusAllowedIndicator_h | 5 #ifndef ScopedWindowFocusAllowedIndicator_h |
6 #define ScopedWindowFocusAllowedIndicator_h | 6 #define ScopedWindowFocusAllowedIndicator_h |
7 | 7 |
8 #include "core/dom/ContextLifecycleObserver.h" | 8 #include "core/dom/ContextLifecycleObserver.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class ScopedWindowFocusAllowedIndicator final { | 14 class ScopedWindowFocusAllowedIndicator final { |
15 USING_FAST_MALLOC(ScopedWindowFocusAllowedIndicator); | 15 USING_FAST_MALLOC(ScopedWindowFocusAllowedIndicator); |
16 WTF_MAKE_NONCOPYABLE(ScopedWindowFocusAllowedIndicator); | 16 WTF_MAKE_NONCOPYABLE(ScopedWindowFocusAllowedIndicator); |
17 public: | 17 public: |
18 explicit ScopedWindowFocusAllowedIndicator(ExecutionContext* executionContex
t) | 18 explicit ScopedWindowFocusAllowedIndicator(ExecutionContext* executionContex
t) |
19 : m_observer(new Observer(executionContext)) | 19 : m_observer(new Observer(executionContext)) |
20 { | 20 { |
21 } | 21 } |
22 ~ScopedWindowFocusAllowedIndicator() | 22 ~ScopedWindowFocusAllowedIndicator() |
23 { | 23 { |
24 m_observer->dispose(); | 24 m_observer->dispose(); |
25 } | 25 } |
26 | 26 |
27 private: | 27 private: |
28 class Observer final : public GarbageCollected<Observer>, public ContextLife
cycleObserver { | 28 class Observer final : public GarbageCollectedFinalized<Observer>, public Co
ntextLifecycleObserver { |
29 USING_GARBAGE_COLLECTED_MIXIN(Observer); | 29 USING_GARBAGE_COLLECTED_MIXIN(Observer); |
30 public: | 30 public: |
31 explicit Observer(ExecutionContext* executionContext) | 31 explicit Observer(ExecutionContext* executionContext) |
32 : ContextLifecycleObserver(executionContext) | 32 : ContextLifecycleObserver(executionContext) |
33 { | 33 { |
34 if (executionContext) | 34 if (executionContext) |
35 executionContext->allowWindowInteraction(); | 35 executionContext->allowWindowInteraction(); |
36 } | 36 } |
37 | 37 |
38 void dispose() | 38 void dispose() |
39 { | 39 { |
40 if (getExecutionContext()) | 40 if (getExecutionContext()) |
41 getExecutionContext()->consumeWindowInteraction(); | 41 getExecutionContext()->consumeWindowInteraction(); |
42 } | 42 } |
| 43 |
| 44 DEFINE_INLINE_TRACE() |
| 45 { |
| 46 ContextLifecycleObserver::trace(visitor); |
| 47 } |
43 }; | 48 }; |
44 | 49 |
45 // In Oilpan, destructors are not allowed to touch other on-heap objects. | 50 // In Oilpan, destructors are not allowed to touch other on-heap objects. |
46 // The Observer indirection is needed to keep | 51 // The Observer indirection is needed to keep |
47 // ScopedWindowFocusAllowedIndicator off-heap and thus allows its destructor | 52 // ScopedWindowFocusAllowedIndicator off-heap and thus allows its destructor |
48 // to call getExecutionContext()->consumeWindowInteraction(). | 53 // to call getExecutionContext()->consumeWindowInteraction(). |
49 Persistent<Observer> m_observer; | 54 Persistent<Observer> m_observer; |
50 }; | 55 }; |
51 | 56 |
52 } // namespace blink | 57 } // namespace blink |
53 | 58 |
54 #endif // ScopedWindowFocusAllowedIndicator_h | 59 #endif // ScopedWindowFocusAllowedIndicator_h |
OLD | NEW |