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/view_messages.h" | 20 #include "content/common/view_messages.h" |
| 21 #include "content/port/browser/render_view_host_delegate_view.h" | 21 #include "content/port/browser/render_view_host_delegate_view.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/browser/resource_request_details.h" | 27 #include "content/public/browser/resource_request_details.h" |
| 28 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
| 29 #include "content/public/browser/web_contents_view.h" | 29 #include "content/public/browser/web_contents_view.h" |
| 30 #include "content/public/common/media_stream_request.h" | |
| 30 #include "content/public/common/result_codes.h" | 31 #include "content/public/common/result_codes.h" |
| 31 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 32 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 32 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 34 #include "ui/surface/transport_dib.h" | 35 #include "ui/surface/transport_dib.h" |
| 35 #include "webkit/glue/resource_type.h" | 36 #include "webkit/glue/resource_type.h" |
| 36 #include "webkit/glue/webdropdata.h" | 37 #include "webkit/glue/webdropdata.h" |
| 37 | 38 |
| 38 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
| 39 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 40 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 namespace content { | 43 namespace content { |
| 43 | 44 |
| 44 // static | 45 // static |
| 45 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 46 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
| 46 | 47 |
| 48 namespace { | |
| 49 const size_t kNumMaxOutstandingMediaRequests = 1024; | |
| 50 } | |
| 51 | |
| 47 BrowserPluginGuest::BrowserPluginGuest( | 52 BrowserPluginGuest::BrowserPluginGuest( |
| 48 int instance_id, | 53 int instance_id, |
| 49 WebContentsImpl* web_contents, | 54 WebContentsImpl* web_contents, |
| 50 const BrowserPluginHostMsg_CreateGuest_Params& params) | 55 const BrowserPluginHostMsg_CreateGuest_Params& params) |
| 51 : WebContentsObserver(web_contents), | 56 : WebContentsObserver(web_contents), |
| 52 embedder_web_contents_(NULL), | 57 embedder_web_contents_(NULL), |
| 53 instance_id_(instance_id), | 58 instance_id_(instance_id), |
| 54 damage_buffer_sequence_id_(0), | 59 damage_buffer_sequence_id_(0), |
| 55 damage_buffer_size_(0), | 60 damage_buffer_size_(0), |
| 56 damage_buffer_scale_factor_(1.0f), | 61 damage_buffer_scale_factor_(1.0f), |
| 57 guest_hang_timeout_( | 62 guest_hang_timeout_( |
| 58 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 63 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 59 focused_(params.focused), | 64 focused_(params.focused), |
| 60 visible_(params.visible), | 65 visible_(params.visible), |
| 61 name_(params.name), | 66 name_(params.name), |
| 62 auto_size_enabled_(params.auto_size_params.enable), | 67 auto_size_enabled_(params.auto_size_params.enable), |
| 63 max_auto_size_(params.auto_size_params.max_size), | 68 max_auto_size_(params.auto_size_params.max_size), |
| 64 min_auto_size_(params.auto_size_params.min_size) { | 69 min_auto_size_(params.auto_size_params.min_size), |
| 70 current_media_access_request_id_(0) { | |
| 65 DCHECK(web_contents); | 71 DCHECK(web_contents); |
| 66 } | 72 } |
| 67 | 73 |
| 68 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 74 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 69 const IPC::Message& message) { | 75 const IPC::Message& message) { |
| 70 bool handled = true; | 76 bool handled = true; |
| 71 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 77 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 78 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllowMediaAccess, | |
| 79 OnAllowMediaAccess) | |
| 72 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 80 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 73 OnDragStatusUpdate) | 81 OnDragStatusUpdate) |
| 74 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) | 82 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| 75 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 83 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 76 OnHandleInputEvent) | 84 OnHandleInputEvent) |
| 77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) | 85 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) |
| 78 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) | 86 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) |
| 79 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) | 87 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
| 80 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) | 88 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) |
| 81 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) | 89 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 if (!is_top_level) | 673 if (!is_top_level) |
| 666 return; | 674 return; |
| 667 | 675 |
| 668 name_ = name; | 676 name_ = name; |
| 669 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 677 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 670 embedder_routing_id(), | 678 embedder_routing_id(), |
| 671 instance_id_, | 679 instance_id_, |
| 672 name)); | 680 name)); |
| 673 } | 681 } |
| 674 | 682 |
| 683 void BrowserPluginGuest::RequestMediaAccessPermission( | |
| 684 WebContents* web_contents, | |
| 685 const content::MediaStreamRequest& request, | |
| 686 const content::MediaResponseCallback& callback) { | |
| 687 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { | |
| 688 // Deny the media request. | |
| 689 // TODO(lazyboy): We should use timeouts to clear this pending requests if | |
|
Fady Samuel
2013/02/07 15:40:34
Do we still care about this if we're tying pending
lazyboy
2013/02/07 21:24:41
Hmmm, probably not; I'll let Charlie comment on th
| |
| 690 // decision has not been made. | |
| 691 callback.Run(content::MediaStreamDevices()); | |
| 692 return; | |
| 693 } | |
| 694 int request_id = current_media_access_request_id_++; | |
| 695 media_requests_map_.insert( | |
| 696 std::make_pair(request_id, | |
| 697 std::make_pair(request, callback))); | |
| 698 | |
| 699 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess( | |
|
Fady Samuel
2013/02/07 15:40:34
How about generalizing this? BrowserPluginMsg_Requ
lazyboy
2013/02/07 21:24:41
request.security_origin might be a problem here to
| |
| 700 embedder_routing_id(), instance_id(), request_id, | |
| 701 request.security_origin)); | |
| 702 } | |
| 703 | |
| 704 void BrowserPluginGuest::OnAllowMediaAccess(int /*instance_id*/, | |
| 705 int request_id, | |
| 706 bool should_allow) { | |
| 707 MediaStreamRequestsMap::iterator media_request_iter = | |
| 708 media_requests_map_.find(request_id); | |
| 709 if (media_request_iter == media_requests_map_.end()) { | |
| 710 LOG(INFO) << "Not a valid request ID."; | |
| 711 return; | |
| 712 } | |
| 713 const content::MediaStreamRequest& request = media_request_iter->second.first; | |
| 714 const content::MediaResponseCallback& callback = | |
| 715 media_request_iter->second.second; | |
| 716 | |
| 717 if (should_allow && embedder_web_contents_) { | |
| 718 // Re-route the request to the embedder's WebContents; the guest gets the | |
| 719 // permission this way. | |
| 720 embedder_web_contents_->RequestMediaAccessPermission(request, callback); | |
| 721 } else { | |
| 722 // Deny the request. | |
| 723 callback.Run(content::MediaStreamDevices()); | |
| 724 } | |
| 725 media_requests_map_.erase(media_request_iter); | |
| 726 } | |
| 727 | |
| 728 | |
| 675 void BrowserPluginGuest::OnUpdateRect( | 729 void BrowserPluginGuest::OnUpdateRect( |
| 676 const ViewHostMsg_UpdateRect_Params& params) { | 730 const ViewHostMsg_UpdateRect_Params& params) { |
| 677 | 731 |
| 678 BrowserPluginMsg_UpdateRect_Params relay_params; | 732 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 679 relay_params.view_size = params.view_size; | 733 relay_params.view_size = params.view_size; |
| 680 relay_params.scale_factor = params.scale_factor; | 734 relay_params.scale_factor = params.scale_factor; |
| 681 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 735 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 682 params.flags); | 736 params.flags); |
| 683 relay_params.needs_ack = params.needs_ack; | 737 relay_params.needs_ack = params.needs_ack; |
| 684 | 738 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 relay_params.scroll_delta = params.scroll_delta; | 780 relay_params.scroll_delta = params.scroll_delta; |
| 727 relay_params.scroll_rect = params.scroll_rect; | 781 relay_params.scroll_rect = params.scroll_rect; |
| 728 relay_params.copy_rects = params.copy_rects; | 782 relay_params.copy_rects = params.copy_rects; |
| 729 | 783 |
| 730 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 784 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 731 instance_id(), | 785 instance_id(), |
| 732 relay_params)); | 786 relay_params)); |
| 733 } | 787 } |
| 734 | 788 |
| 735 } // namespace content | 789 } // namespace content |
| OLD | NEW |