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

Unified Diff: content/browser/android/content_view_core_impl.cc

Issue 387113003: Add a content API to create a message channel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address mikhail's comments Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
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..62c4fed0611f792e137f470085958aff2b97cc79 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,
+ 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,31 @@ void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env,
c_callback);
}
+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;
Yaron 2014/07/18 21:54:00 These are stack allocated and are passing to anoth
sgurun-gerrit only 2014/10/28 00:41:10 Done.
+ 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();

Powered by Google App Engine
This is Rietveld 408576698