Chromium Code Reviews| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 host->DragTargetDragLeave(); | 187 host->DragTargetDragLeave(); |
| 188 break; | 188 break; |
| 189 case WebKit::WebDragStatusDrop: | 189 case WebKit::WebDragStatusDrop: |
| 190 host->DragTargetDrop(location, location, 0); | 190 host->DragTargetDrop(location, location, 0); |
| 191 break; | 191 break; |
| 192 case WebKit::WebDragStatusUnknown: | 192 case WebKit::WebDragStatusUnknown: |
| 193 NOTREACHED(); | 193 NOTREACHED(); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 void BrowserPluginGuest::SetAutoSize( | |
| 198 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, | |
| 199 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { | |
| 200 auto_size_ = auto_size_params.enable; | |
| 201 max_height_ = auto_size_params.max_height; | |
| 202 max_width_ = auto_size_params.max_width; | |
| 203 min_height_ = auto_size_params.min_height; | |
| 204 min_width_ = auto_size_params.min_width; | |
| 205 if (auto_size_) { | |
| 206 web_contents()->GetRenderViewHost()->EnableAutoResize( | |
| 207 gfx::Size(min_width_, min_height_), gfx::Size(max_width_, max_height_)); | |
|
lazyboy
2012/11/06 22:22:35
probably easier to keep these as gfx::Size min_aut
Fady Samuel
2012/11/06 23:52:34
Done.
| |
| 208 } else { | |
| 209 web_contents()->GetRenderViewHost()->DisableAutoResize( | |
| 210 gfx::Size(resize_guest_params.width, resize_guest_params.height)); | |
| 211 } | |
| 212 // We call resize here to update the damage buffer. | |
| 213 Resize(embedder_web_contents_->GetRenderViewHost(), resize_guest_params); | |
| 214 } | |
| 215 | |
| 197 void BrowserPluginGuest::UpdateDragCursor(WebKit::WebDragOperation operation) { | 216 void BrowserPluginGuest::UpdateDragCursor(WebKit::WebDragOperation operation) { |
| 198 RenderViewHostImpl* embedder_render_view_host = | 217 RenderViewHostImpl* embedder_render_view_host = |
| 199 static_cast<RenderViewHostImpl*>( | 218 static_cast<RenderViewHostImpl*>( |
| 200 embedder_web_contents_->GetRenderViewHost()); | 219 embedder_web_contents_->GetRenderViewHost()); |
| 201 CHECK(embedder_render_view_host); | 220 CHECK(embedder_render_view_host); |
| 202 RenderViewHostDelegateView* view = | 221 RenderViewHostDelegateView* view = |
| 203 embedder_render_view_host->GetDelegate()->GetDelegateView(); | 222 embedder_render_view_host->GetDelegate()->GetDelegateView(); |
| 204 if (view) | 223 if (view) |
| 205 view->UpdateDragCursor(operation); | 224 view->UpdateDragCursor(operation); |
| 206 } | 225 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 // between the embedder and browser processes. | 298 // between the embedder and browser processes. |
| 280 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); | 299 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); |
| 281 damage_buffer_.reset(damage_buffer); | 300 damage_buffer_.reset(damage_buffer); |
| 282 #if defined(OS_WIN) | 301 #if defined(OS_WIN) |
| 283 damage_buffer_size_ = damage_buffer_size; | 302 damage_buffer_size_ = damage_buffer_size; |
| 284 #endif | 303 #endif |
| 285 damage_view_size_ = damage_view_size; | 304 damage_view_size_ = damage_view_size; |
| 286 damage_buffer_scale_factor_ = scale_factor; | 305 damage_buffer_scale_factor_ = scale_factor; |
| 287 } | 306 } |
| 288 | 307 |
| 308 bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const { | |
| 309 return size.width() <= max_width_ && size.height() <= max_height_; | |
| 310 } | |
| 311 | |
| 289 void BrowserPluginGuest::UpdateRect( | 312 void BrowserPluginGuest::UpdateRect( |
| 290 RenderViewHost* render_view_host, | 313 RenderViewHost* render_view_host, |
| 291 const ViewHostMsg_UpdateRect_Params& params) { | 314 const ViewHostMsg_UpdateRect_Params& params) { |
| 292 RenderWidgetHostImpl* render_widget_host = | 315 RenderWidgetHostImpl* render_widget_host = |
| 293 RenderWidgetHostImpl::From(render_view_host); | 316 RenderWidgetHostImpl::From(render_view_host); |
| 294 render_widget_host->ResetSizeAndRepaintPendingFlags(); | 317 render_widget_host->ResetSizeAndRepaintPendingFlags(); |
| 295 // This handler is only of interest to us for the 2D software rendering path. | 318 // 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. | 319 // needs_ack should always be true for the 2D path. |
| 297 // TODO(fsamuel): Do we need to do something different in the 3D case? | 320 // TODO(fsamuel): Do we need to do something different in the 3D case? |
| 298 if (!params.needs_ack) | 321 if (!params.needs_ack) |
| 299 return; | 322 return; |
| 300 | 323 |
| 301 // Only copy damage if the guest's view size is equal to the damage buffer's | 324 // 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 | 325 // is less than the maximum size or the guest's view size is equal to the |
| 303 // factor. | 326 // damage buffer's size and the guest's scale factor is equal to the damage |
| 327 // buffer's scale factor. | |
| 304 // The scaling change can happen due to asynchronous updates of the DPI on a | 328 // The scaling change can happen due to asynchronous updates of the DPI on a |
| 305 // resolution change. | 329 // resolution change. |
| 306 if (params.view_size.width() == damage_view_size().width() && | 330 if ((auto_size_ && InAutoSizeBounds(params.view_size)) || |
|
lazyboy
2012/11/06 22:22:35
Do we need to handle the case where auto_size is s
Fady Samuel
2012/11/06 23:52:34
Good catch. In this case, we still want to drop th
| |
| 307 params.view_size.height() == damage_view_size().height() && | 331 (params.view_size.width() == damage_view_size().width() && |
| 308 params.scale_factor == damage_buffer_scale_factor()) { | 332 params.view_size.height() == damage_view_size().height() && |
| 333 params.scale_factor == damage_buffer_scale_factor())) { | |
| 309 TransportDIB* dib = render_view_host->GetProcess()-> | 334 TransportDIB* dib = render_view_host->GetProcess()-> |
| 310 GetTransportDIB(params.bitmap); | 335 GetTransportDIB(params.bitmap); |
| 311 if (dib) { | 336 if (dib) { |
| 312 #if defined(OS_WIN) | 337 #if defined(OS_WIN) |
| 313 size_t guest_damage_buffer_size = params.bitmap_rect.width() * | 338 size_t guest_damage_buffer_size = params.bitmap_rect.width() * |
| 314 params.bitmap_rect.height() * 4; | 339 params.bitmap_rect.height() * 4; |
| 315 size_t embedder_damage_buffer_size = damage_buffer_size_; | 340 size_t embedder_damage_buffer_size = damage_buffer_size_; |
| 316 #else | 341 #else |
| 317 size_t guest_damage_buffer_size = dib->size(); | 342 size_t guest_damage_buffer_size = dib->size(); |
| 318 size_t embedder_damage_buffer_size = damage_buffer_->size(); | 343 size_t embedder_damage_buffer_size = damage_buffer_->size(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 | 544 |
| 520 void BrowserPluginGuest::RenderViewReady() { | 545 void BrowserPluginGuest::RenderViewReady() { |
| 521 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 546 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 522 // here (see http://www.crbug.com/158151). | 547 // here (see http://www.crbug.com/158151). |
| 523 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); | 548 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); |
| 524 render_view_host->Send( | 549 render_view_host->Send( |
| 525 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused_)); | 550 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused_)); |
| 526 bool embedder_visible = | 551 bool embedder_visible = |
| 527 embedder_web_contents_->GetBrowserPluginEmbedder()->visible(); | 552 embedder_web_contents_->GetBrowserPluginEmbedder()->visible(); |
| 528 SetVisibility(embedder_visible, visible()); | 553 SetVisibility(embedder_visible, visible()); |
| 554 if (auto_size_) { | |
| 555 web_contents()->GetRenderViewHost()->EnableAutoResize( | |
| 556 gfx::Size(min_width_, min_height_), gfx::Size(max_width_, max_height_)); | |
| 557 } else { | |
| 558 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); | |
| 559 } | |
| 529 } | 560 } |
| 530 | 561 |
| 531 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { | 562 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
| 532 if (pending_input_event_reply_.get()) { | 563 if (pending_input_event_reply_.get()) { |
| 533 IPC::Message* reply_message = pending_input_event_reply_.release(); | 564 IPC::Message* reply_message = pending_input_event_reply_.release(); |
| 534 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, | 565 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, |
| 535 false, | 566 false, |
| 536 cursor_); | 567 cursor_); |
| 537 SendMessageToEmbedder(reply_message); | 568 SendMessageToEmbedder(reply_message); |
| 538 } | 569 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 559 default: | 590 default: |
| 560 break; | 591 break; |
| 561 } | 592 } |
| 562 } | 593 } |
| 563 | 594 |
| 564 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 595 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 565 embedder_web_contents_->GetRenderProcessHost()->Send(msg); | 596 embedder_web_contents_->GetRenderProcessHost()->Send(msg); |
| 566 } | 597 } |
| 567 | 598 |
| 568 } // namespace content | 599 } // namespace content |
| OLD | NEW |