Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/renderer/extensions/extension_custom_bindings.cc

Issue 10991044: Revert 158830 - Revert 156678 - Native messaging now uses the MessageService back-end. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extension_custom_bindings.h" 5 #include "chrome/renderer/extensions/extension_custom_bindings.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_action.h" 11 #include "chrome/common/extensions/extension_action.h"
12 #include "chrome/common/extensions/extension_messages.h" 12 #include "chrome/common/extensions/extension_messages.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "chrome/common/view_type.h" 14 #include "chrome/common/view_type.h"
15 #include "chrome/renderer/extensions/dispatcher.h" 15 #include "chrome/renderer/extensions/dispatcher.h"
16 #include "chrome/renderer/extensions/extension_helper.h" 16 #include "chrome/renderer/extensions/extension_helper.h"
17 #include "content/public/renderer/render_view.h" 17 #include "content/public/renderer/render_view.h"
18 #include "content/public/renderer/v8_value_converter.h"
18 #include "grit/renderer_resources.h" 19 #include "grit/renderer_resources.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
21 #include "webkit/glue/webkit_glue.h" 22 #include "webkit/glue/webkit_glue.h"
22 #include "v8/include/v8.h" 23 #include "v8/include/v8.h"
23 24
24 namespace extensions { 25 namespace extensions {
25 26
26 namespace { 27 namespace {
27 28
28 } // namespace 29 } // namespace
29 30
30 ExtensionCustomBindings::ExtensionCustomBindings(Dispatcher* dispatcher) 31 ExtensionCustomBindings::ExtensionCustomBindings(Dispatcher* dispatcher)
31 : ChromeV8Extension(dispatcher) { 32 : ChromeV8Extension(dispatcher) {
32 RouteStaticFunction("GetExtensionViews", &GetExtensionViews); 33 RouteStaticFunction("GetExtensionViews", &GetExtensionViews);
33 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension); 34 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension);
35 RouteStaticFunction("OpenChannelToNativeApp", &OpenChannelToNativeApp);
34 } 36 }
35 37
36 // static 38 // static
37 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews( 39 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews(
38 const v8::Arguments& args) { 40 const v8::Arguments& args) {
39 if (args.Length() != 2) 41 if (args.Length() != 2)
40 return v8::Undefined(); 42 return v8::Undefined();
41 43
42 if (!args[0]->IsInt32() || !args[1]->IsString()) 44 if (!args[0]->IsInt32() || !args[1]->IsString())
43 return v8::Undefined(); 45 return v8::Undefined();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 int port_id = -1; 118 int port_id = -1;
117 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( 119 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension(
118 renderview->GetRoutingID(), 120 renderview->GetRoutingID(),
119 source_id, 121 source_id,
120 target_id, 122 target_id,
121 channel_name, 123 channel_name,
122 &port_id)); 124 &port_id));
123 return v8::Integer::New(port_id); 125 return v8::Integer::New(port_id);
124 } 126 }
125 127
128 // static
129 v8::Handle<v8::Value> ExtensionCustomBindings::OpenChannelToNativeApp(
130 const v8::Arguments& args) {
131 // Get the current RenderView so that we can send a routed IPC message from
132 // the correct source.
133 content::RenderView* renderview = GetCurrentRenderView();
134 if (!renderview)
135 return v8::Undefined();
136
137 // The Javascript code should validate/fill the arguments.
138 CHECK(args.Length() >= 3 &&
139 args[0]->IsString() &&
140 args[1]->IsString() &&
141 args[2]->IsString() &&
142 args[3]->IsString());
143
144 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString());
145 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString());
146 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString());
147 std::string connect_message = *v8::String::Utf8Value(args[3]->ToString());
148
149 int port_id = -1;
150 renderview->Send(new ExtensionHostMsg_OpenChannelToNativeApp(
151 renderview->GetRoutingID(),
152 extension_id,
153 native_app_name,
154 channel_name,
155 connect_message,
156 &port_id));
157 return v8::Integer::New(port_id);
158 }
159
126 } // namespace extensions 160 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698