Index: chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.cc |
diff --git a/chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.cc b/chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5c225d21927fb657507a840aa7d9ec589b92f117 |
--- /dev/null |
+++ b/chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.cc |
@@ -0,0 +1,125 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.h" |
+ |
+#include "base/callback_helpers.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/media/webrtc/desktop_streams_registry.h" |
+#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
+#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "chrome/grit/theme_resources.h" |
+#include "components/infobars/core/infobar.h" |
+#include "components/url_formatter/elide_url.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/common/media_stream_request.h" |
+#include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+// static |
+void ScreenCaptureInfoBarDelegateAndroid::Create( |
+ content::WebContents* web_contents, |
+ const content::MediaStreamRequest& request, |
+ const ResponseCallback& callback) { |
+ InfoBarService* infobar_service = |
+ InfoBarService::FromWebContents(web_contents); |
+ |
+ std::unique_ptr<infobars::InfoBar> new_infobar( |
+ infobar_service->CreateConfirmInfoBar( |
+ std::unique_ptr<ConfirmInfoBarDelegate>( |
+ new ScreenCaptureInfoBarDelegateAndroid(web_contents, request, |
+ callback)))); |
+ |
+ 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.
|
+ infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
+ ScreenCaptureInfoBarDelegateAndroid* delegate = |
+ old_infobar->delegate()->AsScreenCaptureInfoBarDelegateAndroid(); |
+ if (delegate != nullptr) { |
+ infobar_service->ReplaceInfoBar(old_infobar, std::move(new_infobar)); |
+ return; |
+ } |
+ } |
+ |
+ infobar_service->AddInfoBar(std::move(new_infobar)); |
+} |
+ |
+ScreenCaptureInfoBarDelegateAndroid::ScreenCaptureInfoBarDelegateAndroid( |
+ content::WebContents* web_contents, |
+ const content::MediaStreamRequest& request, |
+ const ResponseCallback& callback) |
+ : web_contents_(web_contents), request_(request), callback_(callback) { |
+ 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.
|
+} |
+ |
+ScreenCaptureInfoBarDelegateAndroid::~ScreenCaptureInfoBarDelegateAndroid() { |
+ if (!callback_.is_null()) { |
+ callback_.Run(content::MediaStreamDevices(), |
+ content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
+ 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.
|
+ } |
+} |
+ |
+infobars::InfoBarDelegate::InfoBarIdentifier |
+ScreenCaptureInfoBarDelegateAndroid::GetIdentifier() const { |
+ return SCREEN_CAPTURE_INFOBAR_DELEGATE_ANDROID; |
+} |
+ |
+ScreenCaptureInfoBarDelegateAndroid* |
+ScreenCaptureInfoBarDelegateAndroid::AsScreenCaptureInfoBarDelegateAndroid() { |
+ return this; |
+} |
+ |
+base::string16 ScreenCaptureInfoBarDelegateAndroid::GetMessageText() const { |
+ return l10n_util::GetStringFUTF16( |
+ IDS_MEDIA_CAPTURE_SCREEN, |
+ url_formatter::FormatUrlForSecurityDisplay(request_.security_origin)); |
+} |
+ |
+int ScreenCaptureInfoBarDelegateAndroid::GetIconId() const { |
+ return IDR_INFOBAR_MEDIA_STREAM_SCREEN; |
+} |
+ |
+base::string16 ScreenCaptureInfoBarDelegateAndroid::GetButtonLabel( |
+ InfoBarButton button) const { |
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
+ : IDS_PERMISSION_DENY); |
+} |
+ |
+bool ScreenCaptureInfoBarDelegateAndroid::Accept() { |
+ RunCallback(content::MEDIA_DEVICE_OK); |
+ return true; |
+} |
+ |
+bool ScreenCaptureInfoBarDelegateAndroid::Cancel() { |
+ RunCallback(content::MEDIA_DEVICE_PERMISSION_DENIED); |
+ return true; |
+} |
+ |
+void ScreenCaptureInfoBarDelegateAndroid::InfoBarDismissed() { |
+ RunCallback(content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
+} |
+ |
+void ScreenCaptureInfoBarDelegateAndroid::RunCallback( |
+ content::MediaStreamRequestResult result) { |
+ 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.
|
+ |
+ content::MediaStreamDevices devices = content::MediaStreamDevices(); |
+ if (result == content::MEDIA_DEVICE_OK) { |
+ 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.
|
+ screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
+ webrtc::kFullDesktopScreenId); |
+ devices.push_back(content::MediaStreamDevice( |
+ content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen")); |
+ } |
+ |
+ std::unique_ptr<content::MediaStreamUI> ui; |
+ if (!devices.empty()) { |
+ ui = MediaCaptureDevicesDispatcher::GetInstance() |
+ ->GetMediaStreamCaptureIndicator() |
+ ->RegisterMediaStream(web_contents_, devices); |
+ } |
+ |
+ 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.
|
+} |