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; | |
| 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 const std::string& mailbox_name, | 580 const std::string& mailbox_name, |
| 574 uint32 sync_point) { | 581 uint32 sync_point) { |
| 575 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 582 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 576 ack_params.mailbox_name = mailbox_name; | 583 ack_params.mailbox_name = mailbox_name; |
| 577 ack_params.sync_point = sync_point; | 584 ack_params.sync_point = sync_point; |
| 578 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, | 585 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, |
| 579 gpu_host_id, | 586 gpu_host_id, |
| 580 ack_params); | 587 ack_params); |
| 581 } | 588 } |
| 582 | 589 |
| 590 void BrowserPluginGuest::OnAllowPermission(int /*instance_id*/, | |
| 591 const std::string& permission_type, | |
| 592 int request_id, | |
| 593 bool should_allow) { | |
| 594 if (permission_type != "media") | |
| 595 return; | |
| 596 | |
| 597 MediaStreamRequestsMap::iterator media_request_iter = | |
| 598 media_requests_map_.find(request_id); | |
| 599 if (media_request_iter == media_requests_map_.end()) { | |
| 600 LOG(INFO) << "Not a valid request ID."; | |
| 601 return; | |
| 602 } | |
| 603 const content::MediaStreamRequest& request = media_request_iter->second.first; | |
| 604 const content::MediaResponseCallback& callback = | |
| 605 media_request_iter->second.second; | |
| 606 | |
| 607 if (should_allow && embedder_web_contents_) { | |
| 608 // Re-route the request to the embedder's WebContents; the guest gets the | |
| 609 // permission this way. | |
| 610 embedder_web_contents_->RequestMediaAccessPermission(request, callback); | |
| 611 } else { | |
| 612 // Deny the request. | |
| 613 callback.Run(content::MediaStreamDevices()); | |
| 614 } | |
| 615 media_requests_map_.erase(media_request_iter); | |
| 616 } | |
| 617 | |
| 583 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, | 618 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, |
| 584 int route_id, | 619 int route_id, |
| 585 int gpu_host_id, | 620 int gpu_host_id, |
| 586 const std::string& mailbox_name, | 621 const std::string& mailbox_name, |
| 587 uint32 sync_point) { | 622 uint32 sync_point) { |
| 588 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); | 623 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); |
| 589 | 624 |
| 590 // This is only relevant on MACOSX and WIN when threaded compositing | 625 // This is only relevant on MACOSX and WIN when threaded compositing |
| 591 // is not enabled. In threaded mode, above ACK is sufficient. | 626 // is not enabled. In threaded mode, above ACK is sufficient. |
| 592 #if defined(OS_MACOSX) || defined(OS_WIN) | 627 #if defined(OS_MACOSX) || defined(OS_WIN) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 if (!is_top_level) | 733 if (!is_top_level) |
| 699 return; | 734 return; |
| 700 | 735 |
| 701 name_ = name; | 736 name_ = name; |
| 702 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 737 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 703 embedder_routing_id(), | 738 embedder_routing_id(), |
| 704 instance_id_, | 739 instance_id_, |
| 705 name)); | 740 name)); |
| 706 } | 741 } |
| 707 | 742 |
| 743 void BrowserPluginGuest::RequestMediaAccessPermission( | |
| 744 WebContents* web_contents, | |
| 745 const content::MediaStreamRequest& request, | |
| 746 const content::MediaResponseCallback& callback) { | |
| 747 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { | |
| 748 // Deny the media request. | |
| 749 // TODO(lazyboy): We should use timeouts to clear these pending requests if | |
| 750 // decision has not been made. | |
|
Charlie Reis
2013/02/13 01:44:47
I thought we were watching for when event.request
lazyboy
2013/02/13 04:07:48
yes (Fady also had the same comment), this should
| |
| 751 callback.Run(content::MediaStreamDevices()); | |
| 752 return; | |
| 753 } | |
| 754 int request_id = current_media_access_request_id_++; | |
| 755 media_requests_map_.insert( | |
| 756 std::make_pair(request_id, | |
| 757 std::make_pair(request, callback))); | |
| 758 | |
| 759 base::DictionaryValue request_info; | |
| 760 request_info.Set( | |
| 761 "url", base::Value::CreateStringValue(request.security_origin.spec())); | |
| 762 SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( | |
| 763 embedder_routing_id(), instance_id(), "media", request_id, request_info)); | |
| 764 } | |
| 765 | |
| 708 void BrowserPluginGuest::OnUpdateRect( | 766 void BrowserPluginGuest::OnUpdateRect( |
| 709 const ViewHostMsg_UpdateRect_Params& params) { | 767 const ViewHostMsg_UpdateRect_Params& params) { |
| 710 | 768 |
| 711 BrowserPluginMsg_UpdateRect_Params relay_params; | 769 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 712 relay_params.view_size = params.view_size; | 770 relay_params.view_size = params.view_size; |
| 713 relay_params.scale_factor = params.scale_factor; | 771 relay_params.scale_factor = params.scale_factor; |
| 714 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 772 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 715 params.flags); | 773 params.flags); |
| 716 relay_params.needs_ack = params.needs_ack; | 774 relay_params.needs_ack = params.needs_ack; |
| 717 | 775 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 relay_params.scroll_delta = params.scroll_delta; | 817 relay_params.scroll_delta = params.scroll_delta; |
| 760 relay_params.scroll_rect = params.scroll_rect; | 818 relay_params.scroll_rect = params.scroll_rect; |
| 761 relay_params.copy_rects = params.copy_rects; | 819 relay_params.copy_rects = params.copy_rects; |
| 762 | 820 |
| 763 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 821 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 764 instance_id(), | 822 instance_id(), |
| 765 relay_params)); | 823 relay_params)); |
| 766 } | 824 } |
| 767 | 825 |
| 768 } // namespace content | 826 } // namespace content |
| OLD | NEW |