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

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

Powered by Google App Engine
This is Rietveld 408576698