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

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

Issue 2342003002: Enable the optional permission prompt persistence toggle on grouped infobars (Closed)
Patch Set: 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/media_stream_devices_controller.h" 5 #include "chrome/browser/media/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.h" 13 #include "base/metrics/histogram.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/media_capture_devices_dispatcher.h" 18 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
19 #include "chrome/browser/media/media_permission.h" 19 #include "chrome/browser/media/media_permission.h"
20 #include "chrome/browser/media/media_stream_capture_indicator.h" 20 #include "chrome/browser/media/media_stream_capture_indicator.h"
21 #include "chrome/browser/media/media_stream_device_permissions.h" 21 #include "chrome/browser/media/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 "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"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 159
159 } // namespace 160 } // namespace
160 161
161 MediaStreamDevicesController::MediaStreamDevicesController( 162 MediaStreamDevicesController::MediaStreamDevicesController(
162 content::WebContents* web_contents, 163 content::WebContents* web_contents,
163 const content::MediaStreamRequest& request, 164 const content::MediaStreamRequest& request,
164 const content::MediaResponseCallback& callback) 165 const content::MediaResponseCallback& callback)
165 : web_contents_(web_contents), 166 : web_contents_(web_contents),
166 request_(request), 167 request_(request),
167 callback_(callback), 168 callback_(callback),
168 persist_permission_changes_(true) { 169 persist_(true) {
169 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { 170 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {
170 MediaPermissionRequestLogger::LogRequest( 171 MediaPermissionRequestLogger::LogRequest(
171 web_contents, request.render_process_id, request.render_frame_id, 172 web_contents, request.render_process_id, request.render_frame_id,
172 content::IsOriginSecure(request_.security_origin)); 173 content::IsOriginSecure(request_.security_origin));
173 } 174 }
174 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); 175 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
175 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); 176 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents);
176 177
177 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; 178 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK;
178 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 179 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (!IsAskingForAudio()) 251 if (!IsAskingForAudio())
251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; 252 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
252 else if (!IsAskingForVideo()) 253 else if (!IsAskingForVideo())
253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; 254 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY;
254 return l10n_util::GetStringFUTF16( 255 return l10n_util::GetStringFUTF16(
255 message_id, 256 message_id,
256 url_formatter::FormatUrlForSecurityDisplay( 257 url_formatter::FormatUrlForSecurityDisplay(
257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 258 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
258 } 259 }
259 260
261 content::PermissionType
262 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType(
263 ContentSettingsType content_type) const {
264 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC ||
265 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
266 content::PermissionType permission = content::PermissionType::NUM;
267 CHECK(PermissionUtil::GetPermissionType(content_type, &permission));
268 return permission;
269 }
270
260 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { 271 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() {
261 base::AutoReset<bool> persist_permissions( 272 base::AutoReset<bool> persist_permissions(&persist_, false);
262 &persist_permission_changes_, false);
263 // TODO(tsergeant): Determine whether it is appropriate to record permission 273 // TODO(tsergeant): Determine whether it is appropriate to record permission
264 // action metrics here, as this is a different sort of user action. 274 // action metrics here, as this is a different sort of user action.
265 RunCallback(CONTENT_SETTING_BLOCK, 275 RunCallback(CONTENT_SETTING_BLOCK,
266 CONTENT_SETTING_BLOCK, 276 CONTENT_SETTING_BLOCK,
267 content::MEDIA_DEVICE_PERMISSION_DENIED); 277 content::MEDIA_DEVICE_PERMISSION_DENIED);
268 } 278 }
269 279
270 int MediaStreamDevicesController::GetIconId() const { 280 int MediaStreamDevicesController::GetIconId() const {
271 if (IsAskingForVideo()) 281 if (IsAskingForVideo())
272 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; 282 return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 465 }
456 466
457 void MediaStreamDevicesController::RunCallback( 467 void MediaStreamDevicesController::RunCallback(
458 ContentSetting audio_setting, 468 ContentSetting audio_setting,
459 ContentSetting video_setting, 469 ContentSetting video_setting,
460 content::MediaStreamRequestResult denial_reason) { 470 content::MediaStreamRequestResult denial_reason) {
461 CHECK(!callback_.is_null()); 471 CHECK(!callback_.is_null());
462 472
463 // If the kill switch is on we don't update the tab context or persist the 473 // If the kill switch is on we don't update the tab context or persist the
464 // setting. 474 // setting.
465 if (persist_permission_changes_ && 475 if (denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) {
466 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { 476 if (persist())
467 StorePermission(audio_setting, video_setting); 477 StorePermission(audio_setting, video_setting);
468 UpdateTabSpecificContentSettings(audio_setting, video_setting); 478 UpdateTabSpecificContentSettings(audio_setting, video_setting);
469 } 479 }
470 480
471 content::MediaStreamDevices devices = 481 content::MediaStreamDevices devices =
472 GetDevices(audio_setting, video_setting); 482 GetDevices(audio_setting, video_setting);
473 483
474 // If either audio or video are allowed then the callback should report 484 // If either audio or video are allowed then the callback should report
475 // success, otherwise we report |denial_reason|. 485 // success, otherwise we report |denial_reason|.
476 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; 486 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK;
477 if (audio_setting != CONTENT_SETTING_ALLOW && 487 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) 582 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)
573 requested_device_id = request.requested_audio_device_id; 583 requested_device_id = request.requested_audio_device_id;
574 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) 584 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)
575 requested_device_id = request.requested_video_device_id; 585 requested_device_id = request.requested_video_device_id;
576 586
577 if (!IsUserAcceptAllowed(content_type)) { 587 if (!IsUserAcceptAllowed(content_type)) {
578 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 588 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
579 return CONTENT_SETTING_BLOCK; 589 return CONTENT_SETTING_BLOCK;
580 } 590 }
581 591
582 content::PermissionType permission_type; 592 content::PermissionType permission_type =
583 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 593 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)) { 594 if (ContentTypeIsRequested(permission_type, request)) {
591 DCHECK(content::IsOriginSecure(request_.security_origin) || 595 DCHECK(content::IsOriginSecure(request_.security_origin) ||
592 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); 596 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY);
593 MediaPermission permission(content_type, request.security_origin, 597 MediaPermission permission(content_type, request.security_origin,
594 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); 598 web_contents_->GetLastCommittedURL().GetOrigin(), profile_);
595 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, 599 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id,
596 denial_reason); 600 denial_reason);
597 } 601 }
598 // Return the default content setting if the device is not requested. 602 // Return the default content setting if the device is not requested.
599 return CONTENT_SETTING_DEFAULT; 603 return CONTENT_SETTING_DEFAULT;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 if (android_permission_blocked) 644 if (android_permission_blocked)
641 return false; 645 return false;
642 646
643 // Don't approve device requests if the tab was hidden. 647 // Don't approve device requests if the tab was hidden.
644 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 648 // 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? 649 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
646 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 650 return web_contents_->GetRenderWidgetHostView()->IsShowing();
647 #endif 651 #endif
648 return true; 652 return true;
649 } 653 }
OLDNEW
« no previous file with comments | « chrome/browser/media/media_stream_devices_controller.h ('k') | chrome/browser/media/media_stream_infobar_delegate_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698