Chromium Code Reviews| Index: third_party/WebKit/Source/platform/ScriptForbiddenScope.h |
| diff --git a/third_party/WebKit/Source/platform/ScriptForbiddenScope.h b/third_party/WebKit/Source/platform/ScriptForbiddenScope.h |
| index 4a8e814454cab02ad9fdd6837175c59d9136d435..c8689e9b86c4bae7ccea7c4be307638a159a7bb1 100644 |
| --- a/third_party/WebKit/Source/platform/ScriptForbiddenScope.h |
| +++ b/third_party/WebKit/Source/platform/ScriptForbiddenScope.h |
| @@ -12,28 +12,49 @@ |
| namespace blink { |
| +static unsigned s_scriptForbiddenCount = 0; |
|
esprehn
2016/08/04 18:34:44
Hmm I didn't think this worked because it puts the
|
| + |
| // Scoped disabling of script execution on the main thread, |
| // and only to be used by the main thread. |
| class PLATFORM_EXPORT ScriptForbiddenScope final { |
| STACK_ALLOCATED(); |
| WTF_MAKE_NONCOPYABLE(ScriptForbiddenScope); |
| public: |
| - ScriptForbiddenScope(); |
| - ~ScriptForbiddenScope(); |
| + ScriptForbiddenScope() { enter(); } |
| + ~ScriptForbiddenScope() { exit(); } |
| class PLATFORM_EXPORT AllowUserAgentScript final { |
| STACK_ALLOCATED(); |
| WTF_MAKE_NONCOPYABLE(AllowUserAgentScript); |
| public: |
| - AllowUserAgentScript(); |
| - ~AllowUserAgentScript(); |
| + AllowUserAgentScript() |
| + { |
| + if (isMainThread()) |
| + m_change.emplace(&s_scriptForbiddenCount, 0); |
| + } |
| + ~AllowUserAgentScript() |
| + { |
| + DCHECK(!isMainThread() || !s_scriptForbiddenCount); |
| + } |
| + |
| private: |
| Optional<AutoReset<unsigned>> m_change; |
| }; |
| - static void enter(); |
| - static void exit(); |
| - static bool isScriptForbidden(); |
| + static void enter() |
| + { |
| + DCHECK(isMainThread()); |
| + ++s_scriptForbiddenCount; |
| + } |
| + static void exit() |
| + { |
| + DCHECK(s_scriptForbiddenCount); |
| + --s_scriptForbiddenCount; |
| + } |
| + static bool isScriptForbidden() |
| + { |
| + return isMainThread() && s_scriptForbiddenCount; |
| + } |
| }; |
| // Scoped disabling of script execution on the main thread, |
| @@ -47,8 +68,18 @@ class PLATFORM_EXPORT ScriptForbiddenIfMainThreadScope final { |
| STACK_ALLOCATED(); |
| WTF_MAKE_NONCOPYABLE(ScriptForbiddenIfMainThreadScope); |
| public: |
| - ScriptForbiddenIfMainThreadScope(); |
| - ~ScriptForbiddenIfMainThreadScope(); |
| + ScriptForbiddenIfMainThreadScope() |
| + { |
| + m_IsMainThread = isMainThread(); |
| + if (m_IsMainThread) |
| + ScriptForbiddenScope::enter(); |
| + } |
| + ~ScriptForbiddenIfMainThreadScope() |
| + { |
| + if (m_IsMainThread) |
| + ScriptForbiddenScope::exit(); |
| + } |
| + bool m_IsMainThread; |
| }; |
| } // namespace blink |