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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then | 29 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then |
30 // 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. |
31 class ChromeV8Context { | 31 class ChromeV8Context { |
32 public: | 32 public: |
33 ChromeV8Context(v8::Handle<v8::Context> context, | 33 ChromeV8Context(v8::Handle<v8::Context> context, |
34 WebKit::WebFrame* frame, | 34 WebKit::WebFrame* frame, |
35 const Extension* extension, | 35 const Extension* extension, |
36 Feature::Context context_type); | 36 Feature::Context context_type); |
37 ~ChromeV8Context(); | 37 ~ChromeV8Context(); |
38 | 38 |
| 39 // Clears the WebFrame for this contexts and invalidates the associated |
| 40 // ModuleSystem. |
| 41 void Invalidate(); |
| 42 |
39 v8::Handle<v8::Context> v8_context() const { | 43 v8::Handle<v8::Context> v8_context() const { |
40 return v8_context_; | 44 return v8_context_; |
41 } | 45 } |
42 | 46 |
43 const Extension* extension() const { | 47 const Extension* extension() const { |
44 return extension_.get(); | 48 return extension_.get(); |
45 } | 49 } |
46 | 50 |
47 WebKit::WebFrame* web_frame() const { | 51 WebKit::WebFrame* web_frame() const { |
48 return web_frame_; | 52 return web_frame_; |
49 } | 53 } |
50 void clear_web_frame() { | |
51 web_frame_ = NULL; | |
52 } | |
53 | 54 |
54 Feature::Context context_type() const { | 55 Feature::Context context_type() const { |
55 return context_type_; | 56 return context_type_; |
56 } | 57 } |
57 | 58 |
58 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 59 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
59 module_system_ = module_system.Pass(); | 60 module_system_ = module_system.Pass(); |
60 } | 61 } |
61 | 62 |
62 ModuleSystem* module_system() { return module_system_.get(); } | 63 ModuleSystem* module_system() { return module_system_.get(); } |
(...skipping 30 matching lines...) Expand all Loading... |
93 bool CallChromeHiddenMethod( | 94 bool CallChromeHiddenMethod( |
94 const std::string& function_name, | 95 const std::string& function_name, |
95 int argc, | 96 int argc, |
96 v8::Handle<v8::Value>* argv, | 97 v8::Handle<v8::Value>* argv, |
97 v8::Handle<v8::Value>* result) const; | 98 v8::Handle<v8::Value>* result) const; |
98 | 99 |
99 // Returns the set of extension APIs that are available to this context. If no | 100 // Returns the set of extension APIs that are available to this context. If no |
100 // APIs are available, returns an empty set. | 101 // APIs are available, returns an empty set. |
101 const std::set<std::string>& GetAvailableExtensionAPIs(); | 102 const std::set<std::string>& GetAvailableExtensionAPIs(); |
102 | 103 |
| 104 Feature::Availability GetAvailability(const std::string& api_name); |
| 105 |
103 // Returns a string description of the type of context this is. | 106 // Returns a string description of the type of context this is. |
104 std::string GetContextTypeDescription(); | 107 std::string GetContextTypeDescription(); |
105 | 108 |
106 private: | 109 private: |
107 // The v8 context the bindings are accessible to. We keep a strong reference | 110 // The v8 context the bindings are accessible to. We keep a strong reference |
108 // to it for simplicity. In the case of content scripts, this is necessary | 111 // to it for simplicity. In the case of content scripts, this is necessary |
109 // because we want all scripts from the same extension for the same frame to | 112 // because we want all scripts from the same extension for the same frame to |
110 // run in the same context, so we can't have the contexts being GC'd if | 113 // run in the same context, so we can't have the contexts being GC'd if |
111 // nothing is happening. In the case of page contexts, this isn't necessary | 114 // nothing is happening. In the case of page contexts, this isn't necessary |
112 // since the DOM keeps the context alive, but it makes things simpler to not | 115 // since the DOM keeps the context alive, but it makes things simpler to not |
113 // distinguish the two cases. | 116 // distinguish the two cases. |
114 v8::Persistent<v8::Context> v8_context_; | 117 v8::Persistent<v8::Context> v8_context_; |
115 | 118 |
116 // The WebFrame associated with this context. This can be NULL because this | 119 // The WebFrame associated with this context. This can be NULL because this |
117 // object can outlive is destroyed asynchronously. | 120 // object can outlive is destroyed asynchronously. |
118 WebKit::WebFrame* web_frame_; | 121 WebKit::WebFrame* web_frame_; |
119 | 122 |
120 // The extension associated with this context, or NULL if there is none. This | 123 // The extension associated with this context, or NULL if there is none. This |
121 // might be a hosted app in the case that this context is hosting a web URL. | 124 // might be a hosted app in the case that this context is hosting a web URL. |
122 scoped_refptr<const Extension> extension_; | 125 scoped_refptr<const Extension> extension_; |
123 | 126 |
124 // The type of context. | 127 // The type of context. |
125 Feature::Context context_type_; | 128 Feature::Context context_type_; |
126 | 129 |
127 // Owns and structures the JS that is injected to set up extension bindings. | 130 // Owns and structures the JS that is injected to set up extension bindings. |
128 scoped_ptr<ModuleSystem> module_system_; | 131 scoped_ptr<ModuleSystem> module_system_; |
129 | 132 |
130 // The extension APIs available to this context. | 133 // The extension APIs available to this context. |
131 scoped_ptr<std::set<std::string> > available_extension_apis_; | 134 std::set<std::string> available_extension_apis_; |
| 135 bool available_extension_apis_initialized_; |
132 | 136 |
133 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 137 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
134 }; | 138 }; |
135 | 139 |
136 } // namespace extensions | 140 } // namespace extensions |
137 | 141 |
138 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 142 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
OLD | NEW |