| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "content/browser/media/media_devices_permission_checker.h" | 13 #include "content/browser/media/media_devices_permission_checker.h" |
| 14 #include "content/browser/renderer_host/media/media_devices_manager.h" | 14 #include "content/browser/renderer_host/media/media_devices_manager.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/common/media/media_devices.mojom.h" | 16 #include "content/common/media/media_devices.mojom.h" |
| 17 #include "media/capture/video/video_capture_device_descriptor.h" | 17 #include "media/capture/video/video_capture_device_descriptor.h" |
| 18 #include "url/origin.h" |
| 18 | 19 |
| 19 using ::mojom::MediaDeviceType; | 20 using ::mojom::MediaDeviceType; |
| 20 | 21 |
| 21 namespace service_manager { | 22 namespace service_manager { |
| 22 struct BindSourceInfo; | 23 struct BindSourceInfo; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace url { | |
| 26 class Origin; | |
| 27 } | |
| 28 | |
| 29 namespace content { | 26 namespace content { |
| 30 | 27 |
| 31 class MediaStreamManager; | 28 class MediaStreamManager; |
| 32 | 29 |
| 33 class CONTENT_EXPORT MediaDevicesDispatcherHost | 30 class CONTENT_EXPORT MediaDevicesDispatcherHost |
| 34 : public ::mojom::MediaDevicesDispatcherHost, | 31 : public ::mojom::MediaDevicesDispatcherHost, |
| 35 public MediaDeviceChangeSubscriber { | 32 public MediaDeviceChangeSubscriber { |
| 36 public: | 33 public: |
| 37 MediaDevicesDispatcherHost(int render_process_id, | 34 MediaDevicesDispatcherHost(int render_process_id, |
| 38 int render_frame_id, | 35 int render_frame_id, |
| 39 const std::string& device_id_salt, | 36 const std::string& device_id_salt, |
| 40 MediaStreamManager* media_stream_manager); | 37 MediaStreamManager* media_stream_manager); |
| 41 ~MediaDevicesDispatcherHost() override; | 38 ~MediaDevicesDispatcherHost() override; |
| 42 | 39 |
| 43 static void Create(int render_process_id, | 40 static void Create(int render_process_id, |
| 44 int render_frame_id, | 41 int render_frame_id, |
| 45 const std::string& device_id_salt, | 42 const std::string& device_id_salt, |
| 46 MediaStreamManager* media_stream_manager, | 43 MediaStreamManager* media_stream_manager, |
| 47 const service_manager::BindSourceInfo& source_info, | 44 const service_manager::BindSourceInfo& source_info, |
| 48 ::mojom::MediaDevicesDispatcherHostRequest request); | 45 ::mojom::MediaDevicesDispatcherHostRequest request); |
| 49 | 46 |
| 50 // ::mojom::MediaDevicesDispatcherHost implementation. | 47 // ::mojom::MediaDevicesDispatcherHost implementation. |
| 51 void EnumerateDevices(bool request_audio_input, | 48 void EnumerateDevices(bool request_audio_input, |
| 52 bool request_video_input, | 49 bool request_video_input, |
| 53 bool request_audio_output, | 50 bool request_audio_output, |
| 54 const url::Origin& security_origin, | |
| 55 EnumerateDevicesCallback client_callback) override; | 51 EnumerateDevicesCallback client_callback) override; |
| 56 void GetVideoInputCapabilities( | 52 void GetVideoInputCapabilities( |
| 57 const url::Origin& security_origin, | |
| 58 GetVideoInputCapabilitiesCallback client_callback) override; | 53 GetVideoInputCapabilitiesCallback client_callback) override; |
| 59 void SubscribeDeviceChangeNotifications( | 54 void SubscribeDeviceChangeNotifications(MediaDeviceType type, |
| 60 MediaDeviceType type, | 55 uint32_t subscription_id) override; |
| 61 uint32_t subscription_id, | |
| 62 const url::Origin& security_origin) override; | |
| 63 void UnsubscribeDeviceChangeNotifications(MediaDeviceType type, | 56 void UnsubscribeDeviceChangeNotifications(MediaDeviceType type, |
| 64 uint32_t subscription_id) override; | 57 uint32_t subscription_id) override; |
| 65 | 58 |
| 66 // MediaDeviceChangeSubscriber implementation. | 59 // MediaDeviceChangeSubscriber implementation. |
| 67 void OnDevicesChanged(MediaDeviceType type, | 60 void OnDevicesChanged(MediaDeviceType type, |
| 68 const MediaDeviceInfoArray& device_infos) override; | 61 const MediaDeviceInfoArray& device_infos) override; |
| 69 | 62 |
| 70 void SetPermissionChecker( | 63 void SetPermissionChecker( |
| 71 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker); | 64 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker); |
| 72 | 65 |
| 73 void SetDeviceChangeListenerForTesting( | 66 void SetDeviceChangeListenerForTesting( |
| 74 ::mojom::MediaDevicesListenerPtr listener); | 67 ::mojom::MediaDevicesListenerPtr listener); |
| 75 | 68 |
| 69 void SetSecurityOriginForTesting(const url::Origin& origin); |
| 70 |
| 76 private: | 71 private: |
| 72 void CheckPermissionsForEnumerateDevices( |
| 73 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 74 EnumerateDevicesCallback client_callback, |
| 75 const url::Origin& security_origin); |
| 76 |
| 77 void DoEnumerateDevices( | 77 void DoEnumerateDevices( |
| 78 const MediaDevicesManager::BoolDeviceTypes& requested_types, | 78 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 79 EnumerateDevicesCallback client_callback, |
| 79 const url::Origin& security_origin, | 80 const url::Origin& security_origin, |
| 80 EnumerateDevicesCallback client_callback, | 81 const MediaDevicesManager::BoolDeviceTypes& has_permissions); |
| 81 const MediaDevicesManager::BoolDeviceTypes& permissions); | |
| 82 | 82 |
| 83 void DevicesEnumerated( | 83 void DevicesEnumerated( |
| 84 const MediaDevicesManager::BoolDeviceTypes& requested_types, | 84 const MediaDevicesManager::BoolDeviceTypes& requested_types, |
| 85 EnumerateDevicesCallback client_callback, |
| 85 const url::Origin& security_origin, | 86 const url::Origin& security_origin, |
| 86 EnumerateDevicesCallback client_callback, | |
| 87 const MediaDevicesManager::BoolDeviceTypes& has_permissions, | 87 const MediaDevicesManager::BoolDeviceTypes& has_permissions, |
| 88 const MediaDeviceEnumeration& enumeration); | 88 const MediaDeviceEnumeration& enumeration); |
| 89 | 89 |
| 90 void GetDefaultVideoInputDeviceID( |
| 91 GetVideoInputCapabilitiesCallback client_callback, |
| 92 const url::Origin& security_origin); |
| 93 |
| 90 void GotDefaultVideoInputDeviceID( | 94 void GotDefaultVideoInputDeviceID( |
| 95 GetVideoInputCapabilitiesCallback client_callback, |
| 91 const url::Origin& security_origin, | 96 const url::Origin& security_origin, |
| 92 GetVideoInputCapabilitiesCallback client_callback, | |
| 93 const std::string& default_device_id); | 97 const std::string& default_device_id); |
| 94 | 98 |
| 95 void FinalizeGetVideoInputCapabilities( | 99 void FinalizeGetVideoInputCapabilities( |
| 100 GetVideoInputCapabilitiesCallback client_callback, |
| 96 const url::Origin& security_origin, | 101 const url::Origin& security_origin, |
| 97 GetVideoInputCapabilitiesCallback client_callback, | |
| 98 const std::string& default_device_id, | 102 const std::string& default_device_id, |
| 99 const media::VideoCaptureDeviceDescriptors& device_descriptors); | 103 const media::VideoCaptureDeviceDescriptors& device_descriptors); |
| 100 | 104 |
| 101 // Returns the currently supported video formats for the given |device_id|. | 105 // Returns the currently supported video formats for the given |device_id|. |
| 102 media::VideoCaptureFormats GetVideoInputFormats(const std::string& device_id); | 106 media::VideoCaptureFormats GetVideoInputFormats(const std::string& device_id); |
| 103 | 107 |
| 104 struct SubscriptionInfo; | 108 void NotifyDeviceChangeOnUIThread(const std::vector<uint32_t>& subscriptions, |
| 105 void NotifyDeviceChangeOnUIThread( | 109 MediaDeviceType type, |
| 106 const std::vector<SubscriptionInfo>& subscriptions, | 110 const MediaDeviceInfoArray& device_infos); |
| 107 MediaDeviceType type, | |
| 108 const MediaDeviceInfoArray& device_infos); | |
| 109 | 111 |
| 110 // The following const fields can be accessed on any thread. | 112 // The following const fields can be accessed on any thread. |
| 111 const int render_process_id_; | 113 const int render_process_id_; |
| 112 const int render_frame_id_; | 114 const int render_frame_id_; |
| 113 const std::string device_id_salt_; | 115 const std::string device_id_salt_; |
| 114 const std::string group_id_salt_; | 116 const std::string group_id_salt_; |
| 115 | 117 |
| 116 // The following fields can only be accessed on the IO thread. | 118 // The following fields can only be accessed on the IO thread. |
| 117 MediaStreamManager* media_stream_manager_; | 119 MediaStreamManager* media_stream_manager_; |
| 118 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; | 120 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; |
| 119 std::vector<SubscriptionInfo> | 121 std::vector<uint32_t> device_change_subscriptions_[NUM_MEDIA_DEVICE_TYPES]; |
| 120 device_change_subscriptions_[NUM_MEDIA_DEVICE_TYPES]; | |
| 121 | 122 |
| 122 // This field can only be accessed on the UI thread. | 123 // This field can only be accessed on the UI thread. |
| 123 ::mojom::MediaDevicesListenerPtr device_change_listener_; | 124 ::mojom::MediaDevicesListenerPtr device_change_listener_; |
| 125 url::Origin security_origin_for_testing_; |
| 124 | 126 |
| 125 base::WeakPtrFactory<MediaDevicesDispatcherHost> weak_factory_; | 127 base::WeakPtrFactory<MediaDevicesDispatcherHost> weak_factory_; |
| 126 | 128 |
| 127 DISALLOW_COPY_AND_ASSIGN(MediaDevicesDispatcherHost); | 129 DISALLOW_COPY_AND_ASSIGN(MediaDevicesDispatcherHost); |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 } // namespace content | 132 } // namespace content |
| 131 | 133 |
| 132 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ | 134 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_DEVICES_DISPATCHER_HOST_H_ |
| OLD | NEW |