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 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 5 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 | 59 |
60 static void ClearPortData(int port_id) { | 60 static void ClearPortData(int port_id) { |
61 g_extension_data.Get().ports.erase(port_id); | 61 g_extension_data.Get().ports.erase(port_id); |
62 } | 62 } |
63 | 63 |
64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; | 64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; |
65 | 65 |
66 class ExtensionImpl : public extensions::ChromeV8Extension { | 66 class ExtensionImpl : public extensions::ChromeV8Extension { |
67 public: | 67 public: |
68 explicit ExtensionImpl(extensions::Dispatcher* dispatcher) | 68 explicit ExtensionImpl(extensions::Dispatcher* dispatcher, |
69 : extensions::ChromeV8Extension(dispatcher) { | 69 v8::Handle<v8::Context> context) |
| 70 : extensions::ChromeV8Extension(dispatcher, context) { |
70 RouteStaticFunction("CloseChannel", &CloseChannel); | 71 RouteStaticFunction("CloseChannel", &CloseChannel); |
71 RouteStaticFunction("PortAddRef", &PortAddRef); | 72 RouteStaticFunction("PortAddRef", &PortAddRef); |
72 RouteStaticFunction("PortRelease", &PortRelease); | 73 RouteStaticFunction("PortRelease", &PortRelease); |
73 RouteStaticFunction("PostMessage", &PostMessage); | 74 RouteStaticFunction("PostMessage", &PostMessage); |
74 RouteStaticFunction("BindToGC", &BindToGC); | 75 RouteStaticFunction("BindToGC", &BindToGC); |
75 } | 76 } |
76 | 77 |
77 virtual ~ExtensionImpl() {} | 78 virtual ~ExtensionImpl() {} |
78 | 79 |
79 // Sends a message along the given channel. | 80 // Sends a message along the given channel. |
80 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { | 81 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { |
81 content::RenderView* renderview = GetCurrentRenderView(); | 82 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); |
| 83 content::RenderView* renderview = self->GetRenderView(); |
82 if (!renderview) | 84 if (!renderview) |
83 return v8::Undefined(); | 85 return v8::Undefined(); |
84 | 86 |
85 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { | 87 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { |
86 int port_id = args[0]->Int32Value(); | 88 int port_id = args[0]->Int32Value(); |
87 if (!HasPortData(port_id)) { | 89 if (!HasPortData(port_id)) { |
88 return v8::ThrowException(v8::Exception::Error( | 90 return v8::ThrowException(v8::Exception::Error( |
89 v8::String::New(kPortClosedError))); | 91 v8::String::New(kPortClosedError))); |
90 } | 92 } |
91 std::string message = *v8::String::Utf8Value(args[1]->ToString()); | 93 std::string message = *v8::String::Utf8Value(args[1]->ToString()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 NOTREACHED(); | 173 NOTREACHED(); |
172 } | 174 } |
173 return v8::Undefined(); | 175 return v8::Undefined(); |
174 } | 176 } |
175 }; | 177 }; |
176 | 178 |
177 } // namespace | 179 } // namespace |
178 | 180 |
179 namespace extensions { | 181 namespace extensions { |
180 | 182 |
181 ChromeV8Extension* MiscellaneousBindings::Get(Dispatcher* dispatcher) { | 183 ChromeV8Extension* MiscellaneousBindings::Get( |
182 return new ExtensionImpl(dispatcher); | 184 Dispatcher* dispatcher, |
| 185 v8::Handle<v8::Context> context) { |
| 186 return new ExtensionImpl(dispatcher, context); |
183 } | 187 } |
184 | 188 |
185 // static | 189 // static |
186 void MiscellaneousBindings::DispatchOnConnect( | 190 void MiscellaneousBindings::DispatchOnConnect( |
187 const ChromeV8ContextSet::ContextSet& contexts, | 191 const ChromeV8ContextSet::ContextSet& contexts, |
188 int target_port_id, | 192 int target_port_id, |
189 const std::string& channel_name, | 193 const std::string& channel_name, |
190 const std::string& tab_json, | 194 const std::string& tab_json, |
191 const std::string& source_extension_id, | 195 const std::string& source_extension_id, |
192 const std::string& target_extension_id, | 196 const std::string& target_extension_id, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 std::vector<v8::Handle<v8::Value> > arguments; | 309 std::vector<v8::Handle<v8::Value> > arguments; |
306 arguments.push_back(v8::Integer::New(port_id)); | 310 arguments.push_back(v8::Integer::New(port_id)); |
307 arguments.push_back(v8::Boolean::New(connection_error)); | 311 arguments.push_back(v8::Boolean::New(connection_error)); |
308 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", | 312 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", |
309 arguments.size(), &arguments[0], | 313 arguments.size(), &arguments[0], |
310 NULL); | 314 NULL); |
311 } | 315 } |
312 } | 316 } |
313 | 317 |
314 } // namespace extensions | 318 } // namespace extensions |
OLD | NEW |