Send IPCs from RenderFrameHost to WebContents to match what we do with RenderViewHost. This has two purposes:
-IPCs that go straight to WebContentsObserver methods don't have to touch render_frame_host_impl.cc, render_frame_host_impl.h, and render_frame_host_delegate.h
-IPC's sent with the RenderFrame's routing id now go to WebContentsObservers

We can now dispatch FrameHostMsg_PepperPluginHung in WebContentsImpl like it used to. Also change FrameHostMsg_PluginCrashed to use the RenderFrame's routing ID.

BUG=304341
[email protected]

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=239112

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239228 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 51757de..bb681ede 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -46,6 +46,7 @@
 #include "content/browser/webui/web_ui_impl.h"
 #include "content/common/browser_plugin/browser_plugin_constants.h"
 #include "content/common/browser_plugin/browser_plugin_messages.h"
+#include "content/common/frame_messages.h"
 #include "content/common/image_messages.h"
 #include "content/common/ssl_status_serialization.h"
 #include "content/common/view_messages.h"
@@ -366,7 +367,7 @@
       maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
       temporary_zoom_settings_(false),
       color_chooser_identifier_(0),
-      message_source_(NULL),
+      render_view_message_source_(NULL),
       fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
   for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
     g_created_callbacks.Get().at(i).Run(this);
@@ -474,6 +475,13 @@
 
 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
                                         const IPC::Message& message) {
+  return OnMessageReceived(render_view_host, NULL, message);
+}
+
+bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
+                                        RenderFrameHost* render_frame_host,
+                                        const IPC::Message& message) {
+  DCHECK(render_view_host || render_frame_host);
   if (GetWebUI() &&
       static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
     return true;
@@ -486,11 +494,13 @@
       return true;
 
   // Message handlers should be aware of which RenderViewHost sent the
-  // message, which is temporarily stored in message_source_.
-  message_source_ = render_view_host;
+  // message, which is temporarily stored in render_view_message_source_.
+  render_view_message_source_ = render_view_host;
   bool handled = true;
   bool message_is_ok = true;
   IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
+    IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
+    IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
     IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
                         OnDidLoadResourceFromMemoryCache)
     IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
@@ -509,7 +519,6 @@
     IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
                         OnRegisterProtocolHandler)
     IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
-    IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
     IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
     IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
     IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
@@ -537,7 +546,7 @@
                         OnFirstVisuallyNonEmptyPaint)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP_EX()
-  message_source_ = NULL;
+  render_view_message_source_ = NULL;
 
   if (!message_is_ok) {
     RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
@@ -2241,8 +2250,9 @@
 }
 
 void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
-  FOR_EACH_OBSERVER(WebContentsObserver, observers_,
-                    DocumentLoadedInFrame(frame_id, message_source_));
+  FOR_EACH_OBSERVER(
+      WebContentsObserver, observers_,
+      DocumentLoadedInFrame(frame_id, render_view_message_source_));
 }
 
 void WebContentsImpl::OnDidFinishLoad(
@@ -2250,11 +2260,12 @@
     const GURL& url,
     bool is_main_frame) {
   GURL validated_url(url);
-  RenderProcessHost* render_process_host = message_source_->GetProcess();
+  RenderProcessHost* render_process_host =
+      render_view_message_source_->GetProcess();
   RenderViewHost::FilterURL(render_process_host, false, &validated_url);
   FOR_EACH_OBSERVER(WebContentsObserver, observers_,
                     DidFinishLoad(frame_id, validated_url, is_main_frame,
-                                  message_source_));
+                                  render_view_message_source_));
 }
 
 void WebContentsImpl::OnDidFailLoadWithError(
@@ -2264,12 +2275,13 @@
     int error_code,
     const base::string16& error_description) {
   GURL validated_url(url);
-  RenderProcessHost* render_process_host = message_source_->GetProcess();
+  RenderProcessHost* render_process_host =
+      render_view_message_source_->GetProcess();
   RenderViewHost::FilterURL(render_process_host, false, &validated_url);
   FOR_EACH_OBSERVER(WebContentsObserver, observers_,
                     DidFailLoad(frame_id, validated_url, is_main_frame,
                                 error_code, error_description,
-                                message_source_));
+                                render_view_message_source_));
 }
 
 void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
@@ -2369,12 +2381,21 @@
 
 void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
   java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
-      message_source_, reply_msg);
+      render_view_message_source_, reply_msg);
 }
 
 #endif
 
-void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,
+void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
+                                         const base::FilePath& path,
+                                         bool is_hung) {
+  UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
+
+  FOR_EACH_OBSERVER(WebContentsObserver, observers_,
+                    PluginHungStatusChanged(plugin_child_id, path, is_hung));
+}
+
+void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
                                       base::ProcessId plugin_pid) {
   FOR_EACH_OBSERVER(WebContentsObserver, observers_,
                     PluginCrashed(plugin_path, plugin_pid));
@@ -2503,11 +2524,13 @@
           "Playing audio");
     }
 
-    if (blocker)
-      power_save_blockers_[message_source_][player_cookie] = blocker.release();
+    if (blocker) {
+      power_save_blockers_[render_view_message_source_][player_cookie] =
+          blocker.release();
+    }
   } else {
-    delete power_save_blockers_[message_source_][player_cookie];
-    power_save_blockers_[message_source_].erase(player_cookie);
+    delete power_save_blockers_[render_view_message_source_][player_cookie];
+    power_save_blockers_[render_view_message_source_].erase(player_cookie);
   }
 #endif  // !defined(OS_CHROMEOS)
 }
@@ -2734,13 +2757,9 @@
       WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
 }
 
-void WebContentsImpl::PepperPluginHung(int plugin_child_id,
-                                       const base::FilePath& path,
-                                       bool is_hung) {
-  UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
-
-  FOR_EACH_OBSERVER(WebContentsObserver, observers_,
-                    PluginHungStatusChanged(plugin_child_id, path, is_hung));
+bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
+                                        const IPC::Message& message) {
+  return OnMessageReceived(NULL, render_frame_host, message);
 }
 
 RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {