Browser Plugin: Reduce BrowserPluginEmbedder's responsibilities
Attaching windows to <webview>s across Chrome App windows via window.open is
currently not possible with the BrowserPluginEmbedder abstraction. In upcoming
patches, a new concept, BrowserPluginGuestManager will replace BrowserPluginEmbedder
to allowing routing to guests hosted across multiple Chrome App windows.
Towards that end, this patch reduces the responsibilities of BrowserPluginEmbedder by
moving more code into BrowserPluginGuest.
BUG=140316, 174673
Test=BrowserPluginHostTest.*
Review URL: https://chromiumcodereview.appspot.com/12217141
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182690 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index 3042c736..97460c5 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -47,10 +47,11 @@
BrowserPluginGuest::BrowserPluginGuest(
int instance_id,
+ WebContentsImpl* embedder_web_contents,
WebContentsImpl* web_contents,
const BrowserPluginHostMsg_CreateGuest_Params& params)
: WebContentsObserver(web_contents),
- embedder_web_contents_(NULL),
+ embedder_web_contents_(embedder_web_contents),
instance_id_(instance_id),
damage_buffer_sequence_id_(0),
damage_buffer_size_(0),
@@ -58,12 +59,32 @@
guest_hang_timeout_(
base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)),
focused_(params.focused),
- visible_(params.visible),
+ guest_visible_(params.visible),
+ embedder_visible_(true),
name_(params.name),
auto_size_enabled_(params.auto_size_params.enable),
max_auto_size_(params.auto_size_params.max_size),
min_auto_size_(params.auto_size_params.min_size) {
DCHECK(web_contents);
+ web_contents->SetDelegate(this);
+
+ RendererPreferences* renderer_prefs = web_contents->GetMutableRendererPrefs();
+ // Copy renderer preferences (and nothing else) from the embedder's
+ // WebContents to the guest.
+ //
+ // For GTK and Aura this is necessary to get proper renderer configuration
+ // values for caret blinking interval, colors related to selection and
+ // focus.
+ *renderer_prefs = *embedder_web_contents->GetMutableRendererPrefs();
+
+ renderer_prefs->throttle_input_events = false;
+ // We would like the guest to report changes to frame names so that we can
+ // update the BrowserPlugin's corresponding 'name' attribute.
+ // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed.
+ renderer_prefs->report_frame_name_changes = true;
+ // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated
+ // navigations still continue to function inside the app.
+ renderer_prefs->browser_handles_all_top_level_requests = false;
}
bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
@@ -102,8 +123,26 @@
this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
content::Source<content::WebContents>(web_contents()));
+ // Listen to embedder visibility changes so that the guest is in a 'shown'
+ // state if both the embedder is visible and the BrowserPlugin is marked as
+ // visible.
+ notification_registrar_.Add(
+ this, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
+ content::Source<content::WebContents>(embedder_web_contents_));
+
OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params);
+ // Create a swapped out RenderView for the guest in the embedder render
+ // process, so that the embedder can access the guest's window object.
+ int guest_routing_id =
+ static_cast<WebContentsImpl*>(web_contents())->CreateSwappedOutRenderView(
+ embedder_web_contents()->GetSiteInstance());
+ embedder_web_contents_->Send(new BrowserPluginMsg_GuestContentWindowReady(
+ embedder_web_contents_->GetRoutingID(), instance_id_, guest_routing_id));
+
+ if (!params.src.empty())
+ OnNavigateGuest(instance_id_, params.src);
+
GetContentClient()->browser()->GuestWebContentsCreated(
web_contents(), embedder_web_contents_);
}
@@ -114,15 +153,18 @@
// static
BrowserPluginGuest* BrowserPluginGuest::Create(
int instance_id,
+ WebContentsImpl* embedder_web_contents,
WebContentsImpl* web_contents,
const BrowserPluginHostMsg_CreateGuest_Params& params) {
RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create"));
if (factory_) {
return factory_->CreateBrowserPluginGuest(instance_id,
+ embedder_web_contents,
web_contents,
params);
}
- return new BrowserPluginGuest(instance_id, web_contents,params);
+ return new BrowserPluginGuest(instance_id, embedder_web_contents,
+ web_contents, params);
}
void BrowserPluginGuest::UpdateVisibility() {
@@ -144,6 +186,12 @@
is_top_level);
break;
}
+ case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
+ DCHECK_EQ(Source<WebContents>(source).ptr(), embedder_web_contents_);
+ embedder_visible_ = *Details<bool>(details).ptr();
+ UpdateVisibility();
+ break;
+ }
default:
NOTREACHED() << "Unexpected notification sent.";
break;
@@ -554,10 +602,8 @@
}
void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) {
- visible_ = visible;
- BrowserPluginEmbedder* embedder =
- embedder_web_contents_->GetBrowserPluginEmbedder();
- if (embedder->visible() && visible)
+ guest_visible_ = visible;
+ if (embedder_visible_ && guest_visible_)
web_contents()->WasShown();
else
web_contents()->WasHidden();