| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "chrome/renderer/extensions/module_system.h" | 12 #include "chrome/renderer/extensions/module_system.h" |
| 13 #include "chrome/renderer/extensions/request_sender.h" | 13 #include "chrome/renderer/extensions/request_sender.h" |
| 14 #include "chrome/renderer/extensions/safe_builtins.h" | 14 #include "chrome/renderer/extensions/safe_builtins.h" |
| 15 #include "chrome/renderer/extensions/scoped_persistent.h" | 15 #include "chrome/renderer/extensions/scoped_persistent.h" |
| 16 #include "extensions/common/features/feature.h" | 16 #include "extensions/common/features/feature.h" |
| 17 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
| 18 | 18 |
| 19 namespace WebKit { | 19 namespace blink { |
| 20 class WebFrame; | 20 class WebFrame; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 class RenderView; | 24 class RenderView; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 class Extension; | 28 class Extension; |
| 29 | 29 |
| 30 // Chrome's wrapper for a v8 context. | 30 // Chrome's wrapper for a v8 context. |
| 31 class ChromeV8Context : public RequestSender::Source { | 31 class ChromeV8Context : public RequestSender::Source { |
| 32 public: | 32 public: |
| 33 ChromeV8Context(v8::Handle<v8::Context> context, | 33 ChromeV8Context(v8::Handle<v8::Context> context, |
| 34 WebKit::WebFrame* frame, | 34 blink::WebFrame* frame, |
| 35 const Extension* extension, | 35 const Extension* extension, |
| 36 Feature::Context context_type); | 36 Feature::Context context_type); |
| 37 virtual ~ChromeV8Context(); | 37 virtual ~ChromeV8Context(); |
| 38 | 38 |
| 39 // Clears the WebFrame for this contexts and invalidates the associated | 39 // Clears the WebFrame for this contexts and invalidates the associated |
| 40 // ModuleSystem. | 40 // ModuleSystem. |
| 41 void Invalidate(); | 41 void Invalidate(); |
| 42 | 42 |
| 43 // Returns true if this context is still valid, false if it isn't. | 43 // Returns true if this context is still valid, false if it isn't. |
| 44 // A context becomes invalid via Invalidate(). | 44 // A context becomes invalid via Invalidate(). |
| 45 bool is_valid() const { | 45 bool is_valid() const { |
| 46 return !v8_context_.IsEmpty(); | 46 return !v8_context_.IsEmpty(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 v8::Handle<v8::Context> v8_context() const { | 49 v8::Handle<v8::Context> v8_context() const { |
| 50 return v8_context_.NewHandle(v8::Isolate::GetCurrent()); | 50 return v8_context_.NewHandle(v8::Isolate::GetCurrent()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 const Extension* extension() const { | 53 const Extension* extension() const { |
| 54 return extension_.get(); | 54 return extension_.get(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 WebKit::WebFrame* web_frame() const { | 57 blink::WebFrame* web_frame() const { |
| 58 return web_frame_; | 58 return web_frame_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 Feature::Context context_type() const { | 61 Feature::Context context_type() const { |
| 62 return context_type_; | 62 return context_type_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void set_module_system(scoped_ptr<ModuleSystem> module_system) { | 65 void set_module_system(scoped_ptr<ModuleSystem> module_system) { |
| 66 module_system_ = module_system.Pass(); | 66 module_system_ = module_system.Pass(); |
| 67 } | 67 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 v8::Isolate* isolate() const { | 119 v8::Isolate* isolate() const { |
| 120 return isolate_; | 120 return isolate_; |
| 121 } | 121 } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 // The v8 context the bindings are accessible to. | 124 // The v8 context the bindings are accessible to. |
| 125 ScopedPersistent<v8::Context> v8_context_; | 125 ScopedPersistent<v8::Context> v8_context_; |
| 126 | 126 |
| 127 // The WebFrame associated with this context. This can be NULL because this | 127 // The WebFrame associated with this context. This can be NULL because this |
| 128 // object can outlive is destroyed asynchronously. | 128 // object can outlive is destroyed asynchronously. |
| 129 WebKit::WebFrame* web_frame_; | 129 blink::WebFrame* web_frame_; |
| 130 | 130 |
| 131 // The extension associated with this context, or NULL if there is none. This | 131 // The extension associated with this context, or NULL if there is none. This |
| 132 // might be a hosted app in the case that this context is hosting a web URL. | 132 // might be a hosted app in the case that this context is hosting a web URL. |
| 133 scoped_refptr<const Extension> extension_; | 133 scoped_refptr<const Extension> extension_; |
| 134 | 134 |
| 135 // The type of context. | 135 // The type of context. |
| 136 Feature::Context context_type_; | 136 Feature::Context context_type_; |
| 137 | 137 |
| 138 // Owns and structures the JS that is injected to set up extension bindings. | 138 // Owns and structures the JS that is injected to set up extension bindings. |
| 139 scoped_ptr<ModuleSystem> module_system_; | 139 scoped_ptr<ModuleSystem> module_system_; |
| 140 | 140 |
| 141 // Contains safe copies of builtin objects like Function.prototype. | 141 // Contains safe copies of builtin objects like Function.prototype. |
| 142 SafeBuiltins safe_builtins_; | 142 SafeBuiltins safe_builtins_; |
| 143 | 143 |
| 144 v8::Isolate* isolate_; | 144 v8::Isolate* isolate_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 146 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace extensions | 149 } // namespace extensions |
| 150 | 150 |
| 151 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 151 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
| OLD | NEW |