Chromium Code Reviews| 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 "chrome/browser/media/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/content_settings/content_settings_provider.h" | 8 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | |
| 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory .h" | |
| 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/content_settings.h" | 15 #include "chrome/common/content_settings.h" |
| 14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 15 #include "content/public/common/media_stream_request.h" | 17 #include "content/public/common/media_stream_request.h" |
| 16 | 18 |
| 17 using content::BrowserThread; | 19 using content::BrowserThread; |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 has_audio_ |= !it->second.empty(); | 57 has_audio_ |= !it->second.empty(); |
| 56 } else if (content::IsVideoMediaType(it->first)) { | 58 } else if (content::IsVideoMediaType(it->first)) { |
| 57 has_video_ |= !it->second.empty(); | 59 has_video_ |= !it->second.empty(); |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 MediaStreamDevicesController::~MediaStreamDevicesController() {} | 64 MediaStreamDevicesController::~MediaStreamDevicesController() {} |
| 63 | 65 |
| 64 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { | 66 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { |
| 67 // For tab media requests, we need to make sure the request came from the | |
| 68 // extension API, so we check the registry here. | |
| 69 content::MediaStreamDeviceMap::const_iterator tab_video = | |
| 70 request_.devices.find(content::MEDIA_TAB_VIDEO_CAPTURE); | |
| 71 content::MediaStreamDeviceMap::const_iterator tab_audio = | |
| 72 request_.devices.find(content::MEDIA_TAB_AUDIO_CAPTURE); | |
| 73 if (tab_video != request_.devices.end() || | |
| 74 tab_audio != request_.devices.end()) { | |
| 75 extensions::TabCaptureRegistry* registry = | |
| 76 extensions::TabCaptureRegistryFactory::GetForProfile(profile_); | |
| 77 | |
| 78 DCHECK(tab_audio->second.size() || tab_video->second.size()); | |
|
no longer working on chromium
2012/10/18 08:36:17
use !tab_audio->second.empty(), the same for other
justinlin
2012/10/18 09:33:29
Done.
| |
| 79 std::string audio_device_id; | |
| 80 std::string video_device_id; | |
| 81 | |
| 82 if (tab_audio->second.size()) | |
| 83 audio_device_id = tab_audio->second[0].device_id; | |
| 84 if (tab_video->second.size()) | |
| 85 video_device_id = tab_video->second[0].device_id; | |
| 86 | |
| 87 if (!registry->VerifyRequest(!video_device_id.empty() ? | |
| 88 video_device_id : audio_device_id)) | |
|
no longer working on chromium
2012/10/18 08:36:17
Does it mean that we will have either video_device
no longer working on chromium
2012/10/18 08:36:17
add a { because "if" takes two line.
justinlin
2012/10/18 09:33:29
Done.
justinlin
2012/10/18 09:33:29
No, this is a little bit related to http://crbug.c
| |
| 89 Deny(); | |
| 90 else | |
| 91 Accept(audio_device_id, video_device_id, false); | |
| 92 | |
| 93 return true; | |
| 94 } | |
| 95 | |
| 65 // Deny the request if the security origin is empty, this happens with | 96 // Deny the request if the security origin is empty, this happens with |
| 66 // file access without |--allow-file-access-from-files| flag. | 97 // file access without |--allow-file-access-from-files| flag. |
| 67 if (request_.security_origin.is_empty()) { | 98 if (request_.security_origin.is_empty()) { |
| 68 Deny(); | 99 Deny(); |
| 69 return true; | 100 return true; |
| 70 } | 101 } |
| 71 | 102 |
| 72 // Deny the request and don't show the infobar if there is no devices. | 103 // Deny the request and don't show the infobar if there is no devices. |
| 73 if (!has_audio_ && !has_video_) { | 104 if (!has_audio_ && !has_video_) { |
| 74 // TODO(xians): We should detect this in a early state, and post a callback | 105 // TODO(xians): We should detect this in a early state, and post a callback |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 for (content::MediaStreamDevices::const_iterator device_it = | 352 for (content::MediaStreamDevices::const_iterator device_it = |
| 322 it->second.begin(); | 353 it->second.begin(); |
| 323 device_it != it->second.end(); ++device_it) { | 354 device_it != it->second.end(); ++device_it) { |
| 324 const content::MediaStreamDevice& candidate = *device_it; | 355 const content::MediaStreamDevice& candidate = *device_it; |
| 325 if (candidate.device_id == device_id) | 356 if (candidate.device_id == device_id) |
| 326 return &candidate; | 357 return &candidate; |
| 327 } | 358 } |
| 328 } | 359 } |
| 329 return NULL; | 360 return NULL; |
| 330 } | 361 } |
| OLD | NEW |