// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/environment-variable.h>
+#include <dali/devel-api/adaptor-framework/lifecycle-controller.h>
#include <dali/devel-api/adaptor-framework/web-engine/web-engine-back-forward-list.h>
#include <dali/devel-api/adaptor-framework/web-engine/web-engine-certificate.h>
#include <dali/devel-api/adaptor-framework/web-engine/web-engine-console-message.h>
/**
* @brief Control the WebEnginePlugin library lifecycle.
- * Hold the plugin library handle in static singletone.
- * It will makes library handle alives during all WebEngine resources create & destory.
*/
struct WebEnginePluginObject
{
public:
- static WebEnginePluginObject& GetInstance()
- {
- static WebEnginePluginObject gPluginHandle;
- return gPluginHandle;
- }
-
- /**
- * @brief Converts an handle to a bool.
- *
- * This is useful for checking whether the WebEnginePluginObject succes to load library.
- * @note We don't check mHandle because it is possible that mHandle load is success but
- * Create/Destroy API load failed.
- */
- explicit operator bool() const
+ WebEnginePluginObject()
+ : mPluginName{},
+ mHandle{nullptr},
+ mCreateWebEnginePtr{nullptr},
+ mDestroyWebEnginePtr{nullptr},
+ mGetWebEngineContextPtr{nullptr},
+ mGetWebEngineCookieManagerPtr{nullptr}
{
- return mLoadSuccess;
}
- bool InitializeContextHandle()
+ ~WebEnginePluginObject()
{
- if(!mHandle)
- {
- return false;
- }
-
- if(!mGetWebEngineContextPtr)
+ if(mHandle)
{
- mGetWebEngineContextPtr = reinterpret_cast<GetWebEngineContext>(dlsym(mHandle, "GetWebEngineContext"));
-
- if(!mGetWebEngineContextPtr)
- {
- DALI_LOG_ERROR("Can't load symbol GetWebEngineContext(), error: %s\n", dlerror());
- return false;
- }
+ dlclose(mHandle);
+ mHandle = nullptr;
}
-
- return true;
}
- bool InitializeCookieManagerHandle()
+ bool InitializePluginHandle()
{
- if(!mHandle)
- {
- return false;
- }
-
- if(!mGetWebEngineCookieManagerPtr)
+ if(mHandle)
{
- mGetWebEngineCookieManagerPtr = reinterpret_cast<GetWebEngineCookieManager>(dlsym(mHandle, "GetWebEngineCookieManager"));
-
- if(!mGetWebEngineCookieManagerPtr)
- {
- DALI_LOG_ERROR("Can't load symbol GetWebEngineCookieManager(), error: %s\n", dlerror());
- return false;
- }
+ DALI_LOG_ERROR("Plugin.so has been opened already.\n");
+ return true;
}
- return true;
- }
-
-private:
- // Private constructor / destructor
- WebEnginePluginObject()
- : mPluginName{},
- mLoadSuccess{false},
- mHandle{nullptr},
- mCreateWebEnginePtr{nullptr},
- mDestroyWebEnginePtr{nullptr},
- mGetWebEngineContextPtr{nullptr},
- mGetWebEngineCookieManagerPtr{nullptr}
- {
if(mPluginName.length() == 0)
{
// mPluginName is not initialized yet.
if(!mHandle)
{
DALI_LOG_ERROR("Can't load %s : %s\n", mPluginName.c_str(), dlerror());
- return;
+ return false;
}
mCreateWebEnginePtr = reinterpret_cast<CreateWebEngineFunction>(dlsym(mHandle, "CreateWebEnginePlugin"));
if(mCreateWebEnginePtr == nullptr)
{
DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", dlerror());
- return;
+
+ return false;
}
mDestroyWebEnginePtr = reinterpret_cast<DestroyWebEngineFunction>(dlsym(mHandle, "DestroyWebEnginePlugin"));
if(mDestroyWebEnginePtr == nullptr)
{
DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", dlerror());
- return;
+ return false;
}
- mLoadSuccess = true;
+ return true;
}
- ~WebEnginePluginObject()
+ bool InitializeContextHandle()
{
- if(mHandle)
+ if(!InitializePluginHandle())
{
- dlclose(mHandle);
- mHandle = nullptr;
- mLoadSuccess = false;
+ return false;
+ }
+
+ mGetWebEngineContextPtr = reinterpret_cast<GetWebEngineContext>(dlsym(mHandle, "GetWebEngineContext"));
+
+ if(!mGetWebEngineContextPtr)
+ {
+ DALI_LOG_ERROR("Can't load symbol GetWebEngineContext(), error: %s\n", dlerror());
+ return false;
}
+
+ return true;
}
+ bool InitializeCookieManagerHandle()
+ {
+ if(!InitializePluginHandle())
+ {
+ return false;
+ }
+
+ mGetWebEngineCookieManagerPtr = reinterpret_cast<GetWebEngineCookieManager>(dlsym(mHandle, "GetWebEngineCookieManager"));
+
+ if(!mGetWebEngineCookieManagerPtr)
+ {
+ DALI_LOG_ERROR("Can't load symbol GetWebEngineCookieManager(), error: %s\n", dlerror());
+ return false;
+ }
+
+ return true;
+ }
+
+private:
WebEnginePluginObject(const WebEnginePluginObject&) = delete;
WebEnginePluginObject(WebEnginePluginObject&&) = delete;
WebEnginePluginObject& operator=(const WebEnginePluginObject&) = delete;
/// 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.
- bool mLoadSuccess; ///< True if library loaded successfully. False otherwise.
-
public:
using CreateWebEngineFunction = Dali::WebEnginePlugin* (*)();
using DestroyWebEngineFunction = void (*)(Dali::WebEnginePlugin* plugin);
GetWebEngineCookieManager mGetWebEngineCookieManagerPtr; ///< Function to get WebEngineCookieManager
};
+static WebEnginePluginObject gPluginHandle; // Keep this object as static, so Let we assume that library closed after all WebEngines are disposed.
+
} // unnamed namespace
WebEnginePtr WebEngine::New()
Dali::WebEngineContext* WebEngine::GetContext()
{
- if(!WebEnginePluginObject::GetInstance().InitializeContextHandle())
+ if(!gPluginHandle.InitializeContextHandle())
{
return nullptr;
}
- if(WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr)
+ if(gPluginHandle.mGetWebEngineContextPtr)
{
- return WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr();
+ return gPluginHandle.mGetWebEngineContextPtr();
}
return nullptr;
Dali::WebEngineCookieManager* WebEngine::GetCookieManager()
{
- if(!WebEnginePluginObject::GetInstance().InitializeCookieManagerHandle())
+ if(!gPluginHandle.InitializeCookieManagerHandle())
{
return nullptr;
}
- if(WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr)
+ if(gPluginHandle.mGetWebEngineCookieManagerPtr)
{
- return WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr();
+ return gPluginHandle.mGetWebEngineCookieManagerPtr();
}
return nullptr;
if(mPlugin != nullptr)
{
mPlugin->Destroy();
- // Check whether plugin load sccess or not.
- if(DALI_LIKELY(WebEnginePluginObject::GetInstance()))
+ if(gPluginHandle.mDestroyWebEnginePtr != nullptr)
{
- WebEnginePluginObject::GetInstance().mDestroyWebEnginePtr(mPlugin);
+ gPluginHandle.mDestroyWebEnginePtr(mPlugin);
}
mPlugin = nullptr;
}
bool WebEngine::Initialize()
{
- // Check whether plugin load sccess or not.
- if(!WebEnginePluginObject::GetInstance())
+ if(!gPluginHandle.InitializePluginHandle())
{
return false;
}
- mPlugin = WebEnginePluginObject::GetInstance().mCreateWebEnginePtr();
+ mPlugin = gPluginHandle.mCreateWebEnginePtr();
if(mPlugin == nullptr)
{
DALI_LOG_ERROR("Can't create the WebEnginePlugin object\n");