Chromium Code Reviews| Index: content/browser/browser_plugin/browser_plugin_guest.cc |
| diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc |
| index 1d6931d0a4a3d74c1085e76670112c08327f32f7..d4defab6780f37b025392ebe49b9ef21169bc737 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
| @@ -126,20 +126,31 @@ int BrowserPluginGuest::GetGuestProxyRoutingID() { |
| if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) |
| return guest_proxy_routing_id_; |
| - // Create a RenderFrameProxyHost for the guest in the embedder renderer |
| - // process, so that the embedder can access the guest's window object. |
| - // On reattachment, we can reuse the same RenderFrameProxyHost because |
| - // the embedder process will always be the same even if the embedder |
| - // WebContents changes. |
| + // In order to enable the embedder to post messages to the |
| + // guest, we need to create a RenderFrameProxyHost in root node of guest |
| + // WebContents' frame tree (i.e., create a RenderFrameProxy in the embedder |
| + // process which can be used by the embedder to post messages to the guest). |
| + // The creation of RFPH for the reverse path, which enables the guest to post |
| + // messages to the embedder, will be postponed to when the embedder posts its |
| + // first message to the guest. |
| // |
| // TODO(fsamuel): Make sure this works for transferring guests across |
| // owners in different processes. We probably need to clear the |
| // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach |
| // to enable this. |
| - SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance(); |
| - int proxy_routing_id = |
| - GetWebContents()->GetFrameTree()->root()->render_manager()-> |
| - CreateRenderFrameProxy(owner_site_instance); |
| + // |
| + // TODO(ekaramad): If the guest is embedded inside a cross-process <iframe> |
| + // (e.g., <embed>-ed PDF), the reverse proxy will not be created and the |
| + // posted message's source attribute will be null which in turn breaks the |
| + // two-way messaging between the guest and the embedder. We should either |
| + // create a RenderFrameProxyHost for the reverse path, or, implement |
|
Charlie Reis
2016/11/15 23:45:33
nit: No comma after "or"
EhsanK
2016/11/16 21:27:31
Done.
|
| + // MimeHandlerViewGuest's using OOPIF (https://crbug.com/659750). |
|
Charlie Reis
2016/11/15 23:45:33
nit: No apostrophe.
EhsanK
2016/11/16 21:27:31
Done.
|
| + SiteInstance* owner_site_instance = GetOwnerFrame()->GetSiteInstance(); |
| + int proxy_routing_id = GetWebContents() |
| + ->GetFrameTree() |
| + ->root() |
| + ->render_manager() |
| + ->CreateRenderFrameProxy(owner_site_instance); |
| guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( |
| owner_site_instance->GetProcess()->GetID(), proxy_routing_id) |
| ->GetRenderViewHost()->GetRoutingID(); |
| @@ -170,6 +181,10 @@ void BrowserPluginGuest::WillDestroy() { |
| attached_ = false; |
| } |
| +RenderFrameHostImpl* BrowserPluginGuest::GetOwnerFrame() const { |
| + return static_cast<RenderFrameHostImpl*>(delegate_->GetOwnerFrame()); |
| +} |
| + |
| void BrowserPluginGuest::Init() { |
| if (initialized_) |
| return; |
| @@ -241,12 +256,12 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| const IPC::Message& message) { |
| RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( |
| web_contents()->GetRenderWidgetHostView()); |
| + RenderFrameHostImpl* rfhi = GetOwnerFrame(); |
| + RenderWidgetHostImpl* rwhi = rfhi ? rfhi->GetRenderWidgetHost() : nullptr; |
| + DCHECK(rwhi); |
| // Until the guest is attached, it should not be handling input events. |
| - if (attached() && rwhv && |
| - rwhv->OnMessageReceivedFromEmbedder( |
| - message, |
| - RenderWidgetHostImpl::From( |
| - embedder_web_contents()->GetRenderViewHost()->GetWidget()))) { |
| + if (attached() && rwhv && rwhi && |
| + rwhv->OnMessageReceivedFromEmbedder(message, rwhi)) { |
| return true; |
| } |
| @@ -374,9 +389,10 @@ bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { |
| } |
| RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { |
| - if (!owner_web_contents_) |
| - return nullptr; |
| - return owner_web_contents_->GetRenderWidgetHostView(); |
| + if (GetOwnerFrame()) |
| + return GetOwnerFrame()->GetView(); |
| + |
| + return nullptr; |
| } |
| void BrowserPluginGuest::UpdateVisibility() { |
| @@ -448,8 +464,8 @@ void BrowserPluginGuest::ResendEventToEmbedder( |
| return; |
| DCHECK(browser_plugin_instance_id_); |
| - RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| - embedder_web_contents()->GetMainFrame()->GetView()); |
| + RenderWidgetHostViewBase* view = |
| + static_cast<RenderWidgetHostViewBase*>(GetOwnerRenderWidgetHostView()); |
| gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); |
| if (event.type == blink::WebInputEvent::GestureScrollUpdate) { |
| @@ -506,7 +522,8 @@ void BrowserPluginGuest::SendMessageToEmbedder( |
| pending_messages_.push_back(std::move(msg)); |
| return; |
| } |
| - owner_web_contents_->Send(msg.release()); |
| + |
| + GetOwnerFrame()->GetRenderWidgetHost()->Send(msg.release()); |
| } |
| void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |