[Tizen] Add WebView's JavascriptMessageHandler callback 46/315746/1 accepted/tizen_8.0_unified tizen_8.0 accepted/tizen/8.0/unified/20240809.180215
authordongsug.song <dongsug.song@samsung.com>
Wed, 7 Aug 2024 06:29:18 +0000 (15:29 +0900)
committerdongsug.song <dongsug.song@samsung.com>
Wed, 7 Aug 2024 06:31:16 +0000 (15:31 +0900)
- JavascriptMessageHandler callback which has two arguments of msg name and body

Change-Id: Ia2a430044375e86623664948a1e31fabff9d4155

dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp
dali-extension/web-engine-chromium/tizen-web-engine-chromium.h
dali-extension/web-engine-lwe/tizen-web-engine-lwe.cpp
dali-extension/web-engine-lwe/tizen-web-engine-lwe.h

index 1d80d0d..6ee4642 100644 (file)
@@ -408,6 +408,12 @@ void TizenWebEngineChromium::AddJavaScriptMessageHandler(const std::string& expo
   ewk_view_javascript_message_handler_add(mWebView, &TizenWebEngineChromium::OnJavaScriptInjected, exposedObjectName.c_str());
 }
 
+void TizenWebEngineChromium::AddJavaScriptEntireMessageHandler(const std::string& exposedObjectName, JavaScriptEntireMessageHandlerCallback handler)
+{
+  mJavaScriptEntireMessageReceivedCallback = handler;
+  ewk_view_javascript_message_handler_add(mWebView, &TizenWebEngineChromium::OnJavaScriptEntireMessageReceived, exposedObjectName.c_str());
+}
+
 void TizenWebEngineChromium::RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback)
 {
   mJavaScriptAlertCallback = callback;
@@ -1278,6 +1284,22 @@ void TizenWebEngineChromium::OnJavaScriptInjected(Evas_Object* o, Ewk_Script_Mes
   }
 }
 
+void TizenWebEngineChromium::OnJavaScriptEntireMessageReceived(Evas_Object* o, Ewk_Script_Message message)
+{
+  auto plugin = WebEngineManager::Get().Find(o);
+  if(plugin)
+  {
+    auto        pThis       = static_cast<TizenWebEngineChromium*>(plugin);
+    std::string messageName = static_cast<const char*>(message.name);
+    std::string messageBody;
+    if(message.body != nullptr)
+    {
+      messageBody = static_cast<char*>(message.body);
+    }
+    ExecuteCallback(pThis->mJavaScriptEntireMessageReceivedCallback, messageName, messageBody);
+  }
+}
+
 Eina_Bool TizenWebEngineChromium::OnJavaScriptAlert(Evas_Object* o, const char* alert_text, void* data)
 {
   auto        pThis = static_cast<TizenWebEngineChromium*>(data);
index 97dbeed..794380d 100644 (file)
@@ -243,6 +243,11 @@ public:
   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) override;
 
   /**
+   * @copydoc Dali::WebEnginePlugin::AddJavaScriptEntireMessageHandler()
+   */
+  void AddJavaScriptEntireMessageHandler(const std::string& exposedObjectName, JavaScriptEntireMessageHandlerCallback handler) override;
+
+  /**
    * @copydoc Dali::WebEnginePlugin::RegisterJavaScriptAlertCallback()
    */
   void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) override;
@@ -601,6 +606,7 @@ private:
   static void OnAuthenticationChallenged(Evas_Object*, Ewk_Auth_Challenge* authChallenge, void* data);
   static void OnJavaScriptEvaluated(Evas_Object* o, const char* result, void* data);
   static void OnJavaScriptInjected(Evas_Object* o, Ewk_Script_Message message);
+  static void OnJavaScriptEntireMessageReceived(Evas_Object* o, Ewk_Script_Message message);
   static Eina_Bool OnJavaScriptAlert(Evas_Object* o, const char* alert_text, void*);
   static Eina_Bool OnJavaScriptConfirm(Evas_Object* o, const char* message, void*);
   static Eina_Bool OnJavaScriptPrompt(Evas_Object* o, const char* message, const char* default_value, void*);
@@ -660,6 +666,7 @@ private:
   GeolocationPermissionCallback            mGeolocationPermissionCallback;
   PlainTextReceivedCallback                mPlainTextReceivedCallback;
   JavaScriptMessageHandlerCallback         mJavaScriptEvaluatedCallback;
+  JavaScriptEntireMessageHandlerCallback   mJavaScriptEntireMessageReceivedCallback;
 };
 } // namespace Plugin
 } // namespace Dali
index 8eb9eae..c097b27 100755 (executable)
@@ -932,6 +932,11 @@ void TizenWebEngineLWE::AddJavaScriptMessageHandler(const std::string& exposedOb
   });
 }
 
+void TizenWebEngineLWE::AddJavaScriptEntireMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptEntireMessageHandlerCallback handler)
+{
+  // NOT IMPLEMENTED
+}
+
 void TizenWebEngineLWE::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
 {
   // NOT IMPLEMENTED
index 2ea1be5..23f5414 100755 (executable)
@@ -249,6 +249,11 @@ public:
   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) override;
 
   /**
+   * @copydoc Dali::WebEnginePlugin::AddJavaScriptEntireMessageHandler()
+   */
+  void AddJavaScriptEntireMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptEntireMessageHandlerCallback handler) override;
+
+  /**
    * @copydoc Dali::WebEnginePlugin::RegisterJavaScriptAlertCallback()
    */
   void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback) override;