Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: chrome/browser/media/webrtc/media_stream_devices_controller.cc

Issue 2711883003: Change MediaStreamDevicesController tests to use RequestPermissions function (Closed)
Patch Set: Add test delegate Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 void RenderFrameDeleted( 168 void RenderFrameDeleted(
169 content::RenderFrameHost* render_frame_host) override { 169 content::RenderFrameHost* render_frame_host) override {
170 PageChanged(render_frame_host); 170 PageChanged(render_frame_host);
171 } 171 }
172 172
173 RequestMap::key_type key_; 173 RequestMap::key_type key_;
174 }; 174 };
175 175
176 } // namespace 176 } // namespace
177 177
178 // Implementation of PermissionPromptDelegate which actually shows a permission
179 // prompt.
180 class MediaStreamDevicesController::PermissionPromptDelegateImpl
181 : public MediaStreamDevicesController::PermissionPromptDelegate {
182 public:
183 void ShowPrompt(
184 bool user_gesture,
185 content::WebContents* web_contents,
186 std::unique_ptr<MediaStreamDevicesController> controller) override {
187 #if defined(OS_ANDROID)
188 PermissionUmaUtil::RecordPermissionPromptShown(
189 controller->GetPermissionRequestType(),
190 PermissionUtil::GetGestureType(user_gesture));
191 if (PermissionDialogDelegate::ShouldShowDialog(user_gesture)) {
192 PermissionDialogDelegate::CreateMediaStreamDialog(
193 web_contents, user_gesture, std::move(controller));
194 } else {
195 MediaStreamInfoBarDelegateAndroid::Create(web_contents, user_gesture,
196 std::move(controller));
197 }
198 #else
199 PermissionRequestManager* permission_request_manager =
200 PermissionRequestManager::FromWebContents(web_contents);
201 if (permission_request_manager)
202 permission_request_manager->AddRequest(controller.release());
203 #endif
204 }
205 };
206
178 // static 207 // static
179 void MediaStreamDevicesController::RequestPermissions( 208 void MediaStreamDevicesController::RequestPermissions(
180 content::WebContents* web_contents, 209 content::WebContents* web_contents,
181 const content::MediaStreamRequest& request, 210 const content::MediaStreamRequest& request,
182 const content::MediaResponseCallback& callback) { 211 const content::MediaResponseCallback& callback) {
183 std::unique_ptr<MediaStreamDevicesController> controller( 212 PermissionPromptDelegateImpl delegate;
184 new MediaStreamDevicesController(web_contents, request, callback)); 213 RequestPermissionsWithDelegate(web_contents, request, callback, &delegate);
185 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) {
186 #if defined(OS_ANDROID)
187 // If either audio or video was previously allowed and Chrome no longer has
188 // the necessary permissions, show a infobar to attempt to address this
189 // mismatch.
190 std::vector<ContentSettingsType> content_settings_types;
191 if (controller->IsAllowedForAudio())
192 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
193
194 if (controller->IsAllowedForVideo()) {
195 content_settings_types.push_back(
196 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
197 }
198 if (!content_settings_types.empty() &&
199 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
200 web_contents, content_settings_types)) {
201 PermissionUpdateInfoBarDelegate::Create(
202 web_contents, content_settings_types,
203 base::Bind(&OnPermissionConflictResolved, base::Passed(&controller)));
204 }
205 #endif
206 return;
207 }
208
209 #if defined(OS_ANDROID)
210 PermissionUmaUtil::RecordPermissionPromptShown(
211 controller->GetPermissionRequestType(),
212 PermissionUtil::GetGestureType(request.user_gesture));
213 if (PermissionDialogDelegate::ShouldShowDialog(request.user_gesture)) {
214 PermissionDialogDelegate::CreateMediaStreamDialog(
215 web_contents, request.user_gesture, std::move(controller));
216 } else {
217 MediaStreamInfoBarDelegateAndroid::Create(
218 web_contents, request.user_gesture, std::move(controller));
219 }
220 #else
221 PermissionRequestManager* permission_request_manager =
222 PermissionRequestManager::FromWebContents(web_contents);
223 if (permission_request_manager)
224 permission_request_manager->AddRequest(controller.release());
225 #endif
226 } 214 }
227 215
228 // static 216 // static
229 void MediaStreamDevicesController::RegisterProfilePrefs( 217 void MediaStreamDevicesController::RegisterProfilePrefs(
230 user_prefs::PrefRegistrySyncable* prefs) { 218 user_prefs::PrefRegistrySyncable* prefs) {
231 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); 219 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true);
232 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, true); 220 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, true);
233 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls); 221 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls);
234 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls); 222 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls);
235 } 223 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 317
330 void MediaStreamDevicesController::RequestFinished() { 318 void MediaStreamDevicesController::RequestFinished() {
331 delete this; 319 delete this;
332 } 320 }
333 321
334 PermissionRequestType MediaStreamDevicesController::GetPermissionRequestType() 322 PermissionRequestType MediaStreamDevicesController::GetPermissionRequestType()
335 const { 323 const {
336 return PermissionRequestType::MEDIA_STREAM; 324 return PermissionRequestType::MEDIA_STREAM;
337 } 325 }
338 326
327 // static
328 void MediaStreamDevicesController::RequestPermissionsWithDelegate(
329 content::WebContents* web_contents,
330 const content::MediaStreamRequest& request,
331 const content::MediaResponseCallback& callback,
332 PermissionPromptDelegate* delegate) {
333 std::unique_ptr<MediaStreamDevicesController> controller(
334 new MediaStreamDevicesController(web_contents, request, callback));
335 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) {
336 #if defined(OS_ANDROID)
337 // If either audio or video was previously allowed and Chrome no longer has
338 // the necessary permissions, show a infobar to attempt to address this
339 // mismatch.
340 std::vector<ContentSettingsType> content_settings_types;
341 if (controller->IsAllowedForAudio())
342 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
343
344 if (controller->IsAllowedForVideo()) {
345 content_settings_types.push_back(
346 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
347 }
348 if (!content_settings_types.empty() &&
349 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
350 web_contents, content_settings_types)) {
351 PermissionUpdateInfoBarDelegate::Create(
352 web_contents, content_settings_types,
353 base::Bind(&OnPermissionConflictResolved, base::Passed(&controller)));
354 }
355 #endif
356 return;
357 }
358
359 delegate->ShowPrompt(request.user_gesture, web_contents,
360 std::move(controller));
361 }
362
339 MediaStreamDevicesController::MediaStreamDevicesController( 363 MediaStreamDevicesController::MediaStreamDevicesController(
340 content::WebContents* web_contents, 364 content::WebContents* web_contents,
341 const content::MediaStreamRequest& request, 365 const content::MediaStreamRequest& request,
342 const content::MediaResponseCallback& callback) 366 const content::MediaResponseCallback& callback)
343 : web_contents_(web_contents), request_(request), callback_(callback) { 367 : web_contents_(web_contents), request_(request), callback_(callback) {
344 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { 368 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {
345 MediaPermissionRequestLogger::LogRequest( 369 MediaPermissionRequestLogger::LogRequest(
346 web_contents, request.render_process_id, request.render_frame_id, 370 web_contents, request.render_process_id, request.render_frame_id,
347 content::IsOriginSecure(request_.security_origin)); 371 content::IsOriginSecure(request_.security_origin));
348 } 372 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 683 }
660 } 684 }
661 685
662 // Don't approve device requests if the tab was hidden. 686 // Don't approve device requests if the tab was hidden.
663 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 687 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
664 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 688 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
665 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 689 return web_contents_->GetRenderWidgetHostView()->IsShowing();
666 #endif 690 #endif
667 return true; 691 return true;
668 } 692 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698