BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(ecore)
+BuildRequires: pkgconfig(notification)
BuildRequires: boost-devel
%if %{with x}
BuildRequires: pkgconfig(ecore-x)
efl-assist
deviced
ecore
+ notification
REQUIRED
)
${BASE_SRCDIR}/runtime/web_view_impl.cc
${BASE_SRCDIR}/runtime/vibration_manager.cc
${BASE_SRCDIR}/runtime/app_db.cc
+ ${BASE_SRCDIR}/runtime/notification_manager.cc
)
# Compiler Flags
--- /dev/null
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "runtime/notification_manager.h"
+
+#include <notification.h>
+#include <memory>
+
+#include "common/logger.h"
+
+namespace wrt {
+
+NotificationManager* NotificationManager::GetInstance() {
+ static NotificationManager instance;
+ return &instance;
+}
+
+NotificationManager::NotificationManager() {
+}
+
+bool NotificationManager::Show(uint64_t tag,
+ const std::string& title,
+ const std::string& body,
+ const std::string& icon_path) {
+ auto found = keymapper_.find(tag);
+ if (found != keymapper_.end()) {
+ Hide(tag);
+ }
+
+ notification_h noti_h = NULL;
+ int ret = NOTIFICATION_ERROR_NONE;
+ noti_h = notification_new(
+ NOTIFICATION_TYPE_NOTI,
+ NOTIFICATION_GROUP_ID_DEFAULT,
+ NOTIFICATION_PRIV_ID_NONE);
+ if (noti_h == NULL) {
+ LOGGER(ERROR) << "Can't create notification handle";
+ return false;
+ }
+
+ std::unique_ptr<std::remove_pointer<notification_h>::type,
+ decltype(notification_free)*>
+ auto_release {noti_h, notification_free};
+
+ // set notification title
+ ret = notification_set_text(
+ noti_h,
+ NOTIFICATION_TEXT_TYPE_TITLE,
+ title.c_str(),
+ NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ LOGGER(ERROR) << "Can't set title";
+ return false;
+ }
+
+ // set notification content
+ ret = notification_set_text(
+ noti_h,
+ NOTIFICATION_TEXT_TYPE_CONTENT,
+ body.c_str(),
+ NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ LOGGER(ERROR) << "Can't set content";
+ return false;
+ }
+
+ if (!icon_path.empty()) {
+ ret = notification_set_image(
+ noti_h,
+ NOTIFICATION_IMAGE_TYPE_ICON,
+ icon_path.c_str());
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ LOGGER(ERROR) << "Can't set icon";
+ return false;
+ }
+ }
+
+ // insert notification
+ int platform_key = NOTIFICATION_PRIV_ID_NONE;
+ ret = notification_insert(noti_h, &platform_key);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ LOGGER(ERROR) << "Can't insert notification";
+ return false;
+ }
+ keymapper_[tag] = platform_key;
+ return true;
+}
+
+bool NotificationManager::Hide(uint64_t tag) {
+ auto found = keymapper_.find(tag);
+ if (found == keymapper_.end()) {
+ LOGGER(ERROR) << "Can't find notification";
+ return false;
+ }
+ notification_delete_by_priv_id(NULL,
+ NOTIFICATION_TYPE_NOTI,
+ found->second);
+ keymapper_.erase(found);
+ return true;
+}
+
+
+} // namespace wrt
--- /dev/null
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WRT_RUNTIME_NOTIFICATION_MANAGER_H_
+#define WRT_RUNTIME_NOTIFICATION_MANAGER_H_
+
+#include <string>
+#include <map>
+
+namespace wrt {
+class NotificationManager {
+ public:
+ static NotificationManager* GetInstance();
+ bool Show(uint64_t tag,
+ const std::string& title,
+ const std::string& body,
+ const std::string& icon_path);
+ bool Hide(uint64_t tag);
+ private:
+ NotificationManager();
+ std::map<uint64_t, int> keymapper_;
+};
+} // namespace wrt
+
+#endif // WRT_RUNTIME_NOTIFICATION_MANAGER_H_
#include "common/application_data.h"
#include "common/resource_manager.h"
#include "runtime/app_db.h"
+#include "runtime/notification_manager.h"
namespace wrt {
"http://tizen.org/privilege/location";
const char* kStoragePrivilege =
"http://tizen.org/privilege/unlimitedstorage";
+const char* kNotiIconFile = "noti_icon.png";
const char* kVisibilitySuspendFeature = "visibility,suspend";
const char* kMediastreamRecordFeature = "mediastream,record";
request.LaunchRequest();
}
+static void InitializeNotificationCallback(Ewk_Context* ewk_context,
+ WebApplication* app) {
+ auto show = [](Ewk_Context*,
+ Ewk_Notification* noti,
+ void* user_data) {
+ WebApplication* self = static_cast<WebApplication*>(user_data);
+ if (self == NULL)
+ return;
+ uint64_t id = ewk_notification_id_get(noti);
+ std::string title(ewk_notification_title_get(noti) ?
+ ewk_notification_title_get(noti) : "");
+ std::string body(ewk_notification_body_get(noti) ?
+ ewk_notification_body_get(noti) : "");
+ std::string icon_path = self->data_path() + "/" + kNotiIconFile;
+ if (!ewk_notification_icon_save_as_png(noti, icon_path.c_str())) {
+ icon_path = "";
+ }
+ if (NotificationManager::GetInstance()->Show(id, title, body, icon_path))
+ ewk_notification_showed(id);
+ };
+ auto hide = [](Ewk_Context*,
+ uint64_t noti_id,
+ void *) {
+ NotificationManager::GetInstance()->Hide(noti_id);
+ ewk_notification_closed(noti_id, EINA_FALSE);
+ };
+ ewk_context_notification_callbacks_set(ewk_context,
+ show,
+ hide,
+ app);
+}
+
} // namespace
WebApplication::WebApplication(
ewk_context_did_start_download_callback_set(ewk_context_,
download_callback,
this);
+ InitializeNotificationCallback(ewk_context_, this);
if (FindPrivilege(app_data_.get(), kFullscreenPrivilege)) {
ewk_context_tizen_extensible_api_string_set(ewk_context_,