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/content_settings/tab_specific_content_settings.h" | |
10 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory .h" | 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory .h" |
12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
13 #include "chrome/browser/media/media_internals.h" | 14 #include "chrome/browser/media/media_internals.h" |
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/common/content_settings.h" | 18 #include "chrome/common/content_settings.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/common/media_stream_request.h" | 21 #include "content/public/common/media_stream_request.h" |
21 | 22 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 | 24 |
24 // TODO(xians): Remove this when the Omnibar UI has been completed. | |
25 // See http://crbug.com/167263 for more details. | |
26 #define ALLOW_STICKY_DENY 0 | |
27 | |
28 namespace { | 25 namespace { |
29 | 26 |
30 bool HasAnyAvailableDevice() { | 27 bool HasAnyAvailableDevice() { |
31 MediaCaptureDevicesDispatcher* dispatcher = | 28 MediaCaptureDevicesDispatcher* dispatcher = |
32 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); | 29 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); |
33 const content::MediaStreamDevices& audio_devices = | 30 const content::MediaStreamDevices& audio_devices = |
34 dispatcher->GetAudioCaptureDevices(); | 31 dispatcher->GetAudioCaptureDevices(); |
35 const content::MediaStreamDevices& video_devices = | 32 const content::MediaStreamDevices& video_devices = |
36 dispatcher->GetVideoCaptureDevices(); | 33 dispatcher->GetVideoCaptureDevices(); |
37 | 34 |
38 return !audio_devices.empty() || !video_devices.empty(); | 35 return !audio_devices.empty() || !video_devices.empty(); |
39 }; | 36 }; |
40 | 37 |
41 } // namespace | 38 } // namespace |
42 | 39 |
43 MediaStreamDevicesController::MediaStreamDevicesController( | 40 MediaStreamDevicesController::MediaStreamDevicesController( |
44 Profile* profile, | 41 Profile* profile, |
42 TabSpecificContentSettings* content_settings, | |
45 const content::MediaStreamRequest& request, | 43 const content::MediaStreamRequest& request, |
46 const content::MediaResponseCallback& callback) | 44 const content::MediaResponseCallback& callback) |
47 : profile_(profile), | 45 : profile_(profile), |
46 content_settings_(content_settings), | |
48 request_(request), | 47 request_(request), |
49 callback_(callback), | 48 callback_(callback), |
50 has_audio_(content::IsAudioMediaType(request.audio_type) && | 49 has_audio_(content::IsAudioMediaType(request.audio_type) && |
51 !IsAudioDeviceBlockedByPolicy()), | 50 !IsAudioDeviceBlockedByPolicy()), |
52 has_video_(content::IsVideoMediaType(request.video_type) && | 51 has_video_(content::IsVideoMediaType(request.video_type) && |
53 !IsVideoDeviceBlockedByPolicy()) { | 52 !IsVideoDeviceBlockedByPolicy()) { |
54 } | 53 } |
55 | 54 |
56 MediaStreamDevicesController::~MediaStreamDevicesController() {} | 55 MediaStreamDevicesController::~MediaStreamDevicesController() {} |
57 | 56 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 113 |
115 // Show the infobar. | 114 // Show the infobar. |
116 return false; | 115 return false; |
117 } | 116 } |
118 | 117 |
119 const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const { | 118 const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const { |
120 return request_.security_origin.spec(); | 119 return request_.security_origin.spec(); |
121 } | 120 } |
122 | 121 |
123 void MediaStreamDevicesController::Accept(bool update_content_setting) { | 122 void MediaStreamDevicesController::Accept(bool update_content_setting) { |
123 content_settings_->OnMediaStreamAccessed(); | |
124 // Get the default devices for the request. | |
no longer working on chromium
2013/01/23 11:48:06
nit, add an empty line.
markusheintz_
2013/01/23 12:18:33
Done.
| |
124 content::MediaStreamDevices devices; | 125 content::MediaStreamDevices devices; |
125 if (has_audio_ || has_video_) { | 126 if (has_audio_ || has_video_) { |
126 switch (request_.request_type) { | 127 switch (request_.request_type) { |
127 case content::MEDIA_OPEN_DEVICE: | 128 case content::MEDIA_OPEN_DEVICE: |
128 // For open device request pick the desired device or fall back to the | 129 // For open device request pick the desired device or fall back to the |
129 // first available of the given type. | 130 // first available of the given type. |
130 media::GetRequestedDevice(request_.requested_device_id, | 131 media::GetRequestedDevice(request_.requested_device_id, |
131 has_audio_, | 132 has_audio_, |
132 has_video_, | 133 has_video_, |
133 &devices); | 134 &devices); |
134 break; | 135 break; |
135 case content::MEDIA_DEVICE_ACCESS: | 136 case content::MEDIA_DEVICE_ACCESS: |
136 case content::MEDIA_GENERATE_STREAM: | 137 case content::MEDIA_GENERATE_STREAM: |
137 case content::MEDIA_ENUMERATE_DEVICES: | 138 case content::MEDIA_ENUMERATE_DEVICES: |
138 // Get the default devices for the request. | 139 // Get the default devices for the request. |
139 media::GetDefaultDevicesForProfile(profile_, | 140 media::GetDefaultDevicesForProfile(profile_, |
140 has_audio_, | 141 has_audio_, |
141 has_video_, | 142 has_video_, |
142 &devices); | 143 &devices); |
143 break; | 144 break; |
144 } | 145 } |
145 | 146 |
146 if (update_content_setting && IsSchemeSecure() && !devices.empty()) | 147 if (update_content_setting && IsSchemeSecure() && !devices.empty()) |
147 SetPermission(true); | 148 SetPermission(true); |
148 } | 149 } |
149 | 150 |
150 callback_.Run(devices); | 151 callback_.Run(devices); |
151 } | 152 } |
152 | 153 |
153 void MediaStreamDevicesController::Deny(bool update_content_setting) { | 154 void MediaStreamDevicesController::Deny(bool update_content_setting) { |
154 #if ALLOW_STICKY_DENY | 155 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the |
156 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and | |
157 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. | |
158 content_settings_->OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM, | |
159 std::string()); | |
155 if (update_content_setting) | 160 if (update_content_setting) |
156 SetPermission(false); | 161 SetPermission(false); |
157 #endif | |
158 | 162 |
159 callback_.Run(content::MediaStreamDevices()); | 163 callback_.Run(content::MediaStreamDevices()); |
160 } | 164 } |
161 | 165 |
162 bool MediaStreamDevicesController::IsAudioDeviceBlockedByPolicy() const { | 166 bool MediaStreamDevicesController::IsAudioDeviceBlockedByPolicy() const { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 return (!profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed) && | 168 return (!profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed) && |
165 profile_->GetPrefs()->IsManagedPreference( | 169 profile_->GetPrefs()->IsManagedPreference( |
166 prefs::kAudioCaptureAllowed)); | 170 prefs::kAudioCaptureAllowed)); |
167 } | 171 } |
(...skipping 25 matching lines...) Expand all Loading... | |
193 request_.security_origin, | 197 request_.security_origin, |
194 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 198 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
195 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_ALLOW) { | 199 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_ALLOW) { |
196 return false; | 200 return false; |
197 } | 201 } |
198 | 202 |
199 return true; | 203 return true; |
200 } | 204 } |
201 | 205 |
202 bool MediaStreamDevicesController::IsRequestBlockedByDefault() const { | 206 bool MediaStreamDevicesController::IsRequestBlockedByDefault() const { |
203 #if ALLOW_STICKY_DENY | |
204 if (has_audio_ && | 207 if (has_audio_ && |
205 profile_->GetHostContentSettingsMap()->GetContentSetting( | 208 profile_->GetHostContentSettingsMap()->GetContentSetting( |
206 request_.security_origin, | 209 request_.security_origin, |
207 request_.security_origin, | 210 request_.security_origin, |
208 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 211 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
209 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { | 212 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { |
210 return false; | 213 return false; |
211 } | 214 } |
212 | 215 |
213 if (has_video_ && | 216 if (has_video_ && |
214 profile_->GetHostContentSettingsMap()->GetContentSetting( | 217 profile_->GetHostContentSettingsMap()->GetContentSetting( |
215 request_.security_origin, | 218 request_.security_origin, |
216 request_.security_origin, | 219 request_.security_origin, |
217 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 220 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
218 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { | 221 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { |
219 return false; | 222 return false; |
220 } | 223 } |
221 | 224 |
222 return true; | 225 return true; |
223 #else | |
224 return false; | |
225 #endif | |
226 } | 226 } |
227 | 227 |
228 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const { | 228 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const { |
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
230 #if ALLOW_STICKY_DENY | 230 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the |
231 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and | |
232 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. | |
231 ContentSetting current_setting = | 233 ContentSetting current_setting = |
232 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 234 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
233 CONTENT_SETTINGS_TYPE_MEDIASTREAM, NULL); | 235 CONTENT_SETTINGS_TYPE_MEDIASTREAM, NULL); |
234 return (current_setting == CONTENT_SETTING_BLOCK); | 236 return (current_setting == CONTENT_SETTING_BLOCK); |
235 #else | |
236 return false; | |
237 #endif | |
238 } | 237 } |
239 | 238 |
240 void MediaStreamDevicesController::HandleTapMediaRequest() { | 239 void MediaStreamDevicesController::HandleTapMediaRequest() { |
241 // For tab media requests, we need to make sure the request came from the | 240 // For tab media requests, we need to make sure the request came from the |
242 // extension API, so we check the registry here. | 241 // extension API, so we check the registry here. |
243 extensions::TabCaptureRegistry* registry = | 242 extensions::TabCaptureRegistry* registry = |
244 extensions::TabCaptureRegistryFactory::GetForProfile(profile_); | 243 extensions::TabCaptureRegistryFactory::GetForProfile(profile_); |
245 | 244 |
246 if (!registry->VerifyRequest(request_.render_process_id, | 245 if (!registry->VerifyRequest(request_.render_process_id, |
247 request_.render_view_id)) { | 246 request_.render_view_id)) { |
(...skipping 12 matching lines...) Expand all Loading... | |
260 | 259 |
261 callback_.Run(devices); | 260 callback_.Run(devices); |
262 } | 261 } |
263 } | 262 } |
264 | 263 |
265 bool MediaStreamDevicesController::IsSchemeSecure() const { | 264 bool MediaStreamDevicesController::IsSchemeSecure() const { |
266 return (request_.security_origin.SchemeIsSecure()); | 265 return (request_.security_origin.SchemeIsSecure()); |
267 } | 266 } |
268 | 267 |
269 bool MediaStreamDevicesController::ShouldAlwaysAllowOrigin() const { | 268 bool MediaStreamDevicesController::ShouldAlwaysAllowOrigin() const { |
269 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the | |
270 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and | |
271 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. | |
270 return profile_->GetHostContentSettingsMap()->ShouldAllowAllContent( | 272 return profile_->GetHostContentSettingsMap()->ShouldAllowAllContent( |
271 request_.security_origin, request_.security_origin, | 273 request_.security_origin, request_.security_origin, |
272 CONTENT_SETTINGS_TYPE_MEDIASTREAM); | 274 CONTENT_SETTINGS_TYPE_MEDIASTREAM); |
273 } | 275 } |
274 | 276 |
275 void MediaStreamDevicesController::SetPermission(bool allowed) const { | 277 void MediaStreamDevicesController::SetPermission(bool allowed) const { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
277 ContentSettingsPattern primary_pattern = | 279 ContentSettingsPattern primary_pattern = |
278 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); | 280 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); |
279 // Check the pattern is valid or not. When the request is from a file access, | 281 // Check the pattern is valid or not. When the request is from a file access, |
(...skipping 13 matching lines...) Expand all Loading... | |
293 } | 295 } |
294 if (has_video_) { | 296 if (has_video_) { |
295 profile_->GetHostContentSettingsMap()->SetContentSetting( | 297 profile_->GetHostContentSettingsMap()->SetContentSetting( |
296 primary_pattern, | 298 primary_pattern, |
297 ContentSettingsPattern::Wildcard(), | 299 ContentSettingsPattern::Wildcard(), |
298 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 300 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
299 std::string(), | 301 std::string(), |
300 content_setting); | 302 content_setting); |
301 } | 303 } |
302 } | 304 } |
OLD | NEW |