| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/ui/screen_capture_infobar_delegate.h" | 5 #include "chrome/browser/ui/screen_capture_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/api/infobars/infobar_service.h" | 7 #include "chrome/browser/api/infobars/infobar_service.h" |
| 10 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/browser/ui/screen_capture_confirmation_ui_infobar.h" |
| 11 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 13 | 11 |
| 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( | 12 ScreenCaptureInfoBarDelegate::ScreenCaptureInfoBarDelegate( |
| 56 InfoBarService* infobar_service, | 13 InfoBarService* infobar_service, |
| 57 const content::MediaStreamRequest& request, | 14 const string16& application_name, |
| 58 const content::MediaResponseCallback& callback) | 15 ScreenCaptureConfirmationUIInfobar* result_handler) |
| 59 : ConfirmInfoBarDelegate(infobar_service), | 16 : ConfirmInfoBarDelegate(infobar_service), |
| 60 request_(request), | 17 result_handler_(result_handler), |
| 61 callback_(callback) { | 18 application_name_(application_name) { |
| 62 DCHECK_EQ(content::MEDIA_SCREEN_VIDEO_CAPTURE, request.video_type); | |
| 63 } | 19 } |
| 64 | 20 |
| 65 ScreenCaptureInfoBarDelegate::~ScreenCaptureInfoBarDelegate() { | 21 ScreenCaptureInfoBarDelegate::~ScreenCaptureInfoBarDelegate() { |
| 66 } | 22 // Notify the handler if it hasn't been notified yet (e.g. if the tab is being |
| 67 | 23 // closed). |
| 68 // Needed to avoid having more than one infobar with the same request. | 24 if (result_handler_) |
| 69 bool ScreenCaptureInfoBarDelegate::EqualsDelegate( | 25 result_handler_->OnInfobarResult(false); |
| 70 InfoBarDelegate* delegate) const { | |
| 71 ScreenCaptureInfoBarDelegate* other = | |
| 72 delegate->AsScreenCaptureInfoBarDelegate(); | |
| 73 return other && other->request_.security_origin == request_.security_origin; | |
| 74 } | 26 } |
| 75 | 27 |
| 76 void ScreenCaptureInfoBarDelegate::InfoBarDismissed() { | 28 void ScreenCaptureInfoBarDelegate::InfoBarDismissed() { |
| 77 Deny(); | 29 result_handler_->OnInfobarResult(false); |
| 30 result_handler_ = NULL; |
| 78 } | 31 } |
| 79 | 32 |
| 80 InfoBarDelegate::Type ScreenCaptureInfoBarDelegate::GetInfoBarType() const { | 33 InfoBarDelegate::Type ScreenCaptureInfoBarDelegate::GetInfoBarType() const { |
| 81 return PAGE_ACTION_TYPE; | 34 return PAGE_ACTION_TYPE; |
| 82 } | 35 } |
| 83 | 36 |
| 84 ScreenCaptureInfoBarDelegate* | 37 ScreenCaptureInfoBarDelegate* |
| 85 ScreenCaptureInfoBarDelegate::AsScreenCaptureInfoBarDelegate() { | 38 ScreenCaptureInfoBarDelegate::AsScreenCaptureInfoBarDelegate() { |
| 86 return this; | 39 return this; |
| 87 } | 40 } |
| 88 | 41 |
| 89 string16 ScreenCaptureInfoBarDelegate::GetMessageText() const { | 42 string16 ScreenCaptureInfoBarDelegate::GetMessageText() const { |
| 90 return l10n_util::GetStringFUTF16( | 43 return l10n_util::GetStringFUTF16( |
| 91 IDS_MEDIA_CAPTURE_SCREEN, | 44 IDS_MEDIA_CAPTURE_SCREEN, application_name_); |
| 92 UTF8ToUTF16(request_.security_origin.spec())); | |
| 93 } | 45 } |
| 94 | 46 |
| 95 string16 ScreenCaptureInfoBarDelegate::GetButtonLabel( | 47 string16 ScreenCaptureInfoBarDelegate::GetButtonLabel( |
| 96 InfoBarButton button) const { | 48 InfoBarButton button) const { |
| 97 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 49 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 98 IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_DENY); | 50 IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_DENY); |
| 99 } | 51 } |
| 100 | 52 |
| 101 bool ScreenCaptureInfoBarDelegate::Accept() { | 53 bool ScreenCaptureInfoBarDelegate::Accept() { |
| 102 content::MediaStreamDevices devices; | 54 result_handler_->OnInfobarResult(true); |
| 103 | 55 result_handler_ = NULL; |
| 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; | 56 return true; |
| 110 } | 57 } |
| 111 | 58 |
| 112 bool ScreenCaptureInfoBarDelegate::Cancel() { | 59 bool ScreenCaptureInfoBarDelegate::Cancel() { |
| 113 Deny(); | 60 result_handler_->OnInfobarResult(false); |
| 61 result_handler_ = NULL; |
| 114 return true; | 62 return true; |
| 115 } | 63 } |
| 116 | |
| 117 void ScreenCaptureInfoBarDelegate::Deny() { | |
| 118 callback_.Run(content::MediaStreamDevices()); | |
| 119 } | |
| OLD | NEW |