| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
| 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 16 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 17 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
| 18 #include "content/common/browser_plugin_messages.h" | 18 #include "content/common/browser_plugin_messages.h" |
| 19 #include "content/common/content_constants_internal.h" | 19 #include "content/common/content_constants_internal.h" |
| 20 #include "content/common/drag_messages.h" | 20 #include "content/common/drag_messages.h" |
| 21 #include "content/common/gpu/gpu_messages.h" |
| 21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 22 #include "content/common/gpu/gpu_messages.h" | |
| 23 #include "content/port/browser/render_view_host_delegate_view.h" | 23 #include "content/port/browser/render_view_host_delegate_view.h" |
| 24 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 27 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/render_widget_host_view.h" | 28 #include "content/public/browser/render_widget_host_view.h" |
| 29 #include "content/public/browser/resource_request_details.h" | 29 #include "content/public/browser/resource_request_details.h" |
| 30 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 31 #include "content/public/browser/web_contents_view.h" | 31 #include "content/public/browser/web_contents_view.h" |
| 32 #include "content/public/common/media_stream_request.h" |
| 32 #include "content/public/common/result_codes.h" | 33 #include "content/public/common/result_codes.h" |
| 33 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 34 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 36 #include "ui/surface/transport_dib.h" | 37 #include "ui/surface/transport_dib.h" |
| 37 #include "webkit/glue/resource_type.h" | 38 #include "webkit/glue/resource_type.h" |
| 38 #include "webkit/glue/webdropdata.h" | 39 #include "webkit/glue/webdropdata.h" |
| 39 | 40 |
| 40 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
| 41 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 namespace content { | 45 namespace content { |
| 45 | 46 |
| 46 // static | 47 // static |
| 47 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 48 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
| 48 | 49 |
| 50 namespace { |
| 51 const size_t kNumMaxOutstandingMediaRequests = 1024; |
| 52 } |
| 53 |
| 49 BrowserPluginGuest::BrowserPluginGuest( | 54 BrowserPluginGuest::BrowserPluginGuest( |
| 50 int instance_id, | 55 int instance_id, |
| 51 WebContentsImpl* embedder_web_contents, | 56 WebContentsImpl* embedder_web_contents, |
| 52 WebContentsImpl* web_contents, | 57 WebContentsImpl* web_contents, |
| 53 const BrowserPluginHostMsg_CreateGuest_Params& params) | 58 const BrowserPluginHostMsg_CreateGuest_Params& params) |
| 54 : WebContentsObserver(web_contents), | 59 : WebContentsObserver(web_contents), |
| 55 embedder_web_contents_(embedder_web_contents), | 60 embedder_web_contents_(embedder_web_contents), |
| 56 instance_id_(instance_id), | 61 instance_id_(instance_id), |
| 57 damage_buffer_sequence_id_(0), | 62 damage_buffer_sequence_id_(0), |
| 58 damage_buffer_size_(0), | 63 damage_buffer_size_(0), |
| 59 damage_buffer_scale_factor_(1.0f), | 64 damage_buffer_scale_factor_(1.0f), |
| 60 guest_hang_timeout_( | 65 guest_hang_timeout_( |
| 61 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 66 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 62 focused_(params.focused), | 67 focused_(params.focused), |
| 63 guest_visible_(params.visible), | 68 guest_visible_(params.visible), |
| 64 embedder_visible_(true), | 69 embedder_visible_(true), |
| 65 name_(params.name), | 70 name_(params.name), |
| 66 auto_size_enabled_(params.auto_size_params.enable), | 71 auto_size_enabled_(params.auto_size_params.enable), |
| 67 max_auto_size_(params.auto_size_params.max_size), | 72 max_auto_size_(params.auto_size_params.max_size), |
| 68 min_auto_size_(params.auto_size_params.min_size), | 73 min_auto_size_(params.auto_size_params.min_size), |
| 69 destroy_called_(false) { | 74 destroy_called_(false), |
| 75 current_media_access_request_id_(0) { |
| 70 DCHECK(web_contents); | 76 DCHECK(web_contents); |
| 71 web_contents->SetDelegate(this); | 77 web_contents->SetDelegate(this); |
| 72 | 78 |
| 73 RendererPreferences* renderer_prefs = web_contents->GetMutableRendererPrefs(); | 79 RendererPreferences* renderer_prefs = web_contents->GetMutableRendererPrefs(); |
| 74 // Copy renderer preferences (and nothing else) from the embedder's | 80 // Copy renderer preferences (and nothing else) from the embedder's |
| 75 // WebContents to the guest. | 81 // WebContents to the guest. |
| 76 // | 82 // |
| 77 // For GTK and Aura this is necessary to get proper renderer configuration | 83 // For GTK and Aura this is necessary to get proper renderer configuration |
| 78 // values for caret blinking interval, colors related to selection and | 84 // values for caret blinking interval, colors related to selection and |
| 79 // focus. | 85 // focus. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 105 OnSwapBuffersACK) | 111 OnSwapBuffersACK) |
| 106 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 112 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 107 OnDragStatusUpdate) | 113 OnDragStatusUpdate) |
| 108 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) | 114 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| 109 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 115 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 110 OnHandleInputEvent) | 116 OnHandleInputEvent) |
| 111 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) | 117 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) |
| 112 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) | 118 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) |
| 113 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) | 119 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) |
| 114 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) | 120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
| 121 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_RespondPermission, |
| 122 OnRespondPermission) |
| 115 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) | 123 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) |
| 116 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) | 124 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) |
| 117 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName) | 125 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName) |
| 118 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 126 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
| 119 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) | 127 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) |
| 120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) | 128 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) |
| 121 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) | 129 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) |
| 122 IPC_MESSAGE_UNHANDLED(handled = false) | 130 IPC_MESSAGE_UNHANDLED(handled = false) |
| 123 IPC_END_MESSAGE_MAP() | 131 IPC_END_MESSAGE_MAP() |
| 124 return handled; | 132 return handled; |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 const std::string& mailbox_name, | 649 const std::string& mailbox_name, |
| 642 uint32 sync_point) { | 650 uint32 sync_point) { |
| 643 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 651 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 644 ack_params.mailbox_name = mailbox_name; | 652 ack_params.mailbox_name = mailbox_name; |
| 645 ack_params.sync_point = sync_point; | 653 ack_params.sync_point = sync_point; |
| 646 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, | 654 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, |
| 647 gpu_host_id, | 655 gpu_host_id, |
| 648 ack_params); | 656 ack_params); |
| 649 } | 657 } |
| 650 | 658 |
| 659 void BrowserPluginGuest::OnRespondPermission( |
| 660 int /*instance_id*/, |
| 661 BrowserPluginPermissionType permission_type, |
| 662 int request_id, |
| 663 bool should_allow) { |
| 664 if (permission_type != BrowserPluginPermissionTypeMedia) |
| 665 return; |
| 666 |
| 667 MediaStreamRequestsMap::iterator media_request_iter = |
| 668 media_requests_map_.find(request_id); |
| 669 if (media_request_iter == media_requests_map_.end()) { |
| 670 LOG(INFO) << "Not a valid request ID."; |
| 671 return; |
| 672 } |
| 673 const content::MediaStreamRequest& request = media_request_iter->second.first; |
| 674 const content::MediaResponseCallback& callback = |
| 675 media_request_iter->second.second; |
| 676 |
| 677 if (should_allow && embedder_web_contents_) { |
| 678 // Re-route the request to the embedder's WebContents; the guest gets the |
| 679 // permission this way. |
| 680 embedder_web_contents_->RequestMediaAccessPermission(request, callback); |
| 681 } else { |
| 682 // Deny the request. |
| 683 callback.Run(content::MediaStreamDevices()); |
| 684 } |
| 685 media_requests_map_.erase(media_request_iter); |
| 686 } |
| 687 |
| 651 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, | 688 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, |
| 652 int route_id, | 689 int route_id, |
| 653 int gpu_host_id, | 690 int gpu_host_id, |
| 654 const std::string& mailbox_name, | 691 const std::string& mailbox_name, |
| 655 uint32 sync_point) { | 692 uint32 sync_point) { |
| 656 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); | 693 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); |
| 657 | 694 |
| 658 // This is only relevant on MACOSX and WIN when threaded compositing | 695 // This is only relevant on MACOSX and WIN when threaded compositing |
| 659 // is not enabled. In threaded mode, above ACK is sufficient. | 696 // is not enabled. In threaded mode, above ACK is sufficient. |
| 660 #if defined(OS_MACOSX) || defined(OS_WIN) | 697 #if defined(OS_MACOSX) || defined(OS_WIN) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | 794 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| 758 bool is_top_level, | 795 bool is_top_level, |
| 759 const std::string& name) { | 796 const std::string& name) { |
| 760 if (!is_top_level) | 797 if (!is_top_level) |
| 761 return; | 798 return; |
| 762 | 799 |
| 763 name_ = name; | 800 name_ = name; |
| 764 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); | 801 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); |
| 765 } | 802 } |
| 766 | 803 |
| 804 void BrowserPluginGuest::RequestMediaAccessPermission( |
| 805 WebContents* web_contents, |
| 806 const content::MediaStreamRequest& request, |
| 807 const content::MediaResponseCallback& callback) { |
| 808 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { |
| 809 // Deny the media request. |
| 810 callback.Run(content::MediaStreamDevices()); |
| 811 return; |
| 812 } |
| 813 int request_id = current_media_access_request_id_++; |
| 814 media_requests_map_.insert( |
| 815 std::make_pair(request_id, |
| 816 std::make_pair(request, callback))); |
| 817 |
| 818 base::DictionaryValue request_info; |
| 819 request_info.Set( |
| 820 "url", base::Value::CreateStringValue(request.security_origin.spec())); |
| 821 SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( |
| 822 instance_id(), BrowserPluginPermissionTypeMedia, |
| 823 request_id, request_info)); |
| 824 } |
| 825 |
| 767 void BrowserPluginGuest::OnUpdateRect( | 826 void BrowserPluginGuest::OnUpdateRect( |
| 768 const ViewHostMsg_UpdateRect_Params& params) { | 827 const ViewHostMsg_UpdateRect_Params& params) { |
| 769 | 828 |
| 770 BrowserPluginMsg_UpdateRect_Params relay_params; | 829 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 771 relay_params.view_size = params.view_size; | 830 relay_params.view_size = params.view_size; |
| 772 relay_params.scale_factor = params.scale_factor; | 831 relay_params.scale_factor = params.scale_factor; |
| 773 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 832 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 774 params.flags); | 833 params.flags); |
| 775 relay_params.needs_ack = params.needs_ack; | 834 relay_params.needs_ack = params.needs_ack; |
| 776 | 835 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 relay_params.bitmap_rect = params.bitmap_rect; | 874 relay_params.bitmap_rect = params.bitmap_rect; |
| 816 relay_params.scroll_delta = params.scroll_delta; | 875 relay_params.scroll_delta = params.scroll_delta; |
| 817 relay_params.scroll_rect = params.scroll_rect; | 876 relay_params.scroll_rect = params.scroll_rect; |
| 818 relay_params.copy_rects = params.copy_rects; | 877 relay_params.copy_rects = params.copy_rects; |
| 819 | 878 |
| 820 SendMessageToEmbedder( | 879 SendMessageToEmbedder( |
| 821 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); | 880 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); |
| 822 } | 881 } |
| 823 | 882 |
| 824 } // namespace content | 883 } // namespace content |
| OLD | NEW |