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 */)>; |
Nico
2017/04/24 13:51:53
nit: spell this like `/*persist=*/bool` -- clang-f
raymes
2017/04/26 00:28:14
Thanks I didn't know that. That was the convention
| |
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 // Whether the prompt has been answered. | |
79 bool responded_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(Request); | |
82 }; | |
83 | |
84 // This class is only needed interally and for tests. It can be removed once | |
85 // crbug.com/606138 is fixed. Delegate for showing permission prompts. It's | |
86 // only public because subclassing from a friend class doesn't work in gcc | |
87 // (see https://codereview.chromium.org/2768923003). | |
88 class PermissionPromptDelegate { | |
Nico
2017/04/24 13:51:53
std::unique_ptr<PermissionPromptDelegate> delegate
raymes
2017/04/26 00:28:14
Thanks for catching this. Fixed in: https://codere
| |
89 public: | |
90 virtual void ShowPrompt( | |
91 bool user_gesture, | |
92 content::WebContents* web_contents, | |
93 std::unique_ptr<MediaStreamDevicesController::Request> request) = 0; | |
94 }; | |
95 | |
49 static void RequestPermissions( | 96 static void RequestPermissions( |
50 const content::MediaStreamRequest& request, | 97 const content::MediaStreamRequest& request, |
51 const content::MediaResponseCallback& callback); | 98 const content::MediaResponseCallback& callback); |
52 | 99 |
53 // Registers the prefs backing the audio and video policies. | 100 // Registers the prefs backing the audio and video policies. |
54 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 101 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
55 | 102 |
56 ~MediaStreamDevicesController() override; | 103 ~MediaStreamDevicesController(); |
57 | 104 |
58 bool IsAskingForAudio() const; | 105 bool IsAskingForAudio() const; |
59 bool IsAskingForVideo() const; | 106 bool IsAskingForVideo() const; |
60 base::string16 GetMessageText() const; | 107 |
108 // Called when a permission prompt has been answered, with the |response| and | |
109 // whether the choice should be persisted. | |
110 void PromptAnswered(ContentSetting response, bool persist); | |
61 | 111 |
62 #if defined(OS_ANDROID) | 112 #if defined(OS_ANDROID) |
63 // Called when the Android OS-level prompt is answered. | 113 // Called when the Android OS-level prompt is answered. |
64 void AndroidOSPromptAnswered(bool allowed); | 114 void AndroidOSPromptAnswered(bool allowed); |
65 #endif // defined(OS_ANDROID) | 115 #endif // defined(OS_ANDROID) |
66 | 116 |
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: | 117 private: |
80 friend class MediaStreamDevicesControllerTest; | 118 friend class MediaStreamDevicesControllerTest; |
81 friend class test::MediaStreamDevicesControllerTestApi; | 119 friend class test::MediaStreamDevicesControllerTestApi; |
82 friend class policy::MediaStreamDevicesControllerBrowserTest; | 120 friend class policy::MediaStreamDevicesControllerBrowserTest; |
83 | 121 |
84 class PermissionPromptDelegateImpl; | 122 class PermissionPromptDelegateImpl; |
85 | 123 |
86 static void RequestPermissionsWithDelegate( | 124 static void RequestPermissionsWithDelegate( |
87 const content::MediaStreamRequest& request, | 125 const content::MediaStreamRequest& request, |
88 const content::MediaResponseCallback& callback, | 126 const content::MediaResponseCallback& callback, |
89 internal::PermissionPromptDelegate* delegate); | 127 PermissionPromptDelegate* delegate); |
90 | 128 |
91 MediaStreamDevicesController(content::WebContents* web_contents, | 129 MediaStreamDevicesController(content::WebContents* web_contents, |
92 const content::MediaStreamRequest& request, | 130 const content::MediaStreamRequest& request, |
93 const content::MediaResponseCallback& callback); | 131 const content::MediaResponseCallback& callback); |
94 | 132 |
95 bool IsAllowedForAudio() const; | 133 bool IsAllowedForAudio() const; |
96 bool IsAllowedForVideo() const; | 134 bool IsAllowedForVideo() const; |
97 | 135 |
98 // Returns a list of devices available for the request for the given | 136 // Returns a list of devices available for the request for the given |
99 // audio/video permission settings. | 137 // audio/video permission settings. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 // was created. | 189 // was created. |
152 TabSpecificContentSettings* content_settings_; | 190 TabSpecificContentSettings* content_settings_; |
153 | 191 |
154 // The original request for access to devices. | 192 // The original request for access to devices. |
155 const content::MediaStreamRequest request_; | 193 const content::MediaStreamRequest request_; |
156 | 194 |
157 // The callback that needs to be Run to notify WebRTC of whether access to | 195 // The callback that needs to be Run to notify WebRTC of whether access to |
158 // audio/video devices was granted or not. | 196 // audio/video devices was granted or not. |
159 content::MediaResponseCallback callback_; | 197 content::MediaResponseCallback callback_; |
160 | 198 |
161 std::unique_ptr<internal::PermissionPromptDelegate> delegate_; | 199 std::unique_ptr<PermissionPromptDelegate> delegate_; |
162 | 200 |
163 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); | 201 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); |
164 }; | 202 }; |
165 | 203 |
166 #endif // CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ | 204 #endif // CHROME_BROWSER_MEDIA_WEBRTC_MEDIA_STREAM_DEVICES_CONTROLLER_H_ |
OLD | NEW |