Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: content/browser/message_port_provider.cc

Issue 831523004: Enable posting a message from JS to Android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add v8 as a dependency Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/message_port_message_filter.h ('k') | content/browser/message_port_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(
19 WebContents* web_contents, 21 WebContents* web_contents,
20 const base::string16& source_origin, 22 const base::string16& source_origin,
sgurun-gerrit only 2015/01/06 17:57:06 passing web_contents to IO thread is not safe. We
sgurun-gerrit only 2015/01/10 02:36:29 Done.
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));
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;
(...skipping 10 matching lines...) Expand all
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 &params.new_routing_ids); 46 &params.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
OLDNEW
« no previous file with comments | « content/browser/message_port_message_filter.h ('k') | content/browser/message_port_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698