Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.cc

Issue 2123863004: ScreenCapture for Android phase1, part II (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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);
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, nullptr);
47 }
48 }
49
50 infobars::InfoBarDelegate::InfoBarIdentifier
51 ScreenCaptureInfoBarDelegateAndroid::GetIdentifier() const {
52 return SCREEN_CAPTURE_INFOBAR_DELEGATE_ANDROID;
53 }
54
55 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetMessageText() const {
56 return l10n_util::GetStringFUTF16(
57 IDS_MEDIA_CAPTURE_SCREEN,
58 url_formatter::FormatUrlForSecurityDisplay(request_.security_origin));
59 }
60
61 int ScreenCaptureInfoBarDelegateAndroid::GetIconId() const {
62 return IDR_INFOBAR_MEDIA_STREAM_SCREEN;
63 }
64
65 base::string16 ScreenCaptureInfoBarDelegateAndroid::GetButtonLabel(
66 InfoBarButton button) const {
67 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW
68 : IDS_PERMISSION_DENY);
69 }
70
71 bool ScreenCaptureInfoBarDelegateAndroid::Accept() {
72 RunCallback(content::MEDIA_DEVICE_OK);
73 return true;
74 }
75
76 bool ScreenCaptureInfoBarDelegateAndroid::Cancel() {
77 RunCallback(content::MEDIA_DEVICE_PERMISSION_DENIED);
78 return true;
79 }
80
81 void ScreenCaptureInfoBarDelegateAndroid::InfoBarDismissed() {
82 RunCallback(content::MEDIA_DEVICE_PERMISSION_DISMISSED);
83 }
84
85 void ScreenCaptureInfoBarDelegateAndroid::RunCallback(
86 content::MediaStreamRequestResult result) {
87 DCHECK(!callback_.is_null());
88
89 content::MediaStreamDevices devices;
90 std::unique_ptr<content::MediaStreamUI> ui;
91 if (result == content::MEDIA_DEVICE_OK) {
92 content::DesktopMediaID screen_id = content::DesktopMediaID(
93 content::DesktopMediaID::TYPE_SCREEN, webrtc::kFullDesktopScreenId);
94 devices.push_back(content::MediaStreamDevice(
95 content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen"));
96
97 ui = MediaCaptureDevicesDispatcher::GetInstance()
98 ->GetMediaStreamCaptureIndicator()
99 ->RegisterMediaStream(web_contents_, devices);
100 }
101
102 base::ResetAndReturn(&callback_).Run(devices, result, std::move(ui));
103 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/screen_capture_infobar_delegate_android.h ('k') | components/infobars/core/infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698