Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments from abarth@ Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 24 matching lines...) Expand all
104 OnSwapBuffersACK) 110 OnSwapBuffersACK)
105 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, 111 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
106 OnDragStatusUpdate) 112 OnDragStatusUpdate)
107 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) 113 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo)
108 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, 114 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
109 OnHandleInputEvent) 115 OnHandleInputEvent)
110 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) 116 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest)
111 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) 117 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed)
112 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) 118 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload)
113 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) 119 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_RespondPermission,
121 OnRespondPermission)
114 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) 122 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize)
115 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) 123 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
116 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName) 124 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName)
117 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) 125 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
118 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) 126 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop)
119 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) 127 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest)
120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) 128 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK)
121 IPC_MESSAGE_UNHANDLED(handled = false) 129 IPC_MESSAGE_UNHANDLED(handled = false)
122 IPC_END_MESSAGE_MAP() 130 IPC_END_MESSAGE_MAP()
123 return handled; 131 return handled;
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 const std::string& mailbox_name, 652 const std::string& mailbox_name,
645 uint32 sync_point) { 653 uint32 sync_point) {
646 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; 654 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
647 ack_params.mailbox_name = mailbox_name; 655 ack_params.mailbox_name = mailbox_name;
648 ack_params.sync_point = sync_point; 656 ack_params.sync_point = sync_point;
649 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, 657 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id,
650 gpu_host_id, 658 gpu_host_id,
651 ack_params); 659 ack_params);
652 } 660 }
653 661
662 void BrowserPluginGuest::OnRespondPermission(
663 int /*instance_id*/,
664 BrowserPluginPermissionType permission_type,
665 int request_id,
666 bool should_allow) {
667 if (permission_type != BrowserPluginPermissionTypeMedia)
668 return;
669
670 MediaStreamRequestsMap::iterator media_request_iter =
671 media_requests_map_.find(request_id);
672 if (media_request_iter == media_requests_map_.end()) {
673 LOG(INFO) << "Not a valid request ID.";
674 return;
675 }
676 const content::MediaStreamRequest& request = media_request_iter->second.first;
677 const content::MediaResponseCallback& callback =
678 media_request_iter->second.second;
679
680 if (should_allow && embedder_web_contents_) {
681 // Re-route the request to the embedder's WebContents; the guest gets the
682 // permission this way.
683 embedder_web_contents_->RequestMediaAccessPermission(request, callback);
684 } else {
685 // Deny the request.
686 callback.Run(content::MediaStreamDevices());
687 }
688 media_requests_map_.erase(media_request_iter);
689 }
690
654 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, 691 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id,
655 int route_id, 692 int route_id,
656 int gpu_host_id, 693 int gpu_host_id,
657 const std::string& mailbox_name, 694 const std::string& mailbox_name,
658 uint32 sync_point) { 695 uint32 sync_point) {
659 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); 696 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point);
660 697
661 // This is only relevant on MACOSX and WIN when threaded compositing 698 // This is only relevant on MACOSX and WIN when threaded compositing
662 // is not enabled. In threaded mode, above ACK is sufficient. 699 // is not enabled. In threaded mode, above ACK is sufficient.
663 #if defined(OS_MACOSX) || defined(OS_WIN) 700 #if defined(OS_MACOSX) || defined(OS_WIN)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 if (!is_top_level) 806 if (!is_top_level)
770 return; 807 return;
771 808
772 name_ = name; 809 name_ = name;
773 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( 810 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(
774 embedder_routing_id(), 811 embedder_routing_id(),
775 instance_id_, 812 instance_id_,
776 name)); 813 name));
777 } 814 }
778 815
816 void BrowserPluginGuest::RequestMediaAccessPermission(
817 WebContents* web_contents,
818 const content::MediaStreamRequest& request,
819 const content::MediaResponseCallback& callback) {
820 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) {
821 // Deny the media request.
822 callback.Run(content::MediaStreamDevices());
823 return;
824 }
825 int request_id = current_media_access_request_id_++;
826 media_requests_map_.insert(
827 std::make_pair(request_id,
828 std::make_pair(request, callback)));
829
830 base::DictionaryValue request_info;
831 request_info.Set(
832 "url", base::Value::CreateStringValue(request.security_origin.spec()));
833 SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission(
834 embedder_routing_id(), instance_id(), BrowserPluginPermissionTypeMedia,
835 request_id, request_info));
836 }
837
779 void BrowserPluginGuest::OnUpdateRect( 838 void BrowserPluginGuest::OnUpdateRect(
780 const ViewHostMsg_UpdateRect_Params& params) { 839 const ViewHostMsg_UpdateRect_Params& params) {
781 840
782 BrowserPluginMsg_UpdateRect_Params relay_params; 841 BrowserPluginMsg_UpdateRect_Params relay_params;
783 relay_params.view_size = params.view_size; 842 relay_params.view_size = params.view_size;
784 relay_params.scale_factor = params.scale_factor; 843 relay_params.scale_factor = params.scale_factor;
785 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( 844 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
786 params.flags); 845 params.flags);
787 relay_params.needs_ack = params.needs_ack; 846 relay_params.needs_ack = params.needs_ack;
788 847
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 relay_params.scroll_delta = params.scroll_delta; 889 relay_params.scroll_delta = params.scroll_delta;
831 relay_params.scroll_rect = params.scroll_rect; 890 relay_params.scroll_rect = params.scroll_rect;
832 relay_params.copy_rects = params.copy_rects; 891 relay_params.copy_rects = params.copy_rects;
833 892
834 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), 893 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(),
835 instance_id(), 894 instance_id(),
836 relay_params)); 895 relay_params));
837 } 896 }
838 897
839 } // namespace content 898 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698