Index: content/browser/browser_plugin/browser_plugin_embedder.cc |
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..505dd312e87af76f2c942d210dc1696b4b5b7c8e |
--- /dev/null |
+++ b/content/browser/browser_plugin/browser_plugin_embedder.cc |
@@ -0,0 +1,217 @@ |
+// 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_embedder.h" |
+ |
+#include "base/time.h" |
+#include "content/browser/browser_plugin/browser_plugin_embedder_helper.h" |
+#include "content/browser/browser_plugin/browser_plugin_guest.h" |
+#include "content/browser/browser_plugin/browser_plugin_guest_helper.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 { |
+ |
+BrowserPluginEmbedder::BrowserPluginEmbedder( |
+ WebContentsImpl* web_contents, |
+ RenderViewHost* render_view_host) |
+ : WebContentsObserver(web_contents) { |
+ new BrowserPluginEmbedderHelper(this, web_contents, render_view_host); |
Fady Samuel
2012/08/25 05:28:32
The helpers are not being created in the correct s
|
+} |
+ |
+BrowserPluginEmbedder::~BrowserPluginEmbedder() { |
+} |
+ |
+BrowserPluginGuest* BrowserPluginEmbedder:: 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 BrowserPluginEmbedder::AddGuest(int instance_id, |
+ BrowserPluginGuest* guest, |
+ int64 frame_id) { |
+ DCHECK(guests_by_instance_id_.find(instance_id) == |
Charlie Reis
2012/08/27 20:23:59
nit: DCHECK_EQ
Should we make this a CHECK_EQ?
lazyboy
2012/08/28 19:07:14
Isn't CHECK more aggressive for this case?
Also, _
|
+ guests_by_instance_id_.end()); |
+ guests_by_instance_id_[instance_id] = guest; |
+ guests_[guest->web_contents()] = frame_id; |
+} |
+ |
+void BrowserPluginEmbedder::NavigateGuest(RenderViewHost* render_view_host, |
+ int instance_id, |
+ int64 frame_id, |
+ const std::string& src, |
+ const gfx::Size& size) { |
+ BrowserPluginGuest* 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 |
+ // 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 |
+ )); |
+ |
+ guest = guest_web_contents->AddBrowserPluginGuest(instance_id); |
+ 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); |
Charlie Reis
2012/08/27 20:23:59
Do we need to set this again if the guest already
lazyboy
2012/08/28 19:07:14
Moved.
Also this is a bit weird this part has gues
Fady Samuel
2012/08/29 08:16:20
Yea, it doesn't look like the local variable guest
lazyboy
2012/08/31 00:38:04
Done.
|
+ guest->web_contents()->GetController().LoadURL(url, |
+ Referrer(), |
+ PAGE_TRANSITION_AUTO_SUBFRAME, |
Charlie Reis
2012/08/27 20:23:59
I like that we're classifying this as a subframe l
lazyboy
2012/08/28 19:07:14
I'm not aware of the differences. Only related dif
|
+ std::string()); |
+ if (!size.IsEmpty()) |
+ guest_web_contents->GetView()->SizeContents(size); |
+} |
+ |
+void BrowserPluginEmbedder::UpdateRectACK(int instance_id, |
+ int message_id, |
+ const gfx::Size& size) { |
+ BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) |
+ guest->UpdateRectACK(message_id, size); |
+} |
+ |
+void BrowserPluginEmbedder::ResizeGuest(int instance_id, |
+ TransportDIB* damage_buffer, |
+ int width, |
+ int height, |
+ bool resize_pending, |
+ float scale_factor) { |
+ BrowserPluginGuest* 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 BrowserPluginEmbedder::SetFocus(int instance_id, |
+ bool focused) { |
+ BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) |
+ guest->SetFocus(focused); |
+} |
+ |
+void BrowserPluginEmbedder::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 BrowserPluginEmbedder::HandleInputEvent(int instance_id, |
+ RenderViewHost* render_view_host, |
+ const gfx::Rect& guest_rect, |
+ const WebKit::WebInputEvent& event, |
+ IPC::Message* reply_message) { |
+ BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
+ if (guest) |
+ guest->HandleInputEvent(render_view_host, guest_rect, event, reply_message); |
+} |
+ |
+void BrowserPluginEmbedder::DestroyGuestByInstanceID(int instance_id) { |
+ BrowserPluginGuest* 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 BrowserPluginEmbedder::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. |
Charlie Reis
2012/08/27 20:23:59
nit: Clean up
lazyboy
2012/08/28 19:07:14
Done.
|
+ typedef std::set<WebContents*> GuestSet; |
+ GuestSet guests_to_delete; |
+ for (GuestMap::const_iterator it = guests_.begin(); |
+ it != guests_.end(); ++it) { |
Charlie Reis
2012/08/27 20:23:59
nit: Wrong indent. Same below.
lazyboy
2012/08/28 19:07:14
I somehow broke this thinking for statements are n
|
+ 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. |
Charlie Reis
2012/08/27 20:23:59
This is not sufficient.
If the embedder has a tre
lazyboy
2012/08/28 19:07:14
Wouldn't that iframe's embedder take care of that?
|
+ 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)-> |
+ GetBrowserPluginGuest()->instance_id(); |
+ DestroyGuestByInstanceID(instance_id); |
+ } |
+} |
+ |
+void BrowserPluginEmbedder::RenderViewDeleted( |
+ RenderViewHost* render_view_host) { |
+ DestroyGuests(); |
+} |
+ |
+void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { |
+ DestroyGuests(); |
+} |
+ |
+void BrowserPluginEmbedder::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) { |
Charlie Reis
2012/08/27 20:23:59
nit: Wrong indent.
lazyboy
2012/08/28 19:07:14
Done.
|
+ WebContents* web_contents = it->first; |
+ if (visible) |
+ web_contents->WasShown(); |
+ else |
+ web_contents->WasHidden(); |
+ } |
+} |
+ |
+void BrowserPluginEmbedder::PluginDestroyed(int instance_id) { |
+ DestroyGuestByInstanceID(instance_id); |
+} |
+ |
+} // namespace content |