| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 AwMessagePortMessageFilter* filter) { | 115 AwMessagePortMessageFilter* filter) { |
| 116 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 116 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 117 for (MessagePorts::iterator iter = ports_.begin(); | 117 for (MessagePorts::iterator iter = ports_.begin(); |
| 118 iter != ports_.end(); iter++) { | 118 iter != ports_.end(); iter++) { |
| 119 if (iter->second == filter) { | 119 if (iter->second == filter) { |
| 120 ports_.erase(iter); | 120 ports_.erase(iter); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 void AwMessagePortServiceImpl::PostAppToWebMessage(JNIEnv* env, jobject obj, | 125 void AwMessagePortServiceImpl::PostAppToWebMessage( |
| 126 int sender_id, jstring message, jintArray sent_ports) { | 126 JNIEnv* env, |
| 127 const JavaParamRef<jobject>& obj, |
| 128 int sender_id, |
| 129 const JavaParamRef<jstring>& message, |
| 130 const JavaParamRef<jintArray>& sent_ports) { |
| 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 131 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 128 base::string16* j_message = new base::string16; | 132 base::string16* j_message = new base::string16; |
| 129 ConvertJavaStringToUTF16(env, message, j_message); | 133 ConvertJavaStringToUTF16(env, message, j_message); |
| 130 std::vector<int>* j_sent_ports = new std::vector<int>; | 134 std::vector<int>* j_sent_ports = new std::vector<int>; |
| 131 if (sent_ports != nullptr) | 135 if (sent_ports != nullptr) |
| 132 base::android::JavaIntArrayToIntVector(env, sent_ports, j_sent_ports); | 136 base::android::JavaIntArrayToIntVector(env, sent_ports, j_sent_ports); |
| 133 | 137 |
| 134 BrowserThread::PostTask( | 138 BrowserThread::PostTask( |
| 135 BrowserThread::IO, | 139 BrowserThread::IO, |
| 136 FROM_HERE, | 140 FROM_HERE, |
| 137 base::Bind(&AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread, | 141 base::Bind(&AwMessagePortServiceImpl::PostAppToWebMessageOnIOThread, |
| 138 base::Unretained(this), | 142 base::Unretained(this), |
| 139 sender_id, | 143 sender_id, |
| 140 base::Owned(j_message), | 144 base::Owned(j_message), |
| 141 base::Owned(j_sent_ports))); | 145 base::Owned(j_sent_ports))); |
| 142 } | 146 } |
| 143 | 147 |
| 144 // The message port service cannot immediately close the port, because | 148 // The message port service cannot immediately close the port, because |
| 145 // it is possible that messages are still queued in the renderer process | 149 // it is possible that messages are still queued in the renderer process |
| 146 // waiting for a conversion. Instead, it sends a special message with | 150 // waiting for a conversion. Instead, it sends a special message with |
| 147 // a flag which indicates that this message port should be closed. | 151 // a flag which indicates that this message port should be closed. |
| 148 void AwMessagePortServiceImpl::ClosePort(JNIEnv* env, jobject obj, | 152 void AwMessagePortServiceImpl::ClosePort(JNIEnv* env, |
| 149 int message_port_id) { | 153 const JavaParamRef<jobject>& obj, |
| 154 int message_port_id) { |
| 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 151 BrowserThread::PostTask( | 156 BrowserThread::PostTask( |
| 152 BrowserThread::IO, | 157 BrowserThread::IO, |
| 153 FROM_HERE, | 158 FROM_HERE, |
| 154 base::Bind(&AwMessagePortServiceImpl::PostClosePortMessage, | 159 base::Bind(&AwMessagePortServiceImpl::PostClosePortMessage, |
| 155 base::Unretained(this), | 160 base::Unretained(this), |
| 156 message_port_id)); | 161 message_port_id)); |
| 157 } | 162 } |
| 158 | 163 |
| 159 void AwMessagePortServiceImpl::ReleaseMessages(JNIEnv* env, jobject obj, | 164 void AwMessagePortServiceImpl::ReleaseMessages(JNIEnv* env, |
| 160 int message_port_id) { | 165 const JavaParamRef<jobject>& obj, |
| 166 int message_port_id) { |
| 161 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 167 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 162 BrowserThread::PostTask( | 168 BrowserThread::PostTask( |
| 163 BrowserThread::IO, | 169 BrowserThread::IO, |
| 164 FROM_HERE, | 170 FROM_HERE, |
| 165 base::Bind(&MessagePortProvider::ReleaseMessages, message_port_id)); | 171 base::Bind(&MessagePortProvider::ReleaseMessages, message_port_id)); |
| 166 } | 172 } |
| 167 | 173 |
| 168 void AwMessagePortServiceImpl::RemoveSentPorts( | 174 void AwMessagePortServiceImpl::RemoveSentPorts( |
| 169 const std::vector<int>& sent_ports) { | 175 const std::vector<int>& sent_ports) { |
| 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 176 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 237 } |
| 232 | 238 |
| 233 // static | 239 // static |
| 234 jlong InitAwMessagePortService(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 240 jlong InitAwMessagePortService(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 235 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); | 241 AwMessagePortServiceImpl* service = AwMessagePortServiceImpl::GetInstance(); |
| 236 service->Init(env, obj); | 242 service->Init(env, obj); |
| 237 return reinterpret_cast<intptr_t>(service); | 243 return reinterpret_cast<intptr_t>(service); |
| 238 } | 244 } |
| 239 | 245 |
| 240 } // namespace android_webview | 246 } // namespace android_webview |
| OLD | NEW |