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/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" | |
11 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 14 #include "base/values.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 17 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
19 #include "chrome/browser/media/webrtc/media_permission.h" | 18 #include "chrome/browser/media/webrtc/media_permission.h" |
20 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 19 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 }; | 156 }; |
158 | 157 |
159 } // namespace | 158 } // namespace |
160 | 159 |
161 MediaStreamDevicesController::MediaStreamDevicesController( | 160 MediaStreamDevicesController::MediaStreamDevicesController( |
162 content::WebContents* web_contents, | 161 content::WebContents* web_contents, |
163 const content::MediaStreamRequest& request, | 162 const content::MediaStreamRequest& request, |
164 const content::MediaResponseCallback& callback) | 163 const content::MediaResponseCallback& callback) |
165 : web_contents_(web_contents), | 164 : web_contents_(web_contents), |
166 request_(request), | 165 request_(request), |
167 callback_(callback), | 166 callback_(callback) { |
168 persist_(true) { | |
169 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { | 167 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { |
170 MediaPermissionRequestLogger::LogRequest( | 168 MediaPermissionRequestLogger::LogRequest( |
171 web_contents, request.render_process_id, request.render_frame_id, | 169 web_contents, request.render_process_id, request.render_frame_id, |
172 content::IsOriginSecure(request_.security_origin)); | 170 content::IsOriginSecure(request_.security_origin)); |
173 } | 171 } |
174 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 172 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
175 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); | 173 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); |
176 | 174 |
177 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; | 175 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; |
178 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 176 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType( | 259 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType( |
262 ContentSettingsType content_type) const { | 260 ContentSettingsType content_type) const { |
263 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 261 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
264 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 262 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
265 content::PermissionType permission = content::PermissionType::NUM; | 263 content::PermissionType permission = content::PermissionType::NUM; |
266 CHECK(PermissionUtil::GetPermissionType(content_type, &permission)); | 264 CHECK(PermissionUtil::GetPermissionType(content_type, &permission)); |
267 return permission; | 265 return permission; |
268 } | 266 } |
269 | 267 |
270 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { | 268 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { |
271 base::AutoReset<bool> persist_permissions(&persist_, false); | 269 set_persist(false); |
272 // TODO(tsergeant): Determine whether it is appropriate to record permission | 270 // TODO(tsergeant): Determine whether it is appropriate to record permission |
273 // action metrics here, as this is a different sort of user action. | 271 // action metrics here, as this is a different sort of user action. |
274 RunCallback(CONTENT_SETTING_BLOCK, | 272 RunCallback(CONTENT_SETTING_BLOCK, |
275 CONTENT_SETTING_BLOCK, | 273 CONTENT_SETTING_BLOCK, |
276 content::MEDIA_DEVICE_PERMISSION_DENIED); | 274 content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 275 set_persist(true); |
277 } | 276 } |
278 | 277 |
279 int MediaStreamDevicesController::GetIconId() const { | 278 int MediaStreamDevicesController::GetIconId() const { |
280 if (IsAskingForVideo()) | 279 if (IsAskingForVideo()) |
281 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; | 280 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; |
282 | 281 |
283 return IDR_INFOBAR_MEDIA_STREAM_MIC; | 282 return IDR_INFOBAR_MEDIA_STREAM_MIC; |
284 } | 283 } |
285 | 284 |
286 base::string16 MediaStreamDevicesController::GetMessageTextFragment() const { | 285 base::string16 MediaStreamDevicesController::GetMessageTextFragment() const { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 330 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
332 ContentSetting video_setting = | 331 ContentSetting video_setting = |
333 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 332 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
334 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 333 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
335 old_audio_setting_, audio_setting), | 334 old_audio_setting_, audio_setting), |
336 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 335 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
337 old_video_setting_, video_setting), | 336 old_video_setting_, video_setting), |
338 content::MEDIA_DEVICE_PERMISSION_DENIED); | 337 content::MEDIA_DEVICE_PERMISSION_DENIED); |
339 } | 338 } |
340 | 339 |
| 340 bool MediaStreamDevicesController::ShouldShowPersistenceToggle() const { |
| 341 return PermissionUtil::ShouldShowPersistenceToggle(); |
| 342 } |
| 343 |
341 void MediaStreamDevicesController::Cancelled() { | 344 void MediaStreamDevicesController::Cancelled() { |
342 RecordPermissionAction(request_, profile_, | 345 RecordPermissionAction(request_, profile_, |
343 base::Bind(PermissionUmaUtil::PermissionDismissed)); | 346 base::Bind(PermissionUmaUtil::PermissionDismissed)); |
344 RunCallback(old_audio_setting_, old_video_setting_, | 347 RunCallback(old_audio_setting_, old_video_setting_, |
345 content::MEDIA_DEVICE_PERMISSION_DISMISSED); | 348 content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
346 } | 349 } |
347 | 350 |
348 void MediaStreamDevicesController::RequestFinished() { | 351 void MediaStreamDevicesController::RequestFinished() { |
349 delete this; | 352 delete this; |
350 } | 353 } |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 if (android_permission_blocked) | 646 if (android_permission_blocked) |
644 return false; | 647 return false; |
645 | 648 |
646 // Don't approve device requests if the tab was hidden. | 649 // Don't approve device requests if the tab was hidden. |
647 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 650 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
648 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 651 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
649 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 652 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
650 #endif | 653 #endif |
651 return true; | 654 return true; |
652 } | 655 } |
OLD | NEW |