blob: 91e62fbb7748abe22a3b9245bf18bffda299edb5 [file] [log] [blame]
Balazs Engedye9934acb2019-12-04 22:15:071// Copyright 2019 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 DuVall5ca4ae12020-02-19 22:25:275#ifndef COMPONENTS_PERMISSIONS_NOTIFICATION_PERMISSION_UI_SELECTOR_H_
6#define COMPONENTS_PERMISSIONS_NOTIFICATION_PERMISSION_UI_SELECTOR_H_
Balazs Engedye9934acb2019-12-04 22:15:077
Balazs Engedy825e89b2020-05-28 12:48:178#include "base/callback_forward.h"
9#include "base/optional.h"
Clark DuVall484c2562020-01-23 22:05:0910#include "components/permissions/permission_request.h"
Balazs Engedye9934acb2019-12-04 22:15:0711
Clark DuVall5ca4ae12020-02-19 22:25:2712namespace permissions {
13
Balazs Engedye9934acb2019-12-04 22:15:0714// The interface for implementations that decide if the quiet prompt UI should
Balazs Engedy825e89b2020-05-28 12:48:1715// be used to display a notification permission |request|, whether a warning
16// should be printed to the Dev Tools console, and the reasons for both.
Balazs Engedye9934acb2019-12-04 22:15:0717//
18// Implementations of interface are expected to have long-lived instances that
19// can support multiple requests, but only one at a time.
20class NotificationPermissionUiSelector {
21 public:
Balazs Engedye9934acb2019-12-04 22:15:0722 enum class QuietUiReason {
23 kEnabledInPrefs,
24 kTriggeredByCrowdDeny,
Balazs Engedyb968c192020-05-14 15:20:1925 kTriggeredDueToAbusiveRequests,
Illia Klimovf7863522020-07-03 14:54:2726 kTriggeredDueToAbusiveContent,
Balazs Engedye9934acb2019-12-04 22:15:0727 };
28
Balazs Engedy825e89b2020-05-28 12:48:1729 enum class WarningReason {
30 kAbusiveRequests,
Illia Klimovf7863522020-07-03 14:54:2731 kAbusiveContent,
Balazs Engedy825e89b2020-05-28 12:48:1732 };
33
34 struct Decision {
35 Decision(base::Optional<QuietUiReason> quiet_ui_reason,
36 base::Optional<WarningReason> warning_reason);
37 ~Decision();
38
39 Decision(const Decision&);
40 Decision& operator=(const Decision&);
41
42 static constexpr base::Optional<QuietUiReason> UseNormalUi() {
43 return base::nullopt;
44 }
45
46 static constexpr base::Optional<WarningReason> ShowNoWarning() {
47 return base::nullopt;
48 }
49
50 static Decision UseNormalUiAndShowNoWarning();
51
52 // The reason for showing the quiet UI, or `base::nullopt` if the normal UI
53 // should be used.
54 base::Optional<QuietUiReason> quiet_ui_reason;
55
56 // The reason for printing a warning to the console, or `base::nullopt` if
57 // no warning should be printed.
58 base::Optional<WarningReason> warning_reason;
59 };
60
61 using DecisionMadeCallback = base::OnceCallback<void(const Decision&)>;
Balazs Engedye9934acb2019-12-04 22:15:0762
63 virtual ~NotificationPermissionUiSelector() {}
64
Bret Sepulvedae710f892020-10-08 10:40:5065 // Determines whether animations should be suppressed because we're very
66 // confident the user does not want notifications (e.g. they're abusive).
67 static bool ShouldSuppressAnimation(QuietUiReason reason);
68
Balazs Engedye9934acb2019-12-04 22:15:0769 // Determines the UI to use for the given |request|, and invokes |callback|
Darwin Huang1620c5f2020-01-30 20:34:0670 // when done, either synchronously or asynchronously. The |callback| is
Balazs Engedye9934acb2019-12-04 22:15:0771 // guaranteed never to be invoked after |this| goes out of scope. Only one
72 // request is supported at a time.
Clark DuVall5ca4ae12020-02-19 22:25:2773 virtual void SelectUiToUse(PermissionRequest* request,
Balazs Engedye9934acb2019-12-04 22:15:0774 DecisionMadeCallback callback) = 0;
75
76 // Cancel the pending request, if any. After this, the |callback| is
77 // guaranteed not to be invoked anymore, and another call to SelectUiToUse()
78 // can be issued.
79 virtual void Cancel() {}
80};
81
Clark DuVall5ca4ae12020-02-19 22:25:2782} // namespace permissions
83
84#endif // COMPONENTS_PERMISSIONS_NOTIFICATION_PERMISSION_UI_SELECTOR_H_