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) |
| 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 |
| 31 #if defined(OS_ANDROID) |
| 32 BrowserThread::PostTask( |
| 33 BrowserThread::IO, FROM_HERE, |
| 34 base::Bind(&content::AppWebMessagePortServiceImpl::RemoveSentPorts, |
| 35 base::Unretained(AppWebMessagePortServiceImpl::GetInstance()), |
| 36 ports)); |
| 37 #endif |
27 FrameMsg_PostMessage_Params params; | 38 FrameMsg_PostMessage_Params params; |
28 params.is_data_raw_string = true; | 39 params.is_data_raw_string = true; |
29 params.data = data; | 40 params.data = data; |
30 params.source_routing_id = MSG_ROUTING_NONE; | 41 params.source_routing_id = MSG_ROUTING_NONE; |
31 params.source_origin = source_origin; | 42 params.source_origin = source_origin; |
32 params.target_origin = target_origin; | 43 params.target_origin = target_origin; |
33 params.message_ports = ports; | 44 params.message_ports = ports; |
34 | 45 |
35 RenderProcessHostImpl* rph = | 46 RenderProcessHostImpl* rph = |
36 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost()); | 47 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost()); |
37 BrowserThread::PostTask( | 48 BrowserThread::PostTask( |
38 BrowserThread::IO, FROM_HERE, | 49 BrowserThread::IO, FROM_HERE, |
39 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, | 50 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts, |
40 rph->message_port_message_filter(), | 51 rph->message_port_message_filter(), |
41 web_contents->GetMainFrame()->GetRoutingID(), params)); | 52 web_contents->GetMainFrame()->GetRoutingID(), params)); |
42 } | 53 } |
43 | 54 |
| 55 #if defined(OS_ANDROID) |
44 // static | 56 // static |
45 void MessagePortProvider::CreateMessageChannel(MessagePortDelegate* delegate, | 57 AppWebMessagePortService* MessagePortProvider::GetAppWebMessagePortService() { |
46 int* port1, | 58 return AppWebMessagePortServiceImpl::GetInstance(); |
47 int* port2) { | |
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 } | 59 } |
61 | 60 #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 | 61 |
108 } // namespace content | 62 } // namespace content |
OLD | NEW |