blob: 9b82d782a3143c0e23c0802c4ca015651def2a3c [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2014 The Chromium Authors
[email protected]efad90f2014-01-17 00:45:542// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Clark DuVall484c2562020-01-23 22:05:095#ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_
6#define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_
[email protected]efad90f2014-01-17 00:45:547
Florian Jacky7f3e3ca1b2025-05-05 16:19:208#include <memory>
Arthur Sonzognic571efb2024-01-26 20:26:189#include <optional>
Jan Wilken Dörriead587c32021-03-11 14:09:2710#include <string>
11
Avi Drissman12be0312023-01-11 09:16:0912#include "base/functional/callback.h"
Thomas Nguyen9f1ff7302023-03-30 12:23:3513#include "base/memory/weak_ptr.h"
Clark DuVall484c2562020-01-23 22:05:0914#include "build/build_config.h"
Bret Sepulveda5327d8b52021-07-21 17:44:2315#include "components/content_settings/core/common/content_settings.h"
lshangada00c12016-10-17 04:51:1016#include "components/content_settings/core/common/content_settings_types.h"
Piotr Bialeckib62b90cc2025-04-18 12:39:5817#include "components/permissions/permission_hats_trigger_helper.h"
Andy Paicu0a6d4b502023-08-29 15:13:0918#include "components/permissions/permission_request_data.h"
Andy Paicu4a88f422020-11-12 18:21:3919#include "components/permissions/permission_request_enums.h"
Illia Klimovfabd8b52021-10-21 07:15:4020#include "components/permissions/request_type.h"
Illia Klimove406ecc12022-11-22 15:53:2921#include "content/public/browser/global_routing_id.h"
[email protected]d23cdeee2014-03-10 06:39:5322#include "url/gurl.h"
[email protected]efad90f2014-01-17 00:45:5423
Clark DuVall484c2562020-01-23 22:05:0924namespace permissions {
Bret Sepulveda362cce42021-01-13 18:47:5425enum class RequestType;
tsergeant58defcfb2016-07-19 23:47:2826// Describes the interface a feature making permission requests should
27// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5428// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2829// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4830// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5431// 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.
tsergeant58defcfb2016-07-19 23:47:2834class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5435 public:
Bret Sepulveda5327d8b52021-07-21 17:44:2336 // 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 Jacky7f3e3ca1b2025-05-05 16:19:2043 using PermissionDecidedCallback = base::RepeatingCallback<void(
44 ContentSetting /*result*/,
45 bool /*is_one_time*/,
46 bool /*is_final_decision*/,
Chris Fredrickson173060c862025-05-14 14:23:0147 const PermissionRequestData& /*request_data*/)>;
[email protected]efad90f2014-01-17 00:45:5448
Bret Sepulveda5327d8b52021-07-21 17:44:2349 // `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 Jacky7f3e3ca1b2025-05-05 16:19:2058 PermissionRequest(std::unique_ptr<PermissionRequestData> request_data,
Andy Paicu0a6d4b502023-08-29 15:13:0959 PermissionDecidedCallback permission_decided_callback,
Elad Alonb3331802024-01-24 22:29:3660 base::OnceClosure delete_callback,
Florian Jacky7f3e3ca1b2025-05-05 16:19:2061 bool uses_automatic_embargo = true);
Andy Paicu0a6d4b502023-08-29 15:13:0962
Bret Sepulveda5327d8b52021-07-21 17:44:2363 PermissionRequest(const PermissionRequest&) = delete;
64 PermissionRequest& operator=(const PermissionRequest&) = delete;
65
Florian Jackyeeb62062022-10-05 18:04:0766 enum ChipTextType {
67 LOUD_REQUEST,
68 QUIET_REQUEST,
69 ALLOW_CONFIRMATION,
Florian Jacky2b3f54f2023-05-03 08:31:5270 ALLOW_ONCE_CONFIRMATION,
Florian Jackyeeb62062022-10-05 18:04:0771 BLOCKED_CONFIRMATION,
72 ACCESSIBILITY_ALLOWED_CONFIRMATION,
Florian Jacky2b3f54f2023-05-03 08:31:5273 ACCESSIBILITY_ALLOWED_ONCE_CONFIRMATION,
Florian Jackyeeb62062022-10-05 18:04:0774 ACCESSIBILITY_BLOCKED_CONFIRMATION
75 };
76
Bret Sepulveda5327d8b52021-07-21 17:44:2377 virtual ~PermissionRequest();