blob: 3213077234e275e3d6a8c72b67bb282526ced58f [file] [log] [blame]
[email protected]efad90f2014-01-17 00:45:541// 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
tsergeant58defcfb2016-07-19 23:47:285#ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_
6#define CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_
[email protected]efad90f2014-01-17 00:45:547
dominicknd4e446a2016-09-13 07:44:138#include "base/macros.h"
[email protected]efad90f2014-01-17 00:45:549#include "base/strings/string16.h"
lshangada00c12016-10-17 04:51:1010#include "components/content_settings/core/common/content_settings_types.h"
[email protected]d23cdeee2014-03-10 06:39:5311#include "url/gurl.h"
[email protected]efad90f2014-01-17 00:45:5412
estade292df4f82015-07-31 18:53:2513namespace gfx {
estade1e235b62017-02-15 01:40:3414struct VectorIcon;
estade292df4f82015-07-31 18:53:2515}
16
benwells46b02fa2016-04-20 02:37:0217// Used for UMA to record the types of permission prompts shown.
Adam Langley5472afb2018-01-10 00:07:4018// 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:
benwells46b02fa2016-04-20 02:37:0226// - don't remove values
27// - only ever add values at the end
tsergeant58defcfb2016-07-19 23:47:2828enum class PermissionRequestType {
cm.sanchi761e67a2017-11-16 08:23:2829 UNKNOWN = 0,
30 MULTIPLE = 1,
Timothy Lohbbd67f72017-12-12 06:14:5031 // UNUSED_PERMISSION = 2,
cm.sanchi761e67a2017-11-16 08:23:2832 QUOTA = 3,
33 DOWNLOAD = 4,
Timothy Lohbbd67f72017-12-12 06:14:5034 // MEDIA_STREAM = 5,
cm.sanchi761e67a2017-11-16 08:23:2835 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,
Gary Kacmarcik726325ee2017-11-17 07:12:0845 PERMISSION_CLIPBOARD_READ = 16,
Adam Langley5472afb2018-01-10 00:07:4046 PERMISSION_SECURITY_KEY_ATTESTATION = 17,
Jinho Bang22de3a92018-02-27 18:16:2247 PERMISSION_PAYMENT_HANDLER = 18,
Francois Beaufortdbb86fd2019-11-22 14:29:0948 PERMISSION_NFC = 19,
benwells46b02fa2016-04-20 02:37:0249 // NUM must be the last value in the enum.
50 NUM
51};
52
benwells471d1f12016-07-25 23:58:0453// Used for UMA to record whether a gesture was associated with the request. For
54// simplicity not all request types track whether a gesture is associated with
55// it or not, for these types of requests metrics are not recorded.
56enum class PermissionRequestGestureType {
57 UNKNOWN,
58 GESTURE,
59 NO_GESTURE,
60 // NUM must be the last value in the enum.
61 NUM
62};
63
tsergeant58defcfb2016-07-19 23:47:2864// Describes the interface a feature making permission requests should
65// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5466// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2867// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4868// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5469// Note that no particular guarantees are made about what exact UI surface
70// is presented to the user. The delegate may be coalesced with other bubble
71// requests, or depending on the situation, not shown at all.
tsergeant58defcfb2016-07-19 23:47:2872class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5473 public:
estade20c051a92016-10-15 22:53:2274#if defined(OS_ANDROID)
75 // On Android, icons are represented with an IDR_ identifier.
76 typedef int IconId;
77#else
estade1e235b62017-02-15 01:40:3478 // On desktop, we use a vector icon.
79 typedef const gfx::VectorIcon& IconId;
estade20c051a92016-10-15 22:53:2280#endif
81
dominicknd4e446a2016-09-13 07:44:1382 PermissionRequest();
tsergeant58defcfb2016-07-19 23:47:2883 virtual ~PermissionRequest() {}
[email protected]efad90f2014-01-17 00:45:5484
[email protected]d23cdeee2014-03-10 06:39:5385 // The icon to use next to the message text fragment in the permission bubble.
estade20c051a92016-10-15 22:53:2286 virtual IconId GetIconId() const = 0;
[email protected]d23cdeee2014-03-10 06:39:5387
timlohaa3ce262017-06-01 05:29:4088#if defined(OS_ANDROID)
Matt Jones2cd761c2019-09-18 18:53:4089 // Returns the title of this permission as text.
Mehran Mahmoudi088fb772019-05-14 21:58:3190 virtual base::string16 GetTitleText() const = 0;
91
timlohaa3ce262017-06-01 05:29:4092 // Returns the full prompt text for this permission. This is currently only
93 // used on Android.
94 virtual base::string16 GetMessageText() const = 0;
Andy Paicua5972f32019-08-22 20:23:1895
96 // Returns the title of this permission as text when the permission request is
97 // displayed as a quiet prompt. Only used on Android. By default it returns
98 // the same value as |GetTitleText| unless overridden.
99 virtual base::string16 GetQuietTitleText() const;
100
101 // Returns the full prompt text for this permission as text when the
102 // permission request is displayed as a quiet prompt. Only used on Android. By
103 // default it returns the same value as |GetMessageText| unless overridden.
104 virtual base::string16 GetQuietMessageText() const;
timlohaa3ce262017-06-01 05:29:40105#endif
106
Marijn Kruisselbrink5d4f1b242019-05-23 00:45:23107 // Returns the shortened prompt text for this permission. The permission
108 // bubble may coalesce different requests, and if it does, this text will
109 // be displayed next to an image and indicate the user grants the permission.
[email protected]dd1ba692014-01-24 23:17:37110 virtual base::string16 GetMessageTextFragment() const = 0;
111
johnmefe4e96d2016-01-27 16:14:41112 // Get the origin on whose behalf this permission request is being made.
113 virtual GURL GetOrigin() const = 0;
[email protected]dd1ba692014-01-24 23:17:37114
[email protected]efad90f2014-01-17 00:45:54115 // Called when the user has granted the requested permission.
116 virtual void PermissionGranted() = 0;
117
118 // Called when the user has denied the requested permission.
119 virtual void PermissionDenied() = 0;
120
121 // Called when the user has cancelled the permission request. This
122 // corresponds to a denial, but is segregated in case the context needs to
123 // be able to distinguish between an active refusal or an implicit refusal.
124 virtual void Cancelled() = 0;
125
tsergeant58defcfb2016-07-19 23:47:28126 // The UI this request was associated with was answered by the user.
[email protected]e2ff17e2014-02-06 02:32:33127 // It is safe for the request to be deleted at this point -- it will receive
tsergeant58defcfb2016-07-19 23:47:28128 // no further message from the permission request system. This method will
[email protected]e2ff17e2014-02-06 02:32:33129 // eventually be called on every request which is not unregistered.
[email protected]efad90f2014-01-17 00:45:54130 virtual void RequestFinished() = 0;
benwells46b02fa2016-04-20 02:37:02131
tsergeant58defcfb2016-07-19 23:47:28132 // Used to record UMA metrics for permission requests.
timloh102eac82017-07-21 03:55:09133 virtual PermissionRequestType GetPermissionRequestType() const = 0;
benwells471d1f12016-07-25 23:58:04134
135 // Used to record UMA for whether requests are associated with a user gesture.
136 // To keep things simple this metric is only recorded for the most popular
137 // request types.
138 virtual PermissionRequestGestureType GetGestureType() const;
dominicknd4e446a2016-09-13 07:44:13139
lshangada00c12016-10-17 04:51:10140 // Used on Android to determine what Android OS permissions are needed for
141 // this permission request.
142 virtual ContentSettingsType GetContentSettingsType() const;
143
dominicknd4e446a2016-09-13 07:44:13144 private:
dominicknd4e446a2016-09-13 07:44:13145 DISALLOW_COPY_AND_ASSIGN(PermissionRequest);
[email protected]efad90f2014-01-17 00:45:54146};
147
tsergeant58defcfb2016-07-19 23:47:28148#endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_