Index: content/browser/browser_plugin/browser_plugin_embedder_helper.cc |
diff --git a/content/browser/browser_plugin/browser_plugin_embedder_helper.cc b/content/browser/browser_plugin/browser_plugin_embedder_helper.cc |
index 7039b2bb06fa548466dab0491ea084c5bc8387f4..68331cea377f1f05ccdf165f23828c4b720e4eb6 100644 |
--- a/content/browser/browser_plugin/browser_plugin_embedder_helper.cc |
+++ b/content/browser/browser_plugin/browser_plugin_embedder_helper.cc |
@@ -5,7 +5,9 @@ |
#include "content/browser/browser_plugin/browser_plugin_embedder_helper.h" |
#include "content/browser/browser_plugin/browser_plugin_embedder.h" |
+#include "content/browser/browser_plugin/browser_plugin_guest.h" |
#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
#include "content/common/browser_plugin_messages.h" |
#include "content/common/view_messages.h" |
#include "content/public/browser/render_process_host.h" |
@@ -32,6 +34,15 @@ bool BrowserPluginEmbedderHelper::Send(IPC::Message* message) { |
bool BrowserPluginEmbedderHelper::OnMessageReceived( |
const IPC::Message& message) { |
bool handled = true; |
+ if (static_cast<content::RenderViewHostImpl*>(render_view_host())-> |
+ is_swapped_out()) { |
+ IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message) |
+ IPC_MESSAGE_HANDLER(ViewHostMsg_RouteMessageEvent, |
+ OnRouteMessageEvent) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+ } |
IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message) |
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, |
OnNavigateGuest); |
@@ -48,6 +59,7 @@ bool BrowserPluginEmbedderHelper::OnMessageReceived( |
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
+ |
return handled; |
} |
@@ -121,6 +133,28 @@ void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) { |
embedder_->PluginDestroyed(instance_id); |
} |
+void BrowserPluginEmbedderHelper::OnRouteMessageEvent( |
+ const ViewMsg_PostMessage_Params& params) { |
+ // This helper's RVH corresponds to a swapped out RenderView living in |
+ // the embedder's render process. If this RVH's WebContents has a |
+ // BrowserPluginGuest, then we know this is actually a RVH for the |
+ // guest for the purpose of catching ViewHostMsg_RouteMessageEvent and |
+ // routing it to the guest WebContents. |
+ // This code path is executed when the embedder tries to send a message |
+ // back through event.source.postMessage within a 'message' event |
+ // listener. |
+ WebContentsImpl* guest_web_contents = static_cast<WebContentsImpl*>( |
+ render_view_host()->GetDelegate()); |
+ if (!guest_web_contents->GetBrowserPluginGuest()) |
+ return; |
+ embedder_->RouteMessageEvent( |
+ guest_web_contents->GetBrowserPluginGuest()->instance_id(), |
+ params.data, |
+ params.source_frame_id, |
+ params.target_origin, |
+ params.target_frame_id); |
+} |
+ |
void BrowserPluginEmbedderHelper::OnGo(int instance_id, int relative_index) { |
embedder_->Go(instance_id, relative_index); |
} |