Chromium Code Reviews| 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 "content/browser/browser_thread_impl.h" | 7 #include "content/browser/browser_thread_impl.h" |
| 8 #include "content/browser/message_port_message_filter.h" | 8 #include "content/browser/message_port_message_filter.h" |
| 9 #include "content/browser/message_port_service.h" | 9 #include "content/browser/message_port_service.h" |
| 10 #include "content/browser/renderer_host/render_process_host_impl.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/common/frame_messages.h" | 13 #include "content/common/frame_messages.h" |
| 14 #include "content/public/browser/message_port_delegate.h" | 14 #include "content/public/browser/message_port_delegate.h" |
| 15 | 15 |
| 16 #if defined(OS_ANDROID) | |
|
sgurun-gerrit only
2016/09/30 23:40:59
this sounds like the code is not well spread betwe
Yusuf
2016/10/04 21:33:14
We still need the PostMessageToFrame since it is u
| |
| 17 #include "content/browser/android/app_web_message_port_service_impl.h" | |
| 18 #endif | |
| 19 | |
| 16 namespace content { | 20 namespace content { |
| 17 | 21 |
| 18 // static | 22 // static |
| 19 void MessagePortProvider::PostMessageToFrame( | 23 void MessagePortProvider::PostMessageToFrame( |
| 20 WebContents* web_contents, | 24 WebContents* web_contents, |
| 21 const base::string16& source_origin, | 25 const base::string16& source_origin, |
| 22 const base::string16& target_origin, | 26 const base::string16& target_origin, |
| 23 const base::string16& data, | 27 const base::string16& data, |
| 24 const std::vector<int>& ports) { | 28 const std::vector<int>& ports) { |
| 25 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 26 | 30 |
| 27 FrameMsg_PostMessage_Params params; | 31 FrameMsg_PostMessage_Params params; |
| 28 params.is_data_raw_string = true; | 32 params.is_data_raw_string = true; |
| 29 params.data = data; | 33 params.data = data; |
| 30 params.source_routing_id = MSG_ROUTING_NONE; | 34 params.source_routing_id = MSG_ROUTING_NONE; |
| 31 params.source_origin = source_origin; | 35 params.source_origin = source_origin; |
| 32 params.target_origin = target_origin; | 36 params.target_origin = target_origin; |
| 33 params.message_ports = ports; | 37 params.message_ports = ports; |
| 34 | 38 |
| 35 RenderProcessHostImpl* rph = | 39 RenderProcessHostImpl* rph = |
| 36 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost()); | 40 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost()); |
| 37 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
| 38 BrowserThread::IO, FROM_HERE, | 42 BrowserThread::IO, FROM_HERE, |
| 39 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, | 43 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, |
| 40 rph->message_port_message_filter(), | 44 rph->message_port_message_filter(), |
| 41 web_contents->GetMainFrame()->GetRoutingID(), params)); | 45 web_contents->GetMainFrame()->GetRoutingID(), params)); |
| 42 } | 46 } |
| 43 | 47 |
| 44 // static | 48 #if defined(OS_ANDROID) |
| 45 void MessagePortProvider::CreateMessageChannel(MessagePortDelegate* delegate, | 49 //static |
| 46 int* port1, | 50 AppWebMessagePortService* MessagePortProvider::GetAppWebMessagePortService() { |
| 47 int* port2) { | 51 return AppWebMessagePortServiceImpl::GetInstance(); |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 49 *port1 = 0; | |
| 50 *port2 = 0; | |
| 51 MessagePortService* msp = MessagePortService::GetInstance(); | |
| 52 msp->Create(MSG_ROUTING_NONE, delegate, port1); | |
| 53 msp->Create(MSG_ROUTING_NONE, delegate, port2); | |
| 54 // Update the routing number of the message ports to be equal to the message | |
| 55 // port numbers. | |
| 56 msp->UpdateMessagePort(*port1, delegate, *port1); | |
| 57 msp->UpdateMessagePort(*port2, delegate, *port2); | |
| 58 msp->Entangle(*port1, *port2); | |
| 59 msp->Entangle(*port2, *port1); | |
| 60 } | 52 } |
| 61 | 53 #endif |
| 62 // static | |
| 63 void MessagePortProvider::PostMessageToPort( | |
| 64 int sender_port_id, | |
| 65 const base::string16& message, | |
| 66 const std::vector<int>& sent_ports) { | |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 68 MessagePortService* msp = MessagePortService::GetInstance(); | |
| 69 msp->PostMessage(sender_port_id, message, sent_ports); | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 void MessagePortProvider::ClosePort(int message_port_id) { | |
| 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 75 MessagePortService* msp = MessagePortService::GetInstance(); | |
| 76 msp->ClosePort(message_port_id); | |
| 77 } | |
| 78 | |
| 79 // static | |
| 80 void MessagePortProvider::HoldMessages(int message_port_id) { | |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 82 MessagePortService* msp = MessagePortService::GetInstance(); | |
| 83 msp->HoldMessages(message_port_id); | |
| 84 } | |
| 85 | |
| 86 // static | |
| 87 void MessagePortProvider::ReleaseMessages(int message_port_id) { | |
| 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 89 MessagePortService* msp = MessagePortService::GetInstance(); | |
| 90 msp->ReleaseMessages(message_port_id); | |
| 91 } | |
| 92 | |
| 93 // static | |
| 94 void MessagePortProvider::OnMessagePortDelegateClosing( | |
| 95 MessagePortDelegate* delegate) { | |
| 96 MessagePortService::GetInstance()->OnMessagePortDelegateClosing(delegate); | |
| 97 } | |
| 98 | |
| 99 // static | |
| 100 void MessagePortProvider::UpdateMessagePort(int message_port_id, | |
| 101 MessagePortDelegate* delegate) { | |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 103 MessagePortService::GetInstance()->UpdateMessagePort(message_port_id, | |
| 104 delegate, | |
| 105 message_port_id); | |
| 106 } | |
| 107 | 54 |
| 108 } // namespace content | 55 } // namespace content |
| OLD | NEW |