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

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

Issue 2417693002: Allow MimeHandlerViewGuest be embedded inside OOPIFs (Closed)
Patch Set: Added a NOTREACHED Created 4 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_guest.cc
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index bcb8464383290287d0f6998aa759a6589b3020f2..9edbcc40defa4999cb0c46b9d6f6d57b10b8edca 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -107,6 +107,8 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
ignore_dragged_url_(true),
delegate_(delegate),
can_use_cross_process_frames_(delegate->CanUseCrossProcessFrames()),
+ embedder_process_id_(0),
Charlie Reis 2016/10/18 22:52:20 ChildProcessHost::kInvalidUniqueID
EhsanK 2016/10/20 21:41:17 Thanks. Used in mime_handler_view_guest.cc.
+ embedder_routing_id_(MSG_ROUTING_NONE),
weak_ptr_factory_(this) {
DCHECK(web_contents);
DCHECK(delegate);
@@ -135,10 +137,13 @@ int BrowserPluginGuest::GetGuestProxyRoutingID() {
// 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);
+ SiteInstance* owner_site_instance =
+ GetEmbedderFrame()->render_view_host()->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();
@@ -169,6 +174,37 @@ void BrowserPluginGuest::WillDestroy() {
attached_ = false;
}
+WebContents* BrowserPluginGuest::RegisterEmbedderID(int process_id,
+ int routing_id) {
+ RenderFrameHostImpl* rfh =
+ RenderFrameHostImpl::FromID(process_id, routing_id);
+
+ // Both |process_id| and |routing_id| are reported from the renderer side. For
Charlie Reis 2016/10/18 22:52:20 Renderer processes should never be told process ID
EhsanK 2016/10/20 21:41:17 I see. I moved the logic to initialize the embedde
+ // invalid values, |rfh| will be nullptr.
+ if (!rfh)
+ return nullptr;
+
+ // For now consider the |rfh| as the rightful embedder. The GuestViewManager
+ // will later decide if this |rfh| could be an embedder of the BrowserPlugin.
+ embedder_process_id_ = process_id;
+ embedder_routing_id_ = routing_id;
+
+ return static_cast<WebContentsImpl*>(rfh->delegate());
+}
+
+RenderFrameHostImpl* BrowserPluginGuest::GetEmbedderFrame() const {
+ RenderFrameHostImpl* rfh =
+ RenderFrameHostImpl::FromID(embedder_process_id_, embedder_routing_id_);
+
+ // In <webview> we get here before GuestViewManager::AttachGuest is called.
+ // Our best bet for now is to rely on |owner_web_contents_| main frame. This
+ // is incorrect is <webview> is at some point embedded inside an OOPIF.
Charlie Reis 2016/10/18 22:52:20 Typo (too many "is"'s)
EhsanK 2016/10/20 21:41:17 Thanks! This block is removed now however.
+ if (!rfh)
+ rfh = owner_web_contents_ ? owner_web_contents_->GetMainFrame() : nullptr;
+
+ return rfh;
+}
+
void BrowserPluginGuest::Init() {
if (initialized_)
return;
@@ -241,11 +277,11 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>(
web_contents()->GetRenderWidgetHostView());
// Until the guest is attached, it should not be handling input events.
- if (attached() && rwhv &&
+ if (attached() && rwhv && GetEmbedderFrame() &&
+ GetEmbedderFrame()->GetRenderWidgetHost() &&
rwhv->OnMessageReceivedFromEmbedder(
- message,
- RenderWidgetHostImpl::From(
- embedder_web_contents()->GetRenderViewHost()->GetWidget()))) {
+ message, RenderWidgetHostImpl::From(
+ GetEmbedderFrame()->GetRenderWidgetHost()))) {
return true;
}
@@ -373,9 +409,10 @@ bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
}
RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
- if (!owner_web_contents_)
- return nullptr;
- return owner_web_contents_->GetRenderWidgetHostView();
+ if (GetEmbedderFrame())
+ return GetEmbedderFrame()->GetView();
+
+ return nullptr;
}
void BrowserPluginGuest::UpdateVisibility() {
@@ -447,8 +484,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*>(GetEmbedderFrame()->GetView());
gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin();
if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
@@ -504,7 +541,8 @@ void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
pending_messages_.push_back(linked_ptr<IPC::Message>(msg));
return;
}
- owner_web_contents_->Send(msg);
+
+ GetEmbedderFrame()->GetRenderWidgetHost()->Send(msg);
}
void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
@@ -746,6 +784,7 @@ void BrowserPluginGuest::Attach(
int browser_plugin_instance_id,
WebContentsImpl* embedder_web_contents,
const BrowserPluginHostMsg_Attach_Params& params) {
+ DCHECK_EQ(GetEmbedderFrame()->delegate(), embedder_web_contents);
browser_plugin_instance_id_ = browser_plugin_instance_id;
// The guest is owned by the embedder. Attach is queued up so we cannot
// change embedders before attach completes. If the embedder goes away,

Powered by Google App Engine
This is Rietveld 408576698