Chromium Code Reviews| 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 void Invalidate(); | |
|
not at google - send to devlin
2013/02/20 00:36:38
comment
cduvall
2013/02/20 00:57:53
Done.
| |
| 40 | |
| 39 v8::Handle<v8::Context> v8_context() const { | 41 v8::Handle<v8::Context> v8_context() const { |
| 40 return v8_context_; | 42 return v8_context_; |
| 41 } | 43 } |
| 42 | 44 |
| 43 const Extension* extension() const { | 45 const Extension* extension() const { |
| 44 return extension_.get(); | 46 return extension_.get(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 WebKit::WebFrame* web_frame() const { | 49 WebKit::WebFrame* web_frame() const { |
| 48 return web_frame_; | 50 return web_frame_; |
| 49 } | 51 } |
| 50 void clear_web_frame() { | 52 void clear_web_frame() { |
| 51 web_frame_ = NULL; | 53 web_frame_ = NULL; |
|
not at google - send to devlin
2013/02/20 00:36:38
let's merge this into Invalidate().
cduvall
2013/02/20 00:57:53
Done.
| |
| 52 } | 54 } |
| 53 | 55 |
| 54 Feature::Context context_type() const { | 56 Feature::Context context_type() const { |
| 55 return context_type_; | 57 return context_type_; |
| 56 } | 58 } |
| 57 | 59 |
| 58 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 60 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
| 59 module_system_ = module_system.Pass(); | 61 module_system_ = module_system.Pass(); |
| 60 } | 62 } |
| 61 | 63 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 bool CallChromeHiddenMethod( | 95 bool CallChromeHiddenMethod( |
| 94 const std::string& function_name, | 96 const std::string& function_name, |
| 95 int argc, | 97 int argc, |
| 96 v8::Handle<v8::Value>* argv, | 98 v8::Handle<v8::Value>* argv, |
| 97 v8::Handle<v8::Value>* result) const; | 99 v8::Handle<v8::Value>* result) const; |
| 98 | 100 |
| 99 // 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 |
| 100 // APIs are available, returns an empty set. | 102 // APIs are available, returns an empty set. |
| 101 const std::set<std::string>& GetAvailableExtensionAPIs(); | 103 const std::set<std::string>& GetAvailableExtensionAPIs(); |
| 102 | 104 |
| 105 Feature::Availability GetAvailability(const std::string& api_name); | |
| 106 | |
| 103 // Returns a string description of the type of context this is. | 107 // Returns a string description of the type of context this is. |
| 104 std::string GetContextTypeDescription(); | 108 std::string GetContextTypeDescription(); |
| 105 | 109 |
| 106 private: | 110 private: |
| 107 // The v8 context the bindings are accessible to. We keep a strong reference | 111 // 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 | 112 // 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 | 113 // 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 | 114 // 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 | 115 // 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 | 116 // since the DOM keeps the context alive, but it makes things simpler to not |
| 113 // distinguish the two cases. | 117 // distinguish the two cases. |
| 114 v8::Persistent<v8::Context> v8_context_; | 118 v8::Persistent<v8::Context> v8_context_; |
| 115 | 119 |
| 116 // The WebFrame associated with this context. This can be NULL because this | 120 // The WebFrame associated with this context. This can be NULL because this |
| 117 // object can outlive is destroyed asynchronously. | 121 // object can outlive is destroyed asynchronously. |
| 118 WebKit::WebFrame* web_frame_; | 122 WebKit::WebFrame* web_frame_; |
| 119 | 123 |
| 120 // The extension associated with this context, or NULL if there is none. This | 124 // 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. | 125 // might be a hosted app in the case that this context is hosting a web URL. |
| 122 scoped_refptr<const Extension> extension_; | 126 scoped_refptr<const Extension> extension_; |
| 123 | 127 |
| 124 // The type of context. | 128 // The type of context. |
| 125 Feature::Context context_type_; | 129 Feature::Context context_type_; |
| 126 | 130 |
| 127 // Owns and structures the JS that is injected to set up extension bindings. | 131 // Owns and structures the JS that is injected to set up extension bindings. |
| 128 scoped_ptr<ModuleSystem> module_system_; | 132 scoped_ptr<ModuleSystem> module_system_; |
| 129 | 133 |
| 130 // The extension APIs available to this context. | 134 // The extension APIs available to this context. |
| 131 scoped_ptr<std::set<std::string> > available_extension_apis_; | 135 std::set<std::string> available_extension_apis_; |
| 136 bool available_extension_apis_initialized_; | |
| 132 | 137 |
| 133 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 138 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 } // namespace extensions | 141 } // namespace extensions |
| 137 | 142 |
| 138 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 143 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
| OLD | NEW |