| OLD | NEW |
| (Empty) |
| 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 <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "chrome/browser/permissions/permission_request.h" | |
| 13 #include "components/content_settings/core/common/content_settings.h" | |
| 14 #include "content/public/browser/web_contents_delegate.h" | |
| 15 | |
| 16 class Profile; | |
| 17 class TabSpecificContentSettings; | |
| 18 | |
| 19 namespace content { | |
| 20 class WebContents; | |
| 21 } | |
| 22 | |
| 23 namespace user_prefs { | |
| 24 class PrefRegistrySyncable; | |
| 25 } | |
| 26 | |
| 27 class MediaStreamDevicesController : public PermissionRequest { | |
| 28 public: | |
| 29 MediaStreamDevicesController(content::WebContents* web_contents, | |
| 30 const content::MediaStreamRequest& request, | |
| 31 const content::MediaResponseCallback& callback); | |
| 32 | |
| 33 ~MediaStreamDevicesController() override; | |
| 34 | |
| 35 // Registers the prefs backing the audio and video policies. | |
| 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 37 | |
| 38 bool IsAllowedForAudio() const; | |
| 39 bool IsAllowedForVideo() const; | |
| 40 bool IsAskingForAudio() const; | |
| 41 bool IsAskingForVideo() const; | |
| 42 base::string16 GetMessageText() const; | |
| 43 | |
| 44 // Forces the permissions to be denied (without being persisted) regardless | |
| 45 // of what the previous state was. If the user had previously allowed the | |
| 46 // site video or audio access, this ignores that and informs the site it was | |
| 47 // denied. | |
| 48 // | |
| 49 // This differs from PermissionGranted/PermissionDenied as they only operate | |
| 50 // on the permissions if they are in the ASK state. | |
| 51 void ForcePermissionDeniedTemporarily(); | |
| 52 | |
| 53 // Answers a permission request with (possibly) different values for | |
| 54 // |audio_accepted| and |video_accepted|. Intended for use from | |
| 55 // MediaStreamInfobarDelegateAndroid. | |
| 56 // TODO(tsergeant): Remove this by refactoring Android to use | |
| 57 // PermissionRequest instead of a custom infobar delegate. | |
| 58 void GroupedRequestFinished(bool audio_accepted, bool video_accepted); | |
| 59 | |
| 60 // PermissionRequest: | |
| 61 int GetIconId() const override; | |
| 62 base::string16 GetMessageTextFragment() const override; | |
| 63 GURL GetOrigin() const override; | |
| 64 void PermissionGranted() override; | |
| 65 void PermissionDenied() override; | |
| 66 void Cancelled() override; | |
| 67 void RequestFinished() override; | |
| 68 PermissionRequestType GetPermissionRequestType() const override; | |
| 69 | |
| 70 private: | |
| 71 // Returns a list of devices available for the request for the given | |
| 72 // audio/video permission settings. | |
| 73 content::MediaStreamDevices GetDevices(ContentSetting audio_setting, | |
| 74 ContentSetting video_setting); | |
| 75 | |
| 76 // Runs |callback_| with the given audio/video permission settings. If neither | |
| 77 // |audio_setting| or |video_setting| is set to allow, |denial_reason| should | |
| 78 // be set to the error to be reported when running |callback_|. | |
| 79 void RunCallback(ContentSetting audio_setting, | |
| 80 ContentSetting video_setting, | |
| 81 content::MediaStreamRequestResult denial_reason); | |
| 82 | |
| 83 // Store the permission to use media devices for the origin of the request. | |
| 84 // This is triggered when the user makes a decision. | |
| 85 void StorePermission(ContentSetting new_audio_setting, | |
| 86 ContentSetting new_video_setting) const; | |
| 87 | |
| 88 // Called when the permission has been set to update the | |
| 89 // TabSpecificContentSettings. | |
| 90 void UpdateTabSpecificContentSettings(ContentSetting audio_setting, | |
| 91 ContentSetting video_setting) const; | |
| 92 | |
| 93 // Returns the content settings for the given content type and request. | |
| 94 ContentSetting GetContentSetting( | |
| 95 ContentSettingsType content_type, | |
| 96 const content::MediaStreamRequest& request, | |
| 97 content::MediaStreamRequestResult* denial_reason) const; | |
| 98 | |
| 99 // Returns the content setting that should apply given an old content setting | |
| 100 // and a user decision that has been made. If a user isn't being asked for one | |
| 101 // of audio/video then we shouldn't change that setting, even if they accept | |
| 102 // the dialog. | |
| 103 ContentSetting GetNewSetting(ContentSettingsType content_type, | |
| 104 ContentSetting old_setting, | |
| 105 ContentSetting user_decision) const; | |
| 106 | |
| 107 // Returns true if clicking allow on the dialog should give access to the | |
| 108 // requested devices. | |
| 109 bool IsUserAcceptAllowed(ContentSettingsType content_type) const; | |
| 110 | |
| 111 // The audio/video content settings BEFORE the user clicks accept/deny. | |
| 112 ContentSetting old_audio_setting_; | |
| 113 ContentSetting old_video_setting_; | |
| 114 | |
| 115 content::WebContents* web_contents_; | |
| 116 | |
| 117 // The owner of this class needs to make sure it does not outlive the profile. | |
| 118 Profile* profile_; | |
| 119 | |
| 120 // Weak pointer to the tab specific content settings of the tab for which the | |
| 121 // MediaStreamDevicesController was created. The tab specific content | |
| 122 // settings are associated with a the web contents of the tab. The | |
| 123 // MediaStreamDeviceController must not outlive the web contents for which it | |
| 124 // was created. | |
| 125 TabSpecificContentSettings* content_settings_; | |
| 126 | |
| 127 // The original request for access to devices. | |
| 128 const content::MediaStreamRequest request_; | |
| 129 | |
| 130 // The callback that needs to be Run to notify WebRTC of whether access to | |
| 131 // audio/video devices was granted or not. | |
| 132 content::MediaResponseCallback callback_; | |
| 133 | |
| 134 // Whether the permissions granted or denied by the user should be persisted. | |
| 135 bool persist_permission_changes_; | |
| 136 | |
| 137 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); | |
| 138 }; | |
| 139 | |
| 140 #endif // CHROME_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ | |
| OLD | NEW |