| 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 #include "platform/ScriptForbiddenScope.h" | 5 #include "platform/ScriptForbiddenScope.h" |
| 6 | 6 |
| 7 #include "wtf/Assertions.h" | 7 #include "wtf/Assertions.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 static unsigned s_scriptForbiddenCount = 0; | 11 unsigned ScriptForbiddenScope::s_scriptForbiddenCount = 0; |
| 12 | 12 |
| 13 ScriptForbiddenScope::ScriptForbiddenScope() | |
| 14 { | |
| 15 enter(); | |
| 16 } | |
| 17 | |
| 18 ScriptForbiddenScope::~ScriptForbiddenScope() | |
| 19 { | |
| 20 exit(); | |
| 21 } | |
| 22 | |
| 23 void ScriptForbiddenScope::enter() | |
| 24 { | |
| 25 ASSERT(isMainThread()); | |
| 26 ++s_scriptForbiddenCount; | |
| 27 } | |
| 28 | |
| 29 void ScriptForbiddenScope::exit() | |
| 30 { | |
| 31 ASSERT(isMainThread()); | |
| 32 ASSERT(s_scriptForbiddenCount); | |
| 33 --s_scriptForbiddenCount; | |
| 34 } | |
| 35 | |
| 36 bool ScriptForbiddenScope::isScriptForbidden() | |
| 37 { | |
| 38 return isMainThread() && s_scriptForbiddenCount; | |
| 39 } | |
| 40 | |
| 41 ScriptForbiddenScope::AllowUserAgentScript::AllowUserAgentScript() | |
| 42 { | |
| 43 if (isMainThread()) | |
| 44 m_change.emplace(&s_scriptForbiddenCount, 0); | |
| 45 } | |
| 46 | |
| 47 ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript() | |
| 48 { | |
| 49 ASSERT(!isMainThread() || !s_scriptForbiddenCount); | |
| 50 } | |
| 51 | |
| 52 ScriptForbiddenIfMainThreadScope::ScriptForbiddenIfMainThreadScope() | |
| 53 { | |
| 54 if (isMainThread()) | |
| 55 ScriptForbiddenScope::enter(); | |
| 56 } | |
| 57 | |
| 58 ScriptForbiddenIfMainThreadScope::~ScriptForbiddenIfMainThreadScope() | |
| 59 { | |
| 60 if (isMainThread()) | |
| 61 ScriptForbiddenScope::exit(); | |
| 62 } | |
| 63 } // namespace blink | 13 } // namespace blink |
| OLD | NEW |