summaryrefslogtreecommitdiff
path: root/chromium/extensions/renderer/get_script_context.cc
blob: 43efa7ee87df7870d378d678f9b767208fd0361b (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
// Copyright 2017 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 "extensions/renderer/get_script_context.h"

#include "base/check.h"
#include "extensions/renderer/script_context.h"
#include "extensions/renderer/script_context_set.h"
#include "extensions/renderer/worker_thread_dispatcher.h"
#include "extensions/renderer/worker_thread_util.h"

namespace extensions {

ScriptContext* GetScriptContextFromV8Context(v8::Local<v8::Context> context) {
  ScriptContext* script_context =
      worker_thread_util::IsWorkerThread()
          ? WorkerThreadDispatcher::GetScriptContext()
          : ScriptContextSet::GetContextByV8Context(context);
  DCHECK(!script_context || script_context->v8_context() == context);
  return script_context;
}

ScriptContext* GetScriptContextFromV8ContextChecked(
    v8::Local<v8::Context> context) {
  ScriptContext* script_context = GetScriptContextFromV8Context(context);
  CHECK(script_context);
  return script_context;
}

}  // namespace extensions