Index: content/browser/browser_plugin/browser_plugin_host_embedder_delegate.cc |
diff --git a/content/browser/browser_plugin/browser_plugin_host_embedder_delegate.cc b/content/browser/browser_plugin/browser_plugin_host_embedder_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..626e2de734ec5c4f7e36f3fa6372b87450a2a7c6 |
--- /dev/null |
+++ b/content/browser/browser_plugin/browser_plugin_host_embedder_delegate.cc |
@@ -0,0 +1,225 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/browser_plugin/browser_plugin_host_embedder_delegate.h" |
+ |
+#include "base/time.h" |
+#include "content/browser/browser_plugin/browser_plugin_host_guest_delegate.h" |
+#include "content/browser/browser_plugin/browser_plugin_host_guest_role.h" |
+#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "content/browser/renderer_host/render_widget_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/render_process_host.h" |
+#include "content/public/browser/render_view_host.h" |
+#include "content/public/browser/render_widget_host_view.h" |
+#include "content/public/browser/web_contents_observer.h" |
+#include "content/public/browser/web_contents_view.h" |
+#include "content/public/common/url_constants.h" |
+#include "ui/gfx/size.h" |
+ |
+namespace content { |
+ |
+BrowserPluginHostEmbedderDelegate::BrowserPluginHostEmbedderDelegate( |
+ WebContentsImpl* web_contents) : WebContentsObserver(web_contents) { |
+} |
+ |
+BrowserPluginHostEmbedderDelegate::~BrowserPluginHostEmbedderDelegate() { |
+} |
+ |
+BrowserPluginHostGuestDelegate* BrowserPluginHostEmbedderDelegate:: |
+ GetGuestByInstanceID(int instance_id) const { |
+ ContainerInstanceMap::const_iterator it = |
+ guests_by_instance_id_.find(instance_id); |
+ if (it != guests_by_instance_id_.end()) |
+ return it->second; |
+ return NULL; |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::AddGuest(int instance_id, |
+ BrowserPluginHostGuestDelegate* guest, |
+ int64 frame_id) { |
+ DCHECK(guests_by_instance_id_.find(instance_id) == |
+ guests_by_instance_id_.end()); |
+ guests_by_instance_id_[instance_id] = guest; |
+ guests_[guest->web_contents()] = frame_id; |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::NavigateGuest( |
+ RenderViewHost* render_view_host, |
+ int instance_id, |
+ int64 frame_id, |
+ const std::string& src, |
+ const gfx::Size& size) { |
+ BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); |
+ WebContentsImpl* guest_web_contents = NULL; |
+ GURL url(src); |
+ if (!guest) { |
+ // The SiteInstance of a given guest is based on the fact that it's a guest |
lazyboy
2012/08/23 01:41:51
creis 2012/08/13 17:50:14
========================
Charlie Reis
2012/08/24 00:28:32
WebUI pages are special privileged pages in Chrome
|
+ // in addition to which platform application the guest belongs to, rather |
+ // than the URL that the guest is being navigated to. |
+ std::string host = render_view_host->GetSiteInstance()->GetSite().host(); |
+ GURL guest_site( |
+ base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); |
+ SiteInstance* guest_site_instance = |
+ SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), |
+ guest_site); |
+ guest_web_contents = |
+ static_cast<WebContentsImpl*>( |
+ WebContents::Create(web_contents()->GetBrowserContext(), |
+ guest_site_instance, |
+ MSG_ROUTING_NONE, |
+ NULL, // base WebContents |
+ NULL // session storage namespace |
+ )); |
+ |
+ BrowserPluginHostGuestRole* guest_role = guest_web_contents->AddGuestRole( |
+ instance_id, |
+ render_view_host->GetProcess()); |
+ guest = guest_role->GetDelegate(); |
+ guest->set_embedder_render_process_host( |
+ render_view_host->GetProcess()); |
+ |
+ guest_web_contents->GetMutableRendererPrefs()-> |
+ throttle_input_events = false; |
+ AddGuest(instance_id, guest, frame_id); |
+ } else { |
+ guest_web_contents = static_cast<WebContentsImpl*>(guest->web_contents()); |
+ } |
+ guest->web_contents()->SetDelegate(guest); |
+ guest->web_contents()->GetController().LoadURL(url, |
+ Referrer(), |
+ PAGE_TRANSITION_AUTO_SUBFRAME, |
+ std::string()); |
+ if (!size.IsEmpty()) |
+ guest_web_contents->GetView()->SizeContents(size); |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::UpdateRectACK(int instance_id, |
+ int message_id, |
+ const gfx::Size& size) { |
+ BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) { |
+ guest->UpdateRectACK(message_id, size); |
+ } |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::ResizeGuest(int instance_id, |
+ TransportDIB* damage_buffer, |
+ int width, |
+ int height, |
+ bool resize_pending, |
+ float scale_factor) { |
+ BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); |
+ if (!guest) |
+ return; |
+ WebContentsImpl* guest_web_contents = |
+ static_cast<WebContentsImpl*>(guest->web_contents()); |
+ guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor); |
+ if (!resize_pending) |
+ guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::SetFocus(int instance_id, |
+ bool focused) { |
+ BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) { |
+ guest->SetFocus(focused); |
+ } |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::DestroyGuests() { |
+ for (GuestMap::const_iterator it = guests_.begin(); |
+ it != guests_.end(); ++it) { |
+ WebContents* web_contents = it->first; |
+ delete web_contents; |
+ } |
+ guests_.clear(); |
+ guests_by_instance_id_.clear(); |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::HandleInputEvent( |
+ int instance_id, |
+ RenderViewHost* render_view_host, |
+ const gfx::Rect& guest_rect, |
+ const WebKit::WebInputEvent& event, |
+ IPC::Message* reply_message) { |
+ BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) { |
+ guest->HandleInputEvent(render_view_host, guest_rect, event, reply_message); |
+ } |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::DestroyGuestByInstanceID( |
+ int instance_id) { |
+ BrowserPluginHostGuestDelegate* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) { |
+ WebContents* guest_web_contents = guest->web_contents(); |
+ |
+ GuestMap::iterator guest_it = guests_.find(guest_web_contents); |
+ DCHECK(guest_it != guests_.end()); |
+ |
+ guests_.erase(guest_it); |
+ guests_by_instance_id_.erase(instance_id); |
+ |
+ guest->Destroy(); |
+ } |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::DidCommitProvisionalLoadForFrame( |
+ int64 frame_id, |
+ bool is_main_frame, |
+ const GURL& url, |
+ PageTransition transition_type, |
+ RenderViewHost* render_view_host) { |
+ // Clean-up guests that lie in the frame that we're navigating. |
+ typedef std::set<WebContents*> GuestSet; |
+ GuestSet guests_to_delete; |
lazyboy
2012/08/23 01:41:51
creis 2012/08/13 17:50:14
========================
Charlie Reis
2012/08/24 00:28:32
Good to know, but that's not quite what I meant.
|
+ for (GuestMap::const_iterator it = guests_.begin(); |
+ it != guests_.end(); ++it) { |
+ WebContents* web_contents = it->first; |
+ if (it->second == frame_id) { |
+ // TODO(lazyboy): If we allow browser tags to be nested, we need to take |
+ // care of subframes inside this frame as well. |
+ guests_to_delete.insert(web_contents); |
+ } |
+ } |
+ for (GuestSet::const_iterator it = guests_to_delete.begin(); |
+ it != guests_to_delete.end(); ++it) { |
+ int instance_id = static_cast<WebContentsImpl*>(*it)->GetGuestRole()-> |
+ GetDelegate()->instance_id(); |
+ DestroyGuestByInstanceID(instance_id); |
+ } |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::RenderViewDeleted( |
+ RenderViewHost* render_view_host) { |
+ DestroyGuests(); |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::RenderViewGone( |
+ base::TerminationStatus status) { |
+ DestroyGuests(); |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::WebContentsVisiblitlyChanged( |
+ bool visible) { |
+ // If the embedder is hidden we need to hide the guests as well. |
+ for (GuestMap::const_iterator it = guests_.begin(); |
+ it != guests_.end(); ++it) { |
+ WebContents* web_contents = it->first; |
+ if (visible) |
+ web_contents->WasShown(); |
+ else |
+ web_contents->WasHidden(); |
+ } |
+} |
+ |
+void BrowserPluginHostEmbedderDelegate::PluginDestroyed( |
+ int instance_id) { |
+ DestroyGuestByInstanceID(instance_id); |
+} |
+ |
+} // namespace content |