Devlin Cronin | 9ff5b9c5 | 2017-12-06 23:18:21 | [diff] [blame] | 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 | |
Hans Wennborg | 0997959 | 2020-04-27 12:34:30 | [diff] [blame] | 7 | #include "base/check.h" |
Devlin Cronin | 9ff5b9c5 | 2017-12-06 23:18:21 | [diff] [blame] | 8 | #include "extensions/renderer/script_context.h" |
| 9 | #include "extensions/renderer/script_context_set.h" |
| 10 | #include "extensions/renderer/worker_thread_dispatcher.h" |
Istiaque Ahmed | 82872ce | 2019-02-28 04:31:20 | [diff] [blame] | 11 | #include "extensions/renderer/worker_thread_util.h" |
Devlin Cronin | 9ff5b9c5 | 2017-12-06 23:18:21 | [diff] [blame] | 12 | |
| 13 | namespace extensions { |
| 14 | |
| 15 | ScriptContext* GetScriptContextFromV8Context(v8::Local<v8::Context> context) { |
| 16 | ScriptContext* script_context = |
Istiaque Ahmed | 82872ce | 2019-02-28 04:31:20 | [diff] [blame] | 17 | worker_thread_util::IsWorkerThread() |
Devlin Cronin | 9ff5b9c5 | 2017-12-06 23:18:21 | [diff] [blame] | 18 | ? WorkerThreadDispatcher::GetScriptContext() |
| 19 | : ScriptContextSet::GetContextByV8Context(context); |
| 20 | DCHECK(!script_context || script_context->v8_context() == context); |
| 21 | return script_context; |
| 22 | } |
| 23 | |
| 24 | ScriptContext* 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 |