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 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.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" | 18 #include "content/public/browser/permission_type.h" |
19 | 19 |
20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
21 class PermissionQueueController; | 21 class PermissionQueueController; |
22 #endif | 22 #endif |
23 class GURL; | 23 class GURL; |
24 class HostContentSettingsMap; | |
25 class PermissionRequestID; | 24 class PermissionRequestID; |
26 class Profile; | 25 class Profile; |
27 | 26 |
28 namespace content { | 27 namespace content { |
29 class WebContents; | 28 class WebContents; |
30 } | 29 } |
31 | 30 |
32 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; | 31 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; |
33 | 32 |
34 // This base class contains common operations for granting permissions. | 33 // This base class contains common operations for granting permissions. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const PermissionRequestID& id, | 78 const PermissionRequestID& id, |
80 const GURL& requesting_frame, | 79 const GURL& requesting_frame, |
81 bool user_gesture, | 80 bool user_gesture, |
82 const BrowserPermissionCallback& callback); | 81 const BrowserPermissionCallback& callback); |
83 | 82 |
84 // Returns whether the permission has been granted, denied... | 83 // Returns whether the permission has been granted, denied... |
85 virtual ContentSetting GetPermissionStatus( | 84 virtual ContentSetting GetPermissionStatus( |
86 const GURL& requesting_origin, | 85 const GURL& requesting_origin, |
87 const GURL& embedding_origin) const; | 86 const GURL& embedding_origin) const; |
88 | 87 |
89 // Thread safe version of GetPermissionStatus for consumers that already have | |
90 // an associated HostContentSettingsMap. | |
91 virtual ContentSetting GetPermissionStatus( | |
92 HostContentSettingsMap* host, | |
93 const GURL& requesting_origin, | |
94 const GURL& embedding_origin) const; | |
95 | |
96 // Resets the permission to its default value. | 88 // Resets the permission to its default value. |
97 virtual void ResetPermission(const GURL& requesting_origin, | 89 virtual void ResetPermission(const GURL& requesting_origin, |
98 const GURL& embedding_origin); | 90 const GURL& embedding_origin); |
99 | 91 |
100 // Withdraw an existing permission request, no op if the permission request | 92 // Withdraw an existing permission request, no op if the permission request |
101 // was already cancelled by some other means. | 93 // was already cancelled by some other means. |
102 virtual void CancelPermissionRequest(content::WebContents* web_contents, | 94 virtual void CancelPermissionRequest(content::WebContents* web_contents, |
103 const PermissionRequestID& id); | 95 const PermissionRequestID& id); |
104 | 96 |
105 // Whether the kill switch has been enabled for this permission. | 97 // Whether the kill switch has been enabled for this permission. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 Profile* profile() const; | 141 Profile* profile() const; |
150 | 142 |
151 // Store the decided permission as a content setting. | 143 // Store the decided permission as a content setting. |
152 // virtual since the permission might be stored with different restrictions | 144 // virtual since the permission might be stored with different restrictions |
153 // (for example for desktop notifications). | 145 // (for example for desktop notifications). |
154 virtual void UpdateContentSetting(const GURL& requesting_origin, | 146 virtual void UpdateContentSetting(const GURL& requesting_origin, |
155 const GURL& embedding_origin, | 147 const GURL& embedding_origin, |
156 ContentSetting content_setting); | 148 ContentSetting content_setting); |
157 | 149 |
158 // Whether the permission should be restricted to secure origins. | 150 // Whether the permission should be restricted to secure origins. |
159 // Note: Maybe be called from multiple threads. | |
160 virtual bool IsRestrictedToSecureOrigins() const = 0; | 151 virtual bool IsRestrictedToSecureOrigins() const = 0; |
161 | 152 |
162 content::PermissionType permission_type() const { return permission_type_; } | 153 content::PermissionType permission_type() const { return permission_type_; } |
163 ContentSettingsType content_settings_type() const { | 154 ContentSettingsType content_settings_type() const { |
164 return content_settings_type_; | 155 return content_settings_type_; |
165 } | 156 } |
166 | 157 |
167 private: | 158 private: |
168 friend class PermissionContextBaseTests; | 159 friend class PermissionContextBaseTests; |
169 | 160 |
170 // Called when a request is no longer used so it can be cleaned up. | 161 // Called when a request is no longer used so it can be cleaned up. |
171 void CleanUpRequest(const PermissionRequestID& id); | 162 void CleanUpRequest(const PermissionRequestID& id); |
172 | 163 |
173 Profile* profile_; | 164 Profile* profile_; |
174 const content::PermissionType permission_type_; | 165 const content::PermissionType permission_type_; |
175 const ContentSettingsType content_settings_type_; | 166 const ContentSettingsType content_settings_type_; |
176 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
177 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 168 std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
178 #endif | 169 #endif |
179 base::ScopedPtrHashMap<std::string, std::unique_ptr<PermissionRequest>> | 170 base::ScopedPtrHashMap<std::string, std::unique_ptr<PermissionRequest>> |
180 pending_requests_; | 171 pending_requests_; |
181 | 172 |
182 // Must be the last member, to ensure that it will be | 173 // Must be the last member, to ensure that it will be |
183 // destroyed first, which will invalidate weak pointers | 174 // destroyed first, which will invalidate weak pointers |
184 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 175 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
185 }; | 176 }; |
186 | 177 |
187 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 178 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
OLD | NEW |