| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "chrome/common/extensions/feature.h" |
| 12 #include "chrome/renderer/module_system.h" | 13 #include "chrome/renderer/module_system.h" |
| 13 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 14 | 15 |
| 15 namespace WebKit { | 16 namespace WebKit { |
| 16 class WebFrame; | 17 class WebFrame; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 class RenderView; | 21 class RenderView; |
| 21 } | 22 } |
| 22 | 23 |
| 23 // Chrome's wrapper for a v8 context. | 24 // Chrome's wrapper for a v8 context. |
| 24 // | 25 // |
| 25 // TODO(aa): Consider converting this back to a set of bindings_utils. It would | 26 // TODO(aa): Consider converting this back to a set of bindings_utils. It would |
| 26 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then | 27 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then |
| 27 // we won't need this object and it's a bit less state to keep track of. | 28 // we won't need this object and it's a bit less state to keep track of. |
| 28 class ChromeV8Context { | 29 class ChromeV8Context { |
| 29 public: | 30 public: |
| 30 enum ContextType { | |
| 31 CONTENT_SCRIPT, | |
| 32 | |
| 33 // TODO(kalman): for now, have this as OTHER, since we only currently need | |
| 34 // know whether something is a content script or not. However, when | |
| 35 // necessary this should enumerate the other types, such as FRAME. | |
| 36 OTHER | |
| 37 }; | |
| 38 | |
| 39 ChromeV8Context(v8::Handle<v8::Context> context, | 31 ChromeV8Context(v8::Handle<v8::Context> context, |
| 40 WebKit::WebFrame* frame, | 32 WebKit::WebFrame* frame, |
| 41 const std::string& extension_id, | 33 const std::string& extension_id, |
| 42 ContextType context_type); | 34 extensions::Feature::Context context_type); |
| 43 ~ChromeV8Context(); | 35 ~ChromeV8Context(); |
| 44 | 36 |
| 45 v8::Handle<v8::Context> v8_context() const { | 37 v8::Handle<v8::Context> v8_context() const { |
| 46 return v8_context_; | 38 return v8_context_; |
| 47 } | 39 } |
| 48 | 40 |
| 49 const std::string& extension_id() const { | 41 const std::string& extension_id() const { |
| 50 return extension_id_; | 42 return extension_id_; |
| 51 } | 43 } |
| 52 | 44 |
| 53 WebKit::WebFrame* web_frame() const { | 45 WebKit::WebFrame* web_frame() const { |
| 54 return web_frame_; | 46 return web_frame_; |
| 55 } | 47 } |
| 56 void clear_web_frame() { | 48 void clear_web_frame() { |
| 57 web_frame_ = NULL; | 49 web_frame_ = NULL; |
| 58 } | 50 } |
| 59 | 51 |
| 60 ContextType context_type() const { | 52 extensions::Feature::Context context_type() const { |
| 61 return context_type_; | 53 return context_type_; |
| 62 } | 54 } |
| 63 | 55 |
| 64 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 56 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
| 65 module_system_ = module_system.Pass(); | 57 module_system_ = module_system.Pass(); |
| 66 } | 58 } |
| 67 | 59 |
| 68 // Returns a special Chrome-specific hidden object that is associated with a | 60 // Returns a special Chrome-specific hidden object that is associated with a |
| 69 // context, but not reachable from the JavaScript in that context. This is | 61 // context, but not reachable from the JavaScript in that context. This is |
| 70 // used by our v8::Extension implementations as a way to share code and as a | 62 // used by our v8::Extension implementations as a way to share code and as a |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 v8::Persistent<v8::Context> v8_context_; | 101 v8::Persistent<v8::Context> v8_context_; |
| 110 | 102 |
| 111 // The WebFrame associated with this context. This can be NULL because this | 103 // The WebFrame associated with this context. This can be NULL because this |
| 112 // object can outlive is destroyed asynchronously. | 104 // object can outlive is destroyed asynchronously. |
| 113 WebKit::WebFrame* web_frame_; | 105 WebKit::WebFrame* web_frame_; |
| 114 | 106 |
| 115 // The extension ID this context is associated with. | 107 // The extension ID this context is associated with. |
| 116 std::string extension_id_; | 108 std::string extension_id_; |
| 117 | 109 |
| 118 // The type of context. | 110 // The type of context. |
| 119 ContextType context_type_; | 111 extensions::Feature::Context context_type_; |
| 120 | 112 |
| 121 // Owns and structures the JS that is injected to set up extension bindings. | 113 // Owns and structures the JS that is injected to set up extension bindings. |
| 122 scoped_ptr<ModuleSystem> module_system_; | 114 scoped_ptr<ModuleSystem> module_system_; |
| 123 | 115 |
| 124 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 116 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
| 125 }; | 117 }; |
| 126 | 118 |
| 127 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 119 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
| OLD | NEW |