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 // MediaStreamManager is used to open/enumerate media capture devices (video | 5 // MediaStreamManager is used to open/enumerate media capture devices (video |
6 // supported now). Call flow: | 6 // supported now). Call flow: |
7 // 1. GenerateStream is called when a render process wants to use a capture | 7 // 1. GenerateStream is called when a render process wants to use a capture |
8 // device. | 8 // device. |
9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to | 9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to |
10 // use devices and for which device to use. | 10 // use devices and for which device to use. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const url::Origin& security_origin, | 112 const url::Origin& security_origin, |
113 const MediaRequestResponseCallback& callback); | 113 const MediaRequestResponseCallback& callback); |
114 | 114 |
115 // GenerateStream opens new media devices according to |components|. It | 115 // GenerateStream opens new media devices according to |components|. It |
116 // creates a new request which is identified by a unique string that's | 116 // creates a new request which is identified by a unique string that's |
117 // returned to the caller. |render_process_id| and |render_frame_id| are used | 117 // returned to the caller. |render_process_id| and |render_frame_id| are used |
118 // to determine where the infobar will appear to the user. | 118 // to determine where the infobar will appear to the user. |
119 void GenerateStream(MediaStreamRequester* requester, | 119 void GenerateStream(MediaStreamRequester* requester, |
120 int render_process_id, | 120 int render_process_id, |
121 int render_frame_id, | 121 int render_frame_id, |
122 const ResourceContext::SaltCallback& sc, | 122 const std::string& salt, |
123 int page_request_id, | 123 int page_request_id, |
124 const StreamControls& controls, | 124 const StreamControls& controls, |
125 const url::Origin& security_origin, | 125 const url::Origin& security_origin, |
126 bool user_gesture); | 126 bool user_gesture); |
127 | 127 |
128 void CancelRequest(int render_process_id, | 128 void CancelRequest(int render_process_id, |
129 int render_frame_id, | 129 int render_frame_id, |
130 int page_request_id); | 130 int page_request_id); |
131 | 131 |
132 // Cancel an open request identified by |label|. | 132 // Cancel an open request identified by |label|. |
(...skipping 11 matching lines...) Expand all Loading... |
144 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE | 144 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE |
145 // or MEDIA_DEVICE_VIDEO_CAPTURE. | 145 // or MEDIA_DEVICE_VIDEO_CAPTURE. |
146 // The request is identified using the string returned to the caller. | 146 // The request is identified using the string returned to the caller. |
147 // When the |requester| is NULL, MediaStreamManager will enumerate both audio | 147 // When the |requester| is NULL, MediaStreamManager will enumerate both audio |
148 // and video devices and also start monitoring device changes, such as | 148 // and video devices and also start monitoring device changes, such as |
149 // plug/unplug. The new device lists will be delivered via media observer to | 149 // plug/unplug. The new device lists will be delivered via media observer to |
150 // MediaCaptureDevicesDispatcher. | 150 // MediaCaptureDevicesDispatcher. |
151 virtual std::string EnumerateDevices(MediaStreamRequester* requester, | 151 virtual std::string EnumerateDevices(MediaStreamRequester* requester, |
152 int render_process_id, | 152 int render_process_id, |
153 int render_frame_id, | 153 int render_frame_id, |
154 const ResourceContext::SaltCallback& sc, | 154 const std::string& salt, |
155 int page_request_id, | 155 int page_request_id, |
156 MediaStreamType type, | 156 MediaStreamType type, |
157 const url::Origin& security_origin); | 157 const url::Origin& security_origin); |
158 | 158 |
159 // Open a device identified by |device_id|. |type| must be either | 159 // Open a device identified by |device_id|. |type| must be either |
160 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 160 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
161 // The request is identified using string returned to the caller. | 161 // The request is identified using string returned to the caller. |
162 void OpenDevice(MediaStreamRequester* requester, | 162 void OpenDevice(MediaStreamRequester* requester, |
163 int render_process_id, | 163 int render_process_id, |
164 int render_frame_id, | 164 int render_frame_id, |
165 const ResourceContext::SaltCallback& sc, | 165 const std::string& salt, |
166 int page_request_id, | 166 int page_request_id, |
167 const std::string& device_id, | 167 const std::string& device_id, |
168 MediaStreamType type, | 168 MediaStreamType type, |
169 const url::Origin& security_origin); | 169 const url::Origin& security_origin); |
170 | 170 |
171 // Finds and returns the device id corresponding to the given | 171 // Finds and returns the device id corresponding to the given |
172 // |source_id|. Returns true if there was a raw device id that matched the | 172 // |source_id|. Returns true if there was a raw device id that matched the |
173 // given |source_id|, false if nothing matched it. | 173 // given |source_id|, false if nothing matched it. |
174 bool TranslateSourceIdToDeviceId(MediaStreamType stream_type, | 174 bool TranslateSourceIdToDeviceId(MediaStreamType stream_type, |
175 const ResourceContext::SaltCallback& rc, | 175 const std::string& salt, |
176 const url::Origin& security_origin, | 176 const url::Origin& security_origin, |
177 const std::string& source_id, | 177 const std::string& source_id, |
178 std::string* device_id) const; | 178 std::string* device_id) const; |
179 | 179 |
180 // Find |device_id| in the list of |requests_|, and returns its session id, | 180 // Find |device_id| in the list of |requests_|, and returns its session id, |
181 // or StreamDeviceInfo::kNoId if not found. | 181 // or StreamDeviceInfo::kNoId if not found. |
182 int VideoDeviceIdToSessionId(const std::string& device_id) const; | 182 int VideoDeviceIdToSessionId(const std::string& device_id) const; |
183 | 183 |
184 // Called by UI to make sure the device monitor is started so that UI receive | 184 // Called by UI to make sure the device monitor is started so that UI receive |
185 // notifications about device changes. | 185 // notifications about device changes. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // It is an error to try to subscribe a |subscriber| that is already | 235 // It is an error to try to subscribe a |subscriber| that is already |
236 // subscribed or to cancel the subscription of a |subscriber| that is not | 236 // subscribed or to cancel the subscription of a |subscriber| that is not |
237 // subscribed. Also, subscribers must make sure to invoke | 237 // subscribed. Also, subscribers must make sure to invoke |
238 // CancelDeviceChangeNotifications() before destruction. Otherwise, dangling | 238 // CancelDeviceChangeNotifications() before destruction. Otherwise, dangling |
239 // pointers and use-after-destruction problems will occur. | 239 // pointers and use-after-destruction problems will occur. |
240 void SubscribeToDeviceChangeNotifications(MediaStreamRequester* subscriber); | 240 void SubscribeToDeviceChangeNotifications(MediaStreamRequester* subscriber); |
241 void CancelDeviceChangeNotifications(MediaStreamRequester* subscriber); | 241 void CancelDeviceChangeNotifications(MediaStreamRequester* subscriber); |
242 | 242 |
243 // Generates a hash of a device's unique ID usable by one | 243 // Generates a hash of a device's unique ID usable by one |
244 // particular security origin. | 244 // particular security origin. |
245 static std::string GetHMACForMediaDeviceID( | 245 static std::string GetHMACForMediaDeviceID(const std::string& salt, |
246 const ResourceContext::SaltCallback& sc, | 246 const url::Origin& security_origin, |
247 const url::Origin& security_origin, | 247 const std::string& raw_unique_id); |
248 const std::string& raw_unique_id); | |
249 | 248 |
250 // Convenience method to check if |device_guid| is an HMAC of | 249 // Convenience method to check if |device_guid| is an HMAC of |
251 // |raw_device_id| for |security_origin|. | 250 // |raw_device_id| for |security_origin|. |
252 static bool DoesMediaDeviceIDMatchHMAC( | 251 static bool DoesMediaDeviceIDMatchHMAC(const std::string& salt, |
253 const ResourceContext::SaltCallback& sc, | 252 const url::Origin& security_origin, |
254 const url::Origin& security_origin, | 253 const std::string& device_guid, |
255 const std::string& device_guid, | 254 const std::string& raw_unique_id); |
256 const std::string& raw_unique_id); | |
257 | 255 |
258 // Returns true if the renderer process identified with |render_process_id| | 256 // Returns true if the renderer process identified with |render_process_id| |
259 // is allowed to access |origin|. | 257 // is allowed to access |origin|. |
260 static bool IsOriginAllowed(int render_process_id, const url::Origin& origin); | 258 static bool IsOriginAllowed(int render_process_id, const url::Origin& origin); |
261 | 259 |
262 // Set whether the capturing is secure for the capturing session with given | 260 // Set whether the capturing is secure for the capturing session with given |
263 // |session_id|, |render_process_id|, and the MediaStreamType |type|. | 261 // |session_id|, |render_process_id|, and the MediaStreamType |type|. |
264 void SetCapturingLinkSecured(int render_process_id, | 262 void SetCapturingLinkSecured(int render_process_id, |
265 int session_id, | 263 int session_id, |
266 content::MediaStreamType type, | 264 content::MediaStreamType type, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 void StartMonitoringOnUIThread(); | 396 void StartMonitoringOnUIThread(); |
399 #endif | 397 #endif |
400 | 398 |
401 // Picks a device ID from a list of required and alternate device IDs, | 399 // Picks a device ID from a list of required and alternate device IDs, |
402 // presented as part of a TrackControls structure. | 400 // presented as part of a TrackControls structure. |
403 // Either the required device ID is picked (if present), or the first | 401 // Either the required device ID is picked (if present), or the first |
404 // valid alternate device ID. | 402 // valid alternate device ID. |
405 // Returns false if the required device ID is present and invalid. | 403 // Returns false if the required device ID is present and invalid. |
406 // Otherwise, if no valid device is found, device_id is unchanged. | 404 // Otherwise, if no valid device is found, device_id is unchanged. |
407 bool PickDeviceId(MediaStreamType type, | 405 bool PickDeviceId(MediaStreamType type, |
408 const ResourceContext::SaltCallback& salt_callback, | 406 const std::string& salt, |
409 const url::Origin& security_origin, | 407 const url::Origin& security_origin, |
410 const TrackControls& controls, | 408 const TrackControls& controls, |
411 std::string* device_id) const; | 409 std::string* device_id) const; |
412 | 410 |
413 // Finds the requested device id from request. The requested device type | 411 // Finds the requested device id from request. The requested device type |
414 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 412 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
415 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, | 413 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, |
416 MediaStreamType type, | 414 MediaStreamType type, |
417 std::string* device_id) const; | 415 std::string* device_id) const; |
418 | 416 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 467 |
470 // Objects subscribed to changes in the set of media devices. | 468 // Objects subscribed to changes in the set of media devices. |
471 std::vector<MediaStreamRequester*> device_change_subscribers_; | 469 std::vector<MediaStreamRequester*> device_change_subscribers_; |
472 | 470 |
473 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 471 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
474 }; | 472 }; |
475 | 473 |
476 } // namespace content | 474 } // namespace content |
477 | 475 |
478 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 476 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
OLD | NEW |