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/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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 extensions::ExtensionSystem::Get(profile)->extension_service(); | 209 extensions::ExtensionSystem::Get(profile)->extension_service(); |
210 bool has_permission = false; | 210 bool has_permission = false; |
211 if (extension_service) { | 211 if (extension_service) { |
212 const Extension* extension = | 212 const Extension* extension = |
213 extension_service->GetExtensionById(source_extension_id, false); | 213 extension_service->GetExtensionById(source_extension_id, false); |
214 has_permission = extension && extension->HasAPIPermission( | 214 has_permission = extension && extension->HasAPIPermission( |
215 APIPermission::kNativeMessaging); | 215 APIPermission::kNativeMessaging); |
216 } | 216 } |
217 | 217 |
218 if (!has_permission) { | 218 if (!has_permission) { |
219 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 219 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, std::string()); |
220 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), | 220 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), |
221 kMissingPermissionError); | 221 kMissingPermissionError); |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 WebContents* source_contents = tab_util::GetWebContentsByID( | 225 WebContents* source_contents = tab_util::GetWebContentsByID( |
226 source_process_id, source_routing_id); | 226 source_process_id, source_routing_id); |
227 | 227 |
228 // Include info about the opener's tab (if it was a tab). | 228 // Include info about the opener's tab (if it was a tab). |
229 std::string tab_json = "null"; | 229 std::string tab_json = "null"; |
(...skipping 10 matching lines...) Expand all Loading... |
240 scoped_ptr<NativeMessageProcessHost> native_process = | 240 scoped_ptr<NativeMessageProcessHost> native_process = |
241 NativeMessageProcessHost::Create( | 241 NativeMessageProcessHost::Create( |
242 base::WeakPtr<NativeMessageProcessHost::Client>( | 242 base::WeakPtr<NativeMessageProcessHost::Client>( |
243 weak_factory_.GetWeakPtr()), | 243 weak_factory_.GetWeakPtr()), |
244 source_extension_id, native_app_name, receiver_port_id); | 244 source_extension_id, native_app_name, receiver_port_id); |
245 | 245 |
246 // Abandon the channel. | 246 // Abandon the channel. |
247 if (!native_process.get()) { | 247 if (!native_process.get()) { |
248 LOG(ERROR) << "Failed to create native process."; | 248 LOG(ERROR) << "Failed to create native process."; |
249 // Treat it as a disconnect. | 249 // Treat it as a disconnect. |
250 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 250 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, std::string()); |
251 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), | 251 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), |
252 kReceivingEndDoesntExistError); | 252 kReceivingEndDoesntExistError); |
253 return; | 253 return; |
254 } | 254 } |
255 channel->receiver.reset(new NativeMessagePort(native_process.release())); | 255 channel->receiver.reset(new NativeMessagePort(native_process.release())); |
256 | 256 |
257 // Keep the opener alive until the channel is closed. | 257 // Keep the opener alive until the channel is closed. |
258 channel->opener->IncrementLazyKeepaliveCount(); | 258 channel->opener->IncrementLazyKeepaliveCount(); |
259 | 259 |
260 AddChannel(channel.release(), receiver_port_id); | 260 AddChannel(channel.release(), receiver_port_id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 channel_name)); | 313 channel_name)); |
314 OpenChannelImpl(params.Pass()); | 314 OpenChannelImpl(params.Pass()); |
315 } | 315 } |
316 | 316 |
317 bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) { | 317 bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) { |
318 if (!params->source) | 318 if (!params->source) |
319 return false; // Closed while in flight. | 319 return false; // Closed while in flight. |
320 | 320 |
321 if (!params->receiver.get() || !params->receiver->GetRenderProcessHost()) { | 321 if (!params->receiver.get() || !params->receiver->GetRenderProcessHost()) { |
322 // Treat it as a disconnect. | 322 // Treat it as a disconnect. |
323 ExtensionMessagePort port(params->source, MSG_ROUTING_CONTROL, ""); | 323 ExtensionMessagePort port( |
| 324 params->source, MSG_ROUTING_CONTROL, std::string()); |
324 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(params->receiver_port_id), | 325 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(params->receiver_port_id), |
325 kReceivingEndDoesntExistError); | 326 kReceivingEndDoesntExistError); |
326 return false; | 327 return false; |
327 } | 328 } |
328 | 329 |
329 // Add extra paranoid CHECKs, since we have crash reports of this being NULL. | 330 // Add extra paranoid CHECKs, since we have crash reports of this being NULL. |
330 // http://code.google.com/p/chromium/issues/detail?id=19067 | 331 // http://code.google.com/p/chromium/issues/detail?id=19067 |
331 CHECK(params->receiver->GetRenderProcessHost()); | 332 CHECK(params->receiver->GetRenderProcessHost()); |
332 | 333 |
333 MessageChannel* channel(new MessageChannel); | 334 MessageChannel* channel(new MessageChannel); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 return; | 518 return; |
518 | 519 |
519 params->source = source; | 520 params->source = source; |
520 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 521 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
521 MSG_ROUTING_CONTROL, | 522 MSG_ROUTING_CONTROL, |
522 params->target_extension_id)); | 523 params->target_extension_id)); |
523 OpenChannelImpl(params.Pass()); | 524 OpenChannelImpl(params.Pass()); |
524 } | 525 } |
525 | 526 |
526 } // namespace extensions | 527 } // namespace extensions |
OLD | NEW |