| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/screen_capture_infobar_delegate.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/infobars/infobar_service.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "grit/generated_resources.h" | |
| 12 #include "ui/base/l10n/l10n_util.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // This is a short-term solution to allow testing of the the Screen Capture API | |
| 17 // with Google Hangouts in M27. | |
| 18 // TODO(sergeyu): Remove this whitelist as soon as possible. | |
| 19 bool IsWhitelistedOrigin(const GURL& origin) { | |
| 20 #if defined(OFFICIAL_BUILD) | |
| 21 return origin.spec() == "https://staging.talkgadget.google.com/" || | |
| 22 origin.spec() == "https://plus.google.com/"; | |
| 23 #else | |
| 24 return false; | |
| 25 #endif | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 // static | |
| 31 void ScreenCaptureInfoBarDelegate::Create( | |
| 32 content::WebContents* web_contents, | |
| 33 const content::MediaStreamRequest& request, | |
| 34 const content::MediaResponseCallback& callback) { | |
| 35 bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 36 switches::kEnableUserMediaScreenCapturing) || | |
| 37 IsWhitelistedOrigin(request.security_origin); | |
| 38 // Deny request automatically in the following cases: | |
| 39 // 1. Screen capturing is not enabled via command line switch. | |
| 40 // 2. Audio capture was requested (it's not supported yet). | |
| 41 // 3. Request from a page that was not loaded from a secure origin. | |
| 42 if (!screen_capture_enabled || | |
| 43 request.audio_type != content::MEDIA_NO_SERVICE || | |
| 44 !request.security_origin.SchemeIsSecure()) { | |
| 45 callback.Run(content::MediaStreamDevices()); | |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 InfoBarService* infobar_service = | |
| 50 InfoBarService::FromWebContents(web_contents); | |
| 51 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | |
| 52 new ScreenCaptureInfoBarDelegate(infobar_service, request, callback))); | |
| 53 } | |
| 54 | |
| 55 ScreenCaptureInfoBarDelegate::ScreenCaptureInfoBarDelegate( | |
| 56 InfoBarService* infobar_service, | |
| 57 const content::MediaStreamRequest& request, | |
| 58 const content::MediaResponseCallback& callback) | |
| 59 : ConfirmInfoBarDelegate(infobar_service), | |
| 60 request_(request), | |
| 61 callback_(callback) { | |
| 62 DCHECK_EQ(content::MEDIA_SCREEN_VIDEO_CAPTURE, request.video_type); | |
| 63 } | |
| 64 | |
| 65 ScreenCaptureInfoBarDelegate::~ScreenCaptureInfoBarDelegate() { | |
| 66 } | |
| 67 | |
| 68 // Needed to avoid having more than one infobar with the same request. | |
| 69 bool ScreenCaptureInfoBarDelegate::EqualsDelegate( | |
| 70 InfoBarDelegate* delegate) const { | |
| 71 ScreenCaptureInfoBarDelegate* other = | |
| 72 delegate->AsScreenCaptureInfoBarDelegate(); | |
| 73 return other && other->request_.security_origin == request_.security_origin; | |
| 74 } | |
| 75 | |
| 76 void ScreenCaptureInfoBarDelegate::InfoBarDismissed() { | |
| 77 Deny(); | |
| 78 } | |
| 79 | |
| 80 InfoBarDelegate::Type ScreenCaptureInfoBarDelegate::GetInfoBarType() const { | |
| 81 return PAGE_ACTION_TYPE; | |
| 82 } | |
| 83 | |
| 84 ScreenCaptureInfoBarDelegate* | |
| 85 ScreenCaptureInfoBarDelegate::AsScreenCaptureInfoBarDelegate() { | |
| 86 return this; | |
| 87 } | |
| 88 | |
| 89 string16 ScreenCaptureInfoBarDelegate::GetMessageText() const { | |
| 90 return l10n_util::GetStringFUTF16( | |
| 91 IDS_MEDIA_CAPTURE_SCREEN, | |
| 92 UTF8ToUTF16(request_.security_origin.spec())); | |
| 93 } | |
| 94 | |
| 95 string16 ScreenCaptureInfoBarDelegate::GetButtonLabel( | |
| 96 InfoBarButton button) const { | |
| 97 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 98 IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_DENY); | |
| 99 } | |
| 100 | |
| 101 bool ScreenCaptureInfoBarDelegate::Accept() { | |
| 102 content::MediaStreamDevices devices; | |
| 103 | |
| 104 // Add screen capturer source if it was requested. | |
| 105 devices.push_back(content::MediaStreamDevice( | |
| 106 content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); | |
| 107 | |
| 108 callback_.Run(devices); | |
| 109 return true; | |
| 110 } | |
| 111 | |
| 112 bool ScreenCaptureInfoBarDelegate::Cancel() { | |
| 113 Deny(); | |
| 114 return true; | |
| 115 } | |
| 116 | |
| 117 void ScreenCaptureInfoBarDelegate::Deny() { | |
| 118 callback_.Run(content::MediaStreamDevices()); | |
| 119 } | |
| OLD | NEW |