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
3 // found in the LICENSE file.
5 #ifndef ScopedWindowFocusAllowedIndicator_h
6 #define ScopedWindowFocusAllowedIndicator_h
8 #include "core/dom/ContextLifecycleObserver.h"
9 #include "core/dom/ExecutionContext.h"
10 #include "wtf/Noncopyable.h"
14 class ScopedWindowFocusAllowedIndicator final
{
15 WTF_MAKE_FAST_ALLOCATED(ScopedWindowFocusAllowedIndicator
);
16 WTF_MAKE_NONCOPYABLE(ScopedWindowFocusAllowedIndicator
);
18 explicit ScopedWindowFocusAllowedIndicator(ExecutionContext
* executionContext
)
19 : m_observer(adoptPtrWillBeNoop(new Observer(executionContext
)))
22 ~ScopedWindowFocusAllowedIndicator()
24 m_observer
->dispose();
28 class Observer final
: public NoBaseWillBeGarbageCollectedFinalized
<Observer
>, public ContextLifecycleObserver
{
29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Observer
);
31 explicit Observer(ExecutionContext
* executionContext
)
32 : ContextLifecycleObserver(executionContext
)
35 executionContext
->allowWindowInteraction();
40 if (executionContext())
41 executionContext()->consumeWindowInteraction();
46 ContextLifecycleObserver::trace(visitor
);
50 // In Oilpan, destructors are not allowed to touch other on-heap objects.
51 // The Observer indirection is needed to keep
52 // ScopedWindowFocusAllowedIndicator off-heap and thus allows its destructor
53 // to call executionContext()->consumeWindowInteraction().
54 OwnPtrWillBePersistent
<Observer
> m_observer
;
59 #endif // ScopedWindowFocusAllowedIndicator_h