[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 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_ |
| 6 | #define CHROME_BROWSER_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" |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 9 | #include "base/strings/string16.h" |
lshang | ada00c1 | 2016-10-17 04:51:10 | [diff] [blame] | 10 | #include "components/content_settings/core/common/content_settings_types.h" |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 11 | #include "url/gurl.h" |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 12 | |
estade | 292df4f8 | 2015-07-31 18:53:25 | [diff] [blame] | 13 | namespace gfx { |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 14 | struct VectorIcon; |
estade | 292df4f8 | 2015-07-31 18:53:25 | [diff] [blame] | 15 | } |
| 16 | |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 17 | // Used for UMA to record the types of permission prompts shown. |
Adam Langley | 5472afb | 2018-01-10 00:07:40 | [diff] [blame] | 18 | // When updating, you also need to update: |
| 19 | // 1) The PermissionRequestType enum in tools/metrics/histograms/enums.xml. |
| 20 | // 2) The PermissionRequestTypes suffix list in |
| 21 | // tools/metrics/histograms/histograms.xml. |
| 22 | // 3) GetPermissionRequestString in |
| 23 | // chrome/browser/permissions/permission_uma_util.cc. |
| 24 | // |
| 25 | // The usual rules of updating UMA values applies to this enum: |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 26 | // - don't remove values |
| 27 | // - only ever add values at the end |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 28 | enum class PermissionRequestType { |
cm.sanchi | 761e67a | 2017-11-16 08:23:28 | [diff] [blame] | 29 | UNKNOWN = 0, |
| 30 | MULTIPLE = 1, |
Timothy Loh | bbd67f7 | 2017-12-12 06:14:50 | [diff] [blame] | 31 | // UNUSED_PERMISSION = 2, |
cm.sanchi | 761e67a | 2017-11-16 08:23:28 | [diff] [blame] | 32 | QUOTA = 3, |
| 33 | DOWNLOAD = 4, |
Timothy Loh | bbd67f7 | 2017-12-12 06:14:50 | [diff] [blame] | 34 | // MEDIA_STREAM = 5, |
cm.sanchi | 761e67a | 2017-11-16 08:23:28 | [diff] [blame] | 35 | REGISTER_PROTOCOL_HANDLER = 6, |
| 36 | PERMISSION_GEOLOCATION = 7, |
| 37 | PERMISSION_MIDI_SYSEX = 8, |
| 38 | PERMISSION_NOTIFICATIONS = 9, |
| 39 | PERMISSION_PROTECTED_MEDIA_IDENTIFIER = 10, |
| 40 | // PERMISSION_PUSH_MESSAGING = 11, |
| 41 | PERMISSION_FLASH = 12, |
| 42 | PERMISSION_MEDIASTREAM_MIC = 13, |
| 43 | PERMISSION_MEDIASTREAM_CAMERA = 14, |
| 44 | PERMISSION_ACCESSIBILITY_EVENTS = 15, |
Darwin Huang | f666174 | 2019-12-06 23:31:31 | [diff] [blame] | 45 | // PERMISSION_CLIPBOARD_READ = 16, // Replaced by |
| 46 | // PERMISSION_CLIPBOARD_READ_WRITE in M81. |
Adam Langley | 5472afb | 2018-01-10 00:07:40 | [diff] [blame] | 47 | PERMISSION_SECURITY_KEY_ATTESTATION = 17, |
Jinho Bang | 22de3a9 | 2018-02-27 18:16:22 | [diff] [blame] | 48 | PERMISSION_PAYMENT_HANDLER = 18, |
Francois Beaufort | dbb86fd | 2019-11-22 14:29:09 | [diff] [blame] | 49 | PERMISSION_NFC = 19, |
Darwin Huang | f666174 | 2019-12-06 23:31:31 | [diff] [blame] | 50 | PERMISSION_CLIPBOARD_READ_WRITE = 20, |
Alex Cooper | 530cfbb9 | 2019-12-19 03:19:54 | [diff] [blame] | 51 | PERMISSION_VR = 21, |
| 52 | PERMISSION_AR = 22, |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 53 | // NUM must be the last value in the enum. |
| 54 | NUM |
| 55 | }; |
| 56 | |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 57 | // Used for UMA to record whether a gesture was associated with the request. For |
| 58 | // simplicity not all request types track whether a gesture is associated with |
| 59 | // it or not, for these types of requests metrics are not recorded. |
| 60 | enum class PermissionRequestGestureType { |
| 61 | UNKNOWN, |
| 62 | GESTURE, |
| 63 | NO_GESTURE, |
| 64 | // NUM must be the last value in the enum. |
| 65 | NUM |
| 66 | }; |
| 67 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 68 | // Describes the interface a feature making permission requests should |
| 69 | // implement. A class of this type is registered with the permission request |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 70 | // manager to receive updates about the result of the permissions request |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 71 | // 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] | 72 | // RequestFinished is called. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 73 | // Note that no particular guarantees are made about what exact UI surface |
| 74 | // is presented to the user. The delegate may be coalesced with other bubble |
| 75 | // requests, or depending on the situation, not shown at all. |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 76 | class PermissionRequest { |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 77 | public: |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 78 | #if defined(OS_ANDROID) |
| 79 | // On Android, icons are represented with an IDR_ identifier. |
| 80 | typedef int IconId; |
| 81 | #else |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 82 | // On desktop, we use a vector icon. |
| 83 | typedef const gfx::VectorIcon& IconId; |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 84 | #endif |
| 85 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 86 | PermissionRequest(); |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 87 | virtual ~PermissionRequest() {} |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 88 | |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 89 | // The icon to use next to the message text fragment in the permission bubble. |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 90 | virtual IconId GetIconId() const = 0; |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 91 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 92 | #if defined(OS_ANDROID) |
Matt Jones | 2cd761c | 2019-09-18 18:53:40 | [diff] [blame] | 93 | // Returns the title of this permission as text. |
Mehran Mahmoudi | 088fb77 | 2019-05-14 21:58:31 | [diff] [blame] | 94 | virtual base::string16 GetTitleText() const = 0; |
| 95 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 96 | // Returns the full prompt text for this permission. This is currently only |
| 97 | // used on Android. |
| 98 | virtual base::string16 GetMessageText() const = 0; |
Andy Paicu | a5972f3 | 2019-08-22 20:23:18 | [diff] [blame] | 99 | |
| 100 | // Returns the title of this permission as text when the permission request is |
| 101 | // displayed as a quiet prompt. Only used on Android. By default it returns |
| 102 | // the same value as |GetTitleText| unless overridden. |
| 103 | virtual base::string16 GetQuietTitleText() const; |
| 104 | |
| 105 | // Returns the full prompt text for this permission as text when the |
| 106 | // permission request is displayed as a quiet prompt. Only used on Android. By |
| 107 | // default it returns the same value as |GetMessageText| unless overridden. |
| 108 | virtual base::string16 GetQuietMessageText() const; |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 109 | #endif |
| 110 | |
Marijn Kruisselbrink | 5d4f1b24 | 2019-05-23 00:45:23 | [diff] [blame] | 111 | // Returns the shortened prompt text for this permission. The permission |
| 112 | // bubble may coalesce different requests, and if it does, this text will |
| 113 | // be displayed next to an image and indicate the user grants the permission. |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 114 | virtual base::string16 GetMessageTextFragment() const = 0; |
| 115 | |
johnme | fe4e96d | 2016-01-27 16:14:41 | [diff] [blame] | 116 | // Get the origin on whose behalf this permission request is being made. |
| 117 | virtual GURL GetOrigin() const = 0; |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 118 | |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 119 | // Called when the user has granted the requested permission. |
| 120 | virtual void PermissionGranted() = 0; |
| 121 | |
| 122 | // Called when the user has denied the requested permission. |
| 123 | virtual void PermissionDenied() = 0; |
| 124 | |
| 125 | // Called when the user has cancelled the permission request. This |
| 126 | // corresponds to a denial, but is segregated in case the context needs to |
| 127 | // be able to distinguish between an active refusal or an implicit refusal. |
| 128 | virtual void Cancelled() = 0; |
| 129 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 130 | // The UI this request was associated with was answered by the user. |
[email protected] | e2ff17e | 2014-02-06 02:32:33 | [diff] [blame] | 131 | // 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] | 132 | // no further message from the permission request system. This method will |
[email protected] | e2ff17e | 2014-02-06 02:32:33 | [diff] [blame] | 133 | // eventually be called on every request which is not unregistered. |
Anatoliy Potapchuk | 1c46f7e | 2020-01-23 13:31:03 | [diff] [blame^] | 134 | // It is ok to call this method without actually resolving the request via |
| 135 | // PermissionGranted(), PermissionDenied() or Canceled(). However, it will not |
| 136 | // resolve the javascript promise from the requesting origin. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 137 | virtual void RequestFinished() = 0; |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 138 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 139 | // Used to record UMA metrics for permission requests. |
timloh | 102eac8 | 2017-07-21 03:55:09 | [diff] [blame] | 140 | virtual PermissionRequestType GetPermissionRequestType() const = 0; |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 141 | |
| 142 | // Used to record UMA for whether requests are associated with a user gesture. |
| 143 | // To keep things simple this metric is only recorded for the most popular |
| 144 | // request types. |
| 145 | virtual PermissionRequestGestureType GetGestureType() const; |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 146 | |
lshang | ada00c1 | 2016-10-17 04:51:10 | [diff] [blame] | 147 | // Used on Android to determine what Android OS permissions are needed for |
| 148 | // this permission request. |
| 149 | virtual ContentSettingsType GetContentSettingsType() const; |
| 150 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 151 | private: |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 152 | DISALLOW_COPY_AND_ASSIGN(PermissionRequest); |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 153 | }; |
| 154 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 155 | #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_ |