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/view_messages.h" |
15 #include "content/public/browser/message_port_delegate.h" | |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
19 // static | |
18 void MessagePortProvider::PostMessageToFrame( | 20 void MessagePortProvider::PostMessageToFrame( |
mnaganov (inactive)
2015/01/07 11:43:54
Why do we need to do this on IO thread? Can we pre
sgurun-gerrit only
2015/01/10 02:36:29
Done.
| |
19 WebContents* web_contents, | 21 WebContents* web_contents, |
20 const base::string16& source_origin, | 22 const base::string16& source_origin, |
21 const base::string16& target_origin, | 23 const base::string16& target_origin, |
22 const base::string16& data, | 24 const base::string16& data, |
23 const std::vector<int>& ports) { | 25 const std::vector<int>& ports) { |
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
mnaganov (inactive)
2015/01/07 11:43:54
nit: use DCHECK_CURRENTLY_ON(BrowserThread::IO)
sgurun-gerrit only
2015/01/10 02:36:29
Done.
| |
25 | 27 |
26 RenderViewHost* rvh = web_contents->GetRenderViewHost(); | 28 RenderViewHost* rvh = web_contents->GetRenderViewHost(); |
27 if (!rvh) | 29 if (!rvh) |
28 return; | 30 return; |
29 | 31 |
30 ViewMsg_PostMessage_Params params; | 32 ViewMsg_PostMessage_Params params; |
31 params.is_data_raw_string = true; | 33 params.is_data_raw_string = true; |
32 params.data = data; | 34 params.data = data; |
33 params.source_routing_id = web_contents->GetRoutingID(); | 35 params.source_routing_id = web_contents->GetRoutingID(); |
34 params.source_origin = source_origin; | 36 params.source_origin = source_origin; |
35 params.target_origin = target_origin; | 37 params.target_origin = target_origin; |
36 RenderProcessHostImpl* rph = | 38 RenderProcessHostImpl* rph = |
37 static_cast<RenderProcessHostImpl*>( | 39 static_cast<RenderProcessHostImpl*>( |
38 web_contents->GetRenderProcessHost()); | 40 web_contents->GetRenderProcessHost()); |
39 MessagePortMessageFilter* mf = rph->message_port_message_filter(); | 41 MessagePortMessageFilter* mf = rph->message_port_message_filter(); |
40 | 42 |
41 if (!ports.empty()) { | 43 if (!ports.empty()) { |
42 params.message_port_ids = ports; | 44 params.message_port_ids = ports; |
43 mf->UpdateMessagePortsWithNewRoutes(params.message_port_ids, | 45 mf->UpdateMessagePortsWithNewRoutes(params.message_port_ids, |
44 ¶ms.new_routing_ids); | 46 ¶ms.new_routing_ids); |
45 } | 47 } |
46 rvh->Send(new ViewMsg_PostMessageEvent( | 48 rvh->Send(new ViewMsg_PostMessageEvent( |
47 web_contents->GetRenderViewHost()->GetRoutingID(), | 49 web_contents->GetRenderViewHost()->GetRoutingID(), |
48 params)); | 50 params)); |
49 } | 51 } |
50 | 52 |
51 void MessagePortProvider::CreateMessageChannel(WebContents* web_contents, | 53 // static |
54 void MessagePortProvider::CreateMessageChannel(MessagePortDelegate* delegate, | |
52 int* port1, | 55 int* port1, |
53 int* port2) { | 56 int* port2) { |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
55 | |
56 *port1 = 0; | 58 *port1 = 0; |
57 *port2 = 0; | 59 *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(); | 60 MessagePortService* msp = MessagePortService::GetInstance(); |
64 msp->Create(mf->GetNextRoutingID(), mf, port1); | 61 msp->Create(MSG_ROUTING_NONE, delegate, port1); |
65 msp->Create(mf->GetNextRoutingID(), mf, port2); | 62 msp->Create(MSG_ROUTING_NONE, delegate, port2); |
63 // Update the routing number of the message ports to be equal to the message | |
64 // port numbers. | |
65 msp->UpdateMessagePort(*port1, delegate, *port1); | |
66 msp->UpdateMessagePort(*port2, delegate, *port2); | |
66 msp->Entangle(*port1, *port2); | 67 msp->Entangle(*port1, *port2); |
67 msp->Entangle(*port2, *port1); | 68 msp->Entangle(*port2, *port1); |
68 } | 69 } |
69 | 70 |
71 // static | |
72 void MessagePortProvider::OnMessagePortDelegateClosing( | |
73 MessagePortDelegate* delegate) { | |
74 MessagePortService::GetInstance()->OnMessagePortDelegateClosing(delegate); | |
75 } | |
76 | |
70 } // namespace content | 77 } // namespace content |
OLD | NEW |