[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 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 |
| 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 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 8 | #include "base/macros.h" |
Bret Sepulveda | 55f43dec | 2020-09-27 22:58:56 | [diff] [blame] | 9 | #include "base/optional.h" |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 10 | #include "base/strings/string16.h" |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 11 | #include "build/build_config.h" |
lshang | ada00c1 | 2016-10-17 04:51:10 | [diff] [blame] | 12 | #include "components/content_settings/core/common/content_settings_types.h" |
Andy Paicu | 4a88f42 | 2020-11-12 18:21:39 | [diff] [blame] | 13 | #include "components/permissions/permission_request_enums.h" |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 14 | #include "url/gurl.h" |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 15 | |
estade | 292df4f8 | 2015-07-31 18:53:25 | [diff] [blame] | 16 | namespace gfx { |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 17 | struct VectorIcon; |
estade | 292df4f8 | 2015-07-31 18:53:25 | [diff] [blame] | 18 | } |
| 19 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 20 | namespace permissions { |
| 21 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 22 | // Describes the interface a feature making permission requests should |
| 23 | // implement. A class of this type is registered with the permission request |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 24 | // manager to receive updates about the result of the permissions request |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 25 | // 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] | 26 | // RequestFinished is called. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 27 | // Note that no particular guarantees are made about what exact UI surface |
| 28 | // is presented to the user. The delegate may be coalesced with other bubble |
| 29 | // requests, or depending on the situation, not shown at all. |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 30 | class PermissionRequest { |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 31 | public: |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 32 | #if defined(OS_ANDROID) |
| 33 | // On Android, icons are represented with an IDR_ identifier. |
| 34 | typedef int IconId; |
| 35 | #else |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 36 | // On desktop, we use a vector icon. |
| 37 | typedef const gfx::VectorIcon& IconId; |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 38 | #endif |
| 39 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 40 | PermissionRequest(); |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 41 | virtual ~PermissionRequest() {} |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 42 | |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 43 | // The icon to use next to the message text fragment in the permission bubble. |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 44 | virtual IconId GetIconId() const = 0; |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 45 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 46 | #if defined(OS_ANDROID) |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 47 | // Returns the full prompt text for this permission. This is currently only |
| 48 | // used on Android. |
| 49 | virtual base::string16 GetMessageText() const = 0; |
Andy Paicu | a5972f3 | 2019-08-22 20:23:18 | [diff] [blame] | 50 | |
| 51 | // Returns the title of this permission as text when the permission request is |
| 52 | // displayed as a quiet prompt. Only used on Android. By default it returns |
| 53 | // the same value as |GetTitleText| unless overridden. |
| 54 | virtual base::string16 GetQuietTitleText() const; |
| 55 | |
| 56 | // Returns the full prompt text for this permission as text when the |
| 57 | // permission request is displayed as a quiet prompt. Only used on Android. By |
| 58 | // default it returns the same value as |GetMessageText| unless overridden. |
| 59 | virtual base::string16 GetQuietMessageText() const; |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 60 | #endif |
| 61 | |
Olesia Marukhno | f8a4bed8 | 2020-06-17 13:35:31 | [diff] [blame] | 62 | #if !defined(OS_ANDROID) |
| 63 | // Returns the short text for the chip button related to this permission. |
Bret Sepulveda | 55f43dec | 2020-09-27 22:58:56 | [diff] [blame] | 64 | virtual base::Optional<base::string16> GetChipText() const; |
Olesia Marukhno | f8a4bed8 | 2020-06-17 13:35:31 | [diff] [blame] | 65 | #endif |
| 66 | |
Marijn Kruisselbrink | 5d4f1b24 | 2019-05-23 00:45:23 | [diff] [blame] | 67 | // Returns the shortened prompt text for this permission. The permission |
| 68 | // bubble may coalesce different requests, and if it does, this text will |
| 69 | // be displayed next to an image and indicate the user grants the permission. |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 70 | virtual base::string16 GetMessageTextFragment() const = 0; |
| 71 | |
johnme | fe4e96d | 2016-01-27 16:14:41 | [diff] [blame] | 72 | // Get the origin on whose behalf this permission request is being made. |
| 73 | virtual GURL GetOrigin() const = 0; |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 74 | |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 75 | // Called when the user has granted the requested permission. |
Ravjit Singh Uppal | c73b5a6 | 2020-11-13 01:38:52 | [diff] [blame^] | 76 | // If is_one_time is true the permission will last until all tabs of a given |
| 77 | // |origin| are closed or navigated away from. The permission will |
| 78 | // automatically expire after 1 day. |
| 79 | virtual void PermissionGranted(bool is_one_time) = 0; |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 80 | |
| 81 | // Called when the user has denied the requested permission. |
| 82 | virtual void PermissionDenied() = 0; |
| 83 | |
| 84 | // Called when the user has cancelled the permission request. This |
| 85 | // corresponds to a denial, but is segregated in case the context needs to |
| 86 | // be able to distinguish between an active refusal or an implicit refusal. |
| 87 | virtual void Cancelled() = 0; |
| 88 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 89 | // The UI this request was associated with was answered by the user. |
[email protected] | e2ff17e | 2014-02-06 02:32:33 | [diff] [blame] | 90 | // It is safe for the request to be deleted at this point -- it will receive |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 91 | // no further message from the permission request system. This method will |
[email protected] | e2ff17e | 2014-02-06 02:32:33 | [diff] [blame] | 92 | // eventually be called on every request which is not unregistered. |
Anatoliy Potapchuk | 1c46f7e | 2020-01-23 13:31:03 | [diff] [blame] | 93 | // It is ok to call this method without actually resolving the request via |
| 94 | // PermissionGranted(), PermissionDenied() or Canceled(). However, it will not |
| 95 | // resolve the javascript promise from the requesting origin. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 96 | virtual void RequestFinished() = 0; |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 97 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 98 | // Used to record UMA metrics for permission requests. |
timloh | 102eac8 | 2017-07-21 03:55:09 | [diff] [blame] | 99 | virtual PermissionRequestType GetPermissionRequestType() const = 0; |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 100 | |
| 101 | // Used to record UMA for whether requests are associated with a user gesture. |
| 102 | // To keep things simple this metric is only recorded for the most popular |
| 103 | // request types. |
| 104 | virtual PermissionRequestGestureType GetGestureType() const; |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 105 | |
lshang | ada00c1 | 2016-10-17 04:51:10 | [diff] [blame] | 106 | // Used on Android to determine what Android OS permissions are needed for |
| 107 | // this permission request. |
| 108 | virtual ContentSettingsType GetContentSettingsType() const; |
| 109 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 110 | private: |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 111 | DISALLOW_COPY_AND_ASSIGN(PermissionRequest); |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 112 | }; |
| 113 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 114 | } // namespace permissions |
| 115 | |
| 116 | #endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_ |