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 21 matching lines...) Expand all Loading... |
50 // After this you can override several other methods to customize behavior, | 49 // After this you can override several other methods to customize behavior, |
51 // in particular it is advised to override UpdateTabContext in order to manage | 50 // in particular it is advised to override UpdateTabContext in order to manage |
52 // the permission from the omnibox. | 51 // the permission from the omnibox. |
53 // It is mandatory to override IsRestrictedToSecureOrigin. | 52 // It is mandatory to override IsRestrictedToSecureOrigin. |
54 // See midi_permission_context.h/cc or push_permission_context.cc/h for some | 53 // See midi_permission_context.h/cc or push_permission_context.cc/h for some |
55 // examples. | 54 // examples. |
56 | 55 |
57 class PermissionContextBase : public KeyedService { | 56 class PermissionContextBase : public KeyedService { |
58 public: | 57 public: |
59 PermissionContextBase(Profile* profile, | 58 PermissionContextBase(Profile* profile, |
60 const content::PermissionType permission_type, | |
61 const ContentSettingsType content_settings_type); | 59 const ContentSettingsType content_settings_type); |
62 ~PermissionContextBase() override; | 60 ~PermissionContextBase() override; |
63 | 61 |
64 // A field trial used to enable the global permissions kill switch. | 62 // A field trial used to enable the global permissions kill switch. |
65 // This is public so permissions that don't yet inherit from | 63 // This is public so permissions that don't yet inherit from |
66 // PermissionContextBase can use it. | 64 // PermissionContextBase can use it. |
67 static const char kPermissionsKillSwitchFieldStudy[]; | 65 static const char kPermissionsKillSwitchFieldStudy[]; |
68 | 66 |
69 // The field trial param to enable the global permissions kill switch. | 67 // The field trial param to enable the global permissions kill switch. |
70 // This is public so permissions that don't yet inherit from | 68 // This is public so permissions that don't yet inherit from |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Store the decided permission as a content setting. | 146 // Store the decided permission as a content setting. |
149 // virtual since the permission might be stored with different restrictions | 147 // virtual since the permission might be stored with different restrictions |
150 // (for example for desktop notifications). | 148 // (for example for desktop notifications). |
151 virtual void UpdateContentSetting(const GURL& requesting_origin, | 149 virtual void UpdateContentSetting(const GURL& requesting_origin, |
152 const GURL& embedding_origin, | 150 const GURL& embedding_origin, |
153 ContentSetting content_setting); | 151 ContentSetting content_setting); |
154 | 152 |
155 // Whether the permission should be restricted to secure origins. | 153 // Whether the permission should be restricted to secure origins. |
156 virtual bool IsRestrictedToSecureOrigins() const = 0; | 154 virtual bool IsRestrictedToSecureOrigins() const = 0; |
157 | 155 |
158 content::PermissionType permission_type() const { return permission_type_; } | |
159 ContentSettingsType content_settings_type() const { | 156 ContentSettingsType content_settings_type() const { |
160 return content_settings_type_; | 157 return content_settings_type_; |
161 } | 158 } |
162 | 159 |
163 private: | 160 private: |
164 friend class PermissionContextBaseTests; | 161 friend class PermissionContextBaseTests; |
165 | 162 |
166 // Called when a request is no longer used so it can be cleaned up. | 163 // Called when a request is no longer used so it can be cleaned up. |
167 void CleanUpRequest(const PermissionRequestID& id); | 164 void CleanUpRequest(const PermissionRequestID& id); |
168 | 165 |
169 // Called when the requesting origin and permission have been checked by Safe | 166 // Called when the requesting origin and permission have been checked by Safe |
170 // Browsing. |permission_blocked| determines whether to auto-block the | 167 // Browsing. |permission_blocked| determines whether to auto-block the |
171 // permission request without prompting the user for a decision. | 168 // permission request without prompting the user for a decision. |
172 void ContinueRequestPermission(content::WebContents* web_contents, | 169 void ContinueRequestPermission(content::WebContents* web_contents, |
173 const PermissionRequestID& id, | 170 const PermissionRequestID& id, |
174 const GURL& requesting_origin, | 171 const GURL& requesting_origin, |
175 const GURL& embedding_origin, | 172 const GURL& embedding_origin, |
176 bool user_gesture, | 173 bool user_gesture, |
177 const BrowserPermissionCallback& callback, | 174 const BrowserPermissionCallback& callback, |
178 bool permission_blocked); | 175 bool permission_blocked); |
179 | 176 |
180 Profile* profile_; | 177 Profile* profile_; |
181 const content::PermissionType permission_type_; | |
182 const ContentSettingsType content_settings_type_; | 178 const ContentSettingsType content_settings_type_; |
183 #if defined(OS_ANDROID) | 179 #if defined(OS_ANDROID) |
184 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 180 std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
185 #endif | 181 #endif |
186 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> | 182 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> |
187 pending_requests_; | 183 pending_requests_; |
188 | 184 |
189 // Must be the last member, to ensure that it will be | 185 // Must be the last member, to ensure that it will be |
190 // destroyed first, which will invalidate weak pointers | 186 // destroyed first, which will invalidate weak pointers |
191 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 187 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
192 }; | 188 }; |
193 | 189 |
194 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 190 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
OLD | NEW |