OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/permissions/permission_request.h" | 14 #include "chrome/browser/permissions/permission_request.h" |
15 #include "components/content_settings/core/common/content_settings.h" | 15 #include "components/content_settings/core/common/content_settings.h" |
16 #include "components/content_settings/core/common/content_settings_types.h" | 16 #include "components/content_settings/core/common/content_settings_types.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
18 #include "content/public/browser/permission_type.h" | |
19 | 18 |
20 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
21 class PermissionQueueController; | 20 class PermissionQueueController; |
22 #endif | 21 #endif |
23 class GURL; | 22 class GURL; |
24 class PermissionRequestID; | 23 class PermissionRequestID; |
25 class Profile; | 24 class Profile; |
26 | 25 |
27 namespace content { | 26 namespace content { |
28 class WebContents; | 27 class WebContents; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // After this you can override several other methods to customize behavior, | 75 // After this you can override several other methods to customize behavior, |
77 // in particular it is advised to override UpdateTabContext in order to manage | 76 // in particular it is advised to override UpdateTabContext in order to manage |
78 // the permission from the omnibox. | 77 // the permission from the omnibox. |
79 // It is mandatory to override IsRestrictedToSecureOrigin. | 78 // It is mandatory to override IsRestrictedToSecureOrigin. |
80 // See midi_permission_context.h/cc or push_permission_context.cc/h for some | 79 // See midi_permission_context.h/cc or push_permission_context.cc/h for some |
81 // examples. | 80 // examples. |
82 | 81 |
83 class PermissionContextBase : public KeyedService { | 82 class PermissionContextBase : public KeyedService { |
84 public: | 83 public: |
85 PermissionContextBase(Profile* profile, | 84 PermissionContextBase(Profile* profile, |
86 const content::PermissionType permission_type, | |
87 const ContentSettingsType content_settings_type); | 85 const ContentSettingsType content_settings_type); |
88 ~PermissionContextBase() override; | 86 ~PermissionContextBase() override; |
89 | 87 |
90 // A field trial used to enable the global permissions kill switch. | 88 // A field trial used to enable the global permissions kill switch. |
91 // This is public so permissions that don't yet inherit from | 89 // This is public so permissions that don't yet inherit from |
92 // PermissionContextBase can use it. | 90 // PermissionContextBase can use it. |
93 static const char kPermissionsKillSwitchFieldStudy[]; | 91 static const char kPermissionsKillSwitchFieldStudy[]; |
94 | 92 |
95 // The field trial param to enable the global permissions kill switch. | 93 // The field trial param to enable the global permissions kill switch. |
96 // This is public so permissions that don't yet inherit from | 94 // This is public so permissions that don't yet inherit from |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Store the decided permission as a content setting. | 172 // Store the decided permission as a content setting. |
175 // virtual since the permission might be stored with different restrictions | 173 // virtual since the permission might be stored with different restrictions |
176 // (for example for desktop notifications). | 174 // (for example for desktop notifications). |
177 virtual void UpdateContentSetting(const GURL& requesting_origin, | 175 virtual void UpdateContentSetting(const GURL& requesting_origin, |
178 const GURL& embedding_origin, | 176 const GURL& embedding_origin, |
179 ContentSetting content_setting); | 177 ContentSetting content_setting); |
180 | 178 |
181 // Whether the permission should be restricted to secure origins. | 179 // Whether the permission should be restricted to secure origins. |
182 virtual bool IsRestrictedToSecureOrigins() const = 0; | 180 virtual bool IsRestrictedToSecureOrigins() const = 0; |
183 | 181 |
184 content::PermissionType permission_type() const { return permission_type_; } | |
185 ContentSettingsType content_settings_type() const { | 182 ContentSettingsType content_settings_type() const { |
186 return content_settings_type_; | 183 return content_settings_type_; |
187 } | 184 } |
188 | 185 |
| 186 // TODO(timloh): The CONTENT_SETTINGS_TYPE_NOTIFICATIONS type is used to |
| 187 // store both push messaging and notifications permissions. Remove this |
| 188 // once we've unified these types (crbug.com/563297). |
| 189 ContentSettingsType content_settings_storage_type() const; |
| 190 |
189 private: | 191 private: |
190 friend class PermissionContextBaseTests; | 192 friend class PermissionContextBaseTests; |
191 | 193 |
192 // Called when a request is no longer used so it can be cleaned up. | 194 // Called when a request is no longer used so it can be cleaned up. |
193 void CleanUpRequest(const PermissionRequestID& id); | 195 void CleanUpRequest(const PermissionRequestID& id); |
194 | 196 |
195 // Called when the requesting origin and permission have been checked by Safe | 197 // Called when the requesting origin and permission have been checked by Safe |
196 // Browsing. |permission_blocked| determines whether to auto-block the | 198 // Browsing. |permission_blocked| determines whether to auto-block the |
197 // permission request without prompting the user for a decision. | 199 // permission request without prompting the user for a decision. |
198 void ContinueRequestPermission(content::WebContents* web_contents, | 200 void ContinueRequestPermission(content::WebContents* web_contents, |
199 const PermissionRequestID& id, | 201 const PermissionRequestID& id, |
200 const GURL& requesting_origin, | 202 const GURL& requesting_origin, |
201 const GURL& embedding_origin, | 203 const GURL& embedding_origin, |
202 bool user_gesture, | 204 bool user_gesture, |
203 const BrowserPermissionCallback& callback, | 205 const BrowserPermissionCallback& callback, |
204 bool permission_blocked); | 206 bool permission_blocked); |
205 | 207 |
206 Profile* profile_; | 208 Profile* profile_; |
207 const content::PermissionType permission_type_; | |
208 const ContentSettingsType content_settings_type_; | 209 const ContentSettingsType content_settings_type_; |
209 #if defined(OS_ANDROID) | 210 #if defined(OS_ANDROID) |
210 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 211 std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
211 #endif | 212 #endif |
212 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> | 213 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> |
213 pending_requests_; | 214 pending_requests_; |
214 | 215 |
215 // Must be the last member, to ensure that it will be | 216 // Must be the last member, to ensure that it will be |
216 // destroyed first, which will invalidate weak pointers | 217 // destroyed first, which will invalidate weak pointers |
217 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 218 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
218 }; | 219 }; |
219 | 220 |
220 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 221 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
OLD | NEW |