| 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_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 52 damage_buffer_size_(0), | 52 damage_buffer_size_(0), |
| 53 #endif | 53 #endif |
| 54 damage_buffer_scale_factor_(1.0f), | 54 damage_buffer_scale_factor_(1.0f), |
| 55 pending_update_counter_(0), | 55 pending_update_counter_(0), |
| 56 guest_hang_timeout_( | 56 guest_hang_timeout_( |
| 57 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), | 57 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), |
| 58 focused_(params.focused), | 58 focused_(params.focused), |
| 59 visible_(params.visible), | 59 visible_(params.visible), |
| 60 auto_size_(params.auto_size.enable), | 60 auto_size_(params.auto_size.enable), |
| 61 max_height_(params.auto_size.max_height), | 61 max_auto_size_(params.auto_size.max_size), |
| 62 max_width_(params.auto_size.max_width), | 62 min_auto_size_(params.auto_size.min_size) { |
| 63 min_height_(params.auto_size.min_height), | |
| 64 min_width_(params.auto_size.min_width) { | |
| 65 DCHECK(web_contents); | 63 DCHECK(web_contents); |
| 66 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 64 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
| 67 new BrowserPluginGuestHelper(this, render_view_host); | 65 new BrowserPluginGuestHelper(this, render_view_host); |
| 68 | 66 |
| 69 notification_registrar_.Add( | 67 notification_registrar_.Add( |
| 70 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 68 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 71 content::Source<content::WebContents>(web_contents)); | 69 content::Source<content::WebContents>(web_contents)); |
| 72 } | 70 } |
| 73 | 71 |
| 74 BrowserPluginGuest::~BrowserPluginGuest() { | 72 BrowserPluginGuest::~BrowserPluginGuest() { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 host->DragTargetDragLeave(); | 185 host->DragTargetDragLeave(); |
| 188 break; | 186 break; |
| 189 case WebKit::WebDragStatusDrop: | 187 case WebKit::WebDragStatusDrop: |
| 190 host->DragTargetDrop(location, location, 0); | 188 host->DragTargetDrop(location, location, 0); |
| 191 break; | 189 break; |
| 192 case WebKit::WebDragStatusUnknown: | 190 case WebKit::WebDragStatusUnknown: |
| 193 NOTREACHED(); | 191 NOTREACHED(); |
| 194 } | 192 } |
| 195 } | 193 } |
| 196 | 194 |
| 195 void BrowserPluginGuest::SetAutoSize( |
| 196 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, |
| 197 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { |
| 198 auto_size_ = auto_size_params.enable; |
| 199 max_auto_size_ = auto_size_params.max_size; |
| 200 min_auto_size_ = auto_size_params.min_size; |
| 201 if (auto_size_) { |
| 202 web_contents()->GetRenderViewHost()->EnableAutoResize( |
| 203 min_auto_size_, max_auto_size_); |
| 204 } else { |
| 205 web_contents()->GetRenderViewHost()->DisableAutoResize( |
| 206 gfx::Size(resize_guest_params.width, resize_guest_params.height)); |
| 207 } |
| 208 // We call resize here to update the damage buffer. |
| 209 Resize(embedder_web_contents_->GetRenderViewHost(), resize_guest_params); |
| 210 } |
| 211 |
| 197 void BrowserPluginGuest::UpdateDragCursor(WebKit::WebDragOperation operation) { | 212 void BrowserPluginGuest::UpdateDragCursor(WebKit::WebDragOperation operation) { |
| 198 RenderViewHostImpl* embedder_render_view_host = | 213 RenderViewHostImpl* embedder_render_view_host = |
| 199 static_cast<RenderViewHostImpl*>( | 214 static_cast<RenderViewHostImpl*>( |
| 200 embedder_web_contents_->GetRenderViewHost()); | 215 embedder_web_contents_->GetRenderViewHost()); |
| 201 CHECK(embedder_render_view_host); | 216 CHECK(embedder_render_view_host); |
| 202 RenderViewHostDelegateView* view = | 217 RenderViewHostDelegateView* view = |
| 203 embedder_render_view_host->GetDelegate()->GetDelegateView(); | 218 embedder_render_view_host->GetDelegate()->GetDelegateView(); |
| 204 if (view) | 219 if (view) |
| 205 view->UpdateDragCursor(operation); | 220 view->UpdateDragCursor(operation); |
| 206 } | 221 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // between the embedder and browser processes. | 294 // between the embedder and browser processes. |
| 280 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); | 295 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); |
| 281 damage_buffer_.reset(damage_buffer); | 296 damage_buffer_.reset(damage_buffer); |
| 282 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
| 283 damage_buffer_size_ = damage_buffer_size; | 298 damage_buffer_size_ = damage_buffer_size; |
| 284 #endif | 299 #endif |
| 285 damage_view_size_ = damage_view_size; | 300 damage_view_size_ = damage_view_size; |
| 286 damage_buffer_scale_factor_ = scale_factor; | 301 damage_buffer_scale_factor_ = scale_factor; |
| 287 } | 302 } |
| 288 | 303 |
| 304 bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const { |
| 305 return size.width() <= max_auto_size_.width() && |
| 306 size.height() <= max_auto_size_.height(); |
| 307 } |
| 308 |
| 289 void BrowserPluginGuest::UpdateRect( | 309 void BrowserPluginGuest::UpdateRect( |
| 290 RenderViewHost* render_view_host, | 310 RenderViewHost* render_view_host, |
| 291 const ViewHostMsg_UpdateRect_Params& params) { | 311 const ViewHostMsg_UpdateRect_Params& params) { |
| 292 RenderWidgetHostImpl* render_widget_host = | 312 RenderWidgetHostImpl* render_widget_host = |
| 293 RenderWidgetHostImpl::From(render_view_host); | 313 RenderWidgetHostImpl::From(render_view_host); |
| 294 render_widget_host->ResetSizeAndRepaintPendingFlags(); | 314 render_widget_host->ResetSizeAndRepaintPendingFlags(); |
| 295 // This handler is only of interest to us for the 2D software rendering path. | 315 // This handler is only of interest to us for the 2D software rendering path. |
| 296 // needs_ack should always be true for the 2D path. | 316 // needs_ack should always be true for the 2D path. |
| 297 // TODO(fsamuel): Do we need to do something different in the 3D case? | 317 // TODO(fsamuel): Do we need to do something different in the 3D case? |
| 298 if (!params.needs_ack) | 318 if (!params.needs_ack) |
| 299 return; | 319 return; |
| 300 | 320 |
| 301 // Only copy damage if the guest's view size is equal to the damage buffer's | 321 // Only copy damage if the guest is in autosize mode and the guest's view size |
| 302 // size and the guest's scale factor is equal to the damage buffer's scale | 322 // is less than the maximum size or the guest's view size is equal to the |
| 303 // factor. | 323 // damage buffer's size and the guest's scale factor is equal to the damage |
| 324 // buffer's scale factor. |
| 304 // The scaling change can happen due to asynchronous updates of the DPI on a | 325 // The scaling change can happen due to asynchronous updates of the DPI on a |
| 305 // resolution change. | 326 // resolution change. |
| 306 if (params.view_size.width() == damage_view_size().width() && | 327 if (((auto_size_ && InAutoSizeBounds(params.view_size)) || |
| 307 params.view_size.height() == damage_view_size().height() && | 328 (params.view_size.width() == damage_view_size().width() && |
| 308 params.scale_factor == damage_buffer_scale_factor()) { | 329 params.view_size.height() == damage_view_size().height())) && |
| 330 params.scale_factor == damage_buffer_scale_factor()) { |
| 309 TransportDIB* dib = render_view_host->GetProcess()-> | 331 TransportDIB* dib = render_view_host->GetProcess()-> |
| 310 GetTransportDIB(params.bitmap); | 332 GetTransportDIB(params.bitmap); |
| 311 if (dib) { | 333 if (dib) { |
| 312 #if defined(OS_WIN) | 334 #if defined(OS_WIN) |
| 313 size_t guest_damage_buffer_size = params.bitmap_rect.width() * | 335 size_t guest_damage_buffer_size = params.bitmap_rect.width() * |
| 314 params.bitmap_rect.height() * 4; | 336 params.bitmap_rect.height() * 4; |
| 315 size_t embedder_damage_buffer_size = damage_buffer_size_; | 337 size_t embedder_damage_buffer_size = damage_buffer_size_; |
| 316 #else | 338 #else |
| 317 size_t guest_damage_buffer_size = dib->size(); | 339 size_t guest_damage_buffer_size = dib->size(); |
| 318 size_t embedder_damage_buffer_size = damage_buffer_->size(); | 340 size_t embedder_damage_buffer_size = damage_buffer_->size(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 541 |
| 520 void BrowserPluginGuest::RenderViewReady() { | 542 void BrowserPluginGuest::RenderViewReady() { |
| 521 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 543 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 522 // here (see http://www.crbug.com/158151). | 544 // here (see http://www.crbug.com/158151). |
| 523 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); | 545 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); |
| 524 render_view_host->Send( | 546 render_view_host->Send( |
| 525 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused_)); | 547 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused_)); |
| 526 bool embedder_visible = | 548 bool embedder_visible = |
| 527 embedder_web_contents_->GetBrowserPluginEmbedder()->visible(); | 549 embedder_web_contents_->GetBrowserPluginEmbedder()->visible(); |
| 528 SetVisibility(embedder_visible, visible()); | 550 SetVisibility(embedder_visible, visible()); |
| 551 if (auto_size_) { |
| 552 web_contents()->GetRenderViewHost()->EnableAutoResize( |
| 553 min_auto_size_, max_auto_size_); |
| 554 } else { |
| 555 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); |
| 556 } |
| 529 } | 557 } |
| 530 | 558 |
| 531 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { | 559 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
| 532 if (pending_input_event_reply_.get()) { | 560 if (pending_input_event_reply_.get()) { |
| 533 IPC::Message* reply_message = pending_input_event_reply_.release(); | 561 IPC::Message* reply_message = pending_input_event_reply_.release(); |
| 534 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, | 562 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, |
| 535 false, | 563 false, |
| 536 cursor_); | 564 cursor_); |
| 537 SendMessageToEmbedder(reply_message); | 565 SendMessageToEmbedder(reply_message); |
| 538 } | 566 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 559 default: | 587 default: |
| 560 break; | 588 break; |
| 561 } | 589 } |
| 562 } | 590 } |
| 563 | 591 |
| 564 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 592 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 565 embedder_web_contents_->GetRenderProcessHost()->Send(msg); | 593 embedder_web_contents_->GetRenderProcessHost()->Send(msg); |
| 566 } | 594 } |
| 567 | 595 |
| 568 } // namespace content | 596 } // namespace content |
| OLD | NEW |