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

Side by Side Diff: content/browser/android/app_web_message_port.cc

Issue 2755223002: Enable Blink to pass extra Mojo handles across MessagePorts
Patch Set: Finish plumbing Created 3 years, 9 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 | « no previous file | content/child/webmessageportchannel_impl.h » ('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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/browser/android/app_web_message_port.h" 5 #include "content/browser/android/app_web_message_port.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "content/browser/android/string_message_codec.h" 10 #include "content/browser/android/string_message_codec.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 delete this; 56 delete this;
57 } 57 }
58 58
59 void AppWebMessagePort::PostMessage( 59 void AppWebMessagePort::PostMessage(
60 JNIEnv* env, 60 JNIEnv* env,
61 const base::android::JavaParamRef<jobject>& jcaller, 61 const base::android::JavaParamRef<jobject>& jcaller,
62 const base::android::JavaParamRef<jstring>& jmessage, 62 const base::android::JavaParamRef<jstring>& jmessage,
63 const base::android::JavaParamRef<jobjectArray>& jports) { 63 const base::android::JavaParamRef<jobjectArray>& jports) {
64 port_.PostMessage( 64 port_.PostMessage(
65 EncodeStringMessage(base::android::ConvertJavaStringToUTF16(jmessage)), 65 EncodeStringMessage(base::android::ConvertJavaStringToUTF16(jmessage)),
66 UnwrapJavaArray(env, jports)); 66 UnwrapJavaArray(env, jports), std::vector<mojo::ScopedHandle>());
67 } 67 }
68 68
69 jboolean AppWebMessagePort::DispatchNextMessage( 69 jboolean AppWebMessagePort::DispatchNextMessage(
70 JNIEnv* env, 70 JNIEnv* env,
71 const base::android::JavaParamRef<jobject>& jcaller) { 71 const base::android::JavaParamRef<jobject>& jcaller) {
72 base::android::ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 72 base::android::ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
73 if (obj.is_null()) 73 if (obj.is_null())
74 return false; 74 return false;
75 75
76 jmethodID app_web_message_port_constructor = 76 jmethodID app_web_message_port_constructor =
77 base::android::MethodID::Get<base::android::MethodID::TYPE_INSTANCE>( 77 base::android::MethodID::Get<base::android::MethodID::TYPE_INSTANCE>(
78 env, AppWebMessagePort_clazz(env), "<init>", "()V"); 78 env, AppWebMessagePort_clazz(env), "<init>", "()V");
79 79
80 base::string16 encoded_message; 80 base::string16 encoded_message;
81 std::vector<MessagePort> ports; 81 std::vector<MessagePort> ports;
82 if (!port_.GetMessage(&encoded_message, &ports)) 82 std::vector<mojo::ScopedHandle> handles;
83 if (!port_.GetMessage(&encoded_message, &ports, &handles))
83 return false; 84 return false;
84 85
86 if (!handles.empty()) {
87 DLOG(WARNING) << "Unexpected handles";
88 return false;
89 }
90
85 base::string16 message; 91 base::string16 message;
86 if (!DecodeStringMessage(encoded_message, &message)) 92 if (!DecodeStringMessage(encoded_message, &message))
87 return false; 93 return false;
88 94
89 base::android::ScopedJavaLocalRef<jstring> jmessage = 95 base::android::ScopedJavaLocalRef<jstring> jmessage =
90 base::android::ConvertUTF16ToJavaString(env, message); 96 base::android::ConvertUTF16ToJavaString(env, message);
91 97
92 base::android::ScopedJavaLocalRef<jobjectArray> jports; 98 base::android::ScopedJavaLocalRef<jobjectArray> jports;
93 if (ports.size() > 0) { 99 if (ports.size() > 0) {
94 jports = base::android::ScopedJavaLocalRef<jobjectArray>( 100 jports = base::android::ScopedJavaLocalRef<jobjectArray>(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 AppWebMessagePort::CreateAndBindToJavaObject( 164 AppWebMessagePort::CreateAndBindToJavaObject(
159 env, std::move(pipe.handle0), jport0); 165 env, std::move(pipe.handle0), jport0);
160 166
161 base::android::ScopedJavaLocalRef<jobject> jport1( 167 base::android::ScopedJavaLocalRef<jobject> jport1(
162 env, env->GetObjectArrayElement(ports.obj(), 1)); 168 env, env->GetObjectArrayElement(ports.obj(), 1));
163 AppWebMessagePort::CreateAndBindToJavaObject( 169 AppWebMessagePort::CreateAndBindToJavaObject(
164 env, std::move(pipe.handle1), jport1); 170 env, std::move(pipe.handle1), jport1);
165 } 171 }
166 172
167 } // namespace content 173 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webmessageportchannel_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698