[go: nahoru, domu]

blob: 6c6b8dcd6109451465cbe04f44d965a66870fda5 [file] [log] [blame]
Avi Drissman468e51b62022-09-13 20:47:011// Copyright 2013 The Chromium Authors
abarth@chromium.org97f21ca2013-11-17 17:46:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef GIN_PER_CONTEXT_DATA_H_
6#define GIN_PER_CONTEXT_DATA_H_
7
Keishi Hattori0e45c022021-11-27 09:25:528#include "base/memory/raw_ptr.h"
sky@chromium.orgf2eec2ec2014-02-28 15:26:499#include "base/supports_user_data.h"
jochen@chromium.org48c21632013-12-12 21:32:3410#include "gin/gin_export.h"
Dan Elphick05acd602021-08-30 15:22:0711#include "v8/include/v8-forward.h"
abarth@chromium.org97f21ca2013-11-17 17:46:0712
13namespace gin {
14
sky@chromium.org7f12ca72014-02-28 22:11:5315class ContextHolder;
abarth@chromium.org0d72f002013-11-25 02:19:3416class Runner;
17
abarth@chromium.org60531d52013-11-27 02:10:1518// There is one instance of PerContextData per v8::Context managed by Gin. This
sky@chromium.orgf2eec2ec2014-02-28 15:26:4919// class stores all the Gin-related data that varies per context. Arbitrary data
20// can be associated with this class by way of the SupportsUserData methods.
21// Instances of this class (and any associated user data) are destroyed before
22// the associated v8::Context.
23class GIN_EXPORT PerContextData : public base::SupportsUserData {
abarth@chromium.org97f21ca2013-11-17 17:46:0724 public:
sky@chromium.org7f12ca72014-02-28 22:11:5325 PerContextData(ContextHolder* context_holder,
deepak.sfaaa1b62015-04-30 07:30:4826 v8::Local<v8::Context> context);
Daniel Hosseinian68c0798d2021-04-16 08:16:0727 PerContextData(const PerContextData&) = delete;
28 PerContextData& operator=(const PerContextData&) = delete;
dcheng074c0392014-10-23 19:08:2529 ~PerContextData() override;
abarth@chromium.org97f21ca2013-11-17 17:46:0730
31 // Can return NULL after the ContextHolder has detached from context.
deepak.sfaaa1b62015-04-30 07:30:4832 static PerContextData* From(v8::Local<v8::Context> context);
abarth@chromium.org97f21ca2013-11-17 17:46:0733
abarth@chromium.org60531d52013-11-27 02:10:1534 // The Runner associated with this context. To execute script in this context,
35 // please use the appropriate API on Runner.
abarth@chromium.org0d72f002013-11-25 02:19:3436 Runner* runner() const { return runner_; }
abarth@chromium.org60531d52013-11-27 02:10:1537 void set_runner(Runner* runner) { runner_ = runner; }
abarth@chromium.org0d72f002013-11-25 02:19:3438
sky@chromium.org7f12ca72014-02-28 22:11:5339 ContextHolder* context_holder() { return context_holder_; }
40
abarth@chromium.org97f21ca2013-11-17 17:46:0741 private:
Ali Hijazi96b84782023-01-25 14:03:1242 raw_ptr<ContextHolder, DanglingUntriaged> context_holder_;
Keishi Hattori0e45c022021-11-27 09:25:5243 raw_ptr<Runner> runner_;
abarth@chromium.org97f21ca2013-11-17 17:46:0744};
45
46} // namespace gin
47
48#endif // GIN_PER_CONTEXT_DATA_H_