| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/public/browser/message_port_provider.h" | 5 #include "content/public/browser/message_port_provider.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
| 10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
| 11 #include "content/browser/renderer_host/render_process_host_impl.h" | 11 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 12 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/view_messages.h" | 14 #include "content/common/frame_messages.h" |
| 15 #include "content/public/browser/message_port_delegate.h" | 15 #include "content/public/browser/message_port_delegate.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 // static | 19 // static |
| 20 void MessagePortProvider::PostMessageToFrame( | 20 void MessagePortProvider::PostMessageToFrame( |
| 21 WebContents* web_contents, | 21 WebContents* web_contents, |
| 22 const base::string16& source_origin, | 22 const base::string16& source_origin, |
| 23 const base::string16& target_origin, | 23 const base::string16& target_origin, |
| 24 const base::string16& data, | 24 const base::string16& data, |
| 25 const std::vector<TransferredMessagePort>& ports) { | 25 const std::vector<TransferredMessagePort>& ports) { |
| 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 27 | 27 |
| 28 ViewMsg_PostMessage_Params params; | 28 FrameMsg_PostMessage_Params params; |
| 29 params.is_data_raw_string = true; | 29 params.is_data_raw_string = true; |
| 30 params.data = data; | 30 params.data = data; |
| 31 // Blink requires a source frame to transfer ports. This is why a | 31 // Blink requires a source frame to transfer ports. This is why a |
| 32 // source routing id is set here. See WebDOMMessageEvent::initMessageEvent() | 32 // source routing id is set here. See WebDOMMessageEvent::initMessageEvent() |
| 33 params.source_routing_id = web_contents->GetRoutingID(); | 33 // TODO(alexmos, sgurun): Clean this up once crbug.com/473258 is fixed. |
| 34 // Once message ports can work with a null source frame, |
| 35 // source_view_routing_id can be removed, and this can just pass in |
| 36 // MSG_ROUTING_NONE for the source frame. |
| 37 params.source_view_routing_id = web_contents->GetRoutingID(); |
| 38 params.source_routing_id = MSG_ROUTING_NONE; |
| 34 params.source_origin = source_origin; | 39 params.source_origin = source_origin; |
| 35 params.target_origin = target_origin; | 40 params.target_origin = target_origin; |
| 36 params.message_ports = ports; | 41 params.message_ports = ports; |
| 37 | 42 |
| 38 RenderProcessHostImpl* rph = | 43 RenderProcessHostImpl* rph = |
| 39 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost()); | 44 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost()); |
| 40 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 41 BrowserThread::IO, FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
| 42 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, | 47 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, |
| 43 rph->message_port_message_filter(), | 48 rph->message_port_message_filter(), |
| 44 web_contents->GetRoutingID(), params)); | 49 web_contents->GetMainFrame()->GetRoutingID(), params)); |
| 45 } | 50 } |
| 46 | 51 |
| 47 // static | 52 // static |
| 48 void MessagePortProvider::CreateMessageChannel(MessagePortDelegate* delegate, | 53 void MessagePortProvider::CreateMessageChannel(MessagePortDelegate* delegate, |
| 49 int* port1, | 54 int* port1, |
| 50 int* port2) { | 55 int* port2) { |
| 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 52 *port1 = 0; | 57 *port1 = 0; |
| 53 *port2 = 0; | 58 *port2 = 0; |
| 54 MessagePortService* msp = MessagePortService::GetInstance(); | 59 MessagePortService* msp = MessagePortService::GetInstance(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // static | 107 // static |
| 103 void MessagePortProvider::UpdateMessagePort(int message_port_id, | 108 void MessagePortProvider::UpdateMessagePort(int message_port_id, |
| 104 MessagePortDelegate* delegate) { | 109 MessagePortDelegate* delegate) { |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 106 MessagePortService::GetInstance()->UpdateMessagePort(message_port_id, | 111 MessagePortService::GetInstance()->UpdateMessagePort(message_port_id, |
| 107 delegate, | 112 delegate, |
| 108 message_port_id); | 113 message_port_id); |
| 109 } | 114 } |
| 110 | 115 |
| 111 } // namespace content | 116 } // namespace content |
| OLD | NEW |