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