Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / notifications / notification_ui_manager_android.h
blob6c2e02469e38e35f5b502773226e7e645f22f64c
1 // 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.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
8 #include <jni.h>
9 #include <map>
10 #include <string>
12 #include "base/android/scoped_java_ref.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
15 // Implementation of the Notification UI Manager for Android, which defers to
16 // the Android framework for displaying notifications.
18 // Android does not support getting the notifications currently shown by an
19 // app without very intrusive permissions, which means that it's not possible
20 // to provide reliable implementations for methods which have to iterate over
21 // the existing notifications. Because of this, these have not been implemented.
23 // The UI manager implementation *is* reliable for adding and canceling single
24 // notifications based on their delegate id. Finally, events for persistent Web
25 // Notifications will be forwarded directly to the associated event handlers,
26 // as such notifications may outlive the browser process on Android.
27 class NotificationUIManagerAndroid : public NotificationUIManager {
28 public:
29 NotificationUIManagerAndroid();
30 ~NotificationUIManagerAndroid() override;
32 // Called by the Java implementation when the notification has been clicked.
33 bool OnNotificationClicked(JNIEnv* env,
34 jobject java_object,
35 jlong persistent_notification_id,
36 jstring java_origin,
37 jstring java_tag,
38 jint action_index);
40 // Called by the Java implementation when the notification has been closed.
41 bool OnNotificationClosed(JNIEnv* env,
42 jobject java_object,
43 jlong persistent_notification_id,
44 jstring java_origin,
45 jstring java_tag);
47 // NotificationUIManager implementation.
48 void Add(const Notification& notification, Profile* profile) override;
49 bool Update(const Notification& notification,
50 Profile* profile) override;
51 const Notification* FindById(const std::string& delegate_id,
52 ProfileID profile_id) const override;
53 bool CancelById(const std::string& delegate_id,
54 ProfileID profile_id) override;
55 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
56 ProfileID profile_id,
57 const GURL& source) override;
58 std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) override;
59 bool CancelAllBySourceOrigin(const GURL& source_origin) override;
60 bool CancelAllByProfile(ProfileID profile_id) override;
61 void CancelAll() override;
63 static bool RegisterNotificationUIManager(JNIEnv* env);
65 private:
66 // Pair containing the information necessary in order to enable closing
67 // notifications that were not created by this instance of the manager: the
68 // notification's origin and tag. This list may not contain the notifications
69 // that have not been interacted with since the last restart of Chrome.
70 using RegeneratedNotificationInfo = std::pair<std::string, std::string>;
72 // Mapping of a persistent notification id to renegerated notification info.
73 // TODO(peter): Remove this map once notification delegate ids for Web
74 // notifications are created by the content/ layer.
75 std::map<int64_t, RegeneratedNotificationInfo>
76 regenerated_notification_infos_;
78 base::android::ScopedJavaGlobalRef<jobject> java_object_;
80 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid);
83 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_