| 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 19 matching lines...) Expand all Loading... |
| 30 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then | 30 // 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. | 31 // we won't need this object and it's a bit less state to keep track of. |
| 32 class ChromeV8Context { | 32 class ChromeV8Context { |
| 33 public: | 33 public: |
| 34 ChromeV8Context(v8::Handle<v8::Context> context, | 34 ChromeV8Context(v8::Handle<v8::Context> context, |
| 35 WebKit::WebFrame* frame, | 35 WebKit::WebFrame* frame, |
| 36 const Extension* extension, | 36 const Extension* extension, |
| 37 Feature::Context context_type); | 37 Feature::Context context_type); |
| 38 ~ChromeV8Context(); | 38 ~ChromeV8Context(); |
| 39 | 39 |
| 40 // Clears the WebFrame for this contexts and invalidates the associated |
| 41 // ModuleSystem. |
| 42 void Invalidate(); |
| 43 |
| 40 v8::Handle<v8::Context> v8_context() const { | 44 v8::Handle<v8::Context> v8_context() const { |
| 41 return v8_context_.get(); | 45 return v8_context_.get(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 const Extension* extension() const { | 48 const Extension* extension() const { |
| 45 return extension_.get(); | 49 return extension_.get(); |
| 46 } | 50 } |
| 47 | 51 |
| 48 WebKit::WebFrame* web_frame() const { | 52 WebKit::WebFrame* web_frame() const { |
| 49 return web_frame_; | 53 return web_frame_; |
| 50 } | 54 } |
| 51 void clear_web_frame() { | |
| 52 web_frame_ = NULL; | |
| 53 } | |
| 54 | 55 |
| 55 Feature::Context context_type() const { | 56 Feature::Context context_type() const { |
| 56 return context_type_; | 57 return context_type_; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 60 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
| 60 module_system_ = module_system.Pass(); | 61 module_system_ = module_system.Pass(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 ModuleSystem* module_system() { return module_system_.get(); } | 64 ModuleSystem* module_system() { return module_system_.get(); } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 94 bool CallChromeHiddenMethod( | 95 bool CallChromeHiddenMethod( |
| 95 const std::string& function_name, | 96 const std::string& function_name, |
| 96 int argc, | 97 int argc, |
| 97 v8::Handle<v8::Value>* argv, | 98 v8::Handle<v8::Value>* argv, |
| 98 v8::Handle<v8::Value>* result) const; | 99 v8::Handle<v8::Value>* result) const; |
| 99 | 100 |
| 100 // Returns the set of extension APIs that are available to this context. If no | 101 // Returns the set of extension APIs that are available to this context. If no |
| 101 // APIs are available, returns an empty set. | 102 // APIs are available, returns an empty set. |
| 102 const std::set<std::string>& GetAvailableExtensionAPIs(); | 103 const std::set<std::string>& GetAvailableExtensionAPIs(); |
| 103 | 104 |
| 105 Feature::Availability GetAvailability(const std::string& api_name); |
| 106 |
| 104 // Returns a string description of the type of context this is. | 107 // Returns a string description of the type of context this is. |
| 105 std::string GetContextTypeDescription(); | 108 std::string GetContextTypeDescription(); |
| 106 | 109 |
| 107 private: | 110 private: |
| 108 // The v8 context the bindings are accessible to. | 111 // The v8 context the bindings are accessible to. |
| 109 ScopedPersistent<v8::Context> v8_context_; | 112 ScopedPersistent<v8::Context> v8_context_; |
| 110 | 113 |
| 111 // 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 |
| 112 // object can outlive is destroyed asynchronously. | 115 // object can outlive is destroyed asynchronously. |
| 113 WebKit::WebFrame* web_frame_; | 116 WebKit::WebFrame* web_frame_; |
| 114 | 117 |
| 115 // 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 |
| 116 // 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. |
| 117 scoped_refptr<const Extension> extension_; | 120 scoped_refptr<const Extension> extension_; |
| 118 | 121 |
| 119 // The type of context. | 122 // The type of context. |
| 120 Feature::Context context_type_; | 123 Feature::Context context_type_; |
| 121 | 124 |
| 122 // 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. |
| 123 scoped_ptr<ModuleSystem> module_system_; | 126 scoped_ptr<ModuleSystem> module_system_; |
| 124 | 127 |
| 125 // The extension APIs available to this context. | 128 // The extension APIs available to this context. |
| 126 scoped_ptr<std::set<std::string> > available_extension_apis_; | 129 std::set<std::string> available_extension_apis_; |
| 130 bool available_extension_apis_initialized_; |
| 127 | 131 |
| 128 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 132 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
| 129 }; | 133 }; |
| 130 | 134 |
| 131 } // namespace extensions | 135 } // namespace extensions |
| 132 | 136 |
| 133 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 137 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
| OLD | NEW |