| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/media_access_handler.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 10 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 |
| 14 // static |
| 15 void MediaAccessHandler::CheckDevicesAndRunCallback( |
| 16 content::WebContents* web_contents, |
| 17 const content::MediaStreamRequest& request, |
| 18 const content::MediaResponseCallback& callback, |
| 19 bool audio_allowed, |
| 20 bool video_allowed) { |
| 21 // TODO(vrk): This code is largely duplicated in |
| 22 // MediaStreamDevicesController::GetDevices(). Move this code into a shared |
| 23 // method between the two classes. |
| 24 bool get_default_audio_device = audio_allowed; |
| 25 bool get_default_video_device = video_allowed; |
| 26 |
| 27 content::MediaStreamDevices devices; |
| 28 |
| 29 // Set an initial error result. If neither audio or video is allowed, we'll |
| 30 // never try to get any device below but will just create |ui| and return an |
| 31 // empty list with "invalid state" result. If at least one is allowed, we'll |
| 32 // try to get device(s), and if failure, we want to return "no hardware" |
| 33 // result. |
| 34 // TODO(grunell): The invalid state result should be changed to a new denied |
| 35 // result + a dcheck to ensure at least one of audio or video types is |
| 36 // capture. |
| 37 content::MediaStreamRequestResult result = |
| 38 (audio_allowed || video_allowed) ? content::MEDIA_DEVICE_NO_HARDWARE |
| 39 : content::MEDIA_DEVICE_INVALID_STATE; |
| 40 |
| 41 // Get the exact audio or video device if an id is specified. |
| 42 // We only set any error result here and before running the callback change |
| 43 // it to OK if we have any device. |
| 44 if (audio_allowed && !request.requested_audio_device_id.empty()) { |
| 45 const content::MediaStreamDevice* audio_device = |
| 46 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedAudioDevice( |
| 47 request.requested_audio_device_id); |
| 48 if (audio_device) { |
| 49 devices.push_back(*audio_device); |
| 50 get_default_audio_device = false; |
| 51 } |
| 52 } |
| 53 if (video_allowed && !request.requested_video_device_id.empty()) { |
| 54 const content::MediaStreamDevice* video_device = |
| 55 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice( |
| 56 request.requested_video_device_id); |
| 57 if (video_device) { |
| 58 devices.push_back(*video_device); |
| 59 get_default_video_device = false; |
| 60 } |
| 61 } |
| 62 |
| 63 Profile* profile = |
| 64 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 65 |
| 66 // If either or both audio and video devices were requested but not |
| 67 // specified by id, get the default devices. |
| 68 if (get_default_audio_device || get_default_video_device) { |
| 69 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile( |
| 70 profile, get_default_audio_device, get_default_video_device, &devices); |
| 71 } |
| 72 |
| 73 std::unique_ptr<content::MediaStreamUI> ui; |
| 74 if (!devices.empty()) { |
| 75 result = content::MEDIA_DEVICE_OK; |
| 76 ui = MediaCaptureDevicesDispatcher::GetInstance() |
| 77 ->GetMediaStreamCaptureIndicator() |
| 78 ->RegisterMediaStream(web_contents, devices); |
| 79 } |
| 80 |
| 81 callback.Run(devices, result, std::move(ui)); |
| 82 } |
| OLD | NEW |