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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_manager.h" |
12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 14 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
13 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
14 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
| 17 #include "content/browser/compositor/surface_utils.h" |
15 #include "content/browser/frame_host/render_frame_host_impl.h" | 18 #include "content/browser/frame_host/render_frame_host_impl.h" |
16 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 19 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 20 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
18 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 22 #include "content/browser/renderer_host/render_widget_host_impl.h" |
20 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 23 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
21 #include "content/browser/web_contents/web_contents_impl.h" | 24 #include "content/browser/web_contents/web_contents_impl.h" |
22 #include "content/browser/web_contents/web_contents_view_guest.h" | 25 #include "content/browser/web_contents/web_contents_view_guest.h" |
23 #include "content/common/browser_plugin/browser_plugin_constants.h" | 26 #include "content/common/browser_plugin/browser_plugin_constants.h" |
24 #include "content/common/browser_plugin/browser_plugin_messages.h" | 27 #include "content/common/browser_plugin/browser_plugin_messages.h" |
25 #include "content/common/content_constants_internal.h" | 28 #include "content/common/content_constants_internal.h" |
26 #include "content/common/drag_messages.h" | 29 #include "content/common/drag_messages.h" |
27 #include "content/common/frame_messages.h" | |
28 #include "content/common/host_shared_bitmap_manager.h" | 30 #include "content/common/host_shared_bitmap_manager.h" |
29 #include "content/common/input_messages.h" | 31 #include "content/common/input_messages.h" |
30 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
31 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
32 #include "content/public/browser/browser_plugin_guest_manager.h" | 34 #include "content/public/browser/browser_plugin_guest_manager.h" |
33 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/guest_host.h" | 36 #include "content/public/browser/guest_host.h" |
35 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
36 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
37 #include "content/public/browser/web_contents_observer.h" | 39 #include "content/public/browser/web_contents_observer.h" |
38 #include "content/public/common/drop_data.h" | 40 #include "content/public/common/drop_data.h" |
39 #include "ui/gfx/geometry/size_conversions.h" | 41 #include "ui/gfx/geometry/size_conversions.h" |
40 | 42 |
41 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 44 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| 45 #include "content/common/frame_messages.h" |
43 #endif | 46 #endif |
44 | 47 |
45 namespace content { | 48 namespace content { |
46 | 49 |
47 class BrowserPluginGuest::EmbedderVisibilityObserver | 50 class BrowserPluginGuest::EmbedderVisibilityObserver |
48 : public WebContentsObserver { | 51 : public WebContentsObserver { |
49 public: | 52 public: |
50 explicit EmbedderVisibilityObserver(BrowserPluginGuest* guest) | 53 explicit EmbedderVisibilityObserver(BrowserPluginGuest* guest) |
51 : WebContentsObserver(guest->embedder_web_contents()), | 54 : WebContentsObserver(guest->embedder_web_contents()), |
52 browser_plugin_guest_(guest) { | 55 browser_plugin_guest_(guest) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 OnImeSetComposition) | 238 OnImeSetComposition) |
236 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) | 239 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) |
237 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, | 240 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, |
238 OnReclaimCompositorResources) | 241 OnReclaimCompositorResources) |
239 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, | 242 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, |
240 OnSetEditCommandsForNextKeyEvent) | 243 OnSetEditCommandsForNextKeyEvent) |
241 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) | 244 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) |
242 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 245 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
243 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) | 246 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
244 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) | 247 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
| 248 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SatisfySequence, OnSatisfySequence) |
| 249 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_RequireSequence, OnRequireSequence) |
245 IPC_MESSAGE_UNHANDLED(handled = false) | 250 IPC_MESSAGE_UNHANDLED(handled = false) |
246 IPC_END_MESSAGE_MAP() | 251 IPC_END_MESSAGE_MAP() |
247 return handled; | 252 return handled; |
248 } | 253 } |
249 | 254 |
250 void BrowserPluginGuest::InitInternal( | 255 void BrowserPluginGuest::InitInternal( |
251 const BrowserPluginHostMsg_Attach_Params& params, | 256 const BrowserPluginHostMsg_Attach_Params& params, |
252 WebContentsImpl* owner_web_contents) { | 257 WebContentsImpl* owner_web_contents) { |
253 focused_ = params.focused; | 258 focused_ = params.focused; |
254 OnSetFocus(browser_plugin::kInstanceIDNone, | 259 OnSetFocus(browser_plugin::kInstanceIDNone, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { | 358 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
354 embedder_visible_ = visible; | 359 embedder_visible_ = visible; |
355 UpdateVisibility(); | 360 UpdateVisibility(); |
356 } | 361 } |
357 | 362 |
358 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { | 363 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { |
359 SendMessageToEmbedder( | 364 SendMessageToEmbedder( |
360 new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow)); | 365 new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow)); |
361 } | 366 } |
362 | 367 |
| 368 void BrowserPluginGuest::UpdateGuestSizeIfNecessary( |
| 369 const gfx::Size& frame_size, float scale_factor) { |
| 370 gfx::Size view_size( |
| 371 gfx::ToFlooredSize(gfx::ScaleSize(frame_size, 1.0f / scale_factor))); |
| 372 |
| 373 if (last_seen_view_size_ != view_size) { |
| 374 delegate_->GuestSizeChanged(view_size); |
| 375 last_seen_view_size_ = view_size; |
| 376 } |
| 377 } |
| 378 |
| 379 // TODO(wjmaclean): Remove this once any remaining users of this pathway |
| 380 // are gone. |
363 void BrowserPluginGuest::SwapCompositorFrame( | 381 void BrowserPluginGuest::SwapCompositorFrame( |
364 uint32 output_surface_id, | 382 uint32 output_surface_id, |
365 int host_process_id, | 383 int host_process_id, |
366 int host_routing_id, | 384 int host_routing_id, |
367 scoped_ptr<cc::CompositorFrame> frame) { | 385 scoped_ptr<cc::CompositorFrame> frame) { |
368 cc::RenderPass* root_pass = | 386 cc::RenderPass* root_pass = |
369 frame->delegated_frame_data->render_pass_list.back(); | 387 frame->delegated_frame_data->render_pass_list.back(); |
370 gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize( | 388 UpdateGuestSizeIfNecessary(root_pass->output_rect.size(), |
371 root_pass->output_rect.size(), | 389 frame->metadata.device_scale_factor); |
372 1.0f / frame->metadata.device_scale_factor))); | |
373 | |
374 if (last_seen_view_size_ != view_size) { | |
375 delegate_->GuestSizeChanged(view_size); | |
376 last_seen_view_size_ = view_size; | |
377 } | |
378 | 390 |
379 last_pending_frame_.reset(new FrameMsg_CompositorFrameSwapped_Params()); | 391 last_pending_frame_.reset(new FrameMsg_CompositorFrameSwapped_Params()); |
380 frame->AssignTo(&last_pending_frame_->frame); | 392 frame->AssignTo(&last_pending_frame_->frame); |
381 last_pending_frame_->output_surface_id = output_surface_id; | 393 last_pending_frame_->output_surface_id = output_surface_id; |
382 last_pending_frame_->producing_route_id = host_routing_id; | 394 last_pending_frame_->producing_route_id = host_routing_id; |
383 last_pending_frame_->producing_host_id = host_process_id; | 395 last_pending_frame_->producing_host_id = host_process_id; |
384 | 396 |
385 SendMessageToEmbedder( | 397 SendMessageToEmbedder( |
386 new BrowserPluginMsg_CompositorFrameSwapped( | 398 new BrowserPluginMsg_CompositorFrameSwapped( |
387 browser_plugin_instance_id(), *last_pending_frame_)); | 399 browser_plugin_instance_id(), *last_pending_frame_)); |
388 } | 400 } |
389 | 401 |
| 402 void BrowserPluginGuest::SetChildFrameSurface( |
| 403 const cc::SurfaceId& surface_id, |
| 404 const gfx::Size& frame_size, |
| 405 float scale_factor, |
| 406 const cc::SurfaceSequence& sequence) { |
| 407 SendMessageToEmbedder(new BrowserPluginMsg_SetChildFrameSurface( |
| 408 browser_plugin_instance_id(), surface_id, frame_size, scale_factor, |
| 409 sequence)); |
| 410 } |
| 411 |
| 412 void BrowserPluginGuest::OnSatisfySequence( |
| 413 int instance_id, |
| 414 const cc::SurfaceSequence& sequence) { |
| 415 std::vector<uint32_t> sequences; |
| 416 sequences.push_back(sequence.sequence); |
| 417 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 418 manager->DidSatisfySequences(sequence.id_namespace, &sequences); |
| 419 } |
| 420 |
| 421 void BrowserPluginGuest::OnRequireSequence( |
| 422 int instance_id, |
| 423 const cc::SurfaceId& id, |
| 424 const cc::SurfaceSequence& sequence) { |
| 425 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 426 cc::Surface* surface = manager->GetSurfaceForId(id); |
| 427 if (!surface) { |
| 428 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 429 return; |
| 430 } |
| 431 surface->AddDestructionDependency(sequence); |
| 432 } |
| 433 |
390 void BrowserPluginGuest::SetContentsOpaque(bool opaque) { | 434 void BrowserPluginGuest::SetContentsOpaque(bool opaque) { |
391 SendMessageToEmbedder( | 435 SendMessageToEmbedder( |
392 new BrowserPluginMsg_SetContentsOpaque( | 436 new BrowserPluginMsg_SetContentsOpaque( |
393 browser_plugin_instance_id(), opaque)); | 437 browser_plugin_instance_id(), opaque)); |
394 } | 438 } |
395 | 439 |
396 bool BrowserPluginGuest::Find(int request_id, | 440 bool BrowserPluginGuest::Find(int request_id, |
397 const base::string16& search_text, | 441 const base::string16& search_text, |
398 const blink::WebFindOptions& options) { | 442 const blink::WebFindOptions& options) { |
399 return delegate_->Find(request_id, search_text, options); | 443 return delegate_->Find(request_id, search_text, options); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 969 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
926 const gfx::Range& range, | 970 const gfx::Range& range, |
927 const std::vector<gfx::Rect>& character_bounds) { | 971 const std::vector<gfx::Rect>& character_bounds) { |
928 static_cast<RenderWidgetHostViewBase*>( | 972 static_cast<RenderWidgetHostViewBase*>( |
929 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 973 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
930 range, character_bounds); | 974 range, character_bounds); |
931 } | 975 } |
932 #endif | 976 #endif |
933 | 977 |
934 } // namespace content | 978 } // namespace content |
OLD | NEW |