Add APIs to show javascript popup in web engine.
[platform/core/uifw/dali-adaptor.git] / dali / internal / web-engine / common / web-engine-impl.cpp
index c058c63..e4f54ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/internal/web-engine/common/web-engine-impl.h>
 
 // EXTERNAL INCLUDES
-#include <dlfcn.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/object/type-registry.h>
+#include <dlfcn.h>
 #include <sstream>
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/environment-variable.h>
+#include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
+#include <dali/devel-api/adaptor-framework/web-engine-context.h>
+#include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
+#include <dali/devel-api/adaptor-framework/web-engine-settings.h>
 #include <dali/internal/system/common/environment-variables.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali/public-api/images/pixel-data.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace Adaptor
 {
-
 namespace // unnamed namespace
 {
-
-constexpr char const * const kPluginFullNamePrefix = "libdali2-web-engine-";
-constexpr char const * const kPluginFullNamePostfix = "-plugin.so";
-constexpr char const * const kPluginFullNameDefault = "libdali2-web-engine-plugin.so";
+constexpr char const* const kPluginFullNamePrefix  = "libdali2-web-engine-";
+constexpr char const* const kPluginFullNamePostfix = "-plugin.so";
+constexpr char const* const kPluginFullNameDefault = "libdali2-web-engine-plugin.so";
 
 // Note: Dali WebView policy does not allow to use multiple web engines in an application.
 // So once pluginName is set to non-empty string, it will not change.
 std::string pluginName;
 
-std::string MakePluginName( const char* environmentName )
+std::string MakePluginName(const char* environmentName)
 {
   std::stringstream fullName;
   fullName << kPluginFullNamePrefix << environmentName << kPluginFullNamePostfix;
-  return std::move( fullName.str() );
+  return std::move(fullName.str());
 }
 
 Dali::BaseHandle Create()
@@ -61,7 +62,7 @@ Dali::BaseHandle Create()
   return Dali::WebEngine::New();
 }
 
-Dali::TypeRegistration type( typeid( Dali::WebEngine ), typeid( Dali::BaseHandle ), Create );
+Dali::TypeRegistration type(typeid(Dali::WebEngine), typeid(Dali::BaseHandle), Create);
 
 } // unnamed namespace
 
