blob: f4473c3f81098810806c7dd0ef24fd36f2547180 [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.
tsergeant58defcfb2016-07-19 23:47:2818// This corresponds to the PermissionRequestType enum in
benwells46b02fa2016-04-20 02:37:0219// 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
tsergeant58defcfb2016-07-19 23:47:2823// - keep the PermissionRequestType enum in sync with this definition.
24enum class PermissionRequestType {
cm.sanchi761e67a2017-11-16 08:23:2825 UNKNOWN = 0,
26 MULTIPLE = 1,
Timothy Lohbbd67f72017-12-12 06:14:5027 // UNUSED_PERMISSION = 2,
cm.sanchi761e67a2017-11-16 08:23:2828 QUOTA = 3,
29 DOWNLOAD = 4,
Timothy Lohbbd67f72017-12-12 06:14:5030 // MEDIA_STREAM = 5,
cm.sanchi761e67a2017-11-16 08:23:2831 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,
Gary Kacmarcik726325ee2017-11-17 07:12:0841 PERMISSION_CLIPBOARD_READ = 16,
benwells46b02fa2016-04-20 02:37:0242 // NUM must be the last value in the enum.
43 NUM
44};
45
benwells471d1f12016-07-25 23:58:0446// Used for UMA to record whether a gesture was associated with the request. For
47// simplicity not all request types track whether a gesture is associated with
48// it or not, for these types of requests metrics are not recorded.
49enum class PermissionRequestGestureType {
50 UNKNOWN,
51 GESTURE,
52 NO_GESTURE,
53 // NUM must be the last value in the enum.
54 NUM
55};
56
tsergeant58defcfb2016-07-19 23:47:2857// Describes the interface a feature making permission requests should
58// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5459// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2860// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4861// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5462// Note that no particular guarantees are made about what exact UI surface
63// is presented to the user. The delegate may be coalesced with other bubble
64// requests, or depending on the situation, not shown at all.
tsergeant58defcfb2016-07-19 23:47:2865class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5466 public:
estade20c051a92016-10-15 22:53:2267#if defined(OS_ANDROID)
68 // On Android, icons are represented with an IDR_ identifier.
69 typedef int IconId;
70#else
estade1e235b62017-02-15 01:40:3471 // On desktop, we use a vector icon.
72 typedef const gfx::VectorIcon& IconId;
estade20c051a92016-10-15 22:53:2273#endif
74
dominicknd4e446a2016-09-13 07:44:1375 PermissionRequest();
tsergeant58defcfb2016-07-19 23:47:2876 virtual ~PermissionRequest() {}
[email protected]efad90f2014-01-17 00:45:5477
[email protected]d23cdeee2014-03-10 06:39:5378 // The icon to use next to the message text fragment in the permission bubble.
estade20c051a92016-10-15 22:53:2279 virtual IconId GetIconId() const = 0;
[email protected]d23cdeee2014-03-10 06:39:5380
timlohaa3ce262017-06-01 05:29:4081#if defined(OS_ANDROID)
82 // Returns the full prompt text for this permission. This is currently only
83 // used on Android.
84 virtual base::string16 GetMessageText() const = 0;
85#endif
86
[email protected]dd1ba692014-01-24 23:17:3787 // Returns the shortened prompt text for this permission. Must be phrased
[email protected]d23cdeee2014-03-10 06:39:5388 // as a heading, e.g. "Location", or "Camera". The permission bubble may
89 // coalesce different requests, and if it does, this text will be displayed
90 // next to an image and indicate the user grants the permission.
[email protected]dd1ba692014-01-24 23:17:3791 virtual base::string16 GetMessageTextFragment() const = 0;
92
johnmefe4e96d2016-01-27 16:14:4193 // Get the origin on whose behalf this permission request is being made.
94 virtual GURL GetOrigin() const = 0;
[email protected]dd1ba692014-01-24 23:17:3795
[email protected]efad90f2014-01-17 00:45:5496 // Called when the user has granted the requested permission.
97 virtual void PermissionGranted() = 0;
98
99 // Called when the user has denied the requested permission.
100 virtual void PermissionDenied() = 0;
101
102 // Called when the user has cancelled the permission request. This
103 // corresponds to a denial, but is segregated in case the context needs to
104 // be able to distinguish between an active refusal or an implicit refusal.
105 virtual void Cancelled() = 0;
106
tsergeant58defcfb2016-07-19 23:47:28107 // The UI this request was associated with was answered by the user.
[email protected]e2ff17e2014-02-06 02:32:33108 // It is safe for the request to be deleted at this point -- it will receive
tsergeant58defcfb2016-07-19 23:47:28109 // no further message from the permission request system. This method will
[email protected]e2ff17e2014-02-06 02:32:33110 // eventually be called on every request which is not unregistered.
[email protected]efad90f2014-01-17 00:45:54111 virtual void RequestFinished() = 0;
benwells46b02fa2016-04-20 02:37:02112
tsergeant58defcfb2016-07-19 23:47:28113 // Used to record UMA metrics for permission requests.
timloh102eac82017-07-21 03:55:09114 virtual PermissionRequestType GetPermissionRequestType() const = 0;
benwells471d1f12016-07-25 23:58:04115
116 // Used to record UMA for whether requests are associated with a user gesture.
117 // To keep things simple this metric is only recorded for the most popular
118 // request types.
119 virtual PermissionRequestGestureType GetGestureType() const;
dominicknd4e446a2016-09-13 07:44:13120
lshangada00c12016-10-17 04:51:10121 // Used on Android to determine what Android OS permissions are needed for
122 // this permission request.
123 virtual ContentSettingsType GetContentSettingsType() const;
124
dominicknd4e446a2016-09-13 07:44:13125 private:
dominicknd4e446a2016-09-13 07:44:13126 DISALLOW_COPY_AND_ASSIGN(PermissionRequest);
[email protected]efad90f2014-01-17 00:45:54127};
128
tsergeant58defcfb2016-07-19 23:47:28129#endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_