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 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 5 #include "chrome/renderer/extensions/renderer_extension_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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 } // namespace | 247 } // namespace |
248 | 248 |
249 const char* RendererExtensionBindings::kName = | 249 const char* RendererExtensionBindings::kName = |
250 "chrome/RendererExtensionBindings"; | 250 "chrome/RendererExtensionBindings"; |
251 | 251 |
252 v8::Extension* RendererExtensionBindings::Get(ExtensionDispatcher* dispatcher) { | 252 v8::Extension* RendererExtensionBindings::Get(ExtensionDispatcher* dispatcher) { |
253 static v8::Extension* extension = new ExtensionImpl(dispatcher); | 253 static v8::Extension* extension = new ExtensionImpl(dispatcher); |
254 return extension; | 254 return extension; |
255 } | 255 } |
| 256 |
| 257 void RendererExtensionBindings::DeliverMessage( |
| 258 int target_port_id, |
| 259 const std::string& message, |
| 260 RenderView* restrict_to_render_view) { |
| 261 v8::HandleScope handle_scope; |
| 262 |
| 263 bindings_utils::ContextList contexts = bindings_utils::GetContexts(); |
| 264 for (bindings_utils::ContextList::iterator it = contexts.begin(); |
| 265 it != contexts.end(); ++it) { |
| 266 |
| 267 v8::Handle<v8::Context> context = (*it)->context; |
| 268 if (context.IsEmpty()) |
| 269 continue; |
| 270 |
| 271 if (restrict_to_render_view && |
| 272 restrict_to_render_view != (*it)->GetRenderView()) { |
| 273 continue; |
| 274 } |
| 275 |
| 276 // Check to see whether the context has this port before bothering to create |
| 277 // the message. |
| 278 v8::Handle<v8::Value> port_id_handle = v8::Integer::New(target_port_id); |
| 279 v8::Handle<v8::Value> has_port = |
| 280 bindings_utils::CallFunctionInContext( |
| 281 context, "Port.hasPort", 1, &port_id_handle); |
| 282 CHECK(!has_port.IsEmpty()); |
| 283 if (!has_port->BooleanValue()) |
| 284 continue; |
| 285 |
| 286 std::vector<v8::Handle<v8::Value> > arguments; |
| 287 arguments.push_back(v8::String::New(message.c_str(), message.size())); |
| 288 arguments.push_back(port_id_handle); |
| 289 bindings_utils::CallFunctionInContext( |
| 290 context, "Port.dispatchOnMessage", |
| 291 arguments.size(), &arguments[0]); |
| 292 } |
| 293 } |
OLD | NEW |