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

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

Issue 10990064: Revert 156678 - Native messaging now uses the MessageService back-end. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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"
19 #include "grit/renderer_resources.h" 18 #include "grit/renderer_resources.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
22 #include "webkit/glue/webkit_glue.h" 21 #include "webkit/glue/webkit_glue.h"
23 #include "v8/include/v8.h" 22 #include "v8/include/v8.h"
24 23
25 namespace extensions { 24 namespace extensions {
26 25
27 namespace { 26 namespace {
28 27
29 } // namespace 28 } // namespace
30 29
31 ExtensionCustomBindings::ExtensionCustomBindings(Dispatcher* dispatcher) 30 ExtensionCustomBindings::ExtensionCustomBindings(Dispatcher* dispatcher)
32 : ChromeV8Extension(dispatcher) { 31 : ChromeV8Extension(dispatcher) {
33 RouteStaticFunction("GetExtensionViews", &GetExtensionViews); 32 RouteStaticFunction("GetExtensionViews", &GetExtensionViews);
34 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension); 33 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension);
35 RouteStaticFunction("OpenChannelToNativeApp", &OpenChannelToNativeApp);
36 } 34 }
37 35
38 // static 36 // static
39 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews( 37 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews(
40 const v8::Arguments& args) { 38 const v8::Arguments& args) {
41 if (args.Length() != 2) 39 if (args.Length() != 2)
42 return v8::Undefined(); 40 return v8::Undefined();
43 41
44 if (!args[0]->IsInt32() || !args[1]->IsString()) 42 if (!args[0]->IsInt32() || !args[1]->IsString())
45 return v8::Undefined(); 43 return v8::Undefined();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 int port_id = -1; 116 int port_id = -1;
119 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( 117 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension(
120 renderview->GetRoutingID(), 118 renderview->GetRoutingID(),
121 source_id, 119 source_id,
122 target_id, 120 target_id,
123 channel_name, 121 channel_name,
124 &port_id)); 122 &port_id));
125 return v8::Integer::New(port_id); 123 return v8::Integer::New(port_id);
126 } 124 }
127 125
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
160 } // namespace extensions 126 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698