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

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>& response) {
393 DCHECK(response.size() == 1 || response.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_ = response.front();
399
400 if (video_setting_ == CONTENT_SETTING_ASK)
401 video_setting_ = response.back();
402
403 if (audio_setting_ == CONTENT_SETTING_BLOCK ||
Timothy Loh 2017/04/24 04:18:57 Should this be an &&? Looks like RunCallback() wil
raymes 2017/04/26 00:10:30 We should only really be updating |denial_reason_|
Timothy Loh 2017/04/26 01:40:25 OK, sounds reasonable.
404 video_setting_ == CONTENT_SETTING_BLOCK) {
405 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED;
406 } else if (audio_setting_ == CONTENT_SETTING_ASK ||
407 video_setting_ == CONTENT_SETTING_ASK) {
408 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DISMISSED;
409 }
410
411 RunCallback();
412 }
413
390 #if defined(OS_ANDROID) 414 #if defined(OS_ANDROID)
391 void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) { 415 void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) {
392 DCHECK(audio_setting_ != CONTENT_SETTING_ASK && 416 DCHECK(audio_setting_ != CONTENT_SETTING_ASK &&
393 video_setting_ != CONTENT_SETTING_ASK); 417 video_setting_ != CONTENT_SETTING_ASK);
394 418
395 if (!allowed) { 419 if (!allowed) {
396 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED; 420 denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED;
397 // Only permissions that were previously ALLOW for a site will have had 421 // 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 422 // 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. 423 // to change the setting to BLOCK to reflect that it wasn't allowed.
400 if (audio_setting_ == CONTENT_SETTING_ALLOW) 424 if (audio_setting_ == CONTENT_SETTING_ALLOW)
401 audio_setting_ = CONTENT_SETTING_BLOCK; 425 audio_setting_ = CONTENT_SETTING_BLOCK;
402 if (video_setting_ == CONTENT_SETTING_ALLOW) 426 if (video_setting_ == CONTENT_SETTING_ALLOW)
403 video_setting_ = CONTENT_SETTING_BLOCK; 427 video_setting_ = CONTENT_SETTING_BLOCK;
404 } 428 }
405 429
406 RunCallback(); 430 RunCallback();
407 } 431 }
408 #endif // defined(OS_ANDROID) 432 #endif // defined(OS_ANDROID)
409 433
410 void MediaStreamDevicesController::RequestFinishedNoPrompt() { 434 void MediaStreamDevicesController::RequestFinishedNoPrompt() {
411 RunCallback(); 435 RunCallback();
412 } 436 }
413 437
414 // static 438 // static
415 void MediaStreamDevicesController::RequestPermissionsWithDelegate( 439 void MediaStreamDevicesController::RequestPermissionsWithDelegate(
416 const content::MediaStreamRequest& request, 440 const content::MediaStreamRequest& request,
417 const content::MediaResponseCallback& callback, 441 const content::MediaResponseCallback& callback,
418 PermissionPromptDelegate* delegate) { 442 PermissionPromptDelegate* delegate) {
443 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
444 request.render_process_id, request.render_frame_id);
419 content::WebContents* web_contents = 445 content::WebContents* web_contents =
420 content::WebContents::FromRenderFrameHost( 446 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) { 447 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {
424 MediaPermissionRequestLogger::LogRequest( 448 MediaPermissionRequestLogger::LogRequest(
425 web_contents, request.render_process_id, request.render_frame_id, 449 web_contents, request.render_process_id, request.render_frame_id,
426 content::IsOriginSecure(request.security_origin)); 450 content::IsOriginSecure(request.security_origin));
427 } 451 }
428 452
429 std::unique_ptr<MediaStreamDevicesController> controller( 453 std::unique_ptr<MediaStreamDevicesController> controller(
430 new MediaStreamDevicesController(web_contents, request, callback)); 454 new MediaStreamDevicesController(web_contents, request, callback));
431 455
432 // Show a prompt if needed. 456 // Show a prompt if needed.
433 if (controller->IsAskingForAudio() || controller->IsAskingForVideo()) { 457 if (controller->IsAskingForAudio() || controller->IsAskingForVideo()) {
434 Profile* profile = 458 Profile* profile =
435 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 459 Profile::FromBrowserContext(web_contents->GetBrowserContext());
436 delegate->ShowPrompt( 460 if (base::FeatureList::IsEnabled(
437 request.user_gesture, web_contents, 461 features::kUsePermissionManagerForMediaRequests)) {
438 base::MakeUnique<Request>( 462 std::vector<ContentSettingsType> content_settings_types;
439 profile, controller->IsAskingForAudio(), 463
440 controller->IsAskingForVideo(), request.security_origin, 464 if (controller->IsAskingForAudio())
441 base::Bind(&MediaStreamDevicesController::PromptAnswered, 465 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
442 base::Passed(&controller)))); 466 if (controller->IsAskingForVideo()) {
467 content_settings_types.push_back(
468 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
469 }
470
471 PermissionManager::Get(profile)->RequestPermissions(
472 content_settings_types, rfh, request.security_origin,
473 request.user_gesture,
474 base::Bind(
475 &MediaStreamDevicesController::PromptAnsweredGroupedRequest,
476 base::Passed(&controller)));
477 } else {
478 delegate->ShowPrompt(
479 request.user_gesture, web_contents,
480 base::MakeUnique<Request>(
481 profile, controller->IsAskingForAudio(),
482 controller->IsAskingForVideo(), request.security_origin,
483 base::Bind(&MediaStreamDevicesController::PromptAnswered,
484 base::Passed(&controller))));
485 }
443 return; 486 return;
444 } 487 }
445 488
446 #if defined(OS_ANDROID) 489 #if defined(OS_ANDROID)
447 // If either audio or video was previously allowed and Chrome no longer has 490 // If either audio or video was previously allowed and Chrome no longer has
448 // the necessary permissions, show a infobar to attempt to address this 491 // the necessary permissions, show a infobar to attempt to address this
449 // mismatch. 492 // mismatch.
450 std::vector<ContentSettingsType> content_settings_types; 493 std::vector<ContentSettingsType> content_settings_types;
451 if (controller->IsAllowedForAudio()) 494 if (controller->IsAllowedForAudio())
452 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 495 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } 769 }
727 } 770 }
728 771
729 // Don't approve device requests if the tab was hidden. 772 // Don't approve device requests if the tab was hidden.
730 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 773 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
731 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 774 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
732 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 775 return web_contents_->GetRenderWidgetHostView()->IsShowing();
733 #endif 776 #endif
734 return true; 777 return true;
735 } 778 }
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