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

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

Issue 12218099: Disable native messaging in non-supported configurations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « no previous file | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(OS_WIN) || defined(OS_MAXOSX) || defined(OS_LINUX)
191 content::RenderProcessHost* source = 192 content::RenderProcessHost* source =
192 content::RenderProcessHost::FromID(source_process_id); 193 content::RenderProcessHost::FromID(source_process_id);
193 if (!source) 194 if (!source)
194 return; 195 return;
195 196
196 WebContents* source_contents = tab_util::GetWebContentsByID( 197 WebContents* source_contents = tab_util::GetWebContentsByID(
197 source_process_id, source_routing_id); 198 source_process_id, source_routing_id);
198 199
199 // 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).
200 std::string tab_json = "null"; 201 std::string tab_json = "null";
201 if (source_contents) { 202 if (source_contents) {
202 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( 203 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue(
203 source_contents)); 204 source_contents));
204 base::JSONWriter::Write(tab_value.get(), &tab_json); 205 base::JSONWriter::Write(tab_value.get(), &tab_json);
205 } 206 }
206 207
207 scoped_ptr<MessageChannel> channel(new MessageChannel()); 208 scoped_ptr<MessageChannel> channel(new MessageChannel());
208 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, 209 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL,
209 source_extension_id)); 210 source_extension_id));
210 211
211 scoped_ptr<NativeMessageProcessHost> native_process = 212 scoped_ptr<NativeMessageProcessHost> native_process =
212 NativeMessageProcessHost::Create( 213 NativeMessageProcessHost::Create(
213 base::WeakPtr<NativeMessageProcessHost::Client>( 214 base::WeakPtr<NativeMessageProcessHost::Client>(
214 weak_factory_.GetWeakPtr()), 215 weak_factory_.GetWeakPtr()),
215 native_app_name, receiver_port_id); 216 native_app_name, receiver_port_id);
216 217
217 // Abandon the channel 218 // Abandon the channel
218 if (!native_process.get()) { 219 if (!native_process.get()) {
219 LOG(ERROR) << "Failed to create native process."; 220 LOG(ERROR) << "Failed to create native process.";
221 // Treat it as a disconnect.
222 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, "");
223 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), true);
220 return; 224 return;
221 } 225 }
222 channel->receiver.reset(new NativeMessagePort(native_process.release())); 226 channel->receiver.reset(new NativeMessagePort(native_process.release()));
223 227
224 // Keep the opener alive until the channel is closed. 228 // Keep the opener alive until the channel is closed.
225 channel->opener->IncrementLazyKeepaliveCount(); 229 channel->opener->IncrementLazyKeepaliveCount();
226 230
227 AddChannel(channel.release(), receiver_port_id); 231 AddChannel(channel.release(), receiver_port_id);
232 #else // defined(OS_WIN) || defined(OS_MAXOSX) || defined(OS_LINUX)
233 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, "");
234 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), true);
235 #endif // !(defined(OS_WIN) || defined(OS_MAXOSX) || defined(OS_LINUX))
Matt Perry 2013/02/11 22:44:54 nit: These comments seem backwards to me. The endi
Sergey Ulanov 2013/02/13 01:15:25 Done.
228 } 236 }
229 237
230 void MessageService::OpenChannelToTab( 238 void MessageService::OpenChannelToTab(
231 int source_process_id, int source_routing_id, int receiver_port_id, 239 int source_process_id, int source_routing_id, int receiver_port_id,
232 int tab_id, const std::string& extension_id, 240 int tab_id, const std::string& extension_id,
233 const std::string& channel_name) { 241 const std::string& channel_name) {
234 content::RenderProcessHost* source = 242 content::RenderProcessHost* source =
235 content::RenderProcessHost::FromID(source_process_id); 243 content::RenderProcessHost::FromID(source_process_id);
236 if (!source) 244 if (!source)
237 return; 245 return;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return; 483 return;
476 484
477 params->source = source; 485 params->source = source;
478 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), 486 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(),
479 MSG_ROUTING_CONTROL, 487 MSG_ROUTING_CONTROL,
480 params->target_extension_id)); 488 params->target_extension_id));
481 OpenChannelImpl(params.Pass()); 489 OpenChannelImpl(params.Pass());
482 } 490 }
483 491
484 } // namespace extensions 492 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698