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