Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 NOTREACHED(); | 88 NOTREACHED(); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 base::string16 value; | 92 base::string16 value; |
| 93 if (!message.GetString(0, &value)) { | 93 if (!message.GetString(0, &value)) { |
| 94 LOG(WARNING) << "Converting post message to a string failed for port " | 94 LOG(WARNING) << "Converting post message to a string failed for port " |
| 95 << message_port_id; | 95 << message_port_id; |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | |
| 99 // Add the ports to AwMessagePortService. | |
| 100 for (const auto& iter : sent_message_port_ids) { | |
|
hush (inactive)
2015/03/10 22:31:36
do you really need to use auto? It is just int?
sgurun-gerrit only
2015/03/10 23:20:13
either works.
| |
| 101 AddPort(iter, ports_[message_port_id]); | |
| 102 } | |
| 103 | |
| 98 ScopedJavaLocalRef<jstring> jmsg = ConvertUTF16ToJavaString(env, value); | 104 ScopedJavaLocalRef<jstring> jmsg = ConvertUTF16ToJavaString(env, value); |
| 99 ScopedJavaLocalRef<jintArray> jports = | 105 ScopedJavaLocalRef<jintArray> jports = |
| 100 ToJavaIntArray(env, sent_message_port_ids); | 106 ToJavaIntArray(env, sent_message_port_ids); |
| 101 Java_AwMessagePortService_onReceivedMessage(env, | 107 Java_AwMessagePortService_onReceivedMessage(env, |
| 102 jobj.obj(), | 108 jobj.obj(), |
| 103 message_port_id, | 109 message_port_id, |
| 104 jmsg.obj(), | 110 jmsg.obj(), |
| 105 jports.obj()); | 111 jports.obj()); |
| 106 } | 112 } |
| 107 | 113 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 int* port2) { | 208 int* port2) { |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 209 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 204 JNIEnv* env = AttachCurrentThread(); | 210 JNIEnv* env = AttachCurrentThread(); |
| 205 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 211 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 206 if (obj.is_null()) | 212 if (obj.is_null()) |
| 207 return; | 213 return; |
| 208 Java_AwMessagePortService_onMessageChannelCreated(env, obj.obj(), *port1, | 214 Java_AwMessagePortService_onMessageChannelCreated(env, obj.obj(), *port1, |
| 209 *port2, ports->obj()); | 215 *port2, ports->obj()); |
| 210 } | 216 } |
| 211 | 217 |
| 218 // Adds a new port to the message port service. | |
| 212 void AwMessagePortServiceImpl::AddPort(int message_port_id, | 219 void AwMessagePortServiceImpl::AddPort(int message_port_id, |
| 213 AwMessagePortMessageFilter* filter) { | 220 AwMessagePortMessageFilter* filter) { |
| 214 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 215 if (ports_.count(message_port_id)) { | 222 if (ports_.count(message_port_id)) { |
| 216 NOTREACHED(); | 223 NOTREACHED(); |
| 217 return; | 224 return; |
| 218 } | 225 } |
| 219 ports_[message_port_id] = filter; | 226 ports_[message_port_id] = filter; |
| 220 } | 227 } |
| 221 | 228 |
| 222 bool RegisterAwMessagePortService(JNIEnv* env) { | 229 bool RegisterAwMessagePortService(JNIEnv* env) { |
| 223 return RegisterNativesImpl(env); | 230 return RegisterNativesImpl(env); |
| 224 } | 231 } |
| 225 | 232 |
| 226 // static | 233 // static |
| 227 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) { | 234 jlong InitAwMessagePortService(JNIEnv* env, jobject obj) { |
| 228 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); | 235 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); |
| 229 service->Init(env, obj); | 236 service->Init(env, obj); |
| 230 return reinterpret_cast<intptr_t>(service); | 237 return reinterpret_cast<intptr_t>(service); |
| 231 } | 238 } |
| 232 | 239 |
| 233 } // namespace android_webview | 240 } // namespace android_webview |
| OLD | NEW |