Avi Drissman | 468e51b6 | 2022-09-13 20:47:01 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 2 | // 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 Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 8 | #include "base/memory/raw_ptr.h" |
sky@chromium.org | f2eec2ec | 2014-02-28 15:26:49 | [diff] [blame] | 9 | #include "base/supports_user_data.h" |
jochen@chromium.org | 48c2163 | 2013-12-12 21:32:34 | [diff] [blame] | 10 | #include "gin/gin_export.h" |
Dan Elphick | 05acd60 | 2021-08-30 15:22:07 | [diff] [blame] | 11 | #include "v8/include/v8-forward.h" |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 12 | |
| 13 | namespace gin { |
| 14 | |
sky@chromium.org | 7f12ca7 | 2014-02-28 22:11:53 | [diff] [blame] | 15 | class ContextHolder; |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 16 | class Runner; |
| 17 | |
abarth@chromium.org | 60531d5 | 2013-11-27 02:10:15 | [diff] [blame] | 18 | // There is one instance of PerContextData per v8::Context managed by Gin. This |
sky@chromium.org | f2eec2ec | 2014-02-28 15:26:49 | [diff] [blame] | 19 | // 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. |
| 23 | class GIN_EXPORT PerContextData : public base::SupportsUserData { |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 24 | public: |
sky@chromium.org | 7f12ca7 | 2014-02-28 22:11:53 | [diff] [blame] | 25 | PerContextData(ContextHolder* context_holder, |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 26 | v8::Local<v8::Context> context); |
Daniel Hosseinian | 68c0798d | 2021-04-16 08:16:07 | [diff] [blame] | 27 | PerContextData(const PerContextData&) = delete; |
| 28 | PerContextData& operator=(const PerContextData&) = delete; |
dcheng | 074c039 | 2014-10-23 19:08:25 | [diff] [blame] | 29 | ~PerContextData() override; |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 30 | |
| 31 | // Can return NULL after the ContextHolder has detached from context. |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame] | 32 | static PerContextData* From(v8::Local<v8::Context> context); |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 33 | |
abarth@chromium.org | 60531d5 | 2013-11-27 02:10:15 | [diff] [blame] | 34 | // The Runner associated with this context. To execute script in this context, |
| 35 | // please use the appropriate API on Runner. |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 36 | Runner* runner() const { return runner_; } |
abarth@chromium.org | 60531d5 | 2013-11-27 02:10:15 | [diff] [blame] | 37 | void set_runner(Runner* runner) { runner_ = runner; } |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 38 | |
sky@chromium.org | 7f12ca7 | 2014-02-28 22:11:53 | [diff] [blame] | 39 | ContextHolder* context_holder() { return context_holder_; } |
| 40 | |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 41 | private: |
Ali Hijazi | 96b8478 | 2023-01-25 14:03:12 | [diff] [blame] | 42 | raw_ptr<ContextHolder, DanglingUntriaged> context_holder_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 43 | raw_ptr<Runner> runner_; |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | } // namespace gin |
| 47 | |
| 48 | #endif // GIN_PER_CONTEXT_DATA_H_ |