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
3 // found in the LICENSE file.
5 #include "chrome/renderer/extensions/tabs_custom_bindings.h"
10 #include "content/public/renderer/render_view.h"
11 #include "extensions/common/extension_messages.h"
12 #include "extensions/renderer/script_context.h"
13 #include "v8/include/v8.h"
15 namespace extensions
{
17 TabsCustomBindings::TabsCustomBindings(ScriptContext
* context
)
18 : ObjectBackedNativeHandler(context
) {
19 RouteFunction("OpenChannelToTab",
20 base::Bind(&TabsCustomBindings::OpenChannelToTab
,
21 base::Unretained(this)));
24 void TabsCustomBindings::OpenChannelToTab(
25 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
26 // Get the current RenderView so that we can send a routed IPC message from
27 // the correct source.
28 content::RenderView
* renderview
= context()->GetRenderView();
32 if (args
.Length() >= 3 && args
[0]->IsInt32() && args
[1]->IsString() &&
33 args
[2]->IsString()) {
34 int tab_id
= args
[0]->Int32Value();
35 std::string extension_id
= *v8::String::Utf8Value(args
[1]->ToString());
36 std::string channel_name
= *v8::String::Utf8Value(args
[2]->ToString());
38 renderview
->Send(new ExtensionHostMsg_OpenChannelToTab(
39 renderview
->GetRoutingID(), tab_id
, extension_id
, channel_name
,
41 args
.GetReturnValue().Set(static_cast<int32_t>(port_id
));
46 } // namespace extensions