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

Side by Side Diff: chrome/browser/media/media_capture_devices_dispatcher.cc

Issue 139053003: Chrome OS: avoid suspending on lid close when casting is active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pass security origin to MediaObserver. Created 6 years, 11 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 | Annotate | Revision Log
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_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
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" ||
Sergey Ulanov 2014/01/17 18:39:32 These do not need to be hashed anymore.
hshi1 2014/01/17 19:31:28 Done (removed hash for public release ID; left a T
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
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 BrowserThread::PostTask( 674 BrowserThread::PostTask(
651 BrowserThread::UI, FROM_HERE, 675 BrowserThread::UI, FROM_HERE,
652 base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread, 676 base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread,
653 base::Unretained(this), devices)); 677 base::Unretained(this), devices));
654 } 678 }
655 679
656 void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( 680 void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
657 int render_process_id, 681 int render_process_id,
658 int render_view_id, 682 int render_view_id,
659 int page_request_id, 683 int page_request_id,
684 const GURL& security_origin,
660 const content::MediaStreamDevice& device, 685 const content::MediaStreamDevice& device,
661 content::MediaRequestState state) { 686 content::MediaRequestState state) {
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
663 BrowserThread::PostTask( 688 BrowserThread::PostTask(
664 BrowserThread::UI, FROM_HERE, 689 BrowserThread::UI, FROM_HERE,
665 base::Bind( 690 base::Bind(
666 &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread, 691 &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread,
667 base::Unretained(this), render_process_id, render_view_id, 692 base::Unretained(this), render_process_id, render_view_id,
668 page_request_id, device, state)); 693 page_request_id, security_origin, device, state));
669 } 694 }
670 695
671 void MediaCaptureDevicesDispatcher::OnAudioStreamPlayingChanged( 696 void MediaCaptureDevicesDispatcher::OnAudioStreamPlayingChanged(
672 int render_process_id, int render_view_id, int stream_id, 697 int render_process_id, int render_view_id, int stream_id,
673 bool is_playing, float power_dbfs, bool clipped) { 698 bool is_playing, float power_dbfs, bool clipped) {
674 audio_stream_indicator_->UpdateWebContentsStatus( 699 audio_stream_indicator_->UpdateWebContentsStatus(
675 render_process_id, render_view_id, stream_id, 700 render_process_id, render_view_id, stream_id,
676 is_playing, power_dbfs, clipped); 701 is_playing, power_dbfs, clipped);
677 } 702 }
678 703
(...skipping 23 matching lines...) Expand all
702 devices_enumerated_ = true; 727 devices_enumerated_ = true;
703 video_devices_ = devices; 728 video_devices_ = devices;
704 FOR_EACH_OBSERVER(Observer, observers_, 729 FOR_EACH_OBSERVER(Observer, observers_,
705 OnUpdateVideoDevices(video_devices_)); 730 OnUpdateVideoDevices(video_devices_));
706 } 731 }
707 732
708 void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( 733 void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
709 int render_process_id, 734 int render_process_id,
710 int render_view_id, 735 int render_view_id,
711 int page_request_id, 736 int page_request_id,
737 const GURL& security_origin,
712 const content::MediaStreamDevice& device, 738 const content::MediaStreamDevice& device,
713 content::MediaRequestState state) { 739 content::MediaRequestState state) {
714 // Track desktop capture sessions. Tracking is necessary to avoid unbalanced 740 // Track desktop capture sessions. Tracking is necessary to avoid unbalanced
715 // session counts since not all requests will reach MEDIA_REQUEST_STATE_DONE, 741 // session counts since not all requests will reach MEDIA_REQUEST_STATE_DONE,
716 // but they will all reach MEDIA_REQUEST_STATE_CLOSING. 742 // but they will all reach MEDIA_REQUEST_STATE_CLOSING.
717 if (device.type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { 743 if (device.type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) {
718 if (state == content::MEDIA_REQUEST_STATE_DONE) { 744 if (state == content::MEDIA_REQUEST_STATE_DONE) {
719 DesktopCaptureSession session = { render_process_id, render_view_id, 745 DesktopCaptureSession session = { render_process_id, render_view_id,
720 page_request_id }; 746 page_request_id };
721 desktop_capture_sessions_.push_back(session); 747 desktop_capture_sessions_.push_back(session);
(...skipping 26 matching lines...) Expand all
748 queue.erase(it); 774 queue.erase(it);
749 found = true; 775 found = true;
750 break; 776 break;
751 } 777 }
752 } 778 }
753 if (found) 779 if (found)
754 break; 780 break;
755 } 781 }
756 } 782 }
757 783
784 #if defined(OS_CHROMEOS)
785 if (IsOriginForCasting(security_origin) && IsVideoMediaType(device.type)) {
786 // Notify ash that casting state has changed.
787 if (state == content::MEDIA_REQUEST_STATE_DONE) {
788 ash::Shell::GetInstance()->OnCastingStateChanged(true);
789 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) {
790 ash::Shell::GetInstance()->OnCastingStateChanged(false);
791 }
792 }
793 #endif
794
758 FOR_EACH_OBSERVER(Observer, observers_, 795 FOR_EACH_OBSERVER(Observer, observers_,
759 OnRequestUpdate(render_process_id, 796 OnRequestUpdate(render_process_id,
760 render_view_id, 797 render_view_id,
761 device, 798 device,
762 state)); 799 state));
763 } 800 }
764 801
765 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( 802 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread(
766 int render_process_id, 803 int render_process_id,
767 int render_view_id) { 804 int render_view_id) {
768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
769 FOR_EACH_OBSERVER(Observer, observers_, 806 FOR_EACH_OBSERVER(Observer, observers_,
770 OnCreatingAudioStream(render_process_id, render_view_id)); 807 OnCreatingAudioStream(render_process_id, render_view_id));
771 } 808 }
772 809
773 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { 810 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() {
774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
775 return desktop_capture_sessions_.size() > 0; 812 return desktop_capture_sessions_.size() > 0;
776 } 813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698