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 <stdint.h> | 7 #include <stdint.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 BrowserContext* context, | 186 BrowserContext* context, |
187 const std::string& extension_id) { | 187 const std::string& extension_id) { |
188 scoped_refptr<SiteInstance> site_instance = | 188 scoped_refptr<SiteInstance> site_instance = |
189 ProcessManager::Get(context)->GetSiteInstanceForURL( | 189 ProcessManager::Get(context)->GetSiteInstanceForURL( |
190 Extension::GetBaseURLFromExtensionId(extension_id)); | 190 Extension::GetBaseURLFromExtensionId(extension_id)); |
191 return site_instance->HasProcess() ? site_instance->GetProcess() : NULL; | 191 return site_instance->HasProcess() ? site_instance->GetProcess() : NULL; |
192 } | 192 } |
193 | 193 |
194 } // namespace | 194 } // namespace |
195 | 195 |
196 void MessageService::MessagePort::WillConnectToPort(const MessagePort& port) {} | |
197 | |
198 bool MessageService::MessagePort::HasFrame( | |
199 content::RenderFrameHost* rfh) const { | |
200 return false; | |
201 } | |
202 | |
196 // static | 203 // static |
197 void MessageService::AllocatePortIdPair(int* port1, int* port2) { | 204 void MessageService::AllocatePortIdPair(int* port1, int* port2) { |
198 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 205 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
199 | 206 |
200 unsigned channel_id = static_cast<unsigned>(g_next_channel_id.GetNext()) % | 207 unsigned channel_id = static_cast<unsigned>(g_next_channel_id.GetNext()) % |
201 (std::numeric_limits<int32_t>::max() / 2); | 208 (std::numeric_limits<int32_t>::max() / 2); |
202 unsigned port1_id = channel_id * 2; | 209 unsigned port1_id = channel_id * 2; |
203 unsigned port2_id = channel_id * 2 + 1; | 210 unsigned port2_id = channel_id * 2 + 1; |
204 | 211 |
205 // Sanity checks to make sure our channel<->port converters are correct. | 212 // Sanity checks to make sure our channel<->port converters are correct. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 return; | 569 return; |
563 } | 570 } |
564 | 571 |
565 scoped_ptr<MessagePort> opener( | 572 scoped_ptr<MessagePort> opener( |
566 new ExtensionMessagePort(weak_factory_.GetWeakPtr(), | 573 new ExtensionMessagePort(weak_factory_.GetWeakPtr(), |
567 GET_OPPOSITE_PORT_ID(params->receiver_port_id), | 574 GET_OPPOSITE_PORT_ID(params->receiver_port_id), |
568 params->source_extension_id, source, false)); | 575 params->source_extension_id, source, false)); |
569 if (!opener->IsValidPort()) | 576 if (!opener->IsValidPort()) |
570 return; | 577 return; |
571 | 578 |
579 // Remove duplicate frames. | |
Devlin
2016/01/13 17:37:22
Nit: since all this method does is check for dupli
robwu
2016/01/13 19:56:20
Done (renamed to RemoveCommonFrames).
| |
580 params->receiver->WillConnectToPort(*opener); | |
581 if (!params->receiver->IsValidPort()) { | |
582 opener->DispatchOnDisconnect(kReceivingEndDoesntExistError); | |
583 return; | |
584 } | |
585 | |
572 MessageChannel* channel(new MessageChannel()); | 586 MessageChannel* channel(new MessageChannel()); |
573 channel->opener.reset(opener.release()); | 587 channel->opener.reset(opener.release()); |
574 channel->receiver.reset(params->receiver.release()); | 588 channel->receiver.reset(params->receiver.release()); |
575 AddChannel(channel, params->receiver_port_id); | 589 AddChannel(channel, params->receiver_port_id); |
576 | 590 |
577 // TODO(robwu): Could |guest_process_id| and |guest_render_frame_routing_id| | 591 // TODO(robwu): Could |guest_process_id| and |guest_render_frame_routing_id| |
578 // be removed? In the past extension message routing was process-based, but | 592 // be removed? In the past extension message routing was process-based, but |
579 // now that extensions are routed from a specific RFH, the special casing for | 593 // now that extensions are routed from a specific RFH, the special casing for |
580 // guest views seems no longer necessary, because the ExtensionMessagePort can | 594 // guest views seems no longer necessary, because the ExtensionMessagePort can |
581 // simply obtain the source process & frame ID directly from the RFH. | 595 // simply obtain the source process & frame ID directly from the RFH. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 } | 715 } |
702 | 716 |
703 void MessageService::CloseChannelImpl( | 717 void MessageService::CloseChannelImpl( |
704 MessageChannelMap::iterator channel_iter, | 718 MessageChannelMap::iterator channel_iter, |
705 int closing_port_id, | 719 int closing_port_id, |
706 const std::string& error_message, | 720 const std::string& error_message, |
707 bool notify_other_port) { | 721 bool notify_other_port) { |
708 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 722 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
709 | 723 |
710 MessageChannel* channel = channel_iter->second; | 724 MessageChannel* channel = channel_iter->second; |
725 // Remove from map to make sure that it is impossible for CloseChannelImpl to | |
726 // run twice for the same channel. | |
727 channels_.erase(channel_iter); | |
711 | 728 |
712 // Notify the other side. | 729 // Notify the other side. |
713 if (notify_other_port) { | 730 if (notify_other_port) { |
714 MessagePort* port = IS_OPENER_PORT_ID(closing_port_id) ? | 731 MessagePort* port = IS_OPENER_PORT_ID(closing_port_id) ? |
715 channel->receiver.get() : channel->opener.get(); | 732 channel->receiver.get() : channel->opener.get(); |
716 port->DispatchOnDisconnect(error_message); | 733 port->DispatchOnDisconnect(error_message); |
717 } | 734 } |
718 | 735 |
719 // Balance the IncrementLazyKeepaliveCount() in OpenChannelImpl. | 736 // Balance the IncrementLazyKeepaliveCount() in OpenChannelImpl. |
720 channel->opener->DecrementLazyKeepaliveCount(); | 737 channel->opener->DecrementLazyKeepaliveCount(); |
721 channel->receiver->DecrementLazyKeepaliveCount(); | 738 channel->receiver->DecrementLazyKeepaliveCount(); |
722 | 739 |
723 delete channel_iter->second; | 740 delete channel; |
724 channels_.erase(channel_iter); | |
725 } | 741 } |
726 | 742 |
727 void MessageService::PostMessage(int source_port_id, const Message& message) { | 743 void MessageService::PostMessage(int source_port_id, const Message& message) { |
728 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 744 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
729 | 745 |
730 int channel_id = GET_CHANNEL_ID(source_port_id); | 746 int channel_id = GET_CHANNEL_ID(source_port_id); |
731 MessageChannelMap::iterator iter = channels_.find(channel_id); | 747 MessageChannelMap::iterator iter = channels_.find(channel_id); |
732 if (iter == channels_.end()) { | 748 if (iter == channels_.end()) { |
733 // If this channel is pending, queue up the PostMessage to run once | 749 // If this channel is pending, queue up the PostMessage to run once |
734 // the channel opens. | 750 // the channel opens. |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
993 | 1009 |
994 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); | 1010 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); |
995 if (channel_iter != channels_.end()) { | 1011 if (channel_iter != channels_.end()) { |
996 for (const PendingMessage& message : queue) { | 1012 for (const PendingMessage& message : queue) { |
997 DispatchMessage(message.first, channel_iter->second, message.second); | 1013 DispatchMessage(message.first, channel_iter->second, message.second); |
998 } | 1014 } |
999 } | 1015 } |
1000 } | 1016 } |
1001 | 1017 |
1002 } // namespace extensions | 1018 } // namespace extensions |
OLD | NEW |