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 87ca245fd77c5fa1aa27d9b8cd4291e2872f2d6a..723ffbd17031570146d8353925a664a77c295374 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_AllowPermissionAccess, |
| + 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.
|
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| OnDragStatusUpdate) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| @@ -673,6 +681,57 @@ 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 |
|
Charlie Reis
2013/02/11 22:20:56
typo: this pending requests
lazyboy
2013/02/12 05:03:45
Done.
|
| + // 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::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
|
| + int /*instance_id*/, |
| + const std::string& permission_type, |
| + int request_id, |
| + bool should_allow) { |
| + if (permission_type != "media") |
| + return; |
| + |
| + 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) { |