OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef NoEventDispatchAssertion_h | |
6 #define NoEventDispatchAssertion_h | |
7 | |
8 #include "wtf/MainThread.h" | |
9 #include "wtf/TemporaryChange.h" | |
10 | |
11 namespace blink { | |
12 | |
13 #if ENABLE(ASSERT) | |
14 | |
15 class NoEventDispatchAssertion { | |
16 public: | |
17 NoEventDispatchAssertion() | |
18 { | |
19 if (!isMainThread()) | |
20 return; | |
21 ++s_count; | |
22 } | |
23 | |
24 ~NoEventDispatchAssertion() | |
25 { | |
26 if (!isMainThread()) | |
27 return; | |
28 ASSERT(s_count); | |
29 --s_count; | |
30 } | |
31 | |
32 static bool isEventDispatchForbidden() | |
33 { | |
34 if (!isMainThread()) | |
35 return false; | |
36 return s_count; | |
37 } | |
38 | |
39 class AllowUserAgentEvents { | |
40 public: | |
41 AllowUserAgentEvents() | |
42 : m_change(s_count, 0) | |
43 { | |
44 } | |
45 | |
46 ~AllowUserAgentEvents() | |
47 { | |
48 ASSERT(!s_count); | |
49 } | |
50 | |
51 TemporaryChange<unsigned> m_change; | |
52 }; | |
53 | |
54 private: | |
55 static unsigned s_count; | |
56 }; | |
57 | |
58 #else | |
59 | |
60 class NoEventDispatchAssertion { | |
61 public: | |
62 NoEventDispatchAssertion() { } | |
63 | |
64 class AllowUserAgentEvents { | |
65 public: | |
66 AllowUserAgentEvents() { } | |
67 }; | |
68 }; | |
69 | |
70 #endif // ENABLE(ASSERT) | |
71 | |
72 } // namespace blink | |
73 | |
74 #endif // NoEventDispatchAssertion_h | |
OLD | NEW |