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

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

Issue 2254763002: Enable the optional permission prompt persistence toggle on grouped infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobardelegate-clean
Patch Set: DCHECK -> CHECK Created 4 years, 3 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/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
19 #include "chrome/browser/media/webrtc/media_permission.h" 19 #include "chrome/browser/media/webrtc/media_permission.h"
20 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" 20 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
21 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" 21 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
22 #include "chrome/browser/permissions/permission_uma_util.h" 22 #include "chrome/browser/permissions/permission_uma_util.h"
23 #include "chrome/browser/permissions/permission_util.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/features.h" 27 #include "chrome/common/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 "chrome/grit/theme_resources.h" 30 #include "chrome/grit/theme_resources.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 31 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/content_settings/core/common/content_settings_pattern.h" 32 #include "components/content_settings/core/common/content_settings_pattern.h"
32 #include "components/pref_registry/pref_registry_syncable.h" 33 #include "components/pref_registry/pref_registry_syncable.h"
33 #include "components/prefs/scoped_user_pref_update.h" 34 #include "components/prefs/scoped_user_pref_update.h"
34 #include "components/url_formatter/elide_url.h" 35 #include "components/url_formatter/elide_url.h"
35 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/permission_type.h"
37 #include "content/public/browser/render_frame_host.h" 37 #include "content/public/browser/render_frame_host.h"
38 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
39 #include "content/public/browser/render_widget_host_view.h" 39 #include "content/public/browser/render_widget_host_view.h"
40 #include "content/public/common/media_stream_request.h" 40 #include "content/public/common/media_stream_request.h"
41 #include "content/public/common/origin_util.h" 41 #include "content/public/common/origin_util.h"
42 #include "extensions/common/constants.h" 42 #include "extensions/common/constants.h"
43 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
44 44
45 #if BUILDFLAG(ANDROID_JAVA_UI) 45 #if BUILDFLAG(ANDROID_JAVA_UI)
46 #include <vector> 46 #include <vector>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 } // namespace 159 } // namespace
160 160
161 MediaStreamDevicesController::MediaStreamDevicesController( 161 MediaStreamDevicesController::MediaStreamDevicesController(
162 content::WebContents* web_contents, 162 content::WebContents* web_contents,
163 const content::MediaStreamRequest& request, 163 const content::MediaStreamRequest& request,
164 const content::MediaResponseCallback& callback) 164 const content::MediaResponseCallback& callback)
165 : web_contents_(web_contents), 165 : web_contents_(web_contents),
166 request_(request), 166 request_(request),
167 callback_(callback), 167 callback_(callback),
168 persist_permission_changes_(true) { 168 persist_(true) {
169 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { 169 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {
170 MediaPermissionRequestLogger::LogRequest( 170 MediaPermissionRequestLogger::LogRequest(
171 web_contents, request.render_process_id, request.render_frame_id, 171 web_contents, request.render_process_id, request.render_frame_id,
172 content::IsOriginSecure(request_.security_origin)); 172 content::IsOriginSecure(request_.security_origin));
173 } 173 }
174 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); 174 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
175 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); 175 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents);
176 176
177 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; 177 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK;
178 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 178 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (!IsAskingForAudio()) 250 if (!IsAskingForAudio())
251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; 251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
252 else if (!IsAskingForVideo()) 252 else if (!IsAskingForVideo())
253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; 253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY;
254 return l10n_util::GetStringFUTF16( 254 return l10n_util::GetStringFUTF16(
255 message_id, 255 message_id,
256 url_formatter::FormatUrlForSecurityDisplay( 256 url_formatter::FormatUrlForSecurityDisplay(
257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
258 } 258 }
259 259
260 content::PermissionType
261 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType(
262 ContentSettingsType content_type) const {
263 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC ||
264 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
265 content::PermissionType permission = content::PermissionType::NUM;
266 CHECK(PermissionUtil::GetPermissionType(content_type, &permission));
267 return permission;
268 }
269
260 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { 270 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() {
261 base::AutoReset<bool> persist_permissions( 271 base::AutoReset<bool> persist_permissions(&persist_, false);
262 &persist_permission_changes_, false);
263 // TODO(tsergeant): Determine whether it is appropriate to record permission 272 // TODO(tsergeant): Determine whether it is appropriate to record permission
264 // action metrics here, as this is a different sort of user action. 273 // action metrics here, as this is a different sort of user action.
265 RunCallback(CONTENT_SETTING_BLOCK, 274 RunCallback(CONTENT_SETTING_BLOCK,
266 CONTENT_SETTING_BLOCK, 275 CONTENT_SETTING_BLOCK,
267 content::MEDIA_DEVICE_PERMISSION_DENIED); 276 content::MEDIA_DEVICE_PERMISSION_DENIED);
268 } 277 }
269 278
270 int MediaStreamDevicesController::GetIconId() const { 279 int MediaStreamDevicesController::GetIconId() const {
271 if (IsAskingForVideo()) 280 if (IsAskingForVideo())
272 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; 281 return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 464 }
456 465
457 void MediaStreamDevicesController::RunCallback( 466 void MediaStreamDevicesController::RunCallback(
458 ContentSetting audio_setting, 467 ContentSetting audio_setting,
459 ContentSetting video_setting, 468 ContentSetting video_setting,
460 content::MediaStreamRequestResult denial_reason) { 469 content::MediaStreamRequestResult denial_reason) {
461 CHECK(!callback_.is_null()); 470 CHECK(!callback_.is_null());
462 471
463 // If the kill switch is on we don't update the tab context or persist the 472 // If the kill switch is on we don't update the tab context or persist the
464 // setting. 473 // setting.
465 if (persist_permission_changes_ && 474 if (denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) {
466 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { 475 if (persist())
467 StorePermission(audio_setting, video_setting); 476 StorePermission(audio_setting, video_setting);
468 UpdateTabSpecificContentSettings(audio_setting, video_setting); 477 UpdateTabSpecificContentSettings(audio_setting, video_setting);
469 } 478 }
470 479
471 content::MediaStreamDevices devices = 480 content::MediaStreamDevices devices =
472 GetDevices(audio_setting, video_setting); 481 GetDevices(audio_setting, video_setting);
473 482
474 // If either audio or video are allowed then the callback should report 483 // If either audio or video are allowed then the callback should report
475 // success, otherwise we report |denial_reason|. 484 // success, otherwise we report |denial_reason|.
476 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; 485 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK;
477 if (audio_setting != CONTENT_SETTING_ALLOW && 486 if (audio_setting != CONTENT_SETTING_ALLOW &&
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) 581 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)
573 requested_device_id = request.requested_audio_device_id; 582 requested_device_id = request.requested_audio_device_id;
574 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) 583 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)
575 requested_device_id = request.requested_video_device_id; 584 requested_device_id = request.requested_video_device_id;
576 585
577 if (!IsUserAcceptAllowed(content_type)) { 586 if (!IsUserAcceptAllowed(content_type)) {
578 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 587 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
579 return CONTENT_SETTING_BLOCK; 588 return CONTENT_SETTING_BLOCK;
580 } 589 }
581 590
582 content::PermissionType permission_type; 591 content::PermissionType permission_type =
583 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 592 GetPermissionTypeForContentSettingsType(content_type);
584 permission_type = content::PermissionType::AUDIO_CAPTURE;
585 } else {
586 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
587 permission_type = content::PermissionType::VIDEO_CAPTURE;
588 }
589
590 if (ContentTypeIsRequested(permission_type, request)) { 593 if (ContentTypeIsRequested(permission_type, request)) {
591 DCHECK(content::IsOriginSecure(request_.security_origin) || 594 DCHECK(content::IsOriginSecure(request_.security_origin) ||
592 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); 595 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY);
593 MediaPermission permission(content_type, request.security_origin, 596 MediaPermission permission(content_type, request.security_origin,
594 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); 597 web_contents_->GetLastCommittedURL().GetOrigin(), profile_);
595 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, 598 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id,
596 denial_reason); 599 denial_reason);
597 } 600 }
598 // Return the default content setting if the device is not requested. 601 // Return the default content setting if the device is not requested.
599 return CONTENT_SETTING_DEFAULT; 602 return CONTENT_SETTING_DEFAULT;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 if (android_permission_blocked) 643 if (android_permission_blocked)
641 return false; 644 return false;
642 645
643 // Don't approve device requests if the tab was hidden. 646 // Don't approve device requests if the tab was hidden.
644 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 647 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
645 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 648 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
646 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 649 return web_contents_->GetRenderWidgetHostView()->IsShowing();
647 #endif 650 #endif
648 return true; 651 return true;
649 } 652 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698