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