Index: content/browser/android/content_view_core_impl.cc |
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc |
index 16e83d8a457ae3969bb8eed13a164c4879ec6290..12fa933358b546cdbc7368dc40cdb11d38d63403 100644 |
--- a/content/browser/android/content_view_core_impl.cc |
+++ b/content/browser/android/content_view_core_impl.cc |
@@ -26,6 +26,7 @@ |
#include "content/browser/frame_host/navigation_entry_impl.h" |
#include "content/browser/geolocation/geolocation_dispatcher_host.h" |
#include "content/browser/media/media_web_contents_observer.h" |
+#include "content/browser/message_port_service.h" |
#include "content/browser/renderer_host/compositor_impl_android.h" |
#include "content/browser/renderer_host/input/motion_event_android.h" |
#include "content/browser/renderer_host/input/web_input_event_builders_android.h" |
@@ -158,6 +159,28 @@ float GetPrimaryDisplayDeviceScaleFactor() { |
return display.device_scale_factor(); |
} |
+void CreateMessageChannelOnIOThread( |
+ MessagePortMessageFilter* filter, |
+ int routing_id, |
+ int* port1, int* port2) { |
+ |
+ *port1 = 0; |
+ *port2 = 0; |
+ MessagePortService* msp = MessagePortService::GetInstance(); |
+ msp->Create(routing_id, filter, port1); |
+ msp->Create(routing_id, filter, port2); |
+ msp->QueueMessages(*port1); |
+ msp->QueueMessages(*port2); |
+} |
+ |
+void OnMessageChannelCreated( |
+ ScopedJavaGlobalRef<jobject>* callback, |
mnaganov (inactive)
2014/07/14 16:06:22
Who owns the scoped callback ref? Do we need to de
sgurun-gerrit only
2014/07/15 22:19:54
We pass it as a owned_ptr. It is deleted once calb
|
+ int* port1, int* port2) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ Java_ContentViewCore_onMessageChannelCreated(env, *port1, *port2, |
+ callback->obj()); |
+} |
+ |
} // namespace |
// Enables a callback when the underlying WebContents is destroyed, to enable |
@@ -1423,6 +1446,32 @@ void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, |
c_callback); |
} |
+// TODO(sgurun) check which thread this has to run on. |
+void ContentViewCoreImpl::CreateMessageChannel(JNIEnv* env, jobject obj, |
+ jobject callback) { |
+ |
+ ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); |
+ j_callback->Reset(env, callback); |
+ RenderProcessHostImpl* rph = |
+ static_cast<RenderProcessHostImpl*>( |
+ web_contents_->GetRenderProcessHost()); |
+ MessagePortMessageFilter* mf = rph->message_port_message_filter(); |
+ |
+ int port1; |
+ int port2; |
+ // Create message channel on IO thread |
+ BrowserThread::PostTaskAndReply( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&CreateMessageChannelOnIOThread, |
+ mf, |
+ GetWebContents()->GetRoutingID(), |
+ &port1, &port2), |
+ base::Bind(&OnMessageChannelCreated, |
+ base::Owned(j_callback), |
+ &port1, &port2)); |
+} |
+ |
bool ContentViewCoreImpl::GetUseDesktopUserAgent( |
JNIEnv* env, jobject obj) { |
NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); |