File: notification_handler.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,624 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_HANDLER_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_HANDLER_H_

#include <memory>
#include <optional>
#include <string>

#include "base/functional/callback_forward.h"

class GURL;
class Profile;

// Interface that enables the different kind of notifications to process
// operations coming from the user or decisions made by the underlying
// notification type.
class NotificationHandler {
 public:
  // Type of notifications that a handler can be responsible for.
  // A Java counterpart will be generated for this enum.
  // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications
  // GENERATED_JAVA_CLASS_NAME_OVERRIDE: NotificationType
  enum class Type {
    WEB_PERSISTENT = 0,
    WEB_NON_PERSISTENT = 1,
    EXTENSION = 2,
    SEND_TAB_TO_SELF = 3,
    TRANSIENT = 4,  // A generic type for any notification that does not outlive
                    // the browser instance and is controlled by a
                    // NotificationDelegate.
    // Deprecated
    // PERMISSION_REQUEST = 5,  // A permission request that is presented to the
    //                          // user via a notification.
    SHARING = 6,
    ANNOUNCEMENT = 7,
    NEARBY_SHARE = 8,
    NOTIFICATIONS_MUTED = 9,
    TAILORED_SECURITY = 10,
    MAX = TAILORED_SECURITY,
  };

  virtual ~NotificationHandler();

  // Called after a notification has been displayed.
  virtual void OnShow(Profile* profile, const std::string& notification_id);

  // Process notification close events. The |completed_closure| must be invoked
  // on the UI thread once processing of the close event has been finished.
  virtual void OnClose(Profile* profile,
                       const GURL& origin,
                       const std::string& notification_id,
                       bool by_user,
                       base::OnceClosure completed_closure);

  // Process clicks on a notification or its buttons, depending on
  // |action_index|. The |completed_closure| must be invoked on the UI thread
  // once processing of the click event has been finished.
  virtual void OnClick(Profile* profile,
                       const GURL& origin,
                       const std::string& notification_id,
                       const std::optional<int>& action_index,
                       const std::optional<std::u16string>& reply,
                       base::OnceClosure completed_closure);

  // Called when notifications of the given origin have to be disabled.
  virtual void DisableNotifications(Profile* profile, const GURL& origin);

  // Called when the settings page for the given origin has to be opened.
  virtual void OpenSettings(Profile* profile, const GURL& origin);

  // Called when a user clicks to report a notification as safe.
  virtual void ReportNotificationAsSafe(const std::string& notification_id,
                                        const GURL& url,
                                        Profile* profile);

  // Called when a user clicks to report a warned notification as spam.
  virtual void ReportWarnedNotificationAsSpam(
      const std::string& notification_id,
      const GURL& url,
      Profile* profile);

  // Called when a user clicks to report an unwarned notification as spam.
  virtual void ReportUnwarnedNotificationAsSpam(
      const std::string& notification_id,
      const GURL& url,
      Profile* profile);
};

#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_HANDLER_H_