OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "content/browser/renderer_host/media/media_devices_manager.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "content/common/media/media_devices.mojom.h" |
| 15 |
| 16 using ::mojom::MediaDeviceType; |
| 17 |
| 18 namespace url { |
| 19 class Origin; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 class MediaStreamManager; |
| 25 class MediaStreamUIProxy; |
| 26 |
| 27 class CONTENT_EXPORT MediaDevicesDispatcherHost |
| 28 : public ::mojom::MediaDevicesDispatcherHost { |
| 29 public: |
| 30 MediaDevicesDispatcherHost(int render_process_id, |
| 31 int routing_id, |
| 32 const std::string& device_id_salt, |
| 33 MediaStreamManager* media_stream_manager, |
| 34 bool use_fake_ui); |
| 35 ~MediaDevicesDispatcherHost() override; |
| 36 |
| 37 static void Create(int render_process_id, |
| 38 int routing_id, |
| 39 const std::string& device_id_salt, |
| 40 MediaStreamManager* media_stream_manager, |
| 41 bool use_fake_ui, |
| 42 ::mojom::MediaDevicesDispatcherHostRequest request); |
| 43 |
| 44 // ::mojom::MediaDevicesDispatcherHost implementation. |
| 45 void EnumerateDevices( |
| 46 bool request_audio_input, |
| 47 bool request_video_input, |
| 48 bool request_audio_output, |
| 49 const url::Origin& security_origin, |
| 50 const EnumerateDevicesCallback& client_callback) override; |
| 51 |
| 52 // Sets a MediaStreamUIProxy to be used in a single run of EnumerateDevices(), |
| 53 // provided that the MediaDevicesDispatcherHost was created with |use_fake_ui| |
| 54 // set to true. Subsequent runs of EnumerateDevices() use a new internally |
| 55 // generated fake MediaStreamUIProxy. |
| 56 // |fake_ui_proxy| is ignored if the MediaDevicesDispatcherHost was created |
| 57 // with |use_fake_ui|, in which case a real MediaStreamUIProxy will be used |
| 58 // instead. |
| 59 // This function is intended to be used for testing. |
| 60 void SetFakeUIProxyForTesting( |
| 61 std::unique_ptr<MediaStreamUIProxy> fake_ui_proxy); |
| 62 |
| 63 private: |
| 64 // Internal type that represents a callback that receives a |
| 65 // MediaDevicesManager::BoolDeviceTypes containing the permissions for each |
| 66 // device type. |
| 67 using AccessCheckedCallback = |
| 68 base::Callback<void(const MediaDevicesManager::BoolDeviceTypes&)>; |
| 69 |
| 70 // Currently, the same permission (MEDIA_DEVICE_AUDIO_CAPTURE) is used for |
| 71 // both audio input and output. |
| 72 // TODO(guidou): use specific permission for audio output when it becomes |
| 73 // available. See http://crbug.com/556542. |
| 74 void CheckAccess(bool check_audio, |
| 75 bool check_video_input, |
| 76 const url::Origin& security_origin, |
| 77 const AccessCheckedCallback& callback); |
| 78 |
| 79 void AudioAccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy, |
| 80 bool check_video_permission, |
| 81 const url::Origin& security_origin, |
| 82 const AccessCheckedCallback& callback, |
| 83 bool has_audio_permission); |
| 84 |
| 85 void VideoAccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy, |
| 86 bool has_audio_permission, |
| 87 const AccessCheckedCallback& callback, |
| 88 bool has_video_permission); |
| 89 |
| 90 void DoEnumerateDevices( |
| 91 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 92 const url::Origin& security_origin, |
| 93 const EnumerateDevicesCallback& client_callback, |
| 94 const MediaDevicesManager::BoolDeviceTypes& permissions); |
| 95 |
| 96 void DevicesEnumerated( |
| 97 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 98 const url::Origin& security_origin, |
| 99 const EnumerateDevicesCallback& client_callback, |
| 100 const MediaDevicesManager::BoolDeviceTypes& has_permissions, |
| 101 const MediaDeviceEnumeration& enumeration); |
| 102 |
| 103 std::unique_ptr<MediaStreamUIProxy> GetUIProxy(); |
| 104 |
| 105 int render_process_id_; |
| 106 int routing_id_; |
| 107 std::string device_id_salt_; |
| 108 std::string group_id_salt_; |
| 109 MediaStreamManager* media_stream_manager_; |
| 110 bool use_fake_ui_; |
| 111 std::unique_ptr<MediaStreamUIProxy> fake_ui_proxy_; |
| 112 |
| 113 base::WeakPtrFactory<MediaDevicesDispatcherHost> weak_factory_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(MediaDevicesDispatcherHost); |
| 116 }; |
| 117 |
| 118 } // namespace content |
| 119 |
| 120 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ |
OLD | NEW |