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