mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Clark DuVall | 6b73c74 | 2020-03-11 19:00:15 | [diff] [blame] | 5 | #ifndef COMPONENTS_PERMISSIONS_PERMISSION_MANAGER_H_ |
| 6 | #define COMPONENTS_PERMISSIONS_PERMISSION_MANAGER_H_ |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 7 | |
raymes | e3afee6b | 2016-04-18 02:00:50 | [diff] [blame] | 8 | #include <unordered_map> |
| 9 | |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
James Hollyer | d281a731 | 2021-04-29 21:07:59 | [diff] [blame^] | 11 | #include "base/containers/flat_map.h" |
Brett Wilson | f976d3f | 2017-08-18 17:23:39 | [diff] [blame] | 12 | #include "base/containers/id_map.h" |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 13 | #include "base/macros.h" |
mlamouri | 23957a2 | 2015-04-01 10:37:56 | [diff] [blame] | 14 | #include "components/content_settings/core/browser/content_settings_observer.h" |
lalitm | 27583e9 | 2015-10-02 11:34:17 | [diff] [blame] | 15 | #include "components/content_settings/core/common/content_settings.h" |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 16 | #include "components/keyed_service/core/keyed_service.h" |
James Hollyer | d281a731 | 2021-04-29 21:07:59 | [diff] [blame^] | 17 | #include "components/permissions/permission_context_base.h" |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 18 | #include "components/permissions/permission_request_id.h" |
Clark DuVall | 732778e | 2020-01-27 18:13:58 | [diff] [blame] | 19 | #include "components/permissions/permission_util.h" |
Andrey Lushnikov | f350010 | 2018-07-16 19:55:22 | [diff] [blame] | 20 | #include "content/public/browser/permission_controller_delegate.h" |
Pavel Feldman | 73b2202 | 2018-11-02 02:55:30 | [diff] [blame] | 21 | #include "content/public/browser/permission_type.h" |
Rohan Pavone | faf6457 | 2019-07-30 17:50:20 | [diff] [blame] | 22 | #include "url/origin.h" |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 23 | |
Clark DuVall | 6b73c74 | 2020-03-11 19:00:15 | [diff] [blame] | 24 | namespace content { |
| 25 | class BrowserContext; |
| 26 | } |
| 27 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 28 | namespace permissions { |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 29 | class PermissionContextBase; |
timloh | c691180 | 2017-03-01 05:37:03 | [diff] [blame] | 30 | struct PermissionResult; |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 31 | |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 32 | class PermissionManager : public KeyedService, |
Andrey Lushnikov | f350010 | 2018-07-16 19:55:22 | [diff] [blame] | 33 | public content::PermissionControllerDelegate, |
James Hollyer | d281a731 | 2021-04-29 21:07:59 | [diff] [blame^] | 34 | public permissions::Observer { |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 35 | public: |
Clark DuVall | 6b73c74 | 2020-03-11 19:00:15 | [diff] [blame] | 36 | using PermissionContextMap = |
| 37 | std::unordered_map<ContentSettingsType, |
| 38 | std::unique_ptr<PermissionContextBase>, |
| 39 | ContentSettingsTypeHash>; |
| 40 | PermissionManager(content::BrowserContext* browser_context, |
| 41 | PermissionContextMap permission_contexts); |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 42 | ~PermissionManager() override; |
| 43 | |
Marc Treib | 9e4bd92 | 2017-09-25 08:32:13 | [diff] [blame] | 44 | // Converts from |url|'s actual origin to the "canonical origin" that should |
| 45 | // be used for the purpose of requesting/storing permissions. For example, the |
Raymes Khoury | b474c64 | 2018-02-28 06:16:28 | [diff] [blame] | 46 | // origin of the local NTP gets mapped to the Google base URL instead. With |
| 47 | // Permission Delegation it will transform the requesting origin into |
| 48 | // the embedding origin because all permission checks happen on the top level |
| 49 | // origin. |
| 50 | // |
| 51 | // All the public methods below, such as RequestPermission or |
| 52 | // GetPermissionStatus, take the actual origin and do the canonicalization |
| 53 | // internally. You only need to call this directly if you do something else |
| 54 | // with the origin, such as display it in the UI. |
Balazs Engedy | f39e22b | 2019-07-30 11:16:24 | [diff] [blame] | 55 | GURL GetCanonicalOrigin(ContentSettingsType permission, |
| 56 | const GURL& requesting_origin, |
Raymes Khoury | b474c64 | 2018-02-28 06:16:28 | [diff] [blame] | 57 | const GURL& embedding_origin) const; |
Marc Treib | 9e4bd92 | 2017-09-25 08:32:13 | [diff] [blame] | 58 | |
timloh | 9a180ad | 2017-02-20 07:15:23 | [diff] [blame] | 59 | // Callers from within chrome/ should use the methods which take the |
| 60 | // ContentSettingsType enum. The methods which take PermissionType values |
Andrey Lushnikov | f350010 | 2018-07-16 19:55:22 | [
|