Chromium Code Reviews| 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..943d47bc3efd43eccdc7eafd3fea4749befaf512 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 |
| + // 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. |
|
Charlie Reis
2012/10/04 21:58:25
Do we need to do this in all cases? I think we ca
Fady Samuel
2012/10/10 21:36:07
Removed.
|
| + if (guest->swapped_out_guest_routing_id() == MSG_ROUTING_NONE) { |
| + guest->set_swapped_out_guest_routing_id( |
| + static_cast<WebContentsImpl*>(web_contents())-> |
| + CreateSwappedOutRenderView(guest_site_instance)); |
| + // Attach a BrowserPluginGuestHelper to the swapped out guest RVH so that it |
| + // can catch custom IDs. |
|
Charlie Reis
2012/10/04 21:58:25
What does "catch custom IDs" mean?
Fady Samuel
2012/10/10 21:36:07
Removed.
|
| + 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())-> |
| + CreateSwappedOutRenderView( |
| + 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(); |
|
Charlie Reis
2012/10/04 21:58:25
How is this handled now? Do we still need this me
Fady Samuel
2012/10/10 21:36:07
BrowserPluginHostMsg_PluginDestroyed takes care of
|
| } |
| void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { |
| @@ -265,6 +309,32 @@ void BrowserPluginEmbedder::PluginDestroyed(int instance_id) { |
| DestroyGuestByInstanceID(instance_id); |
| } |
| +void BrowserPluginEmbedder::RouteMessageEvent( |
|
Charlie Reis
2012/10/04 21:58:25
Why do we need this? Won't WebContentsImpl::Route
Fady Samuel
2012/10/10 21:36:07
Done.
|
| + 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) |