blob: ccc2201d21db467fd17b12992fa49eb5bab7fd7f [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
Jan Wilken Dörriead587c32021-03-11 14:09:278#include <string>
9
Avi Drissman12be0312023-01-11 09:16:0910#include "base/functional/callback.h"
Thomas Nguyen9f1ff7302023-03-30 12:23:3511#include "base/memory/weak_ptr.h"
Clark DuVall484c2562020-01-23 22:05:0912#include "build/build_config.h"
Bret Sepulveda5327d8b52021-07-21 17:44:2313#include "components/content_settings/core/common/content_settings.h"
lshangada00c12016-10-17 04:51:1014#include "components/content_settings/core/common/content_settings_types.h"
Andy Paicu0a6d4b502023-08-29 15:13:0915#include "components/permissions/permission_request_data.h"
Andy Paicu4a88f422020-11-12 18:21:3916#include "components/permissions/permission_request_enums.h"
Illia Klimovfabd8b52021-10-21 07:15:4017#include "components/permissions/request_type.h"
Illia Klimove406ecc12022-11-22 15:53:2918#include "content/public/browser/global_routing_id.h"
Anton Bikineev1156b5f2021-05-15 22:35:3619#include "third_party/abseil-cpp/absl/types/optional.h"
[email protected]d23cdeee2014-03-10 06:39:5320#include "url/gurl.h"
[email protected]efad90f2014-01-17 00:45:5421
Clark DuVall484c2562020-01-23 22:05:0922namespace permissions {
Bret Sepulveda362cce42021-01-13 18:47:5423enum class RequestType;
Clark DuVall484c2562020-01-23 22:05:0924
tsergeant58defcfb2016-07-19 23:47:2825// Describes the interface a feature making permission requests should
26// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5427// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2828// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4829// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5430// Note that no particular guarantees are made about what exact UI surface
31// is presented to the user. The delegate may be coalesced with other bubble
32// requests, or depending on the situation, not shown at all.
tsergeant58defcfb2016-07-19 23:47:2833class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5434 public:
Bret Sepulveda5327d8b52021-07-21 17:44:2335 // If `result` is CONTENT_SETTING_ALLOW, the permission was granted by the
36 // user. If it's CONTENT_SETTING_BLOCK, the permission was blocked by the
37 // user. If it's CONTENT_SETTING_DEFAULT, the permission was ignored or
38 // dismissed without an explicit decision. No other ContentSetting value will
39 // be passed into this callback.
40 // If `is_one_time` is true, the decision will last until all tabs of
41 // `requesting_origin_` are closed or navigated away from.
42 using PermissionDecidedCallback =
Illia Klimove406ecc12022-11-22 15:53:2943 base::RepeatingCallback<void(ContentSetting /*result*/,
44 bool /*is_one_time*/,
45 bool /*is_final_decision*/)>;
[email protected]efad90f2014-01-17 00:45:5446
Bret Sepulveda5327d8b52021-07-21 17:44:2347 // `permission_decided_callback` is called when the permission request is
48 // resolved by the user (see comment on PermissionDecidedCallback above).
49 // `delete_callback` is called when the permission request is no longer needed
50 // by the permission system. Therefore, it is safe to delete `this` inside
51 // `delete_callback`. It will always be called eventually by the permission
52 // system.
53 // `delete_callback` may be called before `permission_decided_callback`, for
54 // example if the tab is closed without user interaction. In this case, the
55 // javascript promise from the requesting origin will not be resolved.
56 PermissionRequest(const GURL& requesting_origin,
57 RequestType request_type,
58 bool has_gesture,
59 PermissionDecidedCallback permission_decided_callback,
60 base::OnceClosure delete_callback);
61
Andy Paicu0a6d4b502023-08-29 15:13:0962 PermissionRequest(PermissionRequestData request_data,
63 PermissionDecidedCallback permission_decided_callback,
64 base::OnceClosure delete_callback);
65
Bret Sepulveda5327d8b52021-07-21 17:44:2366 PermissionRequest(const PermissionRequest&) = delete;
67 PermissionRequest& operator=(const PermissionRequest&) = delete;
68
Florian Jackyeeb62062022-10-05 18:04:0769 enum ChipTextType {
70 LOUD_REQUEST,
71 QUIET_REQUEST,
72 ALLOW_CONFIRMATION,
Florian Jacky2b3f54f2023-05-03 08:31:5273 ALLOW_ONCE_CONFIRMATION,
Florian Jackyeeb62062022-10-05 18:04:0774 BLOCKED_CONFIRMATION,
75 ACCESSIBILITY_ALLOWED_CONFIRMATION,
Florian Jacky2b3f54f2023-05-03 08:31:5276 ACCESSIBILITY_ALLOWED_ONCE_CONFIRMATION,
Florian Jackyeeb62062022-10-05 18:04:0777 ACCESSIBILITY_BLOCKED_CONFIRMATION
78 };
79
Bret Sepulveda5327d8b52021-07-21 17:44:2380 virtual ~PermissionRequest();
81
Andy Paicu0a6d4b502023-08-29 15:13:0982 GURL requesting_origin() const { return data_.requesting_origin; }
83 RequestType request_type() const;
[email protected]d23cdeee2014-03-10 06:39:5384
Bret Sepulvedad7e4d442021-04-20 13:46:4185 // Whether |this| and |other_request| are duplicates and therefore don't both
86 // need to be shown in the UI.
87 virtual bool IsDuplicateOf(PermissionRequest* other_request) const;
88
Xiaohan Wange813582302022-01-14 14:50:4689#if BUILDFLAG(IS_ANDROID)
Bret Sepulveda5327d8b52021-07-21 17:44:2390 // Returns prompt text appropriate for displaying in an Android dialog.
91 virtual std::u16string GetDialogMessageText() const;
timlohaa3ce262017-06-01 05:29:4092#endif
93
Thomas Nguyen9f1ff7302023-03-30 12:23:3594 // Returns a weak pointer to this instance.
95 base::WeakPtr<PermissionRequest> GetWeakPtr();
96
Xiaohan Wange813582302022-01-14 14:50:4697#if !BUILDFLAG(IS_ANDROID)
Florian Jacky4748cf32022-10-06 09:04:1898 // Returns whether displaying a confirmation chip for the request is
99 // supported.
100 bool IsConfirmationChipSupported();
101
Illia Klimovfabd8b52021-10-21 07:15:40