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/webrtc/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // device id is non-empty, then the corresponding device list must not be | 183 // device id is non-empty, then the corresponding device list must not be |
184 // NULL. | 184 // NULL. |
185 if (!device_id.empty() && !devices->FindById(device_id)) | 185 if (!device_id.empty() && !devices->FindById(device_id)) |
186 return false; | 186 return false; |
187 | 187 |
188 return true; | 188 return true; |
189 } | 189 } |
190 | 190 |
191 } // namespace | 191 } // namespace |
192 | 192 |
| 193 MediaStreamDevicesController::Request::Request( |
| 194 Profile* profile, |
| 195 bool is_asking_for_audio, |
| 196 bool is_asking_for_video, |
| 197 const GURL& security_origin, |
| 198 PromptAnsweredCallback prompt_answered_callback) |
| 199 : profile_(profile), |
| 200 is_asking_for_audio_(is_asking_for_audio), |
| 201 is_asking_for_video_(is_asking_for_video), |
| 202 security_origin_(security_origin), |
| 203 prompt_answered_callback_(prompt_answered_callback), |
| 204 responded_(false) {} |
| 205 |
| 206 MediaStreamDevicesController::Request::~Request() { |
| 207 if (!responded_) { |
| 208 RecordPermissionAction(is_asking_for_audio_, is_asking_for_video_, |
| 209 security_origin_, profile_, |
| 210 base::Bind(PermissionUmaUtil::PermissionIgnored)); |
| 211 } |
| 212 } |
| 213 |
| 214 bool MediaStreamDevicesController::Request::IsAskingForAudio() const { |
| 215 return is_asking_for_audio_; |
| 216 } |
| 217 |
| 218 bool MediaStreamDevicesController::Request::IsAskingForVideo() const { |
| 219 return is_asking_for_video_; |
| 220 } |
| 221 |
| 222 base::string16 MediaStreamDevicesController::Request::GetMessageText() const { |
| 223 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; |
| 224 if (!IsAskingForAudio()) |
| 225 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| 226 else if (!IsAskingForVideo()) |
| 227 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
| 228 return l10n_util::GetStringFUTF16( |
| 229 message_id, |
| 230 url_formatter::FormatUrlForSecurityDisplay( |
| 231 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
| 232 } |
| 233 |
| 234 PermissionRequest::IconId MediaStreamDevicesController::Request::GetIconId() |
| 235 const { |
| 236 #if defined(OS_ANDROID) |
| 237 return IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA |
| 238 : IDR_INFOBAR_MEDIA_STREAM_MIC; |
| 239 #else |
| 240 return IsAskingForVideo() ? ui::kVideocamIcon : ui::kMicrophoneIcon; |
| 241 #endif |
| 242 } |
| 243 |
| 244 base::string16 MediaStreamDevicesController::Request::GetMessageTextFragment() |
| 245 const { |
| 246 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO_PERMISSION_FRAGMENT; |
| 247 if (!IsAskingForAudio()) |
| 248 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; |
| 249 else if (!IsAskingForVideo()) |
| 250 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; |
| 251 return l10n_util::GetStringUTF16(message_id); |
| 252 } |
| 253 |
| 254 GURL MediaStreamDevicesController::Request::GetOrigin() const { |
| 255 return security_origin_; |
| 256 } |
| 257 |
| 258 void MediaStreamDevicesController::Request::PermissionGranted() { |
| 259 RecordPermissionAction(is_asking_for_audio_, is_asking_for_video_, |
| 260 security_origin_, profile_, |
| 261 base::Bind(PermissionUmaUtil::PermissionGranted)); |
| 262 responded_ = true; |
| 263 prompt_answered_callback_.Run(CONTENT_SETTING_ALLOW, persist()); |
| 264 } |
| 265 |
| 266 void MediaStreamDevicesController::Request::PermissionDenied() { |
| 267 RecordPermissionAction(is_asking_for_audio_, is_asking_for_video_, |
| 268 security_origin_, profile_, |
| 269 base::Bind(PermissionUmaUtil::PermissionDenied)); |
| 270 responded_ = true; |
| 271 prompt_answered_callback_.Run(CONTENT_SETTING_BLOCK, persist()); |
| 272 } |
| 273 |
| 274 void MediaStreamDevicesController::Request::Cancelled() { |
| 275 RecordPermissionAction(is_asking_for_audio_, is_asking_for_video_, |
| 276 security_origin_, profile_, |
| 277 base::Bind(PermissionUmaUtil::PermissionDismissed)); |
| 278 responded_ = true; |
| 279 prompt_answered_callback_.Run(CONTENT_SETTING_ASK, false /* persist */); |
| 280 } |
| 281 |
| 282 void MediaStreamDevicesController::Request::RequestFinished() { |
| 283 delete this; |
| 284 } |
| 285 |
| 286 PermissionRequestType |
| 287 MediaStreamDevicesController::Request::GetPermissionRequestType() const { |
| 288 return PermissionRequestType::MEDIA_STREAM; |
| 289 } |
| 290 |
| 291 bool MediaStreamDevicesController::Request::ShouldShowPersistenceToggle() |
| 292 const { |
| 293 return PermissionUtil::ShouldShowPersistenceToggle(); |
| 294 } |
| 295 |
193 // Implementation of PermissionPromptDelegate which actually shows a permission | 296 // Implementation of PermissionPromptDelegate which actually shows a permission |
194 // prompt. | 297 // prompt. |
195 class MediaStreamDevicesController::PermissionPromptDelegateImpl | 298 class MediaStreamDevicesController::PermissionPromptDelegateImpl |
196 : public internal::PermissionPromptDelegate { | 299 : public MediaStreamDevicesController::PermissionPromptDelegate { |
197 public: | 300 public: |
198 void ShowPrompt( | 301 void ShowPrompt( |
199 bool user_gesture, | 302 bool user_gesture, |
200 content::WebContents* web_contents, | 303 content::WebContents* web_contents, |
201 std::unique_ptr<MediaStreamDevicesController> controller) override { | 304 std::unique_ptr<MediaStreamDevicesController::Request> request) override { |
202 #if defined(OS_ANDROID) | 305 #if defined(OS_ANDROID) |
203 PermissionUmaUtil::RecordPermissionPromptShown( | 306 PermissionUmaUtil::RecordPermissionPromptShown( |
204 controller->GetPermissionRequestType(), | 307 request->GetPermissionRequestType(), |
205 PermissionUtil::GetGestureType(user_gesture)); | 308 PermissionUtil::GetGestureType(user_gesture)); |
206 if (PermissionDialogDelegate::ShouldShowDialog(user_gesture)) { | 309 if (PermissionDialogDelegate::ShouldShowDialog(user_gesture)) { |
207 PermissionDialogDelegate::CreateMediaStreamDialog( | 310 PermissionDialogDelegate::CreateMediaStreamDialog( |
208 web_contents, user_gesture, std::move(controller)); | 311 web_contents, user_gesture, std::move(request)); |
209 } else { | 312 } else { |
210 MediaStreamInfoBarDelegateAndroid::Create(web_contents, user_gesture, | 313 MediaStreamInfoBarDelegateAndroid::Create(web_contents, user_gesture, |
211 std::move(controller)); | 314 std::move(request)); |
212 } | 315 } |
213 #else | 316 #else |
214 PermissionRequestManager* permission_request_manager = | 317 PermissionRequestManager* permission_request_manager = |
215 PermissionRequestManager::FromWebContents(web_contents); | 318 PermissionRequestManager::FromWebContents(web_contents); |
216 if (permission_request_manager) | 319 if (permission_request_manager) |
217 permission_request_manager->AddRequest(controller.release()); | 320 permission_request_manager->AddRequest(request.release()); |
218 #endif | 321 #endif |
219 } | 322 } |
220 }; | 323 }; |
221 | 324 |
222 // static | 325 // static |
223 void MediaStreamDevicesController::RequestPermissions( | 326 void MediaStreamDevicesController::RequestPermissions( |
224 const content::MediaStreamRequest& request, | 327 const content::MediaStreamRequest& request, |
225 const content::MediaResponseCallback& callback) { | 328 const content::MediaResponseCallback& callback) { |
226 PermissionPromptDelegateImpl delegate; | 329 PermissionPromptDelegateImpl delegate; |
227 RequestPermissionsWithDelegate(request, callback, &delegate); | 330 RequestPermissionsWithDelegate(request, callback, &delegate); |
228 } | 331 } |
229 | 332 |
230 // static | 333 // static |
231 void MediaStreamDevicesController::RegisterProfilePrefs( | 334 void MediaStreamDevicesController::RegisterProfilePrefs( |
232 user_prefs::PrefRegistrySyncable* prefs) { | 335 user_prefs::PrefRegistrySyncable* prefs) { |
233 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); | 336 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); |
234 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, true); | 337 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, true); |
235 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls); | 338 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls); |
236 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls); | 339 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls); |
237 } | 340 } |
238 | 341 |
239 MediaStreamDevicesController::~MediaStreamDevicesController() { | 342 MediaStreamDevicesController::~MediaStreamDevicesController() { |
240 if (!callback_.is_null()) { | 343 if (!callback_.is_null()) { |
241 RecordPermissionAction(IsAskingForAudio(), IsAskingForVideo(), GetOrigin(), | |
242 profile_, | |
243 base::Bind(PermissionUmaUtil::PermissionIgnored)); | |
244 callback_.Run(content::MediaStreamDevices(), | 344 callback_.Run(content::MediaStreamDevices(), |
245 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, | 345 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
246 std::unique_ptr<content::MediaStreamUI>()); | 346 std::unique_ptr<content::MediaStreamUI>()); |
247 } | 347 } |
248 } | 348 } |
249 | 349 |
250 bool MediaStreamDevicesController::IsAskingForAudio() const { | 350 bool MediaStreamDevicesController::IsAskingForAudio() const { |
251 return old_audio_setting_ == CONTENT_SETTING_ASK; | 351 return old_audio_setting_ == CONTENT_SETTING_ASK; |
252 } | 352 } |
253 | 353 |
254 bool MediaStreamDevicesController::IsAskingForVideo() const { | 354 bool MediaStreamDevicesController::IsAskingForVideo() const { |
255 return old_video_setting_ == CONTENT_SETTING_ASK; | 355 return old_video_setting_ == CONTENT_SETTING_ASK; |
256 } | 356 } |
257 | 357 |
258 base::string16 MediaStreamDevicesController::GetMessageText() const { | 358 void MediaStreamDevicesController::PromptAnswered(ContentSetting setting, |
259 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; | 359 bool persist) { |
260 if (!IsAskingForAudio()) | 360 ContentSetting audio_setting = GetNewSetting( |
261 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 361 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, old_audio_setting_, setting); |
262 else if (!IsAskingForVideo()) | 362 ContentSetting video_setting = GetNewSetting( |
263 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 363 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, old_video_setting_, setting); |
264 return l10n_util::GetStringFUTF16( | 364 |
265 message_id, | 365 if (persist) |
266 url_formatter::FormatUrlForSecurityDisplay( | 366 StorePermission(audio_setting, video_setting); |
267 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 367 |
| 368 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; |
| 369 if (setting == CONTENT_SETTING_ASK) |
| 370 denial_reason = content::MEDIA_DEVICE_PERMISSION_DISMISSED; |
| 371 else if (setting == CONTENT_SETTING_BLOCK) |
| 372 denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| 373 |
| 374 RunCallback(audio_setting, video_setting, denial_reason); |
268 } | 375 } |
269 | 376 |
270 #if defined(OS_ANDROID) | 377 #if defined(OS_ANDROID) |
271 void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) { | 378 void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) { |
272 DCHECK(old_audio_setting_ != CONTENT_SETTING_ASK && | 379 DCHECK(old_audio_setting_ != CONTENT_SETTING_ASK && |
273 old_video_setting_ != CONTENT_SETTING_ASK); | 380 old_video_setting_ != CONTENT_SETTING_ASK); |
274 | 381 |
275 ContentSetting audio_setting = old_audio_setting_; | 382 ContentSetting audio_setting = old_audio_setting_; |
276 ContentSetting video_setting = old_video_setting_; | 383 ContentSetting video_setting = old_video_setting_; |
277 | 384 |
278 if (!allowed) { | 385 if (!allowed) { |
279 // Only permissions that were previously ALLOW for a site will have had | 386 // Only permissions that were previously ALLOW for a site will have had |
280 // their android permissions requested. It's only in that case that we need | 387 // their android permissions requested. It's only in that case that we need |
281 // to change the setting to BLOCK to reflect that it wasn't allowed. | 388 // to change the setting to BLOCK to reflect that it wasn't allowed. |
282 if (audio_setting == CONTENT_SETTING_ALLOW) | 389 if (audio_setting == CONTENT_SETTING_ALLOW) |
283 audio_setting = CONTENT_SETTING_BLOCK; | 390 audio_setting = CONTENT_SETTING_BLOCK; |
284 if (video_setting == CONTENT_SETTING_ALLOW) | 391 if (video_setting == CONTENT_SETTING_ALLOW) |
285 video_setting = CONTENT_SETTING_BLOCK; | 392 video_setting = CONTENT_SETTING_BLOCK; |
286 } | 393 } |
287 | 394 |
288 RunCallback(audio_setting, video_setting, | 395 RunCallback(audio_setting, video_setting, |
289 content::MEDIA_DEVICE_PERMISSION_DENIED); | 396 content::MEDIA_DEVICE_PERMISSION_DENIED); |
290 } | 397 } |
291 #endif // defined(OS_ANDROID) | 398 #endif // defined(OS_ANDROID) |
292 | 399 |
293 PermissionRequest::IconId MediaStreamDevicesController::GetIconId() const { | |
294 #if defined(OS_ANDROID) | |
295 return IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA | |
296 : IDR_INFOBAR_MEDIA_STREAM_MIC; | |
297 #else | |
298 return IsAskingForVideo() ? ui::kVideocamIcon : ui::kMicrophoneIcon; | |
299 #endif | |
300 } | |
301 | |
302 base::string16 MediaStreamDevicesController::GetMessageTextFragment() const { | |
303 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO_PERMISSION_FRAGMENT; | |
304 if (!IsAskingForAudio()) | |
305 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; | |
306 else if (!IsAskingForVideo()) | |
307 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; | |
308 return l10n_util::GetStringUTF16(message_id); | |
309 } | |
310 | |
311 GURL MediaStreamDevicesController::GetOrigin() const { | |
312 return request_.security_origin; | |
313 } | |
314 | |
315 void MediaStreamDevicesController::PermissionGranted() { | |
316 RecordPermissionAction(IsAskingForAudio(), IsAskingForVideo(), GetOrigin(), | |
317 profile_, | |
318 base::Bind(PermissionUmaUtil::PermissionGranted)); | |
319 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
320 old_audio_setting_, CONTENT_SETTING_ALLOW), | |
321 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | |
322 old_video_setting_, CONTENT_SETTING_ALLOW), | |
323 content::MEDIA_DEVICE_PERMISSION_DENIED); | |
324 } | |
325 | |
326 void MediaStreamDevicesController::PermissionDenied() { | |
327 RecordPermissionAction(IsAskingForAudio(), IsAskingForVideo(), GetOrigin(), | |
328 profile_, | |
329 base::Bind(PermissionUmaUtil::PermissionDenied)); | |
330 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
331 old_audio_setting_, CONTENT_SETTING_BLOCK), | |
332 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | |
333 old_video_setting_, CONTENT_SETTING_BLOCK), | |
334 content::MEDIA_DEVICE_PERMISSION_DENIED); | |
335 } | |
336 | |
337 bool MediaStreamDevicesController::ShouldShowPersistenceToggle() const { | |
338 return PermissionUtil::ShouldShowPersistenceToggle(); | |
339 } | |
340 | |
341 void MediaStreamDevicesController::Cancelled() { | |
342 RecordPermissionAction(IsAskingForAudio(), IsAskingForVideo(), GetOrigin(), | |
343 profile_, | |
344 base::Bind(PermissionUmaUtil::PermissionDismissed)); | |
345 RunCallback(old_audio_setting_, old_video_setting_, | |
346 content::MEDIA_DEVICE_PERMISSION_DISMISSED); | |
347 } | |
348 | |
349 void MediaStreamDevicesController::RequestFinished() { | |
350 delete this; | |
351 } | |
352 | |
353 PermissionRequestType MediaStreamDevicesController::GetPermissionRequestType() | |
354 const { | |
355 return PermissionRequestType::MEDIA_STREAM; | |
356 } | |
357 | |
358 // static | 400 // static |
359 void MediaStreamDevicesController::RequestPermissionsWithDelegate( | 401 void MediaStreamDevicesController::RequestPermissionsWithDelegate( |
360 const content::MediaStreamRequest& request, | 402 const content::MediaStreamRequest& request, |
361 const content::MediaResponseCallback& callback, | 403 const content::MediaResponseCallback& callback, |
362 internal::PermissionPromptDelegate* delegate) { | 404 PermissionPromptDelegate* delegate) { |
363 content::WebContents* web_contents = | 405 content::WebContents* web_contents = |
364 content::WebContents::FromRenderFrameHost( | 406 content::WebContents::FromRenderFrameHost( |
365 content::RenderFrameHost::FromID(request.render_process_id, | 407 content::RenderFrameHost::FromID(request.render_process_id, |
366 request.render_frame_id)); | 408 request.render_frame_id)); |
367 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { | 409 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { |
368 MediaPermissionRequestLogger::LogRequest( | 410 MediaPermissionRequestLogger::LogRequest( |
369 web_contents, request.render_process_id, request.render_frame_id, | 411 web_contents, request.render_process_id, request.render_frame_id, |
370 content::IsOriginSecure(request.security_origin)); | 412 content::IsOriginSecure(request.security_origin)); |
371 } | 413 } |
372 | 414 |
(...skipping 17 matching lines...) Expand all Loading... |
390 web_contents, content_settings_types)) { | 432 web_contents, content_settings_types)) { |
391 PermissionUpdateInfoBarDelegate::Create( | 433 PermissionUpdateInfoBarDelegate::Create( |
392 web_contents, content_settings_types, | 434 web_contents, content_settings_types, |
393 base::Bind(&MediaStreamDevicesController::AndroidOSPromptAnswered, | 435 base::Bind(&MediaStreamDevicesController::AndroidOSPromptAnswered, |
394 base::Passed(&controller))); | 436 base::Passed(&controller))); |
395 } | 437 } |
396 #endif | 438 #endif |
397 return; | 439 return; |
398 } | 440 } |
399 | 441 |
400 delegate->ShowPrompt(request.user_gesture, web_contents, | 442 Profile* profile = |
401 std::move(controller)); | 443 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 444 delegate->ShowPrompt( |
| 445 request.user_gesture, web_contents, |
| 446 base::MakeUnique<MediaStreamDevicesController::Request>( |
| 447 profile, controller->IsAskingForAudio(), |
| 448 controller->IsAskingForVideo(), request.security_origin, |
| 449 base::Bind(&MediaStreamDevicesController::PromptAnswered, |
| 450 base::Passed(&controller)))); |
402 } | 451 } |
403 | 452 |
404 MediaStreamDevicesController::MediaStreamDevicesController( | 453 MediaStreamDevicesController::MediaStreamDevicesController( |
405 content::WebContents* web_contents, | 454 content::WebContents* web_contents, |
406 const content::MediaStreamRequest& request, | 455 const content::MediaStreamRequest& request, |
407 const content::MediaResponseCallback& callback) | 456 const content::MediaResponseCallback& callback) |
408 : web_contents_(web_contents), request_(request), callback_(callback) { | 457 : web_contents_(web_contents), request_(request), callback_(callback) { |
409 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 458 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
410 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); | 459 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); |
411 | 460 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 589 |
541 return devices; | 590 return devices; |
542 } | 591 } |
543 | 592 |
544 void MediaStreamDevicesController::RunCallback( | 593 void MediaStreamDevicesController::RunCallback( |
545 ContentSetting audio_setting, | 594 ContentSetting audio_setting, |
546 ContentSetting video_setting, | 595 ContentSetting video_setting, |
547 content::MediaStreamRequestResult denial_reason) { | 596 content::MediaStreamRequestResult denial_reason) { |
548 CHECK(!callback_.is_null()); | 597 CHECK(!callback_.is_null()); |
549 | 598 |
550 // If the kill switch is on we don't update the tab context or persist the | 599 // If the kill switch is on we don't update the tab context. |
551 // setting. | 600 if (denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) |
552 if (denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { | |
553 if (persist()) | |
554 StorePermission(audio_setting, video_setting); | |
555 UpdateTabSpecificContentSettings(audio_setting, video_setting); | 601 UpdateTabSpecificContentSettings(audio_setting, video_setting); |
556 } | |
557 | 602 |
558 content::MediaStreamDevices devices = | 603 content::MediaStreamDevices devices = |
559 GetDevices(audio_setting, video_setting); | 604 GetDevices(audio_setting, video_setting); |
560 | 605 |
561 // If either audio or video are allowed then the callback should report | 606 // If either audio or video are allowed then the callback should report |
562 // success, otherwise we report |denial_reason|. | 607 // success, otherwise we report |denial_reason|. |
563 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; | 608 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
564 if (audio_setting != CONTENT_SETTING_ALLOW && | 609 if (audio_setting != CONTENT_SETTING_ALLOW && |
565 video_setting != CONTENT_SETTING_ALLOW) { | 610 video_setting != CONTENT_SETTING_ALLOW) { |
566 DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason); | 611 DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 : content::MEDIA_DEVICE_PERMISSION_DENIED; | 732 : content::MEDIA_DEVICE_PERMISSION_DENIED; |
688 } | 733 } |
689 | 734 |
690 return result.content_setting; | 735 return result.content_setting; |
691 } | 736 } |
692 | 737 |
693 ContentSetting MediaStreamDevicesController::GetNewSetting( | 738 ContentSetting MediaStreamDevicesController::GetNewSetting( |
694 ContentSettingsType content_type, | 739 ContentSettingsType content_type, |
695 ContentSetting old_setting, | 740 ContentSetting old_setting, |
696 ContentSetting user_decision) const { | 741 ContentSetting user_decision) const { |
697 DCHECK(user_decision == CONTENT_SETTING_ALLOW || | |
698 user_decision == CONTENT_SETTING_BLOCK); | |
699 ContentSetting result = old_setting; | 742 ContentSetting result = old_setting; |
700 if (old_setting == CONTENT_SETTING_ASK) | 743 if (old_setting == CONTENT_SETTING_ASK) |
701 result = user_decision; | 744 result = user_decision; |
702 return result; | 745 return result; |
703 } | 746 } |
704 | 747 |
705 bool MediaStreamDevicesController::IsUserAcceptAllowed( | 748 bool MediaStreamDevicesController::IsUserAcceptAllowed( |
706 ContentSettingsType content_type) const { | 749 ContentSettingsType content_type) const { |
707 #if defined(OS_ANDROID) | 750 #if defined(OS_ANDROID) |
708 content::ContentViewCore* cvc = | 751 content::ContentViewCore* cvc = |
(...skipping 15 matching lines...) Expand all Loading... |
724 } | 767 } |
725 } | 768 } |
726 | 769 |
727 // Don't approve device requests if the tab was hidden. | 770 // Don't approve device requests if the tab was hidden. |
728 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 771 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
729 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 772 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
730 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 773 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
731 #endif | 774 #endif |
732 return true; | 775 return true; |
733 } | 776 } |
OLD | NEW |