Chromium Code Reviews| 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 content::MediaResponseCallback& callback) { | |
| 26 InfoBarService* infobar_service = | |
| 27 InfoBarService::FromWebContents(web_contents); | |
|
Peter Kasting
2016/09/23 01:07:19
Nit: It's kinda ugly, but it's shorter to just inl
braveyao
2016/09/23 18:40:55
|infobar_service| is used twice. It isn't better t
Peter Kasting
2016/09/23 18:46:03
Oh, yeah, nm, I had looked for a second invocation
| |
| 28 | |
| 29 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | |
| 30 std::unique_ptr<ConfirmInfoBarDelegate>( | |
| 31 new ScreenCaptureInfoBarDelegateAndroid(web_contents, request, | |
| 32 callback)))); | |
| 33 } | |
| 34 | |
| 35 ScreenCaptureInfoBarDelegateAndroid::ScreenCaptureInfoBarDelegateAndroid( | |
| 36 content::WebContents* web_contents, | |
| 37 const content::MediaStreamRequest& request, | |
| 38 const content::MediaResponseCallback& callback) | |
| 39 : web_contents_(web_contents), request_(request), callback_(callback) { | |
| 40 DCHECK_EQ(content::MEDIA_DESKTOP_VIDEO_CAPTURE, request.video_type); | |
| 41 } | |
| 42 | |
| 43 ScreenCaptureInfoBarDelegateAndroid::~ScreenCaptureInfoBarDelegateAndroid() { | |
| 44 if (!callback_.is_null()) { | |
| 45 callback_.Run(content::MediaStreamDevices(), | |
| 46 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, | |
| 47 nullptr); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 52 ScreenCaptureInfoBarDelegateAndroid::GetIdentifier() const { | |
| 53 return SCREEN_CAPTURE_INFOBAR_DELEGATE_ANDROID; | |
| 54 } | |
| 55 | |
| 56 ScreenCaptureInfoBarDelegateAndroid* | |
| 57 ScreenCaptureInfoBarDelegateAndroid::AsScreenCaptureInfoBarDelegateAndroid() { | |
| 58 return this; | |
| 59 } | |
| 60 | |
| 61 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetMessageText() const { | |
| 62 return l10n_util::GetStringFUTF16( | |
| 63 IDS_MEDIA_CAPTURE_SCREEN, | |
| 64 url_formatter::FormatUrlForSecurityDisplay(request_.security_origin)); | |
| 65 } | |
| 66 | |
| 67 int ScreenCaptureInfoBarDelegateAndroid::GetIconId() const { | |
| 68 return IDR_INFOBAR_MEDIA_STREAM_SCREEN; | |
| 69 } | |
| 70 | |
| 71 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetButtonLabel( | |
| 72 InfoBarButton button) const { | |
| 73 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | |
| 74 : IDS_PERMISSION_DENY); | |
| 75 } | |
| 76 | |
| 77 bool ScreenCaptureInfoBarDelegateAndroid::Accept() { | |
| 78 RunCallback(content::MEDIA_DEVICE_OK); | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 bool ScreenCaptureInfoBarDelegateAndroid::Cancel() { | |
| 83 RunCallback(content::MEDIA_DEVICE_PERMISSION_DENIED); | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 void ScreenCaptureInfoBarDelegateAndroid::InfoBarDismissed() { | |
| 88 RunCallback(content::MEDIA_DEVICE_PERMISSION_DISMISSED); | |
| 89 } | |
| 90 | |
| 91 void ScreenCaptureInfoBarDelegateAndroid::RunCallback( | |
| 92 content::MediaStreamRequestResult result) { | |
| 93 DCHECK(!callback_.is_null()); | |
| 94 | |
| 95 content::MediaStreamDevices devices = content::MediaStreamDevices(); | |
|
Peter Kasting
2016/09/23 01:17:58
Nit: Omit "= content::MediaStreamDevices();", it d
braveyao
2016/09/23 18:40:55
Done.
| |
| 96 if (result == content::MEDIA_DEVICE_OK) { | |
| 97 content::DesktopMediaID screen_id = | |
| 98 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | |
| 99 webrtc::kFullDesktopScreenId); | |
| 100 devices.push_back(content::MediaStreamDevice( | |
| 101 content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen")); | |
| 102 } | |
| 103 | |
| 104 std::unique_ptr<content::MediaStreamUI> ui; | |
| 105 if (!devices.empty()) { | |
|
Peter Kasting
2016/09/23 01:17:58
Nit: Isn't this true iff the above conditional suc
braveyao
2016/09/23 18:40:55
Done.
| |
| 106 ui = MediaCaptureDevicesDispatcher::GetInstance() | |
| 107 ->GetMediaStreamCaptureIndicator() | |
| 108 ->RegisterMediaStream(web_contents_, devices); | |
| 109 } | |
| 110 | |
| 111 base::ResetAndReturn(&callback_).Run(devices, result, std::move(ui)); | |
| 112 } | |
| OLD | NEW |