| 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 28 matching lines...) Expand all Loading... |
| 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" | 42 #include "base/sha1.h" |
| 43 #endif // defined(OS_CHROMEOS) | 43 #endif // defined(OS_CHROMEOS) |
| 44 | 44 |
| 45 using content::BrowserThread; | 45 using content::BrowserThread; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 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 | 49 // Helper to get title of the calling application shown in the screen capture |
| 75 // notification. | 50 // notification. |
| 76 base::string16 GetApplicationTitle(content::WebContents* web_contents, | 51 base::string16 GetApplicationTitle(content::WebContents* web_contents, |
| 77 const extensions::Extension* extension) { | 52 const extensions::Extension* extension) { |
| 78 // Use extension name as title for extensions and host/origin for drive-by | 53 // Use extension name as title for extensions and host/origin for drive-by |
| 79 // web. | 54 // web. |
| 80 std::string title; | 55 std::string title; |
| 81 if (extension) { | 56 if (extension) { |
| 82 title = extension->name(); | 57 title = extension->name(); |
| 83 return base::UTF8ToUTF16(title); | 58 return base::UTF8ToUTF16(title); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 void DesktopCaptureAccessHandler::ProcessScreenCaptureAccessRequest( | 208 void DesktopCaptureAccessHandler::ProcessScreenCaptureAccessRequest( |
| 234 content::WebContents* web_contents, | 209 content::WebContents* web_contents, |
| 235 const content::MediaStreamRequest& request, | 210 const content::MediaStreamRequest& request, |
| 236 const content::MediaResponseCallback& callback, | 211 const content::MediaResponseCallback& callback, |
| 237 const extensions::Extension* extension) { | 212 const extensions::Extension* extension) { |
| 238 content::MediaStreamDevices devices; | 213 content::MediaStreamDevices devices; |
| 239 std::unique_ptr<content::MediaStreamUI> ui; | 214 std::unique_ptr<content::MediaStreamUI> ui; |
| 240 | 215 |
| 241 DCHECK_EQ(request.video_type, content::MEDIA_DESKTOP_VIDEO_CAPTURE); | 216 DCHECK_EQ(request.video_type, content::MEDIA_DESKTOP_VIDEO_CAPTURE); |
| 242 | 217 |
| 218 UpdateExtensionTrusted(request, extension); |
| 219 |
| 243 bool loopback_audio_supported = false; | 220 bool loopback_audio_supported = false; |
| 244 #if defined(USE_CRAS) || defined(OS_WIN) | 221 #if defined(USE_CRAS) || defined(OS_WIN) |
| 245 // Currently loopback audio capture is supported only on Windows and ChromeOS. | 222 // Currently loopback audio capture is supported only on Windows and ChromeOS. |
| 246 loopback_audio_supported = true; | 223 loopback_audio_supported = true; |
| 247 #endif | 224 #endif |
| 248 | 225 |
| 249 bool component_extension = false; | 226 bool component_extension = false; |
| 250 component_extension = | 227 component_extension = |
| 251 extension && extension->location() == extensions::Manifest::COMPONENT; | 228 extension && extension->location() == extensions::Manifest::COMPONENT; |
| 252 | 229 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 const bool check_audio_permission = | 414 const bool check_audio_permission = |
| 438 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 415 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 439 extensions::switches::kDisableDesktopCaptureAudio); | 416 extensions::switches::kDisableDesktopCaptureAudio); |
| 440 const bool capture_audio = | 417 const bool capture_audio = |
| 441 (check_audio_permission ? audio_permitted : true) && audio_requested && | 418 (check_audio_permission ? audio_permitted : true) && audio_requested && |
| 442 audio_supported; | 419 audio_supported; |
| 443 | 420 |
| 444 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, true, | 421 ui = GetDevicesForDesktopCapture(&devices, media_id, capture_audio, true, |
| 445 GetApplicationTitle(web_contents, extension), | 422 GetApplicationTitle(web_contents, extension), |
| 446 base::UTF8ToUTF16(original_extension_name)); | 423 base::UTF8ToUTF16(original_extension_name)); |
| 447 | 424 UpdateExtensionTrusted(request, extension); |
| 448 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); | 425 callback.Run(devices, content::MEDIA_DEVICE_OK, std::move(ui)); |
| 449 } | 426 } |
| 450 | 427 |
| 451 void DesktopCaptureAccessHandler::UpdateMediaRequestState( | |
| 452 int render_process_id, | |
| 453 int render_frame_id, | |
| 454 int page_request_id, | |
| 455 content::MediaStreamType stream_type, | |
| 456 content::MediaRequestState state) { | |
| 457 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 458 // Track desktop capture sessions. Tracking is necessary to avoid unbalanced | |
| 459 // session counts since not all requests will reach MEDIA_REQUEST_STATE_DONE, | |
| 460 // but they will all reach MEDIA_REQUEST_STATE_CLOSING. | |
| 461 if (stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) | |
| 462 return; | |
| 463 | |
| 464 if (state == content::MEDIA_REQUEST_STATE_DONE) { | |
| 465 DesktopCaptureSession session = { | |
| 466 render_process_id, render_frame_id, page_request_id}; | |
| 467 desktop_capture_sessions_.push_back(session); | |
| 468 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) { | |
| 469 for (DesktopCaptureSessions::iterator it = | |
| 470 desktop_capture_sessions_.begin(); | |
| 471 it != desktop_capture_sessions_.end(); ++it) { | |
| 472 if (it->render_process_id == render_process_id && | |
| 473 it->render_frame_id == render_frame_id && | |
| 474 it->page_request_id == page_request_id) { | |
| 475 desktop_capture_sessions_.erase(it); | |
| 476 break; | |
| 477 } | |
| 478 } | |
| 479 } | |
| 480 } | |
| 481 | |
| 482 bool DesktopCaptureAccessHandler::IsCaptureInProgress() { | |
| 483 return desktop_capture_sessions_.size() > 0; | |
| 484 } | |
| OLD | NEW |