1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (c) 2013 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/ui/screen_capture_infobar_delegate.h"
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/api/infobars/infobar_service.h"
#include "chrome/common/chrome_switches.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
// static
void ScreenCaptureInfoBarDelegate::Create(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) {
bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableUserMediaScreenCapturing);
// Deny request automatically in the following cases:
// 1. Screen capturing is not enabled via command line switch.
// 2. Audio capture was requested (it's not supported yet).
// 3. Request from a page that was not loaded from a secure origin.
if (!screen_capture_enabled ||
request.audio_type != content::MEDIA_NO_SERVICE ||
!request.security_origin.SchemeIsSecure()) {
callback.Run(content::MediaStreamDevices());
return;
}
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents);
infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
new ScreenCaptureInfoBarDelegate(infobar_service, request, callback)));
}
ScreenCaptureInfoBarDelegate::ScreenCaptureInfoBarDelegate(
InfoBarService* infobar_service,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback)
: ConfirmInfoBarDelegate(infobar_service),
request_(request),
callback_(callback) {
DCHECK_EQ(content::MEDIA_SCREEN_VIDEO_CAPTURE, request.video_type);
}
ScreenCaptureInfoBarDelegate::~ScreenCaptureInfoBarDelegate() {
}
// Needed to avoid having more than one infobar with the same request.
bool ScreenCaptureInfoBarDelegate::EqualsDelegate(
InfoBarDelegate* delegate) const {
ScreenCaptureInfoBarDelegate* other =
delegate->AsScreenCaptureInfoBarDelegate();
return other && other->request_.security_origin == request_.security_origin;
}
void ScreenCaptureInfoBarDelegate::InfoBarDismissed() {
Deny();
}
InfoBarDelegate::Type ScreenCaptureInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
ScreenCaptureInfoBarDelegate*
ScreenCaptureInfoBarDelegate::AsScreenCaptureInfoBarDelegate() {
return this;
}
string16 ScreenCaptureInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(
IDS_MEDIA_CAPTURE_SCREEN,
UTF8ToUTF16(request_.security_origin.spec()));
}
string16 ScreenCaptureInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_DENY);
}
bool ScreenCaptureInfoBarDelegate::Accept() {
content::MediaStreamDevices devices;
// Add screen capturer source if it was requested.
devices.push_back(content::MediaStreamDevice(
content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen"));
callback_.Run(devices);
return true;
}
bool ScreenCaptureInfoBarDelegate::Cancel() {
Deny();
return true;
}
void ScreenCaptureInfoBarDelegate::Deny() {
callback_.Run(content::MediaStreamDevices());
}
|