Chromium Code Reviews| Index: content/browser/browser_plugin/browser_plugin_guest.cc |
| diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc |
| index 0ad619d834c8a99fdfe5b948dd18c0a9e3a77d3c..58a0dd1bc49924d173c58efb97a158e64e7ba4c6 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
| @@ -27,6 +27,7 @@ |
| #include "content/public/browser/resource_request_details.h" |
| #include "content/public/browser/user_metrics.h" |
| #include "content/public/browser/web_contents_view.h" |
| +#include "content/public/common/media_stream_request.h" |
| #include "content/public/common/result_codes.h" |
| #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| #include "net/base/net_errors.h" |
| @@ -44,6 +45,10 @@ namespace content { |
| // static |
| BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
| +namespace { |
| +const size_t kNumMaxOutstandingMediaRequests = 1024; |
| +} |
| + |
| BrowserPluginGuest::BrowserPluginGuest( |
| int instance_id, |
| WebContentsImpl* web_contents, |
| @@ -61,7 +66,8 @@ BrowserPluginGuest::BrowserPluginGuest( |
| name_(params.name), |
| auto_size_enabled_(params.auto_size_params.enable), |
| max_auto_size_(params.auto_size_params.max_size), |
| - min_auto_size_(params.auto_size_params.min_size) { |
| + min_auto_size_(params.auto_size_params.min_size), |
| + current_media_access_request_id_(0) { |
| DCHECK(web_contents); |
| } |
| @@ -69,6 +75,8 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllowMediaAccess, |
| + OnAllowMediaAccess) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| OnDragStatusUpdate) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| @@ -672,6 +680,52 @@ void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| name)); |
| } |
| +void BrowserPluginGuest::RequestMediaAccessPermission( |
| + WebContents* web_contents, |
| + const content::MediaStreamRequest& request, |
| + const content::MediaResponseCallback& callback) { |
| + if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { |
| + // Deny the media request. |
| + // 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
|
| + // decision has not been made. |
| + callback.Run(content::MediaStreamDevices()); |
| + return; |
| + } |
| + int request_id = current_media_access_request_id_++; |
| + media_requests_map_.insert( |
| + std::make_pair(request_id, |
| + std::make_pair(request, callback))); |
| + |
| + 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
|
| + embedder_routing_id(), instance_id(), request_id, |
| + request.security_origin)); |
| +} |
| + |
| +void BrowserPluginGuest::OnAllowMediaAccess(int /*instance_id*/, |
| + int request_id, |
| + bool should_allow) { |
| + MediaStreamRequestsMap::iterator media_request_iter = |
| + media_requests_map_.find(request_id); |
| + if (media_request_iter == media_requests_map_.end()) { |
| + LOG(INFO) << "Not a valid request ID."; |
| + return; |
| + } |
| + const content::MediaStreamRequest& request = media_request_iter->second.first; |
| + const content::MediaResponseCallback& callback = |
| + media_request_iter->second.second; |
| + |
| + if (should_allow && embedder_web_contents_) { |
| + // Re-route the request to the embedder's WebContents; the guest gets the |
| + // permission this way. |
| + embedder_web_contents_->RequestMediaAccessPermission(request, callback); |
| + } else { |
| + // Deny the request. |
| + callback.Run(content::MediaStreamDevices()); |
| + } |
| + media_requests_map_.erase(media_request_iter); |
| +} |
| + |
| + |
| void BrowserPluginGuest::OnUpdateRect( |
| const ViewHostMsg_UpdateRect_Params& params) { |