OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GIN_PER_CONTEXT_DATA_H_ | 5 #ifndef GIN_PER_CONTEXT_DATA_H_ |
6 #define GIN_PER_CONTEXT_DATA_H_ | 6 #define GIN_PER_CONTEXT_DATA_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "gin/gin_export.h" |
11 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
12 | 13 |
13 namespace gin { | 14 namespace gin { |
14 | 15 |
15 class Runner; | 16 class Runner; |
16 | 17 |
17 // Embedders can store additional per-context data by subclassing | 18 // Embedders can store additional per-context data by subclassing |
18 // ContextSupplement. | 19 // ContextSupplement. |
19 class ContextSupplement { | 20 class GIN_EXPORT ContextSupplement { |
20 public: | 21 public: |
21 ContextSupplement(); | 22 ContextSupplement(); |
22 virtual ~ContextSupplement(); | 23 virtual ~ContextSupplement(); |
23 | 24 |
24 // Detach will be called before ContextHolder disposes the v8::Context. | 25 // Detach will be called before ContextHolder disposes the v8::Context. |
25 // Embedders should not interact with |context| after Detach has been called. | 26 // Embedders should not interact with |context| after Detach has been called. |
26 virtual void Detach(v8::Handle<v8::Context> context) = 0; | 27 virtual void Detach(v8::Handle<v8::Context> context) = 0; |
27 | 28 |
28 private: | 29 private: |
29 DISALLOW_COPY_AND_ASSIGN(ContextSupplement); | 30 DISALLOW_COPY_AND_ASSIGN(ContextSupplement); |
30 }; | 31 }; |
31 | 32 |
32 // There is one instance of PerContextData per v8::Context managed by Gin. This | 33 // There is one instance of PerContextData per v8::Context managed by Gin. This |
33 // class stores all the Gin-related data that varies per context. | 34 // class stores all the Gin-related data that varies per context. |
34 class PerContextData { | 35 class GIN_EXPORT PerContextData { |
35 public: | 36 public: |
36 explicit PerContextData(v8::Handle<v8::Context> context); | 37 explicit PerContextData(v8::Handle<v8::Context> context); |
37 ~PerContextData(); | 38 ~PerContextData(); |
38 | 39 |
39 // Can return NULL after the ContextHolder has detached from context. | 40 // Can return NULL after the ContextHolder has detached from context. |
40 static PerContextData* From(v8::Handle<v8::Context>); | 41 static PerContextData* From(v8::Handle<v8::Context>); |
41 void Detach(v8::Handle<v8::Context> context); | 42 void Detach(v8::Handle<v8::Context> context); |
42 | 43 |
43 // The Runner associated with this context. To execute script in this context, | 44 // The Runner associated with this context. To execute script in this context, |
44 // please use the appropriate API on Runner. | 45 // please use the appropriate API on Runner. |
45 Runner* runner() const { return runner_; } | 46 Runner* runner() const { return runner_; } |
46 void set_runner(Runner* runner) { runner_ = runner; } | 47 void set_runner(Runner* runner) { runner_ = runner; } |
47 | 48 |
48 void AddSupplement(scoped_ptr<ContextSupplement> supplement); | 49 void AddSupplement(scoped_ptr<ContextSupplement> supplement); |
49 | 50 |
50 private: | 51 private: |
51 typedef ScopedVector<ContextSupplement> SuplementVector; | 52 typedef ScopedVector<ContextSupplement> SuplementVector; |
52 | 53 |
53 Runner* runner_; | 54 Runner* runner_; |
54 SuplementVector supplements_; | 55 SuplementVector supplements_; |
55 | 56 |
56 DISALLOW_COPY_AND_ASSIGN(PerContextData); | 57 DISALLOW_COPY_AND_ASSIGN(PerContextData); |
57 }; | 58 }; |
58 | 59 |
59 } // namespace gin | 60 } // namespace gin |
60 | 61 |
61 #endif // GIN_PER_CONTEXT_DATA_H_ | 62 #endif // GIN_PER_CONTEXT_DATA_H_ |
OLD | NEW |