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

Unified Diff: content/browser/browser_plugin/browser_plugin_embedder.cc

Issue 10829225: Browser Plugin: Add HTML5-like postMessage support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT. Added subframe targeting + test. Created 8 years, 2 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/browser_plugin/browser_plugin_embedder.cc
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc
index 09057f721b744cb67216a1d56b01544a787fb567..5d54f7b20262990393abc74754ffe06d07c8f0ad 100644
--- a/content/browser/browser_plugin/browser_plugin_embedder.cc
+++ b/content/browser/browser_plugin/browser_plugin_embedder.cc
@@ -11,10 +11,12 @@
#include "base/time.h"
#include "content/browser/browser_plugin/browser_plugin_embedder_helper.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
+#include "content/browser/browser_plugin/browser_plugin_guest_helper.h"
#include "content/browser/browser_plugin/browser_plugin_host_factory.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/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -129,10 +131,53 @@ void BrowserPluginEmbedder::NavigateGuest(
if (!src.empty()) {
guest_web_contents->GetController().LoadURL(url,
Referrer(),
- PAGE_TRANSITION_AUTO_SUBFRAME,
+ PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
}
+ // Prepare the swapped out RenderView for the guest in the embedder process
nasko 2012/10/02 17:52:31 Shouldn't that code move to the new _CreateGuest m
Fady Samuel 2012/10/02 22:04:08 The first block can be. The second block cannot be
+ // and the swapped out RenderView for the embedder in the guest render process
+ // to enable two-way postMessage.
+ SiteInstance* guest_site_instance = guest_web_contents->GetSiteInstance();
+ // Create a swapped out RenderView for the embedder in the guest render
+ // process if it does not already exist.
+ if (guest->swapped_out_guest_routing_id() == MSG_ROUTING_NONE) {
+ guest->set_swapped_out_guest_routing_id(
+ static_cast<WebContentsImpl*>(web_contents())->
+ CreateSwappedOutRenderViewForGuest(guest_site_instance));
+ // Attach a BrowserPluginGuestHelper to the swapped out guest RVH so that it
+ // can catch custom IDs.
+ RenderViewHostImpl* swapped_out_rvh = RenderViewHostImpl::FromID(
+ guest_site_instance->GetProcess()->GetID(),
+ guest->swapped_out_guest_routing_id());
+ DCHECK(swapped_out_rvh);
+ // |swapped_out_rvh| manages the ownership of this BrowserPluginGuestHelper.
+ new BrowserPluginGuestHelper(guest, swapped_out_rvh);
+ }
+
+ // Create a swapped out RenderView for the guest in the embedder render
+ // process, so that the embedder can reply to the guest from the source
+ // field in the JS event object.
+ if (guest->swapped_out_embedder_routing_id() == MSG_ROUTING_NONE) {
+ guest->set_swapped_out_embedder_routing_id(
+ static_cast<WebContentsImpl*>(guest->GetWebContents())->
+ CreateSwappedOutRenderViewForGuest(
+ web_contents()->GetSiteInstance()));
+ // Attach a BrowserPluginEmbedderHelper to the swapped out embedder RVH
+ // so that it can catch custom IDs.
+ RenderViewHostImpl* swapped_out_rvh = RenderViewHostImpl::FromID(
+ web_contents()->GetRenderProcessHost()->GetID(),
+ guest->swapped_out_embedder_routing_id());
+ DCHECK(swapped_out_rvh);
+ // |swapped_out_rvh| manages the ownership of this
+ // BrowserPluginEmbedderHelper.
+ new BrowserPluginEmbedderHelper(this, swapped_out_rvh);
+ // Tell the embedder about its routing ID so it can use its content window.
+ render_view_host->Send(new BrowserPluginMsg_GuestContentWindowReady(
+ instance_id,
+ guest->swapped_out_embedder_routing_id()));
+ }
+
// Resize the guest if the resize parameter was set from the renderer.
ResizeGuest(render_view_host, instance_id, resize_params);
}
@@ -241,7 +286,6 @@ void BrowserPluginEmbedder::DestroyGuestByInstanceID(int instance_id) {
void BrowserPluginEmbedder::RenderViewDeleted(
RenderViewHost* render_view_host) {
- DestroyGuests();
}
void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) {
@@ -265,6 +309,32 @@ void BrowserPluginEmbedder::PluginDestroyed(int instance_id) {
DestroyGuestByInstanceID(instance_id);
}
+void BrowserPluginEmbedder::RouteMessageEvent(
+ int instance_id,
+ const string16& data,
+ int source_frame_id,
+ const string16& target_origin,
+ int target_frame_id) {
+ BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
+ if (!guest)
+ return;
+
+ WebContentsImpl* guest_web_contents =
+ static_cast<WebContentsImpl*>(guest->GetWebContents());
+
+ ViewMsg_PostMessage_Params new_params;
+ new_params.data = data;
+ new_params.target_origin = target_origin;
+ new_params.target_frame_id = target_frame_id;
+ new_params.source_frame_id = source_frame_id;
+
+ DCHECK(guest->swapped_out_guest_routing_id() != MSG_ROUTING_NONE);
+ new_params.source_routing_id = guest->swapped_out_guest_routing_id();
+
+ guest_web_contents->GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
+ guest_web_contents->GetRenderViewHost()->GetRoutingID(), new_params));
+}
+
void BrowserPluginEmbedder::Go(int instance_id, int relative_index) {
BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
if (guest)

Powered by Google App Engine
This is Rietveld 408576698