OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/public/browser/message_port_provider.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/message_port_message_filter.h" |
| 10 #include "content/browser/message_port_service.h" |
| 11 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/view_messages.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 void MessagePortProvider::PostMessageToFrame( |
| 19 WebContents* web_contents, |
| 20 const base::string16& source_origin, |
| 21 const base::string16& target_origin, |
| 22 const base::string16& data, |
| 23 const std::vector<int>& ports) { |
| 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 25 |
| 26 RenderViewHost* rvh = web_contents->GetRenderViewHost(); |
| 27 if (!rvh) |
| 28 return; |
| 29 |
| 30 ViewMsg_PostMessage_Params params; |
| 31 params.is_data_raw_string = true; |
| 32 params.data = data; |
| 33 params.source_routing_id = web_contents->GetRoutingID(); |
| 34 params.source_origin = source_origin; |
| 35 params.target_origin = target_origin; |
| 36 RenderProcessHostImpl* rph = |
| 37 static_cast<RenderProcessHostImpl*>( |
| 38 web_contents->GetRenderProcessHost()); |
| 39 MessagePortMessageFilter* mf = rph->message_port_message_filter(); |
| 40 |
| 41 if (!ports.empty()) { |
| 42 params.message_port_ids = ports; |
| 43 mf->UpdateMessagePortsWithNewRoutes(params.message_port_ids, |
| 44 ¶ms.new_routing_ids); |
| 45 } |
| 46 rvh->Send(new ViewMsg_PostMessageEvent( |
| 47 web_contents->GetRenderViewHost()->GetRoutingID(), |
| 48 params)); |
| 49 } |
| 50 |
| 51 void MessagePortProvider::CreateMessageChannel(WebContents* web_contents, |
| 52 int* port1, |
| 53 int* port2) { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 55 |
| 56 *port1 = 0; |
| 57 *port2 = 0; |
| 58 |
| 59 RenderProcessHostImpl* rph = |
| 60 static_cast<RenderProcessHostImpl*>( |
| 61 web_contents->GetRenderProcessHost()); |
| 62 MessagePortMessageFilter* mf = rph->message_port_message_filter(); |
| 63 MessagePortService* msp = MessagePortService::GetInstance(); |
| 64 msp->Create(mf->GetNextRoutingID(), mf, port1); |
| 65 msp->Create(mf->GetNextRoutingID(), mf, port2); |
| 66 } |
| 67 |
| 68 } // namespace content |
OLD | NEW |