| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Helper to get list of media stream devices for desktop capture in |devices|. | 175 // Helper to get list of media stream devices for desktop capture in |devices|. |
| 176 // Registers to display notification if |display_notification| is true. | 176 // Registers to display notification if |display_notification| is true. |
| 177 // Returns an instance of MediaStreamUI to be passed to content layer. | 177 // Returns an instance of MediaStreamUI to be passed to content layer. |
| 178 scoped_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( | 178 scoped_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( |
| 179 content::MediaStreamDevices* devices, | 179 content::MediaStreamDevices* devices, |
| 180 content::DesktopMediaID media_id, | 180 content::DesktopMediaID media_id, |
| 181 bool capture_audio, | 181 bool capture_audio, |
| 182 bool display_notification, | 182 bool display_notification, |
| 183 const base::string16& application_title, | 183 const base::string16& application_title, |
| 184 const base::string16& registered_extension_name) { | 184 const base::string16& registered_extension_name) { |
| 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 185 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 186 scoped_ptr<content::MediaStreamUI> ui; | 186 scoped_ptr<content::MediaStreamUI> ui; |
| 187 | 187 |
| 188 // Add selected desktop source to the list. | 188 // Add selected desktop source to the list. |
| 189 devices->push_back(content::MediaStreamDevice( | 189 devices->push_back(content::MediaStreamDevice( |
| 190 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); | 190 content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); |
| 191 if (capture_audio) { | 191 if (capture_audio) { |
| 192 // Use the special loopback device ID for system audio capture. | 192 // Use the special loopback device ID for system audio capture. |
| 193 devices->push_back(content::MediaStreamDevice( | 193 devices->push_back(content::MediaStreamDevice( |
| 194 content::MEDIA_DESKTOP_AUDIO_CAPTURE, | 194 content::MEDIA_DESKTOP_AUDIO_CAPTURE, |
| 195 media::AudioManagerBase::kLoopbackInputDeviceId, "System Audio")); | 195 media::AudioManagerBase::kLoopbackInputDeviceId, "System Audio")); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return Singleton<MediaCaptureDevicesDispatcher>::get(); | 264 return Singleton<MediaCaptureDevicesDispatcher>::get(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 267 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() |
| 268 : is_device_enumeration_disabled_(false), | 268 : is_device_enumeration_disabled_(false), |
| 269 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) { | 269 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) { |
| 270 // MediaCaptureDevicesDispatcher is a singleton. It should be created on | 270 // MediaCaptureDevicesDispatcher is a singleton. It should be created on |
| 271 // UI thread. Otherwise, it will not receive | 271 // UI thread. Otherwise, it will not receive |
| 272 // content::NOTIFICATION_WEB_CONTENTS_DESTROYED, and that will result in | 272 // content::NOTIFICATION_WEB_CONTENTS_DESTROYED, and that will result in |
| 273 // possible use after free. | 273 // possible use after free. |
| 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 275 notifications_registrar_.Add( | 275 notifications_registrar_.Add( |
| 276 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 276 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 277 content::NotificationService::AllSources()); | 277 content::NotificationService::AllSources()); |
| 278 | 278 |
| 279 #if defined(OS_MACOSX) | 279 #if defined(OS_MACOSX) |
| 280 // AVFoundation is used for video/audio device monitoring and video capture. | 280 // AVFoundation is used for video/audio device monitoring and video capture. |
| 281 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 281 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 282 switches::kForceQTKit)) { | 282 switches::kForceQTKit)) { |
| 283 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 283 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 284 switches::kEnableAVFoundation); | 284 switches::kEnableAVFoundation); |
| 285 } | 285 } |
| 286 #endif | 286 #endif |
| 287 } | 287 } |
| 288 | 288 |
| 289 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} | 289 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} |
| 290 | 290 |
| 291 void MediaCaptureDevicesDispatcher::RegisterProfilePrefs( | 291 void MediaCaptureDevicesDispatcher::RegisterProfilePrefs( |
| 292 user_prefs::PrefRegistrySyncable* registry) { | 292 user_prefs::PrefRegistrySyncable* registry) { |
| 293 registry->RegisterStringPref( | 293 registry->RegisterStringPref( |
| 294 prefs::kDefaultAudioCaptureDevice, | 294 prefs::kDefaultAudioCaptureDevice, |
| 295 std::string(), | 295 std::string(), |
| 296 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 296 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 297 registry->RegisterStringPref( | 297 registry->RegisterStringPref( |
| 298 prefs::kDefaultVideoCaptureDevice, | 298 prefs::kDefaultVideoCaptureDevice, |
| 299 std::string(), | 299 std::string(), |
| 300 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 300 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void MediaCaptureDevicesDispatcher::AddObserver(Observer* observer) { | 303 void MediaCaptureDevicesDispatcher::AddObserver(Observer* observer) { |
| 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 304 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 305 if (!observers_.HasObserver(observer)) | 305 if (!observers_.HasObserver(observer)) |
| 306 observers_.AddObserver(observer); | 306 observers_.AddObserver(observer); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* observer) { | 309 void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* observer) { |
| 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 310 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 311 observers_.RemoveObserver(observer); | 311 observers_.RemoveObserver(observer); |
| 312 } | 312 } |
| 313 | 313 |
| 314 const MediaStreamDevices& | 314 const MediaStreamDevices& |
| 315 MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { | 315 MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { |
| 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 317 if (is_device_enumeration_disabled_ || !test_audio_devices_.empty()) | 317 if (is_device_enumeration_disabled_ || !test_audio_devices_.empty()) |
| 318 return test_audio_devices_; | 318 return test_audio_devices_; |
| 319 | 319 |
| 320 return MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); | 320 return MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 const MediaStreamDevices& | 323 const MediaStreamDevices& |
| 324 MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { | 324 MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { |
| 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 326 if (is_device_enumeration_disabled_ || !test_video_devices_.empty()) | 326 if (is_device_enumeration_disabled_ || !test_video_devices_.empty()) |
| 327 return test_video_devices_; | 327 return test_video_devices_; |
| 328 | 328 |
| 329 return MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); | 329 return MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void MediaCaptureDevicesDispatcher::Observe( | 332 void MediaCaptureDevicesDispatcher::Observe( |
| 333 int type, | 333 int type, |
| 334 const content::NotificationSource& source, | 334 const content::NotificationSource& source, |
| 335 const content::NotificationDetails& details) { | 335 const content::NotificationDetails& details) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 337 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 337 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 338 content::WebContents* web_contents = | 338 content::WebContents* web_contents = |
| 339 content::Source<content::WebContents>(source).ptr(); | 339 content::Source<content::WebContents>(source).ptr(); |
| 340 pending_requests_.erase(web_contents); | 340 pending_requests_.erase(web_contents); |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( | 344 void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( |
| 345 content::WebContents* web_contents, | 345 content::WebContents* web_contents, |
| 346 const content::MediaStreamRequest& request, | 346 const content::MediaStreamRequest& request, |
| 347 const content::MediaResponseCallback& callback, | 347 const content::MediaResponseCallback& callback, |
| 348 const extensions::Extension* extension) { | 348 const extensions::Extension* extension) { |
| 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 350 | 350 |
| 351 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE || | 351 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE || |
| 352 request.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE) { | 352 request.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE) { |
| 353 ProcessDesktopCaptureAccessRequest( | 353 ProcessDesktopCaptureAccessRequest( |
| 354 web_contents, request, callback, extension); | 354 web_contents, request, callback, extension); |
| 355 } else if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || | 355 } else if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || |
| 356 request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) { | 356 request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) { |
| 357 ProcessTabCaptureAccessRequest( | 357 ProcessTabCaptureAccessRequest( |
| 358 web_contents, request, callback, extension); | 358 web_contents, request, callback, extension); |
| 359 } else { | 359 } else { |
| 360 #if defined(ENABLE_EXTENSIONS) | 360 #if defined(ENABLE_EXTENSIONS) |
| 361 bool is_whitelisted = | 361 bool is_whitelisted = |
| 362 extension && (extension->is_platform_app() || | 362 extension && (extension->is_platform_app() || |
| 363 IsMediaRequestWhitelistedForExtension(extension)); | 363 IsMediaRequestWhitelistedForExtension(extension)); |
| 364 if (is_whitelisted) { | 364 if (is_whitelisted) { |
| 365 // For extensions access is approved based on extension permissions. | 365 // For extensions access is approved based on extension permissions. |
| 366 ProcessMediaAccessRequestFromPlatformAppOrExtension( | 366 ProcessMediaAccessRequestFromPlatformAppOrExtension( |
| 367 web_contents, request, callback, extension); | 367 web_contents, request, callback, extension); |
| 368 return; | 368 return; |
| 369 } | 369 } |
| 370 #endif | 370 #endif |
| 371 ProcessRegularMediaAccessRequest(web_contents, request, callback); | 371 ProcessRegularMediaAccessRequest(web_contents, request, callback); |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 375 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 376 content::BrowserContext* browser_context, | 376 content::BrowserContext* browser_context, |
| 377 const GURL& security_origin, | 377 const GURL& security_origin, |
| 378 content::MediaStreamType type) { | 378 content::MediaStreamType type) { |
| 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 379 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 380 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 380 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 381 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 381 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 382 | 382 |
| 383 Profile* profile = Profile::FromBrowserContext(browser_context); | 383 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 384 #if defined(ENABLE_EXTENSIONS) | 384 #if defined(ENABLE_EXTENSIONS) |
| 385 const extensions::Extension* extension = | 385 const extensions::Extension* extension = |
| 386 GetExtensionForOrigin(profile, security_origin); | 386 GetExtensionForOrigin(profile, security_origin); |
| 387 | 387 |
| 388 if (extension && (extension->is_platform_app() || | 388 if (extension && (extension->is_platform_app() || |
| 389 IsMediaRequestWhitelistedForExtension(extension))) { | 389 IsMediaRequestWhitelistedForExtension(extension))) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 return true; | 426 return true; |
| 427 } | 427 } |
| 428 | 428 |
| 429 return false; | 429 return false; |
| 430 } | 430 } |
| 431 | 431 |
| 432 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 432 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 433 content::WebContents* web_contents, | 433 content::WebContents* web_contents, |
| 434 const GURL& security_origin, | 434 const GURL& security_origin, |
| 435 content::MediaStreamType type) { | 435 content::MediaStreamType type) { |
| 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 437 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 437 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 438 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 438 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 439 | 439 |
| 440 Profile* profile = | 440 Profile* profile = |
| 441 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 441 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 442 | 442 |
| 443 ContentSettingsType contentSettingsType = | 443 ContentSettingsType contentSettingsType = |
| 444 type == content::MEDIA_DEVICE_AUDIO_CAPTURE | 444 type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 445 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 445 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 446 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | 446 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 474 | 474 |
| 475 return false; | 475 return false; |
| 476 } | 476 } |
| 477 | 477 |
| 478 #if defined(ENABLE_EXTENSIONS) | 478 #if defined(ENABLE_EXTENSIONS) |
| 479 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 479 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 480 content::WebContents* web_contents, | 480 content::WebContents* web_contents, |
| 481 const GURL& security_origin, | 481 const GURL& security_origin, |
| 482 content::MediaStreamType type, | 482 content::MediaStreamType type, |
| 483 const extensions::Extension* extension) { | 483 const extensions::Extension* extension) { |
| 484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 484 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 485 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 485 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 486 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 486 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 487 | 487 |
| 488 if (extension->is_platform_app() || | 488 if (extension->is_platform_app() || |
| 489 IsMediaRequestWhitelistedForExtension(extension)) { | 489 IsMediaRequestWhitelistedForExtension(extension)) { |
| 490 return extension->permissions_data()->HasAPIPermission( | 490 return extension->permissions_data()->HasAPIPermission( |
| 491 type == content::MEDIA_DEVICE_AUDIO_CAPTURE | 491 type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 492 ? extensions::APIPermission::kAudioCapture | 492 ? extensions::APIPermission::kAudioCapture |
| 493 : extensions::APIPermission::kVideoCapture); | 493 : extensions::APIPermission::kVideoCapture); |
| 494 } | 494 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 } | 828 } |
| 829 | 829 |
| 830 callback.Run(devices, result, ui.Pass()); | 830 callback.Run(devices, result, ui.Pass()); |
| 831 } | 831 } |
| 832 #endif | 832 #endif |
| 833 | 833 |
| 834 void MediaCaptureDevicesDispatcher::ProcessRegularMediaAccessRequest( | 834 void MediaCaptureDevicesDispatcher::ProcessRegularMediaAccessRequest( |
| 835 content::WebContents* web_contents, | 835 content::WebContents* web_contents, |
| 836 const content::MediaStreamRequest& request, | 836 const content::MediaStreamRequest& request, |
| 837 const content::MediaResponseCallback& callback) { | 837 const content::MediaResponseCallback& callback) { |
| 838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 838 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 839 | 839 |
| 840 RequestsQueue& queue = pending_requests_[web_contents]; | 840 RequestsQueue& queue = pending_requests_[web_contents]; |
| 841 queue.push_back(PendingAccessRequest(request, callback)); | 841 queue.push_back(PendingAccessRequest(request, callback)); |
| 842 | 842 |
| 843 // If this is the only request then show the infobar. | 843 // If this is the only request then show the infobar. |
| 844 if (queue.size() == 1) | 844 if (queue.size() == 1) |
| 845 ProcessQueuedAccessRequest(web_contents); | 845 ProcessQueuedAccessRequest(web_contents); |
| 846 } | 846 } |
| 847 | 847 |
| 848 void MediaCaptureDevicesDispatcher::ProcessQueuedAccessRequest( | 848 void MediaCaptureDevicesDispatcher::ProcessQueuedAccessRequest( |
| 849 content::WebContents* web_contents) { | 849 content::WebContents* web_contents) { |
| 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 850 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 851 | 851 |
| 852 std::map<content::WebContents*, RequestsQueue>::iterator it = | 852 std::map<content::WebContents*, RequestsQueue>::iterator it = |
| 853 pending_requests_.find(web_contents); | 853 pending_requests_.find(web_contents); |
| 854 | 854 |
| 855 if (it == pending_requests_.end() || it->second.empty()) { | 855 if (it == pending_requests_.end() || it->second.empty()) { |
| 856 // Don't do anything if the tab was closed. | 856 // Don't do anything if the tab was closed. |
| 857 return; | 857 return; |
| 858 } | 858 } |
| 859 | 859 |
| 860 DCHECK(!it->second.empty()); | 860 DCHECK(!it->second.empty()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 881 web_contents, it->second.front().request, | 881 web_contents, it->second.front().request, |
| 882 base::Bind(&MediaCaptureDevicesDispatcher::OnAccessRequestResponse, | 882 base::Bind(&MediaCaptureDevicesDispatcher::OnAccessRequestResponse, |
| 883 base::Unretained(this), web_contents)); | 883 base::Unretained(this), web_contents)); |
| 884 } | 884 } |
| 885 | 885 |
| 886 void MediaCaptureDevicesDispatcher::OnAccessRequestResponse( | 886 void MediaCaptureDevicesDispatcher::OnAccessRequestResponse( |
| 887 content::WebContents* web_contents, | 887 content::WebContents* web_contents, |
| 888 const content::MediaStreamDevices& devices, | 888 const content::MediaStreamDevices& devices, |
| 889 content::MediaStreamRequestResult result, | 889 content::MediaStreamRequestResult result, |
| 890 scoped_ptr<content::MediaStreamUI> ui) { | 890 scoped_ptr<content::MediaStreamUI> ui) { |
| 891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 891 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 892 | 892 |
| 893 std::map<content::WebContents*, RequestsQueue>::iterator it = | 893 std::map<content::WebContents*, RequestsQueue>::iterator it = |
| 894 pending_requests_.find(web_contents); | 894 pending_requests_.find(web_contents); |
| 895 if (it == pending_requests_.end()) { | 895 if (it == pending_requests_.end()) { |
| 896 // WebContents has been destroyed. Don't need to do anything. | 896 // WebContents has been destroyed. Don't need to do anything. |
| 897 return; | 897 return; |
| 898 } | 898 } |
| 899 | 899 |
| 900 RequestsQueue& queue(it->second); | 900 RequestsQueue& queue(it->second); |
| 901 if (queue.empty()) | 901 if (queue.empty()) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 915 } | 915 } |
| 916 | 916 |
| 917 callback.Run(devices, result, ui.Pass()); | 917 callback.Run(devices, result, ui.Pass()); |
| 918 } | 918 } |
| 919 | 919 |
| 920 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 920 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( |
| 921 Profile* profile, | 921 Profile* profile, |
| 922 bool audio, | 922 bool audio, |
| 923 bool video, | 923 bool video, |
| 924 content::MediaStreamDevices* devices) { | 924 content::MediaStreamDevices* devices) { |
| 925 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 925 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 926 DCHECK(audio || video); | 926 DCHECK(audio || video); |
| 927 | 927 |
| 928 PrefService* prefs = profile->GetPrefs(); | 928 PrefService* prefs = profile->GetPrefs(); |
| 929 std::string default_device; | 929 std::string default_device; |
| 930 if (audio) { | 930 if (audio) { |
| 931 default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice); | 931 default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
| 932 const content::MediaStreamDevice* device = | 932 const content::MediaStreamDevice* device = |
| 933 GetRequestedAudioDevice(default_device); | 933 GetRequestedAudioDevice(default_device); |
| 934 if (!device) | 934 if (!device) |
| 935 device = GetFirstAvailableAudioDevice(); | 935 device = GetFirstAvailableAudioDevice(); |
| 936 if (device) | 936 if (device) |
| 937 devices->push_back(*device); | 937 devices->push_back(*device); |
| 938 } | 938 } |
| 939 | 939 |
| 940 if (video) { | 940 if (video) { |
| 941 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); | 941 default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice); |
| 942 const content::MediaStreamDevice* device = | 942 const content::MediaStreamDevice* device = |
| 943 GetRequestedVideoDevice(default_device); | 943 GetRequestedVideoDevice(default_device); |
| 944 if (!device) | 944 if (!device) |
| 945 device = GetFirstAvailableVideoDevice(); | 945 device = GetFirstAvailableVideoDevice(); |
| 946 if (device) | 946 if (device) |
| 947 devices->push_back(*device); | 947 devices->push_back(*device); |
| 948 } | 948 } |
| 949 } | 949 } |
| 950 | 950 |
| 951 const content::MediaStreamDevice* | 951 const content::MediaStreamDevice* |
| 952 MediaCaptureDevicesDispatcher::GetRequestedAudioDevice( | 952 MediaCaptureDevicesDispatcher::GetRequestedAudioDevice( |
| 953 const std::string& requested_audio_device_id) { | 953 const std::string& requested_audio_device_id) { |
| 954 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 954 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 955 const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); | 955 const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); |
| 956 const content::MediaStreamDevice* const device = | 956 const content::MediaStreamDevice* const device = |
| 957 FindDeviceWithId(audio_devices, requested_audio_device_id); | 957 FindDeviceWithId(audio_devices, requested_audio_device_id); |
| 958 return device; | 958 return device; |
| 959 } | 959 } |
| 960 | 960 |
| 961 const content::MediaStreamDevice* | 961 const content::MediaStreamDevice* |
| 962 MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() { | 962 MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() { |
| 963 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 963 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 964 const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); | 964 const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); |
| 965 if (audio_devices.empty()) | 965 if (audio_devices.empty()) |
| 966 return NULL; | 966 return NULL; |
| 967 return &(*audio_devices.begin()); | 967 return &(*audio_devices.begin()); |
| 968 } | 968 } |
| 969 | 969 |
| 970 const content::MediaStreamDevice* | 970 const content::MediaStreamDevice* |
| 971 MediaCaptureDevicesDispatcher::GetRequestedVideoDevice( | 971 MediaCaptureDevicesDispatcher::GetRequestedVideoDevice( |
| 972 const std::string& requested_video_device_id) { | 972 const std::string& requested_video_device_id) { |
| 973 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 973 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 974 const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); | 974 const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); |
| 975 const content::MediaStreamDevice* const device = | 975 const content::MediaStreamDevice* const device = |
| 976 FindDeviceWithId(video_devices, requested_video_device_id); | 976 FindDeviceWithId(video_devices, requested_video_device_id); |
| 977 return device; | 977 return device; |
| 978 } | 978 } |
| 979 | 979 |
| 980 const content::MediaStreamDevice* | 980 const content::MediaStreamDevice* |
| 981 MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() { | 981 MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() { |
| 982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 982 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 983 const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); | 983 const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); |
| 984 if (video_devices.empty()) | 984 if (video_devices.empty()) |
| 985 return NULL; | 985 return NULL; |
| 986 return &(*video_devices.begin()); | 986 return &(*video_devices.begin()); |
| 987 } | 987 } |
| 988 | 988 |
| 989 void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() { | 989 void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() { |
| 990 is_device_enumeration_disabled_ = true; | 990 is_device_enumeration_disabled_ = true; |
| 991 } | 991 } |
| 992 | 992 |
| 993 scoped_refptr<MediaStreamCaptureIndicator> | 993 scoped_refptr<MediaStreamCaptureIndicator> |
| 994 MediaCaptureDevicesDispatcher::GetMediaStreamCaptureIndicator() { | 994 MediaCaptureDevicesDispatcher::GetMediaStreamCaptureIndicator() { |
| 995 return media_stream_capture_indicator_; | 995 return media_stream_capture_indicator_; |
| 996 } | 996 } |
| 997 | 997 |
| 998 DesktopStreamsRegistry* | 998 DesktopStreamsRegistry* |
| 999 MediaCaptureDevicesDispatcher::GetDesktopStreamsRegistry() { | 999 MediaCaptureDevicesDispatcher::GetDesktopStreamsRegistry() { |
| 1000 if (!desktop_streams_registry_) | 1000 if (!desktop_streams_registry_) |
| 1001 desktop_streams_registry_.reset(new DesktopStreamsRegistry()); | 1001 desktop_streams_registry_.reset(new DesktopStreamsRegistry()); |
| 1002 return desktop_streams_registry_.get(); | 1002 return desktop_streams_registry_.get(); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() { | 1005 void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() { |
| 1006 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1006 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1007 BrowserThread::PostTask( | 1007 BrowserThread::PostTask( |
| 1008 BrowserThread::UI, FROM_HERE, | 1008 BrowserThread::UI, FROM_HERE, |
| 1009 base::Bind( | 1009 base::Bind( |
| 1010 &MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread, | 1010 &MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread, |
| 1011 base::Unretained(this))); | 1011 base::Unretained(this))); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() { | 1014 void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() { |
| 1015 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1015 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1016 BrowserThread::PostTask( | 1016 BrowserThread::PostTask( |
| 1017 BrowserThread::UI, FROM_HERE, | 1017 BrowserThread::UI, FROM_HERE, |
| 1018 base::Bind( | 1018 base::Bind( |
| 1019 &MediaCaptureDevicesDispatcher::NotifyVideoDevicesChangedOnUIThread, | 1019 &MediaCaptureDevicesDispatcher::NotifyVideoDevicesChangedOnUIThread, |
| 1020 base::Unretained(this))); | 1020 base::Unretained(this))); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( | 1023 void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( |
| 1024 int render_process_id, | 1024 int render_process_id, |
| 1025 int render_frame_id, | 1025 int render_frame_id, |
| 1026 int page_request_id, | 1026 int page_request_id, |
| 1027 const GURL& security_origin, | 1027 const GURL& security_origin, |
| 1028 content::MediaStreamType stream_type, | 1028 content::MediaStreamType stream_type, |
| 1029 content::MediaRequestState state) { | 1029 content::MediaRequestState state) { |
| 1030 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1030 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1031 BrowserThread::PostTask( | 1031 BrowserThread::PostTask( |
| 1032 BrowserThread::UI, FROM_HERE, | 1032 BrowserThread::UI, FROM_HERE, |
| 1033 base::Bind( | 1033 base::Bind( |
| 1034 &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread, | 1034 &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread, |
| 1035 base::Unretained(this), render_process_id, render_frame_id, | 1035 base::Unretained(this), render_process_id, render_frame_id, |
| 1036 page_request_id, security_origin, stream_type, state)); | 1036 page_request_id, security_origin, stream_type, state)); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( | 1039 void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( |
| 1040 int render_process_id, | 1040 int render_process_id, |
| 1041 int render_frame_id) { | 1041 int render_frame_id) { |
| 1042 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1042 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1043 BrowserThread::PostTask( | 1043 BrowserThread::PostTask( |
| 1044 BrowserThread::UI, FROM_HERE, | 1044 BrowserThread::UI, FROM_HERE, |
| 1045 base::Bind( | 1045 base::Bind( |
| 1046 &MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread, | 1046 &MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread, |
| 1047 base::Unretained(this), render_process_id, render_frame_id)); | 1047 base::Unretained(this), render_process_id, render_frame_id)); |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 void MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread() { | 1050 void MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread() { |
| 1051 MediaStreamDevices devices = GetAudioCaptureDevices(); | 1051 MediaStreamDevices devices = GetAudioCaptureDevices(); |
| 1052 FOR_EACH_OBSERVER(Observer, observers_, | 1052 FOR_EACH_OBSERVER(Observer, observers_, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 FOR_EACH_OBSERVER(Observer, observers_, | 1124 FOR_EACH_OBSERVER(Observer, observers_, |
| 1125 OnRequestUpdate(render_process_id, | 1125 OnRequestUpdate(render_process_id, |
| 1126 render_frame_id, | 1126 render_frame_id, |
| 1127 stream_type, | 1127 stream_type, |
| 1128 state)); | 1128 state)); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( | 1131 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( |
| 1132 int render_process_id, | 1132 int render_process_id, |
| 1133 int render_frame_id) { | 1133 int render_frame_id) { |
| 1134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1134 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1135 FOR_EACH_OBSERVER(Observer, observers_, | 1135 FOR_EACH_OBSERVER(Observer, observers_, |
| 1136 OnCreatingAudioStream(render_process_id, render_frame_id)); | 1136 OnCreatingAudioStream(render_process_id, render_frame_id)); |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { | 1139 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { |
| 1140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1140 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1141 return desktop_capture_sessions_.size() > 0; | 1141 return desktop_capture_sessions_.size() > 0; |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( | 1144 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( |
| 1145 const MediaStreamDevices& devices) { | 1145 const MediaStreamDevices& devices) { |
| 1146 test_audio_devices_ = devices; | 1146 test_audio_devices_ = devices; |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( | 1149 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( |
| 1150 const MediaStreamDevices& devices) { | 1150 const MediaStreamDevices& devices) { |
| 1151 test_video_devices_ = devices; | 1151 test_video_devices_ = devices; |
| 1152 } | 1152 } |
| OLD | NEW |