OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/media/webrtc/screen_capture_infobar_delegate_android.h" |
| 6 |
| 7 #include "base/callback_helpers.h" |
| 8 #include "chrome/browser/infobars/infobar_service.h" |
| 9 #include "chrome/browser/media/webrtc/desktop_streams_registry.h" |
| 10 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 11 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 12 #include "chrome/grit/generated_resources.h" |
| 13 #include "chrome/grit/theme_resources.h" |
| 14 #include "components/infobars/core/infobar.h" |
| 15 #include "components/url_formatter/elide_url.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/media_stream_request.h" |
| 18 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
| 20 |
| 21 // static |
| 22 void ScreenCaptureInfoBarDelegateAndroid::Create( |
| 23 content::WebContents* web_contents, |
| 24 const content::MediaStreamRequest& request, |
| 25 const ResponseCallback& callback) { |
| 26 InfoBarService* infobar_service = |
| 27 InfoBarService::FromWebContents(web_contents); |
| 28 |
| 29 std::unique_ptr<infobars::InfoBar> new_infobar( |
| 30 infobar_service->CreateConfirmInfoBar( |
| 31 std::unique_ptr<ConfirmInfoBarDelegate>( |
| 32 new ScreenCaptureInfoBarDelegateAndroid(web_contents, request, |
| 33 callback)))); |
| 34 |
| 35 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 36 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 37 ScreenCaptureInfoBarDelegateAndroid* delegate = |
| 38 old_infobar->delegate()->AsScreenCaptureInfoBarDelegateAndroid(); |
| 39 if (delegate != nullptr) { |
| 40 infobar_service->ReplaceInfoBar(old_infobar, std::move(new_infobar)); |
| 41 return; |
| 42 } |
| 43 } |
| 44 |
| 45 infobar_service->AddInfoBar(std::move(new_infobar)); |
| 46 } |
| 47 |
| 48 ScreenCaptureInfoBarDelegateAndroid::ScreenCaptureInfoBarDelegateAndroid( |
| 49 content::WebContents* web_contents, |
| 50 const content::MediaStreamRequest& request, |
| 51 const ResponseCallback& callback) |
| 52 : web_contents_(web_contents), |
| 53 request_(request), |
| 54 callback_(callback) { |
| 55 DCHECK(request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE); |
| 56 } |
| 57 |
| 58 ScreenCaptureInfoBarDelegateAndroid::~ScreenCaptureInfoBarDelegateAndroid() {} |
| 59 |
| 60 infobars::InfoBarDelegate::InfoBarIdentifier |
| 61 ScreenCaptureInfoBarDelegateAndroid::GetIdentifier() const { |
| 62 return SCREEN_CAPTURE_INFOBAR_DELEGATE_ANDROID; |
| 63 } |
| 64 |
| 65 ScreenCaptureInfoBarDelegateAndroid* |
| 66 ScreenCaptureInfoBarDelegateAndroid::AsScreenCaptureInfoBarDelegateAndroid() { |
| 67 return this; |
| 68 } |
| 69 |
| 70 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetMessageText() const { |
| 71 return l10n_util::GetStringFUTF16( |
| 72 IDS_MEDIA_CAPTURE_SCREEN, |
| 73 url_formatter::FormatUrlForSecurityDisplay(request_.security_origin)); |
| 74 } |
| 75 |
| 76 int ScreenCaptureInfoBarDelegateAndroid::GetIconId() const { |
| 77 return IDR_INFOBAR_MEDIA_STREAM_SCREEN; |
| 78 } |
| 79 |
| 80 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetButtonLabel( |
| 81 InfoBarButton button) const { |
| 82 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
| 83 : IDS_PERMISSION_DENY); |
| 84 } |
| 85 |
| 86 bool ScreenCaptureInfoBarDelegateAndroid::Accept() { |
| 87 RunCallback(content::MEDIA_DEVICE_OK); |
| 88 return true; |
| 89 } |
| 90 |
| 91 bool ScreenCaptureInfoBarDelegateAndroid::Cancel() { |
| 92 RunCallback(content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 93 return true; |
| 94 } |
| 95 |
| 96 void ScreenCaptureInfoBarDelegateAndroid::InfoBarDismissed() { |
| 97 RunCallback(content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
| 98 } |
| 99 |
| 100 void ScreenCaptureInfoBarDelegateAndroid::RunCallback( |
| 101 content::MediaStreamRequestResult result) { |
| 102 CHECK(!callback_.is_null()); |
| 103 |
| 104 content::MediaStreamDevices devices = content::MediaStreamDevices(); |
| 105 if (result == content::MEDIA_DEVICE_OK) { |
| 106 content::DesktopMediaID screen_id; |
| 107 screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 108 webrtc::kFullDesktopScreenId); |
| 109 devices.push_back(content::MediaStreamDevice( |
| 110 content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen")); |
| 111 } |
| 112 |
| 113 std::unique_ptr<content::MediaStreamUI> ui; |
| 114 if (!devices.empty()) { |
| 115 ui = MediaCaptureDevicesDispatcher::GetInstance() |
| 116 ->GetMediaStreamCaptureIndicator() |
| 117 ->RegisterMediaStream(web_contents_, devices); |
| 118 } |
| 119 |
| 120 base::ResetAndReturn(&callback_).Run(devices, result, std::move(ui)); |
| 121 } |
OLD | NEW |