blob: 0115cabdb04afc297d98d57ac46d46e8e41a0fa8 [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
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
dominicknd4e446a2016-09-13 07:44:138#include "base/macros.h"
[email protected]efad90f2014-01-17 00:45:549#include "base/strings/string16.h"
Clark DuVall484c2562020-01-23 22:05:0910#include "build/build_config.h"
lshangada00c12016-10-17 04:51:1011#include "components/content_settings/core/common/content_settings_types.h"
[email protected]d23cdeee2014-03-10 06:39:5312#include "url/gurl.h"
[email protected]efad90f2014-01-17 00:45:5413
estade292df4f82015-07-31 18:53:2514namespace gfx {
estade1e235b62017-02-15 01:40:3415struct VectorIcon;
estade292df4f82015-07-31 18:53:2516}
17
Clark DuVall484c2562020-01-23 22:05:0918namespace permissions {
19
benwells46b02fa2016-04-20 02:37:0220// Used for UMA to record the types of permission prompts shown.
Adam Langley5472afb2018-01-10 00:07:4021// When updating, you also need to update:
22// 1) The PermissionRequestType enum in tools/metrics/histograms/enums.xml.
23// 2) The PermissionRequestTypes suffix list in
24// tools/metrics/histograms/histograms.xml.
25// 3) GetPermissionRequestString in
26// chrome/browser/permissions/permission_uma_util.cc.
27//
28// The usual rules of updating UMA values applies to this enum:
benwells46b02fa2016-04-20 02:37:0229// - don't remove values
30// - only ever add values at the end
tsergeant58defcfb2016-07-19 23:47:2831enum class PermissionRequestType {
cm.sanchi761e67a2017-11-16 08:23:2832 UNKNOWN = 0,
33 MULTIPLE = 1,
Timothy Lohbbd67f72017-12-12 06:14:5034 // UNUSED_PERMISSION = 2,
cm.sanchi761e67a2017-11-16 08:23:2835 QUOTA = 3,
36 DOWNLOAD = 4,
Timothy Lohbbd67f72017-12-12 06:14:5037 // MEDIA_STREAM = 5,
cm.sanchi761e67a2017-11-16 08:23:2838 REGISTER_PROTOCOL_HANDLER = 6,
39 PERMISSION_GEOLOCATION = 7,
40 PERMISSION_MIDI_SYSEX = 8,
41 PERMISSION_NOTIFICATIONS = 9,
42 PERMISSION_PROTECTED_MEDIA_IDENTIFIER = 10,
43 // PERMISSION_PUSH_MESSAGING = 11,
44 PERMISSION_FLASH = 12,
45 PERMISSION_MEDIASTREAM_MIC = 13,
46 PERMISSION_MEDIASTREAM_CAMERA = 14,
47 PERMISSION_ACCESSIBILITY_EVENTS = 15,
Darwin Huangf6661742019-12-06 23:31:3148 // PERMISSION_CLIPBOARD_READ = 16, // Replaced by
49 // PERMISSION_CLIPBOARD_READ_WRITE in M81.
Adam Langley5472afb2018-01-10 00:07:4050 PERMISSION_SECURITY_KEY_ATTESTATION = 17,
Jinho Bang22de3a92018-02-27 18:16:2251 PERMISSION_PAYMENT_HANDLER = 18,
Francois Beaufortdbb86fd2019-11-22 14:29:0952 PERMISSION_NFC = 19,
Darwin Huangf6661742019-12-06 23:31:3153 PERMISSION_CLIPBOARD_READ_WRITE = 20,
Alex Cooper530cfbb92019-12-19 03:19:5454 PERMISSION_VR = 21,
55 PERMISSION_AR = 22,
benwells46b02fa2016-04-20 02:37:0256 // NUM must be the last value in the enum.
57 NUM
58};
59
benwells471d1f12016-07-25 23:58:0460// Used for UMA to record whether a gesture was associated with the request. For
61// simplicity not all request types track whether a gesture is associated with
62// it or not, for these types of requests metrics are not recorded.
63enum class PermissionRequestGestureType {
64 UNKNOWN,
65 GESTURE,
66 NO_GESTURE,
67 // NUM must be the last value in the enum.
68 NUM
69};
70
tsergeant58defcfb2016-07-19 23:47:2871// Describes the interface a feature making permission requests should
72// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5473// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2874// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4875// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5476// Note that no particular guarantees are made about what exact UI surface
77// is presented to the user. The delegate may be coalesced with other bubble
78// requests, or depending on the situation, not shown at all.
tsergeant58defcfb2016-07-19 23:47:2879class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5480 public:
estade20c051a92016-10-15 22:53:2281#if defined(OS_ANDROID)
82 // On Android, icons are represented with an IDR_ identifier.
83 typedef int IconId;
84#else
estade1e235b62017-02-15 01:40:3485 // On desktop, we use a vector icon.
86 typedef const gfx::VectorIcon& IconId;
estade20c051a92016-10-15 22:53:2287#endif
88
dominicknd4e446a2016-09-13 07:44:1389 PermissionRequest();
tsergeant58defcfb2016-07-19 23:47:2890 virtual ~PermissionRequest() {}
[email protected]efad90f2014-01-17 00:45:5491
[email protected]d23cdeee2014-03-10 06:39:5392 // The icon to use next to the message text fragment in the permission bubble.
estade20c051a92016-10-15 22:53:2293 virtual IconId GetIconId() const = 0;
[email protected]d23cdeee2014-03-10 06:39:5394
timlohaa3ce262017-06-01 05:29:4095#if defined(OS_ANDROID)
Matt Jones2cd761c2019-09-18 18:53:4096 // Returns the title of this permission as text.
Mehran Mahmoudi088fb772019-05-14 21:58:3197 virtual base::string16 GetTitleText() const = 0;
98
timlohaa3ce262017-06-01 05:29:4099 // Returns the full prompt text for this permission. This is currently only
100 // used on Android.
101 virtual base::string16 GetMessageText() const = 0;
Andy Paicua5972f32019-08-22 20:23:18102
103 // Returns the title of this permission as text when the permission request is
104 // displayed as a quiet prompt. Only used on Android. By default it returns
105 // the same value as |GetTitleText| unless overridden.
106 virtual base::string16 GetQuietTitleText() const;
107
108 // Returns the full prompt text for this permission as text when the
109 // permission request is displayed as a quiet prompt. Only used on Android. By
110 // default it returns the same value as |GetMessageText| unless overridden.
111 virtual base::string16 GetQuietMessageText() const;
timlohaa3ce262017-06-01 05:29:40112#endif
113
Marijn Kruisselbrink5d4f1b242019-05-23 00:45:23114 // Returns the shortened prompt text for this permission. The permission
115 // bubble may coalesce different requests, and if it does, this text will
116 // be displayed next to an image and indicate the user grants the permission.
[email protected]dd1ba692014-01-24 23:17:37117 virtual base::string16 GetMessageTextFragment() const = 0;
118
johnmefe4e96d2016-01-27 16:14:41119 // Get the origin on whose behalf this permission request is being made.
120 virtual GURL GetOrigin() const = 0;
[email protected]dd1ba692014-01-24 23:17:37121
[email protected]efad90f2014-01-17 00:45:54122 // Called when the user has granted the requested permission.
123 virtual void PermissionGranted() = 0;
124
125 // Called when the user has denied the requested permission.
126 virtual void PermissionDenied() = 0;
127
128 // Called when the user has cancelled the permission request. This
129 // corresponds to a denial, but is segregated in case the context needs to
130 // be able to distinguish between an active refusal or an implicit refusal.
131 virtual void Cancelled() = 0;
132
tsergeant58defcfb2016-07-19 23:47:28133 // The UI this request was associated with was answered by the user.
[email protected]e2ff17e2014-02-06 02:32:33134 // It is safe for the request to be deleted at this point -- it will receive
tsergeant58defcfb2016-07-19 23:47:28135 // no further message from the permission request system. This method will
[email protected]e2ff17e2014-02-06 02:32:33136 // eventually be called on every request which is not unregistered.
Anatoliy Potapchuk1c46f7e2020-01-23 13:31:03137 // It is ok to call this method without actually resolving the request via
138 // PermissionGranted(), PermissionDenied() or Canceled(). However, it will not
139 // resolve the javascript promise from the requesting origin.
[email protected]efad90f2014-01-17 00:45:54140 virtual void RequestFinished() = 0;
benwells46b02fa2016-04-20 02:37:02141
tsergeant58defcfb2016-07-19 23:47:28142 // Used to record UMA metrics for permission requests.
timloh102eac82017-07-21 03:55:09143 virtual PermissionRequestType GetPermissionRequestType() const = 0;
benwells471d1f12016-07-25 23:58:04144
145 // Used to record UMA for whether requests are associated with a user gesture.
146 // To keep things simple this metric is only recorded for the most popular
147 // request types.
148 virtual PermissionRequestGestureType GetGestureType() const;
dominicknd4e446a2016-09-13 07:44:13149
lshangada00c12016-10-17 04:51:10150 // Used on Android to determine what Android OS permissions are needed for
151 // this permission request.
152 virtual ContentSettingsType GetContentSettingsType() const;
153
dominicknd4e446a2016-09-13 07:44:13154 private:
dominicknd4e446a2016-09-13 07:44:13155 DISALLOW_COPY_AND_ASSIGN(PermissionRequest);
[email protected]efad90f2014-01-17 00:45:54156};
157
Clark DuVall484c2562020-01-23 22:05:09158} // namespace permissions
159
160#endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_