[Tizen] Add WebView's JavascriptMessageHandler callback
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Tue, 27 Aug 2024 06:43:34 +0000 (15:43 +0900)
committerJaehyun Cho <jae_hyun.cho@samsung.com>
Tue, 27 Aug 2024 06:43:34 +0000 (15:43 +0900)
This reverts commit 7378cf3b2f6baef088aaca23f7f7c82683cc0edf.

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 24c08f8..ce42853 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;