Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 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 | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 5 | #ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_ |
| 6 | #define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_ |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 7 | |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 8 | #include <memory> |
Arthur Sonzogni | c571efb | 2024-01-26 20:26:18 | [diff] [blame] | 9 | #include <optional> |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Avi Drissman | 12be031 | 2023-01-11 09:16:09 | [diff] [blame] | 12 | #include "base/functional/callback.h" |
Thomas Nguyen | 9f1ff730 | 2023-03-30 12:23:35 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 14 | #include "build/build_config.h" |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 15 | #include "components/content_settings/core/common/content_settings.h" |
lshang | ada00c1 | 2016-10-17 04:51:10 | [diff] [blame] | 16 | #include "components/content_settings/core/common/content_settings_types.h" |
Piotr Bialecki | b62b90cc | 2025-04-18 12:39:58 | [diff] [blame] | 17 | #include "components/permissions/permission_hats_trigger_helper.h" |
Andy Paicu | 0a6d4b50 | 2023-08-29 15:13:09 | [diff] [blame] | 18 | #include "components/permissions/permission_request_data.h" |
Andy Paicu | 4a88f42 | 2020-11-12 18:21:39 | [diff] [blame] | 19 | #include "components/permissions/permission_request_enums.h" |
Illia Klimov | fabd8b5 | 2021-10-21 07:15:40 | [diff] [blame] | 20 | #include "components/permissions/request_type.h" |
Illia Klimov | e406ecc1 | 2022-11-22 15:53:29 | [diff] [blame] | 21 | #include "content/public/browser/global_routing_id.h" |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 22 | #include "url/gurl.h" |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 23 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 24 | namespace permissions { |
Bret Sepulveda | 362cce4 | 2021-01-13 18:47:54 | [diff] [blame] | 25 | enum class RequestType; |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 26 | // Describes the interface a feature making permission requests should |
| 27 | // implement. A class of this type is registered with the permission request |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 28 | // manager to receive updates about the result of the permissions request |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 29 | // from the bubble or infobar. It should live until it is unregistered or until |
[email protected] | 634e598 | 2014-04-18 19:20:48 | [diff] [blame] | 30 | // RequestFinished is called. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 31 | // Note that no particular guarantees are made about what exact UI surface |
| 32 | // is presented to the user. The delegate may be coalesced with other bubble |
| 33 | // requests, or depending on the situation, not shown at all. |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 34 | class PermissionRequest { |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 35 | public: |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 36 | // If `result` is CONTENT_SETTING_ALLOW, the permission was granted by the |
| 37 | // user. If it's CONTENT_SETTING_BLOCK, the permission was blocked by the |
| 38 | // user. If it's CONTENT_SETTING_DEFAULT, the permission was ignored or |
| 39 | // dismissed without an explicit decision. No other ContentSetting value will |
| 40 | // be passed into this callback. |
| 41 | // If `is_one_time` is true, the decision will last until all tabs of |
| 42 | // `requesting_origin_` are closed or navigated away from. |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 43 | using PermissionDecidedCallback = base::RepeatingCallback<void( |
| 44 | ContentSetting /*result*/, |
| 45 | bool /*is_one_time*/, |
| 46 | bool /*is_final_decision*/, |
Chris Fredrickson | 173060c86 | 2025-05-14 14:23:01 | [diff] [blame] | 47 | const PermissionRequestData& /*request_data*/)>; |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 48 | |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 49 | // `permission_decided_callback` is called when the permission request is |
| 50 | // resolved by the user (see comment on PermissionDecidedCallback above). |
| 51 | // `delete_callback` is called when the permission request is no longer needed |
| 52 | // by the permission system. Therefore, it is safe to delete `this` inside |
| 53 | // `delete_callback`. It will always be called eventually by the permission |
| 54 | // system. |
| 55 | // `delete_callback` may be called before `permission_decided_callback`, for |
| 56 | // example if the tab is closed without user interaction. In this case, the |
| 57 | // javascript promise from the requesting origin will not be resolved. |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 58 | PermissionRequest(std::unique_ptr<PermissionRequestData> request_data, |
Andy Paicu | 0a6d4b50 | 2023-08-29 15:13:09 | [diff] [blame] | 59 | PermissionDecidedCallback permission_decided_callback, |
Elad Alon | b333180 | 2024-01-24 22:29:36 | [diff] [blame] | 60 | base::OnceClosure delete_callback, |
Florian Jacky | 7f3e3ca1b | 2025-05-05 16:19:20 | [diff] [blame] | 61 | bool uses_automatic_embargo = true); |
Andy Paicu | 0a6d4b50 | 2023-08-29 15:13:09 | [diff] [blame] | 62 | |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 63 | PermissionRequest(const PermissionRequest&) = delete; |
| 64 | PermissionRequest& operator=(const PermissionRequest&) = delete; |
| 65 | |
Florian Jacky | eeb6206 | 2022-10-05 18:04:07 | [diff] [blame] | 66 | enum ChipTextType { |
| 67 | LOUD_REQUEST, |
| 68 | QUIET_REQUEST, |
| 69 | ALLOW_CONFIRMATION, |
Florian Jacky | 2b3f54f | 2023-05-03 08:31:52 | [diff] [blame] | 70 | ALLOW_ONCE_CONFIRMATION, |
Florian Jacky | eeb6206 | 2022-10-05 18:04:07 | [diff] [blame] | 71 | BLOCKED_CONFIRMATION, |
| 72 | ACCESSIBILITY_ALLOWED_CONFIRMATION, |
Florian Jacky | 2b3f54f | 2023-05-03 08:31:52 | [diff] [blame] | 73 | ACCESSIBILITY_ALLOWED_ONCE_CONFIRMATION, |
Florian Jacky | eeb6206 | 2022-10-05 18:04:07 | [diff] [blame] | 74 | ACCESSIBILITY_BLOCKED_CONFIRMATION |
| 75 | }; |
| 76 | |
Bret Sepulveda | 5327d8b5 | 2021-07-21 17:44:23 | [diff] [blame] | 77 | virtual ~PermissionRequest(); |
|
|