| 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 "chrome/browser/permissions/permission_result.h" | 15 #include "chrome/browser/permissions/permission_result.h" |
| 16 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "third_party/WebKit/public/platform/WebFeaturePolicyFeature.h" |
| 19 | 20 |
| 20 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| 21 class PermissionQueueController; | 22 class PermissionQueueController; |
| 22 #endif | 23 #endif |
| 23 class GURL; | 24 class GURL; |
| 24 class PermissionRequestID; | 25 class PermissionRequestID; |
| 25 class Profile; | 26 class Profile; |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 class RenderFrameHost; | 29 class RenderFrameHost; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 51 // After this you can override several other methods to customize behavior, | 52 // After this you can override several other methods to customize behavior, |
| 52 // in particular it is advised to override UpdateTabContext in order to manage | 53 // in particular it is advised to override UpdateTabContext in order to manage |
| 53 // the permission from the omnibox. | 54 // the permission from the omnibox. |
| 54 // It is mandatory to override IsRestrictedToSecureOrigin. | 55 // It is mandatory to override IsRestrictedToSecureOrigin. |
| 55 // See midi_permission_context.h/cc or push_permission_context.cc/h for some | 56 // See midi_permission_context.h/cc or push_permission_context.cc/h for some |
| 56 // examples. | 57 // examples. |
| 57 | 58 |
| 58 class PermissionContextBase : public KeyedService { | 59 class PermissionContextBase : public KeyedService { |
| 59 public: | 60 public: |
| 60 PermissionContextBase(Profile* profile, | 61 PermissionContextBase(Profile* profile, |
| 61 const ContentSettingsType content_settings_type); | 62 ContentSettingsType content_settings_type, |
| 63 blink::WebFeaturePolicyFeature feature_policy_feature); |
| 62 ~PermissionContextBase() override; | 64 ~PermissionContextBase() override; |
| 63 | 65 |
| 64 // A field trial used to enable the global permissions kill switch. | 66 // A field trial used to enable the global permissions kill switch. |
| 65 // This is public so permissions that don't yet inherit from | 67 // This is public so permissions that don't yet inherit from |
| 66 // PermissionContextBase can use it. | 68 // PermissionContextBase can use it. |
| 67 static const char kPermissionsKillSwitchFieldStudy[]; | 69 static const char kPermissionsKillSwitchFieldStudy[]; |
| 68 | 70 |
| 69 // The field trial param to enable the global permissions kill switch. | 71 // The field trial param to enable the global permissions kill switch. |
| 70 // This is public so permissions that don't yet inherit from | 72 // This is public so permissions that don't yet inherit from |
| 71 // PermissionContextBase can use it. | 73 // PermissionContextBase can use it. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 175 } |
| 174 | 176 |
| 175 // TODO(timloh): The CONTENT_SETTINGS_TYPE_NOTIFICATIONS type is used to | 177 // TODO(timloh): The CONTENT_SETTINGS_TYPE_NOTIFICATIONS type is used to |
| 176 // store both push messaging and notifications permissions. Remove this | 178 // store both push messaging and notifications permissions. Remove this |
| 177 // once we've unified these types (crbug.com/563297). | 179 // once we've unified these types (crbug.com/563297). |
| 178 ContentSettingsType content_settings_storage_type() const; | 180 ContentSettingsType content_settings_storage_type() const; |
| 179 | 181 |
| 180 private: | 182 private: |
| 181 friend class PermissionContextBaseTests; | 183 friend class PermissionContextBaseTests; |
| 182 | 184 |
| 185 bool PermissionAllowedByFeaturePolicy(content::RenderFrameHost* rfh) const; |
| 186 |
| 183 // Called when a request is no longer used so it can be cleaned up. | 187 // Called when a request is no longer used so it can be cleaned up. |
| 184 void CleanUpRequest(const PermissionRequestID& id); | 188 void CleanUpRequest(const PermissionRequestID& id); |
| 185 | 189 |
| 186 // Called when the requesting origin and permission have been checked by Safe | 190 // Called when the requesting origin and permission have been checked by Safe |
| 187 // Browsing. |permission_blocked| determines whether to auto-block the | 191 // Browsing. |permission_blocked| determines whether to auto-block the |
| 188 // permission request without prompting the user for a decision. | 192 // permission request without prompting the user for a decision. |
| 189 void ContinueRequestPermission(content::WebContents* web_contents, | 193 void ContinueRequestPermission(content::WebContents* web_contents, |
| 190 const PermissionRequestID& id, | 194 const PermissionRequestID& id, |
| 191 const GURL& requesting_origin, | 195 const GURL& requesting_origin, |
| 192 const GURL& embedding_origin, | 196 const GURL& embedding_origin, |
| 193 bool user_gesture, | 197 bool user_gesture, |
| 194 const BrowserPermissionCallback& callback, | 198 const BrowserPermissionCallback& callback, |
| 195 bool permission_blocked); | 199 bool permission_blocked); |
| 196 | 200 |
| 197 // Called when the user has made a permission decision. This is a hook for | 201 // Called when the user has made a permission decision. This is a hook for |
| 198 // descendent classes to do appropriate things they might need to do when this | 202 // descendent classes to do appropriate things they might need to do when this |
| 199 // happens. | 203 // happens. |
| 200 virtual void UserMadePermissionDecision(const PermissionRequestID& id, | 204 virtual void UserMadePermissionDecision(const PermissionRequestID& id, |
| 201 const GURL& requesting_origin, | 205 const GURL& requesting_origin, |
| 202 const GURL& embedding_origin, | 206 const GURL& embedding_origin, |
| 203 ContentSetting content_setting); | 207 ContentSetting content_setting); |
| 204 | 208 |
| 205 Profile* profile_; | 209 Profile* profile_; |
| 206 const ContentSettingsType content_settings_type_; | 210 const ContentSettingsType content_settings_type_; |
| 211 const blink::WebFeaturePolicyFeature feature_policy_feature_; |
| 207 #if defined(OS_ANDROID) | 212 #if defined(OS_ANDROID) |
| 208 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 213 std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
| 209 #endif | 214 #endif |
| 210 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> | 215 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> |
| 211 pending_requests_; | 216 pending_requests_; |
| 212 | 217 |
| 213 // Must be the last member, to ensure that it will be | 218 // Must be the last member, to ensure that it will be |
| 214 // destroyed first, which will invalidate weak pointers | 219 // destroyed first, which will invalidate weak pointers |
| 215 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 220 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
| 216 }; | 221 }; |
| 217 | 222 |
| 218 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 223 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
| OLD | NEW |