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

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

Issue 769363002: Initialize BrowserPluginGuest to attach to the View hierarchy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@basic_detach_plumbing
Patch Set: Don't initialize by default Created 6 years 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 dba54f42cd8bc1f63b9653d47c433e538ce93aa3..eadc30dbd9914f041a10454a306b47dcbb474a04 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -72,7 +72,7 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
WebContentsImpl* web_contents,
BrowserPluginGuestDelegate* delegate)
: WebContentsObserver(web_contents),
- owner_web_contents_(NULL),
+ owner_web_contents_(nullptr),
attached_(false),
browser_plugin_instance_id_(browser_plugin::kInstanceIDNone),
guest_device_scale_factor_(1.0f),
@@ -84,6 +84,7 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
is_full_page_plugin_(false),
has_render_view_(has_render_view),
is_in_destruction_(false),
+ initialized_(false),
last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
last_input_flags_(0),
@@ -99,6 +100,19 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr()));
}
+void BrowserPluginGuest::Init() {
+ if (initialized_)
+ return;
+ initialized_ = true;
+
+ if (!delegate_->CanRunInDetachedState())
lazyboy 2014/12/04 16:51:13 Add a todo saying we should guard this with WTFram
Fady Samuel 2014/12/04 20:54:44 Done.
+ return;
+
+ WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
+ delegate_->GetOwnerWebContents());
+ InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
+}
+
void BrowserPluginGuest::WillDestroy() {
is_in_destruction_ = true;
owner_web_contents_ = NULL;
@@ -193,26 +207,30 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
return handled;
}
-void BrowserPluginGuest::Initialize(
- int browser_plugin_instance_id,
+void BrowserPluginGuest::InitInternal(
const BrowserPluginHostMsg_Attach_Params& params,
- WebContentsImpl* embedder_web_contents) {
- browser_plugin_instance_id_ = browser_plugin_instance_id;
+ WebContentsImpl* owner_web_contents) {
focused_ = params.focused;
+ OnSetFocus(0, focused_);
+
guest_visible_ = params.visible;
+ UpdateVisibility();
+
is_full_page_plugin_ = params.is_full_page_plugin;
guest_window_rect_ = gfx::Rect(params.origin,
params.resize_guest_params.view_size);
- WebContentsViewGuest* new_view =
- static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
- if (attached())
- new_view->OnGuestDetached(owner_web_contents_->GetView());
+ if (owner_web_contents_ != owner_web_contents) {
+ WebContentsViewGuest* new_view =
+ static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
+ if (owner_web_contents_)
+ new_view->OnGuestDetached(owner_web_contents_->GetView());
- // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
- // be attached.
- owner_web_contents_ = embedder_web_contents;
- new_view->OnGuestAttached(owner_web_contents_->GetView());
+ // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
+ // be attached.
+ owner_web_contents_ = owner_web_contents;
+ new_view->OnGuestAttached(owner_web_contents_->GetView());
+ }
RendererPreferences* renderer_prefs =
GetWebContents()->GetMutableRendererPrefs();
@@ -238,7 +256,8 @@ void BrowserPluginGuest::Initialize(
embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this));
- OnResizeGuest(browser_plugin_instance_id_, params.resize_guest_params);
+ // The instance ID does not matter here.
+ OnResizeGuest(browser_plugin::kInstanceIDNone, params.resize_guest_params);
// TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will
// be reset again the next time preferences are updated.
@@ -320,14 +339,15 @@ void BrowserPluginGuest::SwapCompositorFrame(
last_seen_view_size_ = view_size;
}
- FrameMsg_CompositorFrameSwapped_Params guest_params;
- frame->AssignTo(&guest_params.frame);
- guest_params.output_surface_id = output_surface_id;
- guest_params.producing_route_id = host_routing_id;
- guest_params.producing_host_id = host_process_id;
+ pending_frame_.reset(new FrameMsg_CompositorFrameSwapped_Params());
+ frame->AssignTo(&pending_frame_->frame);
+ pending_frame_->output_surface_id = output_surface_id;
+ pending_frame_->producing_route_id = host_routing_id;
+ pending_frame_->producing_host_id = host_process_id;
+
SendMessageToEmbedder(
new BrowserPluginMsg_CompositorFrameSwapped(
- browser_plugin_instance_id(), guest_params));
+ browser_plugin_instance_id(), *pending_frame_));
}
void BrowserPluginGuest::SetContentsOpaque(bool opaque) {
@@ -513,6 +533,16 @@ void BrowserPluginGuest::Attach(
int browser_plugin_instance_id,
WebContentsImpl* embedder_web_contents,
const BrowserPluginHostMsg_Attach_Params& params) {
+ browser_plugin_instance_id_ = browser_plugin_instance_id;
+ if (pending_frame_) {
lazyboy 2014/12/04 16:51:12 Add a not when this can happen.
Fady Samuel 2014/12/04 20:54:44 Done.
+ cc::CompositorFrameAck ack;
+ RenderWidgetHostImpl::SendSwapCompositorFrameAck(
+ pending_frame_->producing_route_id,
+ pending_frame_->output_surface_id,
+ pending_frame_->producing_host_id,
+ ack);
+ pending_frame_.reset();
+ }
delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
params.is_full_page_plugin);
@@ -531,7 +561,7 @@ void BrowserPluginGuest::Attach(
}
}
- Initialize(browser_plugin_instance_id, params, embedder_web_contents);
+ InitInternal(params, embedder_web_contents);
attached_ = true;
SendQueuedMessages();
@@ -561,6 +591,7 @@ void BrowserPluginGuest::OnCompositorFrameSwappedACK(
params.output_surface_id,
params.producing_host_id,
params.ack);
+ pending_frame_.reset();
}
void BrowserPluginGuest::OnDetach(int browser_plugin_instance_id) {
@@ -675,7 +706,7 @@ void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id,
}
void BrowserPluginGuest::OnResizeGuest(
- int browser_plugin_instance_id,
+ int /* unused */,
lazyboy 2014/12/04 16:51:13 nit: This is not consistent in this file, revert t
Fady Samuel 2014/12/04 20:54:44 Done.
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
// If we are setting the size for the first time before navigating then
// BrowserPluginGuest does not yet have a RenderViewHost.

Powered by Google App Engine
This is Rietveld 408576698