blob: d5dc0efb7d76efca699a6939190375617b1fb76b [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,
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,
benwells46b02fa2016-04-20 02:37:0241 // NUM must be the last value in the enum.
42 NUM
43};
44
benwells471d1f12016-07-25 23:58:0445// 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.
48enum class PermissionRequestGestureType {
49 UNKNOWN,
50 GESTURE,
51 NO_GESTURE,
52 // NUM must be the last value in the enum.
53 NUM
54};
55
tsergeant58defcfb2016-07-19 23:47:2856// Describes the interface a feature making permission requests should
57// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5458// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2859// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4860// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5461// 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.
tsergeant58defcfb2016-07-19 23:47:2864class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5465 public:
estade20c051a92016-10-15 22:53:2266#if defined(OS_ANDROID)
67 // On Android, icons are represented with an IDR_ identifier.
68 typedef int IconId;
69#else
estade1e235b62017-02-15 01:40:3470 // On desktop, we use a vector icon.
71 typedef const gfx::VectorIcon& IconId;
estade20c051a92016-10-15 22:53:2272#endif
73
dominicknd4e446a2016-09-13 07:44:1374 PermissionRequest();
tsergeant58defcfb2016-07-19 23:47:2875 virtual ~PermissionRequest() {}
[email protected]efad90f2014-01-17 00:45:5476
[email protected]d23cdeee2014-03-10 06:39:5377 // The icon to use next to the message text fragment in the permission bubble.
estade20c051a92016-10-15 22:53:2278 virtual IconId GetIconId() const = 0;
[email protected]d23cdeee2014-03-10 06:39:5379
timlohaa3ce262017-06-01 05:29:4080#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]dd1ba692014-01-24 23:17:3786 // Returns the shortened prompt text for this permission. Must be phrased
[email protected]d23cdeee2014-03-10 06:39:5387 // 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]dd1ba692014-01-24 23:17:3790 virtual base::string16 GetMessageTextFragment() const = 0;
91
johnmefe4e96d2016-01-27 16:14:4192 // Get the origin on whose behalf this permission request is being made.
93 virtual GURL GetOrigin() const = 0;
[email protected]dd1ba692014-01-24 23:17:3794
[email protected]efad90f2014-01-17 00:45:5495 // 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
tsergeant58defcfb2016-07-19 23:47:28106 // The UI this request was associated with was answered by the user.
[email protected]e2ff17e2014-02-06 02:32:33107 // It is safe for the request to be deleted at this point -- it will receive
tsergeant58defcfb2016-07-19 23:47:28108 // no further message from the permission request system. This method will
[email protected]e2ff17e2014-02-06 02:32:33109 // eventually be called on every request which is not unregistered.
[email protected]efad90f2014-01-17 00:45:54110 virtual void RequestFinished() = 0;
benwells46b02fa2016-04-20 02:37:02111
dominicknd4e446a2016-09-13 07:44:13112 // True if a persistence toggle should be shown in the UI for this request.
113 virtual bool ShouldShowPersistenceToggle() const;
114
tsergeant58defcfb2016-07-19 23:47:28115 // Used to record UMA metrics for permission requests.
timloh102eac82017-07-21 03:55:09116 virtual PermissionRequestType GetPermissionRequestType() const = 0;
benwells471d1f12016-07-25 23:58:04117
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;
dominicknd4e446a2016-09-13 07:44:13122
lshangada00c12016-10-17 04:51:10123 // Used on Android to determine what Android OS permissions are needed for
124 // this permission request.
125 virtual ContentSettingsType GetContentSettingsType() const;
126
dominicknd4e446a2016-09-13 07:44:13127 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]efad90f2014-01-17 00:45:54137};
138
tsergeant58defcfb2016-07-19 23:47:28139#endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_REQUEST_H_