X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fweb-engine%2Fcommon%2Fweb-engine-impl.cpp;h=3d5e30006ac85adf71b0600de8f0a5f5bef7d390;hb=d105b28a6c25960236f2e3d1204c4171f50579ca;hp=75fe93fc0b5fbffb01570152c90c404b79ff0d6d;hpb=416da9ed16daedbf3592a7a79e7b36b7b7422235;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/web-engine/common/web-engine-impl.cpp b/dali/internal/web-engine/common/web-engine-impl.cpp old mode 100755 new mode 100644 index 75fe93f..3d5e300 --- a/dali/internal/web-engine/common/web-engine-impl.cpp +++ b/dali/internal/web-engine/common/web-engine-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -26,16 +26,16 @@ // INTERNAL INCLUDES #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -52,10 +52,6 @@ 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::stringstream fullName; @@ -70,103 +66,237 @@ Dali::BaseHandle Create() Dali::TypeRegistration type(typeid(Dali::WebEngine), typeid(Dali::BaseHandle), Create); -} // unnamed namespace - -WebEnginePtr WebEngine::New() +/** + * @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 { - WebEngine* instance = new WebEngine(); +public: + static WebEnginePluginObject& GetInstance() + { + static WebEnginePluginObject gPluginHandle; + return gPluginHandle; + } - if(!instance->Initialize()) + /** + * @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 { - delete instance; - return nullptr; + return mLoadSuccess; } - return instance; -} + bool InitializeContextHandle() + { + if(!mHandle) + { + return false; + } -WebEngine::WebEngine() -: mPlugin(NULL), - mHandle(NULL), - mCreateWebEnginePtr(NULL), - mDestroyWebEnginePtr(NULL) -{ -} + if(!mGetWebEngineContextPtr) + { + mGetWebEngineContextPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineContext")); -WebEngine::~WebEngine() -{ - if(mHandle != NULL) + if(!mGetWebEngineContextPtr) + { + DALI_LOG_ERROR("Can't load symbol GetWebEngineContext(), error: %s\n", dlerror()); + return false; + } + } + + return true; + } + + bool InitializeCookieManagerHandle() { - if(mDestroyWebEnginePtr != NULL) + if(!mHandle) { - mPlugin->Destroy(); - mDestroyWebEnginePtr(mPlugin); + return false; } - dlclose(mHandle); + if(!mGetWebEngineCookieManagerPtr) + { + mGetWebEngineCookieManagerPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineCookieManager")); + + if(!mGetWebEngineCookieManagerPtr) + { + DALI_LOG_ERROR("Can't load symbol GetWebEngineCookieManager(), error: %s\n", dlerror()); + return false; + } + } + + return true; } -} -bool WebEngine::InitializePluginHandle() -{ - if(pluginName.length() == 0) +private: + // Private constructor / destructor + WebEnginePluginObject() + : mPluginName{}, + mLoadSuccess{false}, + mHandle{nullptr}, + mCreateWebEnginePtr{nullptr}, + mDestroyWebEnginePtr{nullptr}, + mGetWebEngineContextPtr{nullptr}, + mGetWebEngineCookieManagerPtr{nullptr} { - // pluginName is not initialized yet. - const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME); - if(name) + if(mPluginName.length() == 0) { - pluginName = MakePluginName(name); - mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); - if(mHandle) + // mPluginName is not initialized yet. + const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME); + if(name) { - return true; + mPluginName = MakePluginName(name); } + else + { + mPluginName = std::string(kPluginFullNameDefault); + } + } + + mHandle = dlopen(mPluginName.c_str(), RTLD_LAZY); + if(!mHandle) + { + DALI_LOG_ERROR("Can't load %s : %s\n", mPluginName.c_str(), dlerror()); + return; + } + + mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); + if(mCreateWebEnginePtr == nullptr) + { + DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", dlerror()); + return; + } + + mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); + if(mDestroyWebEnginePtr == nullptr) + { + DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", dlerror()); + return; } - pluginName = std::string(kPluginFullNameDefault); + + mLoadSuccess = true; } - mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); - if(!mHandle) + ~WebEnginePluginObject() { - DALI_LOG_ERROR("Can't load %s : %s\n", pluginName.c_str(), dlerror()); - return false; + if(mHandle) + { + dlclose(mHandle); + mHandle = nullptr; + mLoadSuccess = false; + } } - return true; + WebEnginePluginObject(const WebEnginePluginObject&) = delete; + WebEnginePluginObject(WebEnginePluginObject&&) = delete; + WebEnginePluginObject& operator=(const WebEnginePluginObject&) = delete; + WebEnginePluginObject& operator=(WebEnginePluginObject&&) = delete; + +private: + std::string mPluginName; ///< Name of web engine plugin + /// 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); + + using GetWebEngineContext = Dali::WebEngineContext* (*)(); + using GetWebEngineCookieManager = Dali::WebEngineCookieManager* (*)(); + + void* mHandle; ///< Handle for the loaded library + CreateWebEngineFunction mCreateWebEnginePtr; ///< Function to create plugin instance + DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance + + GetWebEngineContext mGetWebEngineContextPtr; ///< Function to get WebEngineContext + GetWebEngineCookieManager mGetWebEngineCookieManagerPtr; ///< Function to get WebEngineCookieManager +}; + +} // unnamed namespace + +WebEnginePtr WebEngine::New() +{ + WebEngine* instance = new WebEngine(); + if(!instance->Initialize()) + { + delete instance; + return nullptr; + } + + return instance; } -bool WebEngine::Initialize() +Dali::WebEngineContext* WebEngine::GetContext() { - char* error = NULL; + if(!WebEnginePluginObject::GetInstance().InitializeContextHandle()) + { + return nullptr; + } - if(!InitializePluginHandle()) + if(WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr) { - return false; + return WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr(); + } + + return nullptr; +} + +Dali::WebEngineCookieManager* WebEngine::GetCookieManager() +{ + if(!WebEnginePluginObject::GetInstance().InitializeCookieManagerHandle()) + { + return nullptr; } - mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); - if(mCreateWebEnginePtr == NULL) + if(WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr) { - DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", error); - return false; + return WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr(); } - mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); + return nullptr; +} + +WebEngine::WebEngine() +: mPlugin(nullptr) +{ +} - if(mDestroyWebEnginePtr == NULL) +WebEngine::~WebEngine() +{ + if(mPlugin != nullptr) { - DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error); - return false; + mPlugin->Destroy(); + // Check whether plugin load sccess or not. + if(DALI_LIKELY(WebEnginePluginObject::GetInstance())) + { + WebEnginePluginObject::GetInstance().mDestroyWebEnginePtr(mPlugin); + } + mPlugin = nullptr; } +} - mPlugin = mCreateWebEnginePtr(); +bool WebEngine::Initialize() +{ + // Check whether plugin load sccess or not. + if(!WebEnginePluginObject::GetInstance()) + { + return false; + } - if(mPlugin == NULL) + mPlugin = WebEnginePluginObject::GetInstance().mCreateWebEnginePtr(); + if(mPlugin == nullptr) { DALI_LOG_ERROR("Can't create the WebEnginePlugin object\n"); return false; } - return true; } @@ -185,6 +315,11 @@ void WebEngine::Destroy() mPlugin->Destroy(); } +Dali::WebEnginePlugin* WebEngine::GetPlugin() const +{ + return mPlugin; +} + Dali::NativeImageSourcePtr WebEngine::GetNativeImageSource() { return mPlugin->GetNativeImageSource(); @@ -195,16 +330,6 @@ 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(); @@ -515,6 +640,11 @@ void WebEngine::ActivateAccessibility(bool activated) mPlugin->ActivateAccessibility(activated); } +Accessibility::Address WebEngine::GetAccessibilityAddress() +{ + return mPlugin->GetAccessibilityAddress(); +} + bool WebEngine::SetVisibility(bool visible) { return mPlugin->SetVisibility(visible);