Chromium Code Reviews| 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_bridge.h" |
| 16 | 17 |
| 17 // Implementation of the Notification UI Manager for Android, which defers to | 18 // Implementation of the NotificationBridge 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 // Android does not support getting the notifications currently shown by an |
| 21 // app without very intrusive permissions, which means that it's not possible | 22 // app without very intrusive permissions, which means that it's not possible |
| 22 // to provide reliable implementations for methods which have to iterate over | 23 // to provide reliable implementations for methods which have to iterate over |
| 23 // the existing notifications. Because of this, these have not been implemented. | 24 // the existing notifications. Because of this, they return false. |
|
Peter Beverloo
2016/04/18 14:57:10
Let's rephrase this entire paragraph, since it's n
Miguel Garcia
2016/04/19 14:24:57
Done.
| |
| 24 // | 25 // |
| 25 // The UI manager implementation *is* reliable for adding and canceling single | 26 // The Android implementation *is* reliable for adding and canceling |
| 26 // notifications based on their delegate id. Finally, events for persistent Web | 27 // single notifications based on their delegate id. Finally, events for |
| 27 // Notifications will be forwarded directly to the associated event handlers, | 28 // persistent |
|
Peter Beverloo
2016/04/18 14:57:10
nit: odd line break
Miguel Garcia
2016/04/19 14:24:57
Done.
| |
| 29 // Web Notifications will be forwarded directly to the associated event | |
| 30 // handlers, | |
| 28 // as such notifications may outlive the browser process on Android. | 31 // as such notifications may outlive the browser process on Android. |
| 29 class NotificationUIManagerAndroid : public NotificationUIManager { | 32 class NotificationUIManagerAndroid : public NotificationBridge { |
| 30 public: | 33 public: |
| 31 NotificationUIManagerAndroid(); | 34 NotificationUIManagerAndroid(); |
| 32 ~NotificationUIManagerAndroid() override; | 35 ~NotificationUIManagerAndroid() override; |
| 33 | 36 |
| 34 // Called by the Java implementation when the notification has been clicked. | 37 // Called by the Java implementation when the notification has been clicked. |
| 35 void OnNotificationClicked( | 38 void OnNotificationClicked( |
| 36 JNIEnv* env, | 39 JNIEnv* env, |
| 37 const base::android::JavaParamRef<jobject>& java_object, | 40 const base::android::JavaParamRef<jobject>& java_object, |
| 38 jlong persistent_notification_id, | 41 jlong persistent_notification_id, |
| 39 const base::android::JavaParamRef<jstring>& java_origin, | 42 const base::android::JavaParamRef<jstring>& java_origin, |
| 40 const base::android::JavaParamRef<jstring>& java_profile_id, | 43 const base::android::JavaParamRef<jstring>& java_profile_id, |
| 41 jboolean incognito, | 44 jboolean incognito, |
| 42 const base::android::JavaParamRef<jstring>& java_tag, | 45 const base::android::JavaParamRef<jstring>& java_tag, |
| 43 jint action_index); | 46 jint action_index); |
| 44 | 47 |
| 45 // Called by the Java implementation when the notification has been closed. | 48 // Called by the Java implementation when the notification has been closed. |
| 46 void OnNotificationClosed( | 49 void OnNotificationClosed( |
| 47 JNIEnv* env, | 50 JNIEnv* env, |
| 48 const base::android::JavaParamRef<jobject>& java_object, | 51 const base::android::JavaParamRef<jobject>& java_object, |
| 49 jlong persistent_notification_id, | 52 jlong persistent_notification_id, |
| 50 const base::android::JavaParamRef<jstring>& java_origin, | 53 const base::android::JavaParamRef<jstring>& java_origin, |
| 51 const base::android::JavaParamRef<jstring>& java_profile_id, | 54 const base::android::JavaParamRef<jstring>& java_profile_id, |
| 52 jboolean incognito, | 55 jboolean incognito, |
| 53 const base::android::JavaParamRef<jstring>& java_tag, | 56 const base::android::JavaParamRef<jstring>& java_tag, |
| 54 jboolean by_user); | 57 jboolean by_user); |
| 55 | 58 |
| 56 // NotificationUIManager implementation. | 59 // NotificationBridge implementation. |
| 57 void Add(const Notification& notification, Profile* profile) override; | 60 void Display(const std::string& notification_id, |
| 58 bool Update(const Notification& notification, | 61 const std::string& profile_id, |
| 59 Profile* profile) override; | 62 bool incognito, |
| 60 const Notification* FindById(const std::string& delegate_id, | 63 const Notification& notification) override; |
| 61 ProfileID profile_id) const override; | 64 void Close(const std::string& profile_id, |
| 62 bool CancelById(const std::string& delegate_id, | 65 const std::string& notification_id) override; |
| 63 ProfileID profile_id) override; | 66 bool GetDisplayed(const std::string& profile_id, |
| 64 std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | 67 bool incognito, |
| 65 ProfileID profile_id, | 68 std::set<std::string>* notifications) const override; |
| 66 const GURL& source) override; | 69 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 | 70 |
| 72 static bool RegisterNotificationUIManager(JNIEnv* env); | 71 static bool RegisterNotificationBridge(JNIEnv* env); |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 // Pair containing the information necessary in order to enable closing | 74 // Pair containing the information necessary in order to enable closing |
| 76 // notifications that were not created by this instance of the manager: the | 75 // 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 | 76 // 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. | 77 // that have not been interacted with since the last restart of Chrome. |
| 79 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; | 78 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; |
| 80 | 79 |
| 81 // Mapping of a persistent notification id to renegerated notification info. | 80 // Mapping of a persistent notification id to renegerated notification info. |
| 82 // TODO(peter): Remove this map once notification delegate ids for Web | 81 // TODO(peter): Remove this map once notification delegate ids for Web |
| 83 // notifications are created by the content/ layer. | 82 // notifications are created by the content/ layer. |
| 84 std::map<int64_t, RegeneratedNotificationInfo> | 83 std::map<int64_t, RegeneratedNotificationInfo> |
| 85 regenerated_notification_infos_; | 84 regenerated_notification_infos_; |
| 86 | 85 |
| 87 base::android::ScopedJavaGlobalRef<jobject> java_object_; | 86 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| 88 | 87 |
| 89 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); | 88 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 91 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
| OLD | NEW |