| 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 11 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 12 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 15 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 16 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
| 17 #include "content/common/browser_plugin_messages.h" | 17 #include "content/common/browser_plugin_messages.h" |
| 18 #include "content/common/content_constants_internal.h" | 18 #include "content/common/content_constants_internal.h" |
| 19 #include "content/common/drag_messages.h" | 19 #include "content/common/drag_messages.h" |
| 20 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| 21 #include "content/common/gpu/gpu_messages.h" | |
| 22 #include "content/port/browser/render_view_host_delegate_view.h" | 22 #include "content/port/browser/render_view_host_delegate_view.h" |
| 23 #include "content/public/browser/content_browser_client.h" | 23 #include "content/public/browser/content_browser_client.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
| 28 #include "content/public/browser/resource_request_details.h" | 28 #include "content/public/browser/resource_request_details.h" |
| 29 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 30 #include "content/public/browser/web_contents_view.h" | 30 #include "content/public/browser/web_contents_view.h" |
| 31 #include "content/public/common/media_stream_request.h" |
| 31 #include "content/public/common/result_codes.h" | 32 #include "content/public/common/result_codes.h" |
| 32 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 33 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 33 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 35 #include "ui/surface/transport_dib.h" | 36 #include "ui/surface/transport_dib.h" |
| 36 #include "webkit/glue/resource_type.h" | 37 #include "webkit/glue/resource_type.h" |
| 37 #include "webkit/glue/webdropdata.h" | 38 #include "webkit/glue/webdropdata.h" |
| 38 | 39 |
| 39 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
| 40 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 41 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 43 namespace content { | 44 namespace content { |
| 44 | 45 |
| 45 // static | 46 // static |
| 46 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 47 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
| 47 | 48 |
| 49 namespace { |
| 50 const size_t kNumMaxOutstandingMediaRequests = 1024; |
| 51 } |
| 52 |
| 48 BrowserPluginGuest::BrowserPluginGuest( | 53 BrowserPluginGuest::BrowserPluginGuest( |
| 49 int instance_id, | 54 int instance_id, |
| 50 WebContentsImpl* embedder_web_contents, | 55 WebContentsImpl* embedder_web_contents, |
| 51 WebContentsImpl* web_contents, | 56 WebContentsImpl* web_contents, |
| 52 const BrowserPluginHostMsg_CreateGuest_Params& params) | 57 const BrowserPluginHostMsg_CreateGuest_Params& params) |
| 53 : WebContentsObserver(web_contents), | 58 : WebContentsObserver(web_contents), |
| 54 embedder_web_contents_(embedder_web_contents), | 59 embedder_web_contents_(embedder_web_contents), |
| 55 instance_id_(instance_id), | 60 instance_id_(instance_id), |
| 56 damage_buffer_sequence_id_(0), | 61 damage_buffer_sequence_id_(0), |
| 57 damage_buffer_size_(0), | 62 damage_buffer_size_(0), |
| 58 damage_buffer_scale_factor_(1.0f), | 63 damage_buffer_scale_factor_(1.0f), |
| 59 guest_hang_timeout_( | 64 guest_hang_timeout_( |
| 60 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 65 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 61 focused_(params.focused), | 66 focused_(params.focused), |
| 62 guest_visible_(params.visible), | 67 guest_visible_(params.visible), |
| 63 embedder_visible_(true), | 68 embedder_visible_(true), |
| 64 name_(params.name), | 69 name_(params.name), |
| 65 auto_size_enabled_(params.auto_size_params.enable), | 70 auto_size_enabled_(params.auto_size_params.enable), |
| 66 max_auto_size_(params.auto_size_params.max_size), | 71 max_auto_size_(params.auto_size_params.max_size), |
| 67 min_auto_size_(params.auto_size_params.min_size) { | 72 min_auto_size_(params.auto_size_params.min_size), |
| 73 current_media_access_request_id_(0) { |
| 68 DCHECK(web_contents); | 74 DCHECK(web_contents); |
| 69 web_contents->SetDelegate(this); | 75 web_contents->SetDelegate(this); |
| 70 | 76 |
| 71 RendererPreferences* renderer_prefs = web_contents->GetMutableRendererPrefs(); | 77 RendererPreferences* renderer_prefs = web_contents->GetMutableRendererPrefs(); |
| 72 // Copy renderer preferences (and nothing else) from the embedder's | 78 // Copy renderer preferences (and nothing else) from the embedder's |
| 73 // WebContents to the guest. | 79 // WebContents to the guest. |
| 74 // | 80 // |
| 75 // For GTK and Aura this is necessary to get proper renderer configuration | 81 // For GTK and Aura this is necessary to get proper renderer configuration |
| 76 // values for caret blinking interval, colors related to selection and | 82 // values for caret blinking interval, colors related to selection and |
| 77 // focus. | 83 // focus. |
| 78 *renderer_prefs = *embedder_web_contents->GetMutableRendererPrefs(); | 84 *renderer_prefs = *embedder_web_contents->GetMutableRendererPrefs(); |
| 79 | 85 |
| 80 renderer_prefs->throttle_input_events = false; | 86 renderer_prefs->throttle_input_events = false; |
| 81 // We would like the guest to report changes to frame names so that we can | 87 // We would like the guest to report changes to frame names so that we can |
| 82 // update the BrowserPlugin's corresponding 'name' attribute. | 88 // update the BrowserPlugin's corresponding 'name' attribute. |
| 83 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. | 89 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. |
| 84 renderer_prefs->report_frame_name_changes = true; | 90 renderer_prefs->report_frame_name_changes = true; |
| 85 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 91 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
| 86 // navigations still continue to function inside the app. | 92 // navigations still continue to function inside the app. |
| 87 renderer_prefs->browser_handles_all_top_level_requests = false; | 93 renderer_prefs->browser_handles_all_top_level_requests = false; |
| 88 } | 94 } |
| 89 | 95 |
| 90 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 96 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 91 const IPC::Message& message) { | 97 const IPC::Message& message) { |
| 92 bool handled = true; | 98 bool handled = true; |
| 93 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 99 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 100 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllowPermission, OnAllowPermission) |
| 94 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK, | 101 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK, |
| 95 OnSwapBuffersACK) | 102 OnSwapBuffersACK) |
| 96 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 103 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 97 OnDragStatusUpdate) | 104 OnDragStatusUpdate) |
| 98 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) | 105 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| 99 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 106 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 100 OnHandleInputEvent) | 107 OnHandleInputEvent) |
| 101 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) | 108 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) |
| 102 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) | 109 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) |
| 103 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) | 110 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 const std::string& mailbox_name, | 626 const std::string& mailbox_name, |
| 620 uint32 sync_point) { | 627 uint32 sync_point) { |
| 621 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 628 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 622 ack_params.mailbox_name = mailbox_name; | 629 ack_params.mailbox_name = mailbox_name; |
| 623 ack_params.sync_point = sync_point; | 630 ack_params.sync_point = sync_point; |
| 624 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, | 631 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, |
| 625 gpu_host_id, | 632 gpu_host_id, |
| 626 ack_params); | 633 ack_params); |
| 627 } | 634 } |
| 628 | 635 |
| 636 void BrowserPluginGuest::OnAllowPermission(int /*instance_id*/, |
| 637 const std::string& permission_type, |
| 638 int request_id, |
| 639 bool should_allow) { |
| 640 if (permission_type != "media") |
| 641 return; |
| 642 |
| 643 MediaStreamRequestsMap::iterator media_request_iter = |
| 644 media_requests_map_.find(request_id); |
| 645 if (media_request_iter == media_requests_map_.end()) { |
| 646 LOG(INFO) << "Not a valid request ID."; |
| 647 return; |
| 648 } |
| 649 const content::MediaStreamRequest& request = media_request_iter->second.first; |
| 650 const content::MediaResponseCallback& callback = |
| 651 media_request_iter->second.second; |
| 652 |
| 653 if (should_allow && embedder_web_contents_) { |
| 654 // Re-route the request to the embedder's WebContents; the guest gets the |
| 655 // permission this way. |
| 656 embedder_web_contents_->RequestMediaAccessPermission(request, callback); |
| 657 } else { |
| 658 // Deny the request. |
| 659 callback.Run(content::MediaStreamDevices()); |
| 660 } |
| 661 media_requests_map_.erase(media_request_iter); |
| 662 } |
| 663 |
| 629 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, | 664 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, |
| 630 int route_id, | 665 int route_id, |
| 631 int gpu_host_id, | 666 int gpu_host_id, |
| 632 const std::string& mailbox_name, | 667 const std::string& mailbox_name, |
| 633 uint32 sync_point) { | 668 uint32 sync_point) { |
| 634 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); | 669 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); |
| 635 | 670 |
| 636 // This is only relevant on MACOSX and WIN when threaded compositing | 671 // This is only relevant on MACOSX and WIN when threaded compositing |
| 637 // is not enabled. In threaded mode, above ACK is sufficient. | 672 // is not enabled. In threaded mode, above ACK is sufficient. |
| 638 #if defined(OS_MACOSX) || defined(OS_WIN) | 673 #if defined(OS_MACOSX) || defined(OS_WIN) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 if (!is_top_level) | 779 if (!is_top_level) |
| 745 return; | 780 return; |
| 746 | 781 |
| 747 name_ = name; | 782 name_ = name; |
| 748 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 783 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 749 embedder_routing_id(), | 784 embedder_routing_id(), |
| 750 instance_id_, | 785 instance_id_, |
| 751 name)); | 786 name)); |
| 752 } | 787 } |
| 753 | 788 |
| 789 void BrowserPluginGuest::RequestMediaAccessPermission( |
| 790 WebContents* web_contents, |
| 791 const content::MediaStreamRequest& request, |
| 792 const content::MediaResponseCallback& callback) { |
| 793 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { |
| 794 // Deny the media request. |
| 795 callback.Run(content::MediaStreamDevices()); |
| 796 return; |
| 797 } |
| 798 int request_id = current_media_access_request_id_++; |
| 799 media_requests_map_.insert( |
| 800 std::make_pair(request_id, |
| 801 std::make_pair(request, callback))); |
| 802 |
| 803 base::DictionaryValue request_info; |
| 804 request_info.Set( |
| 805 "url", base::Value::CreateStringValue(request.security_origin.spec())); |
| 806 SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( |
| 807 embedder_routing_id(), instance_id(), "media", request_id, request_info)); |
| 808 } |
| 809 |
| 754 void BrowserPluginGuest::OnUpdateRect( | 810 void BrowserPluginGuest::OnUpdateRect( |
| 755 const ViewHostMsg_UpdateRect_Params& params) { | 811 const ViewHostMsg_UpdateRect_Params& params) { |
| 756 | 812 |
| 757 BrowserPluginMsg_UpdateRect_Params relay_params; | 813 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 758 relay_params.view_size = params.view_size; | 814 relay_params.view_size = params.view_size; |
| 759 relay_params.scale_factor = params.scale_factor; | 815 relay_params.scale_factor = params.scale_factor; |
| 760 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 816 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 761 params.flags); | 817 params.flags); |
| 762 relay_params.needs_ack = params.needs_ack; | 818 relay_params.needs_ack = params.needs_ack; |
| 763 | 819 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 relay_params.scroll_delta = params.scroll_delta; | 861 relay_params.scroll_delta = params.scroll_delta; |
| 806 relay_params.scroll_rect = params.scroll_rect; | 862 relay_params.scroll_rect = params.scroll_rect; |
| 807 relay_params.copy_rects = params.copy_rects; | 863 relay_params.copy_rects = params.copy_rects; |
| 808 | 864 |
| 809 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 865 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 810 instance_id(), | 866 instance_id(), |
| 811 relay_params)); | 867 relay_params)); |
| 812 } | 868 } |
| 813 | 869 |
| 814 } // namespace content | 870 } // namespace content |
| OLD | NEW |