blob: c78e7b2fb1aae870d110923c1d6c8741e47ffb48 [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
Jan Wilken Dörriead587c32021-03-11 14:09:278#include <string>
9
dominicknd4e446a2016-09-13 07:44:1310#include "base/macros.h"
Bret Sepulveda55f43dec2020-09-27 22:58:5611#include "base/optional.h"
[email protected]efad90f2014-01-17 00:45:5412#include "base/strings/string16.h"
Clark DuVall484c2562020-01-23 22:05:0913#include "build/build_config.h"
lshangada00c12016-10-17 04:51:1014#include "components/content_settings/core/common/content_settings_types.h"
Andy Paicu4a88f422020-11-12 18:21:3915#include "components/permissions/permission_request_enums.h"
[email protected]d23cdeee2014-03-10 06:39:5316#include "url/gurl.h"
[email protected]efad90f2014-01-17 00:45:5417
Clark DuVall484c2562020-01-23 22:05:0918namespace permissions {
Bret Sepulveda362cce42021-01-13 18:47:5419enum class RequestType;
Clark DuVall484c2562020-01-23 22:05:0920
tsergeant58defcfb2016-07-19 23:47:2821// Describes the interface a feature making permission requests should
22// implement. A class of this type is registered with the permission request
[email protected]efad90f2014-01-17 00:45:5423// manager to receive updates about the result of the permissions request
tsergeant58defcfb2016-07-19 23:47:2824// from the bubble or infobar. It should live until it is unregistered or until
[email protected]634e5982014-04-18 19:20:4825// RequestFinished is called.
[email protected]efad90f2014-01-17 00:45:5426// Note that no particular guarantees are made about what exact UI surface
27// is presented to the user. The delegate may be coalesced with other bubble
28// requests, or depending on the situation, not shown at all.
tsergeant58defcfb2016-07-19 23:47:2829class PermissionRequest {
[email protected]efad90f2014-01-17 00:45:5430 public:
dominicknd4e446a2016-09-13 07:44:1331 PermissionRequest();
tsergeant58defcfb2016-07-19 23:47:2832 virtual ~PermissionRequest() {}
[email protected]efad90f2014-01-17 00:45:5433
Bret Sepulveda362cce42021-01-13 18:47:5434 // The type of this request.
35 virtual RequestType GetRequestType() const = 0;
[email protected]d23cdeee2014-03-10 06:39:5336
timlohaa3ce262017-06-01 05:29:4037#if defined(OS_ANDROID)
timlohaa3ce262017-06-01 05:29:4038 // Returns the full prompt text for this permission. This is currently only
39 // used on Android.
Jan Wilken Dörriefa241ba2021-03-11 17:57:0140 virtual std::u16string GetMessageText() const = 0;
Andy Paicua5972f32019-08-22 20:23:1841
42 // Returns the title of this permission as text when the permission request is
43 // displayed as a quiet prompt. Only used on Android. By default it returns
44 // the same value as |GetTitleText| unless overridden.
Jan Wilken Dörriefa241ba2021-03-11 17:57:0145 virtual std::u16string GetQuietTitleText() const;
Andy Paicua5972f32019-08-22 20:23:1846
47 // Returns the full prompt text for this permission as text when the
48 // permission request is displayed as a quiet prompt. Only used on Android. By
49 // default it returns the same value as |GetMessageText| unless overridden.
Jan Wilken Dörriefa241ba2021-03-11 17:57:0150 virtual std::u16string GetQuietMessageText() const;
timlohaa3ce262017-06-01 05:29:4051#endif
52
Olesia Marukhnof8a4bed82020-06-17 13:35:3153#if !defined(OS_ANDROID)
54 // Returns the short text for the chip button related to this permission.
Jan Wilken Dörriefa241ba2021-03-11 17:57:0155 virtual base::Optional<std::u16string> GetChipText() const;
Olesia Marukhnof8a4bed82020-06-17 13:35:3156#endif
57
Marijn Kruisselbrink5d4f1b242019-05-23 00:45:2358 // Returns the shortened prompt text for this permission. The permission
59 // bubble may coalesce different requests, and if it does, this text will
60 // be displayed next to an image and indicate the user grants the permission.
Jan Wilken Dörriefa241ba2021-03-11 17:57:0161 virtual std::u16string GetMessageTextFragment() const = 0;
[email protected]dd1ba692014-01-24 23:17:3762
johnmefe4e96d2016-01-27 16:14:4163 // Get the origin on whose behalf this permission request is being made.
64 virtual GURL GetOrigin() const = 0;
[email protected]dd1ba692014-01-24 23:17:3765
[email protected]efad90f2014-01-17 00:45:5466 // Called when the user has granted the requested permission.
Ravjit Singh Uppalc73b5a62020-11-13 01:38:5267 // If is_one_time is true the permission will last until all tabs of a given
68 // |origin| are closed or navigated away from. The permission will
69 // automatically expire after 1 day.
70 virtual void PermissionGranted(bool is_one_time) = 0;
[email protected]efad90f2014-01-17 00:45:5471
72 // Called when the user has denied the requested permission.
73 virtual void PermissionDenied() = 0;
74
75 // Called when the user has cancelled the permission request. This
76 // corresponds to a denial, but is segregated in case the context needs to
77 // be able to distinguish between an active refusal or an implicit refusal.
78 virtual void Cancelled() = 0;
79
tsergeant58defcfb2016-07-19 23:47:2880 // The UI this request was associated with was answered by the user.
[email protected]e2ff17e2014-02-06 02:32:3381 // It is safe for the request to be deleted at this point -- it will receive
tsergeant58defcfb2016-07-19 23:47:2882 // no further message from the permission request system. This method will
[email protected]e2ff17e2014-02-06 02:32:3383 // eventually be called on every request which is not unregistered.
Anatoliy Potapchuk1c46f7e2020-01-23 13:31:0384 // It is ok to call this method without actually resolving the request via
85 // PermissionGranted(), PermissionDenied() or Canceled(). However, it will not
86 // resolve the javascript promise from the requesting origin.
[email protected]efad90f2014-01-17 00:45:5487 virtual void RequestFinished() = 0;
benwells46b02fa2016-04-20 02:37:0288
benwells471d1f12016-07-25 23:58:0489 // Used to record UMA for whether requests are associated with a user gesture.
90 // To keep things simple this metric is only recorded for the most popular
91 // request types.
92 virtual PermissionRequestGestureType GetGestureType() const;
dominicknd4e446a2016-09-13 07:44:1393
lshangada00c12016-10-17 04:51:1094 // Used on Android to determine what Android OS permissions are needed for
95 // this permission request.
96 virtual ContentSettingsType GetContentSettingsType() const;
97
dominicknd4e446a2016-09-13 07:44:1398 private:
dominicknd4e446a2016-09-13 07:44:1399 DISALLOW_COPY_AND_ASSIGN(PermissionRequest);
[email protected]efad90f2014-01-17 00:45:54100};
101
Clark DuVall484c2562020-01-23 22:05:09102} // namespace permissions
103
104#endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_