| 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 <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.h" | 12 #include "base/metrics/histogram.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/media_capture_devices_dispatcher.h" | 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 19 #include "chrome/browser/media/media_permission.h" | 18 #include "chrome/browser/media/media_permission.h" |
| 20 #include "chrome/browser/media/media_stream_capture_indicator.h" | 19 #include "chrome/browser/media/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_permission_changes_(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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 249 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| 252 else if (!IsAskingForVideo()) | 250 else if (!IsAskingForVideo()) |
| 253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 251 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
| 254 return l10n_util::GetStringFUTF16( | 252 return l10n_util::GetStringFUTF16( |
| 255 message_id, | 253 message_id, |
| 256 url_formatter::FormatUrlForSecurityDisplay( | 254 url_formatter::FormatUrlForSecurityDisplay( |
| 257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 255 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
| 258 } | 256 } |
| 259 | 257 |
| 260 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { | 258 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { |
| 261 base::AutoReset<bool> persist_permissions( | 259 set_persist(false); |
| 262 &persist_permission_changes_, false); | |
| 263 // TODO(tsergeant): Determine whether it is appropriate to record permission | 260 // TODO(tsergeant): Determine whether it is appropriate to record permission |
| 264 // action metrics here, as this is a different sort of user action. | 261 // action metrics here, as this is a different sort of user action. |
| 265 RunCallback(CONTENT_SETTING_BLOCK, | 262 RunCallback(CONTENT_SETTING_BLOCK, |
| 266 CONTENT_SETTING_BLOCK, | 263 CONTENT_SETTING_BLOCK, |
| 267 content::MEDIA_DEVICE_PERMISSION_DENIED); | 264 content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 265 set_persist(true); |
| 268 } | 266 } |
| 269 | 267 |
| 270 int MediaStreamDevicesController::GetIconId() const { | 268 int MediaStreamDevicesController::GetIconId() const { |
| 271 if (IsAskingForVideo()) | 269 if (IsAskingForVideo()) |
| 272 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; | 270 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; |
| 273 | 271 |
| 274 return IDR_INFOBAR_MEDIA_STREAM_MIC; | 272 return IDR_INFOBAR_MEDIA_STREAM_MIC; |
| 275 } | 273 } |
| 276 | 274 |
| 277 base::string16 MediaStreamDevicesController::GetMessageTextFragment() const { | 275 base::string16 MediaStreamDevicesController::GetMessageTextFragment() const { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 320 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 323 ContentSetting video_setting = | 321 ContentSetting video_setting = |
| 324 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 322 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 325 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 323 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 326 old_audio_setting_, audio_setting), | 324 old_audio_setting_, audio_setting), |
| 327 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 325 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 328 old_video_setting_, video_setting), | 326 old_video_setting_, video_setting), |
| 329 content::MEDIA_DEVICE_PERMISSION_DENIED); | 327 content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 330 } | 328 } |
| 331 | 329 |
| 330 bool MediaStreamDevicesController::ShouldShowPersistenceToggle() const { |
| 331 return PermissionUtil::ShouldShowPersistenceToggle(); |
| 332 } |
| 333 |
| 332 void MediaStreamDevicesController::Cancelled() { | 334 void MediaStreamDevicesController::Cancelled() { |
| 333 RecordPermissionAction(request_, profile_, | 335 RecordPermissionAction(request_, profile_, |
| 334 base::Bind(PermissionUmaUtil::PermissionDismissed)); | 336 base::Bind(PermissionUmaUtil::PermissionDismissed)); |
| 335 RunCallback(old_audio_setting_, old_video_setting_, | 337 RunCallback(old_audio_setting_, old_video_setting_, |
| 336 content::MEDIA_DEVICE_PERMISSION_DISMISSED); | 338 content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
| 337 } | 339 } |
| 338 | 340 |
| 339 void MediaStreamDevicesController::RequestFinished() { | 341 void MediaStreamDevicesController::RequestFinished() { |
| 340 delete this; | 342 delete this; |
| 341 } | 343 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 457 } |
| 456 | 458 |
| 457 void MediaStreamDevicesController::RunCallback( | 459 void MediaStreamDevicesController::RunCallback( |
| 458 ContentSetting audio_setting, | 460 ContentSetting audio_setting, |
| 459 ContentSetting video_setting, | 461 ContentSetting video_setting, |
| 460 content::MediaStreamRequestResult denial_reason) { | 462 content::MediaStreamRequestResult denial_reason) { |
| 461 CHECK(!callback_.is_null()); | 463 CHECK(!callback_.is_null()); |
| 462 | 464 |
| 463 // If the kill switch is on we don't update the tab context or persist the | 465 // If the kill switch is on we don't update the tab context or persist the |
| 464 // setting. | 466 // setting. |
| 465 if (persist_permission_changes_ && | 467 if (persist() && denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { |
| 466 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { | |
| 467 StorePermission(audio_setting, video_setting); | 468 StorePermission(audio_setting, video_setting); |
| 468 UpdateTabSpecificContentSettings(audio_setting, video_setting); | 469 UpdateTabSpecificContentSettings(audio_setting, video_setting); |
| 469 } | 470 } |
| 470 | 471 |
| 471 content::MediaStreamDevices devices = | 472 content::MediaStreamDevices devices = |
| 472 GetDevices(audio_setting, video_setting); | 473 GetDevices(audio_setting, video_setting); |
| 473 | 474 |
| 474 // If either audio or video are allowed then the callback should report | 475 // If either audio or video are allowed then the callback should report |
| 475 // success, otherwise we report |denial_reason|. | 476 // success, otherwise we report |denial_reason|. |
| 476 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; | 477 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 if (android_permission_blocked) | 641 if (android_permission_blocked) |
| 641 return false; | 642 return false; |
| 642 | 643 |
| 643 // Don't approve device requests if the tab was hidden. | 644 // Don't approve device requests if the tab was hidden. |
| 644 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 645 // 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? | 646 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 646 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 647 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 647 #endif | 648 #endif |
| 648 return true; | 649 return true; |
| 649 } | 650 } |
| OLD | NEW |