@@ -69,7 +70,7 @@ WebEnginePtr WebEngine::New()
 {
   WebEngine* instance = new WebEngine();
 
-  if( !instance->Initialize() )
+  if(!instance->Initialize())
   {
     delete instance;
     return nullptr;
@@ -79,49 +80,49 @@ WebEnginePtr WebEngine::New()
 }
 
 WebEngine::WebEngine()
-: mPlugin( NULL ),
-  mHandle( NULL ),
-  mCreateWebEnginePtr( NULL ),
-  mDestroyWebEnginePtr( NULL )
+: mPlugin(NULL),
+  mHandle(NULL),
+  mCreateWebEnginePtr(NULL),
+  mDestroyWebEnginePtr(NULL)
 {
 }
 
 WebEngine::~WebEngine()
 {
-  if( mHandle != NULL )
+  if(mHandle != NULL)
   {
-    if( mDestroyWebEnginePtr != NULL )
+    if(mDestroyWebEnginePtr != NULL)
     {
       mPlugin->Destroy();
-      mDestroyWebEnginePtr( mPlugin );
+      mDestroyWebEnginePtr(mPlugin);
     }
 
-    dlclose( mHandle );
+    dlclose(mHandle);
   }
 }
 
 bool WebEngine::InitializePluginHandle()
 {
-  if( pluginName.length() == 0 )
+  if(pluginName.length() == 0)
   {
     // pluginName is not initialized yet.
-    const char* name = EnvironmentVariable::GetEnvironmentVariable( DALI_ENV_WEB_ENGINE_NAME );
-    if( name )
+    const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME);
+    if(name)
     {
-      pluginName = MakePluginName( name );
-      mHandle = dlopen( pluginName.c_str(), RTLD_LAZY );
-      if( mHandle )
+      pluginName = MakePluginName(name);
+      mHandle    = dlopen(pluginName.c_str(), RTLD_LAZY);
+      if(mHandle)
       {
         return true;
       }
     }
-    pluginName = std::string( kPluginFullNameDefault );
+    pluginName = std::string(kPluginFullNameDefault);
   }
 
-  mHandle = dlopen( pluginName.c_str(), RTLD_LAZY );
-  if( !mHandle )
+  mHandle = dlopen(pluginName.c_str(), RTLD_LAZY);
+  if(!mHandle)
   {
-    DALI_LOG_ERROR( "Can't load %s : %s\n", pluginName.c_str(), dlerror() );
+    DALI_LOG_ERROR("Can't load %s : %s\n", pluginName.c_str(), dlerror());
     return false;
   }
 
@@ -132,40 +133,45 @@ bool WebEngine::Initialize()
 {
   char* error = NULL;
 
-  if( !InitializePluginHandle() )
+  if(!InitializePluginHandle())
   {
     return false;
   }
 
-  mCreateWebEnginePtr = reinterpret_cast< CreateWebEngineFunction >( dlsym( mHandle, "CreateWebEnginePlugin" ) );
-  if( mCreateWebEnginePtr == NULL )
+  mCreateWebEnginePtr = reinterpret_cast<CreateWebEngineFunction>(dlsym(mHandle, "CreateWebEnginePlugin"));
+  if(mCreateWebEnginePtr == NULL)
   {
-    DALI_LOG_ERROR( "Can't load symbol CreateWebEnginePlugin(), error: %s\n", error );
+    DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", error);
     return false;
   }
 
-  mDestroyWebEnginePtr = reinterpret_cast< DestroyWebEngineFunction >( dlsym( mHandle, "DestroyWebEnginePlugin" ) );
+  mDestroyWebEnginePtr = reinterpret_cast<DestroyWebEngineFunction>(dlsym(mHandle, "DestroyWebEnginePlugin"));
 
-  if( mDestroyWebEnginePtr == NULL )
+  if(mDestroyWebEnginePtr == NULL)
   {
-    DALI_LOG_ERROR( "Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error );
+    DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error);
     return false;
   }
 
   mPlugin = mCreateWebEnginePtr();
 
-  if( mPlugin == NULL )
+  if(mPlugin == NULL)
   {
-    DALI_LOG_ERROR( "Can't create the WebEnginePlugin object\n" );
+    DALI_LOG_ERROR("Can't create the WebEnginePlugin object\n");
     return false;
   }
 
   return true;
 }
 
-void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
+void WebEngine::Create(int width, int height, const std::string& locale, const std::string& timezoneId)
+{
+  mPlugin->Create(width, height, locale, timezoneId);
+}
+
+void WebEngine::Create(int width, int height, int argc, char** argv)
 {
-  mPlugin->Create( width, height, locale, timezoneId );
+  mPlugin->Create(width, height, argc, argv);
 }
 
 void WebEngine::Destroy()
@@ -178,9 +184,39 @@ Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource()
   return mPlugin->GetNativeImageSource();
 }
 
+Dali::WebEngineSettings& WebEngine::GetSettings() const
+{
+  return mPlugin->GetSettings();
+}
+
+Dali::WebEngineContext& WebEngine::GetContext() const
+{
+  return mPlugin->GetContext();
+}
+
+Dali::WebEngineCookieManager& WebEngine::GetCookieManager() const
+{
+  return mPlugin->GetCookieManager();
+}
+
+Dali::WebEngineBackForwardList& WebEngine::GetBackForwardList() const
+{
+  return mPlugin->GetBackForwardList();
+}
+
 void WebEngine::LoadUrl( const std::string& url )
 {
-  mPlugin->LoadUrl( url );
+  mPlugin->LoadUrl(url);
+}
+
+std::string WebEngine::GetTitle() const
+{
+  return mPlugin->GetTitle();
+}
+
+Dali::PixelData WebEngine::GetFavicon() const
+{
+  return mPlugin->GetFavicon();
 }
 
 const std::string& WebEngine::GetUrl()
