OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "chrome/common/extensions/features/feature.h" | 11 #include "chrome/common/extensions/features/feature.h" |
12 #include "chrome/renderer/module_system.h" | 12 #include "chrome/renderer/module_system.h" |
13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
14 | 14 |
15 namespace WebKit { | 15 namespace WebKit { |
16 class WebFrame; | 16 class WebFrame; |
17 } | 17 } |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 class RenderView; | 20 class RenderView; |
21 } | 21 } |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
24 class Extension; | 24 class Extension; |
25 } | |
26 | 25 |
27 // Chrome's wrapper for a v8 context. | 26 // Chrome's wrapper for a v8 context. |
28 // | 27 // |
29 // TODO(aa): Consider converting this back to a set of bindings_utils. It would | 28 // TODO(aa): Consider converting this back to a set of bindings_utils. It would |
30 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then | 29 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then |
31 // we won't need this object and it's a bit less state to keep track of. | 30 // we won't need this object and it's a bit less state to keep track of. |
32 class ChromeV8Context { | 31 class ChromeV8Context { |
33 public: | 32 public: |
34 ChromeV8Context(v8::Handle<v8::Context> context, | 33 ChromeV8Context(v8::Handle<v8::Context> context, |
35 WebKit::WebFrame* frame, | 34 WebKit::WebFrame* frame, |
36 const extensions::Extension* extension, | 35 const Extension* extension, |
37 extensions::Feature::Context context_type); | 36 Feature::Context context_type); |
38 ~ChromeV8Context(); | 37 ~ChromeV8Context(); |
39 | 38 |
40 v8::Handle<v8::Context> v8_context() const { | 39 v8::Handle<v8::Context> v8_context() const { |
41 return v8_context_; | 40 return v8_context_; |
42 } | 41 } |
43 | 42 |
44 const extensions::Extension* extension() const { | 43 const Extension* extension() const { |
45 return extension_.get(); | 44 return extension_.get(); |
46 } | 45 } |
47 | 46 |
48 WebKit::WebFrame* web_frame() const { | 47 WebKit::WebFrame* web_frame() const { |
49 return web_frame_; | 48 return web_frame_; |
50 } | 49 } |
51 void clear_web_frame() { | 50 void clear_web_frame() { |
52 web_frame_ = NULL; | 51 web_frame_ = NULL; |
53 } | 52 } |
54 | 53 |
55 extensions::Feature::Context context_type() const { | 54 Feature::Context context_type() const { |
56 return context_type_; | 55 return context_type_; |
57 } | 56 } |
58 | 57 |
59 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 58 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
60 module_system_ = module_system.Pass(); | 59 module_system_ = module_system.Pass(); |
61 } | 60 } |
62 | 61 |
63 // Returns the ID of the extension associated with this context, or empty | 62 // Returns the ID of the extension associated with this context, or empty |
64 // string if there is no such extension. | 63 // string if there is no such extension. |
65 std::string GetExtensionID(); | 64 std::string GetExtensionID(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // since the DOM keeps the context alive, but it makes things simpler to not | 110 // since the DOM keeps the context alive, but it makes things simpler to not |
112 // distinguish the two cases. | 111 // distinguish the two cases. |
113 v8::Persistent<v8::Context> v8_context_; | 112 v8::Persistent<v8::Context> v8_context_; |
114 | 113 |
115 // The WebFrame associated with this context. This can be NULL because this | 114 // The WebFrame associated with this context. This can be NULL because this |
116 // object can outlive is destroyed asynchronously. | 115 // object can outlive is destroyed asynchronously. |
117 WebKit::WebFrame* web_frame_; | 116 WebKit::WebFrame* web_frame_; |
118 | 117 |
119 // The extension associated with this context, or NULL if there is none. This | 118 // The extension associated with this context, or NULL if there is none. This |
120 // might be a hosted app in the case that this context is hosting a web URL. | 119 // might be a hosted app in the case that this context is hosting a web URL. |
121 scoped_refptr<const extensions::Extension> extension_; | 120 scoped_refptr<const Extension> extension_; |
122 | 121 |
123 // The type of context. | 122 // The type of context. |
124 extensions::Feature::Context context_type_; | 123 Feature::Context context_type_; |
125 | 124 |
126 // Owns and structures the JS that is injected to set up extension bindings. | 125 // Owns and structures the JS that is injected to set up extension bindings. |
127 scoped_ptr<ModuleSystem> module_system_; | 126 scoped_ptr<ModuleSystem> module_system_; |
128 | 127 |
129 // The extension APIs available to this context. | 128 // The extension APIs available to this context. |
130 scoped_ptr<std::set<std::string> > available_extension_apis_; | 129 scoped_ptr<std::set<std::string> > available_extension_apis_; |
131 | 130 |
132 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 131 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
133 }; | 132 }; |
134 | 133 |
| 134 } // namespace extensions |
| 135 |
135 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 136 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
OLD | NEW |