Implement notification onclick event 22/112122/1
authorYoungsoo Choi <kenshin.choi@samsung.com>
Thu, 26 Jan 2017 06:21:07 +0000 (15:21 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Thu, 26 Jan 2017 06:21:07 +0000 (15:21 +0900)
This CL enables notification onclick event.

Bug: http://suprem.sec.samsung.net/jira/browse/TWF-2866

Change-Id: Iecb07daaacea6d82abc2824cabcc9941c33f70d1
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
runtime/browser/notification_manager.cc
runtime/browser/notification_manager.h [changed mode: 0644->0755]

index aebd6e4..cff02ad 100755 (executable)
@@ -22,6 +22,7 @@
 #include <memory>
 
 #include "common/logger.h"
+#include "EWebKit_internal.h"
 
 namespace runtime {
 
@@ -33,6 +34,26 @@ NotificationManager* NotificationManager::GetInstance() {
 NotificationManager::NotificationManager() {
 }
 
+static void notification_onclick_event_cb(
+    notification_h noti, int event_type, void* userdata) {
+  NotificationManager* thiz =
+    static_cast<NotificationManager*>(userdata);
+  int notification_priv_id = NOTIFICATION_PRIV_ID_NONE;
+  int ret = notification_get_id(noti, nullptr, &notification_priv_id);
+  if (ret != NOTIFICATION_ERROR_NONE)
+    LOGGER(ERROR) << "Can't get notification ID" << ret;
+  ewk_notification_clicked(thiz->FindNotificationID(notification_priv_id));
+}
+
+uint64_t NotificationManager::FindNotificationID(
+    int notification_priv_id) {
+  for (auto it = keymapper_.begin(); it != keymapper_.end(); it++)
+    if (it->second == notification_priv_id)
+      return it->first;
+  LOGGER(ERROR) << "Can't find notification ID" << notification_priv_id;
+  return 0;
+}
+
 bool NotificationManager::Show(uint64_t tag,
                                const std::string& title,
                                const std::string& body,
@@ -93,13 +114,21 @@ bool NotificationManager::Show(uint64_t tag,
   }
 
   // insert notification
-  int platform_key = NOTIFICATION_PRIV_ID_NONE;
-  ret = notification_insert(noti_h, &platform_key);
+  ret = notification_post_with_event_cb(
+      noti_h, notification_onclick_event_cb, this);
+  if (ret != NOTIFICATION_ERROR_NONE) {
+    LOGGER(ERROR) << "Can't insert notification " << ret;
+    return false;
+  }
+
+  int notification_priv_id = NOTIFICATION_PRIV_ID_NONE;
+
+  ret = notification_get_id(noti_h, nullptr, &notification_priv_id);
   if (ret != NOTIFICATION_ERROR_NONE) {
-    LOGGER(ERROR) << "Can't insert notification";
+    LOGGER(ERROR) << "Can't get notification ID" << ret;
     return false;
   }
-  keymapper_[tag] = platform_key;
+  keymapper_[tag] = notification_priv_id;
   return true;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index da93524..da703bc
@@ -30,6 +30,7 @@ class NotificationManager {
             const std::string& body,
             const std::string& icon_path);
   bool Hide(uint64_t tag);
+  uint64_t FindNotificationID(int notification_priv_id);
  private:
   NotificationManager();
   std::map<uint64_t, int> keymapper_;