@@ -188,9 +224,19 @@ const std::string& WebEngine::GetUrl()
   return mPlugin->GetUrl();
 }
 
-void WebEngine::LoadHTMLString( const std::string& htmlString )
+const std::string& WebEngine::GetUserAgent() const
+{
+  return mPlugin->GetUserAgent();
+}
+
+void WebEngine::SetUserAgent(const std::string& userAgent)
 {
-  mPlugin->LoadHTMLString( htmlString );
+  mPlugin->SetUserAgent(userAgent);
+}
+
+void WebEngine::LoadHtmlString(const std::string& htmlString)
+{
+  mPlugin->LoadHtmlString(htmlString);
 }
 
 void WebEngine::Reload()
@@ -213,139 +259,139 @@ void WebEngine::Resume()
   mPlugin->Resume();
 }
 
-bool WebEngine::CanGoForward()
+void WebEngine::ScrollBy(int deltaX, int deltaY)
 {
-  return mPlugin->CanGoForward();
+  mPlugin->ScrollBy(deltaX, deltaY);
 }
 
-void WebEngine::GoForward()
+void WebEngine::SetScrollPosition(int x, int y)
 {
-  mPlugin->GoForward();
+  mPlugin->SetScrollPosition(x, y);
 }
 
-bool WebEngine::CanGoBack()
+Dali::Vector2 WebEngine::GetScrollPosition() const
 {
-  return mPlugin->CanGoBack();
+  return mPlugin->GetScrollPosition();
 }
 
-void WebEngine::GoBack()
+Dali::Vector2 WebEngine::GetScrollSize() const
 {
-  mPlugin->GoBack();
+  return mPlugin->GetScrollSize();
 }
 
-void WebEngine::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
+Dali::Vector2 WebEngine::GetContentSize() const
 {
-  mPlugin->EvaluateJavaScript( script, resultHandler );
+  return mPlugin->GetContentSize();
 }
 
-void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler )
+void WebEngine::RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
 {
-  mPlugin->AddJavaScriptMessageHandler( exposedObjectName, handler );
+  mPlugin->RegisterJavaScriptAlertCallback( callback );
 }
 
-void WebEngine::ClearHistory()
+void WebEngine::JavaScriptAlertReply()
 {
-  mPlugin->ClearHistory();
+  mPlugin->JavaScriptAlertReply();
 }
 
-void WebEngine::ClearCache()
+void WebEngine::RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
 {
-  mPlugin->ClearCache();
+  mPlugin->RegisterJavaScriptAlertCallback( callback );
 }
 
-void WebEngine::ClearCookies()
+void WebEngine::JavaScriptConfirmReply( bool confirmed )
 {
-  mPlugin->ClearCookies();
+  mPlugin->JavaScriptConfirmReply( confirmed );
 }
 
-Dali::WebEnginePlugin::CacheModel WebEngine::GetCacheModel() const
+void WebEngine::RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
 {
-  return mPlugin->GetCacheModel();
+  mPlugin->RegisterJavaScriptPromptCallback( callback );
 }
 
-void WebEngine::SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel )
+void WebEngine::JavaScriptPromptReply( const std::string& result )
 {
-  mPlugin->SetCacheModel( cacheModel );
+  mPlugin->JavaScriptPromptReply( result );
 }
 
-Dali::WebEnginePlugin::CookieAcceptPolicy WebEngine::GetCookieAcceptPolicy() const
+bool WebEngine::CanGoForward()
 {
-  return mPlugin->GetCookieAcceptPolicy();
+  return mPlugin->CanGoForward();
 }
 
-void WebEngine::SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy )
+void WebEngine::GoForward()
 {
-  mPlugin->SetCookieAcceptPolicy( policy );
+  mPlugin->GoForward();
 }
 
