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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // Helper to print from bindings javascript. | 75 // Helper to print from bindings javascript. |
76 static v8::Handle<v8::Value> Print(const v8::Arguments& args); | 76 static v8::Handle<v8::Value> Print(const v8::Arguments& args); |
77 }; | 77 }; |
78 | 78 |
79 const char* GetStringResource(int resource_id); | 79 const char* GetStringResource(int resource_id); |
80 | 80 |
81 // Contains information about a JavaScript context that is hosting extension | 81 // Contains information about a JavaScript context that is hosting extension |
82 // bindings. | 82 // bindings. |
83 struct ContextInfo { | 83 struct ContextInfo { |
84 ContextInfo(v8::Persistent<v8::Context> context, | 84 ContextInfo(v8::Persistent<v8::Context> context, |
85 const std::string& extension_id, | 85 v8::Persistent<v8::Context> main_world_context, |
86 WebKit::WebFrame* frame); | 86 const std::string& extension_id); |
87 ~ContextInfo(); | 87 ~ContextInfo(); |
88 | 88 |
| 89 // The context hosting the bindings. If this is a content script, the handle |
| 90 // will be weak. |
89 v8::Persistent<v8::Context> context; | 91 v8::Persistent<v8::Context> context; |
90 | 92 |
| 93 // If the context is a content script, this contains a reference to the |
| 94 // corresponding main world's context. It is weak, but it should always be |
| 95 // valid because we delete ContextInfo for content scripts when the |
| 96 // corresponding main world context is destroyed. |
| 97 v8::Persistent<v8::Context> main_world_context; |
| 98 |
91 // The extension ID this context is associated with. | 99 // The extension ID this context is associated with. |
92 std::string extension_id; | 100 std::string extension_id; |
93 | 101 |
94 // The frame the context is associated with. We can't always get this from | |
95 // WebFrame::frameForContext() (in particular as the the frame is navigating | |
96 // or being destroyed). | |
97 WebKit::WebFrame* frame; | |
98 | |
99 // A count of the number of events that are listening in this context. When | 102 // A count of the number of events that are listening in this context. When |
100 // this is zero, |context| will be a weak handle. | 103 // this is zero, |context| will be a weak handle. |
101 int num_connected_events; | 104 int num_connected_events; |
102 }; | 105 }; |
103 typedef std::list< linked_ptr<ContextInfo> > ContextList; | 106 typedef std::list< linked_ptr<ContextInfo> > ContextList; |
104 | 107 |
105 // Returns a mutable reference to the ContextList. Note: be careful using this. | 108 // Returns a mutable reference to the ContextList. Note: be careful using this. |
106 // Calling into javascript may result in the list being modified, so don't rely | 109 // Calling into javascript may result in the list being modified, so don't rely |
107 // on iterators remaining valid between calls to javascript. | 110 // on iterators remaining valid between calls to javascript. |
108 ContextList& GetContexts(); | 111 ContextList& GetContexts(); |
(...skipping 27 matching lines...) Expand all Loading... |
136 // be a sub-property like "Port.dispatchOnMessage". Returns the result of | 139 // be a sub-property like "Port.dispatchOnMessage". Returns the result of |
137 // the function call. If an exception is thrown an empty Handle will be | 140 // the function call. If an exception is thrown an empty Handle will be |
138 // returned. | 141 // returned. |
139 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, | 142 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, |
140 const std::string& function_name, int argc, | 143 const std::string& function_name, int argc, |
141 v8::Handle<v8::Value>* argv); | 144 v8::Handle<v8::Value>* argv); |
142 | 145 |
143 } // namespace bindings_utils | 146 } // namespace bindings_utils |
144 | 147 |
145 #endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ | 148 #endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_ |
OLD | NEW |