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