| 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/tabs_custom_bindings.h" | 5 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "chrome/common/extensions/extension_messages.h" | 9 #include "chrome/common/extensions/extension_messages.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| 11 #include "grit/renderer_resources.h" | 11 #include "grit/renderer_resources.h" |
| 12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 TabsCustomBindings::TabsCustomBindings(Dispatcher* dispatcher, | 16 TabsCustomBindings::TabsCustomBindings() |
| 17 v8::Handle<v8::Context> context) | 17 : ChromeV8Extension(NULL) { |
| 18 : ChromeV8Extension(dispatcher, context) { | |
| 19 RouteStaticFunction("OpenChannelToTab", &OpenChannelToTab); | 18 RouteStaticFunction("OpenChannelToTab", &OpenChannelToTab); |
| 20 } | 19 } |
| 21 | 20 |
| 22 // static | 21 // static |
| 23 v8::Handle<v8::Value> TabsCustomBindings::OpenChannelToTab( | 22 v8::Handle<v8::Value> TabsCustomBindings::OpenChannelToTab( |
| 24 const v8::Arguments& args) { | 23 const v8::Arguments& args) { |
| 25 // Get the current RenderView so that we can send a routed IPC message from | 24 // Get the current RenderView so that we can send a routed IPC message from |
| 26 // the correct source. | 25 // the correct source. |
| 27 TabsCustomBindings* self = GetFromArguments<TabsCustomBindings>(args); | 26 content::RenderView* renderview = GetCurrentRenderView(); |
| 28 content::RenderView* renderview = self->GetRenderView(); | |
| 29 if (!renderview) | 27 if (!renderview) |
| 30 return v8::Undefined(); | 28 return v8::Undefined(); |
| 31 | 29 |
| 32 if (args.Length() >= 3 && args[0]->IsInt32() && args[1]->IsString() && | 30 if (args.Length() >= 3 && args[0]->IsInt32() && args[1]->IsString() && |
| 33 args[2]->IsString()) { | 31 args[2]->IsString()) { |
| 34 int tab_id = args[0]->Int32Value(); | 32 int tab_id = args[0]->Int32Value(); |
| 35 std::string extension_id = *v8::String::Utf8Value(args[1]->ToString()); | 33 std::string extension_id = *v8::String::Utf8Value(args[1]->ToString()); |
| 36 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); | 34 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); |
| 37 int port_id = -1; | 35 int port_id = -1; |
| 38 renderview->Send(new ExtensionHostMsg_OpenChannelToTab( | 36 renderview->Send(new ExtensionHostMsg_OpenChannelToTab( |
| 39 renderview->GetRoutingID(), tab_id, extension_id, channel_name, | 37 renderview->GetRoutingID(), tab_id, extension_id, channel_name, |
| 40 &port_id)); | 38 &port_id)); |
| 41 return v8::Integer::New(port_id); | 39 return v8::Integer::New(port_id); |
| 42 } | 40 } |
| 43 return v8::Undefined(); | 41 return v8::Undefined(); |
| 44 } | 42 } |
| 45 | 43 |
| 46 } // extensions | 44 } // extensions |
| OLD | NEW |