abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 1 | // Copyright 2013 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 | #ifndef GIN_PER_CONTEXT_DATA_H_ |
| 6 | #define GIN_PER_CONTEXT_DATA_H_ |
| 7 | |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 8 | #include "base/basictypes.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" |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 11 | #include "v8/include/v8.h" |
| 12 | |
| 13 | namespace gin { |
| 14 | |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 15 | class Runner; |
| 16 | |
abarth@chromium.org | 60531d5 | 2013-11-27 02:10:15 | [diff] [blame] | 17 | // 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^] | 18 | // class stores all the Gin-related data that varies per context. Arbitrary data |
| 19 | // can be associated with this class by way of the SupportsUserData methods. |
| 20 | // Instances of this class (and any associated user data) are destroyed before |
| 21 | // the associated v8::Context. |
| 22 | class GIN_EXPORT PerContextData : public base::SupportsUserData { |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 23 | public: |
| 24 | explicit PerContextData(v8::Handle<v8::Context> context); |
sky@chromium.org | f2eec2ec | 2014-02-28 15:26:49 | [diff] [blame^] | 25 | virtual ~PerContextData(); |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 26 | |
| 27 | // Can return NULL after the ContextHolder has detached from context. |
sky@chromium.org | f2eec2ec | 2014-02-28 15:26:49 | [diff] [blame^] | 28 | static PerContextData* From(v8::Handle<v8::Context> context); |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 29 | |
abarth@chromium.org | 60531d5 | 2013-11-27 02:10:15 | [diff] [blame] | 30 | // The Runner associated with this context. To execute script in this context, |
| 31 | // please use the appropriate API on Runner. |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 32 | Runner* runner() const { return runner_; } |
abarth@chromium.org | 60531d5 | 2013-11-27 02:10:15 | [diff] [blame] | 33 | void set_runner(Runner* runner) { runner_ = runner; } |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 34 | |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 35 | private: |
abarth@chromium.org | 0d72f00 | 2013-11-25 02:19:34 | [diff] [blame] | 36 | Runner* runner_; |
abarth@chromium.org | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(PerContextData); |
| 39 | }; |
| 40 | |
| 41 | } // namespace gin |
| 42 | |
| 43 | #endif // GIN_PER_CONTEXT_DATA_H_ |