| 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/webrtc/media_capture_devices_dispatcher.h" | 5 #include "chrome/browser/media/webrtc/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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
| 31 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
| 34 #include "extensions/common/constants.h" | 34 #include "extensions/common/constants.h" |
| 35 #include "extensions/features/features.h" | 35 #include "extensions/features/features.h" |
| 36 #include "media/base/media_switches.h" | 36 #include "media/base/media_switches.h" |
| 37 | 37 |
| 38 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 39 #include "ash/shell.h" | 39 #include "ash/shell.h" |
| 40 #include "chrome/browser/media/chromeos_login_media_access_handler.h" |
| 40 #include "chrome/browser/media/public_session_media_access_handler.h" | 41 #include "chrome/browser/media/public_session_media_access_handler.h" |
| 41 #include "chrome/browser/media/public_session_tab_capture_access_handler.h" | 42 #include "chrome/browser/media/public_session_tab_capture_access_handler.h" |
| 42 #endif // defined(OS_CHROMEOS) | 43 #endif // defined(OS_CHROMEOS) |
| 43 | 44 |
| 44 #if BUILDFLAG(ENABLE_EXTENSIONS) | 45 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 45 #include "chrome/browser/media/extension_media_access_handler.h" | 46 #include "chrome/browser/media/extension_media_access_handler.h" |
| 46 #include "chrome/browser/media/webrtc/desktop_capture_access_handler.h" | 47 #include "chrome/browser/media/webrtc/desktop_capture_access_handler.h" |
| 47 #include "chrome/browser/media/webrtc/tab_capture_access_handler.h" | 48 #include "chrome/browser/media/webrtc/tab_capture_access_handler.h" |
| 48 #include "extensions/browser/extension_registry.h" | 49 #include "extensions/browser/extension_registry.h" |
| 49 #include "extensions/common/extension.h" | 50 #include "extensions/common/extension.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 const std::string& device_id) { | 63 const std::string& device_id) { |
| 63 content::MediaStreamDevices::const_iterator iter = devices.begin(); | 64 content::MediaStreamDevices::const_iterator iter = devices.begin(); |
| 64 for (; iter != devices.end(); ++iter) { | 65 for (; iter != devices.end(); ++iter) { |
| 65 if (iter->id == device_id) { | 66 if (iter->id == device_id) { |
| 66 return &(*iter); | 67 return &(*iter); |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 return NULL; | 70 return NULL; |
| 70 } | 71 } |
| 71 | 72 |
| 73 content::WebContents* WebContentsFromIds(int render_process_id, |
| 74 int render_frame_id) { |
| 75 content::WebContents* web_contents = |
| 76 content::WebContents::FromRenderFrameHost( |
| 77 content::RenderFrameHost::FromID(render_process_id, render_frame_id)); |
| 78 return web_contents; |
| 79 } |
| 80 |
| 72 #if BUILDFLAG(ENABLE_EXTENSIONS) | 81 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 73 inline CaptureAccessHandlerBase* ToCaptureAccessHandlerBase( | 82 inline CaptureAccessHandlerBase* ToCaptureAccessHandlerBase( |
| 74 MediaAccessHandler* handler) { | 83 MediaAccessHandler* handler) { |
| 75 return static_cast<CaptureAccessHandlerBase*>(handler); | 84 return static_cast<CaptureAccessHandlerBase*>(handler); |
| 76 } | 85 } |
| 77 #endif | 86 #endif |
| 78 } // namespace | 87 } // namespace |
| 79 | 88 |
| 80 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 89 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { |
| 81 return base::Singleton<MediaCaptureDevicesDispatcher>::get(); | 90 return base::Singleton<MediaCaptureDevicesDispatcher>::get(); |
| 82 } | 91 } |
| 83 | 92 |
| 84 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 93 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() |
| 85 : is_device_enumeration_disabled_(false), | 94 : is_device_enumeration_disabled_(false), |
| 86 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) { | 95 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) { |
| 87 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 88 | 97 |
| 89 #if BUILDFLAG(ENABLE_EXTENSIONS) | 98 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 90 #if defined(OS_CHROMEOS) | 99 #if defined(OS_CHROMEOS) |
| 100 media_access_handlers_.push_back( |
| 101 base::MakeUnique<ChromeOSLoginMediaAccessHandler>()); |
| 91 // Wrapper around ExtensionMediaAccessHandler used in Public Sessions. | 102 // Wrapper around ExtensionMediaAccessHandler used in Public Sessions. |
| 92 media_access_handlers_.push_back( | 103 media_access_handlers_.push_back( |
| 93 base::MakeUnique<PublicSessionMediaAccessHandler>()); | 104 base::MakeUnique<PublicSessionMediaAccessHandler>()); |
| 94 #else | 105 #else |
| 95 media_access_handlers_.push_back( | 106 media_access_handlers_.push_back( |
| 96 base::MakeUnique<ExtensionMediaAccessHandler>()); | 107 base::MakeUnique<ExtensionMediaAccessHandler>()); |
| 97 #endif | 108 #endif |
| 98 media_access_handlers_.push_back( | 109 media_access_handlers_.push_back( |
| 99 base::MakeUnique<DesktopCaptureAccessHandler>()); | 110 base::MakeUnique<DesktopCaptureAccessHandler>()); |
| 100 #if defined(OS_CHROMEOS) | 111 #if defined(OS_CHROMEOS) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 169 } |
| 159 | 170 |
| 160 void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( | 171 void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( |
| 161 content::WebContents* web_contents, | 172 content::WebContents* web_contents, |
| 162 const content::MediaStreamRequest& request, | 173 const content::MediaStreamRequest& request, |
| 163 const content::MediaResponseCallback& callback, | 174 const content::MediaResponseCallback& callback, |
| 164 const extensions::Extension* extension) { | 175 const extensions::Extension* extension) { |
| 165 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 166 | 177 |
| 167 for (const auto& handler : media_access_handlers_) { | 178 for (const auto& handler : media_access_handlers_) { |
| 168 if (handler->SupportsStreamType(request.video_type, extension) || | 179 if (handler->SupportsStreamType(web_contents, request.video_type, |
| 169 handler->SupportsStreamType(request.audio_type, extension)) { | 180 extension) || |
| 181 handler->SupportsStreamType(web_contents, request.audio_type, |
| 182 extension)) { |
| 170 handler->HandleRequest(web_contents, request, callback, extension); | 183 handler->HandleRequest(web_contents, request, callback, extension); |
| 171 return; | 184 return; |
| 172 } | 185 } |
| 173 } | 186 } |
| 174 callback.Run(content::MediaStreamDevices(), | 187 callback.Run(content::MediaStreamDevices(), |
| 175 content::MEDIA_DEVICE_NOT_SUPPORTED, nullptr); | 188 content::MEDIA_DEVICE_NOT_SUPPORTED, nullptr); |
| 176 } | 189 } |
| 177 | 190 |
| 178 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 191 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 179 content::WebContents* web_contents, | 192 content::WebContents* web_contents, |
| 180 const GURL& security_origin, | 193 const GURL& security_origin, |
| 181 content::MediaStreamType type) { | 194 content::MediaStreamType type) { |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 195 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 183 return CheckMediaAccessPermission(web_contents, security_origin, type, | 196 return CheckMediaAccessPermission(web_contents, security_origin, type, |
| 184 nullptr); | 197 nullptr); |
| 185 } | 198 } |
| 186 | 199 |
| 187 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 200 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 188 content::WebContents* web_contents, | 201 content::WebContents* web_contents, |
| 189 const GURL& security_origin, | 202 const GURL& security_origin, |
| 190 content::MediaStreamType type, | 203 content::MediaStreamType type, |
| 191 const extensions::Extension* extension) { | 204 const extensions::Extension* extension) { |
| 192 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 205 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 193 for (const auto& handler : media_access_handlers_) { | 206 for (const auto& handler : media_access_handlers_) { |
| 194 if (handler->SupportsStreamType(type, extension)) { | 207 if (handler->SupportsStreamType(web_contents, type, extension)) { |
| 195 return handler->CheckMediaAccessPermission(web_contents, security_origin, | 208 return handler->CheckMediaAccessPermission(web_contents, security_origin, |
| 196 type, extension); | 209 type, extension); |
| 197 } | 210 } |
| 198 } | 211 } |
| 199 return false; | 212 return false; |
| 200 } | 213 } |
| 201 | 214 |
| 202 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 215 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( |
| 203 Profile* profile, | 216 Profile* profile, |
| 204 bool audio, | 217 bool audio, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 observer.OnUpdateVideoDevices(devices); | 367 observer.OnUpdateVideoDevices(devices); |
| 355 } | 368 } |
| 356 | 369 |
| 357 void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( | 370 void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( |
| 358 int render_process_id, | 371 int render_process_id, |
| 359 int render_frame_id, | 372 int render_frame_id, |
| 360 int page_request_id, | 373 int page_request_id, |
| 361 const GURL& security_origin, | 374 const GURL& security_origin, |
| 362 content::MediaStreamType stream_type, | 375 content::MediaStreamType stream_type, |
| 363 content::MediaRequestState state) { | 376 content::MediaRequestState state) { |
| 377 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 364 for (const auto& handler : media_access_handlers_) { | 378 for (const auto& handler : media_access_handlers_) { |
| 365 if (handler->SupportsStreamType(stream_type, nullptr)) { | 379 if (handler->SupportsStreamType( |
| 380 WebContentsFromIds(render_process_id, render_frame_id), stream_type, |
| 381 nullptr)) { |
| 366 handler->UpdateMediaRequestState(render_process_id, render_frame_id, | 382 handler->UpdateMediaRequestState(render_process_id, render_frame_id, |
| 367 page_request_id, stream_type, state); | 383 page_request_id, stream_type, state); |
| 368 break; | 384 break; |
| 369 } | 385 } |
| 370 } | 386 } |
| 371 | 387 |
| 372 #if defined(OS_CHROMEOS) | 388 #if defined(OS_CHROMEOS) |
| 373 if (IsOriginForCasting(security_origin) && IsVideoMediaType(stream_type)) { | 389 if (IsOriginForCasting(security_origin) && IsVideoMediaType(stream_type)) { |
| 374 // Notify ash that casting state has changed. | 390 // Notify ash that casting state has changed. |
| 375 if (state == content::MEDIA_REQUEST_STATE_DONE) { | 391 if (state == content::MEDIA_REQUEST_STATE_DONE) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 393 for (auto& observer : observers_) | 409 for (auto& observer : observers_) |
| 394 observer.OnCreatingAudioStream(render_process_id, render_frame_id); | 410 observer.OnCreatingAudioStream(render_process_id, render_frame_id); |
| 395 } | 411 } |
| 396 | 412 |
| 397 bool MediaCaptureDevicesDispatcher::IsInsecureCapturingInProgress( | 413 bool MediaCaptureDevicesDispatcher::IsInsecureCapturingInProgress( |
| 398 int render_process_id, | 414 int render_process_id, |
| 399 int render_frame_id) { | 415 int render_frame_id) { |
| 400 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 416 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 401 #if BUILDFLAG(ENABLE_EXTENSIONS) | 417 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 402 for (const auto& handler : media_access_handlers_) { | 418 for (const auto& handler : media_access_handlers_) { |
| 403 if (handler->SupportsStreamType(content::MEDIA_DESKTOP_VIDEO_CAPTURE, | 419 if (handler->SupportsStreamType( |
| 404 nullptr) || | 420 WebContentsFromIds(render_process_id, render_frame_id), |
| 405 handler->SupportsStreamType(content::MEDIA_TAB_VIDEO_CAPTURE, | 421 content::MEDIA_DESKTOP_VIDEO_CAPTURE, nullptr) || |
| 406 nullptr)) { | 422 handler->SupportsStreamType( |
| 423 WebContentsFromIds(render_process_id, render_frame_id), |
| 424 content::MEDIA_TAB_VIDEO_CAPTURE, nullptr)) { |
| 407 if (ToCaptureAccessHandlerBase(handler.get()) | 425 if (ToCaptureAccessHandlerBase(handler.get()) |
| 408 ->IsInsecureCapturingInProgress(render_process_id, | 426 ->IsInsecureCapturingInProgress(render_process_id, |
| 409 render_frame_id)) | 427 render_frame_id)) |
| 410 return true; | 428 return true; |
| 411 } | 429 } |
| 412 } | 430 } |
| 413 #endif | 431 #endif |
| 414 return false; | 432 return false; |
| 415 } | 433 } |
| 416 | 434 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 int page_request_id, | 466 int page_request_id, |
| 449 content::MediaStreamType stream_type, | 467 content::MediaStreamType stream_type, |
| 450 bool is_secure) { | 468 bool is_secure) { |
| 451 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 469 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 452 if (stream_type != content::MEDIA_TAB_VIDEO_CAPTURE && | 470 if (stream_type != content::MEDIA_TAB_VIDEO_CAPTURE && |
| 453 stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) | 471 stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) |
| 454 return; | 472 return; |
| 455 | 473 |
| 456 #if BUILDFLAG(ENABLE_EXTENSIONS) | 474 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 457 for (const auto& handler : media_access_handlers_) { | 475 for (const auto& handler : media_access_handlers_) { |
| 458 if (handler->SupportsStreamType(stream_type, nullptr)) { | 476 if (handler->SupportsStreamType( |
| 477 WebContentsFromIds(render_process_id, render_frame_id), stream_type, |
| 478 nullptr)) { |
| 459 ToCaptureAccessHandlerBase(handler.get()) | 479 ToCaptureAccessHandlerBase(handler.get()) |
| 460 ->UpdateCapturingLinkSecured(render_process_id, render_frame_id, | 480 ->UpdateCapturingLinkSecured(render_process_id, render_frame_id, |
| 461 page_request_id, is_secure); | 481 page_request_id, is_secure); |
| 462 break; | 482 break; |
| 463 } | 483 } |
| 464 } | 484 } |
| 465 #endif | 485 #endif |
| 466 } | 486 } |
| OLD | NEW |