Chromium Code Reviews| 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; | |
|
Fady Samuel
2013/02/12 16:13:20
Hmm, I feel like we should be centralizing all the
lazyboy
2013/02/12 18:57:51
OK. As we discussed offline, this might be tricky/
| |
| 51 } | |
| 52 | |
| 48 BrowserPluginGuest::BrowserPluginGuest( | 53 BrowserPluginGuest::BrowserPluginGuest( |
| 49 int instance_id, | 54 int instance_id, |
| 50 WebContentsImpl* web_contents, | 55 WebContentsImpl* web_contents, |
| 51 const BrowserPluginHostMsg_CreateGuest_Params& params) | 56 const BrowserPluginHostMsg_CreateGuest_Params& params) |
| 52 : WebContentsObserver(web_contents), | 57 : WebContentsObserver(web_contents), |
| 53 embedder_web_contents_(NULL), | 58 embedder_web_contents_(NULL), |
| 54 instance_id_(instance_id), | 59 instance_id_(instance_id), |
| 55 damage_buffer_sequence_id_(0), | 60 damage_buffer_sequence_id_(0), |
| 56 damage_buffer_size_(0), | 61 damage_buffer_size_(0), |
| 57 damage_buffer_scale_factor_(1.0f), | 62 damage_buffer_scale_factor_(1.0f), |
| 58 guest_hang_timeout_( | 63 guest_hang_timeout_( |
| 59 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 64 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 60 focused_(params.focused), | 65 focused_(params.focused), |
| 61 visible_(params.visible), | 66 visible_(params.visible), |
| 62 name_(params.name), | 67 name_(params.name), |
| 63 auto_size_enabled_(params.auto_size_params.enable), | 68 auto_size_enabled_(params.auto_size_params.enable), |
| 64 max_auto_size_(params.auto_size_params.max_size), | 69 max_auto_size_(params.auto_size_params.max_size), |
| 65 min_auto_size_(params.auto_size_params.min_size) { | 70 min_auto_size_(params.auto_size_params.min_size), |
| 71 current_media_access_request_id_(0) { | |
| 66 DCHECK(web_contents); | 72 DCHECK(web_contents); |
| 67 } | 73 } |
| 68 | 74 |
| 69 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 75 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 70 const IPC::Message& message) { | 76 const IPC::Message& message) { |
| 71 bool handled = true; | 77 bool handled = true; |
| 72 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 78 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 79 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllowPermission, OnAllowPermission) | |
| 73 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK, | 80 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK, |
| 74 OnSwapBuffersACK) | 81 OnSwapBuffersACK) |
| 75 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 82 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 76 OnDragStatusUpdate) | 83 OnDragStatusUpdate) |
| 77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) | 84 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| 78 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 85 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 79 OnHandleInputEvent) | 86 OnHandleInputEvent) |
| 80 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) | 87 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) |
| 81 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) | 88 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) |
| 82 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) | 89 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 if (!is_top_level) | 705 if (!is_top_level) |
| 699 return; | 706 return; |
| 700 | 707 |
| 701 name_ = name; | 708 name_ = name; |
| 702 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 709 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 703 embedder_routing_id(), | 710 embedder_routing_id(), |
| 704 instance_id_, | 711 instance_id_, |
| 705 name)); | 712 name)); |
| 706 } | 713 } |
| 707 | 714 |
| 715 void BrowserPluginGuest::RequestMediaAccessPermission( | |
| 716 WebContents* web_contents, | |
| 717 const content::MediaStreamRequest& request, | |
| 718 const content::MediaResponseCallback& callback) { | |
| 719 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { | |
| 720 // Deny the media request. | |
| 721 // TODO(lazyboy): We should use timeouts to clear these pending requests if | |
| 722 // decision has not been made. | |
| 723 callback.Run(content::MediaStreamDevices()); | |
| 724 return; | |
| 725 } | |
| 726 int request_id = current_media_access_request_id_++; | |
| 727 media_requests_map_.insert( | |
| 728 std::make_pair(request_id, | |
| 729 std::make_pair(request, callback))); | |
| 730 | |
| 731 base::DictionaryValue request_info; | |
| 732 request_info.Set( | |
| 733 "url", base::Value::CreateStringValue(request.security_origin.spec())); | |
| 734 SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( | |
| 735 embedder_routing_id(), instance_id(), "media", request_id, request_info)); | |
| 736 } | |
| 737 | |
| 738 void BrowserPluginGuest::OnAllowPermission(int /*instance_id*/, | |
|
Fady Samuel
2013/02/12 16:13:20
Alphabetize with other message handlers for messag
lazyboy
2013/02/12 18:57:51
Done.
| |
| 739 const std::string& permission_type, | |
| 740 int request_id, | |
| 741 bool should_allow) { | |
| 742 if (permission_type != "media") | |
| 743 return; | |
| 744 | |
| 745 MediaStreamRequestsMap::iterator media_request_iter = | |
| 746 media_requests_map_.find(request_id); | |
| 747 if (media_request_iter == media_requests_map_.end()) { | |
| 748 LOG(INFO) << "Not a valid request ID."; | |
| 749 return; | |
| 750 } | |
| 751 const content::MediaStreamRequest& request = media_request_iter->second.first; | |
| 752 const content::MediaResponseCallback& callback = | |
| 753 media_request_iter->second.second; | |
| 754 | |
| 755 if (should_allow && embedder_web_contents_) { | |
| 756 // Re-route the request to the embedder's WebContents; the guest gets the | |
| 757 // permission this way. | |
| 758 embedder_web_contents_->RequestMediaAccessPermission(request, callback); | |
| 759 } else { | |
| 760 // Deny the request. | |
| 761 callback.Run(content::MediaStreamDevices()); | |
| 762 } | |
| 763 media_requests_map_.erase(media_request_iter); | |
| 764 } | |
| 765 | |
| 766 | |
| 708 void BrowserPluginGuest::OnUpdateRect( | 767 void BrowserPluginGuest::OnUpdateRect( |
| 709 const ViewHostMsg_UpdateRect_Params& params) { | 768 const ViewHostMsg_UpdateRect_Params& params) { |
| 710 | 769 |
| 711 BrowserPluginMsg_UpdateRect_Params relay_params; | 770 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 712 relay_params.view_size = params.view_size; | 771 relay_params.view_size = params.view_size; |
| 713 relay_params.scale_factor = params.scale_factor; | 772 relay_params.scale_factor = params.scale_factor; |
| 714 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 773 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 715 params.flags); | 774 params.flags); |
| 716 relay_params.needs_ack = params.needs_ack; | 775 relay_params.needs_ack = params.needs_ack; |
| 717 | 776 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 relay_params.scroll_delta = params.scroll_delta; | 818 relay_params.scroll_delta = params.scroll_delta; |
| 760 relay_params.scroll_rect = params.scroll_rect; | 819 relay_params.scroll_rect = params.scroll_rect; |
| 761 relay_params.copy_rects = params.copy_rects; | 820 relay_params.copy_rects = params.copy_rects; |
| 762 | 821 |
| 763 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 822 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 764 instance_id(), | 823 instance_id(), |
| 765 relay_params)); | 824 relay_params)); |
| 766 } | 825 } |
| 767 | 826 |
| 768 } // namespace content | 827 } // namespace content |
| OLD | NEW |