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

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

Powered by Google App Engine
This is Rietveld 408576698