| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/browser_plugin/browser_plugin_host.h" | 5 #include "content/browser/browser_plugin/browser_plugin_host.h" |
| 6 | 6 |
| 7 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" | 7 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 damage_buffer_(NULL), | 29 damage_buffer_(NULL), |
| 30 pending_update_counter_(0) { | 30 pending_update_counter_(0) { |
| 31 // Listen to visibility changes so that an embedder hides its guests | 31 // Listen to visibility changes so that an embedder hides its guests |
| 32 // as well. | 32 // as well. |
| 33 registrar_.Add(this, | 33 registrar_.Add(this, |
| 34 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 34 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 35 Source<WebContents>(web_contents)); | 35 Source<WebContents>(web_contents)); |
| 36 // Construct plumbing helpers when a new RenderViewHost is created for | 36 // Construct plumbing helpers when a new RenderViewHost is created for |
| 37 // this BrowserPluginHost's WebContentsImpl. | 37 // this BrowserPluginHost's WebContentsImpl. |
| 38 registrar_.Add(this, | 38 registrar_.Add(this, |
| 39 NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 39 NOTIFICATION_WILL_CREATE_RENDER_VIEW, |
| 40 Source<WebContents>(web_contents)); | 40 Source<WebContents>(web_contents)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 BrowserPluginHost::~BrowserPluginHost() { | 43 BrowserPluginHost::~BrowserPluginHost() { |
| 44 if (damage_buffer_) | 44 if (damage_buffer_) |
| 45 delete damage_buffer_; | 45 delete damage_buffer_; |
| 46 } | 46 } |
| 47 | 47 |
| 48 BrowserPluginHost* BrowserPluginHost::GetGuestByContainerID(int container_id) { | 48 BrowserPluginHost* BrowserPluginHost::GetGuestByContainerID(int container_id) { |
| 49 ContainerInstanceMap::const_iterator it = | 49 ContainerInstanceMap::const_iterator it = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { | 70 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void BrowserPluginHost::NavigateGuestFromEmbedder( | 74 void BrowserPluginHost::NavigateGuestFromEmbedder( |
| 75 RenderViewHost* render_view_host, | 75 RenderViewHost* render_view_host, |
| 76 int container_instance_id, | 76 int container_instance_id, |
| 77 long long frame_id, | 77 long long frame_id, |
| 78 const std::string& src) { | 78 const std::string& src, |
| 79 const BrowserPluginHostMsg_Surface_Params& params) { |
| 79 BrowserPluginHost* guest = | 80 BrowserPluginHost* guest = |
| 80 GetGuestByContainerID(container_instance_id); | 81 GetGuestByContainerID(container_instance_id); |
| 81 WebContentsImpl* guest_web_contents = | 82 WebContentsImpl* guest_web_contents = |
| 82 guest ? | 83 guest ? |
| 83 static_cast<WebContentsImpl*>(guest->web_contents()): NULL; | 84 static_cast<WebContentsImpl*>(guest->web_contents()): NULL; |
| 84 GURL url(src); | 85 GURL url(src); |
| 85 if (!guest) { | 86 if (!guest) { |
| 86 std::string host = render_view_host->GetSiteInstance()->GetSite().host(); | 87 std::string host = render_view_host->GetSiteInstance()->GetSite().host(); |
| 87 GURL guest_url( | 88 GURL guest_url( |
| 88 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); | 89 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); |
| 89 // The SiteInstance of a given guest is based on the fact that it's a guest | 90 // The SiteInstance of a given guest is based on the fact that it's a guest |
| 90 // in addition to which platform application the guest belongs to, rather | 91 // in addition to which platform application the guest belongs to, rather |
| 91 // than the URL that the guest is being navigated to. | 92 // than the URL that the guest is being navigated to. |
| 92 SiteInstance* guest_site_instance = | 93 SiteInstance* guest_site_instance = |
| 93 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), | 94 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), |
| 94 guest_url); | 95 guest_url); |
| 95 guest_web_contents = | 96 guest_web_contents = |
| 96 static_cast<WebContentsImpl*>( | 97 static_cast<WebContentsImpl*>( |
| 97 WebContents::Create( | 98 WebContents::Create( |
| 98 web_contents()->GetBrowserContext(), | 99 web_contents()->GetBrowserContext(), |
| 99 guest_site_instance, | 100 guest_site_instance, |
| 100 MSG_ROUTING_NONE, | 101 MSG_ROUTING_NONE, |
| 101 NULL, // base WebContents | 102 NULL, // base WebContents |
| 102 NULL // session storage namespace | 103 NULL // session storage namespace |
| 103 )); | 104 )); |
| 104 guest = guest_web_contents->browser_plugin_host(); | 105 guest = guest_web_contents->browser_plugin_host(); |
| 106 guest->set_surface_params(params); |
| 105 guest->set_embedder_render_process_host( | 107 guest->set_embedder_render_process_host( |
| 106 render_view_host->GetProcess()); | 108 render_view_host->GetProcess()); |
| 107 guest->set_instance_id(container_instance_id); | 109 guest->set_instance_id(container_instance_id); |
| 108 RegisterContainerInstance(container_instance_id, guest); | 110 RegisterContainerInstance(container_instance_id, guest); |
| 109 AddGuest(guest_web_contents, frame_id); | 111 AddGuest(guest_web_contents, frame_id); |
| 110 } | 112 } |
| 111 guest->web_contents()->SetDelegate(guest); | 113 guest->web_contents()->SetDelegate(guest); |
| 112 guest->web_contents()->GetController().LoadURL( | 114 guest->web_contents()->GetController().LoadURL( |
| 113 url, | 115 url, |
| 114 Referrer(), | 116 Referrer(), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 handled); | 219 handled); |
| 218 embedder_render_process_host()->Send(reply_message); | 220 embedder_render_process_host()->Send(reply_message); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void BrowserPluginHost::SetFocus(bool focused) { | 223 void BrowserPluginHost::SetFocus(bool focused) { |
| 222 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); | 224 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); |
| 223 render_view_host->Send( | 225 render_view_host->Send( |
| 224 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused)); | 226 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused)); |
| 225 } | 227 } |
| 226 | 228 |
| 229 void BrowserPluginHost::SendBuffersSwappedToEmbedder(uint64 surface_handle, cons
t BrowserPlugin_SwapInfo& info) { |
| 230 DCHECK(embedder_render_process_host()); |
| 231 embedder_render_process_host()->Send( |
| 232 new BrowserPluginMsg_BuffersSwapped(instance_id_, surface_handle, info)); |
| 233 } |
| 234 |
| 235 |
| 227 void BrowserPluginHost::AddGuest(WebContentsImpl* guest, int64 frame_id) { | 236 void BrowserPluginHost::AddGuest(WebContentsImpl* guest, int64 frame_id) { |
| 228 guests_[guest] = frame_id; | 237 guests_[guest] = frame_id; |
| 229 } | 238 } |
| 230 | 239 |
| 231 void BrowserPluginHost::RemoveGuest(WebContentsImpl* guest) { | 240 void BrowserPluginHost::RemoveGuest(WebContentsImpl* guest) { |
| 232 guests_.erase(guest); | 241 guests_.erase(guest); |
| 233 } | 242 } |
| 234 | 243 |
| 235 void BrowserPluginHost::DestroyGuests() { | 244 void BrowserPluginHost::DestroyGuests() { |
| 236 for (GuestMap::const_iterator it = guests_.begin(); | 245 for (GuestMap::const_iterator it = guests_.begin(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 embedder_render_process_host()->Send( | 286 embedder_render_process_host()->Send( |
| 278 new BrowserPluginMsg_GuestCrashed(instance_id())); | 287 new BrowserPluginMsg_GuestCrashed(instance_id())); |
| 279 } | 288 } |
| 280 } | 289 } |
| 281 | 290 |
| 282 void BrowserPluginHost::Observe( | 291 void BrowserPluginHost::Observe( |
| 283 int type, | 292 int type, |
| 284 const NotificationSource& source, | 293 const NotificationSource& source, |
| 285 const NotificationDetails& details) { | 294 const NotificationDetails& details) { |
| 286 switch (type) { | 295 switch (type) { |
| 287 case NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 296 case NOTIFICATION_WILL_CREATE_RENDER_VIEW: { |
| 288 RenderViewHost* render_view_host = | 297 RenderViewHost* render_view_host = |
| 289 Details<RenderViewHost>(details).ptr(); | 298 Details<RenderViewHost>(details).ptr(); |
| 290 // BrowserPluginHostHelper is destroyed when its associated RenderViewHost | 299 // BrowserPluginHostHelper is destroyed when its associated RenderViewHost |
| 291 // is destroyed. | 300 // is destroyed. |
| 292 new BrowserPluginHostHelper(this, render_view_host); | 301 new BrowserPluginHostHelper(this, render_view_host, surface_params_); |
| 293 break; | 302 break; |
| 294 } | 303 } |
| 295 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { | 304 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { |
| 296 bool visible = *Details<bool>(details).ptr(); | 305 bool visible = *Details<bool>(details).ptr(); |
| 297 // If the embedder is hidden we need to hide the guests as well. | 306 // If the embedder is hidden we need to hide the guests as well. |
| 298 for (GuestMap::const_iterator it = guests_.begin(); | 307 for (GuestMap::const_iterator it = guests_.begin(); |
| 299 it != guests_.end(); ++it) { | 308 it != guests_.end(); ++it) { |
| 300 WebContentsImpl* web_contents = it->first; | 309 WebContentsImpl* web_contents = it->first; |
| 301 if (visible) | 310 if (visible) |
| 302 web_contents->WasRestored(); | 311 web_contents->WasRestored(); |
| 303 else | 312 else |
| 304 web_contents->WasHidden(); | 313 web_contents->WasHidden(); |
| 305 } | 314 } |
| 306 break; | 315 break; |
| 307 } | 316 } |
| 308 default: | 317 default: |
| 309 NOTREACHED() << "Unexpected notification type: " << type; | 318 NOTREACHED() << "Unexpected notification type: " << type; |
| 310 } | 319 } |
| 311 } | 320 } |
| 312 | 321 |
| 313 } // namespace browser_plugin | 322 } // namespace browser_plugin |
| 314 } // namespace content | 323 } // namespace content |
| OLD | NEW |