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 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) { | |
|
Peter Kasting
2016/09/20 23:50:28
Why do you need this block? Are you expecting to
braveyao
2016/09/21 00:35:55
Yes I think so. Same as here, https://cs.chromium.
Peter Kasting
2016/09/21 04:07:27
Can you say more about this? Normally we prevent
braveyao
2016/09/21 21:04:02
Done.
It's really good to know it's handled intern
Peter Kasting
2016/09/21 21:39:43
Well, what matters is what you want to happen when
braveyao
2016/09/21 22:42:21
Dumping the old one sounds more proper here. So ke
Peter Kasting
2016/09/21 23:00:32
Wait, so if they're called one by one, and the nex
braveyao
2016/09/21 23:43:18
Done.
| |
| 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), request_(request), callback_(callback) { | |
| 53 DCHECK(request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE); | |
|
Peter Kasting
2016/09/20 23:50:28
Nit: DCHECK_EQ(content::MEDIA_DESKTOP_VIDEO_CAPTUR
braveyao
2016/09/21 00:35:55
Done.
| |
| 54 } | |
| 55 | |
| 56 ScreenCaptureInfoBarDelegateAndroid::~ScreenCaptureInfoBarDelegateAndroid() { | |
| 57 if (!callback_.is_null()) { | |
| 58 callback_.Run(content::MediaStreamDevices(), | |
| 59 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, | |
| 60 std::unique_ptr<content::MediaStreamUI>()); | |
|
Peter Kasting
2016/09/20 23:50:28
Nit: Just use nullptr?
braveyao
2016/09/21 00:35:55
Done.
| |
| 61 } | |
| 62 } | |
| 63 | |
| 64 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 65 ScreenCaptureInfoBarDelegateAndroid::GetIdentifier() const { | |
| 66 return SCREEN_CAPTURE_INFOBAR_DELEGATE_ANDROID; | |
| 67 } | |
| 68 | |
| 69 ScreenCaptureInfoBarDelegateAndroid* | |
| 70 ScreenCaptureInfoBarDelegateAndroid::AsScreenCaptureInfoBarDelegateAndroid() { | |
| 71 return this; | |
| 72 } | |
| 73 | |
| 74 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetMessageText() const { | |
| 75 return l10n_util::GetStringFUTF16( | |
| 76 IDS_MEDIA_CAPTURE_SCREEN, | |
| 77 url_formatter::FormatUrlForSecurityDisplay(request_.security_origin)); | |
| 78 } | |
| 79 | |
| 80 int ScreenCaptureInfoBarDelegateAndroid::GetIconId() const { | |
| 81 return IDR_INFOBAR_MEDIA_STREAM_SCREEN; | |
| 82 } | |
| 83 | |
| 84 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetButtonLabel( | |
| 85 InfoBarButton button) const { | |
| 86 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | |
| 87 : IDS_PERMISSION_DENY); | |
| 88 } | |
| 89 | |
| 90 bool ScreenCaptureInfoBarDelegateAndroid::Accept() { | |
| 91 RunCallback(content::MEDIA_DEVICE_OK); | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 bool ScreenCaptureInfoBarDelegateAndroid::Cancel() { | |
| 96 RunCallback(content::MEDIA_DEVICE_PERMISSION_DENIED); | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 void ScreenCaptureInfoBarDelegateAndroid::InfoBarDismissed() { | |
| 101 RunCallback(content::MEDIA_DEVICE_PERMISSION_DISMISSED); | |
| 102 } | |
| 103 | |
| 104 void ScreenCaptureInfoBarDelegateAndroid::RunCallback( | |
| 105 content::MediaStreamRequestResult result) { | |
| 106 CHECK(!callback_.is_null()); | |
|
Peter Kasting
2016/09/20 23:50:28
Nit: Prefer DCHECK except for debugging or securit
braveyao
2016/09/21 00:35:55
Done.
| |
| 107 | |
| 108 content::MediaStreamDevices devices = content::MediaStreamDevices(); | |
| 109 if (result == content::MEDIA_DEVICE_OK) { | |
| 110 content::DesktopMediaID screen_id; | |
|
Peter Kasting
2016/09/20 23:50:28
Nit: Combine these two lines
braveyao
2016/09/21 00:35:55
Done.
| |
| 111 screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | |
| 112 webrtc::kFullDesktopScreenId); | |
| 113 devices.push_back(content::MediaStreamDevice( | |
| 114 content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen")); | |
| 115 } | |
| 116 | |
| 117 std::unique_ptr<content::MediaStreamUI> ui; | |
| 118 if (!devices.empty()) { | |
| 119 ui = MediaCaptureDevicesDispatcher::GetInstance() | |
| 120 ->GetMediaStreamCaptureIndicator() | |
| 121 ->RegisterMediaStream(web_contents_, devices); | |
| 122 } | |
| 123 | |
| 124 base::ResetAndReturn(&callback_).Run(devices, result, std::move(ui)); | |
|
Peter Kasting
2016/09/20 23:50:29
Is there a reason you need to use ResetAndReturn()
braveyao
2016/09/21 00:35:55
Because ResetAndReturn() is used here too, https:/
Peter Kasting
2016/09/21 04:07:27
That doesn't answer my question. Don't do somethi
braveyao
2016/09/21 21:04:02
Done.
I just noticed that in chrome/browser/media
Peter Kasting
2016/09/21 21:39:43
I don't think you understood my objection.
I'm no
braveyao
2016/09/21 22:42:21
In my case, Run-Reset and Reset-run are same thing
Peter Kasting
2016/09/21 23:00:32
Then do the latter.
braveyao
2016/09/21 23:43:18
Done.
Peter Kasting
2016/09/22 00:12:38
So, I just wrote an email thread to chromium-dev a
braveyao
2016/09/22 00:30:23
Done.
| |
| 125 } | |
| OLD | NEW |