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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 if (policy_permission == DISALLOW) { | 396 if (policy_permission == DISALLOW) { |
397 DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError); | 397 DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError); |
398 return; | 398 return; |
399 } | 399 } |
400 | 400 |
401 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 401 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
402 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 402 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
403 source_extension_id)); | 403 source_extension_id)); |
404 | 404 |
405 // Get handle of the native view and pass it to the native messaging host. | 405 // Get handle of the native view and pass it to the native messaging host. |
| 406 content::RenderWidgetHost* render_widget_host = |
| 407 content::RenderWidgetHost::FromID(source_process_id, source_routing_id); |
406 gfx::NativeView native_view = | 408 gfx::NativeView native_view = |
407 content::RenderWidgetHost::FromID(source_process_id, source_routing_id)-> | 409 render_widget_host ? render_widget_host->GetView()->GetNativeView() |
408 GetView()->GetNativeView(); | 410 : nullptr; |
409 | 411 |
410 std::string error = kReceivingEndDoesntExistError; | 412 std::string error = kReceivingEndDoesntExistError; |
411 scoped_ptr<NativeMessageHost> native_host = NativeMessageHost::Create( | 413 scoped_ptr<NativeMessageHost> native_host = NativeMessageHost::Create( |
412 native_view, | 414 native_view, |
413 source_extension_id, | 415 source_extension_id, |
414 native_app_name, | 416 native_app_name, |
415 policy_permission == ALLOW_ALL, | 417 policy_permission == ALLOW_ALL, |
416 &error); | 418 &error); |
417 | 419 |
418 // Abandon the channel. | 420 // Abandon the channel. |
419 if (!native_host.get()) { | 421 if (!native_host.get()) { |
420 LOG(ERROR) << "Failed to create native process."; | 422 LOG(ERROR) << "Failed to create native process."; |
421 DispatchOnDisconnect( | 423 DispatchOnDisconnect(source, receiver_port_id, error); |
422 source, receiver_port_id, error); | |
423 return; | 424 return; |
424 } | 425 } |
425 channel->receiver.reset(new NativeMessagePort( | 426 channel->receiver.reset(new NativeMessagePort( |
426 weak_factory_.GetWeakPtr(), receiver_port_id, native_host.Pass())); | 427 weak_factory_.GetWeakPtr(), receiver_port_id, native_host.Pass())); |
427 | 428 |
428 // Keep the opener alive until the channel is closed. | 429 // Keep the opener alive until the channel is closed. |
429 channel->opener->IncrementLazyKeepaliveCount(); | 430 channel->opener->IncrementLazyKeepaliveCount(); |
430 | 431 |
431 AddChannel(channel.release(), receiver_port_id); | 432 AddChannel(channel.release(), receiver_port_id); |
432 #else // !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)) | 433 #else // !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)) |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 int channel_id) { | 867 int channel_id) { |
867 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); | 868 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); |
868 if (channel_iter != channels_.end()) { | 869 if (channel_iter != channels_.end()) { |
869 for (const PendingMessage& message : queue) { | 870 for (const PendingMessage& message : queue) { |
870 DispatchMessage(message.first, channel_iter->second, message.second); | 871 DispatchMessage(message.first, channel_iter->second, message.second); |
871 } | 872 } |
872 } | 873 } |
873 } | 874 } |
874 | 875 |
875 } // namespace extensions | 876 } // namespace extensions |
OLD | NEW |