[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. |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 18 | // This corresponds to the PermissionRequestType enum in |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 19 | // src/tools/metrics/histograms.xml. The usual rules of updating UMA values |
| 20 | // applies to this enum: |
| 21 | // - don't remove values |
| 22 | // - only ever add values at the end |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 23 | // - keep the PermissionRequestType enum in sync with this definition. |
| 24 | enum class PermissionRequestType { |
cm.sanchi | 761e67a | 2017-11-16 08:23:28 | [diff] [blame^] | 25 | UNKNOWN = 0, |
| 26 | MULTIPLE = 1, |
| 27 | UNUSED_PERMISSION = 2, |
| 28 | QUOTA = 3, |
| 29 | DOWNLOAD = 4, |
| 30 | MEDIA_STREAM = 5, |
| 31 | REGISTER_PROTOCOL_HANDLER = 6, |
| 32 | PERMISSION_GEOLOCATION = 7, |
| 33 | PERMISSION_MIDI_SYSEX = 8, |
| 34 | PERMISSION_NOTIFICATIONS = 9, |
| 35 | PERMISSION_PROTECTED_MEDIA_IDENTIFIER = 10, |
| 36 | // PERMISSION_PUSH_MESSAGING = 11, |
| 37 | PERMISSION_FLASH = 12, |
| 38 | PERMISSION_MEDIASTREAM_MIC = 13, |
| 39 | PERMISSION_MEDIASTREAM_CAMERA = 14, |
| 40 | PERMISSION_ACCESSIBILITY_EVENTS = 15, |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 41 | // NUM must be the last value in the enum. |
| 42 | NUM |
| 43 | }; |
| 44 | |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 45 | // Used for UMA to record whether a gesture was associated with the request. For |
| 46 | // simplicity not all request types track whether a gesture is associated with |
| 47 | // it or not, for these types of requests metrics are not recorded. |
| 48 | enum class PermissionRequestGestureType { |
| 49 | UNKNOWN, |
| 50 | GESTURE, |
| 51 | NO_GESTURE, |
| 52 | // NUM must be the last value in the enum. |
| 53 | NUM |
| 54 | }; |
| 55 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 56 | // Describes the interface a feature making permission requests should |
| 57 | // implement. A class of this type is registered with the permission request |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 58 | // manager to receive updates about the result of the permissions request |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 59 | // 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] | 60 | // RequestFinished is called. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 61 | // Note that no particular guarantees are made about what exact UI surface |
| 62 | // is presented to the user. The delegate may be coalesced with other bubble |
| 63 | // requests, or depending on the situation, not shown at all. |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 64 | class PermissionRequest { |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 65 | public: |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 66 | #if defined(OS_ANDROID) |
| 67 | // On Android, icons are represented with an IDR_ identifier. |
| 68 | typedef int IconId; |
| 69 | #else |
estade | 1e235b6 | 2017-02-15 01:40:34 | [diff] [blame] | 70 | // On desktop, we use a vector icon. |
| 71 | typedef const gfx::VectorIcon& IconId; |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 72 | #endif |
| 73 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 74 | PermissionRequest(); |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 75 | virtual ~PermissionRequest() {} |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 76 | |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 77 | // The icon to use next to the message text fragment in the permission bubble. |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 78 | virtual IconId GetIconId() const = 0; |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 79 | |
timloh | aa3ce26 | 2017-06-01 05:29:40 | [diff] [blame] | 80 | #if defined(OS_ANDROID) |
| 81 | // Returns the full prompt text for this permission. This is currently only |
| 82 | // used on Android. |
| 83 | virtual base::string16 GetMessageText() const = 0; |
| 84 | #endif |
| 85 | |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 86 | // Returns the shortened prompt text for this permission. Must be phrased |
[email protected] | d23cdeee | 2014-03-10 06:39:53 | [diff] [blame] | 87 | // as a heading, e.g. "Location", or "Camera". The permission bubble may |
| 88 | // coalesce different requests, and if it does, this text will be displayed |
| 89 | // next to an image and indicate the user grants the permission. |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 90 | virtual base::string16 GetMessageTextFragment() const = 0; |
| 91 | |
johnme | fe4e96d | 2016-01-27 16:14:41 | [diff] [blame] | 92 | // Get the origin on whose behalf this permission request is being made. |
| 93 | virtual GURL GetOrigin() const = 0; |
[email protected] | dd1ba69 | 2014-01-24 23:17:37 | [diff] [blame] | 94 | |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 95 | // Called when the user has granted the requested permission. |
| 96 | virtual void PermissionGranted() = 0; |
| 97 | |
| 98 | // Called when the user has denied the requested permission. |
| 99 | virtual void PermissionDenied() = 0; |
| 100 | |
| 101 | // Called when the user has cancelled the permission request. This |
| 102 | // corresponds to a denial, but is segregated in case the context needs to |
| 103 | // be able to distinguish between an active refusal or an implicit refusal. |
| 104 | virtual void Cancelled() = 0; |
| 105 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 106 | // The UI this request was associated with was answered by the user. |
[email protected] | e2ff17e | 2014-02-06 02:32:33 | [diff] [blame] | 107 | // 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] | 108 | // no further message from the permission request system. This method will |
[email protected] | e2ff17e | 2014-02-06 02:32:33 | [diff] [blame] | 109 | // eventually be called on every request which is not unregistered. |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 110 | virtual void RequestFinished() = 0; |
benwells | 46b02fa | 2016-04-20 02:37:02 | [diff] [blame] | 111 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 112 | // True if a persistence toggle should be shown in the UI for this request. |
| 113 | virtual bool ShouldShowPersistenceToggle() const; |
| 114 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 115 | // Used to record UMA metrics for permission requests. |
timloh | 102eac8 | 2017-07-21 03:55:09 | [diff] [blame] | 116 | virtual PermissionRequestType GetPermissionRequestType() const = 0; |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 117 | |
| 118 | // Used to record UMA for whether requests are associated with a user gesture. |
| 119 | // To keep things simple this metric is only recorded for the most popular |
| 120 | // request types. |
| 121 | virtual PermissionRequestGestureType GetGestureType() const; |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 122 | |
lshang | ada00c1 | 2016-10-17 04:51:10 | [diff] [blame] | 123 | // Used on Android to determine what Android OS permissions are needed for |
| 124 | // this permission request. |
| 125 | virtual ContentSettingsType GetContentSettingsType() const; |
| 126 | |
dominickn | d4e446a | 2016-09-13 07:44:13 | [diff] [blame] | 127 | void set_persist(bool persist) { persist_ = persist; } |
| 128 | |
| 129 | protected: |
| 130 | bool persist() const { return persist_; } |
| 131 | |
| 132 | private: |
| 133 | // Whether or not the response for this prompt should be persisted. |
| 134 | bool persist_; |
| 135 | |
| 136 | DISALLOW_COPY_AND_ASSIGN(PermissionRequest); |
[email protected] | efad90f | 2014-01-17 00:45:54 | [diff] [blame] | 137 | }; |
| 138 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 139 | #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_ |