| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/permission_bubble_media_access_handler.h" | 5 #include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "chrome/browser/media/webrtc/media_permission.h" | 10 #include "chrome/browser/media/webrtc/media_permission.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 #if BUILDFLAG(ANDROID_JAVA_UI) | 22 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 23 #include <vector> | 23 #include <vector> |
| 24 | 24 |
| 25 #include "base/bind.h" | 25 #include "base/bind.h" |
| 26 #include "base/bind_helpers.h" | 26 #include "base/bind_helpers.h" |
| 27 #include "chrome/browser/android/chrome_feature_list.h" | 27 #include "chrome/browser/android/chrome_feature_list.h" |
| 28 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h" | 28 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h" |
| 29 #include "chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.h" | 29 #include "chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.h" |
| 30 #include "chrome/browser/permissions/permission_dialog_delegate.h" | 30 #include "chrome/browser/permissions/permission_dialog_delegate.h" |
| 31 #include "chrome/browser/permissions/permission_uma_util.h" |
| 31 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 32 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 33 #include "chrome/browser/permissions/permission_util.h" |
| 32 #else | 34 #else |
| 33 #include "chrome/browser/permissions/permission_request_manager.h" | 35 #include "chrome/browser/permissions/permission_request_manager.h" |
| 34 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 36 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 35 | 37 |
| 36 #if BUILDFLAG(ANDROID_JAVA_UI) | 38 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 37 namespace { | 39 namespace { |
| 38 // Callback for the permission update infobar when the site and Chrome | 40 // Callback for the permission update infobar when the site and Chrome |
| 39 // permissions are mismatched on Android. | 41 // permissions are mismatched on Android. |
| 40 void OnPermissionConflictResolved( | 42 void OnPermissionConflictResolved( |
| 41 std::unique_ptr<MediaStreamDevicesController> controller, | 43 std::unique_ptr<MediaStreamDevicesController> controller, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 // PermissionBubbleMediaAccessHandler should be created on UI thread. | 69 // PermissionBubbleMediaAccessHandler should be created on UI thread. |
| 68 // Otherwise, it will not receive | 70 // Otherwise, it will not receive |
| 69 // content::NOTIFICATION_WEB_CONTENTS_DESTROYED, and that will result in | 71 // content::NOTIFICATION_WEB_CONTENTS_DESTROYED, and that will result in |
| 70 // possible use after free. | 72 // possible use after free. |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 72 notifications_registrar_.Add(this, | 74 notifications_registrar_.Add(this, |
| 73 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 75 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 74 content::NotificationService::AllSources()); | 76 content::NotificationService::AllSources()); |
| 75 } | 77 } |
| 76 | 78 |
| 77 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() { | 79 PermissionBubbleMediaAccessHandler::~PermissionBubbleMediaAccessHandler() {} |
| 78 } | |
| 79 | 80 |
| 80 bool PermissionBubbleMediaAccessHandler::SupportsStreamType( | 81 bool PermissionBubbleMediaAccessHandler::SupportsStreamType( |
| 81 const content::MediaStreamType type, | 82 const content::MediaStreamType type, |
| 82 const extensions::Extension* extension) { | 83 const extensions::Extension* extension) { |
| 83 #if BUILDFLAG(ANDROID_JAVA_UI) | 84 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 84 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || | 85 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || |
| 85 type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 86 type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 86 type == content::MEDIA_DESKTOP_VIDEO_CAPTURE; | 87 type == content::MEDIA_DESKTOP_VIDEO_CAPTURE; |
| 87 #else | 88 #else |
| 88 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || | 89 return type == content::MEDIA_DEVICE_VIDEO_CAPTURE || |
| 89 type == content::MEDIA_DEVICE_AUDIO_CAPTURE; | 90 type == content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 90 #endif | 91 #endif |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission( | 94 bool PermissionBubbleMediaAccessHandler::CheckMediaAccessPermission( |
| 94 content::WebContents* web_contents, | 95 content::WebContents* web_contents, |
| 95 const GURL& security_origin, | 96 const GURL& security_origin, |
| 96 content::MediaStreamType type, | 97 content::MediaStreamType type, |
| 97 const extensions::Extension* extension) { | 98 const extensions::Extension* extension) { |
| 98 Profile* profile = | 99 Profile* profile = |
| 99 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 100 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 100 ContentSettingsType content_settings_type = | 101 ContentSettingsType content_settings_type = |
| 101 type == content::MEDIA_DEVICE_AUDIO_CAPTURE | 102 type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 102 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 103 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 103 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | 104 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; |
| 104 | 105 |
| 105 MediaPermission permission(content_settings_type, security_origin, | 106 MediaPermission permission(content_settings_type, security_origin, |
| 106 web_contents->GetLastCommittedURL().GetOrigin(), profile); | 107 web_contents->GetLastCommittedURL().GetOrigin(), |
| 108 profile); |
| 107 content::MediaStreamRequestResult unused; | 109 content::MediaStreamRequestResult unused; |
| 108 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW; | 110 return permission.GetPermissionStatus(&unused) == CONTENT_SETTING_ALLOW; |
| 109 } | 111 } |
| 110 | 112 |
| 111 void PermissionBubbleMediaAccessHandler::HandleRequest( | 113 void PermissionBubbleMediaAccessHandler::HandleRequest( |
| 112 content::WebContents* web_contents, | 114 content::WebContents* web_contents, |
| 113 const content::MediaStreamRequest& request, | 115 const content::MediaStreamRequest& request, |
| 114 const content::MediaResponseCallback& callback, | 116 const content::MediaResponseCallback& callback, |
| 115 const extensions::Extension* extension) { | 117 const extensions::Extension* extension) { |
| 116 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 179 |
| 178 if (controller->IsAllowedForVideo()) { | 180 if (controller->IsAllowedForVideo()) { |
| 179 content_settings_types.push_back( | 181 content_settings_types.push_back( |
| 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 182 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 181 } | 183 } |
| 182 if (!content_settings_types.empty() && | 184 if (!content_settings_types.empty() && |
| 183 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( | 185 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( |
| 184 web_contents, content_settings_types)) { | 186 web_contents, content_settings_types)) { |
| 185 PermissionUpdateInfoBarDelegate::Create( | 187 PermissionUpdateInfoBarDelegate::Create( |
| 186 web_contents, content_settings_types, | 188 web_contents, content_settings_types, |
| 187 base::Bind( | 189 base::Bind(&OnPermissionConflictResolved, base::Passed(&controller))); |
| 188 &OnPermissionConflictResolved, base::Passed(&controller))); | |
| 189 } | 190 } |
| 190 #endif | 191 #endif |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 | 194 |
| 194 #if BUILDFLAG(ANDROID_JAVA_UI) | 195 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 196 PermissionUmaUtil::RecordPermissionPromptShown( |
| 197 controller->GetPermissionRequestType(), |
| 198 PermissionUtil::GetGestureType(request.user_gesture)); |
| 195 if (PermissionDialogDelegate::ShouldShowDialog(request.user_gesture)) { | 199 if (PermissionDialogDelegate::ShouldShowDialog(request.user_gesture)) { |
| 196 PermissionDialogDelegate::CreateMediaStreamDialog(web_contents, | 200 PermissionDialogDelegate::CreateMediaStreamDialog( |
| 197 std::move(controller)); | 201 web_contents, request.user_gesture, std::move(controller)); |
| 198 } else { | 202 } else { |
| 199 MediaStreamInfoBarDelegateAndroid::Create(web_contents, | 203 MediaStreamInfoBarDelegateAndroid::Create( |
| 200 std::move(controller)); | 204 web_contents, request.user_gesture, std::move(controller)); |
| 201 } | 205 } |
| 202 #else | 206 #else |
| 203 PermissionRequestManager* permission_request_manager = | 207 PermissionRequestManager* permission_request_manager = |
| 204 PermissionRequestManager::FromWebContents(web_contents); | 208 PermissionRequestManager::FromWebContents(web_contents); |
| 205 if (permission_request_manager) | 209 if (permission_request_manager) |
| 206 permission_request_manager->AddRequest(controller.release()); | 210 permission_request_manager->AddRequest(controller.release()); |
| 207 #endif | 211 #endif |
| 208 } | 212 } |
| 209 | 213 |
| 210 void PermissionBubbleMediaAccessHandler::UpdateMediaRequestState( | 214 void PermissionBubbleMediaAccessHandler::UpdateMediaRequestState( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 276 |
| 273 void PermissionBubbleMediaAccessHandler::Observe( | 277 void PermissionBubbleMediaAccessHandler::Observe( |
| 274 int type, | 278 int type, |
| 275 const content::NotificationSource& source, | 279 const content::NotificationSource& source, |
| 276 const content::NotificationDetails& details) { | 280 const content::NotificationDetails& details) { |
| 277 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 278 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); | 282 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); |
| 279 | 283 |
| 280 pending_requests_.erase(content::Source<content::WebContents>(source).ptr()); | 284 pending_requests_.erase(content::Source<content::WebContents>(source).ptr()); |
| 281 } | 285 } |
| OLD | NEW |