| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 compositing_helper_ = NULL; | 168 compositing_helper_ = NULL; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 // TODO(fsamuel): Add support for reattachment. | 172 // TODO(fsamuel): Add support for reattachment. |
| 173 BrowserPluginHostMsg_Attach_Params attach_params; | 173 BrowserPluginHostMsg_Attach_Params attach_params; |
| 174 attach_params.focused = ShouldGuestBeFocused(); | 174 attach_params.focused = ShouldGuestBeFocused(); |
| 175 attach_params.visible = visible_; | 175 attach_params.visible = visible_; |
| 176 attach_params.opaque = !GetAllowTransparencyAttribute(); | 176 attach_params.opaque = !GetAllowTransparencyAttribute(); |
| 177 attach_params.origin = plugin_rect().origin(); | 177 attach_params.origin = plugin_rect().origin(); |
| 178 GetSizeParams(&attach_params.resize_guest_params, false); | 178 gfx::Size view_size(width(), height()); |
| 179 | 179 if (!view_size.IsEmpty()) { |
| 180 paint_ack_received_ = false; |
| 181 PopulateResizeGuestParameters(view_size, |
| 182 &attach_params.resize_guest_params); |
| 183 } |
| 180 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( | 184 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( |
| 181 render_view_routing_id_, | 185 render_view_routing_id_, |
| 182 browser_plugin_instance_id_, | 186 browser_plugin_instance_id_, |
| 183 attach_params)); | 187 attach_params)); |
| 184 | 188 |
| 185 attach_pending_ = true; | 189 attach_pending_ = true; |
| 186 } | 190 } |
| 187 | 191 |
| 188 void BrowserPlugin::DidCommitCompositorFrame() { | 192 void BrowserPlugin::DidCommitCompositorFrame() { |
| 189 if (compositing_helper_.get()) | 193 if (compositing_helper_.get()) |
| 190 compositing_helper_->DidCommitCompositorFrame(); | 194 compositing_helper_->DidCommitCompositorFrame(); |
| 191 } | 195 } |
| 192 | 196 |
| 193 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, | 197 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, |
| 194 bool reverse) { | 198 bool reverse) { |
| 195 DCHECK(render_view_.get()); | 199 DCHECK(render_view_); |
| 196 render_view_->GetWebView()->advanceFocus(reverse); | 200 render_view_->GetWebView()->advanceFocus(reverse); |
| 197 } | 201 } |
| 198 | 202 |
| 199 void BrowserPlugin::OnAttachACK(int browser_plugin_instance_id) { | 203 void BrowserPlugin::OnAttachACK(int browser_plugin_instance_id) { |
| 200 DCHECK(!attached()); | 204 DCHECK(!attached()); |
| 201 attached_ = true; | 205 attached_ = true; |
| 202 attach_pending_ = false; | 206 attach_pending_ = false; |
| 203 } | 207 } |
| 204 | 208 |
| 205 void BrowserPlugin::OnBuffersSwapped( | 209 void BrowserPlugin::OnBuffersSwapped( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // resize messages when needed. | 314 // resize messages when needed. |
| 311 if (params.is_resize_ack) | 315 if (params.is_resize_ack) |
| 312 paint_ack_received_ = true; | 316 paint_ack_received_ = true; |
| 313 | 317 |
| 314 if (params.view_size.width() == width() && | 318 if (params.view_size.width() == width() && |
| 315 params.view_size.height() == height()) { | 319 params.view_size.height() == height()) { |
| 316 return; | 320 return; |
| 317 } | 321 } |
| 318 | 322 |
| 319 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | 323 BrowserPluginHostMsg_ResizeGuest_Params resize_params; |
| 320 PopulateResizeGuestParameters(&resize_params, plugin_size(), false); | 324 PopulateResizeGuestParameters(plugin_size(), &resize_params); |
| 321 paint_ack_received_ = false; | 325 paint_ack_received_ = false; |
| 322 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 326 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 323 render_view_routing_id_, | 327 render_view_routing_id_, |
| 324 browser_plugin_instance_id_, | 328 browser_plugin_instance_id_, |
| 325 resize_params)); | 329 resize_params)); |
| 326 } | 330 } |
| 327 | 331 |
| 328 NPObject* BrowserPlugin::GetContentWindow() const { | 332 NPObject* BrowserPlugin::GetContentWindow() const { |
| 329 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 333 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
| 330 return NULL; | 334 return NULL; |
| 331 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( | 335 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( |
| 332 content_window_routing_id_); | 336 content_window_routing_id_); |
| 333 if (!guest_render_view) | 337 if (!guest_render_view) |
| 334 return NULL; | 338 return NULL; |
| 335 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 339 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
| 336 return guest_frame->windowObject(); | 340 return guest_frame->windowObject(); |
| 337 } | 341 } |
| 338 | 342 |
| 339 void BrowserPlugin::ShowSadGraphic() { | 343 void BrowserPlugin::ShowSadGraphic() { |
| 340 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 344 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 341 // NULL so we shouldn't attempt to access it. | 345 // NULL so we shouldn't attempt to access it. |
| 342 if (container_) | 346 if (container_) |
| 343 container_->invalidate(); | 347 container_->invalidate(); |
| 344 } | 348 } |
| 345 | 349 |
| 346 float BrowserPlugin::GetDeviceScaleFactor() const { | 350 float BrowserPlugin::GetDeviceScaleFactor() const { |
| 347 if (!render_view_.get()) | 351 if (!render_view_) |
| 348 return 1.0f; | 352 return 1.0f; |
| 349 return render_view_->GetWebView()->deviceScaleFactor(); | 353 return render_view_->GetWebView()->deviceScaleFactor(); |
| 350 } | 354 } |
| 351 | 355 |
| 352 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { | 356 void BrowserPlugin::UpdateDeviceScaleFactor() { |
| 353 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) | 357 if (!paint_ack_received_ || |
| 358 last_device_scale_factor_ == GetDeviceScaleFactor()) { |
| 354 return; | 359 return; |
| 360 } |
| 355 | 361 |
| 356 BrowserPluginHostMsg_ResizeGuest_Params params; | 362 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 357 PopulateResizeGuestParameters(¶ms, plugin_size(), true); | 363 PopulateResizeGuestParameters(plugin_size(), ¶ms); |
| 358 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 364 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 359 render_view_routing_id_, | 365 render_view_routing_id_, |
| 360 browser_plugin_instance_id_, | 366 browser_plugin_instance_id_, |
| 361 params)); | 367 params)); |
| 362 } | 368 } |
| 363 | 369 |
| 364 void BrowserPlugin::UpdateGuestFocusState() { | 370 void BrowserPlugin::UpdateGuestFocusState() { |
| 365 if (!ready()) | 371 if (!ready()) |
| 366 return; | 372 return; |
| 367 bool should_be_focused = ShouldGuestBeFocused(); | 373 bool should_be_focused = ShouldGuestBeFocused(); |
| 368 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 374 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
| 369 render_view_routing_id_, | 375 render_view_routing_id_, |
| 370 browser_plugin_instance_id_, | 376 browser_plugin_instance_id_, |
| 371 should_be_focused)); | 377 should_be_focused)); |
| 372 } | 378 } |
| 373 | 379 |
| 374 bool BrowserPlugin::ShouldGuestBeFocused() const { | 380 bool BrowserPlugin::ShouldGuestBeFocused() const { |
| 375 bool embedder_focused = false; | 381 bool embedder_focused = false; |
| 376 if (render_view_.get()) | 382 if (render_view_) |
| 377 embedder_focused = render_view_->has_focus(); | 383 embedder_focused = render_view_->has_focus(); |
| 378 return plugin_focused_ && embedder_focused; | 384 return plugin_focused_ && embedder_focused; |
| 379 } | 385 } |
| 380 | 386 |
| 381 WebPluginContainer* BrowserPlugin::container() const { | 387 WebPluginContainer* BrowserPlugin::container() const { |
| 382 return container_; | 388 return container_; |
| 383 } | 389 } |
| 384 | 390 |
| 385 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 391 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 386 if (!container) | 392 if (!container) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // If the plugin was initialized then it has a valid |npp_| identifier, and | 436 // If the plugin was initialized then it has a valid |npp_| identifier, and |
| 431 // the |container_| must clear references to the plugin's script objects. | 437 // the |container_| must clear references to the plugin's script objects. |
| 432 DCHECK(!npp_ || container_); | 438 DCHECK(!npp_ || container_); |
| 433 if (container_) | 439 if (container_) |
| 434 container_->clearScriptObjects(); | 440 container_->clearScriptObjects(); |
| 435 | 441 |
| 436 if (compositing_helper_.get()) | 442 if (compositing_helper_.get()) |
| 437 compositing_helper_->OnContainerDestroy(); | 443 compositing_helper_->OnContainerDestroy(); |
| 438 container_ = NULL; | 444 container_ = NULL; |
| 439 // Will be a no-op if the mouse is not currently locked. | 445 // Will be a no-op if the mouse is not currently locked. |
| 440 if (render_view_.get()) | 446 if (render_view_) |
| 441 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); | 447 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); |
| 442 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 448 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 443 } | 449 } |
| 444 | 450 |
| 445 NPObject* BrowserPlugin::scriptableObject() { | 451 NPObject* BrowserPlugin::scriptableObject() { |
| 446 if (!bindings_) | 452 if (!bindings_) |
| 447 return NULL; | 453 return NULL; |
| 448 | 454 |
| 449 NPObject* browser_plugin_np_object(bindings_->np_object()); | 455 NPObject* browser_plugin_np_object(bindings_->np_object()); |
| 450 // The object is expected to be retained before it is returned. | 456 // The object is expected to be retained before it is returned. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // resize. | 547 // resize. |
| 542 if (!paint_ack_received_ || | 548 if (!paint_ack_received_ || |
| 543 (old_width == window_rect.width && old_height == window_rect.height)) { | 549 (old_width == window_rect.width && old_height == window_rect.height)) { |
| 544 // Let the browser know about the updated view rect. | 550 // Let the browser know about the updated view rect. |
| 545 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry( | 551 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry( |
| 546 render_view_routing_id_, browser_plugin_instance_id_, plugin_rect_)); | 552 render_view_routing_id_, browser_plugin_instance_id_, plugin_rect_)); |
| 547 return; | 553 return; |
| 548 } | 554 } |
| 549 | 555 |
| 550 BrowserPluginHostMsg_ResizeGuest_Params params; | 556 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 551 PopulateResizeGuestParameters(¶ms, plugin_size(), false); | 557 PopulateResizeGuestParameters(plugin_size(), ¶ms); |
| 552 paint_ack_received_ = false; | 558 paint_ack_received_ = false; |
| 553 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 559 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 554 render_view_routing_id_, | 560 render_view_routing_id_, |
| 555 browser_plugin_instance_id_, | 561 browser_plugin_instance_id_, |
| 556 params)); | 562 params)); |
| 557 } | 563 } |
| 558 | 564 |
| 559 void BrowserPlugin::PopulateResizeGuestParameters( | 565 void BrowserPlugin::PopulateResizeGuestParameters( |
| 560 BrowserPluginHostMsg_ResizeGuest_Params* params, | |
| 561 const gfx::Size& view_size, | 566 const gfx::Size& view_size, |
| 562 bool needs_repaint) { | 567 BrowserPluginHostMsg_ResizeGuest_Params* params) { |
| 563 params->size_changed = true; | 568 params->size_changed = true; |
| 564 params->view_size = view_size; | 569 params->view_size = view_size; |
| 565 params->repaint = needs_repaint; | |
| 566 params->scale_factor = GetDeviceScaleFactor(); | 570 params->scale_factor = GetDeviceScaleFactor(); |
| 567 if (last_device_scale_factor_ != params->scale_factor) { | 571 if (last_device_scale_factor_ != params->scale_factor) { |
| 568 DCHECK(params->repaint); | |
| 569 last_device_scale_factor_ = params->scale_factor; | 572 last_device_scale_factor_ = params->scale_factor; |
| 573 params->repaint = true; |
| 570 } | 574 } |
| 571 } | 575 } |
| 572 | 576 |
| 573 void BrowserPlugin::GetSizeParams( | |
| 574 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params, | |
| 575 bool needs_repaint) { | |
| 576 gfx::Size view_size(width(), height()); | |
| 577 if (view_size.IsEmpty()) | |
| 578 return; | |
| 579 paint_ack_received_ = false; | |
| 580 PopulateResizeGuestParameters(resize_guest_params, view_size, needs_repaint); | |
| 581 } | |
| 582 | |
| 583 void BrowserPlugin::updateFocus(bool focused) { | 577 void BrowserPlugin::updateFocus(bool focused) { |
| 584 plugin_focused_ = focused; | 578 plugin_focused_ = focused; |
| 585 UpdateGuestFocusState(); | 579 UpdateGuestFocusState(); |
| 586 } | 580 } |
| 587 | 581 |
| 588 void BrowserPlugin::updateVisibility(bool visible) { | 582 void BrowserPlugin::updateVisibility(bool visible) { |
| 589 if (visible_ == visible) | 583 if (visible_ == visible) |
| 590 return; | 584 return; |
| 591 | 585 |
| 592 visible_ = visible; | 586 visible_ = visible; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 const blink::WebMouseEvent& event) { | 803 const blink::WebMouseEvent& event) { |
| 810 browser_plugin_manager()->Send( | 804 browser_plugin_manager()->Send( |
| 811 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 805 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 812 browser_plugin_instance_id_, | 806 browser_plugin_instance_id_, |
| 813 plugin_rect_, | 807 plugin_rect_, |
| 814 &event)); | 808 &event)); |
| 815 return true; | 809 return true; |
| 816 } | 810 } |
| 817 | 811 |
| 818 } // namespace content | 812 } // namespace content |
| OLD | NEW |