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

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: Plugin can be destroyed before we get Weak Callback, fixed. 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/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_AllowPermissionAccess,
79 OnAllowPermissionAccess)
Charlie Reis 2013/02/11 22:20:56 Why is "Access" in the name? Maybe AllowPermissio
lazyboy 2013/02/12 05:03:45 Done.
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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if (!is_top_level) 674 if (!is_top_level)
667 return; 675 return;
668 676
669 name_ = name; 677 name_ = name;
670 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( 678 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(
671 embedder_routing_id(), 679 embedder_routing_id(),
672 instance_id_, 680 instance_id_,
673 name)); 681 name));
674 } 682 }
675 683
684 void BrowserPluginGuest::RequestMediaAccessPermission(
685 WebContents* web_contents,
686 const content::MediaStreamRequest& request,
687 const content::MediaResponseCallback& callback) {
688 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) {
689 // Deny the media request.
690 // TODO(lazyboy): We should use timeouts to clear this pending requests if
Charlie Reis 2013/02/11 22:20:56 typo: this pending requests
lazyboy 2013/02/12 05:03:45 Done.
691 // decision has not been made.
692 callback.Run(content::MediaStreamDevices());
693 return;
694 }
695 int request_id = current_media_access_request_id_++;
696 media_requests_map_.insert(
697 std::make_pair(request_id,
698 std::make_pair(request, callback)));
699
700 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess(
701 embedder_routing_id(), instance_id(), request_id,
702 request.security_origin));
703 }
704
705 void BrowserPluginGuest::OnAllowPermissionAccess(
Charlie Reis 2013/02/11 22:20:56 Again, will this generalize to other types of perm
lazyboy 2013/02/12 05:03:45 This one is generalized at this point and looks li
706 int /*instance_id*/,
707 const std::string& permission_type,
708 int request_id,
709 bool should_allow) {
710 if (permission_type != "media")
711 return;
712
713 MediaStreamRequestsMap::iterator media_request_iter =
714 media_requests_map_.find(request_id);
715 if (media_request_iter == media_requests_map_.end()) {
716 LOG(INFO) << "Not a valid request ID.";
717 return;
718 }
719 const content::MediaStreamRequest& request = media_request_iter->second.first;
720 const content::MediaResponseCallback& callback =
721 media_request_iter->second.second;
722
723 if (should_allow && embedder_web_contents_) {
724 // Re-route the request to the embedder's WebContents; the guest gets the
725 // permission this way.
726 embedder_web_contents_->RequestMediaAccessPermission(request, callback);
727 } else {
728 // Deny the request.
729 callback.Run(content::MediaStreamDevices());
730 }
731 media_requests_map_.erase(media_request_iter);
732 }
733
734
676 void BrowserPluginGuest::OnUpdateRect( 735 void BrowserPluginGuest::OnUpdateRect(
677 const ViewHostMsg_UpdateRect_Params& params) { 736 const ViewHostMsg_UpdateRect_Params& params) {
678 737
679 BrowserPluginMsg_UpdateRect_Params relay_params; 738 BrowserPluginMsg_UpdateRect_Params relay_params;
680 relay_params.view_size = params.view_size; 739 relay_params.view_size = params.view_size;
681 relay_params.scale_factor = params.scale_factor; 740 relay_params.scale_factor = params.scale_factor;
682 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( 741 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
683 params.flags); 742 params.flags);
684 relay_params.needs_ack = params.needs_ack; 743 relay_params.needs_ack = params.needs_ack;
685 744
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 relay_params.scroll_delta = params.scroll_delta; 786 relay_params.scroll_delta = params.scroll_delta;
728 relay_params.scroll_rect = params.scroll_rect; 787 relay_params.scroll_rect = params.scroll_rect;
729 relay_params.copy_rects = params.copy_rects; 788 relay_params.copy_rects = params.copy_rects;
730 789
731 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), 790 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(),
732 instance_id(), 791 instance_id(),
733 relay_params)); 792 relay_params));
734 } 793 }
735 794
736 } // namespace content 795 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698