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