From 9ab6b03c1af0992b6b4af3f04b7a1bf9554e2276 Mon Sep 17 00:00:00 2001 From: Wonsik Jung Date: Tue, 15 Nov 2022 11:25:35 +0900 Subject: [PATCH] Revert "[Tizen][Web] Fix WebView terminate crash" This reverts commit c7025658d79551ee9f28520fbe010526cb893ab9. --- .../internal/web-engine/common/web-engine-impl.cpp | 225 +++++++-------------- dali/internal/web-engine/common/web-engine-impl.h | 19 ++ 2 files changed, 97 insertions(+), 147 deletions(-) mode change 100644 => 100755 dali/internal/web-engine/common/web-engine-impl.cpp diff --git a/dali/internal/web-engine/common/web-engine-impl.cpp b/dali/internal/web-engine/common/web-engine-impl.cpp old mode 100644 new mode 100755 index c530481..558dac7 --- a/dali/internal/web-engine/common/web-engine-impl.cpp +++ b/dali/internal/web-engine/common/web-engine-impl.cpp @@ -53,6 +53,10 @@ 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; @@ -67,184 +71,114 @@ Dali::BaseHandle Create() Dali::TypeRegistration type(typeid(Dali::WebEngine), typeid(Dali::BaseHandle), Create); -/** - * @brief Control the WebEnginePlugin library lifecycle. - */ -struct WebEnginePluginObject -{ -public: - WebEnginePluginObject() - : mPluginName{}, - mHandle{nullptr}, - mCreateWebEnginePtr{nullptr}, - mDestroyWebEnginePtr{nullptr}, - mGetWebEngineContextPtr{nullptr}, - mGetWebEngineCookieManagerPtr{nullptr} +} // unnamed namespace + +void* WebEngine::mHandle = nullptr; +WebEngine::CreateWebEngineFunction WebEngine::mCreateWebEnginePtr = nullptr; +WebEngine::DestroyWebEngineFunction WebEngine::mDestroyWebEnginePtr = nullptr; + +WebEnginePtr WebEngine::New() +{ + WebEngine* instance = new WebEngine(); + if(!instance->Initialize()) { + delete instance; + return nullptr; } - ~WebEnginePluginObject() + return instance; +} + +Dali::WebEngineContext* WebEngine::GetContext() +{ + if(!InitializePluginHandle()) { - if(mHandle) - { - dlclose(mHandle); - mHandle = nullptr; - } + return nullptr; } - bool InitializePluginHandle() + using GetWebEngineContext = Dali::WebEngineContext* (*)(); + GetWebEngineContext getWebEngineContextPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineContext")); + if(getWebEngineContextPtr) { - if(mHandle) - { - DALI_LOG_ERROR("Plugin.so has been opened already.\n"); - return true; - } - - if(mPluginName.length() == 0) - { - // mPluginName is not initialized yet. - const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME); - if(name) - { - 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 false; - } - - mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); - if(mCreateWebEnginePtr == nullptr) - { - DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", dlerror()); - - return false; - } + return getWebEngineContextPtr(); + } - mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); - if(mDestroyWebEnginePtr == nullptr) - { - DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", dlerror()); - return false; - } + return nullptr; +} - return true; +Dali::WebEngineCookieManager* WebEngine::GetCookieManager() +{ + if(!InitializePluginHandle()) + { + return nullptr; } - bool InitializeContextHandle() + using GetWebEngineCookieManager = Dali::WebEngineCookieManager* (*)(); + GetWebEngineCookieManager getWebEngineCookieManagerPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineCookieManager")); + if(getWebEngineCookieManagerPtr) { - if(!InitializePluginHandle()) - { - return false; - } - - mGetWebEngineContextPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineContext")); + return getWebEngineCookieManagerPtr(); + } - if(!mGetWebEngineContextPtr) - { - DALI_LOG_ERROR("Can't load symbol GetWebEngineContext(), error: %s\n", dlerror()); - return false; - } + return nullptr; +} +bool WebEngine::InitializePluginHandle() +{ + if(mHandle) + { + DALI_LOG_ERROR("Plugin.so has been opened already.\n"); return true; } - bool InitializeCookieManagerHandle() + if(pluginName.length() == 0) { - if(!InitializePluginHandle()) + // pluginName is not initialized yet. + const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME); + if(name) { - return false; + pluginName = MakePluginName(name); } - - mGetWebEngineCookieManagerPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineCookieManager")); - - if(!mGetWebEngineCookieManagerPtr) + else { - DALI_LOG_ERROR("Can't load symbol GetWebEngineCookieManager(), error: %s\n", dlerror()); - return false; + pluginName = std::string(kPluginFullNameDefault); } - - return true; } -private: - 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. - -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 -}; - -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() -{ - WebEngine* instance = new WebEngine(); - if(!instance->Initialize()) + mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); + if(!mHandle) { - delete instance; - return nullptr; + DALI_LOG_ERROR("Can't load %s : %s\n", pluginName.c_str(), dlerror()); + return false; } - return instance; -} + // Make sure that mHandle would be closed. + Dali::LifecycleController::Get().TerminateSignal().Connect(&WebEngine::ClosePluginHandle); -Dali::WebEngineContext* WebEngine::GetContext() -{ - if(!gPluginHandle.InitializeContextHandle()) + mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); + if(mCreateWebEnginePtr == nullptr) { - return nullptr; + DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", dlerror()); + return false; } - if(gPluginHandle.mGetWebEngineContextPtr) + mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); + if(mDestroyWebEnginePtr == nullptr) { - return gPluginHandle.mGetWebEngineContextPtr(); + DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", dlerror()); + return false; } - return nullptr; + return true; } -Dali::WebEngineCookieManager* WebEngine::GetCookieManager() +void WebEngine::ClosePluginHandle() { - if(!gPluginHandle.InitializeCookieManagerHandle()) - { - return nullptr; - } - - if(gPluginHandle.mGetWebEngineCookieManagerPtr) + if(mHandle) { - return gPluginHandle.mGetWebEngineCookieManagerPtr(); + dlclose(mHandle); + mHandle = nullptr; } - - return nullptr; } WebEngine::WebEngine() @@ -254,30 +188,27 @@ WebEngine::WebEngine() WebEngine::~WebEngine() { - if(mPlugin != nullptr) + if(mPlugin != nullptr && mDestroyWebEnginePtr != nullptr) { mPlugin->Destroy(); - if(gPluginHandle.mDestroyWebEnginePtr != nullptr) - { - gPluginHandle.mDestroyWebEnginePtr(mPlugin); - } - mPlugin = nullptr; + mDestroyWebEnginePtr(mPlugin); } } bool WebEngine::Initialize() { - if(!gPluginHandle.InitializePluginHandle()) + if(!InitializePluginHandle()) { return false; } - mPlugin = gPluginHandle.mCreateWebEnginePtr(); + mPlugin = mCreateWebEnginePtr(); if(mPlugin == nullptr) { DALI_LOG_ERROR("Can't create the WebEnginePlugin object\n"); return false; } + return true; } diff --git a/dali/internal/web-engine/common/web-engine-impl.h b/dali/internal/web-engine/common/web-engine-impl.h index 96e6eac..085c28a 100755 --- a/dali/internal/web-engine/common/web-engine-impl.h +++ b/dali/internal/web-engine/common/web-engine-impl.h @@ -576,8 +576,27 @@ private: */ bool Initialize(); + /** + * @brief Initialize library handle by loading web engine plugin. + * + * @return Whether the initialization succeed or not. + */ + static bool InitializePluginHandle(); + + /** + * @brief Close library handle. + */ + static void ClosePluginHandle(); + private: + using CreateWebEngineFunction = Dali::WebEnginePlugin* (*)(); + using DestroyWebEngineFunction = void (*)(Dali::WebEnginePlugin* plugin); + Dali::WebEnginePlugin* mPlugin; ///< WebEnginePlugin instance + + static void* mHandle; ///< Handle for the loaded library + static CreateWebEngineFunction mCreateWebEnginePtr; ///< Function to create plugin instance + static DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance }; } // namespace Adaptor -- 2.7.4