| 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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 BrowserPlugin::BrowserPlugin( | 100 BrowserPlugin::BrowserPlugin( |
| 101 int instance_id, | 101 int instance_id, |
| 102 RenderViewImpl* render_view, | 102 RenderViewImpl* render_view, |
| 103 WebKit::WebFrame* frame, | 103 WebKit::WebFrame* frame, |
| 104 const WebPluginParams& params) | 104 const WebPluginParams& params) |
| 105 : instance_id_(instance_id), | 105 : instance_id_(instance_id), |
| 106 render_view_(render_view->AsWeakPtr()), | 106 render_view_(render_view->AsWeakPtr()), |
| 107 render_view_routing_id_(render_view->GetRoutingID()), | 107 render_view_routing_id_(render_view->GetRoutingID()), |
| 108 container_(NULL), | 108 container_(NULL), |
| 109 current_damage_buffer_(NULL), | 109 damage_buffer_sequence_id_(0), |
| 110 pending_damage_buffer_(NULL), | |
| 111 sad_guest_(NULL), | 110 sad_guest_(NULL), |
| 112 guest_crashed_(false), | 111 guest_crashed_(false), |
| 113 navigate_src_sent_(false), | 112 navigate_src_sent_(false), |
| 114 auto_size_(false), | 113 auto_size_(false), |
| 115 max_height_(0), | 114 max_height_(0), |
| 116 max_width_(0), | 115 max_width_(0), |
| 117 min_height_(0), | 116 min_height_(0), |
| 118 min_width_(0), | 117 min_width_(0), |
| 119 process_id_(-1), | 118 process_id_(-1), |
| 120 persist_storage_(false), | 119 persist_storage_(false), |
| 121 valid_partition_id_(true), | 120 valid_partition_id_(true), |
| 122 content_window_routing_id_(MSG_ROUTING_NONE), | 121 content_window_routing_id_(MSG_ROUTING_NONE), |
| 123 plugin_focused_(false), | 122 plugin_focused_(false), |
| 124 embedder_focused_(false), | 123 embedder_focused_(false), |
| 125 visible_(true), | 124 visible_(true), |
| 126 size_changed_in_flight_(false), | 125 size_changed_in_flight_(false), |
| 127 browser_plugin_manager_(render_view->browser_plugin_manager()), | 126 browser_plugin_manager_(render_view->browser_plugin_manager()), |
| 128 current_nav_entry_index_(0), | 127 current_nav_entry_index_(0), |
| 129 nav_entry_count_(0) { | 128 nav_entry_count_(0) { |
| 130 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | 129 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); |
| 131 bindings_.reset(new BrowserPluginBindings(this)); | 130 bindings_.reset(new BrowserPluginBindings(this)); |
| 132 | 131 |
| 133 ParseAttributes(params); | 132 ParseAttributes(params); |
| 134 } | 133 } |
| 135 | 134 |
| 136 BrowserPlugin::~BrowserPlugin() { | 135 BrowserPlugin::~BrowserPlugin() { |
| 137 if (current_damage_buffer_) | 136 current_damage_buffer_.reset(); |
| 138 FreeDamageBuffer(¤t_damage_buffer_); | 137 pending_damage_buffer_.reset(); |
| 139 if (pending_damage_buffer_) | |
| 140 FreeDamageBuffer(&pending_damage_buffer_); | |
| 141 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); | 138 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); |
| 142 browser_plugin_manager()->Send( | 139 browser_plugin_manager()->Send( |
| 143 new BrowserPluginHostMsg_PluginDestroyed( | 140 new BrowserPluginHostMsg_PluginDestroyed( |
| 144 render_view_routing_id_, | 141 render_view_routing_id_, |
| 145 instance_id_)); | 142 instance_id_)); |
| 146 } | 143 } |
| 147 | 144 |
| 148 void BrowserPlugin::Cleanup() { | 145 void BrowserPlugin::Cleanup() { |
| 149 if (current_damage_buffer_) | 146 current_damage_buffer_.reset(); |
| 150 FreeDamageBuffer(¤t_damage_buffer_); | 147 pending_damage_buffer_.reset(); |
| 151 if (pending_damage_buffer_) | |
| 152 FreeDamageBuffer(&pending_damage_buffer_); | |
| 153 } | 148 } |
| 154 | 149 |
| 155 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 150 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
| 156 bool handled = true; | 151 bool handled = true; |
| 157 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 152 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
| 158 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 153 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
| 159 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 154 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
| 160 OnGuestContentWindowReady) | 155 OnGuestContentWindowReady) |
| 161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 156 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
| 162 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | 157 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 204 |
| 210 // If we haven't created the guest yet, do so now. We will navigate it right | 205 // If we haven't created the guest yet, do so now. We will navigate it right |
| 211 // after creation. If |src| is empty, we can delay the creation until we | 206 // after creation. If |src| is empty, we can delay the creation until we |
| 212 // acutally need it. | 207 // acutally need it. |
| 213 if (!navigate_src_sent_) { | 208 if (!navigate_src_sent_) { |
| 214 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 209 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; |
| 215 create_guest_params.storage_partition_id = storage_partition_id_; | 210 create_guest_params.storage_partition_id = storage_partition_id_; |
| 216 create_guest_params.persist_storage = persist_storage_; | 211 create_guest_params.persist_storage = persist_storage_; |
| 217 create_guest_params.focused = ShouldGuestBeFocused(); | 212 create_guest_params.focused = ShouldGuestBeFocused(); |
| 218 create_guest_params.visible = visible_; | 213 create_guest_params.visible = visible_; |
| 219 pending_damage_buffer_ = | 214 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, |
| 220 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 215 &create_guest_params.resize_guest_params); |
| 221 &create_guest_params.resize_guest_params); | |
| 222 browser_plugin_manager()->Send( | 216 browser_plugin_manager()->Send( |
| 223 new BrowserPluginHostMsg_CreateGuest( | 217 new BrowserPluginHostMsg_CreateGuest( |
| 224 render_view_routing_id_, | 218 render_view_routing_id_, |
| 225 instance_id_, | 219 instance_id_, |
| 226 create_guest_params)); | 220 create_guest_params)); |
| 227 } | 221 } |
| 228 | 222 |
| 229 browser_plugin_manager()->Send( | 223 browser_plugin_manager()->Send( |
| 230 new BrowserPluginHostMsg_NavigateGuest( | 224 new BrowserPluginHostMsg_NavigateGuest( |
| 231 render_view_routing_id_, | 225 render_view_routing_id_, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 262 } | 256 } |
| 263 | 257 |
| 264 void BrowserPlugin::UpdateGuestAutoSizeState() { | 258 void BrowserPlugin::UpdateGuestAutoSizeState() { |
| 265 // If we haven't yet heard back from the guest about the last resize request, | 259 // If we haven't yet heard back from the guest about the last resize request, |
| 266 // then we don't issue another request until we do in | 260 // then we don't issue another request until we do in |
| 267 // BrowserPlugin::UpdateRect. | 261 // BrowserPlugin::UpdateRect. |
| 268 if (!navigate_src_sent_ || pending_damage_buffer_) | 262 if (!navigate_src_sent_ || pending_damage_buffer_) |
| 269 return; | 263 return; |
| 270 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 264 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 271 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 265 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 272 pending_damage_buffer_ = | 266 GetDamageBufferWithSizeParams(&auto_size_params, &resize_guest_params); |
| 273 GetDamageBufferWithSizeParams(&auto_size_params, &resize_guest_params); | |
| 274 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetAutoSize( | 267 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetAutoSize( |
| 275 render_view_routing_id_, | 268 render_view_routing_id_, |
| 276 instance_id_, | 269 instance_id_, |
| 277 auto_size_params, | 270 auto_size_params, |
| 278 resize_guest_params)); | 271 resize_guest_params)); |
| 279 } | 272 } |
| 280 | 273 |
| 281 void BrowserPlugin::SizeChangedDueToAutoSize(const gfx::Size& old_view_size) { | 274 void BrowserPlugin::SizeChangedDueToAutoSize(const gfx::Size& old_view_size) { |
| 282 size_changed_in_flight_ = false; | 275 size_changed_in_flight_ = false; |
| 283 | 276 |
| 284 std::map<std::string, base::Value*> props; | 277 std::map<std::string, base::Value*> props; |
| 285 props[kOldHeight] = base::Value::CreateIntegerValue(old_view_size.height()); | 278 props[kOldHeight] = base::Value::CreateIntegerValue(old_view_size.height()); |
| 286 props[kOldWidth] = base::Value::CreateIntegerValue(old_view_size.width()); | 279 props[kOldWidth] = base::Value::CreateIntegerValue(old_view_size.width()); |
| 287 props[kNewHeight] = base::Value::CreateIntegerValue(last_view_size_.height()); | 280 props[kNewHeight] = base::Value::CreateIntegerValue(last_view_size_.height()); |
| 288 props[kNewWidth] = base::Value::CreateIntegerValue(last_view_size_.width()); | 281 props[kNewWidth] = base::Value::CreateIntegerValue(last_view_size_.width()); |
| 289 TriggerEvent(kEventSizeChanged, &props); | 282 TriggerEvent(kEventSizeChanged, &props); |
| 290 } | 283 } |
| 291 | 284 |
| 292 #if defined(OS_MACOSX) | 285 // static |
| 293 bool BrowserPlugin::DamageBufferMatches( | 286 bool BrowserPlugin::UsesDamageBuffer( |
| 294 const TransportDIB* damage_buffer, | 287 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 295 const TransportDIB::Id& other_damage_buffer_id) { | 288 return params.damage_buffer_sequence_id != 0; |
| 296 if (!damage_buffer) | 289 } |
| 290 |
| 291 bool BrowserPlugin::UsesPendingDamageBuffer( |
| 292 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 293 if (!pending_damage_buffer_.get()) |
| 297 return false; | 294 return false; |
| 298 return damage_buffer->id() == other_damage_buffer_id; | 295 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
| 299 } | 296 } |
| 300 #else | |
| 301 bool BrowserPlugin::DamageBufferMatches( | |
| 302 const TransportDIB* damage_buffer, | |
| 303 const TransportDIB::Handle& other_damage_buffer_handle) { | |
| 304 if (!damage_buffer) | |
| 305 return false; | |
| 306 return damage_buffer->handle() == other_damage_buffer_handle; | |
| 307 } | |
| 308 #endif | |
| 309 | 297 |
| 310 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { | 298 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { |
| 311 DCHECK(render_view_); | 299 DCHECK(render_view_); |
| 312 render_view_->GetWebView()->advanceFocus(reverse); | 300 render_view_->GetWebView()->advanceFocus(reverse); |
| 313 } | 301 } |
| 314 | 302 |
| 315 void BrowserPlugin::OnGuestContentWindowReady(int instance_id, | 303 void BrowserPlugin::OnGuestContentWindowReady(int instance_id, |
| 316 int content_window_routing_id) { | 304 int content_window_routing_id) { |
| 317 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 305 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
| 318 content_window_routing_id_ = content_window_routing_id; | 306 content_window_routing_id_ = content_window_routing_id; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 int instance_id, | 415 int instance_id, |
| 428 int message_id, | 416 int message_id, |
| 429 const BrowserPluginMsg_UpdateRect_Params& params) { | 417 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 430 bool use_new_damage_buffer = !backing_store_; | 418 bool use_new_damage_buffer = !backing_store_; |
| 431 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 419 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 432 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 420 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 433 // If we have a pending damage buffer, and the guest has begun to use the | 421 // If we have a pending damage buffer, and the guest has begun to use the |
| 434 // damage buffer then we know the guest will no longer use the current | 422 // damage buffer then we know the guest will no longer use the current |
| 435 // damage buffer. At this point, we drop the current damage buffer, and | 423 // damage buffer. At this point, we drop the current damage buffer, and |
| 436 // mark the pending damage buffer as the current damage buffer. | 424 // mark the pending damage buffer as the current damage buffer. |
| 437 if (DamageBufferMatches(pending_damage_buffer_, | 425 if (UsesPendingDamageBuffer(params)) { |
| 438 params.damage_buffer_identifier)) { | |
| 439 SwapDamageBuffers(); | 426 SwapDamageBuffers(); |
| 440 use_new_damage_buffer = true; | 427 use_new_damage_buffer = true; |
| 441 } | 428 } |
| 442 if ((!auto_size_ && | 429 if ((!auto_size_ && |
| 443 (width() != params.view_size.width() || | 430 (width() != params.view_size.width() || |
| 444 height() != params.view_size.height())) || | 431 height() != params.view_size.height())) || |
| 445 (auto_size_ && (!InAutoSizeBounds(params.view_size)))) { | 432 (auto_size_ && (!InAutoSizeBounds(params.view_size)))) { |
| 446 if (pending_damage_buffer_) { | 433 if (pending_damage_buffer_) { |
| 447 // The guest has not yet responded to the last resize request, and | 434 // The guest has not yet responded to the last resize request, and |
| 448 // so we don't want to do anything at this point other than ACK the guest. | 435 // so we don't want to do anything at this point other than ACK the guest. |
| 449 PopulateAutoSizeParameters(&auto_size_params); | 436 PopulateAutoSizeParameters(&auto_size_params); |
| 450 } else { | 437 } else { |
| 451 // If we have no pending damage buffer, then the guest has not caught up | 438 // If we have no pending damage buffer, then the guest has not caught up |
| 452 // with the BrowserPlugin container. We now tell the guest about the new | 439 // with the BrowserPlugin container. We now tell the guest about the new |
| 453 // container size. | 440 // container size. |
| 454 pending_damage_buffer_ = | 441 GetDamageBufferWithSizeParams(&auto_size_params, |
| 455 GetDamageBufferWithSizeParams(&auto_size_params, | 442 &resize_guest_params); |
| 456 &resize_guest_params); | |
| 457 } | 443 } |
| 458 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 444 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 459 render_view_routing_id_, | 445 render_view_routing_id_, |
| 460 instance_id_, | 446 instance_id_, |
| 461 message_id, | 447 message_id, |
| 462 auto_size_params, | 448 auto_size_params, |
| 463 resize_guest_params)); | 449 resize_guest_params)); |
| 464 return; | 450 return; |
| 465 } | 451 } |
| 466 | 452 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 487 |
| 502 // Update the backing store. | 488 // Update the backing store. |
| 503 if (!params.scroll_rect.IsEmpty()) { | 489 if (!params.scroll_rect.IsEmpty()) { |
| 504 backing_store_->ScrollBackingStore(params.scroll_delta, | 490 backing_store_->ScrollBackingStore(params.scroll_delta, |
| 505 params.scroll_rect, | 491 params.scroll_rect, |
| 506 params.view_size); | 492 params.view_size); |
| 507 } | 493 } |
| 508 for (unsigned i = 0; i < params.copy_rects.size(); i++) { | 494 for (unsigned i = 0; i < params.copy_rects.size(); i++) { |
| 509 backing_store_->PaintToBackingStore(params.bitmap_rect, | 495 backing_store_->PaintToBackingStore(params.bitmap_rect, |
| 510 params.copy_rects, | 496 params.copy_rects, |
| 511 current_damage_buffer_); | 497 current_damage_buffer_->memory()); |
| 512 } | 498 } |
| 513 // Invalidate the container. | 499 // Invalidate the container. |
| 514 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 500 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 515 // NULL so we shouldn't attempt to access it. | 501 // NULL so we shouldn't attempt to access it. |
| 516 if (container_) | 502 if (container_) |
| 517 container_->invalidate(); | 503 container_->invalidate(); |
| 518 PopulateAutoSizeParameters(&auto_size_params); | 504 PopulateAutoSizeParameters(&auto_size_params); |
| 519 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 505 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 520 render_view_routing_id_, | 506 render_view_routing_id_, |
| 521 instance_id_, | 507 instance_id_, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 // resized. If |pending_damage_buffer_|, then we are still waiting on a | 848 // resized. If |pending_damage_buffer_|, then we are still waiting on a |
| 863 // previous resize to be ACK'ed and so we don't issue additional resizes | 849 // previous resize to be ACK'ed and so we don't issue additional resizes |
| 864 // until the previous one is ACK'ed. | 850 // until the previous one is ACK'ed. |
| 865 if (!navigate_src_sent_ || auto_size_ || pending_damage_buffer_ || | 851 if (!navigate_src_sent_ || auto_size_ || pending_damage_buffer_ || |
| 866 (old_width == window_rect.width && | 852 (old_width == window_rect.width && |
| 867 old_height == window_rect.height)) { | 853 old_height == window_rect.height)) { |
| 868 return; | 854 return; |
| 869 } | 855 } |
| 870 | 856 |
| 871 BrowserPluginHostMsg_ResizeGuest_Params params; | 857 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 872 pending_damage_buffer_ = | 858 PopulateResizeGuestParameters(¶ms, gfx::Size(width(), height())); |
| 873 PopulateResizeGuestParameters(¶ms, gfx::Size(width(), height())); | |
| 874 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 859 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 875 render_view_routing_id_, | 860 render_view_routing_id_, |
| 876 instance_id_, | 861 instance_id_, |
| 877 params)); | 862 params)); |
| 878 } | 863 } |
| 879 | 864 |
| 880 void BrowserPlugin::FreeDamageBuffer(TransportDIB** damage_buffer) { | 865 void BrowserPlugin::SwapDamageBuffers() { |
| 881 DCHECK(damage_buffer); | 866 current_damage_buffer_.reset(pending_damage_buffer_.release()); |
| 882 DCHECK(*damage_buffer); | |
| 883 #if defined(OS_MACOSX) | |
| 884 // We don't need to (nor should we) send ViewHostMsg_FreeTransportDIB | |
| 885 // message to the browser to free the damage buffer since we manage the | |
| 886 // damage buffer ourselves. | |
| 887 delete *damage_buffer; | |
| 888 #else | |
| 889 RenderProcess::current()->FreeTransportDIB(*damage_buffer); | |
| 890 *damage_buffer = NULL; | |
| 891 #endif | |
| 892 } | 867 } |
| 893 | 868 |
| 894 void BrowserPlugin::SwapDamageBuffers() { | 869 void BrowserPlugin::PopulateResizeGuestParameters( |
| 895 if (current_damage_buffer_) | |
| 896 FreeDamageBuffer(¤t_damage_buffer_); | |
| 897 current_damage_buffer_ = pending_damage_buffer_; | |
| 898 pending_damage_buffer_ = NULL; | |
| 899 } | |
| 900 | |
| 901 TransportDIB* BrowserPlugin::PopulateResizeGuestParameters( | |
| 902 BrowserPluginHostMsg_ResizeGuest_Params* params, | 870 BrowserPluginHostMsg_ResizeGuest_Params* params, |
| 903 const gfx::Size& view_size) { | 871 const gfx::Size& view_size) { |
| 904 const size_t stride = skia::PlatformCanvasStrideForWidth(view_size.width()); | 872 const size_t stride = skia::PlatformCanvasStrideForWidth(view_size.width()); |
| 905 // Make sure the size of the damage buffer is at least four bytes so that we | 873 // Make sure the size of the damage buffer is at least four bytes so that we |
| 906 // can fit in a magic word to verify that the memory is shared correctly. | 874 // can fit in a magic word to verify that the memory is shared correctly. |
| 907 size_t size = | 875 size_t size = |
| 908 std::max(sizeof(unsigned int), | 876 std::max(sizeof(unsigned int), |
| 909 static_cast<size_t>(view_size.height() * | 877 static_cast<size_t>(view_size.height() * |
| 910 stride * | 878 stride * |
| 911 GetDeviceScaleFactor() * | 879 GetDeviceScaleFactor() * |
| 912 GetDeviceScaleFactor())); | 880 GetDeviceScaleFactor())); |
| 913 | 881 |
| 914 TransportDIB* new_damage_buffer = CreateTransportDIB(size); | |
| 915 params->damage_buffer_id = new_damage_buffer->id(); | |
| 916 #if defined(OS_MACOSX) | |
| 917 // |damage_buffer_id| is not enough to retrieve the damage buffer (on browser | |
| 918 // side) since we don't let the browser cache the damage buffer. We need a | |
| 919 // handle to the damage buffer for this. | |
| 920 params->damage_buffer_handle = new_damage_buffer->handle(); | |
| 921 #endif | |
| 922 #if defined(OS_WIN) | |
| 923 params->damage_buffer_size = size; | 882 params->damage_buffer_size = size; |
| 924 #endif | |
| 925 params->view_size = view_size; | 883 params->view_size = view_size; |
| 926 params->scale_factor = GetDeviceScaleFactor(); | 884 params->scale_factor = GetDeviceScaleFactor(); |
| 927 return new_damage_buffer; | 885 pending_damage_buffer_.reset( |
| 886 CreateDamageBuffer(size, ¶ms->damage_buffer_handle)); |
| 887 if (!pending_damage_buffer_.get()) |
| 888 NOTREACHED(); |
| 889 params->damage_buffer_sequence_id = ++damage_buffer_sequence_id_; |
| 928 } | 890 } |
| 929 | 891 |
| 930 TransportDIB* BrowserPlugin::GetDamageBufferWithSizeParams( | 892 void BrowserPlugin::GetDamageBufferWithSizeParams( |
| 931 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, | 893 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, |
| 932 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { | 894 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { |
| 933 PopulateAutoSizeParameters(auto_size_params); | 895 PopulateAutoSizeParameters(auto_size_params); |
| 934 gfx::Size view_size = auto_size_params->enable ? auto_size_params->max_size : | 896 gfx::Size view_size = auto_size_params->enable ? auto_size_params->max_size : |
| 935 gfx::Size(width(), height()); | 897 gfx::Size(width(), height()); |
| 936 if (view_size.IsEmpty()) | 898 if (view_size.IsEmpty()) |
| 937 return NULL; | 899 return; |
| 938 return PopulateResizeGuestParameters(resize_guest_params, view_size); | 900 PopulateResizeGuestParameters(resize_guest_params, view_size); |
| 939 } | 901 } |
| 940 | 902 |
| 941 TransportDIB* BrowserPlugin::CreateTransportDIB(const size_t size) { | 903 #if defined(OS_POSIX) |
| 942 #if defined(OS_MACOSX) | 904 base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
| 943 TransportDIB::Handle handle; | 905 const size_t size, |
| 944 // On OSX we don't let the browser manage the transport dib. We manage the | 906 base::SharedMemoryHandle* damage_buffer_handle) { |
| 945 // deletion of the dib in FreeDamageBuffer(). | 907 scoped_ptr<base::SharedMemory> shared_buf( |
| 946 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB( | 908 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( |
| 947 size, | 909 size).release()); |
| 948 false, // cache in browser. | 910 |
| 949 &handle); | 911 if (shared_buf.get()) { |
| 950 TransportDIB* new_damage_buffer = NULL; | 912 if (shared_buf->Map(size)) { |
| 951 if (browser_plugin_manager()->Send(msg) && handle.fd >= 0) | 913 // Insert the magic word. |
| 952 new_damage_buffer = TransportDIB::Map(handle); | 914 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
| 953 #else | 915 shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
| 954 TransportDIB* new_damage_buffer = | 916 damage_buffer_handle); |
| 955 RenderProcess::current()->CreateTransportDIB(size); | 917 return shared_buf.release(); |
| 918 } |
| 919 } |
| 920 NOTREACHED(); |
| 921 return NULL; |
| 922 } |
| 923 #elif defined(OS_WIN) |
| 924 base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
| 925 const size_t size, |
| 926 base::SharedMemoryHandle* damage_buffer_handle) { |
| 927 scoped_ptr<base::SharedMemory> shared_buf(new base::SharedMemory()); |
| 928 |
| 929 if (!shared_buf->CreateAndMapAnonymous(size)) { |
| 930 NOTREACHED() << "Buffer allocation failed"; |
| 931 return NULL; |
| 932 } |
| 933 // Insert the magic word. |
| 934 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
| 935 if (shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
| 936 damage_buffer_handle)) |
| 937 return shared_buf.release(); |
| 938 NOTREACHED(); |
| 939 return NULL; |
| 940 } |
| 956 #endif | 941 #endif |
| 957 if (!new_damage_buffer) | |
| 958 NOTREACHED() << "Unable to create damage buffer"; | |
| 959 #if defined(OS_WIN) | |
| 960 // Windows does not map the buffer by default. | |
| 961 CHECK(new_damage_buffer->Map()); | |
| 962 #endif | |
| 963 DCHECK(new_damage_buffer->memory()); | |
| 964 // Insert the magic word. | |
| 965 *static_cast<unsigned int*>(new_damage_buffer->memory()) = 0xdeadbeef; | |
| 966 return new_damage_buffer; | |
| 967 } | |
| 968 | 942 |
| 969 void BrowserPlugin::updateFocus(bool focused) { | 943 void BrowserPlugin::updateFocus(bool focused) { |
| 970 if (plugin_focused_ == focused) | 944 if (plugin_focused_ == focused) |
| 971 return; | 945 return; |
| 972 | 946 |
| 973 bool old_guest_focus_state = ShouldGuestBeFocused(); | 947 bool old_guest_focus_state = ShouldGuestBeFocused(); |
| 974 plugin_focused_ = focused; | 948 plugin_focused_ = focused; |
| 975 | 949 |
| 976 if (ShouldGuestBeFocused() != old_guest_focus_state) | 950 if (ShouldGuestBeFocused() != old_guest_focus_state) |
| 977 UpdateGuestFocusState(); | 951 UpdateGuestFocusState(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 void* notify_data) { | 1018 void* notify_data) { |
| 1045 } | 1019 } |
| 1046 | 1020 |
| 1047 void BrowserPlugin::didFailLoadingFrameRequest( | 1021 void BrowserPlugin::didFailLoadingFrameRequest( |
| 1048 const WebKit::WebURL& url, | 1022 const WebKit::WebURL& url, |
| 1049 void* notify_data, | 1023 void* notify_data, |
| 1050 const WebKit::WebURLError& error) { | 1024 const WebKit::WebURLError& error) { |
| 1051 } | 1025 } |
| 1052 | 1026 |
| 1053 } // namespace content | 1027 } // namespace content |
| OLD | NEW |