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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
#define CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
#include <map>
#include <string>
#include "chrome/browser/ui/website_settings/permission_bubble_request.h"
#include "content/public/browser/web_contents_delegate.h"
class Profile;
class TabSpecificContentSettings;
namespace content {
class WebContents;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
class MediaStreamDevicesController : public PermissionBubbleRequest {
public:
// Permissions for media stream types.
enum Permission {
MEDIA_NONE,
MEDIA_ALLOWED,
MEDIA_BLOCKED_BY_POLICY,
MEDIA_BLOCKED_BY_USER_SETTING,
MEDIA_BLOCKED_BY_USER,
};
struct MediaStreamTypeSettings {
MediaStreamTypeSettings(Permission permission,
const std::string& requested_device_id);
MediaStreamTypeSettings();
~MediaStreamTypeSettings();
Permission permission;
std::string requested_device_id;
};
typedef std::map<content::MediaStreamType, MediaStreamTypeSettings>
MediaStreamTypeSettingsMap;
MediaStreamDevicesController(content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback);
virtual ~MediaStreamDevicesController();
// TODO(tommi): Clean up all the policy code and integrate with
// HostContentSettingsMap instead. This will make creating the UI simpler
// and the code cleaner. crbug.com/244389.
// Registers the prefs backing the audio and video policies.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// Public method to be called before creating the MediaStreamInfoBarDelegate.
// This function will check the content settings exceptions and take the
// corresponding action on exception which matches the request.
bool DismissInfoBarAndTakeActionOnSettings();
// Public methods to be called by MediaStreamInfoBarDelegate;
bool HasAudio() const;
bool HasVideo() const;
const std::string& GetSecurityOriginSpec() const;
void Accept(bool update_content_setting);
void Deny(bool update_content_setting,
content::MediaStreamRequestResult result);
// PermissionBubbleRequest:
virtual int GetIconID() const OVERRIDE;
virtual base::string16 GetMessageText() const OVERRIDE;
virtual base::string16 GetMessageTextFragment() const OVERRIDE;
virtual bool HasUserGesture() const OVERRIDE;
virtual GURL GetRequestingHostname() const OVERRIDE;
virtual void PermissionGranted() OVERRIDE;
virtual void PermissionDenied() OVERRIDE;
virtual void Cancelled() OVERRIDE;
virtual void RequestFinished() OVERRIDE;
private:
enum DevicePolicy {
POLICY_NOT_SET,
ALWAYS_DENY,
ALWAYS_ALLOW,
};
// Called by GetAudioDevicePolicy and GetVideoDevicePolicy to check
// the currently set capture device policy.
DevicePolicy GetDevicePolicy(const char* policy_name,
const char* whitelist_policy_name) const;
// Returns true if the origin of the request has been granted the media
// access before, otherwise returns false.
bool IsRequestAllowedByDefault() const;
// Check if any device of the request has been blocked for the origin of the
// request and clears |microphone_requested_| or |webcam_requested_| flags if
// they are not allowed anymore. Returns the number of devices that are
// allowed after this step. If the count reaches zero the request can be
// denied completely, else it still has to be partially fullfilled.
int FilterBlockedByDefaultDevices();
// Returns true if the media section in content settings is set to
// |CONTENT_SETTING_BLOCK|, otherwise returns false.
bool IsDefaultMediaAccessBlocked() const;
// Returns true if the origin is a secure scheme, otherwise returns false.
bool IsSchemeSecure() const;
// Returns true if request's origin is from internal objects like
// chrome://URLs, otherwise returns false.
bool ShouldAlwaysAllowOrigin() const;
// Sets the permission of the origin of the request. This is triggered when
// the users deny the request or allow the request for https sites.
void SetPermission(bool allowed) const;
// Notifies the content setting UI that the media stream access request or
// part of the request is accepted.
void NotifyUIRequestAccepted() const;
// Notifies the content setting UI that the media stream access request or
// part of the request is denied.
void NotifyUIRequestDenied();
// Return true if the type has been requested and permission is currently set
// to allowed. Note that it does not reflect the final permission decision.
// This function is called during the filtering steps to check if the type has
// been blocked yet or not and the permission may be changed to blocked during
// these filterings. See also the initialization in the constructor and
// comments on that.
bool IsDeviceAudioCaptureRequestedAndAllowed() const;
bool IsDeviceVideoCaptureRequestedAndAllowed() const;
content::WebContents* web_contents_;
// The owner of this class needs to make sure it does not outlive the profile.
Profile* profile_;
// Weak pointer to the tab specific content settings of the tab for which the
// MediaStreamDevicesController was created. The tab specific content
// settings are associated with a the web contents of the tab. The
// MediaStreamDeviceController must not outlive the web contents for which it
// was created.
TabSpecificContentSettings* content_settings_;
// The original request for access to devices.
const content::MediaStreamRequest request_;
// The callback that needs to be Run to notify WebRTC of whether access to
// audio/video devices was granted or not.
content::MediaResponseCallback callback_;
// Holds the requested media types and the permission for each type. It is
// passed to the tab specific content settings when the permissions have been
// resolved. Currently only used by MEDIA_DEVICE_AUDIO_CAPTURE and
// MEDIA_DEVICE_VIDEO_CAPTURE since those are the only types that require
// updates in the settings.
MediaStreamTypeSettingsMap request_permissions_;
DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController);
};
#endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
|