OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/extensions/request_media_access_permission_helper.h" |
| 6 |
| 7 #include "chrome/common/extensions/feature_switch.h" |
| 8 |
| 9 namespace extensions { |
| 10 |
| 11 // static |
| 12 void RequestMediaAccessPermissionHelper::AuthorizeRequest( |
| 13 const content::MediaStreamRequest* request, |
| 14 const content::MediaResponseCallback& callback, |
| 15 const extensions::Extension* extension, |
| 16 bool is_packaged_app) { |
| 17 content::MediaStreamDevices devices; |
| 18 |
| 19 bool accepted_an_audio_device = false; |
| 20 bool accepted_a_video_device = false; |
| 21 for (content::MediaStreamDeviceMap::const_iterator it = |
| 22 request->devices.begin(); it != request->devices.end(); ++it) { |
| 23 if (!accepted_an_audio_device && |
| 24 content::IsAudioMediaType(it->first) && |
| 25 !it->second.empty()) { |
| 26 // Require flag and tab capture permission for tab media. |
| 27 // Require audio capture permission for packaged apps. |
| 28 if ((it->first == content::MEDIA_TAB_AUDIO_CAPTURE && |
| 29 extensions::FeatureSwitch::tab_capture()->IsEnabled() && |
| 30 extension->HasAPIPermission(APIPermission::kTabCapture)) || |
| 31 (it->first == content::MEDIA_DEVICE_AUDIO_CAPTURE && |
| 32 is_packaged_app && |
| 33 extension->HasAPIPermission(APIPermission::kAudioCapture))) { |
| 34 devices.push_back(it->second.front()); |
| 35 accepted_an_audio_device = true; |
| 36 } |
| 37 } else if (!accepted_a_video_device && |
| 38 content::IsVideoMediaType(it->first) && |
| 39 !it->second.empty()) { |
| 40 // Require flag and tab capture permission for tab media. |
| 41 // Require video capture permission for packaged apps. |
| 42 if ((it->first == content::MEDIA_TAB_VIDEO_CAPTURE && |
| 43 extensions::FeatureSwitch::tab_capture()->IsEnabled() && |
| 44 extension->HasAPIPermission(APIPermission::kTabCapture)) || |
| 45 (it->first == content::MEDIA_DEVICE_VIDEO_CAPTURE && |
| 46 is_packaged_app && |
| 47 extension->HasAPIPermission(APIPermission::kVideoCapture))) { |
| 48 devices.push_back(it->second.front()); |
| 49 accepted_a_video_device = true; |
| 50 } |
| 51 } |
| 52 } |
| 53 |
| 54 callback.Run(devices); |
| 55 } |
| 56 |
| 57 } // namespace extensions |
OLD | NEW |