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/desktop_capture_access_handler.h" | 5 #include "chrome/browser/media/desktop_capture_access_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
33 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
34 #include "extensions/common/switches.h" | 34 #include "extensions/common/switches.h" |
35 #include "media/audio/audio_device_description.h" | 35 #include "media/audio/audio_device_description.h" |
36 #include "net/base/url_util.h" | 36 #include "net/base/url_util.h" |
37 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" | 37 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" |
38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
39 | 39 |
40 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
41 #include "ash/shell.h" | 41 #include "ash/shell.h" |
42 #include "base/sha1.h" | |
43 #endif // defined(OS_CHROMEOS) | 42 #endif // defined(OS_CHROMEOS) |
44 | 43 |
45 using content::BrowserThread; | 44 using content::BrowserThread; |
46 | 45 |
47 namespace { | 46 namespace { |
48 | 47 |
49 bool IsExtensionWhitelistedForScreenCapture( | |
50 const extensions::Extension* extension) { | |
51 if (!extension) | |
52 return false; | |
53 | |
54 #if defined(OS_CHROMEOS) | |
55 std::string hash = base::SHA1HashString(extension->id()); | |
56 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length()); | |
57 | |
58 // crbug.com/446688 | |
59 return hex_hash == "4F25792AF1AA7483936DE29C07806F203C7170A0" || | |
60 hex_hash == "BD8781D757D830FC2E85470A1B6E8A718B7EE0D9" || | |
61 hex_hash == "4AC2B6C63C6480D150DFDA13E4A5956EB1D0DDBB" || | |
62 hex_hash == "81986D4F846CEDDDB962643FA501D1780DD441BB"; | |
63 #else | |
64 return false; | |
65 #endif // defined(OS_CHROMEOS) | |
66 } | |
67 | |
68 bool IsBuiltInExtension(const GURL& origin) { | |
69 return | |
70 // Feedback Extension. | |
71 origin.spec() == "chrome-extension://gfdkimpbcpahaombhbimeihdjnejgicl/"; | |
72 } | |
73 | |
74 // Helper to get title of the calling application shown in the screen capture | 48 // Helper to get title of the calling application shown in the screen capture |
75 // notification. | 49 // notification. |
76 base::string16 GetApplicationTitle(content::WebContents* web_contents, | 50 base::string16 GetApplicationTitle(content::WebContents* web_contents, |
77 const extensions::Extension* extension) { | 51 const extensions::Extension* extension) { |
78 // Use extension name as title for extensions and host/origin for drive-by | 52 // Use extension name as title for extensions and host/origin for drive-by |
79 // web. | 53 // web. |
80 std::string title; | 54 std::string title; |
81 if (extension) { | 55 if (extension) { |
82 title = extension->name(); | 56 title = extension->name(); |
83 return base::UTF8ToUTF16(title); | 57 return base::UTF8ToUTF16(title); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void DesktopCaptureAccessHandler::ProcessScreenCaptureAccessRequest( | 208 void DesktopCaptureAccessHandler::ProcessScreenCaptureAccessRequest( |
235 content::WebContents* web_contents, | 209 content::WebContents* web_contents, |
236 const content::MediaStreamRequest& request, | 210 const content::MediaStreamRequest& request, |
237 const content::MediaResponseCallback& callback, | 211 const content::MediaResponseCallback& callback, |
238 const extensions::Extension* extension) { | 212 const extensions::Extension* extension) { |
239 content::MediaStreamDevices devices; | 213 content::MediaStreamDevices devices; |
240 std::unique_ptr<content::MediaStreamUI> ui; | 214 std::unique_ptr<content::MediaStreamUI> ui; |
241 | 215 |
242 DCHECK_EQ(request.video_type, content::MEDIA_DESKTOP_VIDEO_CAPTURE); | 216 DCHECK_EQ(request.video_type, content::MEDIA_DESKTOP_VIDEO_CAPTURE); |
243 | 217 |
| 218 UpdateExtensionTrusted(request, extension); |
| 219 |
244 bool loopback_audio_supported = false; | 220 bool loopback_audio_supported = false; |
245 #if defined(USE_CRAS) || defined(OS_WIN) | 221 #if defined(USE_CRAS) || defined(OS_WIN) |
246 // Currently loopback audio capture is supported only on Windows and ChromeOS. | 222 // Currently loopback audio capture is supported only on Windows and ChromeOS. |
247 loopback_audio_supported = true; | 223 loopback_audio_supported = true; |
248 #endif | 224 #endif |
249 | 225 |
250 bool component_extension = false; | 226 bool component_extension = false; |
251 component_extension = | 227 component_extension = |
252 extension && extension->location() == extensions::Manifest::COMPONENT; | 228 extension && extension->location() == extensions::Manifest::COMPONENT; |
253 | 229 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 const bool check_audio_permission = | 414 const bool check_audio_permission = |
439 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 415 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
440 extensions::switches::kDisableDesktopCaptureAudio); | 416 extensions::switches::kDisableDesktopCaptureAudio); |
441 const bool capture_audio = | 417 const bool capture_audio = |
442 (check_audio_permission ? audio_permitted : true) && audio_requested && | 418 (check_audio_permission ? audio_permitted : true) && audio_requested && |
443 audio_supported; | 419 audio_supported; |
444 | 420 |
445 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, true, | 421 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, true, |
446 GetApplicationTitle(web_contents, extension), | 422 GetApplicationTitle(web_contents, extension), |
447 base::UTF8ToUTF16(original_extension_name)); | 423 base::UTF8ToUTF16(original_extension_name)); |
448 | 424 UpdateExtensionTrusted(request, extension); |
449 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); | 425 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); |
450 } | 426 } |
451 | 427 |
452 void DesktopCaptureAccessHandler::UpdateMediaRequestState( | |
453 int render_process_id, | |
454 int render_frame_id, | |
455 int page_request_id, | |
456 content::MediaStreamType stream_type, | |
457 content::MediaRequestState state) { | |
458 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
459 // Track desktop capture sessions. Tracking is necessary to avoid unbalanced | |
460 // session counts since not all requests will reach MEDIA_REQUEST_STATE_DONE, | |
461 // but they will all reach MEDIA_REQUEST_STATE_CLOSING. | |
462 if (stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) | |
463 return; | |
464 | |
465 if (state == content::MEDIA_REQUEST_STATE_DONE) { | |
466 DesktopCaptureSession session = { | |
467 render_process_id, render_frame_id, page_request_id}; | |
468 desktop_capture_sessions_.push_back(session); | |
469 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) { | |
470 for (DesktopCaptureSessions::iterator it = | |
471 desktop_capture_sessions_.begin(); | |
472 it != desktop_capture_sessions_.end(); ++it) { | |
473 if (it->render_process_id == render_process_id && | |
474 it->render_frame_id == render_frame_id && | |
475 it->page_request_id == page_request_id) { | |
476 desktop_capture_sessions_.erase(it); | |
477 break; | |
478 } | |
479 } | |
480 } | |
481 } | |
482 | |
483 bool DesktopCaptureAccessHandler::IsCaptureInProgress() { | |
484 return desktop_capture_sessions_.size() > 0; | |
485 } | |
OLD | NEW |