[Tizen] Set focus for web engine.
[platform/core/uifw/dali-adaptor.git] / dali / internal / web-engine / common / web-engine-impl.cpp
index b727a48..8e2d55d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -41,9 +41,9 @@ namespace Adaptor
 namespace // unnamed namespace
 {
 
-constexpr char const * const kPluginFullNamePrefix = "libdali-web-engine-";
+constexpr char const * const kPluginFullNamePrefix = "libdali2-web-engine-";
 constexpr char const * const kPluginFullNamePostfix = "-plugin.so";
-constexpr char const * const kPluginFullNameDefault = "libdali-web-engine-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.
@@ -67,17 +67,15 @@ Dali::TypeRegistration type( typeid( Dali::WebEngine ), typeid( Dali::BaseHandle
 
 WebEnginePtr WebEngine::New()
 {
-  WebEnginePtr ptr;
-  WebEngine* engine = new WebEngine();
+  WebEngine* instance = new WebEngine();
 
-  if ( !engine->Initialize() )
+  if( !instance->Initialize() )
   {
-    delete engine;
-    engine = nullptr;
+    delete instance;
+    return nullptr;
   }
 
-  ptr = engine;
-  return ptr;
+  return instance;
 }
 
 WebEngine::WebEngine()
@@ -104,15 +102,15 @@ WebEngine::~WebEngine()
 
 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 )
+    if( name )
     {
       pluginName = MakePluginName( name );
       mHandle = dlopen( pluginName.c_str(), RTLD_LAZY );
-      if ( mHandle )
+      if( mHandle )
       {
         return true;
       }
@@ -121,7 +119,7 @@ bool WebEngine::InitializePluginHandle()
   }
 
   mHandle = dlopen( pluginName.c_str(), RTLD_LAZY );
-  if ( !mHandle )
+  if( !mHandle )
   {
     DALI_LOG_ERROR( "Can't load %s : %s\n", pluginName.c_str(), dlerror() );
     return false;
@@ -134,7 +132,7 @@ bool WebEngine::Initialize()
 {
   char* error = NULL;
 
-  if ( !InitializePluginHandle() )
+  if( !InitializePluginHandle() )
   {
     return false;
   }
@@ -146,20 +144,19 @@ bool WebEngine::Initialize()
     return false;
   }
 
-  mPlugin = mCreateWebEnginePtr();
+  mDestroyWebEnginePtr = reinterpret_cast< DestroyWebEngineFunction >( dlsym( mHandle, "DestroyWebEnginePlugin" ) );
 
-  if( mPlugin == NULL )
+  if( mDestroyWebEnginePtr == NULL )
   {
-    DALI_LOG_ERROR( "Can't create the WebEnginePlugin object\n" );
+    DALI_LOG_ERROR( "Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error );
     return false;
   }
 
-  mDestroyWebEnginePtr = reinterpret_cast< DestroyWebEngineFunction >( dlsym( mHandle, "DestroyWebEnginePlugin" ) );
+  mPlugin = mCreateWebEnginePtr();
 
-  if( mDestroyWebEnginePtr == NULL )
+  if( mPlugin == NULL )
   {
-
-    DALI_LOG_ERROR( "Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error );
+    DALI_LOG_ERROR( "Can't create the WebEnginePlugin object\n" );
     return false;
   }
 
@@ -168,18 +165,12 @@ bool WebEngine::Initialize()
 
 void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->Create( width, height, locale, timezoneId );
-  }
+  mPlugin->Create( width, height, locale, timezoneId );
 }
 
 void WebEngine::Destroy()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->Destroy();
-  }
+  mPlugin->Destroy();
 }
 
 Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource()
@@ -189,147 +180,191 @@ Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource()
 
 void WebEngine::LoadUrl( const std::string& url )
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->LoadUrl( url );
-  }
+  mPlugin->LoadUrl( url );
 }
 
 const std::string& WebEngine::GetUrl()
 {
-  static std::string emptyUrl;
-  return mPlugin ? mPlugin->GetUrl() : emptyUrl;
+  return mPlugin->GetUrl();
 }
 
 void WebEngine::LoadHTMLString( const std::string& htmlString )
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->LoadHTMLString( htmlString );
-  }
+  mPlugin->LoadHTMLString( htmlString );
 }
 
 void WebEngine::Reload()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->Reload();
-  }
+  mPlugin->Reload();
 }
 
 void WebEngine::StopLoading()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->StopLoading();
-  }
+  mPlugin->StopLoading();
+}
+
+void WebEngine::Suspend()
+{
+  mPlugin->Suspend();
+}
+
+void WebEngine::Resume()
+{
+  mPlugin->Resume();
 }
 
 bool WebEngine::CanGoForward()
 {
-  return mPlugin ? mPlugin->CanGoForward() : false;
+  return mPlugin->CanGoForward();
 }
 
 void WebEngine::GoForward()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->GoForward();
