[M40 Merge] Add Ewk_Context specific notification handling
authorDongJun Kim <djmix.kim@samsung.com>
Sun, 21 Jun 2015 09:23:30 +0000 (18:23 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Below 2 APIs are missed in beta/m42.
So we need to migration from beta/m40
- ewk_context_notification_callbacks_set
- ewk_context_notification_callbacks_reset

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=11367

Original patch: http://web.sec.samsung.net/gerrit/#/c/75818/
Reviewed by: Hyunhak Kim, Karol Furmaniak

Change-Id: I858117f52a5e7ca67ded2b2651cbd23938f8cabb
Signed-off-by: DongJun Kim <djmix.kim@samsung.com>
tizen_src/ewk/efl_integration/browser/notification/notification_controller_efl.cc
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/eweb_context.h
tizen_src/ewk/efl_integration/private/ewk_context_private.cc
tizen_src/ewk/efl_integration/private/ewk_context_private.h
tizen_src/ewk/efl_integration/public/ewk_context.cc
tizen_src/ewk/efl_integration/public/ewk_context.h

index b12a944..cf98d2b 100644 (file)
@@ -99,7 +99,16 @@ void NotificationControllerEfl::DisplayNotification(
     scoped_ptr<DesktopNotificationDelegate> delegate,
     base::Closure* cancel_callback) {
 
-  if (!notification_show_callback_) {
+  BrowserContextEfl* browser_context_efl =
+      static_cast<BrowserContextEfl*>(browser_context);
+  CHECK(browser_context_efl);
+  EWebContext* ctx = browser_context_efl->WebContext();
+  CHECK(ctx);
+
+  bool has_callbacks = ctx->HasNotificationCallbacks()
+      || (notification_show_callback_ && notification_cancel_callback_);
+
+  if (!has_callbacks) {
     delegate->NotificationClosed(false);
     return;
   }
@@ -108,7 +117,10 @@ void NotificationControllerEfl::DisplayNotification(
   if (!notification_data.tag.empty() &&
       IsNotificationPresent(origin,
           base::UTF8ToUTF16(notification_data.tag), replaceUniqueId)) {
-    NotificationCancelled(replaceUniqueId);
+    if (!ctx->NotificationCancelCallback(replaceUniqueId))
+      NotificationCancelled(replaceUniqueId);
+    else
+      NotificationClosed(replaceUniqueId, false);
   }
 
   uint64_t notificationUniqueId = reinterpret_cast<uint64_t>(delegate.get());
@@ -131,7 +143,9 @@ void NotificationControllerEfl::DisplayNotification(
                            notificationUniqueId,
                            origin);
 
-  notification_show_callback_(notification, notification_callback_user_data_);
+  if (!ctx->NotificationShowCallback(notification))
+    notification_show_callback_(notification, notification_callback_user_data_);
+
   delete notification;
 }
 
index a7fe64f..17608e7 100644 (file)
@@ -228,7 +228,10 @@ bool EWebContext::OverrideMimeForURL(const std::string& url_spec,
 EWebContext::EWebContext(bool incognito)
     : m_pixmap(0),
       inspector_server_(NULL),
-      widget_scale_(0) {
+      widget_scale_(0),
+      notification_show_cb_(nullptr),
+      notification_cancel_cb_(nullptr),
+      notification_cb_user_data_(nullptr) {
   CHECK(EwkGlobalData::GetInstance());
 
   browser_context_.reset(new BrowserContextEfl(this, incognito));
@@ -240,7 +243,10 @@ EWebContext::EWebContext(bool incognito)
 EWebContext::EWebContext(const std::string& injectedBundlePath)
     : injected_bundle_path_(injectedBundlePath),
       m_pixmap(0),
-      inspector_server_(NULL) {
+      inspector_server_(NULL),
+      notification_show_cb_(nullptr),
+      notification_cancel_cb_(nullptr),
+      notification_cb_user_data_(nullptr) {
   CHECK(EwkGlobalData::GetInstance());
 
   // WRT does not really care about incognito, so set it to false
@@ -571,3 +577,32 @@ bool EWebContext::InspectorServerStop() {
   inspector_server_ = NULL;
   return true;
 }
+
+void EWebContext::SetNotificationCallbacks(
+    Ewk_Notification_Show_Callback show_callback,
+    Ewk_Notification_Cancel_Callback cancel_callback,
+    void* user_data) {
+  notification_show_cb_ = show_callback;
+  notification_cancel_cb_ = cancel_callback;
+  notification_cb_user_data_ = user_data;
+}
+
+bool EWebContext::HasNotificationCallbacks() const {
+  return notification_show_cb_ && notification_cancel_cb_;
+}
+
+bool EWebContext::NotificationShowCallback(Ewk_Notification* notification) {
+  if (!HasNotificationCallbacks())
+    return false;
+
+  notification_show_cb_(notification, notification_cb_user_data_);
+  return true;
+}
+
+bool EWebContext::NotificationCancelCallback(uint64_t notification_id) {
+  if (!HasNotificationCallbacks())
+    return false;
+
+  notification_cancel_cb_(notification_id, notification_cb_user_data_);
+  return true;
+}
index eaca43d..51763b8 100644 (file)
@@ -9,6 +9,7 @@
 #include "browser/web_cache_efl/web_cache_manager_efl.h"
 #include "private/ewk_cookie_manager_private.h"
 #include "public/ewk_context.h"
+#include "public/ewk_notification.h"
 #include "devtools_delegate_efl.h"
 
 class CookieManager;
@@ -111,6 +112,14 @@ class EWebContext {
   unsigned int InspectorServerStart(unsigned int port);
   bool InspectorServerStop();
 
+  void SetNotificationCallbacks(
+      Ewk_Notification_Show_Callback show_callback,
+      Ewk_Notification_Cancel_Callback cancel_callback,
+      void* user_data);
+  bool HasNotificationCallbacks() const;
+  bool NotificationShowCallback(Ewk_Notification* notification);
+  bool NotificationCancelCallback(uint64_t notification_id);
+
   const std::string& GetInjectedBundlePath() const { return injected_bundle_path_; }
   const std::string& GetTizenId() const { return tizen_id_; }
   const std::string& GetWidgetTheme() const { return widget_theme_; }
@@ -139,6 +148,9 @@ class EWebContext {
   scoped_ptr<EwkMimeOverrideCallback> mime_override_callback_;
   int m_pixmap;
   content::DevToolsDelegateEfl* inspector_server_;
+  Ewk_Notification_Show_Callback notification_show_cb_;
+  Ewk_Notification_Cancel_Callback notification_cancel_cb_;
+  void* notification_cb_user_data_;
 };
 
 #endif
index 89e3e44..40cf351 100644 (file)
@@ -270,3 +270,10 @@ unsigned int Ewk_Context::InspectorServerStart(unsigned int port) const {
 bool Ewk_Context::InspectorServerStop() const {
   return impl->InspectorServerStop();
 }
+
+void Ewk_Context::SetNotificationCallbacks(
+    Ewk_Notification_Show_Callback show_callback,
+    Ewk_Notification_Cancel_Callback cancel_callback,
+    void* user_data) {
+  impl->SetNotificationCallbacks(show_callback, cancel_callback, user_data);
+}
\ No newline at end of file
index 6ee6f38..622dbe7 100644 (file)
@@ -126,6 +126,11 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
   unsigned int InspectorServerStart(unsigned int port) const;
   bool InspectorServerStop() const;
 
+  void SetNotificationCallbacks(
+    Ewk_Notification_Show_Callback show_callback,
+    Ewk_Notification_Cancel_Callback cancel_callback,
+    void* user_data);
+
  private:
   EWebContext* impl;
 
index 4e04356..04ed182 100644 (file)
@@ -591,10 +591,24 @@ Eina_Bool ewk_context_notification_callbacks_set(Ewk_Context* context,
     Ewk_Context_Notification_Show_Callback show_callback,
     Ewk_Context_Notification_Cancel_Callback cancel_callback, void* user_data)
 {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(show_callback, EINA_FALSE);
+  EINA_SAFETY_ON_NULL_RETURN_VAL(cancel_callback, EINA_FALSE);
+
+  Ewk_Notification_Show_Callback scb =
+      reinterpret_cast<Ewk_Notification_Show_Callback>(show_callback);
+
+  Ewk_Notification_Cancel_Callback ccb =
+      reinterpret_cast<Ewk_Notification_Cancel_Callback>(cancel_callback);
+
+  context->SetNotificationCallbacks(scb, ccb, user_data);
   return EINA_TRUE;
 }
 
 Eina_Bool ewk_context_notification_callbacks_reset(Ewk_Context* context)
 {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
+
+  context->SetNotificationCallbacks(nullptr, nullptr, nullptr);
   return EINA_TRUE;
 }
index 5297cb1..65cc529 100644 (file)
@@ -45,10 +45,8 @@ typedef enum Ewk_Extensible_API Ewk_Extensible_API;
 typedef struct Ewk_Context Ewk_Context;
 typedef struct Ewk_Context_Exceeded_Quota Ewk_Context_Exceeded_Quota;
 
-typedef void (*Ewk_Context_Notification_Show_Callback)(Ewk_Context*,
-    Ewk_Notification*, void*);
-typedef void (*Ewk_Context_Notification_Cancel_Callback)(Ewk_Context*,
-    uint64_t, void*);
+typedef void (*Ewk_Context_Notification_Show_Callback)(Ewk_Notification*, void*);
+typedef void (*Ewk_Context_Notification_Cancel_Callback)(uint64_t, void*);
 
 /**
  * Deletes Ewk_Context.