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

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

Issue 2829123003: Make media permission requests go through the PermissionManager (Closed)
Patch Set: Grouped requests Created 3 years, 8 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
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/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"
11 #include "base/feature_list.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
17 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
18 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" 19 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
19 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" 20 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
20 #include "chrome/browser/permissions/permission_manager.h" 21 #include "chrome/browser/permissions/permission_manager.h"
21 #include "chrome/browser/permissions/permission_result.h" 22 #include "chrome/browser/permissions/permission_result.h"
22 #include "chrome/browser/permissions/permission_uma_util.h" 23 #include "chrome/browser/permissions/permission_uma_util.h"
23 #include "chrome/browser/permissions/permission_util.h" 24 #include "chrome/browser/permissions/permission_util.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_features.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
29 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
30 #include "components/content_settings/core/common/content_settings_pattern.h" 31 #include "components/content_settings/core/common/content_settings_pattern.h"
31 #include "components/pref_registry/pref_registry_syncable.h" 32 #include "components/pref_registry/pref_registry_syncable.h"
32 #include "components/prefs/scoped_user_pref_update.h" 33 #include "components/prefs/scoped_user_pref_update.h"
33 #include "components/url_formatter/elide_url.h" 34 #include "components/url_formatter/elide_url.h"
34 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/navigation_handle.h" 36 #include "content/public/browser/navigation_handle.h"
36 #include "content/public/browser/render_frame_host.h" 37 #include "content/public/browser/render_frame_host.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 381 }
381 382
382 if (setting == CONTENT_SETTING_BLOCK) 383 if (setting == CONTENT_SETTING_BLOCK)
383 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED; 384 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED;
384 else if (setting == CONTENT_SETTING_ASK) 385 else if (setting == CONTENT_SETTING_ASK)
385 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DISMISSED; 386 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DISMISSED;
386 387
387 RunCallback(); 388 RunCallback();
388 } 389 }
389 390
391 void MediaStreamDevicesController::PromptAnsweredGroupedRequest(
392 const std::vector<ContentSetting>& responses) {
393 DCHECK(responses.size() == 1 || responses.size() == 2);
394
395 // The audio setting will always be the first one in the vector, if it was
396 // requested.
397 if (audio_setting_ == CONTENT_SETTING_ASK)
398 audio_setting_ = responses.front();
399
400 if (video_setting_ == CONTENT_SETTING_ASK)
401 video_setting_ = responses.back();
402
403 for (ContentSetting response : responses) {
404 if (response == CONTENT_SETTING_BLOCK)
405 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED;
406 else if (response == CONTENT_SETTING_ASK)
407 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DISMISSED;
408 }
409
410 RunCallback();
411 }
412
390 #if defined(OS_ANDROID) 413 #if defined(OS_ANDROID)
391 void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) { 414 void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) {
392 DCHECK(audio_setting_ != CONTENT_SETTING_ASK && 415 DCHECK(audio_setting_ != CONTENT_SETTING_ASK &&
393 video_setting_ != CONTENT_SETTING_ASK); 416 video_setting_ != CONTENT_SETTING_ASK);
394 417
395 if (!allowed) { 418 if (!allowed) {
396 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED; 419 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED;
397 // Only permissions that were previously ALLOW for a site will have had 420 // Only permissions that were previously ALLOW for a site will have had
398 // their android permissions requested. It's only in that case that we need 421 // their android permissions requested. It's only in that case that we need
399 // to change the setting to BLOCK to reflect that it wasn't allowed. 422 // to change the setting to BLOCK to reflect that it wasn't allowed.
400 if (audio_setting_ == CONTENT_SETTING_ALLOW) 423 if (audio_setting_ == CONTENT_SETTING_ALLOW)
401 audio_setting_ = CONTENT_SETTING_BLOCK; 424 audio_setting_ = CONTENT_SETTING_BLOCK;
402 if (video_setting_ == CONTENT_SETTING_ALLOW) 425 if (video_setting_ == CONTENT_SETTING_ALLOW)
403 video_setting_ = CONTENT_SETTING_BLOCK; 426 video_setting_ = CONTENT_SETTING_BLOCK;
404 } 427 }
405 428
406 RunCallback(); 429 RunCallback();
407 } 430 }
408 #endif // defined(OS_ANDROID) 431 #endif // defined(OS_ANDROID)
409 432
410 void MediaStreamDevicesController::RequestFinishedNoPrompt() { 433 void MediaStreamDevicesController::RequestFinishedNoPrompt() {
411 RunCallback(); 434 RunCallback();
412 } 435 }
413 436
414 // static 437 // static
415 void MediaStreamDevicesController::RequestPermissionsWithDelegate( 438 void MediaStreamDevicesController::RequestPermissionsWithDelegate(
416 const content::MediaStreamRequest& request, 439 const content::MediaStreamRequest& request,
417 const content::MediaResponseCallback& callback, 440 const content::MediaResponseCallback& callback,
418 PermissionPromptDelegate* delegate) { 441 PermissionPromptDelegate* delegate) {
442 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
443 request.render_process_id, request.render_frame_id);
419 content::WebContents* web_contents = 444 content::WebContents* web_contents =
420 content::WebContents::FromRenderFrameHost( 445 content::WebContents::FromRenderFrameHost(rfh);
421 content::RenderFrameHost::FromID(request.render_process_id,
422 request.render_frame_id));
423 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { 446 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {
424 MediaPermissionRequestLogger::LogRequest( 447 MediaPermissionRequestLogger::LogRequest(
425 web_contents, request.render_process_id, request.render_frame_id, 448 web_contents, request.render_process_id, request.render_frame_id,
426 content::IsOriginSecure(request.security_origin)); 449 content::IsOriginSecure(request.security_origin));
427 } 450 }
428 451
429 std::unique_ptr<MediaStreamDevicesController> controller( 452 std::unique_ptr<MediaStreamDevicesController> controller(
430 new MediaStreamDevicesController(web_contents, request, callback)); 453 new MediaStreamDevicesController(web_contents, request, callback));
431 454
432 // Show a prompt if needed. 455 // Show a prompt if needed.
433 bool is_asking_for_audio = controller->IsAskingForAudio(); 456 bool is_asking_for_audio = controller->IsAskingForAudio();
434 bool is_asking_for_video = controller->IsAskingForVideo(); 457 bool is_asking_for_video = controller->IsAskingForVideo();
435 if (is_asking_for_audio || is_asking_for_video) { 458 if (is_asking_for_audio || is_asking_for_video) {
436 Profile* profile = 459 Profile* profile =
437 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 460 Profile::FromBrowserContext(web_contents->GetBrowserContext());
438 delegate->ShowPrompt( 461 if (base::FeatureList::IsEnabled(
439 request.user_gesture, web_contents, 462 features::kUsePermissionManagerForMediaRequests)) {
440 base::MakeUnique<Request>( 463 std::vector<ContentSettingsType> content_settings_types;
441 profile, is_asking_for_audio, is_asking_for_video, 464
442 request.security_origin, 465 if (is_asking_for_audio)
443 base::Bind(&MediaStreamDevicesController::PromptAnswered, 466 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
444 base::Passed(&controller)))); 467 if (is_asking_for_video) {
468 content_settings_types.push_back(
469 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
470 }
471
472 PermissionManager::Get(profile)->RequestPermissions(
473 content_settings_types, rfh, request.security_origin,
474 request.user_gesture,
475 base::Bind(
476 &MediaStreamDevicesController::PromptAnsweredGroupedRequest,
477 base::Passed(&controller)));
478 } else {
479 delegate->ShowPrompt(
480 request.user_gesture, web_contents,
481 base::MakeUnique<Request>(
482 profile, is_asking_for_audio, is_asking_for_video,
483 request.security_origin,
484 base::Bind(&MediaStreamDevicesController::PromptAnswered,
485 base::Passed(&controller))));
486 }
445 return; 487 return;
446 } 488 }
447 489
448 #if defined(OS_ANDROID) 490 #if defined(OS_ANDROID)
449 // If either audio or video was previously allowed and Chrome no longer has 491 // If either audio or video was previously allowed and Chrome no longer has
450 // the necessary permissions, show a infobar to attempt to address this 492 // the necessary permissions, show a infobar to attempt to address this
451 // mismatch. 493 // mismatch.
452 std::vector<ContentSettingsType> content_settings_types; 494 std::vector<ContentSettingsType> content_settings_types;
453 if (controller->IsAllowedForAudio()) 495 if (controller->IsAllowedForAudio())
454 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 496 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 770 }
729 } 771 }
730 772
731 // Don't approve device requests if the tab was hidden. 773 // Don't approve device requests if the tab was hidden.
732 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 774 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
733 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 775 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
734 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 776 return web_contents_->GetRenderWidgetHostView()->IsShowing();
735 #endif 777 #endif
736 return true; 778 return true;
737 } 779 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/media_stream_devices_controller.h ('k') | chrome/browser/permissions/permission_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698