1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
11 #include "content/public/browser/web_contents_delegate.h"
14 class TabSpecificContentSettings
;
20 namespace user_prefs
{
21 class PrefRegistrySyncable
;
24 class MediaStreamDevicesController
{
26 // Permissions for media stream types.
30 MEDIA_BLOCKED_BY_POLICY
,
31 MEDIA_BLOCKED_BY_USER_SETTING
,
32 MEDIA_BLOCKED_BY_USER
,
35 struct MediaStreamTypeSettings
{
36 MediaStreamTypeSettings(Permission permission
,
37 const std::string
& requested_device_id
);
38 MediaStreamTypeSettings();
39 ~MediaStreamTypeSettings();
41 Permission permission
;
42 std::string requested_device_id
;
45 typedef std::map
<content::MediaStreamType
, MediaStreamTypeSettings
>
46 MediaStreamTypeSettingsMap
;
48 MediaStreamDevicesController(content::WebContents
* web_contents
,
49 const content::MediaStreamRequest
& request
,
50 const content::MediaResponseCallback
& callback
);
52 virtual ~MediaStreamDevicesController();
54 // TODO(tommi): Clean up all the policy code and integrate with
55 // HostContentSettingsMap instead. This will make creating the UI simpler
56 // and the code cleaner. crbug.com/244389.
58 // Registers the prefs backing the audio and video policies.
59 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
61 // Public method to be called before creating the MediaStreamInfoBarDelegate.
62 // This function will check the content settings exceptions and take the
63 // corresponding action on exception which matches the request.
64 bool DismissInfoBarAndTakeActionOnSettings();
66 // Public methods to be called by MediaStreamInfoBarDelegate;
67 bool HasAudio() const;
68 bool HasVideo() const;
69 const std::string
& GetSecurityOriginSpec() const;
70 void Accept(bool update_content_setting
);
71 void Deny(bool update_content_setting
);
80 // Called by GetAudioDevicePolicy and GetVideoDevicePolicy to check
81 // the currently set capture device policy.
82 DevicePolicy
GetDevicePolicy(const char* policy_name
,
83 const char* whitelist_policy_name
) const;
85 // Returns true if the origin of the request has been granted the media
86 // access before, otherwise returns false.
87 bool IsRequestAllowedByDefault() const;
89 // Check if any device of the request has been blocked for the origin of the
90 // request and clears |microphone_requested_| or |webcam_requested_| flags if
91 // they are not allowed anymore. Returns the number of devices that are
92 // allowed after this step. If the count reaches zero the request can be
93 // denied completely, else it still has to be partially fullfilled.
94 int FilterBlockedByDefaultDevices();
96 // Returns true if the media section in content settings is set to
97 // |CONTENT_SETTING_BLOCK|, otherwise returns false.
98 bool IsDefaultMediaAccessBlocked() const;
100 // Returns true if the origin is a secure scheme, otherwise returns false.
101 bool IsSchemeSecure() const;
103 // Returns true if request's origin is from internal objects like
104 // chrome://URLs, otherwise returns false.
105 bool ShouldAlwaysAllowOrigin() const;
107 // Sets the permission of the origin of the request. This is triggered when
108 // the users deny the request or allow the request for https sites.
109 void SetPermission(bool allowed
) const;
111 // Notifies the content setting UI that the media stream access request or
112 // part of the request is accepted.
113 void NotifyUIRequestAccepted() const;
115 // Notifies the content setting UI that the media stream access request or
116 // part of the request is denied.
117 void NotifyUIRequestDenied();
119 // Return true if the type has been requested and permission is currently set
120 // to allowed. Note that it does not reflect the final permission decision.
121 // This function is called during the filtering steps to check if the type has
122 // been blocked yet or not and the permission may be changed to blocked during
123 // these filterings. See also the initialization in the constructor and
125 bool IsDeviceAudioCaptureRequestedAndAllowed() const;
126 bool IsDeviceVideoCaptureRequestedAndAllowed() const;
128 content::WebContents
* web_contents_
;
130 // The owner of this class needs to make sure it does not outlive the profile.
133 // Weak pointer to the tab specific content settings of the tab for which the
134 // MediaStreamDevicesController was created. The tab specific content
135 // settings are associated with a the web contents of the tab. The
136 // MediaStreamDeviceController must not outlive the web contents for which it
138 TabSpecificContentSettings
* content_settings_
;
140 // The original request for access to devices.
141 const content::MediaStreamRequest request_
;
143 // The callback that needs to be Run to notify WebRTC of whether access to
144 // audio/video devices was granted or not.
145 content::MediaResponseCallback callback_
;
147 // Holds the requested media types and the permission for each type. It is
148 // passed to the tab specific content settings when the permissions have been
149 // resolved. Currently only used by MEDIA_DEVICE_AUDIO_CAPTURE and
150 // MEDIA_DEVICE_VIDEO_CAPTURE since those are the only types that require
151 // updates in the settings.
152 MediaStreamTypeSettingsMap request_permissions_
;
154 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController
);
157 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_