OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ |
6 #define CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ | 6 #define CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace policy { | 28 namespace policy { |
29 class MediaStreamDevicesControllerBrowserTest; | 29 class MediaStreamDevicesControllerBrowserTest; |
30 } | 30 } |
31 | 31 |
32 namespace test { | 32 namespace test { |
33 class MediaStreamDevicesControllerTestApi; | 33 class MediaStreamDevicesControllerTestApi; |
34 } | 34 } |
35 | 35 |
36 namespace internal { | 36 namespace internal { |
37 // Delegate showing permission prompts. | 37 |
| 38 // These classes are only needed interally and for tests. They can be removed |
| 39 // once crbug.com/606138 is fixed. |
| 40 class MediaStreamPermissionRequest : public PermissionRequest { |
| 41 public: |
| 42 MediaStreamPermissionRequest( |
| 43 Profile* profile, |
| 44 bool is_asking_for_audio, |
| 45 bool is_asking_for_video, |
| 46 GURL security_origin, |
| 47 base::Callback<void(ContentSetting, bool)> prompt_answered_callback); |
| 48 |
| 49 ~MediaStreamPermissionRequest() override; |
| 50 |
| 51 bool IsAskingForAudio() const; |
| 52 bool IsAskingForVideo() const; |
| 53 base::string16 GetMessageText() const; |
| 54 |
| 55 bool ShouldShowPersistenceToggle() const override; |
| 56 |
| 57 // PermissionRequest: |
| 58 IconId GetIconId() const override; |
| 59 base::string16 GetMessageTextFragment() const override; |
| 60 GURL GetOrigin() const override; |
| 61 void PermissionGranted() override; |
| 62 void PermissionDenied() override; |
| 63 void Cancelled() override; |
| 64 void RequestFinished() override; |
| 65 PermissionRequestType GetPermissionRequestType() const override; |
| 66 |
| 67 private: |
| 68 Profile* profile_; |
| 69 |
| 70 bool is_asking_for_audio_; |
| 71 bool is_asking_for_video_; |
| 72 |
| 73 GURL security_origin_; |
| 74 |
| 75 base::Callback<void(ContentSetting, bool)> prompt_answered_callback_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionRequest); |
| 78 }; |
| 79 |
| 80 // Delegate for showing permission prompts. |
38 class PermissionPromptDelegate { | 81 class PermissionPromptDelegate { |
39 public: | 82 public: |
40 virtual void ShowPrompt( | 83 virtual void ShowPrompt( |
41 bool user_gesture, | 84 bool user_gesture, |
42 content::WebContents* web_contents, | 85 content::WebContents* web_contents, |
43 std::unique_ptr<MediaStreamDevicesController> controller) = 0; | 86 std::unique_ptr<internal::MediaStreamPermissionRequest> request) = 0; |
44 }; | 87 }; |
45 } | |
46 | 88 |
47 class MediaStreamDevicesController : public PermissionRequest { | 89 } // namespace internal |
| 90 |
| 91 class MediaStreamDevicesController { |
48 public: | 92 public: |
49 static void RequestPermissions( | 93 static void RequestPermissions( |
50 const content::MediaStreamRequest& request, | 94 const content::MediaStreamRequest& request, |
51 const content::MediaResponseCallback& callback); | 95 const content::MediaResponseCallback& callback); |
52 | 96 |
53 // Registers the prefs backing the audio and video policies. | 97 // Registers the prefs backing the audio and video policies. |
54 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 98 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
55 | 99 |
56 ~MediaStreamDevicesController() override; | 100 ~MediaStreamDevicesController(); |
57 | 101 |
58 bool IsAskingForAudio() const; | 102 bool IsAskingForAudio() const; |
59 bool IsAskingForVideo() const; | 103 bool IsAskingForVideo() const; |
60 base::string16 GetMessageText() const; | |
61 | 104 |
62 // Forces the permissions to be denied (without being persisted) regardless | 105 // Called when a permission prompt is answered. TODO(raymes): Remove this |
63 // of what the previous state was. If the user had previously allowed the | 106 // once crbug.com/606138 is fixed. |
64 // site video or audio access, this ignores that and informs the site it was | 107 void PromptAnswered(ContentSetting response, bool persist); |
65 // denied. | |
66 // | |
67 // This differs from PermissionGranted/PermissionDenied as they only operate | |
68 // on the permissions if they are in the ASK state. | |
69 void ForcePermissionDeniedTemporarily(); | |
70 | 108 |
71 bool ShouldShowPersistenceToggle() const override; | 109 // Called when a permission prompt is answered through the PermissionManager. |
| 110 void PromptAnsweredGroupedRequest( |
| 111 const std::vector<ContentSetting>& response); |
72 | 112 |
73 // PermissionRequest: | 113 // Called when the Android OS-level prompt is answered. |
74 IconId GetIconId() const override; | 114 void AndroidOSPromptAnswered(bool allowed); |
75 base::string16 GetMessageTextFragment() const override; | 115 |
76 GURL GetOrigin() const override; | 116 // Called when the request is finished and no prompt is required. |
77 void PermissionGranted() override; | 117 void RequestFinishedNoPrompt(); |
78 void PermissionDenied() override; | |
79 void Cancelled() override; | |
80 void RequestFinished() override; | |
81 PermissionRequestType GetPermissionRequestType() const override; | |
82 | 118 |
83 private: | 119 private: |
84 friend class MediaStreamDevicesControllerTest; | 120 friend class MediaStreamDevicesControllerTest; |
85 friend class test::MediaStreamDevicesControllerTestApi; | 121 friend class test::MediaStreamDevicesControllerTestApi; |
86 friend class policy::MediaStreamDevicesControllerBrowserTest; | 122 friend class policy::MediaStreamDevicesControllerBrowserTest; |
87 | 123 |
88 class MediaPermissionStatus; | |
89 class PermissionPromptDelegateImpl; | 124 class PermissionPromptDelegateImpl; |
90 | 125 |
91 static void RequestPermissionsWithDelegate( | 126 static void RequestPermissionsWithDelegate( |
92 const content::MediaStreamRequest& request, | 127 const content::MediaStreamRequest& request, |
93 const content::MediaResponseCallback& callback, | 128 const content::MediaResponseCallback& callback, |
94 internal::PermissionPromptDelegate* delegate); | 129 internal::PermissionPromptDelegate* delegate); |
95 | 130 |
96 MediaStreamDevicesController(content::WebContents* web_contents, | 131 MediaStreamDevicesController(content::WebContents* web_contents, |
97 const content::MediaStreamRequest& request, | 132 const content::MediaStreamRequest& request, |
98 const content::MediaResponseCallback& callback, | 133 const content::MediaResponseCallback& callback); |
99 const MediaPermissionStatus& initial_permission); | |
100 | 134 |
101 bool IsAllowedForAudio() const; | 135 bool IsAllowedForAudio() const; |
102 bool IsAllowedForVideo() const; | 136 bool IsAllowedForVideo() const; |
103 | 137 |
104 // Returns a list of devices available for the request for the given | 138 // Returns a list of devices available for the request for the given |
105 // audio/video permission settings. | 139 // audio/video permission settings. |
106 content::MediaStreamDevices GetDevices(ContentSetting audio_setting, | 140 content::MediaStreamDevices GetDevices(ContentSetting audio_setting, |
107 ContentSetting video_setting); | 141 ContentSetting video_setting); |
108 | 142 |
109 // Runs |callback_| with the given audio/video permission settings. If neither | 143 // Runs |callback_| with the current audio/video permission settings. |
110 // |audio_setting| or |video_setting| is set to allow, |denial_reason| should | 144 void RunCallback(); |
111 // be set to the error to be reported when running |callback_|. | |
112 void RunCallback(ContentSetting audio_setting, | |
113 ContentSetting video_setting, | |
114 content::MediaStreamRequestResult denial_reason); | |
115 | |
116 // Store the permission to use media devices for the origin of the request. | |
117 // This is triggered when the user makes a decision. | |
118 void StorePermission(ContentSetting new_audio_setting, | |
119 ContentSetting new_video_setting) const; | |
120 | 145 |
121 // Called when the permission has been set to update the | 146 // Called when the permission has been set to update the |
122 // TabSpecificContentSettings. | 147 // TabSpecificContentSettings. |
123 void UpdateTabSpecificContentSettings(ContentSetting audio_setting, | 148 void UpdateTabSpecificContentSettings(ContentSetting audio_setting, |
124 ContentSetting video_setting) const; | 149 ContentSetting video_setting) const; |
125 | 150 |
126 // Returns the content settings for the given content type and request. | 151 // Returns the content settings for the given content type and request. |
127 ContentSetting GetContentSetting( | 152 ContentSetting GetContentSetting( |
128 ContentSettingsType content_type, | 153 ContentSettingsType content_type, |
129 const content::MediaStreamRequest& request, | 154 const content::MediaStreamRequest& request, |
130 bool was_requested, | |
131 bool was_initially_blocked, | |
132 content::MediaStreamRequestResult* denial_reason) const; | 155 content::MediaStreamRequestResult* denial_reason) const; |
133 | 156 |
134 // Returns the content setting that should apply given an old content setting | |
135 // and a user decision that has been made. If a user isn't being asked for one | |
136 // of audio/video then we shouldn't change that setting, even if they accept | |
137 // the dialog. | |
138 ContentSetting GetNewSetting(ContentSettingsType content_type, | |
139 ContentSetting old_setting, | |
140 ContentSetting user_decision) const; | |
141 | |
142 // Returns true if clicking allow on the dialog should give access to the | 157 // Returns true if clicking allow on the dialog should give access to the |
143 // requested devices. | 158 // requested devices. |
144 bool IsUserAcceptAllowed(ContentSettingsType content_type) const; | 159 bool IsUserAcceptAllowed(ContentSettingsType content_type) const; |
145 | 160 |
146 // The audio/video content settings BEFORE the user clicks accept/deny. | 161 // The current state of the audio/video content settings. |
147 ContentSetting old_audio_setting_; | 162 ContentSetting audio_setting_; |
148 ContentSetting old_video_setting_; | 163 ContentSetting video_setting_; |
| 164 content::MediaStreamRequestResult denial_reason_; |
149 | 165 |
150 content::WebContents* web_contents_; | 166 content::WebContents* web_contents_; |
151 | 167 |
152 // The owner of this class needs to make sure it does not outlive the profile. | 168 // The owner of this class needs to make sure it does not outlive the profile. |
153 Profile* profile_; | 169 Profile* profile_; |
154 | 170 |
155 // Weak pointer to the tab specific content settings of the tab for which the | 171 // Weak pointer to the tab specific content settings of the tab for which the |
156 // MediaStreamDevicesController was created. The tab specific content | 172 // MediaStreamDevicesController was created. The tab specific content |
157 // settings are associated with a the web contents of the tab. The | 173 // settings are associated with a the web contents of the tab. The |
158 // MediaStreamDeviceController must not outlive the web contents for which it | 174 // MediaStreamDeviceController must not outlive the web contents for which it |
159 // was created. | 175 // was created. |
160 TabSpecificContentSettings* content_settings_; | 176 TabSpecificContentSettings* content_settings_; |
161 | 177 |
162 // The original request for access to devices. | 178 // The original request for access to devices. |
163 const content::MediaStreamRequest request_; | 179 const content::MediaStreamRequest request_; |
164 | 180 |
165 // The callback that needs to be Run to notify WebRTC of whether access to | 181 // The callback that needs to be Run to notify WebRTC of whether access to |
166 // audio/video devices was granted or not. | 182 // audio/video devices was granted or not. |
167 content::MediaResponseCallback callback_; | 183 content::MediaResponseCallback callback_; |
168 | 184 |
169 std::unique_ptr<internal::PermissionPromptDelegate> delegate_; | 185 std::unique_ptr<internal::PermissionPromptDelegate> delegate_; |
170 | 186 |
171 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); | 187 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); |
172 }; | 188 }; |
173 | 189 |
174 #endif // CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ | 190 #endif // CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ |
OLD | NEW |