| 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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" | 8 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace { | 27 namespace { |
| 28 const int kGuestHangTimeout = 5000; | 28 const int kGuestHangTimeout = 5000; |
| 29 } | 29 } |
| 30 | 30 |
| 31 BrowserPluginHost::BrowserPluginHost( | 31 BrowserPluginHost::BrowserPluginHost( |
| 32 WebContentsImpl* web_contents) | 32 WebContentsImpl* web_contents) |
| 33 : WebContentsObserver(web_contents), | 33 : WebContentsObserver(web_contents), |
| 34 embedder_render_process_host_(NULL), | 34 embedder_render_process_host_(NULL), |
| 35 instance_id_(0), | 35 instance_id_(0), |
| 36 damage_buffer_(NULL), | 36 damage_buffer_(NULL), |
| 37 pending_update_counter_(0) { | 37 pending_update_counter_(0), |
| 38 // Explicitly zero-initialize |
| 39 surface_params_() { |
| 38 // Listen to visibility changes so that an embedder hides its guests | 40 // Listen to visibility changes so that an embedder hides its guests |
| 39 // as well. | 41 // as well. |
| 40 registrar_.Add(this, | 42 registrar_.Add(this, |
| 41 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 43 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 42 Source<WebContents>(web_contents)); | 44 Source<WebContents>(web_contents)); |
| 43 // Construct plumbing helpers when a new RenderViewHost is created for | 45 // Construct plumbing helpers when a new RenderViewHost is created for |
| 44 // this BrowserPluginHost's WebContentsImpl. | 46 // this BrowserPluginHost's WebContentsImpl. |
| 45 registrar_.Add(this, | 47 registrar_.Add(this, |
| 46 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 48 NOTIFICATION_WEB_CONTENTS_WILL_CREATE_RENDER_VIEW, |
| 47 Source<WebContents>(web_contents)); | 49 Source<WebContents>(web_contents)); |
| 48 } | 50 } |
| 49 | 51 |
| 50 BrowserPluginHost::~BrowserPluginHost() { | 52 BrowserPluginHost::~BrowserPluginHost() { |
| 51 if (damage_buffer_) | 53 if (damage_buffer_) |
| 52 delete damage_buffer_; | 54 delete damage_buffer_; |
| 53 } | 55 } |
| 54 | 56 |
| 55 BrowserPluginHost* BrowserPluginHost::GetGuestByInstanceID( | 57 BrowserPluginHost* BrowserPluginHost::GetGuestByInstanceID( |
| 56 int instance_id) const { | 58 int instance_id) const { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 | 88 |
| 87 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { | 89 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { |
| 88 return false; | 90 return false; |
| 89 } | 91 } |
| 90 | 92 |
| 91 void BrowserPluginHost::NavigateGuest( | 93 void BrowserPluginHost::NavigateGuest( |
| 92 RenderViewHost* render_view_host, | 94 RenderViewHost* render_view_host, |
| 93 int instance_id, | 95 int instance_id, |
| 94 int64 frame_id, | 96 int64 frame_id, |
| 95 const std::string& src, | 97 const std::string& src, |
| 96 const gfx::Size& size) { | 98 const gfx::Size& size, |
| 99 const BrowserPluginHostMsg_Surface_Params& params) { |
| 97 BrowserPluginHost* guest = GetGuestByInstanceID(instance_id); | 100 BrowserPluginHost* guest = GetGuestByInstanceID(instance_id); |
| 98 WebContentsImpl* guest_web_contents = NULL; | 101 WebContentsImpl* guest_web_contents = NULL; |
| 99 GURL url(src); | 102 GURL url(src); |
| 100 if (!guest) { | 103 if (!guest) { |
| 101 std::string host = render_view_host->GetSiteInstance()->GetSite().host(); | 104 std::string host = render_view_host->GetSiteInstance()->GetSite().host(); |
| 102 GURL guest_site( | 105 GURL guest_site( |
| 103 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); | 106 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); |
| 104 // The SiteInstance of a given guest is based on the fact that it's a guest | 107 // The SiteInstance of a given guest is based on the fact that it's a guest |
| 105 // in addition to which platform application the guest belongs to, rather | 108 // in addition to which platform application the guest belongs to, rather |
| 106 // than the URL that the guest is being navigated to. | 109 // than the URL that the guest is being navigated to. |
| 107 SiteInstance* guest_site_instance = | 110 SiteInstance* guest_site_instance = |
| 108 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), | 111 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), |
| 109 guest_site); | 112 guest_site); |
| 110 guest_web_contents = | 113 guest_web_contents = |
| 111 static_cast<WebContentsImpl*>( | 114 static_cast<WebContentsImpl*>( |
| 112 WebContents::Create( | 115 WebContents::Create( |
| 113 web_contents()->GetBrowserContext(), | 116 web_contents()->GetBrowserContext(), |
| 114 guest_site_instance, | 117 guest_site_instance, |
| 115 MSG_ROUTING_NONE, | 118 MSG_ROUTING_NONE, |
| 116 NULL // base WebContents | 119 NULL // base WebContents |
| 117 )); | 120 )); |
| 118 guest = guest_web_contents->browser_plugin_host(); | 121 guest = guest_web_contents->browser_plugin_host(); |
| 122 guest->set_surface_params(params); |
| 119 guest->set_embedder_render_process_host( | 123 guest->set_embedder_render_process_host( |
| 120 render_view_host->GetProcess()); | 124 render_view_host->GetProcess()); |
| 121 guest->set_instance_id(instance_id); | 125 guest->set_instance_id(instance_id); |
| 122 guest_web_contents->GetMutableRendererPrefs()-> | 126 guest_web_contents->GetMutableRendererPrefs()-> |
| 123 throttle_input_events = false; | 127 throttle_input_events = false; |
| 124 AddGuest(instance_id, guest, frame_id); | 128 AddGuest(instance_id, guest, frame_id); |
| 125 } else { | 129 } else { |
| 126 guest_web_contents = static_cast<WebContentsImpl*>(guest->web_contents()); | 130 guest_web_contents = static_cast<WebContentsImpl*>(guest->web_contents()); |
| 131 guest_web_contents->browser_plugin_host()->set_surface_params(params); |
| 127 } | 132 } |
| 128 guest->web_contents()->SetDelegate(guest); | 133 guest->web_contents()->SetDelegate(guest); |
| 129 guest->web_contents()->GetController().LoadURL( | 134 guest->web_contents()->GetController().LoadURL( |
| 130 url, | 135 url, |
| 131 Referrer(), | 136 Referrer(), |
| 132 PAGE_TRANSITION_AUTO_SUBFRAME, | 137 PAGE_TRANSITION_AUTO_SUBFRAME, |
| 133 std::string()); | 138 std::string()); |
| 134 if (!size.IsEmpty()) | 139 if (!size.IsEmpty()) |
| 135 guest_web_contents->GetView()->SizeContents(size); | 140 guest_web_contents->GetView()->SizeContents(size); |
| 136 } | 141 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 156 WebContentsImpl* guest_web_contents = | 161 WebContentsImpl* guest_web_contents = |
| 157 guest ? static_cast<WebContentsImpl*>(guest->web_contents()): NULL; | 162 guest ? static_cast<WebContentsImpl*>(guest->web_contents()): NULL; |
| 158 guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor); | 163 guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor); |
| 159 if (!resize_pending) | 164 if (!resize_pending) |
| 160 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); | 165 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); |
| 161 } | 166 } |
| 162 | 167 |
| 163 void BrowserPluginHost::UpdateRect( | 168 void BrowserPluginHost::UpdateRect( |
| 164 RenderViewHost* render_view_host, | 169 RenderViewHost* render_view_host, |
| 165 const ViewHostMsg_UpdateRect_Params& params) { | 170 const ViewHostMsg_UpdateRect_Params& params) { |
| 166 // This handler is only of interest to us for the 2D software rendering path. | |
| 167 // needs_ack should always be true for the 2D path. | |
| 168 // TODO(fsamuel): Do we need to do something different in the 3D case? | |
| 169 if (!params.needs_ack) | |
| 170 return; | |
| 171 | |
| 172 // Only copy damage if the guest's view size is equal to the damage buffer's | 171 // Only copy damage if the guest's view size is equal to the damage buffer's |
| 173 // size and the guest's scale factor is equal to the damage buffer's scale | 172 // size and the guest's scale factor is equal to the damage buffer's scale |
| 174 // factor. | 173 // factor. |
| 175 if (params.view_size.width() == damage_buffer_size().width() && | 174 if (params.view_size.width() == damage_buffer_size().width() && |
| 176 params.view_size.height() == damage_buffer_size().height() && | 175 params.view_size.height() == damage_buffer_size().height() && |
| 177 params.scale_factor == damage_buffer_scale_factor()) { | 176 params.scale_factor == damage_buffer_scale_factor()) { |
| 178 TransportDIB* dib = render_view_host->GetProcess()-> | 177 TransportDIB* dib = render_view_host->GetProcess()-> |
| 179 GetTransportDIB(params.bitmap); | 178 GetTransportDIB(params.bitmap); |
| 180 if (dib) { | 179 if (dib) { |
| 181 void* guest_memory = dib->memory(); | 180 void* guest_memory = dib->memory(); |
| 182 void* embedder_memory = damage_buffer_->memory(); | 181 void* embedder_memory = damage_buffer_->memory(); |
| 183 int size = std::min(dib->size(), damage_buffer_->size()); | 182 int size = std::min(dib->size(), damage_buffer_->size()); |
| 184 memcpy(embedder_memory, guest_memory, size); | 183 memcpy(embedder_memory, guest_memory, size); |
| 185 } | 184 } |
| 186 } | 185 } |
| 187 DCHECK(embedder_render_process_host()); | 186 DCHECK(embedder_render_process_host()); |
| 188 BrowserPluginMsg_UpdateRect_Params relay_params; | 187 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 189 relay_params.bitmap_rect = params.bitmap_rect; | 188 relay_params.bitmap_rect = params.bitmap_rect; |
| 190 relay_params.dx = params.dx; | 189 relay_params.dx = params.dx; |
| 191 relay_params.dy = params.dy; | 190 relay_params.dy = params.dy; |
| 192 relay_params.scroll_rect = params.scroll_rect; | 191 relay_params.scroll_rect = params.scroll_rect; |
| 193 relay_params.copy_rects = params.copy_rects; | 192 relay_params.copy_rects = params.copy_rects; |
| 194 relay_params.view_size = params.view_size; | 193 relay_params.view_size = params.view_size; |
| 195 relay_params.scale_factor = params.scale_factor; | 194 relay_params.scale_factor = params.scale_factor; |
| 196 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 195 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 197 params.flags); | 196 params.flags); |
| 197 relay_params.needs_ack = params.needs_ack; |
| 198 | 198 |
| 199 // We need to send the ACK to the same render_view_host that issued | 199 // We need to send the ACK to the same render_view_host that issued |
| 200 // the UpdateRect. We keep track of this correspondence via a message_id. | 200 // the UpdateRect. We keep track of this correspondence via a message_id. |
| 201 int message_id = pending_update_counter_++; | 201 int message_id = pending_update_counter_++; |
| 202 pending_updates_.AddWithID(render_view_host, message_id); | 202 pending_updates_.AddWithID(render_view_host, message_id); |
| 203 | 203 |
| 204 gfx::Size param_size = gfx::Size( | 204 gfx::Size param_size = gfx::Size( |
| 205 params.view_size.width(), | 205 params.view_size.width(), |
| 206 params.view_size.height()); | 206 params.view_size.height()); |
| 207 content::NotificationService::current()->Notify( | 207 content::NotificationService::current()->Notify( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 static_cast<RenderViewHostImpl*>(render_view_host); | 273 static_cast<RenderViewHostImpl*>(render_view_host); |
| 274 guest_rvh->StopHangMonitorTimeout(); | 274 guest_rvh->StopHangMonitorTimeout(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void BrowserPluginHost::SetFocus(bool focused) { | 277 void BrowserPluginHost::SetFocus(bool focused) { |
| 278 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); | 278 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); |
| 279 render_view_host->Send( | 279 render_view_host->Send( |
| 280 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused)); | 280 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused)); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void BrowserPluginHost::SendBuffersSwappedToEmbedder( |
| 284 uint64 surface_handle, |
| 285 const BrowserPlugin_SwapInfo& info) { |
| 286 DCHECK(embedder_render_process_host()); |
| 287 embedder_render_process_host()->Send( |
| 288 new BrowserPluginMsg_BuffersSwapped(instance_id_, surface_handle, info)); |
| 289 } |
| 290 |
| 291 void BrowserPluginHost::SendSurfaceResizeToEmbedder(const gfx::Size& size) { |
| 292 DCHECK(embedder_render_process_host()); |
| 293 embedder_render_process_host()->Send( |
| 294 new BrowserPluginMsg_SurfaceResize(instance_id_, size)); |
| 295 } |
| 296 |
| 283 void BrowserPluginHost::ShowWidget(RenderViewHost* render_view_host, | 297 void BrowserPluginHost::ShowWidget(RenderViewHost* render_view_host, |
| 284 int route_id, | 298 int route_id, |
| 285 const gfx::Rect& initial_pos) { | 299 const gfx::Rect& initial_pos) { |
| 286 RenderWidgetHostView* popup_rwhv = | 300 RenderWidgetHostView* popup_rwhv = |
| 287 static_cast<WebContentsImpl*>(web_contents())-> | 301 static_cast<WebContentsImpl*>(web_contents())-> |
| 288 GetCreatedWidget(route_id); | 302 GetCreatedWidget(route_id); |
| 289 | 303 |
| 290 RenderWidgetHostViewPort* widget_host_view = | 304 RenderWidgetHostViewPort* widget_host_view = |
| 291 RenderWidgetHostViewPort::FromRWHV(popup_rwhv); | 305 RenderWidgetHostViewPort::FromRWHV(popup_rwhv); |
| 292 if (!widget_host_view) | 306 if (!widget_host_view) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 content::Source<BrowserPluginHost>(this), | 401 content::Source<BrowserPluginHost>(this), |
| 388 content::NotificationService::NoDetails()); | 402 content::NotificationService::NoDetails()); |
| 389 } | 403 } |
| 390 } | 404 } |
| 391 | 405 |
| 392 void BrowserPluginHost::Observe( | 406 void BrowserPluginHost::Observe( |
| 393 int type, | 407 int type, |
| 394 const NotificationSource& source, | 408 const NotificationSource& source, |
| 395 const NotificationDetails& details) { | 409 const NotificationDetails& details) { |
| 396 switch (type) { | 410 switch (type) { |
| 397 case NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: { | 411 case NOTIFICATION_WEB_CONTENTS_WILL_CREATE_RENDER_VIEW: { |
| 398 RenderViewHost* render_view_host = | 412 RenderViewHost* render_view_host = |
| 399 Details<RenderViewHost>(details).ptr(); | 413 Details<RenderViewHost>(details).ptr(); |
| 400 // BrowserPluginHostHelper is destroyed when its associated RenderViewHost | 414 // BrowserPluginHostHelper is destroyed when its associated RenderViewHost |
| 401 // is destroyed. | 415 // is destroyed. |
| 402 new BrowserPluginHostHelper(this, render_view_host); | 416 new BrowserPluginHostHelper(this, render_view_host, surface_params_); |
| 403 break; | 417 break; |
| 404 } | 418 } |
| 405 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { | 419 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { |
| 406 bool visible = *Details<bool>(details).ptr(); | 420 bool visible = *Details<bool>(details).ptr(); |
| 407 // If the embedder is hidden we need to hide the guests as well. | 421 // If the embedder is hidden we need to hide the guests as well. |
| 408 for (GuestMap::const_iterator it = guests_.begin(); | 422 for (GuestMap::const_iterator it = guests_.begin(); |
| 409 it != guests_.end(); ++it) { | 423 it != guests_.end(); ++it) { |
| 410 WebContents* web_contents = it->first; | 424 WebContents* web_contents = it->first; |
| 411 if (visible) | 425 if (visible) |
| 412 web_contents->WasShown(); | 426 web_contents->WasShown(); |
| 413 else | 427 else |
| 414 web_contents->WasHidden(); | 428 web_contents->WasHidden(); |
| 415 } | 429 } |
| 416 break; | 430 break; |
| 417 } | 431 } |
| 418 default: | 432 default: |
| 419 NOTREACHED() << "Unexpected notification type: " << type; | 433 NOTREACHED() << "Unexpected notification type: " << type; |
| 420 } | 434 } |
| 421 } | 435 } |
| 422 | 436 |
| 423 } // namespace content | 437 } // namespace content |
| OLD | NEW |