-const std::string& WebEngine::GetUserAgent() const
+bool WebEngine::CanGoBack()
 {
-  return mPlugin->GetUserAgent();
+  return mPlugin->CanGoBack();
 }
 
-void WebEngine::SetUserAgent( const std::string& userAgent )
+void WebEngine::GoBack()
 {
-  mPlugin->SetUserAgent( userAgent );
+  mPlugin->GoBack();
 }
 
-bool WebEngine::IsJavaScriptEnabled() const
+void WebEngine::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
 {
-  return mPlugin->IsJavaScriptEnabled();
+  mPlugin->EvaluateJavaScript(script, resultHandler);
 }
 
-void WebEngine::EnableJavaScript( bool enabled )
+void WebEngine::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
 {
-  mPlugin->EnableJavaScript( enabled );
+  mPlugin->AddJavaScriptMessageHandler(exposedObjectName, handler);
 }
 
-bool WebEngine::AreImagesAutomaticallyLoaded() const
+void WebEngine::ClearAllTilesResources()
 {
-  return mPlugin->AreImagesAutomaticallyLoaded();
+  mPlugin->ClearAllTilesResources();
 }
 
-void WebEngine::LoadImagesAutomatically( bool automatic )
+void WebEngine::ClearHistory()
 {
-  mPlugin->LoadImagesAutomatically( automatic );
+  mPlugin->ClearHistory();
 }
 
-const std::string& WebEngine::GetDefaultTextEncodingName() const
+void WebEngine::SetSize(int width, int height)
 {
-  return mPlugin->GetDefaultTextEncodingName();
+  mPlugin->SetSize(width, height);
 }
 
-void WebEngine::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName )
+bool WebEngine::SendTouchEvent(const Dali::TouchEvent& touch)
 {
-  mPlugin->SetDefaultTextEncodingName( defaultTextEncodingName );
+  return mPlugin->SendTouchEvent(touch);
 }
 
-int WebEngine::GetDefaultFontSize() const
+bool WebEngine::SendKeyEvent(const Dali::KeyEvent& event)
 {
-  return mPlugin->GetDefaultFontSize();
+  return mPlugin->SendKeyEvent(event);
 }
 
-void WebEngine::SetDefaultFontSize( int defaultFontSize )
+void WebEngine::SetFocus(bool focused)
 {
-  mPlugin->SetDefaultFontSize( defaultFontSize );
+  mPlugin->SetFocus(focused);
 }
 
-void WebEngine::SetSize( int width, int height )
+void WebEngine::UpdateDisplayArea(Dali::Rect<int> displayArea)
 {
-  mPlugin->SetSize( width, height );
+  mPlugin->UpdateDisplayArea(displayArea);
 }
 
-bool WebEngine::SendTouchEvent( const Dali::TouchEvent& touch )
+void WebEngine::EnableVideoHole(bool enabled)
 {
-  return mPlugin->SendTouchEvent( touch );
+  mPlugin->EnableVideoHole(enabled);
 }
 
-bool WebEngine::SendKeyEvent( const Dali::KeyEvent& event )
+Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
 {
-  return mPlugin->SendKeyEvent( event );
+  return mPlugin->PageLoadStartedSignal();
 }
 
-Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
+Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadInProgressSignal()
 {
-  return mPlugin->PageLoadStartedSignal();
+  return mPlugin->PageLoadInProgressSignal();
 }
 
 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal()
@@ -358,6 +404,16 @@ Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& WebEngine::PageLoadErro
   return mPlugin->PageLoadErrorSignal();
 }
 
+Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& WebEngine::ScrollEdgeReachedSignal()
+{
+  return mPlugin->ScrollEdgeReachedSignal();
+}
+
+Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& WebEngine::UrlChangedSignal()
+{
+  return mPlugin->UrlChangedSignal();
+}
+
 } // namespace Adaptor;
 } // namespace Internal;
 } // namespace Dali;