Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 795703003: Don't auto allow access to media devices unless a the security origin of the requester is the same … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win compile. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 MediaStreamType video_type() const { return video_type_; } 260 MediaStreamType video_type() const { return video_type_; }
261 261
262 // Creates a MediaStreamRequest object that is used by this request when UI 262 // Creates a MediaStreamRequest object that is used by this request when UI
263 // is asked for permission and device selection. 263 // is asked for permission and device selection.
264 void CreateUIRequest(const std::string& requested_audio_device_id, 264 void CreateUIRequest(const std::string& requested_audio_device_id,
265 const std::string& requested_video_device_id) { 265 const std::string& requested_video_device_id) {
266 DCHECK(!ui_request_); 266 DCHECK(!ui_request_);
267 ui_request_.reset(new MediaStreamRequest(requesting_process_id, 267 ui_request_.reset(new MediaStreamRequest(requesting_process_id,
268 requesting_frame_id, 268 requesting_frame_id,
269 page_request_id, 269 page_request_id,
270 "",
270 security_origin, 271 security_origin,
271 user_gesture, 272 user_gesture,
272 request_type, 273 request_type,
273 requested_audio_device_id, 274 requested_audio_device_id,
274 requested_video_device_id, 275 requested_video_device_id,
275 audio_type_, 276 audio_type_,
276 video_type_)); 277 video_type_));
277 } 278 }
278 279
279 // Creates a tab capture specific MediaStreamRequest object that is used by 280 // Creates a tab capture specific MediaStreamRequest object that is used by
280 // this request when UI is asked for permission and device selection. 281 // this request when UI is asked for permission and device selection.
281 void CreateTabCaptureUIRequest(int target_render_process_id, 282 void CreateTabCaptureUIRequest(int target_render_process_id,
282 int target_render_frame_id, 283 int target_render_frame_id,
283 const std::string& tab_capture_id) { 284 const std::string& tab_capture_id) {
284 DCHECK(!ui_request_); 285 DCHECK(!ui_request_);
285 ui_request_.reset(new MediaStreamRequest(target_render_process_id, 286 ui_request_.reset(new MediaStreamRequest(target_render_process_id,
286 target_render_frame_id, 287 target_render_frame_id,
287 page_request_id, 288 page_request_id,
289 tab_capture_id,
288 security_origin, 290 security_origin,
289 user_gesture, 291 user_gesture,
290 request_type, 292 request_type,
291 "", 293 "",
292 "", 294 "",
293 audio_type_, 295 audio_type_,
294 video_type_)); 296 video_type_));
295 ui_request_->tab_capture_device_id = tab_capture_id;
296 } 297 }
297 298
298 const MediaStreamRequest* UIRequest() const { return ui_request_.get(); } 299 bool HasUIRequest() const { return ui_request_.get() != NULL; }
tommi (sloooow) - chröme 2015/01/23 10:44:04 nit: nullptr
perkj_chrome 2015/01/26 13:43:39 Done.
300 scoped_ptr<MediaStreamRequest> GetUIRequest() { return ui_request_.Pass(); }
tommi (sloooow) - chröme 2015/01/23 10:44:04 Since this transfers ownership I'd like to give it
perkj_chrome 2015/01/26 13:43:39 Done.
299 301
300 // Update the request state and notify observers. 302 // Update the request state and notify observers.
301 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { 303 void SetState(MediaStreamType stream_type, MediaRequestState new_state) {
302 if (stream_type == NUM_MEDIA_TYPES) { 304 if (stream_type == NUM_MEDIA_TYPES) {
303 for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { 305 for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) {
304 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); 306 const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
305 state_[stream_type] = new_state; 307 state_[stream_type] = new_state;
306 } 308 }
307 } else { 309 } else {
308 state_[stream_type] = new_state; 310 state_[stream_type] = new_state;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 360
359 StreamDeviceInfoArray devices; 361 StreamDeviceInfoArray devices;
360 362
361 // Callback to the requester which audio/video devices have been selected. 363 // Callback to the requester which audio/video devices have been selected.
362 // It can be null if the requester has no interest to know the result. 364 // It can be null if the requester has no interest to know the result.
363 // Currently it is only used by |DEVICE_ACCESS| type. 365 // Currently it is only used by |DEVICE_ACCESS| type.
364 MediaStreamManager::MediaRequestResponseCallback callback; 366 MediaStreamManager::MediaRequestResponseCallback callback;
365 367
366 scoped_ptr<MediaStreamUIProxy> ui_proxy; 368 scoped_ptr<MediaStreamUIProxy> ui_proxy;
367 369
370 std::string tab_capture_device_id;
371
368 private: 372 private:
369 std::vector<MediaRequestState> state_; 373 std::vector<MediaRequestState> state_;
370 scoped_ptr<MediaStreamRequest> ui_request_; 374 scoped_ptr<MediaStreamRequest> ui_request_;
371 MediaStreamType audio_type_; 375 MediaStreamType audio_type_;
372 MediaStreamType video_type_; 376 MediaStreamType video_type_;
373 }; 377 };
374 378
375 MediaStreamManager::EnumerationCache::EnumerationCache() 379 MediaStreamManager::EnumerationCache::EnumerationCache()
376 : valid(false) { 380 : valid(false) {
377 } 381 }
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 requests_.erase(request_it); 1160 requests_.erase(request_it);
1157 return; 1161 return;
1158 } 1162 }
1159 } 1163 }
1160 NOTREACHED(); 1164 NOTREACHED();
1161 } 1165 }
1162 1166
1163 void MediaStreamManager::PostRequestToUI(const std::string& label, 1167 void MediaStreamManager::PostRequestToUI(const std::string& label,
1164 DeviceRequest* request) { 1168 DeviceRequest* request) {
1165 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1169 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1166 DCHECK(request->UIRequest()); 1170 DCHECK(request->HasUIRequest());
1167 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; 1171 DVLOG(1) << "PostRequestToUI({label= " << label << "})";
1168 1172
1169 const MediaStreamType audio_type = request->audio_type(); 1173 const MediaStreamType audio_type = request->audio_type();
1170 const MediaStreamType video_type = request->video_type(); 1174 const MediaStreamType video_type = request->video_type();
1171 1175
1172 // Post the request to UI and set the state. 1176 // Post the request to UI and set the state.
1173 if (IsAudioInputMediaType(audio_type)) 1177 if (IsAudioInputMediaType(audio_type))
1174 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); 1178 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
1175 if (IsVideoMediaType(video_type)) 1179 if (IsVideoMediaType(video_type))
1176 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); 1180 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
(...skipping 19 matching lines...) Expand all
1196 } 1200 }
1197 1201
1198 fake_ui_->SetAvailableDevices(devices); 1202 fake_ui_->SetAvailableDevices(devices);
1199 1203
1200 request->ui_proxy = fake_ui_.Pass(); 1204 request->ui_proxy = fake_ui_.Pass();
1201 } else { 1205 } else {
1202 request->ui_proxy = MediaStreamUIProxy::Create(); 1206 request->ui_proxy = MediaStreamUIProxy::Create();
1203 } 1207 }
1204 1208
1205 request->ui_proxy->RequestAccess( 1209 request->ui_proxy->RequestAccess(
1206 *request->UIRequest(), 1210 request->GetUIRequest(),
1207 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, 1211 base::Bind(&MediaStreamManager::HandleAccessRequestResponse,
1208 base::Unretained(this), label)); 1212 base::Unretained(this), label));
1209 } 1213 }
1210 1214
1211 void MediaStreamManager::SetupRequest(const std::string& label) { 1215 void MediaStreamManager::SetupRequest(const std::string& label) {
1212 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1216 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1213 DeviceRequest* request = FindRequest(label); 1217 DeviceRequest* request = FindRequest(label);
1214 if (!request) { 1218 if (!request) {
1215 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; 1219 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!";
1216 return; // This can happen if the request has been canceled. 1220 return; // This can happen if the request has been canceled.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 1337
1334 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( 1338 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget(
1335 capture_device_id, &target_render_process_id, &target_render_frame_id); 1339 capture_device_id, &target_render_process_id, &target_render_frame_id);
1336 if (!has_valid_device_id || 1340 if (!has_valid_device_id ||
1337 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && 1341 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE &&
1338 request->audio_type() != MEDIA_NO_SERVICE) || 1342 request->audio_type() != MEDIA_NO_SERVICE) ||
1339 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && 1343 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE &&
1340 request->video_type() != MEDIA_NO_SERVICE)) { 1344 request->video_type() != MEDIA_NO_SERVICE)) {
1341 return false; 1345 return false;
1342 } 1346 }
1347 request->tab_capture_device_id = capture_device_id;
1343 1348
1344 request->CreateTabCaptureUIRequest(target_render_process_id, 1349 request->CreateTabCaptureUIRequest(target_render_process_id,
1345 target_render_frame_id, 1350 target_render_frame_id,
1346 capture_device_id); 1351 capture_device_id);
1347 1352
1348 DVLOG(3) << "SetupTabCaptureRequest " 1353 DVLOG(3) << "SetupTabCaptureRequest "
1349 << ", {capture_device_id = " << capture_device_id << "}" 1354 << ", {capture_device_id = " << capture_device_id << "}"
1350 << ", {target_render_process_id = " << target_render_process_id 1355 << ", {target_render_process_id = " << target_render_process_id
1351 << "}" 1356 << "}"
1352 << ", {target_render_frame_id = " << target_render_frame_id << "}"; 1357 << ", {target_render_frame_id = " << target_render_frame_id << "}";
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 // Process all newly-accepted devices for this request. 1911 // Process all newly-accepted devices for this request.
1907 bool found_audio = false; 1912 bool found_audio = false;
1908 bool found_video = false; 1913 bool found_video = false;
1909 for (MediaStreamDevices::const_iterator device_it = devices.begin(); 1914 for (MediaStreamDevices::const_iterator device_it = devices.begin();
1910 device_it != devices.end(); ++device_it) { 1915 device_it != devices.end(); ++device_it) {
1911 StreamDeviceInfo device_info; 1916 StreamDeviceInfo device_info;
1912 device_info.device = *device_it; 1917 device_info.device = *device_it;
1913 1918
1914 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE || 1919 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE ||
1915 device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) { 1920 device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) {
1916 device_info.device.id = request->UIRequest()->tab_capture_device_id; 1921 device_info.device.id = request->tab_capture_device_id;
1917 1922
1918 // Initialize the sample_rate and channel_layout here since for audio 1923 // Initialize the sample_rate and channel_layout here since for audio
1919 // mirroring, we don't go through EnumerateDevices where these are usually 1924 // mirroring, we don't go through EnumerateDevices where these are usually
1920 // initialized. 1925 // initialized.
1921 if (device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) { 1926 if (device_info.device.type == content::MEDIA_TAB_AUDIO_CAPTURE) {
1922 const media::AudioParameters parameters = 1927 const media::AudioParameters parameters =
1923 audio_manager_->GetDefaultOutputStreamParameters(); 1928 audio_manager_->GetDefaultOutputStreamParameters();
1924 int sample_rate = parameters.sample_rate(); 1929 int sample_rate = parameters.sample_rate();
1925 // If we weren't able to get the native sampling rate or the sample_rate 1930 // If we weren't able to get the native sampling rate or the sample_rate
1926 // is outside the valid range for input devices set reasonable defaults. 1931 // is outside the valid range for input devices set reasonable defaults.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 } 2161 }
2157 } 2162 }
2158 2163
2159 void MediaStreamManager::SetKeyboardMicOnDeviceThread() { 2164 void MediaStreamManager::SetKeyboardMicOnDeviceThread() {
2160 DCHECK(device_task_runner_->BelongsToCurrentThread()); 2165 DCHECK(device_task_runner_->BelongsToCurrentThread());
2161 audio_manager_->SetHasKeyboardMic(); 2166 audio_manager_->SetHasKeyboardMic();
2162 } 2167 }
2163 #endif 2168 #endif
2164 2169
2165 } // namespace content 2170 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree_node.h ('k') | content/browser/renderer_host/media/media_stream_ui_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698