-  }
+  mPlugin->GoForward();
 }
 
 bool WebEngine::CanGoBack()
 {
-  return mPlugin ? mPlugin->CanGoBack() : false;
+  return mPlugin->CanGoBack();
 }
 
 void WebEngine::GoBack()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->GoBack();
-  }
+  mPlugin->GoBack();
 }
 
-void WebEngine::EvaluateJavaScript( const std::string& script )
+void WebEngine::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->EvaluateJavaScript( script );
-  }
+  mPlugin->EvaluateJavaScript( script, resultHandler );
 }
 
-void WebEngine::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > cb )
+void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler )
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->AddJavaScriptInterface( exposedObjectName, jsFunctionName, cb );
-  }
+  mPlugin->AddJavaScriptMessageHandler( exposedObjectName, handler );
 }
 
-void WebEngine::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
+void WebEngine::ClearHistory()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->RemoveJavascriptInterface( exposedObjectName, jsFunctionName );
-  }
+  mPlugin->ClearHistory();
 }
 
-void WebEngine::ClearHistory()
+void WebEngine::ClearCache()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->ClearHistory();
-  }
+  mPlugin->ClearCache();
 }
 
-void WebEngine::ClearCache()
+void WebEngine::ClearCookies()
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->ClearCache();
-  }
+  mPlugin->ClearCookies();
 }
 
-void WebEngine::SetSize( int width, int height )
+Dali::WebEnginePlugin::CacheModel WebEngine::GetCacheModel() const
 {
-  if( mPlugin != NULL )
-  {
-    mPlugin->SetSize( width, height );
-  }
+  return mPlugin->GetCacheModel();
 }
 
-bool WebEngine::SendTouchEvent( const Dali::TouchData& touch )
+void WebEngine::SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel )
 {
-  if( mPlugin != NULL )
-  {
-    return mPlugin->SendTouchEvent( touch );
-  }
+  mPlugin->SetCacheModel( cacheModel );
+}
+
+Dali::WebEnginePlugin::CookieAcceptPolicy WebEngine::GetCookieAcceptPolicy() const
+{
+  return mPlugin->GetCookieAcceptPolicy();
+}
+
+void WebEngine::SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy )
+{
+  mPlugin->SetCookieAcceptPolicy( policy );
+}
+
+const std::string& WebEngine::GetUserAgent() const
+{
+  return mPlugin->GetUserAgent();
+}
+
+void WebEngine::SetUserAgent( const std::string& userAgent )
+{
+  mPlugin->SetUserAgent( userAgent );
+}
+
+bool WebEngine::IsJavaScriptEnabled() const
+{
+  return mPlugin->IsJavaScriptEnabled();
+}
+
+void WebEngine::EnableJavaScript( bool enabled )
+{
+  mPlugin->EnableJavaScript( enabled );
+}
+
+bool WebEngine::AreImagesAutomaticallyLoaded() const
+{
+  return mPlugin->AreImagesAutomaticallyLoaded();
+}
+
+void WebEngine::LoadImagesAutomatically( bool automatic )
+{
+  mPlugin->LoadImagesAutomatically( automatic );
+}
+
+const std::string& WebEngine::GetDefaultTextEncodingName() const
+{
+  return mPlugin->GetDefaultTextEncodingName();
+}
+
+void WebEngine::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName )
+{
+  mPlugin->SetDefaultTextEncodingName( defaultTextEncodingName );
+}
+
+int WebEngine::GetDefaultFontSize() const
+{
+  return mPlugin->GetDefaultFontSize();
+}
+
+void WebEngine::SetDefaultFontSize( int defaultFontSize )
+{
+  mPlugin->SetDefaultFontSize( defaultFontSize );
+}
 
-  return false;
+void WebEngine::SetSize( int width, int height )
+{
+  mPlugin->SetSize( width, height );
+}
+
+bool WebEngine::SendTouchEvent( const Dali::TouchEvent& touch )
+{
+  return mPlugin->SendTouchEvent( touch );
 }
 
 bool WebEngine::SendKeyEvent( const Dali::KeyEvent& event )
 {
-  if( mPlugin != NULL )
-  {
-    return mPlugin->SendKeyEvent( event );
-  }
+  return mPlugin->SendKeyEvent( event );
+}
 
-  return false;
+void WebEngine::SetFocus( bool focused )
+{
+  mPlugin->SetFocus( focused );
 }
 
-Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadStartedSignal()
+Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
 {
   return mPlugin->PageLoadStartedSignal();
 }
 
-Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadFinishedSignal()
+Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal()
 {
   return mPlugin->PageLoadFinishedSignal();
 }
 
+Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& WebEngine::PageLoadErrorSignal()
+{
+  return mPlugin->PageLoadErrorSignal();
+}
+
 } // namespace Adaptor;
 } // namespace Internal;
 } // namespace Dali;
 
+