| 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/permission_bubble_media_access_handler.h" | 5 #include "chrome/browser/media/permission_bubble_media_access_handler.h" |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "chrome/browser/media/media_permission.h" | 8 #include "chrome/browser/media/media_permission.h" |
| 9 #include "chrome/browser/media/media_stream_device_permissions.h" | 9 #include "chrome/browser/media/media_stream_device_permissions.h" |
| 10 #include "chrome/browser/media/media_stream_devices_controller.h" | 10 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/features.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 | 19 |
| 19 #if defined(OS_ANDROID) | 20 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 20 #include <vector> | 21 #include <vector> |
| 21 | 22 |
| 22 #include "base/bind.h" | 23 #include "base/bind.h" |
| 23 #include "base/bind_helpers.h" | 24 #include "base/bind_helpers.h" |
| 24 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" | 25 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" |
| 25 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 26 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 26 #else | 27 #else |
| 27 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 28 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 28 #endif // OS_ANDROID | 29 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 29 | 30 |
| 30 #if defined(OS_ANDROID) | 31 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 31 namespace { | 32 namespace { |
| 32 // Callback for the permission update infobar when the site and Chrome | 33 // Callback for the permission update infobar when the site and Chrome |
| 33 // permissions are mismatched on Android. | 34 // permissions are mismatched on Android. |
| 34 void OnPermissionConflictResolved( | 35 void OnPermissionConflictResolved( |
| 35 scoped_ptr<MediaStreamDevicesController> controller, bool allowed) { | 36 scoped_ptr<MediaStreamDevicesController> controller, bool allowed) { |
| 36 if (allowed) | 37 if (allowed) |
| 37 controller->PermissionGranted(); | 38 controller->PermissionGranted(); |
| 38 else | 39 else |
| 39 controller->ForcePermissionDeniedTemporarily(); | 40 controller->ForcePermissionDeniedTemporarily(); |
| 40 } | 41 } |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 #endif // OS_ANDROID | 44 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 44 | 45 |
| 45 using content::BrowserThread; | 46 using content::BrowserThread; |
| 46 | 47 |
| 47 struct PermissionBubbleMediaAccessHandler::PendingAccessRequest { | 48 struct PermissionBubbleMediaAccessHandler::PendingAccessRequest { |
| 48 PendingAccessRequest(const content::MediaStreamRequest& request, | 49 PendingAccessRequest(const content::MediaStreamRequest& request, |
| 49 const content::MediaResponseCallback& callback) | 50 const content::MediaResponseCallback& callback) |
| 50 : request(request), callback(callback) {} | 51 : request(request), callback(callback) {} |
| 51 ~PendingAccessRequest() {} | 52 ~PendingAccessRequest() {} |
| 52 | 53 |
| 53 // TODO(gbillock): make the MediaStreamDevicesController owned by | 54 // TODO(gbillock): make the MediaStreamDevicesController owned by |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 DCHECK(!it->second.empty()); | 136 DCHECK(!it->second.empty()); |
| 136 | 137 |
| 137 scoped_ptr<MediaStreamDevicesController> controller( | 138 scoped_ptr<MediaStreamDevicesController> controller( |
| 138 new MediaStreamDevicesController( | 139 new MediaStreamDevicesController( |
| 139 web_contents, it->second.front().request, | 140 web_contents, it->second.front().request, |
| 140 base::Bind( | 141 base::Bind( |
| 141 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, | 142 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, |
| 142 base::Unretained(this), web_contents))); | 143 base::Unretained(this), web_contents))); |
| 143 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) { | 144 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) { |
| 144 #if defined(OS_ANDROID) | 145 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 145 // If either audio or video was previously allowed and Chrome no longer has | 146 // If either audio or video was previously allowed and Chrome no longer has |
| 146 // the necessary permissions, show a infobar to attempt to address this | 147 // the necessary permissions, show a infobar to attempt to address this |
| 147 // mismatch. | 148 // mismatch. |
| 148 std::vector<ContentSettingsType> content_settings_types; | 149 std::vector<ContentSettingsType> content_settings_types; |
| 149 if (controller->IsAllowedForAudio()) | 150 if (controller->IsAllowedForAudio()) |
| 150 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 151 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 151 | 152 |
| 152 if (controller->IsAllowedForVideo()) { | 153 if (controller->IsAllowedForVideo()) { |
| 153 content_settings_types.push_back( | 154 content_settings_types.push_back( |
| 154 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 155 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 155 } | 156 } |
| 156 if (!content_settings_types.empty() && | 157 if (!content_settings_types.empty() && |
| 157 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( | 158 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( |
| 158 web_contents, content_settings_types)) { | 159 web_contents, content_settings_types)) { |
| 159 PermissionUpdateInfoBarDelegate::Create( | 160 PermissionUpdateInfoBarDelegate::Create( |
| 160 web_contents, content_settings_types, | 161 web_contents, content_settings_types, |
| 161 base::Bind( | 162 base::Bind( |
| 162 &OnPermissionConflictResolved, base::Passed(&controller))); | 163 &OnPermissionConflictResolved, base::Passed(&controller))); |
| 163 } | 164 } |
| 164 #endif | 165 #endif |
| 165 return; | 166 return; |
| 166 } | 167 } |
| 167 | 168 |
| 168 #if defined(OS_ANDROID) | 169 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 169 MediaStreamInfoBarDelegateAndroid::Create(web_contents, controller.Pass()); | 170 MediaStreamInfoBarDelegateAndroid::Create(web_contents, controller.Pass()); |
| 170 #else | 171 #else |
| 171 PermissionBubbleManager* bubble_manager = | 172 PermissionBubbleManager* bubble_manager = |
| 172 PermissionBubbleManager::FromWebContents(web_contents); | 173 PermissionBubbleManager::FromWebContents(web_contents); |
| 173 if (bubble_manager) | 174 if (bubble_manager) |
| 174 bubble_manager->AddRequest(controller.release()); | 175 bubble_manager->AddRequest(controller.release()); |
| 175 #endif | 176 #endif |
| 176 } | 177 } |
| 177 | 178 |
| 178 void PermissionBubbleMediaAccessHandler::UpdateMediaRequestState( | 179 void PermissionBubbleMediaAccessHandler::UpdateMediaRequestState( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 int type, | 243 int type, |
| 243 const content::NotificationSource& source, | 244 const content::NotificationSource& source, |
| 244 const content::NotificationDetails& details) { | 245 const content::NotificationDetails& details) { |
| 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 246 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 247 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 247 content::WebContents* web_contents = | 248 content::WebContents* web_contents = |
| 248 content::Source<content::WebContents>(source).ptr(); | 249 content::Source<content::WebContents>(source).ptr(); |
| 249 pending_requests_.erase(web_contents); | 250 pending_requests_.erase(web_contents); |
| 250 } | 251 } |
| 251 } | 252 } |
| OLD | NEW |