OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BINDINGS_UTILS_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace bindings_utils { | 23 namespace bindings_utils { |
24 | 24 |
25 // Contains information about a JavaScript context that is hosting extension | 25 // Contains information about a JavaScript context that is hosting extension |
26 // bindings. | 26 // bindings. |
27 struct ContextInfo { | 27 struct ContextInfo { |
28 ContextInfo(v8::Persistent<v8::Context> context, | 28 ContextInfo(v8::Persistent<v8::Context> context, |
29 const std::string& extension_id, | 29 const std::string& extension_id, |
30 WebKit::WebFrame* frame); | 30 WebKit::WebFrame* frame); |
31 ~ContextInfo(); | 31 ~ContextInfo(); |
32 | 32 |
| 33 // Returns the web frame associated with this context. Can also return NULL if |
| 34 // the context has been disassociated with the frame, and not GC'd yet. |
| 35 WebKit::WebFrame* GetWebFrame() const; |
| 36 |
| 37 // Returns the RenderView associated wit hthis context. Can also return NULL. |
| 38 RenderView* GetRenderView() const; |
| 39 |
33 v8::Persistent<v8::Context> context; | 40 v8::Persistent<v8::Context> context; |
34 | 41 |
35 // The extension ID this context is associated with. | 42 // The extension ID this context is associated with. |
36 std::string extension_id; | 43 std::string extension_id; |
37 | 44 |
38 // The frame the context is associated with. ContextInfo can outlive its | 45 // The frame the context is associated with. ContextInfo can outlive its |
39 // frame, so this should not be dereferenced. It is stored only for use for | 46 // frame, so this should not be dereferenced. Use GetWebFrame() instead for |
40 // comparison. | 47 // most cases. This is used for comparisons during unload when GetWebFrame() |
| 48 // doesn't work. |
41 void* unsafe_frame; | 49 void* unsafe_frame; |
42 | 50 |
43 // A count of the number of events that are listening in this context. When | 51 // A count of the number of events that are listening in this context. When |
44 // this is zero, |context| will be a weak handle. | 52 // this is zero, |context| will be a weak handle. |
45 int num_connected_events; | 53 int num_connected_events; |
46 }; | 54 }; |
47 typedef std::list< linked_ptr<ContextInfo> > ContextList; | 55 typedef std::list< linked_ptr<ContextInfo> > ContextList; |
48 | 56 |
49 // Returns a mutable reference to the ContextList. Note: be careful using this. | 57 // Returns a mutable reference to the ContextList. Note: be careful using this. |
50 // Calling into javascript may result in the list being modified, so don't rely | 58 // Calling into javascript may result in the list being modified, so don't rely |
(...skipping 29 matching lines...) Expand all Loading... |
80 // be a sub-property like "Port.dispatchOnMessage". Returns the result of | 88 // be a sub-property like "Port.dispatchOnMessage". Returns the result of |
81 // the function call. If an exception is thrown an empty Handle will be | 89 // the function call. If an exception is thrown an empty Handle will be |
82 // returned. | 90 // returned. |
83 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, | 91 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, |
84 const std::string& function_name, int argc, | 92 const std::string& function_name, int argc, |
85 v8::Handle<v8::Value>* argv); | 93 v8::Handle<v8::Value>* argv); |
86 | 94 |
87 } // namespace bindings_utils | 95 } // namespace bindings_utils |
88 | 96 |
89 #endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ | 97 #endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ |
OLD | NEW |