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

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

Issue 2123863004: ScreenCapture for Android phase1, part II (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UI tweaking and rebase Created 4 years, 4 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/media_stream_devices_controller.h" 5 #include "chrome/browser/media/media_stream_devices_controller.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
18 #include "chrome/browser/media/desktop_streams_registry.h"
18 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 19 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
19 #include "chrome/browser/media/media_permission.h" 20 #include "chrome/browser/media/media_permission.h"
20 #include "chrome/browser/media/media_stream_capture_indicator.h" 21 #include "chrome/browser/media/media_stream_capture_indicator.h"
21 #include "chrome/browser/media/media_stream_device_permissions.h" 22 #include "chrome/browser/media/media_stream_device_permissions.h"
22 #include "chrome/browser/permissions/permission_uma_util.h" 23 #include "chrome/browser/permissions/permission_uma_util.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/features.h" 27 #include "chrome/common/features.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
29 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
30 #include "components/content_settings/core/common/content_settings_pattern.h" 31 #include "components/content_settings/core/common/content_settings_pattern.h"
31 #include "components/pref_registry/pref_registry_syncable.h" 32 #include "components/pref_registry/pref_registry_syncable.h"
32 #include "components/prefs/scoped_user_pref_update.h" 33 #include "components/prefs/scoped_user_pref_update.h"
33 #include "components/url_formatter/elide_url.h" 34 #include "components/url_formatter/elide_url.h"
34 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/permission_type.h" 36 #include "content/public/browser/permission_type.h"
36 #include "content/public/browser/render_frame_host.h" 37 #include "content/public/browser/render_frame_host.h"
37 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/render_widget_host_view.h" 39 #include "content/public/browser/render_widget_host_view.h"
39 #include "content/public/common/media_stream_request.h" 40 #include "content/public/common/media_stream_request.h"
40 #include "content/public/common/origin_util.h" 41 #include "content/public/common/origin_util.h"
41 #include "extensions/common/constants.h" 42 #include "extensions/common/constants.h"
42 #include "grit/theme_resources.h" 43 #include "grit/theme_resources.h"
44 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h"
43 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
44 46
45 #if BUILDFLAG(ANDROID_JAVA_UI) 47 #if BUILDFLAG(ANDROID_JAVA_UI)
46 #include <vector> 48 #include <vector>
47 49
48 #include "chrome/browser/android/preferences/pref_service_bridge.h" 50 #include "chrome/browser/android/preferences/pref_service_bridge.h"
49 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" 51 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h"
50 #include "content/public/browser/android/content_view_core.h" 52 #include "content/public/browser/android/content_view_core.h"
51 #include "ui/android/window_android.h" 53 #include "ui/android/window_android.h"
52 #endif // BUILDFLAG(ANDROID_JAVA_UI) 54 #endif // BUILDFLAG(ANDROID_JAVA_UI)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 199 }
198 200
199 // If the site had been previously granted the access to audio or video but 201 // If the site had been previously granted the access to audio or video but
200 // Chrome is now missing the necessary permission, we need to show an infobar 202 // Chrome is now missing the necessary permission, we need to show an infobar
201 // to resolve the difference. 203 // to resolve the difference.
202 if (!content_settings_types.empty() && 204 if (!content_settings_types.empty() &&
203 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( 205 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
204 web_contents, content_settings_types)) { 206 web_contents, content_settings_types)) {
205 return; 207 return;
206 } 208 }
209
210 // Always show infobar for screen capture on Android.
211 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE)
212 return;
207 #endif 213 #endif
208 214
209 // Otherwise we can run the callback immediately. 215 // Otherwise we can run the callback immediately.
210 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); 216 RunCallback(old_audio_setting_, old_video_setting_, denial_reason);
211 } 217 }
212 218
213 MediaStreamDevicesController::~MediaStreamDevicesController() { 219 MediaStreamDevicesController::~MediaStreamDevicesController() {
214 if (!callback_.is_null()) { 220 if (!callback_.is_null()) {
215 RecordPermissionAction(request_, profile_, 221 RecordPermissionAction(request_, profile_,
216 base::Bind(PermissionUmaUtil::PermissionIgnored)); 222 base::Bind(PermissionUmaUtil::PermissionIgnored));
(...skipping 21 matching lines...) Expand all
238 } 244 }
239 245
240 bool MediaStreamDevicesController::IsAskingForAudio() const { 246 bool MediaStreamDevicesController::IsAskingForAudio() const {
241 return old_audio_setting_ == CONTENT_SETTING_ASK; 247 return old_audio_setting_ == CONTENT_SETTING_ASK;
242 } 248 }
243 249
244 bool MediaStreamDevicesController::IsAskingForVideo() const { 250 bool MediaStreamDevicesController::IsAskingForVideo() const {
245 return old_video_setting_ == CONTENT_SETTING_ASK; 251 return old_video_setting_ == CONTENT_SETTING_ASK;
246 } 252 }
247 253
254 bool MediaStreamDevicesController::IsAskingForScreenCapture() const {
255 return request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE;
256 }
257
248 base::string16 MediaStreamDevicesController::GetMessageText() const { 258 base::string16 MediaStreamDevicesController::GetMessageText() const {
249 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; 259 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO;
250 if (!IsAskingForAudio()) 260 if (IsAskingForScreenCapture()) {
261 message_id = IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT;
262 } else if (!IsAskingForAudio()) {
251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; 263 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
252 else if (!IsAskingForVideo()) 264 } else if (!IsAskingForVideo()) {
253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; 265 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY;
266 }
267
254 return l10n_util::GetStringFUTF16( 268 return l10n_util::GetStringFUTF16(
255 message_id, 269 message_id,
256 url_formatter::FormatUrlForSecurityDisplay( 270 url_formatter::FormatUrlForSecurityDisplay(
257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 271 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
258 } 272 }
259 273
260 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { 274 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() {
261 base::AutoReset<bool> persist_permissions( 275 base::AutoReset<bool> persist_permissions(
262 &persist_permission_changes_, false); 276 &persist_permission_changes_, false);
263 // TODO(tsergeant): Determine whether it is appropriate to record permission 277 // TODO(tsergeant): Determine whether it is appropriate to record permission
(...skipping 19 matching lines...) Expand all
283 return l10n_util::GetStringUTF16(message_id); 297 return l10n_util::GetStringUTF16(message_id);
284 } 298 }
285 299
286 GURL MediaStreamDevicesController::GetOrigin() const { 300 GURL MediaStreamDevicesController::GetOrigin() const {
287 return request_.security_origin; 301 return request_.security_origin;
288 } 302 }
289 303
290 void MediaStreamDevicesController::PermissionGranted() { 304 void MediaStreamDevicesController::PermissionGranted() {
291 RecordPermissionAction(request_, profile_, 305 RecordPermissionAction(request_, profile_,
292 base::Bind(PermissionUmaUtil::PermissionGranted)); 306 base::Bind(PermissionUmaUtil::PermissionGranted));
293 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 307 if (IsAskingForScreenCapture()) {
294 old_audio_setting_, CONTENT_SETTING_ALLOW), 308 RunCallback(old_audio_setting_, old_video_setting_,
295 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 309 content::MEDIA_DEVICE_OK);
296 old_video_setting_, CONTENT_SETTING_ALLOW), 310 } else {
297 content::MEDIA_DEVICE_PERMISSION_DENIED); 311 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
312 old_audio_setting_, CONTENT_SETTING_ALLOW),
313 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
314 old_video_setting_, CONTENT_SETTING_ALLOW),
315 content::MEDIA_DEVICE_PERMISSION_DENIED);
316 }
298 } 317 }
299 318
300 void MediaStreamDevicesController::PermissionDenied() { 319 void MediaStreamDevicesController::PermissionDenied() {
301 RecordPermissionAction(request_, profile_, 320 RecordPermissionAction(request_, profile_,
302 base::Bind(PermissionUmaUtil::PermissionDenied)); 321 base::Bind(PermissionUmaUtil::PermissionDenied));
303 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 322 if (IsAskingForScreenCapture()) {
304 old_audio_setting_, CONTENT_SETTING_BLOCK), 323 RunCallback(old_audio_setting_, old_video_setting_,
305 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 324 content::MEDIA_DEVICE_PERMISSION_DENIED);
306 old_video_setting_, CONTENT_SETTING_BLOCK), 325 } else {
307 content::MEDIA_DEVICE_PERMISSION_DENIED); 326 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
327 old_audio_setting_, CONTENT_SETTING_BLOCK),
328 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
329 old_video_setting_, CONTENT_SETTING_BLOCK),
330 content::MEDIA_DEVICE_PERMISSION_DENIED);
331 }
308 } 332 }
309 333
310 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, 334 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted,
311 bool video_accepted) { 335 bool video_accepted) {
312 RecordSinglePermissionAction( 336 RecordSinglePermissionAction(
313 request_, content::PermissionType::AUDIO_CAPTURE, profile_, 337 request_, content::PermissionType::AUDIO_CAPTURE, profile_,
314 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted 338 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted
315 : PermissionUmaUtil::PermissionDenied)); 339 : PermissionUmaUtil::PermissionDenied));
316 RecordSinglePermissionAction( 340 RecordSinglePermissionAction(
317 request_, content::PermissionType::VIDEO_CAPTURE, profile_, 341 request_, content::PermissionType::VIDEO_CAPTURE, profile_,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // setting. 488 // setting.
465 if (persist_permission_changes_ && 489 if (persist_permission_changes_ &&
466 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { 490 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) {
467 StorePermission(audio_setting, video_setting); 491 StorePermission(audio_setting, video_setting);
468 UpdateTabSpecificContentSettings(audio_setting, video_setting); 492 UpdateTabSpecificContentSettings(audio_setting, video_setting);
469 } 493 }
470 494
471 content::MediaStreamDevices devices = 495 content::MediaStreamDevices devices =
472 GetDevices(audio_setting, video_setting); 496 GetDevices(audio_setting, video_setting);
473 497
474 // If either audio or video are allowed then the callback should report
475 // success, otherwise we report |denial_reason|.
476 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; 498 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK;
477 if (audio_setting != CONTENT_SETTING_ALLOW && 499 if (IsAskingForScreenCapture()) {
478 video_setting != CONTENT_SETTING_ALLOW) { 500 request_result = denial_reason;
501 if (request_result == content::MEDIA_DEVICE_OK) {
502 content::DesktopMediaID screen_id;
503 screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN,
504 webrtc::kFullDesktopScreenId);
505 devices.push_back(
506 content::MediaStreamDevice(content::MEDIA_DESKTOP_VIDEO_CAPTURE,
507 screen_id.ToString(), "Screen"));
508 }
509 } else if (audio_setting != CONTENT_SETTING_ALLOW &&
510 video_setting != CONTENT_SETTING_ALLOW) {
511 // If either audio or video are allowed then the callback should report
512 // success, otherwise we report |denial_reason|.
479 DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason); 513 DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason);
480 request_result = denial_reason; 514 request_result = denial_reason;
481 } else if (devices.empty()) { 515 } else if (devices.empty()) {
482 // Even if one of the content settings was allowed, if there are no devices 516 // Even if one of the content settings was allowed, if there are no devices
483 // at this point we still report a failure. 517 // at this point we still report a failure.
484 request_result = content::MEDIA_DEVICE_NO_HARDWARE; 518 request_result = content::MEDIA_DEVICE_NO_HARDWARE;
485 } 519 }
486 520
487 std::unique_ptr<content::MediaStreamUI> ui; 521 std::unique_ptr<content::MediaStreamUI> ui;
488 if (!devices.empty()) { 522 if (!devices.empty()) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 if (android_permission_blocked) 674 if (android_permission_blocked)
641 return false; 675 return false;
642 676
643 // Don't approve device requests if the tab was hidden. 677 // Don't approve device requests if the tab was hidden.
644 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 678 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
645 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 679 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
646 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 680 return web_contents_->GetRenderWidgetHostView()->IsShowing();
647 #endif 681 #endif
648 return true; 682 return true;
649 } 683 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698