OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/media_capture_devices_dispatcher.h" | 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 // Helper to get list of media stream devices for desktop capture in |devices|. | 150 // Helper to get list of media stream devices for desktop capture in |devices|. |
151 // Registers to display notification if |display_notification| is true. | 151 // Registers to display notification if |display_notification| is true. |
152 // Returns an instance of MediaStreamUI to be passed to content layer. | 152 // Returns an instance of MediaStreamUI to be passed to content layer. |
153 scoped_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( | 153 scoped_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( |
154 content::MediaStreamDevices& devices, | 154 content::MediaStreamDevices& devices, |
155 content::DesktopMediaID media_id, | 155 content::DesktopMediaID media_id, |
156 bool capture_audio, | 156 bool capture_audio, |
157 bool display_notification, | 157 bool display_notification, |
158 base::string16 application_title) { | 158 const base::string16& application_title, |
| 159 const base::string16& registered_extension_name) { |
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
160 scoped_ptr<content::MediaStreamUI> ui; | 161 scoped_ptr<content::MediaStreamUI> ui; |
161 | 162 |
162 // Add selected desktop source to the list. | 163 // Add selected desktop source to the list. |
163 devices.push_back(content::MediaStreamDevice( | 164 devices.push_back(content::MediaStreamDevice( |
164 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); | 165 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); |
165 if (capture_audio) { | 166 if (capture_audio) { |
166 // Use the special loopback device ID for system audio capture. | 167 // Use the special loopback device ID for system audio capture. |
167 devices.push_back(content::MediaStreamDevice( | 168 devices.push_back(content::MediaStreamDevice( |
168 content::MEDIA_LOOPBACK_AUDIO_CAPTURE, | 169 content::MEDIA_LOOPBACK_AUDIO_CAPTURE, |
169 media::AudioManagerBase::kLoopbackInputDeviceId, "System Audio")); | 170 media::AudioManagerBase::kLoopbackInputDeviceId, "System Audio")); |
170 } | 171 } |
171 | 172 |
172 // If required, register to display the notification for stream capture. | 173 // If required, register to display the notification for stream capture. |
173 if (display_notification) { | 174 if (display_notification) { |
174 ui = ScreenCaptureNotificationUI::Create(l10n_util::GetStringFUTF16( | 175 if (application_title == registered_extension_name) { |
175 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, | 176 ui = ScreenCaptureNotificationUI::Create(l10n_util::GetStringFUTF16( |
176 application_title)); | 177 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, |
| 178 application_title)); |
| 179 } else { |
| 180 ui = ScreenCaptureNotificationUI::Create(l10n_util::GetStringFUTF16( |
| 181 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT_DELEGATED, |
| 182 registered_extension_name, |
| 183 application_title)); |
| 184 } |
177 } | 185 } |
178 | 186 |
179 return ui.Pass(); | 187 return ui.Pass(); |
180 } | 188 } |
181 | 189 |
182 } // namespace | 190 } // namespace |
183 | 191 |
184 MediaCaptureDevicesDispatcher::PendingAccessRequest::PendingAccessRequest( | 192 MediaCaptureDevicesDispatcher::PendingAccessRequest::PendingAccessRequest( |
185 const content::MediaStreamRequest& request, | 193 const content::MediaStreamRequest& request, |
186 const content::MediaResponseCallback& callback) | 194 const content::MediaResponseCallback& callback) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 313 } |
306 | 314 |
307 // If the device id wasn't specified then this is a screen capture request | 315 // If the device id wasn't specified then this is a screen capture request |
308 // (i.e. chooseDesktopMedia() API wasn't used to generate device id). | 316 // (i.e. chooseDesktopMedia() API wasn't used to generate device id). |
309 if (request.requested_video_device_id.empty()) { | 317 if (request.requested_video_device_id.empty()) { |
310 ProcessScreenCaptureAccessRequest( | 318 ProcessScreenCaptureAccessRequest( |
311 web_contents, request, callback, extension); | 319 web_contents, request, callback, extension); |
312 return; | 320 return; |
313 } | 321 } |
314 | 322 |
| 323 // The extension name that the stream is registered with. |
| 324 std::string original_extension_name; |
315 // Resolve DesktopMediaID for the specified device id. | 325 // Resolve DesktopMediaID for the specified device id. |
316 content::DesktopMediaID media_id = | 326 content::DesktopMediaID media_id = |
317 GetDesktopStreamsRegistry()->RequestMediaForStreamId( | 327 GetDesktopStreamsRegistry()->RequestMediaForStreamId( |
318 request.requested_video_device_id, request.render_process_id, | 328 request.requested_video_device_id, request.render_process_id, |
319 request.render_view_id, request.security_origin); | 329 request.render_view_id, request.security_origin, |
| 330 &original_extension_name); |
320 | 331 |
321 // Received invalid device id. | 332 // Received invalid device id. |
322 if (media_id.type == content::DesktopMediaID::TYPE_NONE) { | 333 if (media_id.type == content::DesktopMediaID::TYPE_NONE) { |
323 callback.Run(devices, ui.Pass()); | 334 callback.Run(devices, ui.Pass()); |
324 return; | 335 return; |
325 } | 336 } |
326 | 337 |
327 bool loopback_audio_supported = false; | 338 bool loopback_audio_supported = false; |
328 #if defined(USE_CRAS) || defined(OS_WIN) | 339 #if defined(USE_CRAS) || defined(OS_WIN) |
329 // Currently loopback audio capture is supported only on Windows and ChromeOS. | 340 // Currently loopback audio capture is supported only on Windows and ChromeOS. |
330 loopback_audio_supported = true; | 341 loopback_audio_supported = true; |
331 #endif | 342 #endif |
332 | 343 |
333 // Audio is only supported for screen capture streams. | 344 // Audio is only supported for screen capture streams. |
334 bool capture_audio = | 345 bool capture_audio = |
335 (media_id.type == content::DesktopMediaID::TYPE_SCREEN && | 346 (media_id.type == content::DesktopMediaID::TYPE_SCREEN && |
336 request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && | 347 request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && |
337 loopback_audio_supported); | 348 loopback_audio_supported); |
338 | 349 |
339 ui = GetDevicesForDesktopCapture( | 350 ui = GetDevicesForDesktopCapture( |
340 devices, media_id, capture_audio, true, | 351 devices, media_id, capture_audio, true, |
341 GetApplicationTitle(web_contents, extension)); | 352 GetApplicationTitle(web_contents, extension), |
| 353 base::UTF8ToUTF16(original_extension_name)); |
342 | 354 |
343 callback.Run(devices, ui.Pass()); | 355 callback.Run(devices, ui.Pass()); |
344 } | 356 } |
345 | 357 |
346 void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( | 358 void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( |
347 content::WebContents* web_contents, | 359 content::WebContents* web_contents, |
348 const content::MediaStreamRequest& request, | 360 const content::MediaStreamRequest& request, |
349 const content::MediaResponseCallback& callback, | 361 const content::MediaResponseCallback& callback, |
350 const extensions::Extension* extension) { | 362 const extensions::Extension* extension) { |
351 content::MediaStreamDevices devices; | 363 content::MediaStreamDevices devices; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 430 |
419 bool capture_audio = | 431 bool capture_audio = |
420 (request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && | 432 (request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && |
421 loopback_audio_supported); | 433 loopback_audio_supported); |
422 | 434 |
423 // Unless we're being invoked from a component extension, register to | 435 // Unless we're being invoked from a component extension, register to |
424 // display the notification for stream capture. | 436 // display the notification for stream capture. |
425 bool display_notification = !component_extension; | 437 bool display_notification = !component_extension; |
426 | 438 |
427 ui = GetDevicesForDesktopCapture(devices, screen_id, capture_audio, | 439 ui = GetDevicesForDesktopCapture(devices, screen_id, capture_audio, |
428 display_notification, application_title); | 440 display_notification, application_title, |
| 441 application_title); |
429 } | 442 } |
430 } | 443 } |
431 | 444 |
432 callback.Run(devices, ui.Pass()); | 445 callback.Run(devices, ui.Pass()); |
433 } | 446 } |
434 | 447 |
435 void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest( | 448 void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest( |
436 content::WebContents* web_contents, | 449 content::WebContents* web_contents, |
437 const content::MediaStreamRequest& request, | 450 const content::MediaStreamRequest& request, |
438 const content::MediaResponseCallback& callback, | 451 const content::MediaResponseCallback& callback, |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 int render_frame_id) { | 837 int render_frame_id) { |
825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
826 FOR_EACH_OBSERVER(Observer, observers_, | 839 FOR_EACH_OBSERVER(Observer, observers_, |
827 OnCreatingAudioStream(render_process_id, render_frame_id)); | 840 OnCreatingAudioStream(render_process_id, render_frame_id)); |
828 } | 841 } |
829 | 842 |
830 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { | 843 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { |
831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
832 return desktop_capture_sessions_.size() > 0; | 845 return desktop_capture_sessions_.size() > 0; |
833 } | 846 } |
OLD | NEW |