| 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 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 18 #include "chrome/browser/media/media_permission.h" | 18 #include "chrome/browser/media/media_permission.h" |
| 19 #include "chrome/browser/media/media_stream_capture_indicator.h" | 19 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 20 #include "chrome/browser/media/media_stream_device_permissions.h" | 20 #include "chrome/browser/media/media_stream_device_permissions.h" |
| 21 #include "chrome/browser/permissions/permission_uma_util.h" | 21 #include "chrome/browser/permissions/permission_uma_util.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/features.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 28 #include "components/content_settings/core/common/content_settings_pattern.h" | 29 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 29 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
| 30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 32 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/common/media_stream_request.h" | 35 #include "content/public/common/media_stream_request.h" |
| 35 #include "content/public/common/origin_util.h" | 36 #include "content/public/common/origin_util.h" |
| 36 #include "extensions/common/constants.h" | 37 #include "extensions/common/constants.h" |
| 37 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 39 | 40 |
| 40 #if defined(OS_ANDROID) | 41 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 41 #include <vector> | 42 #include <vector> |
| 42 | 43 |
| 43 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 44 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
| 44 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 45 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 45 #include "content/public/browser/android/content_view_core.h" | 46 #include "content/public/browser/android/content_view_core.h" |
| 46 #include "ui/android/window_android.h" | 47 #include "ui/android/window_android.h" |
| 47 #endif // OS_ANDROID | 48 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 48 | 49 |
| 49 using content::BrowserThread; | 50 using content::BrowserThread; |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // Returns true if the given ContentSettingsType is being requested in | 54 // Returns true if the given ContentSettingsType is being requested in |
| 54 // |request|. | 55 // |request|. |
| 55 bool ContentTypeIsRequested(ContentSettingsType type, | 56 bool ContentTypeIsRequested(ContentSettingsType type, |
| 56 const content::MediaStreamRequest& request) { | 57 const content::MediaStreamRequest& request) { |
| 57 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) | 58 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 request_, &denial_reason); | 164 request_, &denial_reason); |
| 164 old_video_setting_ = GetContentSetting( | 165 old_video_setting_ = GetContentSetting( |
| 165 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); | 166 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); |
| 166 | 167 |
| 167 // If either setting is ask, we show the infobar. | 168 // If either setting is ask, we show the infobar. |
| 168 if (old_audio_setting_ == CONTENT_SETTING_ASK || | 169 if (old_audio_setting_ == CONTENT_SETTING_ASK || |
| 169 old_video_setting_ == CONTENT_SETTING_ASK) { | 170 old_video_setting_ == CONTENT_SETTING_ASK) { |
| 170 return; | 171 return; |
| 171 } | 172 } |
| 172 | 173 |
| 173 #if defined(OS_ANDROID) | 174 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 174 std::vector<ContentSettingsType> content_settings_types; | 175 std::vector<ContentSettingsType> content_settings_types; |
| 175 if (IsAllowedForAudio()) | 176 if (IsAllowedForAudio()) |
| 176 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 177 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 177 | 178 |
| 178 if (IsAllowedForVideo()) { | 179 if (IsAllowedForVideo()) { |
| 179 content_settings_types.push_back( | 180 content_settings_types.push_back( |
| 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 181 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 181 } | 182 } |
| 182 | 183 |
| 183 // If the site had been previously granted the access to audio or video but | 184 // If the site had been previously granted the access to audio or video but |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 result = CONTENT_SETTING_ALLOW; | 578 result = CONTENT_SETTING_ALLOW; |
| 578 } else if (user_decision == CONTENT_SETTING_BLOCK) { | 579 } else if (user_decision == CONTENT_SETTING_BLOCK) { |
| 579 result = CONTENT_SETTING_BLOCK; | 580 result = CONTENT_SETTING_BLOCK; |
| 580 } | 581 } |
| 581 } | 582 } |
| 582 return result; | 583 return result; |
| 583 } | 584 } |
| 584 | 585 |
| 585 bool MediaStreamDevicesController::IsUserAcceptAllowed( | 586 bool MediaStreamDevicesController::IsUserAcceptAllowed( |
| 586 ContentSettingsType content_type) const { | 587 ContentSettingsType content_type) const { |
| 587 #if defined(OS_ANDROID) | 588 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 588 content::ContentViewCore* cvc = | 589 content::ContentViewCore* cvc = |
| 589 content::ContentViewCore::FromWebContents(web_contents_); | 590 content::ContentViewCore::FromWebContents(web_contents_); |
| 590 if (!cvc) | 591 if (!cvc) |
| 591 return false; | 592 return false; |
| 592 | 593 |
| 593 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 594 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
| 594 if (!window_android) | 595 if (!window_android) |
| 595 return false; | 596 return false; |
| 596 | 597 |
| 597 std::string android_permission = | 598 std::string android_permission = |
| 598 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); | 599 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); |
| 599 bool android_permission_blocked = false; | 600 bool android_permission_blocked = false; |
| 600 if (!android_permission.empty()) { | 601 if (!android_permission.empty()) { |
| 601 android_permission_blocked = | 602 android_permission_blocked = |
| 602 !window_android->HasPermission(android_permission) && | 603 !window_android->HasPermission(android_permission) && |
| 603 !window_android->CanRequestPermission(android_permission); | 604 !window_android->CanRequestPermission(android_permission); |
| 604 } | 605 } |
| 605 if (android_permission_blocked) | 606 if (android_permission_blocked) |
| 606 return false; | 607 return false; |
| 607 | 608 |
| 608 // Don't approve device requests if the tab was hidden. | 609 // Don't approve device requests if the tab was hidden. |
| 609 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 610 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 610 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 611 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 611 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 612 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 612 #endif | 613 #endif |
| 613 return true; | 614 return true; |
| 614 } | 615 } |
| OLD | NEW |