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