| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "android_webview/native/aw_message_port_service_impl.h" | 5 #include "android_webview/native/aw_message_port_service_impl.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/aw_message_port_message_filter.h" | 8 #include "android_webview/browser/aw_message_port_message_filter.h" |
| 9 #include "android_webview/native/aw_contents.h" | 9 #include "android_webview/native/aw_contents.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 LOG(WARNING) << "Converting post message to a string failed for port " | 89 LOG(WARNING) << "Converting post message to a string failed for port " |
| 90 << message_port_id; | 90 << message_port_id; |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (message.GetSize() != 1) { | 94 if (message.GetSize() != 1) { |
| 95 NOTREACHED(); | 95 NOTREACHED(); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Add the ports to AwMessagePortService. |
| 100 for (const auto& iter : sent_message_port_ids) { |
| 101 AddPort(iter, ports_[message_port_id]); |
| 102 } |
| 103 |
| 99 ScopedJavaLocalRef<jstring> jmsg = ConvertUTF16ToJavaString(env, value); | 104 ScopedJavaLocalRef<jstring> jmsg = ConvertUTF16ToJavaString(env, value); |
| 100 ScopedJavaLocalRef<jintArray> jports = | 105 ScopedJavaLocalRef<jintArray> jports = |
| 101 ToJavaIntArray(env, sent_message_port_ids); | 106 ToJavaIntArray(env, sent_message_port_ids); |
| 102 Java_AwMessagePortService_onReceivedMessage(env, | 107 Java_AwMessagePortService_onReceivedMessage(env, |
| 103 jobj.obj(), | 108 jobj.obj(), |
| 104 message_port_id, | 109 message_port_id, |
| 105 jmsg.obj(), | 110 jmsg.obj(), |
| 106 jports.obj()); | 111 jports.obj()); |
| 107 } | 112 } |
| 108 | 113 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 int* port2) { | 208 int* port2) { |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 209 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 205 JNIEnv* env = AttachCurrentThread(); | 210 JNIEnv* env = AttachCurrentThread(); |
| 206 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 211 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 207 if (obj.is_null()) | 212 if (obj.is_null()) |
| 208 return; | 213 return; |
| 209 Java_AwMessagePortService_onMessageChannelCreated(env, obj.obj(), *port1, | 214 Java_AwMessagePortService_onMessageChannelCreated(env, obj.obj(), *port1, |
| 210 *port2, ports->obj()); | 215 *port2, ports->obj()); |
| 211 } | 216 } |
| 212 | 217 |
| 218 // Adds a new port to the message port service. |
| 213 void AwMessagePortServiceImpl::AddPort(int message_port_id, | 219 void AwMessagePortServiceImpl::AddPort(int message_port_id, |
| 214 AwMessagePortMessageFilter* filter) { | 220 AwMessagePortMessageFilter* filter) { |
| 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 216 if (ports_.count(message_port_id)) { | 222 if (ports_.count(message_port_id)) { |
| 217 NOTREACHED(); | 223 NOTREACHED(); |
| 218 return; | 224 return; |
| 219 } | 225 } |
| 220 ports_[message_port_id] = filter; | 226 ports_[message_port_id] = filter; |
| 221 } | 227 } |
| 222 | 228 |
| 223 bool RegisterAwMessagePortService(JNIEnv* env) { | 229 bool RegisterAwMessagePortService(JNIEnv* env) { |
| 224 return RegisterNativesImpl(env); | 230 return RegisterNativesImpl(env); |
| 225 } | 231 } |
| 226 | 232 |
| 227 // static | 233 // static |
| 228 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) { | 234 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) { |
| 229 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); | 235 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); |
| 230 service->Init(env, obj); | 236 service->Init(env, obj); |
| 231 return reinterpret_cast<intptr_t>(service); | 237 return reinterpret_cast<intptr_t>(service); |
| 232 } | 238 } |
| 233 | 239 |
| 234 } // namespace android_webview | 240 } // namespace android_webview |
| OLD | NEW |