| OLD | NEW |
| 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_capture_devices_dispatcher.h" | 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const std::string hexencoded_origin_hash = | 98 const std::string hexencoded_origin_hash = |
| 99 base::HexEncode(origin_hash.data(), origin_hash.length()); | 99 base::HexEncode(origin_hash.data(), origin_hash.length()); |
| 100 return | 100 return |
| 101 hexencoded_origin_hash == "3C2705BC432E7C51CA8553FDC5BEE873FF2468EE" || | 101 hexencoded_origin_hash == "3C2705BC432E7C51CA8553FDC5BEE873FF2468EE" || |
| 102 hexencoded_origin_hash == "50F02B8A668CAB274527D58356F07C2143080FCC"; | 102 hexencoded_origin_hash == "50F02B8A668CAB274527D58356F07C2143080FCC"; |
| 103 #else | 103 #else |
| 104 return false; | 104 return false; |
| 105 #endif | 105 #endif |
| 106 } | 106 } |
| 107 | 107 |
| 108 #if defined(OS_CHROMEOS) |
| 109 // Returns true of the security origin is associated with casting. |
| 110 bool IsOriginForCasting(const GURL& origin) { |
| 111 #if defined(OFFICIAL_BUILD) |
| 112 // Whitelisted tab casting extensions. |
| 113 if (origin.spec() == "chrome-extension://pkedcjkdefgpdelpbcmbmeomcjbeemfm/" || |
| 114 origin.spec() == "chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/" || |
| 115 origin.spec() == "chrome-extension://hfaagokkkhdbgiakmmlclaapfelnkoah/") { |
| 116 return true; |
| 117 } |
| 118 // Check against hashed origins. |
| 119 const std::string origin_hash = base::SHA1HashString(origin.spec()); |
| 120 DCHECK_EQ(origin_hash.length(), base::kSHA1Length); |
| 121 const std::string hexencoded_origin_hash = |
| 122 base::HexEncode(origin_hash.data(), origin_hash.length()); |
| 123 return |
| 124 hexencoded_origin_hash == "3C2705BC432E7C51CA8553FDC5BEE873FF2468EE" || |
| 125 hexencoded_origin_hash == "50F02B8A668CAB274527D58356F07C2143080FCC"; |
| 126 #else |
| 127 return false; |
| 128 #endif |
| 129 } |
| 130 #endif |
| 131 |
| 108 // Helper to get title of the calling application shown in the screen capture | 132 // Helper to get title of the calling application shown in the screen capture |
| 109 // notification. | 133 // notification. |
| 110 base::string16 GetApplicationTitle(content::WebContents* web_contents, | 134 base::string16 GetApplicationTitle(content::WebContents* web_contents, |
| 111 const extensions::Extension* extension) { | 135 const extensions::Extension* extension) { |
| 112 // Use extension name as title for extensions and origin for drive-by web. | 136 // Use extension name as title for extensions and origin for drive-by web. |
| 113 std::string title; | 137 std::string title; |
| 114 if (extension) { | 138 if (extension) { |
| 115 title = extension->name(); | 139 title = extension->name(); |
| 116 } else { | 140 } else { |
| 117 title = web_contents->GetURL().GetOrigin().spec(); | 141 title = web_contents->GetURL().GetOrigin().spec(); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 #endif // !defined(OS_CHROMEOS) | 412 #endif // !defined(OS_CHROMEOS) |
| 389 | 413 |
| 390 bool capture_audio = | 414 bool capture_audio = |
| 391 (request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && | 415 (request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && |
| 392 loopback_audio_supported); | 416 loopback_audio_supported); |
| 393 | 417 |
| 394 // Unless we're being invoked from a component extension, register to | 418 // Unless we're being invoked from a component extension, register to |
| 395 // display the notification for stream capture. | 419 // display the notification for stream capture. |
| 396 bool display_notification = !component_extension; | 420 bool display_notification = !component_extension; |
| 397 | 421 |
| 398 ui = GetDevicesForDesktopCapture(devices, screen_id, capture_audio, | 422 ui = GetDevicesForDesktopCapture(devices, screen_id, capture_audio, |
| 399 display_notification, application_title); | 423 display_notification, application_title); |
| 400 } | 424 } |
| 401 } | 425 } |
| 402 | 426 |
| 403 callback.Run(devices, ui.Pass()); | 427 callback.Run(devices, ui.Pass()); |
| 404 } | 428 } |
| 405 | 429 |
| 406 void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest( | 430 void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest( |
| 407 content::WebContents* web_contents, | 431 content::WebContents* web_contents, |
| 408 const content::MediaStreamRequest& request, | 432 const content::MediaStreamRequest& request, |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 queue.erase(it); | 772 queue.erase(it); |
| 749 found = true; | 773 found = true; |
| 750 break; | 774 break; |
| 751 } | 775 } |
| 752 } | 776 } |
| 753 if (found) | 777 if (found) |
| 754 break; | 778 break; |
| 755 } | 779 } |
| 756 } | 780 } |
| 757 | 781 |
| 782 #if defined(OS_CHROMEOS) |
| 783 if (IsOriginForCasting(device.security_origin) && |
| 784 IsVideoMediaType(device.type)) { |
| 785 // Notify ash that casting state has changed. |
| 786 if (state == content::MEDIA_REQUEST_STATE_DONE) { |
| 787 ash::Shell::GetInstance()->OnCastingStateChanged(true); |
| 788 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) { |
| 789 ash::Shell::GetInstance()->OnCastingStateChanged(false); |
| 790 } |
| 791 } |
| 792 #endif |
| 793 |
| 758 FOR_EACH_OBSERVER(Observer, observers_, | 794 FOR_EACH_OBSERVER(Observer, observers_, |
| 759 OnRequestUpdate(render_process_id, | 795 OnRequestUpdate(render_process_id, |
| 760 render_view_id, | 796 render_view_id, |
| 761 device, | 797 device, |
| 762 state)); | 798 state)); |
| 763 } | 799 } |
| 764 | 800 |
| 765 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( | 801 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( |
| 766 int render_process_id, | 802 int render_process_id, |
| 767 int render_view_id) { | 803 int render_view_id) { |
| 768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 804 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 769 FOR_EACH_OBSERVER(Observer, observers_, | 805 FOR_EACH_OBSERVER(Observer, observers_, |
| 770 OnCreatingAudioStream(render_process_id, render_view_id)); | 806 OnCreatingAudioStream(render_process_id, render_view_id)); |
| 771 } | 807 } |
| 772 | 808 |
| 773 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { | 809 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { |
| 774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 810 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 775 return desktop_capture_sessions_.size() > 0; | 811 return desktop_capture_sessions_.size() > 0; |
| 776 } | 812 } |
| OLD | NEW |