1 // Copyright 2017 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 "extensions/renderer/get_script_context.h" 6 7 #include "base/check.h" 8 #include "extensions/renderer/script_context.h" 9 #include "extensions/renderer/script_context_set.h" 10 #include "extensions/renderer/worker_thread_dispatcher.h" 11 #include "extensions/renderer/worker_thread_util.h" 12 13 namespace extensions { 14 GetScriptContextFromV8Context(v8::Local<v8::Context> context)15ScriptContext* GetScriptContextFromV8Context(v8::Local<v8::Context> context) { 16 ScriptContext* script_context = 17 worker_thread_util::IsWorkerThread() 18 ? WorkerThreadDispatcher::GetScriptContext() 19 : ScriptContextSet::GetContextByV8Context(context); 20 DCHECK(!script_context || script_context->v8_context() == context); 21 return script_context; 22 } 23 GetScriptContextFromV8ContextChecked(v8::Local<v8::Context> context)24ScriptContext* GetScriptContextFromV8ContextChecked( 25 v8::Local<v8::Context> context) { 26 ScriptContext* script_context = GetScriptContextFromV8Context(context); 27 CHECK(script_context); 28 return script_context; 29 } 30 31 } // namespace extensions 32