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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.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/webrtc/media_capture_devices_dispatcher.h" | 17 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
18 #include "chrome/browser/media/webrtc/media_permission.h" | 18 #include "chrome/browser/media/webrtc/media_permission.h" |
19 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 19 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
20 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 20 #include "chrome/browser/media/webrtc/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/permissions/permission_util.h" | 22 #include "chrome/browser/permissions/permission_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/features.h" | |
27 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
28 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
30 #include "components/content_settings/core/common/content_settings_pattern.h" | 29 #include "components/content_settings/core/common/content_settings_pattern.h" |
31 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
32 #include "components/prefs/scoped_user_pref_update.h" | 31 #include "components/prefs/scoped_user_pref_update.h" |
33 #include "components/url_formatter/elide_url.h" | 32 #include "components/url_formatter/elide_url.h" |
34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
36 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
37 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
38 #include "content/public/common/media_stream_request.h" | 37 #include "content/public/common/media_stream_request.h" |
39 #include "content/public/common/origin_util.h" | 38 #include "content/public/common/origin_util.h" |
40 #include "extensions/common/constants.h" | 39 #include "extensions/common/constants.h" |
41 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/gfx/vector_icons_public.h" | 41 #include "ui/gfx/vector_icons_public.h" |
43 | 42 |
44 #if BUILDFLAG(ANDROID_JAVA_UI) | 43 #if defined(OS_ANDROID) |
45 #include <vector> | 44 #include <vector> |
46 | 45 |
47 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 46 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
48 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 47 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
49 #include "chrome/grit/theme_resources.h" | 48 #include "chrome/grit/theme_resources.h" |
50 #include "content/public/browser/android/content_view_core.h" | 49 #include "content/public/browser/android/content_view_core.h" |
51 #include "ui/android/window_android.h" | 50 #include "ui/android/window_android.h" |
52 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 51 #endif // defined(OS_ANDROID) |
53 | 52 |
54 using content::BrowserThread; | 53 using content::BrowserThread; |
55 | 54 |
56 namespace { | 55 namespace { |
57 | 56 |
58 // Returns true if the given ContentSettingsType is being requested in | 57 // Returns true if the given ContentSettingsType is being requested in |
59 // |request|. | 58 // |request|. |
60 bool ContentTypeIsRequested(content::PermissionType type, | 59 bool ContentTypeIsRequested(content::PermissionType type, |
61 const content::MediaStreamRequest& request) { | 60 const content::MediaStreamRequest& request) { |
62 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) | 61 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 request_, &denial_reason); | 177 request_, &denial_reason); |
179 old_video_setting_ = GetContentSetting( | 178 old_video_setting_ = GetContentSetting( |
180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); | 179 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); |
181 | 180 |
182 // If either setting is ask, we show the infobar. | 181 // If either setting is ask, we show the infobar. |
183 if (old_audio_setting_ == CONTENT_SETTING_ASK || | 182 if (old_audio_setting_ == CONTENT_SETTING_ASK || |
184 old_video_setting_ == CONTENT_SETTING_ASK) { | 183 old_video_setting_ == CONTENT_SETTING_ASK) { |
185 return; | 184 return; |
186 } | 185 } |
187 | 186 |
188 #if BUILDFLAG(ANDROID_JAVA_UI) | 187 #if defined(OS_ANDROID) |
189 std::vector<ContentSettingsType> content_settings_types; | 188 std::vector<ContentSettingsType> content_settings_types; |
190 if (IsAllowedForAudio()) | 189 if (IsAllowedForAudio()) |
191 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 190 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
192 | 191 |
193 if (IsAllowedForVideo()) { | 192 if (IsAllowedForVideo()) { |
194 content_settings_types.push_back( | 193 content_settings_types.push_back( |
195 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 194 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
196 } | 195 } |
197 | 196 |
198 // If the site had been previously granted the access to audio or video but | 197 // If the site had been previously granted the access to audio or video but |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 result = CONTENT_SETTING_ALLOW; | 594 result = CONTENT_SETTING_ALLOW; |
596 } else if (user_decision == CONTENT_SETTING_BLOCK) { | 595 } else if (user_decision == CONTENT_SETTING_BLOCK) { |
597 result = CONTENT_SETTING_BLOCK; | 596 result = CONTENT_SETTING_BLOCK; |
598 } | 597 } |
599 } | 598 } |
600 return result; | 599 return result; |
601 } | 600 } |
602 | 601 |
603 bool MediaStreamDevicesController::IsUserAcceptAllowed( | 602 bool MediaStreamDevicesController::IsUserAcceptAllowed( |
604 ContentSettingsType content_type) const { | 603 ContentSettingsType content_type) const { |
605 #if BUILDFLAG(ANDROID_JAVA_UI) | 604 #if defined(OS_ANDROID) |
606 content::ContentViewCore* cvc = | 605 content::ContentViewCore* cvc = |
607 content::ContentViewCore::FromWebContents(web_contents_); | 606 content::ContentViewCore::FromWebContents(web_contents_); |
608 if (!cvc) | 607 if (!cvc) |
609 return false; | 608 return false; |
610 | 609 |
611 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 610 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
612 if (!window_android) | 611 if (!window_android) |
613 return false; | 612 return false; |
614 | 613 |
615 std::string android_permission = | 614 std::string android_permission = |
616 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); | 615 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); |
617 bool android_permission_blocked = false; | 616 bool android_permission_blocked = false; |
618 if (!android_permission.empty()) { | 617 if (!android_permission.empty()) { |
619 android_permission_blocked = | 618 android_permission_blocked = |
620 !window_android->HasPermission(android_permission) && | 619 !window_android->HasPermission(android_permission) && |
621 !window_android->CanRequestPermission(android_permission); | 620 !window_android->CanRequestPermission(android_permission); |
622 } | 621 } |
623 if (android_permission_blocked) | 622 if (android_permission_blocked) |
624 return false; | 623 return false; |
625 | 624 |
626 // Don't approve device requests if the tab was hidden. | 625 // Don't approve device requests if the tab was hidden. |
627 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 626 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
628 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 627 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
629 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 628 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
630 #endif | 629 #endif |
631 return true; | 630 return true; |
632 } | 631 } |
OLD | NEW |