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 "chrome/browser/ui/website_settings/permission_bubble_request.h"
12 #include "content/public/browser/web_contents_delegate.h"
15 class TabSpecificContentSettings
;
21 namespace user_prefs
{
22 class PrefRegistrySyncable
;
25 class MediaStreamDevicesController
: public PermissionBubbleRequest
{
27 // Permissions for media stream types.
31 MEDIA_BLOCKED_BY_POLICY
,
32 MEDIA_BLOCKED_BY_USER_SETTING
,
33 MEDIA_BLOCKED_BY_USER
,
36 struct MediaStreamTypeSettings
{
37 MediaStreamTypeSettings(Permission permission
,
38 const std::string
& requested_device_id
);
39 MediaStreamTypeSettings();
40 ~MediaStreamTypeSettings();
42 Permission permission
;
43 std::string requested_device_id
;
46 typedef std::map
<content::MediaStreamType
, MediaStreamTypeSettings
>
47 MediaStreamTypeSettingsMap
;
49 MediaStreamDevicesController(content::WebContents
* web_contents
,
50 const content::MediaStreamRequest
& request
,
51 const content::MediaResponseCallback
& callback
);
53 virtual ~MediaStreamDevicesController();
55 // TODO(tommi): Clean up all the policy code and integrate with
56 // HostContentSettingsMap instead. This will make creating the UI simpler
57 // and the code cleaner. crbug.com/244389.
59 // Registers the prefs backing the audio and video policies.
60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
62 // Public method to be called before creating the MediaStreamInfoBarDelegate.
63 // This function will check the content settings exceptions and take the
64 // corresponding action on exception which matches the request.
65 bool DismissInfoBarAndTakeActionOnSettings();
67 // Public methods to be called by MediaStreamInfoBarDelegate;
68 bool HasAudio() const;
69 bool HasVideo() const;
70 const std::string
& GetSecurityOriginSpec() const;
71 void Accept(bool update_content_setting
);
72 void Deny(bool update_content_setting
,
73 content::MediaStreamRequestResult result
);
75 // PermissionBubbleRequest:
76 virtual int GetIconID() const OVERRIDE
;
77 virtual base::string16
GetMessageText() const OVERRIDE
;
78 virtual base::string16
GetMessageTextFragment() const OVERRIDE
;
79 virtual bool HasUserGesture() const OVERRIDE
;
80 virtual GURL
GetRequestingHostname() const OVERRIDE
;
81 virtual void PermissionGranted() OVERRIDE
;
82 virtual void PermissionDenied() OVERRIDE
;
83 virtual void Cancelled() OVERRIDE
;
84 virtual void RequestFinished() OVERRIDE
;
93 // Called by GetAudioDevicePolicy and GetVideoDevicePolicy to check
94 // the currently set capture device policy.
95 DevicePolicy
GetDevicePolicy(const char* policy_name
,
96 const char* whitelist_policy_name
) const;
98 // Returns true if the origin of the request has been granted the media
99 // access before, otherwise returns false.
100 bool IsRequestAllowedByDefault() const;
102 // Check if any device of the request has been blocked for the origin of the
103 // request and clears |microphone_requested_| or |webcam_requested_| flags if
104 // they are not allowed anymore. Returns the number of devices that are
105 // allowed after this step. If the count reaches zero the request can be
106 // denied completely, else it still has to be partially fullfilled.
107 int FilterBlockedByDefaultDevices();
109 // Returns true if the media section in content settings is set to
110 // |CONTENT_SETTING_BLOCK|, otherwise returns false.
111 bool IsDefaultMediaAccessBlocked() const;
113 // Returns true if the origin is a secure scheme, otherwise returns false.
114 bool IsSchemeSecure() const;
116 // Returns true if request's origin is from internal objects like
117 // chrome://URLs, otherwise returns false.
118 bool ShouldAlwaysAllowOrigin() const;
120 // Sets the permission of the origin of the request. This is triggered when
121 // the users deny the request or allow the request for https sites.
122 void SetPermission(bool allowed
) const;
124 // Notifies the content setting UI that the media stream access request or
125 // part of the request is accepted.
126 void NotifyUIRequestAccepted() const;
128 // Notifies the content setting UI that the media stream access request or
129 // part of the request is denied.
130 void NotifyUIRequestDenied();
132 // Return true if the type has been requested and permission is currently set
133 // to allowed. Note that it does not reflect the final permission decision.
134 // This function is called during the filtering steps to check if the type has
135 // been blocked yet or not and the permission may be changed to blocked during
136 // these filterings. See also the initialization in the constructor and
138 bool IsDeviceAudioCaptureRequestedAndAllowed() const;
139 bool IsDeviceVideoCaptureRequestedAndAllowed() const;
141 content::WebContents
* web_contents_
;
143 // The owner of this class needs to make sure it does not outlive the profile.
146 // Weak pointer to the tab specific content settings of the tab for which the
147 // MediaStreamDevicesController was created. The tab specific content
148 // settings are associated with a the web contents of the tab. The
149 // MediaStreamDeviceController must not outlive the web contents for which it
151 TabSpecificContentSettings
* content_settings_
;
153 // The original request for access to devices.
154 const content::MediaStreamRequest request_
;
156 // The callback that needs to be Run to notify WebRTC of whether access to
157 // audio/video devices was granted or not.
158 content::MediaResponseCallback callback_
;
160 // Holds the requested media types and the permission for each type. It is
161 // passed to the tab specific content settings when the permissions have been
162 // resolved. Currently only used by MEDIA_DEVICE_AUDIO_CAPTURE and
163 // MEDIA_DEVICE_VIDEO_CAPTURE since those are the only types that require
164 // updates in the settings.
165 MediaStreamTypeSettingsMap request_permissions_
;
167 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController
);
170 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_