| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/webrtc/desktop_capture_access_handler.h" | 5 #include "chrome/browser/media/webrtc/desktop_capture_access_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 return base::string16(); | 143 return base::string16(); |
| 144 } | 144 } |
| 145 // Helper to get list of media stream devices for desktop capture in |devices|. | 145 // Helper to get list of media stream devices for desktop capture in |devices|. |
| 146 // Registers to display notification if |display_notification| is true. | 146 // Registers to display notification if |display_notification| is true. |
| 147 // Returns an instance of MediaStreamUI to be passed to content layer. | 147 // Returns an instance of MediaStreamUI to be passed to content layer. |
| 148 std::unique_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( | 148 std::unique_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( |
| 149 content::MediaStreamDevices* devices, | 149 content::MediaStreamDevices* devices, |
| 150 content::DesktopMediaID media_id, | 150 content::DesktopMediaID media_id, |
| 151 bool capture_audio, | 151 bool capture_audio, |
| 152 bool mute_system_audio, | 152 bool disable_local_echo, |
| 153 bool display_notification, | 153 bool display_notification, |
| 154 const base::string16& application_title, | 154 const base::string16& application_title, |
| 155 const base::string16& registered_extension_name) { | 155 const base::string16& registered_extension_name) { |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 156 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 157 std::unique_ptr<content::MediaStreamUI> ui; | 157 std::unique_ptr<content::MediaStreamUI> ui; |
| 158 | 158 |
| 159 DVLOG(2) << __FUNCTION__ << ": media_id " << media_id.ToString() | 159 DVLOG(2) << __FUNCTION__ << ": media_id " << media_id.ToString() |
| 160 << ", capture_audio " << capture_audio << ", mute_system_audio " | 160 << ", capture_audio " << capture_audio << ", disable_local_echo " |
| 161 << mute_system_audio << ", display_notification " | 161 << disable_local_echo << ", display_notification " |
| 162 << display_notification << ", application_title " | 162 << display_notification << ", application_title " |
| 163 << application_title << ", extension_name " | 163 << application_title << ", extension_name " |
| 164 << registered_extension_name; | 164 << registered_extension_name; |
| 165 | 165 |
| 166 // Add selected desktop source to the list. | 166 // Add selected desktop source to the list. |
| 167 devices->push_back(content::MediaStreamDevice( | 167 devices->push_back(content::MediaStreamDevice( |
| 168 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); | 168 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); |
| 169 if (capture_audio) { | 169 if (capture_audio) { |
| 170 if (media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { | 170 if (media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { |
| 171 content::WebContentsMediaCaptureId web_id = media_id.web_contents_id; |
| 172 web_id.disable_local_echo = disable_local_echo; |
| 171 devices->push_back( | 173 devices->push_back( |
| 172 content::MediaStreamDevice(content::MEDIA_DESKTOP_AUDIO_CAPTURE, | 174 content::MediaStreamDevice(content::MEDIA_DESKTOP_AUDIO_CAPTURE, |
| 173 media_id.ToString(), "Tab audio")); | 175 web_id.ToString(), "Tab audio")); |
| 174 } else if (mute_system_audio) { | 176 } else if (disable_local_echo) { |
| 175 // Use the special loopback device ID for system audio capture. | 177 // Use the special loopback device ID for system audio capture. |
| 176 devices->push_back(content::MediaStreamDevice( | 178 devices->push_back(content::MediaStreamDevice( |
| 177 content::MEDIA_DESKTOP_AUDIO_CAPTURE, | 179 content::MEDIA_DESKTOP_AUDIO_CAPTURE, |
| 178 media::AudioDeviceDescription::kLoopbackWithMuteDeviceId, | 180 media::AudioDeviceDescription::kLoopbackWithMuteDeviceId, |
| 179 "System Audio")); | 181 "System Audio")); |
| 180 } else { | 182 } else { |
| 181 // Use the special loopback device ID for system audio capture. | 183 // Use the special loopback device ID for system audio capture. |
| 182 devices->push_back(content::MediaStreamDevice( | 184 devices->push_back(content::MediaStreamDevice( |
| 183 content::MEDIA_DESKTOP_AUDIO_CAPTURE, | 185 content::MEDIA_DESKTOP_AUDIO_CAPTURE, |
| 184 media::AudioDeviceDescription::kLoopbackInputDeviceId, | 186 media::AudioDeviceDescription::kLoopbackInputDeviceId, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 webrtc::kFullDesktopScreenId); | 320 webrtc::kFullDesktopScreenId); |
| 319 #endif // !defined(OS_CHROMEOS) | 321 #endif // !defined(OS_CHROMEOS) |
| 320 | 322 |
| 321 bool capture_audio = | 323 bool capture_audio = |
| 322 (request.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE && | 324 (request.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE && |
| 323 loopback_audio_supported); | 325 loopback_audio_supported); |
| 324 | 326 |
| 325 // Determine if the extension is required to display a notification. | 327 // Determine if the extension is required to display a notification. |
| 326 const bool display_notification = ShouldDisplayNotification(extension); | 328 const bool display_notification = ShouldDisplayNotification(extension); |
| 327 | 329 |
| 328 ui = GetDevicesForDesktopCapture(&devices, screen_id, capture_audio, true, | 330 ui = GetDevicesForDesktopCapture( |
| 329 display_notification, application_title, | 331 &devices, screen_id, capture_audio, request.disable_local_echo, |
| 330 application_title); | 332 display_notification, application_title, application_title); |
| 331 DCHECK(!devices.empty()); | 333 DCHECK(!devices.empty()); |
| 332 } | 334 } |
| 333 | 335 |
| 334 // The only case when devices can be empty is if the user has denied | 336 // The only case when devices can be empty is if the user has denied |
| 335 // permission. | 337 // permission. |
| 336 result = devices.empty() ? content::MEDIA_DEVICE_PERMISSION_DENIED | 338 result = devices.empty() ? content::MEDIA_DEVICE_PERMISSION_DENIED |
| 337 : content::MEDIA_DEVICE_OK; | 339 : content::MEDIA_DEVICE_OK; |
| 338 } | 340 } |
| 339 | 341 |
| 340 callback.Run(devices, result, std::move(ui)); | 342 callback.Run(devices, result, std::move(ui)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 const bool check_audio_permission = | 440 const bool check_audio_permission = |
| 439 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 441 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 440 extensions::switches::kDisableDesktopCaptureAudio); | 442 extensions::switches::kDisableDesktopCaptureAudio); |
| 441 const bool capture_audio = | 443 const bool capture_audio = |
| 442 (check_audio_permission ? audio_permitted : true) && audio_requested && | 444 (check_audio_permission ? audio_permitted : true) && audio_requested && |
| 443 audio_supported; | 445 audio_supported; |
| 444 | 446 |
| 445 // Determine if the extension is required to display a notification. | 447 // Determine if the extension is required to display a notification. |
| 446 const bool display_notification = ShouldDisplayNotification(extension); | 448 const bool display_notification = ShouldDisplayNotification(extension); |
| 447 | 449 |
| 448 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, false, | 450 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, |
| 451 request.disable_local_echo, |
| 449 display_notification, | 452 display_notification, |
| 450 GetApplicationTitle(web_contents, extension), | 453 GetApplicationTitle(web_contents, extension), |
| 451 base::UTF8ToUTF16(original_extension_name)); | 454 base::UTF8ToUTF16(original_extension_name)); |
| 452 UpdateExtensionTrusted(request, extension); | 455 UpdateExtensionTrusted(request, extension); |
| 453 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); | 456 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); |
| 454 } | 457 } |
| OLD | NEW |