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

Side by Side Diff: chrome/browser/media/media_stream_devices_controller.cc

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

Powered by Google App Engine
This is Rietveld 408576698