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 "content/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 device_info.device.name.clear(); | 161 device_info.device.name.clear(); |
162 } | 162 } |
163 | 163 |
164 bool CalledOnIOThread() { | 164 bool CalledOnIOThread() { |
165 // Check if this function call is on the IO thread, except for unittests where | 165 // Check if this function call is on the IO thread, except for unittests where |
166 // an IO thread might not have been created. | 166 // an IO thread might not have been created. |
167 return BrowserThread::CurrentlyOn(BrowserThread::IO) || | 167 return BrowserThread::CurrentlyOn(BrowserThread::IO) || |
168 !BrowserThread::IsMessageLoopValid(BrowserThread::IO); | 168 !BrowserThread::IsMessageLoopValid(BrowserThread::IO); |
169 } | 169 } |
170 | 170 |
171 GURL ConvertToGURL(const url::Origin& origin) { | |
172 return origin.unique() ? GURL() : GURL(origin.Serialize()); | |
173 } | |
174 | |
175 bool GetDeviceIDFromHMAC(const std::string& salt, | 171 bool GetDeviceIDFromHMAC(const std::string& salt, |
176 const url::Origin& security_origin, | 172 const url::Origin& security_origin, |
177 const std::string& hmac_device_id, | 173 const std::string& hmac_device_id, |
178 const MediaDeviceInfoArray& devices, | 174 const MediaDeviceInfoArray& devices, |
179 std::string* device_id) { | 175 std::string* device_id) { |
180 // The source_id can be empty if the constraint is set but empty. | 176 // The source_id can be empty if the constraint is set but empty. |
181 if (hmac_device_id.empty()) | 177 if (hmac_device_id.empty()) |
182 return false; | 178 return false; |
183 | 179 |
184 for (const auto& device_info : devices) { | 180 for (const auto& device_info : devices) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 296 |
301 // Creates a MediaStreamRequest object that is used by this request when UI | 297 // Creates a MediaStreamRequest object that is used by this request when UI |
302 // is asked for permission and device selection. | 298 // is asked for permission and device selection. |
303 void CreateUIRequest(const std::string& requested_audio_device_id, | 299 void CreateUIRequest(const std::string& requested_audio_device_id, |
304 const std::string& requested_video_device_id) { | 300 const std::string& requested_video_device_id) { |
305 DCHECK(!ui_request_); | 301 DCHECK(!ui_request_); |
306 target_process_id_ = requesting_process_id; | 302 target_process_id_ = requesting_process_id; |
307 target_frame_id_ = requesting_frame_id; | 303 target_frame_id_ = requesting_frame_id; |
308 ui_request_.reset(new MediaStreamRequest( | 304 ui_request_.reset(new MediaStreamRequest( |
309 requesting_process_id, requesting_frame_id, page_request_id, | 305 requesting_process_id, requesting_frame_id, page_request_id, |
310 ConvertToGURL(security_origin), user_gesture, request_type, | 306 security_origin.GetURL(), user_gesture, request_type, |
311 requested_audio_device_id, requested_video_device_id, audio_type_, | 307 requested_audio_device_id, requested_video_device_id, audio_type_, |
312 video_type_)); | 308 video_type_)); |
313 } | 309 } |
314 | 310 |
315 // Creates a tab capture specific MediaStreamRequest object that is used by | 311 // Creates a tab capture specific MediaStreamRequest object that is used by |
316 // this request when UI is asked for permission and device selection. | 312 // this request when UI is asked for permission and device selection. |
317 void CreateTabCaptureUIRequest(int target_render_process_id, | 313 void CreateTabCaptureUIRequest(int target_render_process_id, |
318 int target_render_frame_id) { | 314 int target_render_frame_id) { |
319 DCHECK(!ui_request_); | 315 DCHECK(!ui_request_); |
320 target_process_id_ = target_render_process_id; | 316 target_process_id_ = target_render_process_id; |
321 target_frame_id_ = target_render_frame_id; | 317 target_frame_id_ = target_render_frame_id; |
322 ui_request_.reset(new MediaStreamRequest( | 318 ui_request_.reset(new MediaStreamRequest( |
323 target_render_process_id, target_render_frame_id, page_request_id, | 319 target_render_process_id, target_render_frame_id, page_request_id, |
324 ConvertToGURL(security_origin), user_gesture, request_type, "", "", | 320 security_origin.GetURL(), user_gesture, request_type, "", "", |
325 audio_type_, video_type_)); | 321 audio_type_, video_type_)); |
326 } | 322 } |
327 | 323 |
328 bool HasUIRequest() const { return ui_request_.get() != nullptr; } | 324 bool HasUIRequest() const { return ui_request_.get() != nullptr; } |
329 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { | 325 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { |
330 return std::move(ui_request_); | 326 return std::move(ui_request_); |
331 } | 327 } |
332 | 328 |
333 // Update the request state and notify observers. | 329 // Update the request state and notify observers. |
334 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { | 330 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { |
335 if (stream_type == NUM_MEDIA_TYPES) { | 331 if (stream_type == NUM_MEDIA_TYPES) { |
336 for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { | 332 for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { |
337 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); | 333 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); |
338 state_[stream_type] = new_state; | 334 state_[stream_type] = new_state; |
339 } | 335 } |
340 } else { | 336 } else { |
341 state_[stream_type] = new_state; | 337 state_[stream_type] = new_state; |
342 } | 338 } |
343 | 339 |
344 MediaObserver* media_observer = | 340 MediaObserver* media_observer = |
345 GetContentClient()->browser()->GetMediaObserver(); | 341 GetContentClient()->browser()->GetMediaObserver(); |
346 if (!media_observer) | 342 if (!media_observer) |
347 return; | 343 return; |
348 | 344 |
349 media_observer->OnMediaRequestStateChanged( | 345 media_observer->OnMediaRequestStateChanged( |
350 target_process_id_, target_frame_id_, page_request_id, | 346 target_process_id_, target_frame_id_, page_request_id, |
351 ConvertToGURL(security_origin), stream_type, new_state); | 347 security_origin.GetURL(), stream_type, new_state); |
352 } | 348 } |
353 | 349 |
354 MediaRequestState state(MediaStreamType stream_type) const { | 350 MediaRequestState state(MediaStreamType stream_type) const { |
355 return state_[stream_type]; | 351 return state_[stream_type]; |
356 } | 352 } |
357 | 353 |
358 void SetCapturingLinkSecured(bool is_secure) { | 354 void SetCapturingLinkSecured(bool is_secure) { |
359 MediaObserver* media_observer = | 355 MediaObserver* media_observer = |
360 GetContentClient()->browser()->GetMediaObserver(); | 356 GetContentClient()->browser()->GetMediaObserver(); |
361 if (!media_observer) | 357 if (!media_observer) |
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 DCHECK(!raw_unique_id.empty()); | 1953 DCHECK(!raw_unique_id.empty()); |
1958 std::string guid_from_raw_device_id = | 1954 std::string guid_from_raw_device_id = |
1959 GetHMACForMediaDeviceID(salt, security_origin, raw_unique_id); | 1955 GetHMACForMediaDeviceID(salt, security_origin, raw_unique_id); |
1960 return guid_from_raw_device_id == device_guid; | 1956 return guid_from_raw_device_id == device_guid; |
1961 } | 1957 } |
1962 | 1958 |
1963 // static | 1959 // static |
1964 bool MediaStreamManager::IsOriginAllowed(int render_process_id, | 1960 bool MediaStreamManager::IsOriginAllowed(int render_process_id, |
1965 const url::Origin& origin) { | 1961 const url::Origin& origin) { |
1966 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( | 1962 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( |
1967 render_process_id, ConvertToGURL(origin))) { | 1963 render_process_id, origin.GetURL())) { |
1968 LOG(ERROR) << "MSM: Renderer requested a URL it's not allowed to use."; | 1964 LOG(ERROR) << "MSM: Renderer requested a URL it's not allowed to use."; |
1969 return false; | 1965 return false; |
1970 } | 1966 } |
1971 | 1967 |
1972 return true; | 1968 return true; |
1973 } | 1969 } |
1974 | 1970 |
1975 void MediaStreamManager::SetCapturingLinkSecured(int render_process_id, | 1971 void MediaStreamManager::SetCapturingLinkSecured(int render_process_id, |
1976 int session_id, | 1972 int session_id, |
1977 content::MediaStreamType type, | 1973 content::MediaStreamType type, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 request->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && | 2025 request->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && |
2030 (request->audio_type() == stream_type || | 2026 (request->audio_type() == stream_type || |
2031 request->video_type() == stream_type)) { | 2027 request->video_type() == stream_type)) { |
2032 ProcessEnumerationRequest(labeled_request.first, request, stream_type, | 2028 ProcessEnumerationRequest(labeled_request.first, request, stream_type, |
2033 device_infos); | 2029 device_infos); |
2034 } | 2030 } |
2035 } | 2031 } |
2036 } | 2032 } |
2037 | 2033 |
2038 } // namespace content | 2034 } // namespace content |
OLD | NEW |