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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 namespace content { | 43 namespace content { |
44 | 44 |
45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, | 45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, |
46 blink::WebFrame* frame, | 46 blink::WebFrame* frame, |
47 bool auto_navigate) | 47 bool auto_navigate) |
48 : attached_(false), | 48 : attached_(false), |
49 attach_pending_(false), | 49 attach_pending_(false), |
50 render_view_(render_view->AsWeakPtr()), | 50 render_view_(render_view->AsWeakPtr()), |
51 render_view_routing_id_(render_view->GetRoutingID()), | 51 render_view_routing_id_(render_view->GetRoutingID()), |
52 container_(NULL), | 52 container_(NULL), |
53 paint_ack_received_(true), | |
54 last_device_scale_factor_(GetDeviceScaleFactor()), | 53 last_device_scale_factor_(GetDeviceScaleFactor()), |
55 sad_guest_(NULL), | 54 sad_guest_(NULL), |
56 guest_crashed_(false), | 55 guest_crashed_(false), |
57 content_window_routing_id_(MSG_ROUTING_NONE), | 56 content_window_routing_id_(MSG_ROUTING_NONE), |
58 plugin_focused_(false), | 57 plugin_focused_(false), |
59 visible_(true), | 58 visible_(true), |
60 auto_navigate_(auto_navigate), | 59 auto_navigate_(auto_navigate), |
61 mouse_locked_(false), | 60 mouse_locked_(false), |
62 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 61 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
63 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), | 62 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
(...skipping 21 matching lines...) Expand all Loading... |
85 OnCompositorFrameSwapped(message)) | 84 OnCompositorFrameSwapped(message)) |
86 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface, | 85 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface, |
87 OnCopyFromCompositingSurface) | 86 OnCopyFromCompositingSurface) |
88 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 87 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
89 OnGuestContentWindowReady) | 88 OnGuestContentWindowReady) |
90 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 89 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
91 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 90 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
92 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) | 91 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) |
93 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 92 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
94 OnShouldAcceptTouchEvents) | 93 OnShouldAcceptTouchEvents) |
95 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | |
96 IPC_MESSAGE_UNHANDLED(handled = false) | 94 IPC_MESSAGE_UNHANDLED(handled = false) |
97 IPC_END_MESSAGE_MAP() | 95 IPC_END_MESSAGE_MAP() |
98 return handled; | 96 return handled; |
99 } | 97 } |
100 | 98 |
101 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, | 99 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, |
102 const std::string& attribute_value) { | 100 const std::string& attribute_value) { |
103 if (!container()) | 101 if (!container()) |
104 return; | 102 return; |
105 | 103 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 168 } |
171 | 169 |
172 // TODO(fsamuel): Add support for reattachment. | 170 // TODO(fsamuel): Add support for reattachment. |
173 BrowserPluginHostMsg_Attach_Params attach_params; | 171 BrowserPluginHostMsg_Attach_Params attach_params; |
174 attach_params.focused = ShouldGuestBeFocused(); | 172 attach_params.focused = ShouldGuestBeFocused(); |
175 attach_params.visible = visible_; | 173 attach_params.visible = visible_; |
176 attach_params.opaque = !GetAllowTransparencyAttribute(); | 174 attach_params.opaque = !GetAllowTransparencyAttribute(); |
177 attach_params.origin = plugin_rect().origin(); | 175 attach_params.origin = plugin_rect().origin(); |
178 gfx::Size view_size(width(), height()); | 176 gfx::Size view_size(width(), height()); |
179 if (!view_size.IsEmpty()) { | 177 if (!view_size.IsEmpty()) { |
180 paint_ack_received_ = false; | |
181 PopulateResizeGuestParameters(view_size, | 178 PopulateResizeGuestParameters(view_size, |
182 &attach_params.resize_guest_params); | 179 &attach_params.resize_guest_params); |
183 } | 180 } |
184 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( | 181 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( |
185 render_view_routing_id_, | 182 render_view_routing_id_, |
186 browser_plugin_instance_id_, | 183 browser_plugin_instance_id_, |
187 attach_params)); | 184 attach_params)); |
188 | 185 |
189 attach_pending_ = true; | 186 attach_pending_ = true; |
190 } | 187 } |
(...skipping 24 matching lines...) Expand all Loading... |
215 params.mailbox, | 212 params.mailbox, |
216 params.gpu_route_id, | 213 params.gpu_route_id, |
217 params.gpu_host_id, | 214 params.gpu_host_id, |
218 GetDeviceScaleFactor()); | 215 GetDeviceScaleFactor()); |
219 } | 216 } |
220 | 217 |
221 void BrowserPlugin::OnCompositorFrameSwapped(const IPC::Message& message) { | 218 void BrowserPlugin::OnCompositorFrameSwapped(const IPC::Message& message) { |
222 BrowserPluginMsg_CompositorFrameSwapped::Param param; | 219 BrowserPluginMsg_CompositorFrameSwapped::Param param; |
223 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) | 220 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) |
224 return; | 221 return; |
| 222 |
| 223 // Note that there is no need to send ACK for this message. |
| 224 // If the guest has updated pixels then it is no longer crashed. |
| 225 guest_crashed_ = false; |
| 226 |
225 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 227 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
226 param.b.frame.AssignTo(frame.get()); | 228 param.b.frame.AssignTo(frame.get()); |
227 | 229 |
228 EnableCompositing(true); | 230 EnableCompositing(true); |
229 compositing_helper_->OnCompositorFrameSwapped(frame.Pass(), | 231 compositing_helper_->OnCompositorFrameSwapped(frame.Pass(), |
230 param.b.producing_route_id, | 232 param.b.producing_route_id, |
231 param.b.output_surface_id, | 233 param.b.output_surface_id, |
232 param.b.producing_host_id, | 234 param.b.producing_host_id, |
233 param.b.shared_memory_handle); | 235 param.b.shared_memory_handle); |
234 } | 236 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 297 |
296 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, | 298 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, |
297 bool accept) { | 299 bool accept) { |
298 if (container()) { | 300 if (container()) { |
299 container()->requestTouchEventType( | 301 container()->requestTouchEventType( |
300 accept ? WebPluginContainer::TouchEventRequestTypeRaw | 302 accept ? WebPluginContainer::TouchEventRequestTypeRaw |
301 : WebPluginContainer::TouchEventRequestTypeNone); | 303 : WebPluginContainer::TouchEventRequestTypeNone); |
302 } | 304 } |
303 } | 305 } |
304 | 306 |
305 void BrowserPlugin::OnUpdateRect( | |
306 int browser_plugin_instance_id, | |
307 const BrowserPluginMsg_UpdateRect_Params& params) { | |
308 // Note that there is no need to send ACK for this message. | |
309 // If the guest has updated pixels then it is no longer crashed. | |
310 guest_crashed_ = false; | |
311 | |
312 // We receive a resize ACK in regular mode, but not in autosize. | |
313 // In Compositing mode, we need to do it here so we can continue sending | |
314 // resize messages when needed. | |
315 if (params.is_resize_ack) | |
316 paint_ack_received_ = true; | |
317 | |
318 if (params.view_size.width() == width() && | |
319 params.view_size.height() == height()) { | |
320 return; | |
321 } | |
322 | |
323 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | |
324 PopulateResizeGuestParameters(plugin_size(), &resize_params); | |
325 paint_ack_received_ = false; | |
326 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | |
327 render_view_routing_id_, | |
328 browser_plugin_instance_id_, | |
329 resize_params)); | |
330 } | |
331 | |
332 NPObject* BrowserPlugin::GetContentWindow() const { | 307 NPObject* BrowserPlugin::GetContentWindow() const { |
333 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 308 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
334 return NULL; | 309 return NULL; |
335 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( | 310 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( |
336 content_window_routing_id_); | 311 content_window_routing_id_); |
337 if (!guest_render_view) | 312 if (!guest_render_view) |
338 return NULL; | 313 return NULL; |
339 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 314 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
340 return guest_frame->windowObject(); | 315 return guest_frame->windowObject(); |
341 } | 316 } |
342 | 317 |
343 void BrowserPlugin::ShowSadGraphic() { | 318 void BrowserPlugin::ShowSadGraphic() { |
344 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 319 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
345 // NULL so we shouldn't attempt to access it. | 320 // NULL so we shouldn't attempt to access it. |
346 if (container_) | 321 if (container_) |
347 container_->invalidate(); | 322 container_->invalidate(); |
348 } | 323 } |
349 | 324 |
350 float BrowserPlugin::GetDeviceScaleFactor() const { | 325 float BrowserPlugin::GetDeviceScaleFactor() const { |
351 if (!render_view_) | 326 if (!render_view_) |
352 return 1.0f; | 327 return 1.0f; |
353 return render_view_->GetWebView()->deviceScaleFactor(); | 328 return render_view_->GetWebView()->deviceScaleFactor(); |
354 } | 329 } |
355 | 330 |
356 void BrowserPlugin::UpdateDeviceScaleFactor() { | 331 void BrowserPlugin::UpdateDeviceScaleFactor() { |
357 if (!paint_ack_received_ || | 332 if (last_device_scale_factor_ == GetDeviceScaleFactor()) |
358 last_device_scale_factor_ == GetDeviceScaleFactor()) { | |
359 return; | 333 return; |
360 } | |
361 | 334 |
362 BrowserPluginHostMsg_ResizeGuest_Params params; | 335 BrowserPluginHostMsg_ResizeGuest_Params params; |
363 PopulateResizeGuestParameters(plugin_size(), ¶ms); | 336 PopulateResizeGuestParameters(plugin_size(), ¶ms); |
364 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 337 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
365 render_view_routing_id_, | 338 render_view_routing_id_, |
366 browser_plugin_instance_id_, | 339 browser_plugin_instance_id_, |
367 params)); | 340 params)); |
368 } | 341 } |
369 | 342 |
370 void BrowserPlugin::UpdateGuestFocusState() { | 343 void BrowserPlugin::UpdateGuestFocusState() { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 case BrowserPluginMsg_Attach_ACK::ID: | 486 case BrowserPluginMsg_Attach_ACK::ID: |
514 case BrowserPluginMsg_AdvanceFocus::ID: | 487 case BrowserPluginMsg_AdvanceFocus::ID: |
515 case BrowserPluginMsg_BuffersSwapped::ID: | 488 case BrowserPluginMsg_BuffersSwapped::ID: |
516 case BrowserPluginMsg_CompositorFrameSwapped::ID: | 489 case BrowserPluginMsg_CompositorFrameSwapped::ID: |
517 case BrowserPluginMsg_CopyFromCompositingSurface::ID: | 490 case BrowserPluginMsg_CopyFromCompositingSurface::ID: |
518 case BrowserPluginMsg_GuestContentWindowReady::ID: | 491 case BrowserPluginMsg_GuestContentWindowReady::ID: |
519 case BrowserPluginMsg_GuestGone::ID: | 492 case BrowserPluginMsg_GuestGone::ID: |
520 case BrowserPluginMsg_SetCursor::ID: | 493 case BrowserPluginMsg_SetCursor::ID: |
521 case BrowserPluginMsg_SetMouseLock::ID: | 494 case BrowserPluginMsg_SetMouseLock::ID: |
522 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: | 495 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: |
523 case BrowserPluginMsg_UpdateRect::ID: | |
524 return true; | 496 return true; |
525 default: | 497 default: |
526 break; | 498 break; |
527 } | 499 } |
528 return false; | 500 return false; |
529 } | 501 } |
530 | 502 |
531 void BrowserPlugin::updateGeometry( | 503 void BrowserPlugin::updateGeometry( |
532 const WebRect& window_rect, | 504 const WebRect& window_rect, |
533 const WebRect& clip_rect, | 505 const WebRect& clip_rect, |
534 const WebVector<WebRect>& cut_outs_rects, | 506 const WebVector<WebRect>& cut_outs_rects, |
535 bool is_visible) { | 507 bool is_visible) { |
536 int old_width = width(); | 508 int old_width = width(); |
537 int old_height = height(); | 509 int old_height = height(); |
538 plugin_rect_ = window_rect; | 510 plugin_rect_ = window_rect; |
539 if (!attached()) | 511 if (!attached()) |
540 return; | 512 return; |
541 | 513 |
542 // In AutoSize mode, guests don't care when the BrowserPlugin container is | 514 if (old_width == window_rect.width && old_height == window_rect.height) { |
543 // resized. If |!paint_ack_received_|, then we are still waiting on a | |
544 // previous resize to be ACK'ed and so we don't issue additional resizes | |
545 // until the previous one is ACK'ed. | |
546 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on | |
547 // resize. | |
548 if (!paint_ack_received_ || | |
549 (old_width == window_rect.width && old_height == window_rect.height)) { | |
550 // Let the browser know about the updated view rect. | 515 // Let the browser know about the updated view rect. |
551 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry( | 516 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry( |
552 render_view_routing_id_, browser_plugin_instance_id_, plugin_rect_)); | 517 render_view_routing_id_, browser_plugin_instance_id_, plugin_rect_)); |
553 return; | 518 return; |
554 } | 519 } |
555 | 520 |
556 BrowserPluginHostMsg_ResizeGuest_Params params; | 521 BrowserPluginHostMsg_ResizeGuest_Params params; |
557 PopulateResizeGuestParameters(plugin_size(), ¶ms); | 522 PopulateResizeGuestParameters(plugin_size(), ¶ms); |
558 paint_ack_received_ = false; | |
559 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 523 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
560 render_view_routing_id_, | 524 render_view_routing_id_, |
561 browser_plugin_instance_id_, | 525 browser_plugin_instance_id_, |
562 params)); | 526 params)); |
563 } | 527 } |
564 | 528 |
565 void BrowserPlugin::PopulateResizeGuestParameters( | 529 void BrowserPlugin::PopulateResizeGuestParameters( |
566 const gfx::Size& view_size, | 530 const gfx::Size& view_size, |
567 BrowserPluginHostMsg_ResizeGuest_Params* params) { | 531 BrowserPluginHostMsg_ResizeGuest_Params* params) { |
568 params->size_changed = true; | |
569 params->view_size = view_size; | 532 params->view_size = view_size; |
570 params->scale_factor = GetDeviceScaleFactor(); | 533 params->scale_factor = GetDeviceScaleFactor(); |
571 if (last_device_scale_factor_ != params->scale_factor) { | 534 if (last_device_scale_factor_ != params->scale_factor) { |
572 last_device_scale_factor_ = params->scale_factor; | 535 last_device_scale_factor_ = params->scale_factor; |
573 params->repaint = true; | 536 params->repaint = true; |
574 } | 537 } |
575 } | 538 } |
576 | 539 |
577 void BrowserPlugin::updateFocus(bool focused) { | 540 void BrowserPlugin::updateFocus(bool focused) { |
578 plugin_focused_ = focused; | 541 plugin_focused_ = focused; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 const blink::WebMouseEvent& event) { | 766 const blink::WebMouseEvent& event) { |
804 browser_plugin_manager()->Send( | 767 browser_plugin_manager()->Send( |
805 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 768 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
806 browser_plugin_instance_id_, | 769 browser_plugin_instance_id_, |
807 plugin_rect_, | 770 plugin_rect_, |
808 &event)); | 771 &event)); |
809 return true; | 772 return true; |
810 } | 773 } |
811 | 774 |
812 } // namespace content | 775 } // namespace content |
OLD | NEW |