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

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

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Address feedback from yusuf Created 3 years, 10 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
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 "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/message_port_message_filter.h"
9 #include "content/browser/message_port_service.h"
10 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/common/frame_messages.h" 11 #include "content/common/frame_messages.h"
14 #include "content/public/browser/message_port_delegate.h"
15 12
16 #if defined(OS_ANDROID) 13 #if defined(OS_ANDROID)
17 #include "content/browser/android/app_web_message_port_service_impl.h" 14 #include "base/android/jni_string.h"
15 #include "content/browser/android/app_web_message_port.h"
18 #endif 16 #endif
19 17
20 namespace content { 18 namespace content {
19 namespace {
20
21 void PostMessageToFrameInternal(
22 WebContents* web_contents,
23 const base::string16& source_origin,
24 const base::string16& target_origin,
25 const base::string16& data,
26 std::vector<MessagePort> ports) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI);
28
29 FrameMsg_PostMessage_Params params;
30 params.is_data_raw_string = true;
31 params.data = data;
32 params.source_routing_id = MSG_ROUTING_NONE;
33 params.source_origin = source_origin;
34 params.target_origin = target_origin;
35 params.message_ports = std::move(ports);
36
37 RenderFrameHost* rfh = web_contents->GetMainFrame();
38 rfh->Send(new FrameMsg_PostMessageEvent(rfh->GetRoutingID(), params));
39 }
40
41 #if defined(OS_ANDROID)
42 base::string16 ToString16(JNIEnv* env,
43 const base::android::JavaParamRef<jstring>& s) {
44 if (s.is_null())
45 return base::string16();
46 return base::android::ConvertJavaStringToUTF16(env, s);
47 }
48 #endif
49
50 } // namespace
21 51
22 // static 52 // static
23 void MessagePortProvider::PostMessageToFrame( 53 void MessagePortProvider::PostMessageToFrame(
24 WebContents* web_contents, 54 WebContents* web_contents,
25 const base::string16& source_origin, 55 const base::string16& source_origin,
26 const base::string16& target_origin, 56 const base::string16& target_origin,
27 const base::string16& data, 57 const base::string16& data) {
28 const std::vector<int>& ports) { 58 PostMessageToFrameInternal(web_contents, source_origin, target_origin, data,
29 DCHECK_CURRENTLY_ON(BrowserThread::UI); 59 std::vector<MessagePort>());
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
38 FrameMsg_PostMessage_Params params;
39 params.is_data_raw_string = true;
40 params.data = data;
41 params.source_routing_id = MSG_ROUTING_NONE;
42 params.source_origin = source_origin;
43 params.target_origin = target_origin;
44 params.message_ports = ports;
45
46 RenderProcessHostImpl* rph =
47 static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost());
48 BrowserThread::PostTask(
49 BrowserThread::IO, FROM_HERE,
50 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts,
51 rph->message_port_message_filter(),
52 web_contents->GetMainFrame()->GetRoutingID(), params));
53 } 60 }
54 61
55 #if defined(OS_ANDROID) 62 #if defined(OS_ANDROID)
56 // static 63 void MessagePortProvider::PostMessageToFrame(
57 AppWebMessagePortService* MessagePortProvider::GetAppWebMessagePortService() { 64 WebContents* web_contents,
58 return AppWebMessagePortServiceImpl::GetInstance(); 65 JNIEnv* env,
66 const base::android::JavaParamRef<jstring>& source_origin,
67 const base::android::JavaParamRef<jstring>& target_origin,
68 const base::android::JavaParamRef<jstring>& data,
69 const base::android::JavaParamRef<jobjectArray>& ports) {
70 PostMessageToFrameInternal(
71 web_contents,
72 ToString16(env, source_origin),
73 ToString16(env, target_origin),
74 ToString16(env, data),
75 AppWebMessagePort::UnwrapJavaArray(env, ports));
59 } 76 }
60 #endif 77 #endif
61 78
62 } // namespace content 79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698