summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/dom/ScriptForbiddenScope.cpp
blob: 81540dcb6f3ea68c3cd0d9ca2190b87b46401610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"
#include "core/dom/ScriptForbiddenScope.h"

#include "wtf/Assertions.h"
#include "wtf/MainThread.h"

namespace WebCore {

#if ASSERT_ENABLED

static unsigned s_scriptForbiddenCount = 0;

ScriptForbiddenScope::ScriptForbiddenScope()
{
    ASSERT(isMainThread());
    ++s_scriptForbiddenCount;
}

ScriptForbiddenScope::~ScriptForbiddenScope()
{
    ASSERT(isMainThread());
    --s_scriptForbiddenCount;
}

bool ScriptForbiddenScope::isScriptForbidden()
{
    return isMainThread() && s_scriptForbiddenCount;
}

ScriptForbiddenScope::AllowUserAgentScript::AllowUserAgentScript()
    : m_change(s_scriptForbiddenCount, 0)
{
}

ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript()
{
    ASSERT(!s_scriptForbiddenCount);
}

#endif

} // namespace WebCore