| 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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" | 
|  | 9 #include "base/utf_string_conversions.h" | 
| 8 #include "chrome/browser/media/audio_stream_indicator.h" | 10 #include "chrome/browser/media/audio_stream_indicator.h" | 
| 9 #include "chrome/browser/media/media_stream_capture_indicator.h" | 11 #include "chrome/browser/media/media_stream_capture_indicator.h" | 
| 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 
| 11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" | 
|  | 14 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 
|  | 15 #include "chrome/browser/ui/screen_capture_confirmation_ui_infobar.h" | 
|  | 16 #include "chrome/browser/ui/screen_capture_infobar_delegate.h" | 
|  | 17 #include "chrome/common/chrome_switches.h" | 
| 12 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" | 
| 13 #include "components/user_prefs/pref_registry_syncable.h" | 19 #include "components/user_prefs/pref_registry_syncable.h" | 
| 14 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" | 
| 15 #include "content/public/browser/media_devices_monitor.h" | 21 #include "content/public/browser/media_devices_monitor.h" | 
| 16 #include "content/public/common/media_stream_request.h" | 22 #include "content/public/common/media_stream_request.h" | 
| 17 | 23 | 
| 18 using content::BrowserThread; | 24 using content::BrowserThread; | 
| 19 using content::MediaStreamDevices; | 25 using content::MediaStreamDevices; | 
| 20 | 26 | 
| 21 namespace { | 27 namespace { | 
| 22 | 28 | 
| 23 const content::MediaStreamDevice* FindDefaultDeviceWithId( | 29 const content::MediaStreamDevice* FindDefaultDeviceWithId( | 
| 24     const content::MediaStreamDevices& devices, | 30     const content::MediaStreamDevices& devices, | 
| 25     const std::string& device_id) { | 31     const std::string& device_id) { | 
| 26   if (devices.empty()) | 32   if (devices.empty()) | 
| 27     return NULL; | 33     return NULL; | 
| 28 | 34 | 
| 29   content::MediaStreamDevices::const_iterator iter = devices.begin(); | 35   content::MediaStreamDevices::const_iterator iter = devices.begin(); | 
| 30   for (; iter != devices.end(); ++iter) { | 36   for (; iter != devices.end(); ++iter) { | 
| 31     if (iter->id == device_id) { | 37     if (iter->id == device_id) { | 
| 32       return &(*iter); | 38       return &(*iter); | 
| 33     } | 39     } | 
| 34   } | 40   } | 
| 35 | 41 | 
| 36   return &(*devices.begin()); | 42   return &(*devices.begin()); | 
| 37 }; | 43 }; | 
| 38 | 44 | 
|  | 45 // This is a short-term solution to allow testing of the the Screen Capture API | 
|  | 46 // with Google Hangouts in M27. | 
|  | 47 // TODO(sergeyu): Remove this whitelist as soon as possible. | 
|  | 48 bool IsOriginWhitelistedForScreenCapture(const GURL& origin) { | 
|  | 49 #if defined(OFFICIAL_BUILD) | 
|  | 50   return origin.spec() == "https://staging.talkgadget.google.com/" || | 
|  | 51       origin.spec() == "https://plus.google.com/"; | 
|  | 52 #else | 
|  | 53   return false; | 
|  | 54 #endif | 
|  | 55 } | 
|  | 56 | 
| 39 }  // namespace | 57 }  // namespace | 
| 40 | 58 | 
| 41 |  | 
| 42 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 59 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 
| 43   return Singleton<MediaCaptureDevicesDispatcher>::get(); | 60   return Singleton<MediaCaptureDevicesDispatcher>::get(); | 
| 44 } | 61 } | 
| 45 | 62 | 
| 46 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 63 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 
| 47     : devices_enumerated_(false), | 64     : devices_enumerated_(false), | 
| 48       media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), | 65       media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), | 
| 49       audio_stream_indicator_(new AudioStreamIndicator()) {} | 66       audio_stream_indicator_(new AudioStreamIndicator()) {} | 
| 50 | 67 | 
| 51 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} | 68 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 88   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 105   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 89   if (!devices_enumerated_) { | 106   if (!devices_enumerated_) { | 
| 90     BrowserThread::PostTask( | 107     BrowserThread::PostTask( | 
| 91         BrowserThread::IO, FROM_HERE, | 108         BrowserThread::IO, FROM_HERE, | 
| 92         base::Bind(&content::EnsureMonitorCaptureDevices)); | 109         base::Bind(&content::EnsureMonitorCaptureDevices)); | 
| 93     devices_enumerated_ = true; | 110     devices_enumerated_ = true; | 
| 94   } | 111   } | 
| 95   return video_devices_; | 112   return video_devices_; | 
| 96 } | 113 } | 
| 97 | 114 | 
|  | 115 void MediaCaptureDevicesDispatcher::RequestAccess( | 
|  | 116     content::WebContents* web_contents, | 
|  | 117     const content::MediaStreamRequest& request, | 
|  | 118     const content::MediaResponseCallback& callback) { | 
|  | 119   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  | 120 | 
|  | 121   if (request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE) { | 
|  | 122     bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | 
|  | 123         switches::kEnableUserMediaScreenCapturing) || | 
|  | 124         IsOriginWhitelistedForScreenCapture(request.security_origin); | 
|  | 125     // Deny request automatically in the following cases: | 
|  | 126     //  1. Screen capturing is not enabled via command line switch. | 
|  | 127     //  2. Audio capture was requested (it's not supported yet). | 
|  | 128     //  3. Request from a page that was not loaded from a secure origin. | 
|  | 129     if (!screen_capture_enabled || | 
|  | 130         request.audio_type != content::MEDIA_NO_SERVICE || | 
|  | 131         !request.security_origin.SchemeIsSecure()) { | 
|  | 132       callback.Run(content::MediaStreamDevices()); | 
|  | 133       return; | 
|  | 134     } | 
|  | 135 | 
|  | 136     DCHECK(!screen_capture_confirmation_ui_); | 
|  | 137     screen_capture_confirmation_ui_.reset( | 
|  | 138         new ScreenCaptureConfirmationUIInfobar(web_contents)); | 
|  | 139     if (!screen_capture_confirmation_ui_->Show(base::Bind( | 
|  | 140             &MediaCaptureDevicesDispatcher::OnScreenCaptureConfirmationResult, | 
|  | 141             base::Unretained(this), callback), | 
|  | 142             UTF8ToUTF16(request.security_origin.spec()))) { | 
|  | 143       screen_capture_confirmation_ui_.reset(); | 
|  | 144       callback.Run(content::MediaStreamDevices()); | 
|  | 145     } | 
|  | 146   } else { | 
|  | 147     MediaStreamInfoBarDelegate::Create(web_contents, request, callback); | 
|  | 148   } | 
|  | 149 } | 
|  | 150 | 
| 98 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 151 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 
| 99     Profile* profile, | 152     Profile* profile, | 
| 100     bool audio, | 153     bool audio, | 
| 101     bool video, | 154     bool video, | 
| 102     content::MediaStreamDevices* devices) { | 155     content::MediaStreamDevices* devices) { | 
| 103   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 156   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 104   DCHECK(audio || video); | 157   DCHECK(audio || video); | 
| 105 | 158 | 
| 106   PrefService* prefs = profile->GetPrefs(); | 159   PrefService* prefs = profile->GetPrefs(); | 
| 107   std::string default_device; | 160   std::string default_device; | 
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 233     int render_process_id, | 286     int render_process_id, | 
| 234     int render_view_id, | 287     int render_view_id, | 
| 235     const content::MediaStreamDevice& device, | 288     const content::MediaStreamDevice& device, | 
| 236     content::MediaRequestState state) { | 289     content::MediaRequestState state) { | 
| 237   FOR_EACH_OBSERVER(Observer, observers_, | 290   FOR_EACH_OBSERVER(Observer, observers_, | 
| 238                     OnRequestUpdate(render_process_id, | 291                     OnRequestUpdate(render_process_id, | 
| 239                                     render_view_id, | 292                                     render_view_id, | 
| 240                                     device, | 293                                     device, | 
| 241                                     state)); | 294                                     state)); | 
| 242 } | 295 } | 
|  | 296 | 
|  | 297 void MediaCaptureDevicesDispatcher::OnScreenCaptureConfirmationResult( | 
|  | 298     const content::MediaResponseCallback& callback, | 
|  | 299     ScreenCaptureConfirmationUI::Result result) { | 
|  | 300   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  | 301   screen_capture_confirmation_ui_.reset(); | 
|  | 302   if (result == ScreenCaptureConfirmationUI::ALLOW) { | 
|  | 303     content::MediaStreamDevices devices; | 
|  | 304     devices.push_back(content::MediaStreamDevice( | 
|  | 305         content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); | 
|  | 306     callback.Run(devices); | 
|  | 307   } else { | 
|  | 308     callback.Run(content::MediaStreamDevices()); | 
|  | 309   } | 
|  | 310 } | 
| OLD | NEW | 
|---|