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/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/common/media_stream_request.h" | 18 #include "content/public/common/media_stream_request.h" |
17 | 19 |
18 using content::BrowserThread; | 20 using content::BrowserThread; |
19 | 21 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 has_audio_ |= !it->second.empty(); | 58 has_audio_ |= !it->second.empty(); |
57 } else if (content::IsVideoMediaType(it->first)) { | 59 } else if (content::IsVideoMediaType(it->first)) { |
58 has_video_ |= !it->second.empty(); | 60 has_video_ |= !it->second.empty(); |
59 } | 61 } |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 MediaStreamDevicesController::~MediaStreamDevicesController() {} | 65 MediaStreamDevicesController::~MediaStreamDevicesController() {} |
64 | 66 |
65 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { | 67 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { |
| 68 // For tab media requests, we need to make sure the request came from the |
| 69 // extension API, so we check the registry here. |
| 70 content::MediaStreamDeviceMap::const_iterator tab_video = |
| 71 request_.devices.find(content::MEDIA_TAB_VIDEO_CAPTURE); |
| 72 content::MediaStreamDeviceMap::const_iterator tab_audio = |
| 73 request_.devices.find(content::MEDIA_TAB_AUDIO_CAPTURE); |
| 74 if (tab_video != request_.devices.end() || |
| 75 tab_audio != request_.devices.end()) { |
| 76 extensions::TabCaptureRegistry* registry = |
| 77 extensions::TabCaptureRegistryFactory::GetForProfile(profile_); |
| 78 |
| 79 DCHECK(!tab_audio->second.empty() || !tab_video->second.empty()); |
| 80 std::string audio_device_id; |
| 81 std::string video_device_id; |
| 82 |
| 83 if (!tab_audio->second.empty()) |
| 84 audio_device_id = tab_audio->second[0].device_id; |
| 85 if (!tab_video->second.empty()) |
| 86 video_device_id = tab_video->second[0].device_id; |
| 87 |
| 88 if (!registry->VerifyRequest(!video_device_id.empty() ? |
| 89 video_device_id : audio_device_id)) { |
| 90 Deny(); |
| 91 } else { |
| 92 Accept(audio_device_id, video_device_id, false); |
| 93 } |
| 94 |
| 95 return true; |
| 96 } |
| 97 |
66 // Deny the request if the security origin is empty, this happens with | 98 // Deny the request if the security origin is empty, this happens with |
67 // file access without |--allow-file-access-from-files| flag. | 99 // file access without |--allow-file-access-from-files| flag. |
68 if (request_.security_origin.is_empty()) { | 100 if (request_.security_origin.is_empty()) { |
69 Deny(); | 101 Deny(); |
70 return true; | 102 return true; |
71 } | 103 } |
72 | 104 |
73 // Deny the request and don't show the infobar if there is no devices. | 105 // Deny the request and don't show the infobar if there is no devices. |
74 if (!has_audio_ && !has_video_) { | 106 if (!has_audio_ && !has_video_) { |
75 // TODO(xians): We should detect this in a early state, and post a callback | 107 // 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... |
322 for (content::MediaStreamDevices::const_iterator device_it = | 354 for (content::MediaStreamDevices::const_iterator device_it = |
323 it->second.begin(); | 355 it->second.begin(); |
324 device_it != it->second.end(); ++device_it) { | 356 device_it != it->second.end(); ++device_it) { |
325 const content::MediaStreamDevice& candidate = *device_it; | 357 const content::MediaStreamDevice& candidate = *device_it; |
326 if (candidate.device_id == device_id) | 358 if (candidate.device_id == device_id) |
327 return &candidate; | 359 return &candidate; |
328 } | 360 } |
329 } | 361 } |
330 return NULL; | 362 return NULL; |
331 } | 363 } |
OLD | NEW |