blob: 0b4ba826d7f3206afdbb96a9afdfb9f5993fbc7d [file] [log] [blame]
Devlin Cronin9ff5b9c52017-12-06 23:18:211// 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/logging.h"
8#include "content/public/renderer/worker_thread.h"
9#include "extensions/renderer/script_context.h"
10#include "extensions/renderer/script_context_set.h"
11#include "extensions/renderer/worker_thread_dispatcher.h"
12
13namespace extensions {
14
15ScriptContext* GetScriptContextFromV8Context(v8::Local<v8::Context> context) {
16 ScriptContext* script_context =
17 content::WorkerThread::GetCurrentId() > 0
18 ? WorkerThreadDispatcher::GetScriptContext()
19 : ScriptContextSet::GetContextByV8Context(context);
20 DCHECK(!script_context || script_context->v8_context() == context);
21 return script_context;
22}
23
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