Chromium Code Reviews| 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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/common/media_stream_request.h" | 27 #include "content/public/common/media_stream_request.h" |
| 28 #include "content/public/common/origin_util.h" | 28 #include "content/public/common/origin_util.h" |
| 29 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
| 30 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 | 32 |
| 33 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) |
| 34 #include <vector> | |
| 35 | |
| 34 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 36 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
| 37 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" | |
| 35 #include "content/public/browser/android/content_view_core.h" | 38 #include "content/public/browser/android/content_view_core.h" |
| 36 #include "ui/android/window_android.h" | 39 #include "ui/android/window_android.h" |
| 37 #endif // OS_ANDROID | 40 #endif // OS_ANDROID |
| 38 | 41 |
| 39 using content::BrowserThread; | 42 using content::BrowserThread; |
| 40 | 43 |
| 41 namespace { | 44 namespace { |
| 42 | 45 |
| 43 enum DevicePermissionActions { | 46 enum DevicePermissionActions { |
| 44 kAllowHttps = 0, | 47 kAllowHttps = 0, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 request_, &denial_reason); | 88 request_, &denial_reason); |
| 86 old_video_setting_ = GetContentSetting( | 89 old_video_setting_ = GetContentSetting( |
| 87 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); | 90 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); |
| 88 | 91 |
| 89 // If either setting is ask, we show the infobar. | 92 // If either setting is ask, we show the infobar. |
| 90 if (old_audio_setting_ == CONTENT_SETTING_ASK || | 93 if (old_audio_setting_ == CONTENT_SETTING_ASK || |
| 91 old_video_setting_ == CONTENT_SETTING_ASK) { | 94 old_video_setting_ == CONTENT_SETTING_ASK) { |
| 92 return; | 95 return; |
| 93 } | 96 } |
| 94 | 97 |
| 98 #if defined(OS_ANDROID) | |
| 99 std::vector<ContentSettingsType> content_settings_types; | |
| 100 if (old_audio_setting_ == CONTENT_SETTING_ALLOW) | |
|
Guido Urdaneta
2015/09/23 13:32:14
Shouldn't you use IsAllowedForAudio() and IsAllowe
Ted C
2015/09/23 19:45:34
Done.
| |
| 101 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 102 if (old_video_setting_ == CONTENT_SETTING_ALLOW) | |
| 103 content_settings_types.push_back( | |
| 104 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 105 | |
| 106 // If the site had been previously granted the access to audio or video but | |
| 107 // Chrome is now missing the necessary permission, we need to show an infobar | |
| 108 // to resolve the difference. | |
| 109 if (!content_settings_types.empty() && | |
| 110 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( | |
| 111 web_contents, content_settings_types)) { | |
| 112 return; | |
| 113 } | |
| 114 #endif | |
| 115 | |
| 95 // Otherwise we can run the callback immediately. | 116 // Otherwise we can run the callback immediately. |
| 96 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); | 117 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); |
| 97 } | 118 } |
| 98 | 119 |
| 99 MediaStreamDevicesController::~MediaStreamDevicesController() { | 120 MediaStreamDevicesController::~MediaStreamDevicesController() { |
| 100 if (!callback_.is_null()) { | 121 if (!callback_.is_null()) { |
| 101 callback_.Run(content::MediaStreamDevices(), | 122 callback_.Run(content::MediaStreamDevices(), |
| 102 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, | 123 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
| 103 scoped_ptr<content::MediaStreamUI>()); | 124 scoped_ptr<content::MediaStreamUI>()); |
| 104 } | 125 } |
| 105 } | 126 } |
| 106 | 127 |
| 107 // static | 128 // static |
| 108 void MediaStreamDevicesController::RegisterProfilePrefs( | 129 void MediaStreamDevicesController::RegisterProfilePrefs( |
| 109 user_prefs::PrefRegistrySyncable* prefs) { | 130 user_prefs::PrefRegistrySyncable* prefs) { |
| 110 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); | 131 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); |
| 111 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, true); | 132 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, true); |
| 112 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls); | 133 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls); |
| 113 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls); | 134 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls); |
| 114 } | 135 } |
| 115 | 136 |
| 137 bool MediaStreamDevicesController::IsAllowedForAudio() const { | |
| 138 return old_audio_setting_ == CONTENT_SETTING_ALLOW; | |
| 139 } | |
| 140 | |
| 141 bool MediaStreamDevicesController::IsAllowedForVideo() const { | |
| 142 return old_video_setting_ == CONTENT_SETTING_ALLOW; | |
| 143 } | |
| 144 | |
| 116 bool MediaStreamDevicesController::IsAskingForAudio() const { | 145 bool MediaStreamDevicesController::IsAskingForAudio() const { |
| 117 return old_audio_setting_ == CONTENT_SETTING_ASK; | 146 return old_audio_setting_ == CONTENT_SETTING_ASK; |
| 118 } | 147 } |
| 119 | 148 |
| 120 bool MediaStreamDevicesController::IsAskingForVideo() const { | 149 bool MediaStreamDevicesController::IsAskingForVideo() const { |
| 121 return old_video_setting_ == CONTENT_SETTING_ASK; | 150 return old_video_setting_ == CONTENT_SETTING_ASK; |
| 122 } | 151 } |
| 123 | 152 |
| 124 const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const { | 153 const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const { |
| 125 return request_.security_origin.spec(); | 154 return request_.security_origin.spec(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 331 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 303 } | 332 } |
| 304 | 333 |
| 305 return devices; | 334 return devices; |
| 306 } | 335 } |
| 307 | 336 |
| 308 void MediaStreamDevicesController::RunCallback( | 337 void MediaStreamDevicesController::RunCallback( |
| 309 ContentSetting audio_setting, | 338 ContentSetting audio_setting, |
| 310 ContentSetting video_setting, | 339 ContentSetting video_setting, |
| 311 content::MediaStreamRequestResult denial_reason) { | 340 content::MediaStreamRequestResult denial_reason) { |
| 341 CHECK(!callback_.is_null()); | |
| 312 StorePermission(audio_setting, video_setting); | 342 StorePermission(audio_setting, video_setting); |
| 313 UpdateTabSpecificContentSettings(audio_setting, video_setting); | 343 UpdateTabSpecificContentSettings(audio_setting, video_setting); |
| 314 | 344 |
| 315 content::MediaStreamDevices devices = | 345 content::MediaStreamDevices devices = |
| 316 GetDevices(audio_setting, video_setting); | 346 GetDevices(audio_setting, video_setting); |
| 317 | 347 |
| 318 // If either audio or video are allowed then the callback should report | 348 // If either audio or video are allowed then the callback should report |
| 319 // success, otherwise we report |denial_reason|. | 349 // success, otherwise we report |denial_reason|. |
| 320 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; | 350 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
| 321 if (audio_setting != CONTENT_SETTING_ALLOW && | 351 if (audio_setting != CONTENT_SETTING_ALLOW && |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 if (android_permission_blocked) | 514 if (android_permission_blocked) |
| 485 return false; | 515 return false; |
| 486 | 516 |
| 487 // Don't approve device requests if the tab was hidden. | 517 // Don't approve device requests if the tab was hidden. |
| 488 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 518 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 489 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 519 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 490 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 520 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 491 #endif | 521 #endif |
| 492 return true; | 522 return true; |
| 493 } | 523 } |
| OLD | NEW |