Chromium Code Reviews| 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" |
|
sof
2016/12/07 08:02:18
unused
| |
| 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 | 17 |
| 18 public: | 18 public: |
| 19 explicit ScopedWindowFocusAllowedIndicator(ExecutionContext* executionContext) | 19 explicit ScopedWindowFocusAllowedIndicator(ExecutionContext* executionContext) |
| 20 : m_observer(new Observer(executionContext)) {} | 20 : m_executionContext(executionContext) { |
| 21 ~ScopedWindowFocusAllowedIndicator() { m_observer->dispose(); } | 21 executionContext->allowWindowInteraction(); |
| 22 } | |
| 23 ~ScopedWindowFocusAllowedIndicator() { | |
| 24 m_executionContext->consumeWindowInteraction(); | |
| 25 } | |
| 22 | 26 |
| 23 private: | 27 private: |
| 24 class Observer final : public GarbageCollected<Observer>, | 28 // This doesn't create a cycle because ScopedWindowFocusAllowedIndicator |
| 25 public ContextLifecycleObserver { | 29 // is used only on a machine stack. |
|
haraken
2016/12/07 07:49:17
But we cannot use STACK_ALLOCATED because the obje
sof
2016/12/07 08:02:18
Having a Persistent<ExecutionContext> is scary (wr
| |
| 26 USING_GARBAGE_COLLECTED_MIXIN(Observer); | 30 Persistent<ExecutionContext> m_executionContext; |
| 27 | |
| 28 public: | |
| 29 explicit Observer(ExecutionContext* executionContext) | |
| 30 : ContextLifecycleObserver(executionContext) { | |
| 31 if (executionContext) | |
| 32 executionContext->allowWindowInteraction(); | |
| 33 } | |
| 34 | |
| 35 void dispose() { | |
| 36 if (getExecutionContext()) | |
| 37 getExecutionContext()->consumeWindowInteraction(); | |
| 38 } | |
| 39 }; | |
| 40 | |
| 41 // In Oilpan, destructors are not allowed to touch other on-heap objects. | |
| 42 // The Observer indirection is needed to keep | |
| 43 // ScopedWindowFocusAllowedIndicator off-heap and thus allows its destructor | |
| 44 // to call getExecutionContext()->consumeWindowInteraction(). | |
|
haraken
2016/12/07 07:49:17
I don't understand this comment. The observer indi
sof
2016/12/07 08:02:18
We need(ed) to inject an on-heap ContextLifecycleO
| |
| 45 Persistent<Observer> m_observer; | |
| 46 }; | 31 }; |
| 47 | 32 |
| 48 } // namespace blink | 33 } // namespace blink |
| 49 | 34 |
| 50 #endif // ScopedWindowFocusAllowedIndicator_h | 35 #endif // ScopedWindowFocusAllowedIndicator_h |
| OLD | NEW |