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. 4 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ 6 #define CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ 7 8 #include <string> 9 10 #include "content/public/browser/web_contents_delegate.h" 11 12 class Profile; 13 class TabSpecificContentSettings; 14 15 namespace content { 16 class WebContents; 17 } 18 19 namespace user_prefs { 20 class PrefRegistrySyncable; 21 } 22 23 class MediaStreamDevicesController { 24 public: 25 MediaStreamDevicesController(content::WebContents* web_contents, 26 const content::MediaStreamRequest& request, 27 const content::MediaResponseCallback& callback); 28 29 virtual ~MediaStreamDevicesController(); 30 31 // TODO(tommi): Clean up all the policy code and integrate with 32 // HostContentSettingsMap instead. This will make creating the UI simpler 33 // and the code cleaner. crbug.com/244389. 34 35 // Registers the prefs backing the audio and video policies. 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 37 38 // Public method to be called before creating the MediaStreamInfoBarDelegate. 39 // This function will check the content settings exceptions and take the 40 // corresponding action on exception which matches the request. 41 bool DismissInfoBarAndTakeActionOnSettings(); 42 43 // Public methods to be called by MediaStreamInfoBarDelegate; 44 bool has_audio() const { return microphone_requested_; } 45 bool has_video() const { return webcam_requested_; } 46 const std::string& GetSecurityOriginSpec() const; 47 void Accept(bool update_content_setting); 48 void Deny(bool update_content_setting); 49 50 private: 51 enum DevicePolicy { 52 POLICY_NOT_SET, 53 ALWAYS_DENY, 54 ALWAYS_ALLOW, 55 }; 56 57 // Called by GetAudioDevicePolicy and GetVideoDevicePolicy to check 58 // the currently set capture device policy. 59 DevicePolicy GetDevicePolicy(const char* policy_name, 60 const char* whitelist_policy_name) const; 61 62 // Returns true if the origin of the request has been granted the media 63 // access before, otherwise returns false. 64 bool IsRequestAllowedByDefault() const; 65 66 // Check if any device of the request has been blocked for the origin of the 67 // request and clears |microphone_requested_| or |webcam_requested_| flags if 68 // they are not allowed anymore. Returns the number of devices that are 69 // allowed after this step. If the count reaches zero the request can be 70 // denied completely, else it still has to be partially fullfilled. 71 int FilterBlockedByDefaultDevices(); 72 73 // Returns true if the media section in content settings is set to 74 // |CONTENT_SETTING_BLOCK|, otherwise returns false. 75 bool IsDefaultMediaAccessBlocked() const; 76 77 // Returns true if the origin is a secure scheme, otherwise returns false. 78 bool IsSchemeSecure() const; 79 80 // Returns true if request's origin is from internal objects like 81 // chrome://URLs, otherwise returns false. 82 bool ShouldAlwaysAllowOrigin() const; 83 84 // Sets the permission of the origin of the request. This is triggered when 85 // the users deny the request or allow the request for https sites. 86 void SetPermission(bool allowed) const; 87 88 // Notifies the content setting UI that the media stream access request or 89 // part of the request is accepted. 90 void NotifyUIRequestAccepted() const; 91 92 // Notifies the content setting UI that the media stream access request or 93 // part of the request is denied. 94 void NotifyUIRequestDenied() const; 95 96 content::WebContents* web_contents_; 97 98 // The owner of this class needs to make sure it does not outlive the profile. 99 Profile* profile_; 100 101 // Weak pointer to the tab specific content settings of the tab for which the 102 // MediaStreamDevicesController was created. The tab specific content 103 // settings are associated with a the web contents of the tab. The 104 // MediaStreamDeviceController must not outlive the web contents for which it 105 // was created. 106 TabSpecificContentSettings* content_settings_; 107 108 // The original request for access to devices. 109 const content::MediaStreamRequest request_; 110 111 // The callback that needs to be Run to notify WebRTC of whether access to 112 // audio/video devices was granted or not. 113 content::MediaResponseCallback callback_; 114 115 bool microphone_requested_; 116 bool webcam_requested_; 117 118 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); 119 }; 120 121 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ 122