OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <map> | 10 #include <map> |
| 11 #include <set> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_platform_bridge.h" |
16 | 17 |
17 // Implementation of the Notification UI Manager for Android, which defers to | 18 // Implementation of the NotificationPlatformBridge for Android, which defers to |
18 // the Android framework for displaying notifications. | 19 // the Android framework for displaying notifications. |
19 // | 20 // |
20 // Android does not support getting the notifications currently shown by an | 21 // Prior to Android Marshmellow, Android did not have the ability to retrieve |
21 // app without very intrusive permissions, which means that it's not possible | 22 // the notifications currently showing for an app without a rather intrusive |
22 // to provide reliable implementations for methods which have to iterate over | 23 // permission. The GetDisplayed() method may return false because of this. |
23 // the existing notifications. Because of this, these have not been implemented. | |
24 // | 24 // |
25 // The UI manager implementation *is* reliable for adding and canceling single | 25 // The Android implementation *is* reliable for adding and canceling |
26 // notifications based on their delegate id. Finally, events for persistent Web | 26 // single notifications based on their delegate id. Finally, events for |
27 // Notifications will be forwarded directly to the associated event handlers, | 27 // persistent Web Notifications will be forwarded directly to the associated |
28 // as such notifications may outlive the browser process on Android. | 28 // event handlers, as such notifications may outlive the browser process on |
29 class NotificationUIManagerAndroid : public NotificationUIManager { | 29 // Android. |
| 30 class NotificationUIManagerAndroid : public NotificationPlatformBridge { |
30 public: | 31 public: |
31 NotificationUIManagerAndroid(); | 32 NotificationUIManagerAndroid(); |
32 ~NotificationUIManagerAndroid() override; | 33 ~NotificationUIManagerAndroid() override; |
33 | 34 |
34 // Called by the Java implementation when the notification has been clicked. | 35 // Called by the Java implementation when the notification has been clicked. |
35 void OnNotificationClicked( | 36 void OnNotificationClicked( |
36 JNIEnv* env, | 37 JNIEnv* env, |
37 const base::android::JavaParamRef<jobject>& java_object, | 38 const base::android::JavaParamRef<jobject>& java_object, |
38 jlong persistent_notification_id, | 39 jlong persistent_notification_id, |
39 const base::android::JavaParamRef<jstring>& java_origin, | 40 const base::android::JavaParamRef<jstring>& java_origin, |
40 const base::android::JavaParamRef<jstring>& java_profile_id, | 41 const base::android::JavaParamRef<jstring>& java_profile_id, |
41 jboolean incognito, | 42 jboolean incognito, |
42 const base::android::JavaParamRef<jstring>& java_tag, | 43 const base::android::JavaParamRef<jstring>& java_tag, |
43 jint action_index); | 44 jint action_index); |
44 | 45 |
45 // Called by the Java implementation when the notification has been closed. | 46 // Called by the Java implementation when the notification has been closed. |
46 void OnNotificationClosed( | 47 void OnNotificationClosed( |
47 JNIEnv* env, | 48 JNIEnv* env, |
48 const base::android::JavaParamRef<jobject>& java_object, | 49 const base::android::JavaParamRef<jobject>& java_object, |
49 jlong persistent_notification_id, | 50 jlong persistent_notification_id, |
50 const base::android::JavaParamRef<jstring>& java_origin, | 51 const base::android::JavaParamRef<jstring>& java_origin, |
51 const base::android::JavaParamRef<jstring>& java_profile_id, | 52 const base::android::JavaParamRef<jstring>& java_profile_id, |
52 jboolean incognito, | 53 jboolean incognito, |
53 const base::android::JavaParamRef<jstring>& java_tag, | 54 const base::android::JavaParamRef<jstring>& java_tag, |
54 jboolean by_user); | 55 jboolean by_user); |
55 | 56 |
56 // NotificationUIManager implementation. | 57 // NotificationPlatformBridge implementation. |
57 void Add(const Notification& notification, Profile* profile) override; | 58 void Display(const std::string& notification_id, |
58 bool Update(const Notification& notification, | 59 const std::string& profile_id, |
59 Profile* profile) override; | 60 bool incognito, |
60 const Notification* FindById(const std::string& delegate_id, | 61 const Notification& notification) override; |
61 ProfileID profile_id) const override; | 62 void Close(const std::string& profile_id, |
62 bool CancelById(const std::string& delegate_id, | 63 const std::string& notification_id) override; |
63 ProfileID profile_id) override; | 64 bool GetDisplayed(const std::string& profile_id, |
64 std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | 65 bool incognito, |
65 ProfileID profile_id, | 66 std::set<std::string>* notifications) const override; |
66 const GURL& source) override; | 67 bool SupportsNotificationCenter() const override; |
67 std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) override; | |
68 bool CancelAllBySourceOrigin(const GURL& source_origin) override; | |
69 bool CancelAllByProfile(ProfileID profile_id) override; | |
70 void CancelAll() override; | |
71 | 68 |
72 static bool RegisterNotificationUIManager(JNIEnv* env); | 69 static bool RegisterNotificationPlatformBridge(JNIEnv* env); |
73 | 70 |
74 private: | 71 private: |
75 // Pair containing the information necessary in order to enable closing | 72 // Pair containing the information necessary in order to enable closing |
76 // notifications that were not created by this instance of the manager: the | 73 // notifications that were not created by this instance of the manager: the |
77 // notification's origin and tag. This list may not contain the notifications | 74 // notification's origin and tag. This list may not contain the notifications |
78 // that have not been interacted with since the last restart of Chrome. | 75 // that have not been interacted with since the last restart of Chrome. |
79 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; | 76 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; |
80 | 77 |
81 // Mapping of a persistent notification id to renegerated notification info. | 78 // Mapping of a persistent notification id to renegerated notification info. |
82 // TODO(peter): Remove this map once notification delegate ids for Web | 79 // TODO(peter): Remove this map once notification delegate ids for Web |
83 // notifications are created by the content/ layer. | 80 // notifications are created by the content/ layer. |
84 std::map<int64_t, RegeneratedNotificationInfo> | 81 std::map<int64_t, RegeneratedNotificationInfo> |
85 regenerated_notification_infos_; | 82 regenerated_notification_infos_; |
86 | 83 |
87 base::android::ScopedJavaGlobalRef<jobject> java_object_; | 84 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
88 | 85 |
89 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); | 86 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); |
90 }; | 87 }; |
91 | 88 |
92 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 89 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
OLD | NEW |