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/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/media_stream_devices_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
15 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 15 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
16 #include "chrome/browser/media/media_permission.h" | 16 #include "chrome/browser/media/media_permission.h" |
17 #include "chrome/browser/media/media_stream_capture_indicator.h" | 17 #include "chrome/browser/media/media_stream_capture_indicator.h" |
18 #include "chrome/browser/media/media_stream_device_permissions.h" | 18 #include "chrome/browser/media/media_stream_device_permissions.h" |
19 #include "chrome/browser/permissions/permission_context_uma_util.h" | |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 25 #include "components/content_settings/core/browser/host_content_settings_map.h" |
25 #include "components/content_settings/core/common/content_settings_pattern.h" | 26 #include "components/content_settings/core/common/content_settings_pattern.h" |
26 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 63 |
63 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 64 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
64 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; | 65 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; |
65 | 66 |
66 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 67 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
67 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; | 68 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; |
68 | 69 |
69 return false; | 70 return false; |
70 } | 71 } |
71 | 72 |
73 // Record a Rappor sample for taking an |action| on a media |request|. | |
74 void RecordPermissionAction(const content::MediaStreamRequest& request, | |
75 PermissionAction action) { | |
76 if (ContentTypeIsRequested(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | |
77 request)) { | |
78 PermissionContextUmaUtil::RecordMultiDRapporAction( | |
79 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request.security_origin, | |
80 action); | |
81 } | |
82 if (ContentTypeIsRequested(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, request)) { | |
83 PermissionContextUmaUtil::RecordMultiDRapporAction( | |
84 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, request.security_origin, action); | |
85 } | |
86 } | |
87 | |
72 } // namespace | 88 } // namespace |
73 | 89 |
74 MediaStreamDevicesController::MediaStreamDevicesController( | 90 MediaStreamDevicesController::MediaStreamDevicesController( |
75 content::WebContents* web_contents, | 91 content::WebContents* web_contents, |
76 const content::MediaStreamRequest& request, | 92 const content::MediaStreamRequest& request, |
77 const content::MediaResponseCallback& callback) | 93 const content::MediaResponseCallback& callback) |
78 : web_contents_(web_contents), | 94 : web_contents_(web_contents), |
79 request_(request), | 95 request_(request), |
80 callback_(callback), | 96 callback_(callback), |
81 persist_permission_changes_(true) { | 97 persist_permission_changes_(true) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 return; | 133 return; |
118 } | 134 } |
119 #endif | 135 #endif |
120 | 136 |
121 // Otherwise we can run the callback immediately. | 137 // Otherwise we can run the callback immediately. |
122 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); | 138 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); |
123 } | 139 } |
124 | 140 |
125 MediaStreamDevicesController::~MediaStreamDevicesController() { | 141 MediaStreamDevicesController::~MediaStreamDevicesController() { |
126 if (!callback_.is_null()) { | 142 if (!callback_.is_null()) { |
143 RecordPermissionAction(request_, PermissionAction::IGNORED); | |
mlamouri (slow - plz ping)
2015/10/13 10:00:43
Couldn't you used PermissionContextUmaUtil::Permis
tsergeant
2015/10/13 23:41:20
Calling RecordPermissionAction only records the mu
mlamouri (slow - plz ping)
2015/10/15 12:49:51
Would it make sense to deprecate Media.DevicePermi
kcarattini
2015/10/19 03:32:29
By centralized system do you mean use permission_c
| |
127 callback_.Run(content::MediaStreamDevices(), | 144 callback_.Run(content::MediaStreamDevices(), |
128 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, | 145 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
129 scoped_ptr<content::MediaStreamUI>()); | 146 scoped_ptr<content::MediaStreamUI>()); |
130 } | 147 } |
131 } | 148 } |
132 | 149 |
133 // static | 150 // static |
134 void MediaStreamDevicesController::RegisterProfilePrefs( | 151 void MediaStreamDevicesController::RegisterProfilePrefs( |
135 user_prefs::PrefRegistrySyncable* prefs) { | 152 user_prefs::PrefRegistrySyncable* prefs) { |
136 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); | 153 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 | 222 |
206 void MediaStreamDevicesController::PermissionGranted() { | 223 void MediaStreamDevicesController::PermissionGranted() { |
207 GURL origin(GetSecurityOriginSpec()); | 224 GURL origin(GetSecurityOriginSpec()); |
208 if (content::IsOriginSecure(origin)) { | 225 if (content::IsOriginSecure(origin)) { |
209 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 226 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
210 kAllowHttps, kPermissionActionsMax); | 227 kAllowHttps, kPermissionActionsMax); |
211 } else { | 228 } else { |
212 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 229 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
213 kAllowHttp, kPermissionActionsMax); | 230 kAllowHttp, kPermissionActionsMax); |
214 } | 231 } |
232 RecordPermissionAction(request_, PermissionAction::GRANTED); | |
mlamouri (slow - plz ping)
2015/10/13 10:00:43
ditto with Granted()
| |
215 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 233 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
216 old_audio_setting_, CONTENT_SETTING_ALLOW), | 234 old_audio_setting_, CONTENT_SETTING_ALLOW), |
217 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 235 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
218 old_video_setting_, CONTENT_SETTING_ALLOW), | 236 old_video_setting_, CONTENT_SETTING_ALLOW), |
219 content::MEDIA_DEVICE_PERMISSION_DENIED); | 237 content::MEDIA_DEVICE_PERMISSION_DENIED); |
220 } | 238 } |
221 | 239 |
222 void MediaStreamDevicesController::PermissionDenied() { | 240 void MediaStreamDevicesController::PermissionDenied() { |
223 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 241 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
224 kDeny, kPermissionActionsMax); | 242 kDeny, kPermissionActionsMax); |
243 RecordPermissionAction(request_, PermissionAction::DENIED); | |
mlamouri (slow - plz ping)
2015/10/13 10:00:43
ditto with Denied()
| |
225 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 244 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
226 old_audio_setting_, CONTENT_SETTING_BLOCK), | 245 old_audio_setting_, CONTENT_SETTING_BLOCK), |
227 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 246 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
228 old_video_setting_, CONTENT_SETTING_BLOCK), | 247 old_video_setting_, CONTENT_SETTING_BLOCK), |
229 content::MEDIA_DEVICE_PERMISSION_DENIED); | 248 content::MEDIA_DEVICE_PERMISSION_DENIED); |
230 } | 249 } |
231 | 250 |
232 void MediaStreamDevicesController::Cancelled() { | 251 void MediaStreamDevicesController::Cancelled() { |
233 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 252 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
234 kCancel, kPermissionActionsMax); | 253 kCancel, kPermissionActionsMax); |
254 RecordPermissionAction(request_, PermissionAction::DISMISSED); | |
mlamouri (slow - plz ping)
2015/10/13 10:00:43
ditto with Dismissed()
| |
235 RunCallback(old_audio_setting_, old_video_setting_, | 255 RunCallback(old_audio_setting_, old_video_setting_, |
236 content::MEDIA_DEVICE_PERMISSION_DISMISSED); | 256 content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
237 } | 257 } |
238 | 258 |
239 void MediaStreamDevicesController::RequestFinished() { | 259 void MediaStreamDevicesController::RequestFinished() { |
240 delete this; | 260 delete this; |
241 } | 261 } |
242 | 262 |
243 content::MediaStreamDevices MediaStreamDevicesController::GetDevices( | 263 content::MediaStreamDevices MediaStreamDevicesController::GetDevices( |
244 ContentSetting audio_setting, | 264 ContentSetting audio_setting, |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 if (android_permission_blocked) | 550 if (android_permission_blocked) |
531 return false; | 551 return false; |
532 | 552 |
533 // Don't approve device requests if the tab was hidden. | 553 // Don't approve device requests if the tab was hidden. |
534 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 554 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
535 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 555 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
536 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 556 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
537 #endif | 557 #endif |
538 return true; | 558 return true; |
539 } | 559 } |
OLD | NEW |