| 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 "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
| 13 | 13 |
| 14 namespace WebKit { | 14 namespace WebKit { |
| 15 class WebFrame; | 15 class WebFrame; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class RenderView; | 19 class RenderView; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // Chrome's wrapper for a v8 context. | 22 // Chrome's wrapper for a v8 context. |
| 23 // | 23 // |
| 24 // TODO(aa): Consider converting this back to a set of bindings_utils. It would | 24 // TODO(aa): Consider converting this back to a set of bindings_utils. It would |
| 25 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then | 25 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then |
| 26 // we won't need this object and it's a bit less state to keep track of. | 26 // we won't need this object and it's a bit less state to keep track of. |
| 27 class ChromeV8Context { | 27 class ChromeV8Context { |
| 28 public: | 28 public: |
| 29 enum ContextType { |
| 30 CONTENT_SCRIPT, |
| 31 |
| 32 // TODO(kalman): for now, have this as OTHER, since we only currently need |
| 33 // know whether something is a content script or not. However, when |
| 34 // necessary this should enumerate the other types, such as FRAME. |
| 35 OTHER |
| 36 }; |
| 37 |
| 29 ChromeV8Context(v8::Handle<v8::Context> context, | 38 ChromeV8Context(v8::Handle<v8::Context> context, |
| 30 WebKit::WebFrame* frame, | 39 WebKit::WebFrame* frame, |
| 31 const std::string& extension_id); | 40 const std::string& extension_id, |
| 41 ContextType context_type); |
| 32 ~ChromeV8Context(); | 42 ~ChromeV8Context(); |
| 33 | 43 |
| 34 v8::Handle<v8::Context> v8_context() const { | 44 v8::Handle<v8::Context> v8_context() const { |
| 35 return v8_context_; | 45 return v8_context_; |
| 36 } | 46 } |
| 37 | 47 |
| 38 const std::string& extension_id() const { | 48 const std::string& extension_id() const { |
| 39 return extension_id_; | 49 return extension_id_; |
| 40 } | 50 } |
| 41 | 51 |
| 42 WebKit::WebFrame* web_frame() const { | 52 WebKit::WebFrame* web_frame() const { |
| 43 return web_frame_; | 53 return web_frame_; |
| 44 } | 54 } |
| 45 void clear_web_frame() { | 55 void clear_web_frame() { |
| 46 web_frame_ = NULL; | 56 web_frame_ = NULL; |
| 47 } | 57 } |
| 48 | 58 |
| 59 ContextType context_type() const { |
| 60 return context_type_; |
| 61 } |
| 62 |
| 49 // Returns a special Chrome-specific hidden object that is associated with a | 63 // Returns a special Chrome-specific hidden object that is associated with a |
| 50 // context, but not reachable from the JavaScript in that context. This is | 64 // context, but not reachable from the JavaScript in that context. This is |
| 51 // used by our v8::Extension implementations as a way to share code and as a | 65 // used by our v8::Extension implementations as a way to share code and as a |
| 52 // bridge between C++ and JavaScript. | 66 // bridge between C++ and JavaScript. |
| 53 static v8::Handle<v8::Value> GetOrCreateChromeHidden( | 67 static v8::Handle<v8::Value> GetOrCreateChromeHidden( |
| 54 v8::Handle<v8::Context> context); | 68 v8::Handle<v8::Context> context); |
| 55 | 69 |
| 56 // Return the chromeHidden object associated with this context, or an empty | 70 // Return the chromeHidden object associated with this context, or an empty |
| 57 // handle if no chrome hidden has been created (by GetOrCreateChromeHidden) | 71 // handle if no chrome hidden has been created (by GetOrCreateChromeHidden) |
| 58 // yet for this context. | 72 // yet for this context. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 89 // distinguish the two cases. | 103 // distinguish the two cases. |
| 90 v8::Persistent<v8::Context> v8_context_; | 104 v8::Persistent<v8::Context> v8_context_; |
| 91 | 105 |
| 92 // The WebFrame associated with this context. This can be NULL because this | 106 // The WebFrame associated with this context. This can be NULL because this |
| 93 // object can outlive is destroyed asynchronously. | 107 // object can outlive is destroyed asynchronously. |
| 94 WebKit::WebFrame* web_frame_; | 108 WebKit::WebFrame* web_frame_; |
| 95 | 109 |
| 96 // The extension ID this context is associated with. | 110 // The extension ID this context is associated with. |
| 97 std::string extension_id_; | 111 std::string extension_id_; |
| 98 | 112 |
| 113 // The type of context. |
| 114 ContextType context_type_; |
| 115 |
| 99 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); | 116 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); |
| 100 }; | 117 }; |
| 101 | 118 |
| 102 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ | 119 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ |
| OLD | NEW |