Chromium Code Reviews| 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/desktop_capture_access_handler.h" | 5 #include "chrome/browser/media/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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 133 } |
| 134 return base::string16(); | 134 return base::string16(); |
| 135 } | 135 } |
| 136 // Helper to get list of media stream devices for desktop capture in |devices|. | 136 // Helper to get list of media stream devices for desktop capture in |devices|. |
| 137 // Registers to display notification if |display_notification| is true. | 137 // Registers to display notification if |display_notification| is true. |
| 138 // Returns an instance of MediaStreamUI to be passed to content layer. | 138 // Returns an instance of MediaStreamUI to be passed to content layer. |
| 139 std::unique_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( | 139 std::unique_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( |
| 140 content::MediaStreamDevices* devices, | 140 content::MediaStreamDevices* devices, |
| 141 content::DesktopMediaID media_id, | 141 content::DesktopMediaID media_id, |
| 142 bool capture_audio, | 142 bool capture_audio, |
| 143 bool mute_system_audio, | |
|
miu
2016/07/19 01:09:44
Can this method be called with media_id set to kLo
qiangchen
2016/07/20 22:13:22
This function is shared between HandleRequest and
| |
| 143 bool display_notification, | 144 bool display_notification, |
| 144 const base::string16& application_title, | 145 const base::string16& application_title, |
| 145 const base::string16& registered_extension_name) { | 146 const base::string16& registered_extension_name) { |
| 146 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 147 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 147 std::unique_ptr<content::MediaStreamUI> ui; | 148 std::unique_ptr<content::MediaStreamUI> ui; |
| 148 | 149 |
| 149 // Add selected desktop source to the list. | 150 // Add selected desktop source to the list. |
| 150 devices->push_back(content::MediaStreamDevice( | 151 devices->push_back(content::MediaStreamDevice( |
| 151 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); | 152 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); |
| 152 if (capture_audio) { | 153 if (capture_audio) { |
| 153 if (media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { | 154 if (media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { |
| 154 devices->push_back( | 155 devices->push_back( |
| 155 content::MediaStreamDevice(content::MEDIA_DESKTOP_AUDIO_CAPTURE, | 156 content::MediaStreamDevice(content::MEDIA_DESKTOP_AUDIO_CAPTURE, |
| 156 media_id.ToString(), "Tab audio")); | 157 media_id.ToString(), "Tab audio")); |
| 158 } else if (mute_system_audio) { | |
| 159 // Use the special loopback device ID for system audio capture. | |
| 160 devices->push_back(content::MediaStreamDevice( | |
| 161 content::MEDIA_DESKTOP_AUDIO_CAPTURE, | |
| 162 media::AudioDeviceDescription::kLoopbackWithMuteDeviceId, | |
| 163 "System Audio")); | |
| 157 } else { | 164 } else { |
| 158 // Use the special loopback device ID for system audio capture. | 165 // Use the special loopback device ID for system audio capture. |
| 159 devices->push_back(content::MediaStreamDevice( | 166 devices->push_back(content::MediaStreamDevice( |
| 160 content::MEDIA_DESKTOP_AUDIO_CAPTURE, | 167 content::MEDIA_DESKTOP_AUDIO_CAPTURE, |
| 161 media::AudioDeviceDescription::kLoopbackInputDeviceId, | 168 media::AudioDeviceDescription::kLoopbackInputDeviceId, |
| 162 "System Audio")); | 169 "System Audio")); |
| 163 } | 170 } |
| 164 } | 171 } |
| 165 | 172 |
| 166 // If required, register to display the notification for stream capture. | 173 // If required, register to display the notification for stream capture. |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 #endif // !defined(OS_CHROMEOS) | 309 #endif // !defined(OS_CHROMEOS) |
| 303 | 310 |
| 304 bool capture_audio = | 311 bool capture_audio = |
| 305 (request.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE && | 312 (request.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE && |
| 306 loopback_audio_supported); | 313 loopback_audio_supported); |
| 307 | 314 |
| 308 // Unless we're being invoked from a component extension, register to | 315 // Unless we're being invoked from a component extension, register to |
| 309 // display the notification for stream capture. | 316 // display the notification for stream capture. |
| 310 bool display_notification = !component_extension; | 317 bool display_notification = !component_extension; |
| 311 | 318 |
| 312 ui = GetDevicesForDesktopCapture(&devices, screen_id, capture_audio, | 319 ui = GetDevicesForDesktopCapture(&devices, screen_id, capture_audio, true, |
| 313 display_notification, application_title, | 320 display_notification, application_title, |
| 314 application_title); | 321 application_title); |
| 315 DCHECK(!devices.empty()); | 322 DCHECK(!devices.empty()); |
| 316 } | 323 } |
| 317 | 324 |
| 318 // The only case when devices can be empty is if the user has denied | 325 // The only case when devices can be empty is if the user has denied |
| 319 // permission. | 326 // permission. |
| 320 result = devices.empty() ? content::MEDIA_DEVICE_PERMISSION_DENIED | 327 result = devices.empty() ? content::MEDIA_DEVICE_PERMISSION_DENIED |
| 321 : content::MEDIA_DEVICE_OK; | 328 : content::MEDIA_DEVICE_OK; |
| 322 } | 329 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 loopback_audio_supported) || | 418 loopback_audio_supported) || |
| 412 media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS; | 419 media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS; |
| 413 | 420 |
| 414 const bool check_audio_permission = | 421 const bool check_audio_permission = |
| 415 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 422 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 416 extensions::switches::kDisableDesktopCaptureAudio); | 423 extensions::switches::kDisableDesktopCaptureAudio); |
| 417 const bool capture_audio = | 424 const bool capture_audio = |
| 418 (check_audio_permission ? audio_permitted : true) && audio_requested && | 425 (check_audio_permission ? audio_permitted : true) && audio_requested && |
| 419 audio_supported; | 426 audio_supported; |
| 420 | 427 |
| 421 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, true, | 428 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, false, |
| 429 true, | |
| 422 GetApplicationTitle(web_contents, extension), | 430 GetApplicationTitle(web_contents, extension), |
| 423 base::UTF8ToUTF16(original_extension_name)); | 431 base::UTF8ToUTF16(original_extension_name)); |
| 424 UpdateExtensionTrusted(request, extension); | 432 UpdateExtensionTrusted(request, extension); |
| 425 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); | 433 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); |
| 426 } | 434 } |
| 427 | 435 |
| OLD | NEW |