Make JavaBridgeDispatcherHost not be a RenderViewHostObserver anymore.

The only reason it was inheriting from it was to to dispatch an IPC from the renderer. Dispatch the IPC in WebContentsImpl instead, since that already knows about the java bridge code and send it to JavaBridgeDispatcherHostManager. I did this instead of exposing WebContentsImpl::message_source_ as no one else needs this yet, and I'm nervous of exposing it in case of misuse.

This also fixes usage of RenderProcessHost and RenderViewHost on the background java thread, which is not thread-safe, and a possible use-after-free with RenderViewHost.

This is part of the work in removing RenderViewHostObserver.

BUG=306569
[email protected], [email protected]

Review URL: https://codereview.chromium.org/45933002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231856 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index f089c4a5..ed29f973 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -87,6 +87,8 @@
 
 #if defined(OS_ANDROID)
 #include "content/browser/android/date_time_chooser_android.h"
+#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
+#include "content/common/java_bridge_messages.h"
 #include "content/public/browser/android/content_view_core.h"
 #endif
 
@@ -95,10 +97,6 @@
 #include "ui/gl/io_surface_support_mac.h"
 #endif
 
-#if defined(OS_ANDROID)
-#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
-#endif
-
 // Cross-Site Navigations
 //
 // If a WebContentsImpl is told to navigate to a different web site (as
@@ -527,6 +525,8 @@
                         OnFindMatchRectsReply)
     IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
                         OnOpenDateTimeDialog)
+    IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
+                                    OnJavaBridgeGetChannelHandle)
 #endif
     IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
     IPC_MESSAGE_UNHANDLED(handled = false)
@@ -1050,9 +1050,6 @@
 #if defined(OS_ANDROID)
   java_bridge_dispatcher_host_manager_.reset(
       new JavaBridgeDispatcherHostManager(this));
-#endif
-
-#if defined(OS_ANDROID)
   date_time_chooser_.reset(new DateTimeChooserAndroid());
 #endif
 }
@@ -2310,6 +2307,11 @@
                                  value.step);
 }
 
+void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
+  java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
+      message_source_, reply_msg);
+}
+
 #endif
 
 void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,