X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fweb-engine%2Fcommon%2Fweb-engine-impl.cpp;h=87e1f6e68c8376939a4f61a97b16635e2b9f5160;hb=39e92ce9125526ae5d32882de44f01b03d27dc5a;hp=2388aa75fb938f6e33586f5c316146e5dfa620e1;hpb=2fd1c48c145e791f77d7d2e89fb78b3c206fa848;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 2388aa7..87e1f6e --- 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) 2023 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,227 @@ 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 mLoadSucceeded; } - 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")); + if(!mGetWebEngineContextPtr) + { + DALI_LOG_ERROR("Can't load symbol GetWebEngineContext(), error: %s\n", dlerror()); + return false; + } + } -WebEngine::~WebEngine() -{ - if(mHandle != NULL) + 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() + : mLoadSucceeded{false}, + mHandle{nullptr}, + mCreateWebEnginePtr{nullptr}, + mDestroyWebEnginePtr{nullptr}, + mGetWebEngineContextPtr{nullptr}, + mGetWebEngineCookieManagerPtr{nullptr} { - // pluginName is not initialized yet. + std::string pluginName; const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME); if(name) { pluginName = MakePluginName(name); - mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); - if(mHandle) - { - return true; - } } - pluginName = std::string(kPluginFullNameDefault); + else + { + pluginName = std::string(kPluginFullNameDefault); + } + + mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); + if(!mHandle) + { + DALI_LOG_ERROR("Can't load %s : %s\n", pluginName.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; + } + + mLoadSucceeded = 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; + mLoadSucceeded = false; + } } - return true; + WebEnginePluginObject(const WebEnginePluginObject&) = delete; + WebEnginePluginObject(WebEnginePluginObject&&) = delete; + WebEnginePluginObject& operator=(const WebEnginePluginObject&) = delete; + WebEnginePluginObject& operator=(WebEnginePluginObject&&) = delete; + +private: + bool mLoadSucceeded; ///< 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(); } - mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); - if(mCreateWebEnginePtr == NULL) + return nullptr; +} + +Dali::WebEngineCookieManager* WebEngine::GetCookieManager() +{ + if(!WebEnginePluginObject::GetInstance().InitializeCookieManagerHandle()) { - DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", error); - return false; + return nullptr; } - mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); + if(WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr) + { + return WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr(); + } - if(mDestroyWebEnginePtr == NULL) + return nullptr; +} + +WebEngine::WebEngine() +: mPlugin(nullptr) +{ +} + +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 +305,11 @@ void WebEngine::Destroy() mPlugin->Destroy(); } +Dali::WebEnginePlugin* WebEngine::GetPlugin() const +{ + return mPlugin; +} + Dali::NativeImageSourcePtr WebEngine::GetNativeImageSource() { return mPlugin->GetNativeImageSource(); @@ -195,16 +320,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(); @@ -250,7 +365,7 @@ bool WebEngine::LoadHtmlStringOverrideCurrentEntry(const std::string& html, cons return mPlugin->LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl); } -bool WebEngine::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) +bool WebEngine::LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) { return mPlugin->LoadContents(contents, contentSize, mimeType, encoding, baseUri); } @@ -515,6 +630,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); @@ -570,9 +690,9 @@ bool WebEngine::SendWheelEvent(const Dali::WheelEvent& event) return mPlugin->SendWheelEvent(event); } -Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal() +void WebEngine::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback) { - return mPlugin->FrameRenderedSignal(); + mPlugin->RegisterFrameRenderedCallback(callback); } void WebEngine::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback) @@ -620,6 +740,16 @@ void WebEngine::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::Web mPlugin->RegisterResponsePolicyDecidedCallback(callback); } +void WebEngine::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) +{ + mPlugin->RegisterNavigationPolicyDecidedCallback(callback); +} + +void WebEngine::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback) +{ + mPlugin->RegisterNewWindowCreatedCallback(callback); +} + void WebEngine::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback) { mPlugin->RegisterCertificateConfirmedCallback(callback);