Chromium Code Reviews| 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 return content::WebContents::FromRenderFrameHost( | |
|
emaxx
2017/04/06 02:41:47
It's not entirely clear to me whether we should ca
raymes
2017/04/10 00:16:49
That's a good point. Added a DCHECK for now.
raymes
2017/04/10 02:42:28
This can be nullptr, so I've added a check in the
| |
| 76 content::RenderFrameHost::FromID(render_process_id, render_frame_id)); | |
| 77 } | |
| 78 | |
| 72 #if BUILDFLAG(ENABLE_EXTENSIONS) | 79 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 73 inline CaptureAccessHandlerBase* ToCaptureAccessHandlerBase( | 80 inline CaptureAccessHandlerBase* ToCaptureAccessHandlerBase( |
| 74 MediaAccessHandler* handler) { | 81 MediaAccessHandler* handler) { |
| 75 return static_cast<CaptureAccessHandlerBase*>(handler); | 82 return static_cast<CaptureAccessHandlerBase*>(handler); |
| 76 } | 83 } |
| 77 #endif | 84 #endif |
| 78 } // namespace | 85 } // namespace |
| 79 | 86 |
| 80 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 87 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { |
| 81 return base::Singleton<MediaCaptureDevicesDispatcher>::get(); | 88 return base::Singleton<MediaCaptureDevicesDispatcher>::get(); |
| 82 } | 89 } |
| 83 | 90 |
| 84 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 91 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() |
| 85 : is_device_enumeration_disabled_(false), | 92 : is_device_enumeration_disabled_(false), |
| 86 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) { | 93 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) { |
| 87 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 94 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 88 | 95 |
| 89 #if BUILDFLAG(ENABLE_EXTENSIONS) | 96 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 90 #if defined(OS_CHROMEOS) | 97 #if defined(OS_CHROMEOS) |
| 98 media_access_handlers_.push_back( | |
| 99 base::MakeUnique<ChromeOSLoginMediaAccessHandler>()); | |
| 91 // Wrapper around ExtensionMediaAccessHandler used in Public Sessions. | 100 // Wrapper around ExtensionMediaAccessHandler used in Public Sessions. |
| 92 media_access_handlers_.push_back( | 101 media_access_handlers_.push_back( |
| 93 base::MakeUnique<PublicSessionMediaAccessHandler>()); | 102 base::MakeUnique<PublicSessionMediaAccessHandler>()); |
| 94 #else | 103 #else |
| 95 media_access_handlers_.push_back( | 104 media_access_handlers_.push_back( |
| 96 base::MakeUnique<ExtensionMediaAccessHandler>()); | 105 base::MakeUnique<ExtensionMediaAccessHandler>()); |
| 97 #endif | 106 #endif |
| 98 media_access_handlers_.push_back( | 107 media_access_handlers_.push_back( |
| 99 base::MakeUnique<DesktopCaptureAccessHandler>()); | 108 base::MakeUnique<DesktopCaptureAccessHandler>()); |
| 100 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 } | 167 } |
| 159 | 168 |
| 160 void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( | 169 void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( |
| 161 content::WebContents* web_contents, | 170 content::WebContents* web_contents, |
| 162 const content::MediaStreamRequest& request, | 171 const content::MediaStreamRequest& request, |
| 163 const content::MediaResponseCallback& callback, | 172 const content::MediaResponseCallback& callback, |
| 164 const extensions::Extension* extension) { | 173 const extensions::Extension* extension) { |
| 165 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 174 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 166 | 175 |
| 167 for (const auto& handler : media_access_handlers_) { | 176 for (const auto& handler : media_access_handlers_) { |
| 168 if (handler->SupportsStreamType(request.video_type, extension) || | 177 if (handler->SupportsStreamType(web_contents, request.video_type, |
| 169 handler->SupportsStreamType(request.audio_type, extension)) { | 178 extension) || |
| 179 handler->SupportsStreamType(web_contents, request.audio_type, | |
| 180 extension)) { | |
| 170 handler->HandleRequest(web_contents, request, callback, extension); | 181 handler->HandleRequest(web_contents, request, callback, extension); |
| 171 return; | 182 return; |
| 172 } | 183 } |
| 173 } | 184 } |
| 174 callback.Run(content::MediaStreamDevices(), | 185 callback.Run(content::MediaStreamDevices(), |
| 175 content::MEDIA_DEVICE_NOT_SUPPORTED, nullptr); | 186 content::MEDIA_DEVICE_NOT_SUPPORTED, nullptr); |
| 176 } | 187 } |
| 177 | 188 |
| 178 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 189 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 179 content::WebContents* web_contents, | 190 content::WebContents* web_contents, |
| 180 const GURL& security_origin, | 191 const GURL& security_origin, |
| 181 content::MediaStreamType type) { | 192 content::MediaStreamType type) { |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 183 return CheckMediaAccessPermission(web_contents, security_origin, type, | 194 return CheckMediaAccessPermission(web_contents, security_origin, type, |
| 184 nullptr); | 195 nullptr); |
| 185 } | 196 } |
| 186 | 197 |
| 187 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 198 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 188 content::WebContents* web_contents, | 199 content::WebContents* web_contents, |
| 189 const GURL& security_origin, | 200 const GURL& security_origin, |
| 190 content::MediaStreamType type, | 201 content::MediaStreamType type, |
| 191 const extensions::Extension* extension) { | 202 const extensions::Extension* extension) { |
| 192 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 203 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 193 for (const auto& handler : media_access_handlers_) { | 204 for (const auto& handler : media_access_handlers_) { |
| 194 if (handler->SupportsStreamType(type, extension)) { | 205 if (handler->SupportsStreamType(web_contents, type, extension)) { |
| 195 return handler->CheckMediaAccessPermission(web_contents, security_origin, | 206 return handler->CheckMediaAccessPermission(web_contents, security_origin, |
| 196 type, extension); | 207 type, extension); |
| 197 } | 208 } |
| 198 } | 209 } |
| 199 return false; | 210 return false; |
| 200 } | 211 } |
| 201 | 212 |
| 202 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 213 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( |
| 203 Profile* profile, | 214 Profile* profile, |
| 204 bool audio, | 215 bool audio, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 observer.OnUpdateVideoDevices(devices); | 365 observer.OnUpdateVideoDevices(devices); |
| 355 } | 366 } |
| 356 | 367 |
| 357 void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( | 368 void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( |
| 358 int render_process_id, | 369 int render_process_id, |
| 359 int render_frame_id, | 370 int render_frame_id, |
| 360 int page_request_id, | 371 int page_request_id, |
| 361 const GURL& security_origin, | 372 const GURL& security_origin, |
| 362 content::MediaStreamType stream_type, | 373 content::MediaStreamType stream_type, |
| 363 content::MediaRequestState state) { | 374 content::MediaRequestState state) { |
| 375 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 364 for (const auto& handler : media_access_handlers_) { | 376 for (const auto& handler : media_access_handlers_) { |
| 365 if (handler->SupportsStreamType(stream_type, nullptr)) { | 377 if (handler->SupportsStreamType( |
| 378 WebContentsFromIds(render_process_id, render_frame_id), stream_type, | |
| 379 nullptr)) { | |
| 366 handler->UpdateMediaRequestState(render_process_id, render_frame_id, | 380 handler->UpdateMediaRequestState(render_process_id, render_frame_id, |
| 367 page_request_id, stream_type, state); | 381 page_request_id, stream_type, state); |
| 368 break; | 382 break; |
| 369 } | 383 } |
| 370 } | 384 } |
| 371 | 385 |
| 372 #if defined(OS_CHROMEOS) | 386 #if defined(OS_CHROMEOS) |
| 373 if (IsOriginForCasting(security_origin) && IsVideoMediaType(stream_type)) { | 387 if (IsOriginForCasting(security_origin) && IsVideoMediaType(stream_type)) { |
| 374 // Notify ash that casting state has changed. | 388 // Notify ash that casting state has changed. |
| 375 if (state == content::MEDIA_REQUEST_STATE_DONE) { | 389 if (state == content::MEDIA_REQUEST_STATE_DONE) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 393 for (auto& observer : observers_) | 407 for (auto& observer : observers_) |
| 394 observer.OnCreatingAudioStream(render_process_id, render_frame_id); | 408 observer.OnCreatingAudioStream(render_process_id, render_frame_id); |
| 395 } | 409 } |
| 396 | 410 |
| 397 bool MediaCaptureDevicesDispatcher::IsInsecureCapturingInProgress( | 411 bool MediaCaptureDevicesDispatcher::IsInsecureCapturingInProgress( |
| 398 int render_process_id, | 412 int render_process_id, |
| 399 int render_frame_id) { | 413 int render_frame_id) { |
| 400 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 414 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 401 #if BUILDFLAG(ENABLE_EXTENSIONS) | 415 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 402 for (const auto& handler : media_access_handlers_) { | 416 for (const auto& handler : media_access_handlers_) { |
| 403 if (handler->SupportsStreamType(content::MEDIA_DESKTOP_VIDEO_CAPTURE, | 417 if (handler->SupportsStreamType( |
| 404 nullptr) || | 418 WebContentsFromIds(render_process_id, render_frame_id), |
| 405 handler->SupportsStreamType(content::MEDIA_TAB_VIDEO_CAPTURE, | 419 content::MEDIA_DESKTOP_VIDEO_CAPTURE, nullptr) || |
| 406 nullptr)) { | 420 handler->SupportsStreamType( |
| 421 WebContentsFromIds(render_process_id, render_frame_id), | |
| 422 content::MEDIA_TAB_VIDEO_CAPTURE, nullptr)) { | |
| 407 if (ToCaptureAccessHandlerBase(handler.get()) | 423 if (ToCaptureAccessHandlerBase(handler.get()) |
| 408 ->IsInsecureCapturingInProgress(render_process_id, | 424 ->IsInsecureCapturingInProgress(render_process_id, |
| 409 render_frame_id)) | 425 render_frame_id)) |
| 410 return true; | 426 return true; |
| 411 } | 427 } |
| 412 } | 428 } |
| 413 #endif | 429 #endif |
| 414 return false; | 430 return false; |
| 415 } | 431 } |
| 416 | 432 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 int page_request_id, | 464 int page_request_id, |
| 449 content::MediaStreamType stream_type, | 465 content::MediaStreamType stream_type, |
| 450 bool is_secure) { | 466 bool is_secure) { |
| 451 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 467 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 452 if (stream_type != content::MEDIA_TAB_VIDEO_CAPTURE && | 468 if (stream_type != content::MEDIA_TAB_VIDEO_CAPTURE && |
| 453 stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) | 469 stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) |
| 454 return; | 470 return; |
| 455 | 471 |
| 456 #if BUILDFLAG(ENABLE_EXTENSIONS) | 472 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 457 for (const auto& handler : media_access_handlers_) { | 473 for (const auto& handler : media_access_handlers_) { |
| 458 if (handler->SupportsStreamType(stream_type, nullptr)) { | 474 if (handler->SupportsStreamType( |
| 475 WebContentsFromIds(render_process_id, render_frame_id), stream_type, | |
| 476 nullptr)) { | |
| 459 ToCaptureAccessHandlerBase(handler.get()) | 477 ToCaptureAccessHandlerBase(handler.get()) |
| 460 ->UpdateCapturingLinkSecured(render_process_id, render_frame_id, | 478 ->UpdateCapturingLinkSecured(render_process_id, render_frame_id, |
| 461 page_request_id, is_secure); | 479 page_request_id, is_secure); |
| 462 break; | 480 break; |
| 463 } | 481 } |
| 464 } | 482 } |
| 465 #endif | 483 #endif |
| 466 } | 484 } |
| OLD | NEW |