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

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: Created 4 years, 5 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 191 }
190 192
191 // If the site had been previously granted the access to audio or video but 193 // If the site had been previously granted the access to audio or video but
192 // Chrome is now missing the necessary permission, we need to show an infobar 194 // Chrome is now missing the necessary permission, we need to show an infobar
193 // to resolve the difference. 195 // to resolve the difference.
194 if (!content_settings_types.empty() && 196 if (!content_settings_types.empty() &&
195 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( 197 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
196 web_contents, content_settings_types)) { 198 web_contents, content_settings_types)) {
197 return; 199 return;
198 } 200 }
201
202 // Always show infobar for screen capture on Android.
203 if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) {
204 return;
205 }
199 #endif 206 #endif
200 207
201 // Otherwise we can run the callback immediately. 208 // Otherwise we can run the callback immediately.
202 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); 209 RunCallback(old_audio_setting_, old_video_setting_, denial_reason);
203 } 210 }
204 211
205 MediaStreamDevicesController::~MediaStreamDevicesController() { 212 MediaStreamDevicesController::~MediaStreamDevicesController() {
206 if (!callback_.is_null()) { 213 if (!callback_.is_null()) {
207 RecordPermissionAction( 214 RecordPermissionAction(
208 request_, base::Bind(PermissionUmaUtil::PermissionIgnored)); 215 request_, base::Bind(PermissionUmaUtil::PermissionIgnored));
(...skipping 21 matching lines...) Expand all
230 } 237 }
231 238
232 bool MediaStreamDevicesController::IsAskingForAudio() const { 239 bool MediaStreamDevicesController::IsAskingForAudio() const {
233 return old_audio_setting_ == CONTENT_SETTING_ASK; 240 return old_audio_setting_ == CONTENT_SETTING_ASK;
234 } 241 }
235 242
236 bool MediaStreamDevicesController::IsAskingForVideo() const { 243 bool MediaStreamDevicesController::IsAskingForVideo() const {
237 return old_video_setting_ == CONTENT_SETTING_ASK; 244 return old_video_setting_ == CONTENT_SETTING_ASK;
238 } 245 }
239 246
247 bool MediaStreamDevicesController::IsAskingForScreenCapture() const {
248 return request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE;
249 }
250
240 base::string16 MediaStreamDevicesController::GetMessageText() const { 251 base::string16 MediaStreamDevicesController::GetMessageText() const {
241 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; 252 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO;
242 if (!IsAskingForAudio()) 253 if (IsAskingForScreenCapture())
254 message_id = IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT;
255 else if (!IsAskingForAudio())
243 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; 256 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY;
244 else if (!IsAskingForVideo()) 257 else if (!IsAskingForVideo())
245 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; 258 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY;
246 return l10n_util::GetStringFUTF16( 259 return l10n_util::GetStringFUTF16(
247 message_id, 260 message_id,
248 url_formatter::FormatUrlForSecurityDisplay( 261 url_formatter::FormatUrlForSecurityDisplay(
249 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 262 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
250 } 263 }
251 264
252 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { 265 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() {
(...skipping 22 matching lines...) Expand all
275 return l10n_util::GetStringUTF16(message_id); 288 return l10n_util::GetStringUTF16(message_id);
276 } 289 }
277 290
278 GURL MediaStreamDevicesController::GetOrigin() const { 291 GURL MediaStreamDevicesController::GetOrigin() const {
279 return request_.security_origin; 292 return request_.security_origin;
280 } 293 }
281 294
282 void MediaStreamDevicesController::PermissionGranted() { 295 void MediaStreamDevicesController::PermissionGranted() {
283 RecordPermissionAction( 296 RecordPermissionAction(
284 request_, base::Bind(PermissionUmaUtil::PermissionGranted)); 297 request_, base::Bind(PermissionUmaUtil::PermissionGranted));
285 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 298 if (IsAskingForScreenCapture()) {
286 old_audio_setting_, CONTENT_SETTING_ALLOW), 299 RunCallback(old_audio_setting_, old_video_setting_,
287 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 300 content::MEDIA_DEVICE_OK);
288 old_video_setting_, CONTENT_SETTING_ALLOW), 301 } else {
289 content::MEDIA_DEVICE_PERMISSION_DENIED); 302 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
303 old_audio_setting_, CONTENT_SETTING_ALLOW),
304 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
305 old_video_setting_, CONTENT_SETTING_ALLOW),
306 content::MEDIA_DEVICE_PERMISSION_DENIED);
307 }
290 } 308 }
291 309
292 void MediaStreamDevicesController::PermissionDenied() { 310 void MediaStreamDevicesController::PermissionDenied() {
293 RecordPermissionAction( 311 RecordPermissionAction(
294 request_, base::Bind(PermissionUmaUtil::PermissionDenied)); 312 request_, base::Bind(PermissionUmaUtil::PermissionDenied));
295 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 313 if (IsAskingForScreenCapture()) {
296 old_audio_setting_, CONTENT_SETTING_BLOCK), 314 RunCallback(old_audio_setting_, old_video_setting_,
297 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 315 content::MEDIA_DEVICE_PERMISSION_DENIED);
298 old_video_setting_, CONTENT_SETTING_BLOCK), 316 } else {
299 content::MEDIA_DEVICE_PERMISSION_DENIED); 317 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
318 old_audio_setting_, CONTENT_SETTING_BLOCK),
319 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
320 old_video_setting_, CONTENT_SETTING_BLOCK),
321 content::MEDIA_DEVICE_PERMISSION_DENIED);
322 }
300 } 323 }
301 324
302 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, 325 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted,
303 bool video_accepted) { 326 bool video_accepted) {
304 RecordSinglePermissionAction( 327 RecordSinglePermissionAction(
305 request_, content::PermissionType::AUDIO_CAPTURE, 328 request_, content::PermissionType::AUDIO_CAPTURE,
306 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted 329 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted
307 : PermissionUmaUtil::PermissionDenied)); 330 : PermissionUmaUtil::PermissionDenied));
308 RecordSinglePermissionAction( 331 RecordSinglePermissionAction(
309 request_, content::PermissionType::VIDEO_CAPTURE, 332 request_, content::PermissionType::VIDEO_CAPTURE,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 StorePermission(audio_setting, video_setting); 482 StorePermission(audio_setting, video_setting);
460 UpdateTabSpecificContentSettings(audio_setting, video_setting); 483 UpdateTabSpecificContentSettings(audio_setting, video_setting);
461 } 484 }
462 485
463 content::MediaStreamDevices devices = 486 content::MediaStreamDevices devices =
464 GetDevices(audio_setting, video_setting); 487 GetDevices(audio_setting, video_setting);
465 488
466 // If either audio or video are allowed then the callback should report 489 // If either audio or video are allowed then the callback should report
467 // success, otherwise we report |denial_reason|. 490 // success, otherwise we report |denial_reason|.
468 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; 491 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK;
469 if (audio_setting != CONTENT_SETTING_ALLOW && 492 if (IsAskingForScreenCapture()) {
470 video_setting != CONTENT_SETTING_ALLOW) { 493 request_result = denial_reason;
494
495 content::DesktopMediaID screen_id;
496 screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN,
497 webrtc::kFullDesktopScreenId);
498 devices.push_back(content::MediaStreamDevice(
499 content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen"));
500 } else if (audio_setting != CONTENT_SETTING_ALLOW &&
501 video_setting != CONTENT_SETTING_ALLOW) {
471 DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason); 502 DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason);
472 request_result = denial_reason; 503 request_result = denial_reason;
473 } else if (devices.empty()) { 504 } else if (devices.empty()) {
474 // Even if one of the content settings was allowed, if there are no devices 505 // Even if one of the content settings was allowed, if there are no devices
475 // at this point we still report a failure. 506 // at this point we still report a failure.
476 request_result = content::MEDIA_DEVICE_NO_HARDWARE; 507 request_result = content::MEDIA_DEVICE_NO_HARDWARE;
477 } 508 }
478 509
479 std::unique_ptr<content::MediaStreamUI> ui; 510 std::unique_ptr<content::MediaStreamUI> ui;
480 if (!devices.empty()) { 511 if (!devices.empty()) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 if (android_permission_blocked) 663 if (android_permission_blocked)
633 return false; 664 return false;
634 665
635 // Don't approve device requests if the tab was hidden. 666 // Don't approve device requests if the tab was hidden.
636 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 667 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
637 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 668 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
638 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 669 return web_contents_->GetRenderWidgetHostView()->IsShowing();
639 #endif 670 #endif
640 return true; 671 return true;
641 } 672 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698