| Index: chrome/browser/media/media_capture_devices_dispatcher.cc | 
| diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc | 
| index 5c223849626a46338b2a6e3498843a0828b28b1e..32b3a137162f263d2e1bb2474d841f6552035cdb 100644 | 
| --- a/chrome/browser/media/media_capture_devices_dispatcher.cc | 
| +++ b/chrome/browser/media/media_capture_devices_dispatcher.cc | 
| @@ -4,11 +4,17 @@ | 
|  | 
| #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 
|  | 
| +#include "base/command_line.h" | 
| #include "base/prefs/pref_service.h" | 
| +#include "base/utf_string_conversions.h" | 
| #include "chrome/browser/media/audio_stream_indicator.h" | 
| #include "chrome/browser/media/media_stream_capture_indicator.h" | 
| #include "chrome/browser/prefs/scoped_user_pref_update.h" | 
| #include "chrome/browser/profiles/profile.h" | 
| +#include "chrome/browser/ui/media_stream_infobar_delegate.h" | 
| +#include "chrome/browser/ui/screen_capture_confirmation_ui_infobar.h" | 
| +#include "chrome/browser/ui/screen_capture_infobar_delegate.h" | 
| +#include "chrome/common/chrome_switches.h" | 
| #include "chrome/common/pref_names.h" | 
| #include "components/user_prefs/pref_registry_syncable.h" | 
| #include "content/public/browser/browser_thread.h" | 
| @@ -36,8 +42,19 @@ const content::MediaStreamDevice* FindDefaultDeviceWithId( | 
| return &(*devices.begin()); | 
| }; | 
|  | 
| -}  // namespace | 
| +// This is a short-term solution to allow testing of the the Screen Capture API | 
| +// with Google Hangouts in M27. | 
| +// TODO(sergeyu): Remove this whitelist as soon as possible. | 
| +bool IsOriginWhitelistedForScreenCapture(const GURL& origin) { | 
| +#if defined(OFFICIAL_BUILD) | 
| +  return origin.spec() == "https://staging.talkgadget.google.com/" || | 
| +      origin.spec() == "https://plus.google.com/"; | 
| +#else | 
| +  return false; | 
| +#endif | 
| +} | 
|  | 
| +}  // namespace | 
|  | 
| MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 
| return Singleton<MediaCaptureDevicesDispatcher>::get(); | 
| @@ -95,6 +112,42 @@ MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { | 
| return video_devices_; | 
| } | 
|  | 
| +void MediaCaptureDevicesDispatcher::RequestAccess( | 
| +    content::WebContents* web_contents, | 
| +    const content::MediaStreamRequest& request, | 
| +    const content::MediaResponseCallback& callback) { | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| + | 
| +  if (request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE) { | 
| +    bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | 
| +        switches::kEnableUserMediaScreenCapturing) || | 
| +        IsOriginWhitelistedForScreenCapture(request.security_origin); | 
| +    // Deny request automatically in the following cases: | 
| +    //  1. Screen capturing is not enabled via command line switch. | 
| +    //  2. Audio capture was requested (it's not supported yet). | 
| +    //  3. Request from a page that was not loaded from a secure origin. | 
| +    if (!screen_capture_enabled || | 
| +        request.audio_type != content::MEDIA_NO_SERVICE || | 
| +        !request.security_origin.SchemeIsSecure()) { | 
| +      callback.Run(content::MediaStreamDevices()); | 
| +      return; | 
| +    } | 
| + | 
| +    DCHECK(!screen_capture_confirmation_ui_); | 
| +    screen_capture_confirmation_ui_.reset( | 
| +        new ScreenCaptureConfirmationUIInfobar(web_contents)); | 
| +    if (!screen_capture_confirmation_ui_->Show(base::Bind( | 
| +            &MediaCaptureDevicesDispatcher::OnScreenCaptureConfirmationResult, | 
| +            base::Unretained(this), callback), | 
| +            UTF8ToUTF16(request.security_origin.spec()))) { | 
| +      screen_capture_confirmation_ui_.reset(); | 
| +      callback.Run(content::MediaStreamDevices()); | 
| +    } | 
| +  } else { | 
| +    MediaStreamInfoBarDelegate::Create(web_contents, request, callback); | 
| +  } | 
| +} | 
| + | 
| void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 
| Profile* profile, | 
| bool audio, | 
| @@ -240,3 +293,18 @@ void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( | 
| device, | 
| state)); | 
| } | 
| + | 
| +void MediaCaptureDevicesDispatcher::OnScreenCaptureConfirmationResult( | 
| +    const content::MediaResponseCallback& callback, | 
| +    ScreenCaptureConfirmationUI::Result result) { | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| +  screen_capture_confirmation_ui_.reset(); | 
| +  if (result == ScreenCaptureConfirmationUI::ALLOW) { | 
| +    content::MediaStreamDevices devices; | 
| +    devices.push_back(content::MediaStreamDevice( | 
| +        content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); | 
| +    callback.Run(devices); | 
| +  } else { | 
| +    callback.Run(content::MediaStreamDevices()); | 
| +  } | 
| +} | 
|  |