Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / renderer / extensions / tabs_custom_bindings.cc
blob93576960e5049bba71a167b4fe560111fe8490a0
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"
7 #include <string>
9 #include "base/bind.h"
10 #include "content/public/renderer/render_frame.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 content::RenderFrame* render_frame = context()->GetRenderFrame();
27 if (!render_frame)
28 return;
30 // tabs_custom_bindings.js unwraps arguments to tabs.connect/sendMessage and
31 // passes them to OpenChannelToTab, in the following order:
32 // - |tab_id| - Positive number that specifies the destination of the channel.
33 // - |frame_id| - Target frame(s) in the tab where onConnect is dispatched:
34 // -1 for all frames, 0 for the main frame, >0 for a child frame.
35 // - |extension_id| - Extension ID of sender and destination.
36 // - |channel_name| - A user-defined channel name.
37 CHECK(args.Length() >= 4 &&
38 args[0]->IsInt32() &&
39 args[1]->IsInt32() &&
40 args[2]->IsString() &&
41 args[3]->IsString());
43 ExtensionMsg_TabTargetConnectionInfo info;
44 info.tab_id = args[0]->Int32Value();
45 info.frame_id = args[1]->Int32Value();
46 std::string extension_id = *v8::String::Utf8Value(args[2]);
47 std::string channel_name = *v8::String::Utf8Value(args[3]);
48 int port_id = -1;
49 render_frame->Send(new ExtensionHostMsg_OpenChannelToTab(
50 info, extension_id, channel_name, &port_id));
51 args.GetReturnValue().Set(static_cast<int32_t>(port_id));
54 } // namespace extensions