| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 // Creates a new messaging channel to the given extension. | 71 // Creates a new messaging channel to the given extension. |
| 72 static v8::Handle<v8::Value> OpenChannelToExtension( | 72 static v8::Handle<v8::Value> OpenChannelToExtension( |
| 73 const v8::Arguments& args) { | 73 const v8::Arguments& args) { |
| 74 // Get the current RenderView so that we can send a routed IPC message from | 74 // Get the current RenderView so that we can send a routed IPC message from |
| 75 // the correct source. | 75 // the correct source. |
| 76 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); | 76 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); |
| 77 if (!renderview) | 77 if (!renderview) |
| 78 return v8::Undefined(); | 78 return v8::Undefined(); |
| 79 | 79 |
| 80 if (args.Length() >= 2 && args[0]->IsString() && args[1]->IsString()) { | 80 if (args.Length() >= 3 && args[0]->IsString() && args[1]->IsString() && |
| 81 std::string id = *v8::String::Utf8Value(args[0]->ToString()); | 81 args[2]->IsString()) { |
| 82 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); | 82 std::string source_id = *v8::String::Utf8Value(args[0]->ToString()); |
| 83 std::string target_id = *v8::String::Utf8Value(args[1]->ToString()); |
| 84 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); |
| 83 int port_id = -1; | 85 int port_id = -1; |
| 84 renderview->Send(new ViewHostMsg_OpenChannelToExtension( | 86 renderview->Send(new ViewHostMsg_OpenChannelToExtension( |
| 85 renderview->routing_id(), id, channel_name, &port_id)); | 87 renderview->routing_id(), source_id, target_id, |
| 88 channel_name, &port_id)); |
| 86 return v8::Integer::New(port_id); | 89 return v8::Integer::New(port_id); |
| 87 } | 90 } |
| 88 return v8::Undefined(); | 91 return v8::Undefined(); |
| 89 } | 92 } |
| 90 | 93 |
| 91 // Sends a message along the given channel. | 94 // Sends a message along the given channel. |
| 92 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { | 95 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { |
| 93 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); | 96 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); |
| 94 if (!renderview) | 97 if (!renderview) |
| 95 return v8::Undefined(); | 98 return v8::Undefined(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return extension; | 200 return extension; |
| 198 } | 201 } |
| 199 | 202 |
| 200 void RendererExtensionBindings::Invoke(const std::string& function_name, | 203 void RendererExtensionBindings::Invoke(const std::string& function_name, |
| 201 const ListValue& args, | 204 const ListValue& args, |
| 202 RenderView* renderview) { | 205 RenderView* renderview) { |
| 203 v8::HandleScope handle_scope; | 206 v8::HandleScope handle_scope; |
| 204 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args); | 207 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args); |
| 205 EventBindings::CallFunction(function_name, argv.size(), &argv[0], renderview); | 208 EventBindings::CallFunction(function_name, argv.size(), &argv[0], renderview); |
| 206 } | 209 } |
| OLD | NEW |