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 15 matching lines...) Expand all Loading... |
26 } | 26 } |
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 class MediaStreamDevicesController { |
37 // Delegate showing permission prompts. | |
38 class PermissionPromptDelegate { | |
39 public: | 37 public: |
40 virtual void ShowPrompt( | 38 // This class is only needed until we unify the codepaths for permission |
41 bool user_gesture, | 39 // requests. It can be removed once crbug.com/606138 is fixed. |
42 content::WebContents* web_contents, | 40 class Request : public PermissionRequest { |
43 std::unique_ptr<MediaStreamDevicesController> controller) = 0; | 41 public: |
44 }; | 42 using PromptAnsweredCallback = |
45 } | 43 base::Callback<void(ContentSetting, bool /* persist */)>; |
46 | 44 |
47 class MediaStreamDevicesController : public PermissionRequest { | 45 Request(Profile* profile, |
48 public: | 46 bool is_asking_for_audio, |
| 47 bool is_asking_for_video, |
| 48 const GURL& security_origin, |
| 49 PromptAnsweredCallback prompt_answered_callback); |
| 50 |
| 51 ~Request() override; |
| 52 |
| 53 bool IsAskingForAudio() const; |
| 54 bool IsAskingForVideo() const; |
| 55 base::string16 GetMessageText() const; |
| 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 bool ShouldShowPersistenceToggle() const override; |
| 67 |
| 68 private: |
| 69 Profile* profile_; |
| 70 |
| 71 bool is_asking_for_audio_; |
| 72 bool is_asking_for_video_; |
| 73 |
| 74 GURL security_origin_; |
| 75 |
| 76 PromptAnsweredCallback prompt_answered_callback_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(Request); |
| 79 }; |
| 80 |
| 81 // This class is only needed interally and for tests. It can be removed once |
| 82 // crbug.com/606138 is fixed. Delegate for showing permission prompts. It's |
| 83 // only public because subclassing from a friend class doesn't work in gcc |
| 84 // (see https://codereview.chromium.org/2768923003). |
| 85 class PermissionPromptDelegate { |
| 86 public: |
| 87 virtual void ShowPrompt( |
| 88 bool user_gesture, |
| 89 content::WebContents* web_contents, |
| 90 std::unique_ptr<MediaStreamDevicesController::Request> request) = 0; |
| 91 }; |
| 92 |
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; | 104 |
| 105 // Called when a permission prompt has been answered, with the |response| and |
| 106 // whether the choice should be persisted. |
| 107 void PromptAnswered(ContentSetting response, bool persist); |
61 | 108 |
62 #if defined(OS_ANDROID) | 109 #if defined(OS_ANDROID) |
63 // Called when the Android OS-level prompt is answered. | 110 // Called when the Android OS-level prompt is answered. |
64 void AndroidOSPromptAnswered(bool allowed); | 111 void AndroidOSPromptAnswered(bool allowed); |
65 #endif // defined(OS_ANDROID) | 112 #endif // defined(OS_ANDROID) |
66 | 113 |
67 bool ShouldShowPersistenceToggle() const override; | |
68 | |
69 // PermissionRequest: | |
70 IconId GetIconId() const override; | |
71 base::string16 GetMessageTextFragment() const override; | |
72 GURL GetOrigin() const override; | |
73 void PermissionGranted() override; | |
74 void PermissionDenied() override; | |
75 void Cancelled() override; | |
76 void RequestFinished() override; | |
77 PermissionRequestType GetPermissionRequestType() const override; | |
78 | |
79 private: | 114 private: |
80 friend class MediaStreamDevicesControllerTest; | 115 friend class MediaStreamDevicesControllerTest; |
81 friend class test::MediaStreamDevicesControllerTestApi; | 116 friend class test::MediaStreamDevicesControllerTestApi; |
82 friend class policy::MediaStreamDevicesControllerBrowserTest; | 117 friend class policy::MediaStreamDevicesControllerBrowserTest; |
83 | 118 |
84 class PermissionPromptDelegateImpl; | 119 class PermissionPromptDelegateImpl; |
85 | 120 |
86 static void RequestPermissionsWithDelegate( | 121 static void RequestPermissionsWithDelegate( |
87 const content::MediaStreamRequest& request, | 122 const content::MediaStreamRequest& request, |
88 const content::MediaResponseCallback& callback, | 123 const content::MediaResponseCallback& callback, |
89 internal::PermissionPromptDelegate* delegate); | 124 PermissionPromptDelegate* delegate); |
90 | 125 |
91 MediaStreamDevicesController(content::WebContents* web_contents, | 126 MediaStreamDevicesController(content::WebContents* web_contents, |
92 const content::MediaStreamRequest& request, | 127 const content::MediaStreamRequest& request, |
93 const content::MediaResponseCallback& callback); | 128 const content::MediaResponseCallback& callback); |
94 | 129 |
95 bool IsAllowedForAudio() const; | 130 bool IsAllowedForAudio() const; |
96 bool IsAllowedForVideo() const; | 131 bool IsAllowedForVideo() const; |
97 | 132 |
98 // Returns a list of devices available for the request for the given | 133 // Returns a list of devices available for the request for the given |
99 // audio/video permission settings. | 134 // audio/video permission settings. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // was created. | 186 // was created. |
152 TabSpecificContentSettings* content_settings_; | 187 TabSpecificContentSettings* content_settings_; |
153 | 188 |
154 // The original request for access to devices. | 189 // The original request for access to devices. |
155 const content::MediaStreamRequest request_; | 190 const content::MediaStreamRequest request_; |
156 | 191 |
157 // The callback that needs to be Run to notify WebRTC of whether access to | 192 // The callback that needs to be Run to notify WebRTC of whether access to |
158 // audio/video devices was granted or not. | 193 // audio/video devices was granted or not. |
159 content::MediaResponseCallback callback_; | 194 content::MediaResponseCallback callback_; |
160 | 195 |
161 std::unique_ptr<internal::PermissionPromptDelegate> delegate_; | 196 std::unique_ptr<PermissionPromptDelegate> delegate_; |
162 | 197 |
163 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); | 198 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); |
164 }; | 199 }; |
165 | 200 |
166 #endif // CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ | 201 #endif // CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ |
OLD | NEW |