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..2cbbf9d81489c35c7d4f12fee097f62f8868ec7e 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 int 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); |
| } |
| @@ -672,6 +678,55 @@ 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 |
| + // 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( |
| + embedder_routing_id(), instance_id(), request_id, |
| + request.security_origin)); |
| +} |
| + |
| +void BrowserPluginGuest::AllowMediaAccess(WebContents* embedder_web_contents, |
| + 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"; |
|
Fady Samuel
2013/02/05 17:53:27
nit: Not a valid request ID.
lazyboy
2013/02/07 04:38:42
Done.
|
| + return; |
| + } |
| + const content::MediaStreamRequest& request = media_request_iter->second.first; |
| + const content::MediaResponseCallback& callback = |
| + media_request_iter->second.second; |
| + |
| + if (should_allow) { |
| + WebContentsImpl* embedder_web_contents_impl = |
| + static_cast<WebContentsImpl*>(embedder_web_contents); |
| + // Re-route the request to the embedder's WebContents; the guest gets the |
| + // permission this way. |
| + embedder_web_contents_impl->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) { |