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 435f73b3966b5f32a0bdfd51c050200c754d15c2..8482ee342a97daba8750fcd80b06c6017e9db301 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
| @@ -23,13 +23,14 @@ |
| #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" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| #include "ui/surface/transport_dib.h" |
| -#include "webkit/glue/webdropdata.h" |
| #include "webkit/glue/resource_type.h" |
| +#include "webkit/glue/webdropdata.h" |
| namespace content { |
| @@ -38,6 +39,7 @@ BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
| namespace { |
| const int kGuestHangTimeoutMs = 5000; |
| +const int kNumMaxOutstandingMediaRequests = 1024; |
| } |
| BrowserPluginGuest::BrowserPluginGuest( |
| @@ -59,7 +61,8 @@ BrowserPluginGuest::BrowserPluginGuest( |
| visible_(params.visible), |
| 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); |
| } |
| @@ -159,6 +162,24 @@ bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { |
| return false; |
| } |
| +void BrowserPluginGuest::RequestMediaAccessPermission( |
| + WebContents* web_contents, |
| + const content::MediaStreamRequest* request, |
| + const content::MediaResponseCallback& callback) { |
| + if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { |
| + // Deny the media request. |
| + 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)); |
| +} |
| + |
| void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { |
| SendMessageToEmbedder( |
| new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(), |
| @@ -304,6 +325,33 @@ TransportDIB* BrowserPluginGuest::GetDamageBufferFromEmbedder( |
| return damage_buffer; |
| } |
| +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"; |
| + 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( |
|
Charlie Reis
2012/12/07 19:16:25
Ah, is the security check in here, then? Maybe my
lazyboy
2012/12/07 22:50:44
OK.
|
| + &request, callback); |
| + } else { |
| + // Deny the request. |
| + callback.Run(content::MediaStreamDevices()); |
| + } |
| + media_requests_map_.erase(media_request_iter); |
| +} |
| + |
| void BrowserPluginGuest::SetDamageBuffer( |
| TransportDIB* damage_buffer, |
| #if defined(OS_WIN) |