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

Side by Side Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 11968028: Remove connect message from Native Messaging API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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/browser/extensions/api/messaging/message_service.h" 5 #include "chrome/browser/extensions/api/messaging/message_service.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 OpenChannelImpl(scoped_ptr<OpenChannelParams>(params)); 182 OpenChannelImpl(scoped_ptr<OpenChannelParams>(params));
183 } 183 }
184 184
185 void MessageService::OpenChannelToNativeApp( 185 void MessageService::OpenChannelToNativeApp(
186 int source_process_id, 186 int source_process_id,
187 int source_routing_id, 187 int source_routing_id,
188 int receiver_port_id, 188 int receiver_port_id,
189 const std::string& source_extension_id, 189 const std::string& source_extension_id,
190 const std::string& native_app_name, 190 const std::string& native_app_name,
191 const std::string& channel_name, 191 const std::string& channel_name) {
192 const std::string& connect_message) {
193 content::RenderProcessHost* source = 192 content::RenderProcessHost* source =
194 content::RenderProcessHost::FromID(source_process_id); 193 content::RenderProcessHost::FromID(source_process_id);
195 if (!source) 194 if (!source)
196 return; 195 return;
197 196
198 WebContents* source_contents = tab_util::GetWebContentsByID( 197 WebContents* source_contents = tab_util::GetWebContentsByID(
199 source_process_id, source_routing_id); 198 source_process_id, source_routing_id);
200 199
201 // Include info about the opener's tab (if it was a tab). 200 // Include info about the opener's tab (if it was a tab).
202 std::string tab_json = "null"; 201 std::string tab_json = "null";
203 if (source_contents) { 202 if (source_contents) {
204 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( 203 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue(
205 source_contents)); 204 source_contents));
206 base::JSONWriter::Write(tab_value.get(), &tab_json); 205 base::JSONWriter::Write(tab_value.get(), &tab_json);
207 } 206 }
208 207
209 scoped_ptr<MessageChannel> channel(new MessageChannel()); 208 scoped_ptr<MessageChannel> channel(new MessageChannel());
210 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, 209 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL,
211 source_extension_id)); 210 source_extension_id));
212 211
213 NativeMessageProcessHost::MessageType type =
214 channel_name == "chrome.runtime.sendNativeMessage" ?
215 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST :
216 NativeMessageProcessHost::TYPE_CONNECT;
217
218 content::BrowserThread::PostTask( 212 content::BrowserThread::PostTask(
219 content::BrowserThread::FILE, 213 content::BrowserThread::FILE,
220 FROM_HERE, 214 FROM_HERE,
221 base::Bind(&NativeMessageProcessHost::Create, 215 base::Bind(&NativeMessageProcessHost::Create,
222 base::WeakPtr<NativeMessageProcessHost::Client>( 216 base::WeakPtr<NativeMessageProcessHost::Client>(
223 weak_factory_.GetWeakPtr()), 217 weak_factory_.GetWeakPtr()),
224 native_app_name, connect_message, receiver_port_id, 218 native_app_name, receiver_port_id,
225 type,
226 base::Bind(&MessageService::FinalizeOpenChannelToNativeApp, 219 base::Bind(&MessageService::FinalizeOpenChannelToNativeApp,
227 weak_factory_.GetWeakPtr(), 220 weak_factory_.GetWeakPtr(),
228 receiver_port_id, 221 receiver_port_id,
229 channel_name, 222 channel_name,
230 base::Passed(&channel), 223 base::Passed(&channel),
231 tab_json))); 224 tab_json)));
232 } 225 }
233 226
234 void MessageService::FinalizeOpenChannelToNativeApp( 227 void MessageService::FinalizeOpenChannelToNativeApp(
235 int receiver_port_id, 228 int receiver_port_id,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return; 493 return;
501 494
502 params->source = source; 495 params->source = source;
503 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), 496 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(),
504 MSG_ROUTING_CONTROL, 497 MSG_ROUTING_CONTROL,
505 params->target_extension_id)); 498 params->target_extension_id));
506 OpenChannelImpl(params.Pass()); 499 OpenChannelImpl(params.Pass());
507 } 500 }
508 501
509 } // namespace extensions 502 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698