// 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:
- WebEnginePluginObject()
- : mPluginName{},
- mHandle{nullptr},
- mCreateWebEnginePtr{nullptr},
- mDestroyWebEnginePtr{nullptr},
- mGetWebEngineContextPtr{nullptr},
- mGetWebEngineCookieManagerPtr{nullptr}
+ static WebEnginePluginObject& GetInstance()
{
+ static WebEnginePluginObject gPluginHandle;
+ return gPluginHandle;
}
- ~WebEnginePluginObject()
+ /**
+ * @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
{
- if(mHandle)
+ return mLoadSuccess;
+ }
+
+ bool InitializeContextHandle()
+ {
+ if(!mHandle)
{
- dlclose(mHandle);
- mHandle = nullptr;
+ return false;
+ }
+
+ if(!mGetWebEngineContextPtr)
+ {
+ 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 InitializePluginHandle()
+ bool InitializeCookieManagerHandle()
{
- if(mHandle)
+ if(!mHandle)
{
- DALI_LOG_ERROR("Plugin.so has been opened already.\n");
- return true;
+ return false;
}
+ if(!mGetWebEngineCookieManagerPtr)
+ {
+ 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:
+ // 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 false;
+ return;
}
mCreateWebEnginePtr = reinterpret_cast<CreateWebEngineFunction>(dlsym(mHandle, "CreateWebEnginePlugin"));
if(mCreateWebEnginePtr == nullptr)
{
DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", dlerror());
-
- return false;
+ return;
}
mDestroyWebEnginePtr = reinterpret_cast<DestroyWebEngineFunction>(dlsym(mHandle, "DestroyWebEnginePlugin"));
if(mDestroyWebEnginePtr == nullptr)
{
DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", dlerror());
- return false;
- }
-
- return true;
- }
-
- bool InitializeContextHandle()
- {
- if(!InitializePluginHandle())
- {
- 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;
}
- return true;
+ mLoadSuccess = true;
}
- bool InitializeCookieManagerHandle()
+ ~WebEnginePluginObject()
{
- if(!InitializePluginHandle())
- {
- return false;
- }
-
- mGetWebEngineCookieManagerPtr = reinterpret_cast<GetWebEngineCookieManager>(dlsym(mHandle, "GetWebEngineCookieManager"));
-
- if(!mGetWebEngineCookieManagerPtr)
+ if(mHandle)
{
- DALI_LOG_ERROR("Can't load symbol GetWebEngineCookieManager(), error: %s\n", dlerror());
- return false;
+ dlclose(mHandle);
+ mHandle = nullptr;
+ mLoadSuccess = 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(!gPluginHandle.InitializeContextHandle())
+ if(!WebEnginePluginObject::GetInstance().InitializeContextHandle())
{
return nullptr;
}
- if(gPluginHandle.mGetWebEngineContextPtr)
+ if(WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr)
{
- return gPluginHandle.mGetWebEngineContextPtr();
+ return WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr();
}
return nullptr;
Dali::WebEngineCookieManager* WebEngine::GetCookieManager()
{
- if(!gPluginHandle.InitializeCookieManagerHandle())
+ if(!WebEnginePluginObject::GetInstance().InitializeCookieManagerHandle())
{
return nullptr;
}
- if(gPluginHandle.mGetWebEngineCookieManagerPtr)
+ if(WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr)
{
- return gPluginHandle.mGetWebEngineCookieManagerPtr();
+ return WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr();
}
return nullptr;
if(mPlugin != nullptr)
{
mPlugin->Destroy();
- if(gPluginHandle.mDestroyWebEnginePtr != nullptr)
+ // Check whether plugin load sccess or not.
+ if(DALI_LIKELY(WebEnginePluginObject::GetInstance()))
{
- gPluginHandle.mDestroyWebEnginePtr(mPlugin);
+ WebEnginePluginObject::GetInstance().mDestroyWebEnginePtr(mPlugin);
}
mPlugin = nullptr;
}
bool WebEngine::Initialize()
{
- if(!gPluginHandle.InitializePluginHandle())
+ // Check whether plugin load sccess or not.
+ if(!WebEnginePluginObject::GetInstance())
{
return false;
}
- mPlugin = gPluginHandle.mCreateWebEnginePtr();
+ mPlugin = WebEnginePluginObject::GetInstance().mCreateWebEnginePtr();
if(mPlugin == nullptr)
{
DALI_LOG_ERROR("Can't create the WebEnginePlugin object\n");